shen Posted May 9, 2018 Share Posted May 9, 2018 I tried to clone meshes imported from GLTF file and found that meshes were cloned twice. https://www.babylonjs-playground.com/#PSR2ZX#38 https://www.babylonjs-playground.com/#PSR2ZX#39 use the debug layer, you can find that the original root mesh was used as the parent of a set of cloned meshes. I also wonder whether the scale of the cloned meshes is correct? Quote Link to comment Share on other sites More sharing options...
RaananW Posted May 9, 2018 Share Posted May 9, 2018 Man, that feels like a rick and morty scene! The issue here is that you clone all of the meshes that are included in the gltf, which also clone the children (there is a doNotCloneChildren flag in the clone function which you could use). The simplest way would be to only clone the mesh that doesn't have a parent (like this - https://www.babylonjs-playground.com/#PSR2ZX#40) , which also answers the 2nd question you had. Quote Link to comment Share on other sites More sharing options...
shen Posted May 10, 2018 Author Share Posted May 10, 2018 @RaananW Thanks! doNotCloneChildren flag seems just do the opposite of your code. In your sandbox, the clones meshes are still different from the original ones. Except the size, I found that they got different boundaries by using the debug layers. Quote Link to comment Share on other sites More sharing options...
Guest Posted May 10, 2018 Share Posted May 10, 2018 The size difference comes from the fact that the original one is animated (with bones hence the scale, rotation and position changes) Quote Link to comment Share on other sites More sharing options...
shen Posted May 10, 2018 Author Share Posted May 10, 2018 Is it possible to clone models with exactly the same meshes, skeletons and animations? Quote Link to comment Share on other sites More sharing options...
Guest Posted May 11, 2018 Share Posted May 11, 2018 just affect the skeleton after cloning the mesh should make it: https://www.babylonjs-playground.com/#PSR2ZX#42 Quote Link to comment Share on other sites More sharing options...
shen Posted May 12, 2018 Author Share Posted May 12, 2018 @Deltakosh Thanks! I followed your example and tried to go further. I found that gltf loader seems create meshes from bones, and they are not necessary. In https://www.babylonjs-playground.com/#PSR2ZX#44 line 81-87, I deleted them, and nothing went wrong. In line 112, I also delete the animation targets without _skeleton, and animations all worked correctly without them. Then I cloned skeletons in skeletonClones and meshes in meshClones, and they are all fine. I cloned "abduction_rings" animationGroup in animationClone, and re-targeted it's animations to skeletonClones. Click "abduction_rings_clone" and you can see the animation is different from "abduction_rings". In line 127, I output the original targets and bones in skeletonClones. Bones in original targets seem have more information than the cloned ones. Quote Link to comment Share on other sites More sharing options...
Guest Posted May 14, 2018 Share Posted May 14, 2018 The timing is important here. If you clone the skeleton (not individual bones but the entire skeleton) before launching any animation you should be good Quote Link to comment Share on other sites More sharing options...
shen Posted May 16, 2018 Author Share Posted May 16, 2018 For the first question, I just checked babylon.glTFLoader.ts and found that it generated meshes from all "nodes". Shouldn't it just check all the "nodes" contains "meshes" https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#meshes? private _getMeshes(): Mesh[] { const meshes = new Array<Mesh>(); // Root mesh is always first. meshes.push(this._rootBabylonMesh); const nodes = this._gltf.nodes; if (nodes) { for (const node of nodes) { if (node._babylonMesh) { meshes.push(node._babylonMesh); } if (node._primitiveBabylonMeshes) { for (const babylonMesh of node._primitiveBabylonMeshes) { meshes.push(babylonMesh); } } } } return meshes; } Quote Link to comment Share on other sites More sharing options...
Guest Posted May 16, 2018 Share Posted May 16, 2018 pinging @bghgary Quote Link to comment Share on other sites More sharing options...
bghgary Posted May 16, 2018 Share Posted May 16, 2018 5 hours ago, shen said: generated meshes from all "nodes" @shen The root issue is that glTF puts the skeleton in the hierarchy of nodes. There may be usage cases where a node is being used both as a joint and as a node (say as a node for attaching objects to at runtime). There is no way for the loader to tell if the node is going to be used or not and thus the loader just creates a bone and a mesh and animates both of them. Quote Link to comment Share on other sites More sharing options...
shen Posted May 16, 2018 Author Share Posted May 16, 2018 50 minutes ago, bghgary said: @shen The root issue is that glTF puts the skeleton in the hierarchy of nodes. There may be usage cases where a node is being used both as a joint and as a node (say as a node for attaching objects to at runtime). There is no way for the loader to tell if the node is going to be used or not and thus the loader just creates a bone and a mesh and animates both of them. Can't we sure that "mesh" means mesh? At this moment, light nodes are considered as mesh too. It shouldn't be difficult to exclude obvious no-mesh nodes from meshes. In three.js, "mesh", "bone" and other known types are labeled correctly ("Object3D" for unknown), while the hierarchy of nodes is kept. Of course, I can't guarantee for all the gltf file cases, but so far so good. Quote Link to comment Share on other sites More sharing options...
bghgary Posted May 16, 2018 Share Posted May 16, 2018 9 minutes ago, shen said: Can't we sure that "mesh" means mesh? At this moment, light nodes are considered as mesh too. A Babylon mesh behaves like a glTF node. You can easily check to see if a mesh has geometry by calling the appropriate functions. 7 minutes ago, shen said: can't guarantee for all the gltf file cases This is the problem. There is no way to guarantee it works for all cases. Do you have a specific problem that is caused by glTF nodes all being converted to Babylon "mesh"? Quote Link to comment Share on other sites More sharing options...
shen Posted May 16, 2018 Author Share Posted May 16, 2018 27 minutes ago, bghgary said: A Babylon mesh behaves like a glTF node. That's not right. It make all gltf files awful in Babylonjs, that's not better than "working for most cases". I've described the problems it caused with clone, unnecessary targets in animation and etc. above. Quote Link to comment Share on other sites More sharing options...
bghgary Posted May 16, 2018 Share Posted May 16, 2018 20 minutes ago, shen said: It make all gltf files awful in Babylonjs, that's not better than "working for most cases". I'm not sure I follow this. I tried reading through this thread again to see if something would go wrong if these "extra" mesh and animation targets are present and I don't see anything. Maybe I'm missing something? Quote Link to comment Share on other sites More sharing options...
bghgary Posted May 17, 2018 Share Posted May 17, 2018 If it will help, I can add a flag to the glTF loader to not add Babylon mesh objects for glTF nodes that don't have any geometry. Then, you can choose which behavior you want. Quote Link to comment Share on other sites More sharing options...
shen Posted May 18, 2018 Author Share Posted May 18, 2018 Maybe the loader can provide nodes with meshes, particle, skeletons, and follow "meshes" and other keywords in glTF to fill mesh and bone bins. If certain cases like you mentioned happen, users can check nodes and solve them manually. 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.