dbawel Posted February 12, 2018 Share Posted February 12, 2018 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 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 12, 2018 Share Posted February 12, 2018 scene.getMeshByName("uniqueName") allows you to retrieve the object by name. When you "clone" you add a name : mesh.clone("uniqueName") Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted February 12, 2018 Share Posted February 12, 2018 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. Quote Link to comment Share on other sites More sharing options...
Snouto Posted February 13, 2018 Share Posted February 13, 2018 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 */ } Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 13, 2018 Share Posted February 13, 2018 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. Quote Link to comment Share on other sites More sharing options...
dbawel Posted February 14, 2018 Author Share Posted February 14, 2018 @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 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 14, 2018 Share Posted February 14, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.