dbawel

Animate Cloned Mesh Children

Recommended Posts

Hello,

I have a mesh (an airplane) which needs to be cloned 20 times - and then all 20 clones require their propeller to animate at different speeds and times. How do I identify each propeller or assign a variable (preferably a slot in a "propeller" array) to each cloned propeller to animate - once again animate separately. When I clone each airplane, how do I know the name of each child on the parent mesh, and animate it's children such as the propellers? How do I assign a unique name to each one? Once I have a unique name or variable assigned to each, then I can animate each one separately - but I don't know how to "Get" the names of cloned meshes or assign to a slot in an array upon cloning. Any ideas?

DB

Share this post


Link to post
Share on other sites

if your just transforming the clones use Instances unless they are needing new materials or other unique features.
and when you clone them stick them into an array for later reference would be way better then having to search through all the meshes for a unique name.

then you just apply your animations to what ever correct instance in the array.

 

Share this post


Link to post
Share on other sites

I did this as a test not long ago and it worked fine:

var fan=scene.getMeshByName("Industrial_Fan_1"); /* a mesh already loaded in the scene, with animations */
for (var index = 0; index < 10; index++) {
    var newInstance = fan.createInstance("i" + index); /* iterate the instance name */
/* Probably you'll want to reposition the new instance here. */
    newInstance.animations.push(fan.animations[0]); /* copy the same animations from the original as these aren't carried over in the new instance */
    scene.beginAnimation(newInstance, 0, 30, true); /* start animating the new instance */
}

 

Share this post


Link to post
Share on other sites
18 hours ago, Pryme8 said:

if your just transforming the clones use Instances unless they are needing new materials or other unique features.
and when you clone them stick them into an array for later reference would be way better then having to search through all the meshes for a unique name.

then you just apply your animations to what ever correct instance in the array.

 

I remember this plane from another topic, & looked at the .blend.  The propeller & rubberband are child meshes, so actual making of instances are more work.  Cloning also clones the children meshes unless you say not to, but I do not think instancing does meshes.

For cloning, the trick is to know the name the clone child gets.  Once you have that, the next problem is that cloning does not copy any animation.  Fortunately,  animations, defined at Node level, is an array, a.k.a reference object, so only the reference array needs be copied.

Do not think you need to copy animations for instances.  The bad news is that looks like you wish to change the speeds.  If that cannot be specified when starting the animation on a mesh, you will have to deep copy the animations for clone, & you are just screwed for instances.

Share this post


Link to post
Share on other sites

@JCPalmer -

I tried every method I know to determine the names of the children of a clone. Even mesh._children(); doesn't return the children of a clone. At least I couldn't get any result from this function at all. I'm now considering separating all of the meshes from the parent file that need to animate. But considering there are dozens of meshes to animate - this adds allot of code which could easily be avoided as the children of a clone definitely have names. They must in order to  animate at all. But I'm running out of time, and there appear to be no more options.

DB

Share this post


Link to post
Share on other sites

Ok, forget about doing some call.  I already pointed you to the line where a cloned child gets its name.  Access the mesh clone by:

var source = scene.getMeshByName("parent.Prop").animations;
// in a loop like for each clone
scene.getMeshByName("parent_01.Prop").animations = source;
. . .
scene.getMeshByName("parent_19.Prop").animations = source;

There are always options.  Crude but effective to find every mesh name in the scene written to console:

for(var i = 0, len = scene.meshes.length(); i < len; i++) {
    console.log(scene.meshes[i].name);
}

Scrape out the exact details out of the console, put into the first example, & throw away.  Move on to the rest.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.