Richard C Posted December 11, 2016 Share Posted December 11, 2016 I have an imported blender scene. There are a number of objects. As I understand it, I can parent them to a 'pseudo' object and moving that object will move all the children as one So I create the pseudo object, BoxP............... var boxP = BABYLON.Mesh.CreateBox("box0", 25, scene); ............create a variable........................ var nMeshName Loop through each of the imported objects and parent them one by one to BoxP for (var index = 0; index < scene.meshes.length; index++) { nMeshName = scene.meshes[index].name; nMeshName.parent = boxP; } But console log console.log("children = "+boxP.getChildren().length); returns 0 Therefore, in wanting to check what are the children of boxP ............. for(var i = 0; i < box0.getChildren().length; i++) { } I of course get 0. Could someone tell me what I have one wrong here please or tell me an alternative way of establishing the children of a parent. I have also tried getDescendants which is no more successful Thanks Richard C Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 11, 2016 Share Posted December 11, 2016 you need to do a recursive loop function instead of a standard loop *EDIT whooops reread, um just output the mesh to your console, and you will see there is an array called childrenmeshs or submeshs or something like that, find the one that has the info you need and use its length. Quote Link to comment Share on other sites More sharing options...
ArcticArcade Posted December 11, 2016 Share Posted December 11, 2016 Have you tried console.log("children = "+boxP.children.length); ? if that returns the right amount, then loop boxP.children Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 11, 2016 Share Posted December 11, 2016 http://www.babylonjs-playground.com/#TKM29#0 its mesh._children Quote Link to comment Share on other sites More sharing options...
Richard C Posted December 11, 2016 Author Share Posted December 11, 2016 Thanks Pryme8 and ArcticArca but neither of those suggestions work. Playing a bit more with: var boxP = BABYLON.Mesh.CreateBox("box0", 25, scene); boxP.isVisible = false; var nMeshName for (var index = 0; index < scene.meshes.length; index++) { nMeshName = scene.meshes[index].name; nMeshName.parent = boxP; } Going through the scene meshes a second shows that none of the meshes are being parented to boxP for (var index = 0; index < scene.meshes.length; index++) { console.log("meshes = "+scene.meshes[index]); } Any further suggestions anyone please. Thanks again Quote Link to comment Share on other sites More sharing options...
adam Posted December 12, 2016 Share Posted December 12, 2016 Did you try getChildMeshes? You should create a playground of the issue. Quote Link to comment Share on other sites More sharing options...
Richard C Posted December 12, 2016 Author Share Posted December 12, 2016 Problem resolved A bit more research and I learned that objects assigned to an Empty in Blender will be exported with Parent (the Empty) and Children (all assigned objects) The parent and it's children can be manipulated as necessary. It would be good to know why my earlier post ............. var boxP = BABYLON.Mesh.CreateBox("box0", 25, scene); boxP.isVisible = false; var nMeshName for (var index = 0; index < scene.meshes.length; index++) { nMeshName = scene.meshes[index].name; nMeshName.parent = boxP; } doesn't work though. Any thoughts anyone? Thanks Richard C Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 12, 2016 Share Posted December 12, 2016 Mesh._children.length works your tripping if you say it does not. I even posted a playgroudn taht proves it... im too drunk for this nonesne... night Quote Link to comment Share on other sites More sharing options...
gryff Posted December 12, 2016 Share Posted December 12, 2016 @Richard C, @adam, @Pryme8 : I have never pretended to be anything more than a javascript wimp but I'm curious about the code.posted above 9 hours ago, Richard C said: var boxP = BABYLON.Mesh.CreateBox("box0", 25, scene); But does that not add a mesh to "scene.meshes" and therefore does the loop for (var index = 0; index < scene.meshes.length; index++) { nMeshName = scene.meshes[index].name; nMeshName.parent = boxP; } not try to parent boxP to itself - as boxP will have been added to "scene.meshes"? Should the loop not use "scene.meshes.length-1" As I say just a comment from a javascript wimp cheers, gryff Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Richard C Posted December 12, 2016 Author Share Posted December 12, 2016 Problem resolved I should have remembered that objects assigned to an Empty in Blender will be exported with Parent (the Empty) and Children (all assigned objects).The parent and it's children can be manipulated as necessary. It would be good to know why my earlier post ............. var boxP = BABYLON.Mesh.CreateBox("boxP", 25, scene); boxP.isVisible = false; var nMeshName for (var index = 0; index < scene.meshes.length; index++) { nMeshName = scene.meshes[index].name; nMeshName.parent = boxP; } doesn't work though. Any thoughts anyone? Thanks Richard C Quote Link to comment Share on other sites More sharing options...
Richard C Posted December 12, 2016 Author Share Posted December 12, 2016 Gryff I did have a statement in the loop to prevent boxP being included in the parenting - but because the whole loop didn't work, I can't be sure if it got included or not. In theory it shouldn't because I thought I was looping through imported Blender mesh. Cheers Richard C Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 12, 2016 Share Posted December 12, 2016 22 minutes ago, Richard C said: for (var index = 0; index < scene.meshes.length; index++) { nMeshName = scene.meshes[index].name; nMeshName.parent = boxP; } since scene.meshes[index].name is just the name of the mesh, ie a string, then it is no good trying to give a string a parent. use scene.meshes[index].parent = boxP Quote Link to comment Share on other sites More sharing options...
Richard C Posted December 12, 2016 Author Share Posted December 12, 2016 JohnK That works. It's very annoying when I'm given a solution and immediately think "I'm a knob, of course that's the answer. I should've known that or been able to work it out". Thanks again everyone. Richard C Quote Link to comment Share on other sites More sharing options...
Richard C Posted December 12, 2016 Author Share Posted December 12, 2016 Gryff I confirm that a prevention statement in the loop (in my case "boxP") does exclude it being parent. if (scene.meshes[index] == boxP) { } else { scene.meshes[index].parent = boxP; } } Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 12, 2016 Share Posted December 12, 2016 Meshs.length-1 always.... when looping through an array... that uses the length of the array. 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.