dbawel Posted February 6, 2018 Share Posted February 6, 2018 Hello, I import .babylon files to use in scenes regularly; however, there is a bit of knowledge I'm lacking to fully understand how to use each of the elements in my scene independently. As an example, the following is typical code used to import a scene from Blender and clone many hierarchical meshes from this one .babylon file: Quote // Import Biplane model, transform, and parent to box mesh BABYLON.SceneLoader.ImportMesh('', './Demos/models3/', 'biplane5.babylon', scene, function (newMeshes) { const Rmesh = newMeshes[0]; Rmesh.scaling = new BABYLON.Vector3(4, 4, 4); Rmesh.rotation.y = Math.PI / 2; Rmesh.position.y = -100; for (let nb = 0; nb <= (Vcount - 1); nb++) { rocketsArray[nb] = Rmesh.clone('biplane' + nb); rocketsArray[nb].position.y = 0; rocketsArray[nb].parent = boxRotArray[nb]; } }); And this always works - however, I often need to animate several of the meshes from this one scene separately - such as this scene above is an airplane with a propeller on the front which needs to be animated on many clones of the plane. So what I'm not clear on from reading the documentation as well as running many playground searches, is how to access the other meshes in the scene such as the propeller. I have tried to get mesh by name, access different slots in the newMeshes[] array, and every other method I can think of - but have not been able to access the propeller or other objects in the .babylon file in a simple method. The only way I've been able to animate these other meshes is to import each additional mesh separately, parent the mesh to the plane (such as the propeller) back onto the plane, and animate it's rotation separately. However, I assume this is far more effort than is necessary, and I cannot get the information I require to simplify this from the documentation. So in looking at the above code where I'm importing an airplane with a propeller and cloning the airplane and it's children including the propeller - how do I access and animate the propeller in this scene without having to re-import the propeller, parent to the plane, and then animate the rotation? The propeller is already in the scene, but I simply don't know how to access and assign the propeller in the scene to a variable and/or array to then animate as a separate object. Even though I believe the explanation is easy to understand, I've attached the Blender file so that you can see what I'm speaking about in animating the propeller(simply rotating it.) If there is a playground scene which clearly demonstrates this, it would be much appreciated. although I cannot find one. Only the "Dude" scenes, which aren't relevant to my current needs as I need to animate meshes from the scene in the babylon engine - not in Blender. I know this is done by many users on this forum regularly, but I cannot locate the info on how to set this up myself. As always, any help is greatly appreciated. Thank you, DB biplane_model.zip Quote Link to comment Share on other sites More sharing options...
Guest Posted February 6, 2018 Share Posted February 6, 2018 Hello you can drag and drop the scene with assets in the sandbox and use the debug layer to get the list of meshes (with their names) Once you have the name of the propeller, a simple scene.getMeshByName should suffice dbawel 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted February 6, 2018 Author Share Posted February 6, 2018 @Deltakosh- That is a great idea. I'll give it a try, and let you know how successful it works for me. But this is what I was considering - just not using the sandbox - which is a GREAT idea. Thanks, DB Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 7, 2018 Share Posted February 7, 2018 BABYLON.SceneLoader.ImportMesh('', './Demos/models3/', 'biplane5.babylon', scene, function (newMeshes) { const Biplane = scene.getMeshByName('Biplane'); // case sensitive Biplane.scaling = new BABYLON.Vector3(4, 4, 4); Biplane.rotation.y = Math.PI / 2; Biplane.position.y = -100; for (let nb = 0; nb <= (Vcount - 1); nb++) { rocketsArray[nb] = Biplane.clone('Biplane' + nb); rocketsArray[nb].position.y = 0; rocketsArray[nb].parent = boxRotArray[nb]; } }); 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.