ozRocker Posted May 2, 2017 Share Posted May 2, 2017 I'm looking at scene optimisations so I was playing with instances and clones. I'm just wondering, if a clone shares the same vertex data as the object that it cloned, how come the clone still stays on the screen even after deleting the main object? https://www.babylonjs-playground.com/#XE5CHL to demonstrate the point Quote Link to comment Share on other sites More sharing options...
Raggar Posted May 2, 2017 Share Posted May 2, 2017 A clone is an actual mesh with its own data. This data is simply copied from the original mesh, and recreated into a new, cloned, mesh. An instance is the actual main mesh, where as a clone is an entirely new mesh. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted May 2, 2017 Author Share Posted May 2, 2017 For real? I'm going through Raanan's blog and it says "If all meshes are completely the same, including material, use instances. If the vertex data of the new meshes is the only thing that should be identical to the original mesh, use cloning." and "Cloning a mesh returns a Mesh object that you will be able to manipulate further. The main thing that is cloned here is the geometry - the vertex data of the mesh is reused across all meshes. The material, for example, can be changed." I thought that meant clones will share the same vertex data but separate materials. Quote Link to comment Share on other sites More sharing options...
adam Posted May 2, 2017 Share Posted May 2, 2017 Cloned meshes share geometry. Quote Link to comment Share on other sites More sharing options...
adam Posted May 2, 2017 Share Posted May 2, 2017 3 hours ago, ozRocker said: how come the clone still stays on the screen even after deleting the main object? I think it has to do with this line: https://github.com/BabylonJS/Babylon.js/blob/8e9cc34160fa1b507c1f73e791ed93a131a77378/src/Mesh/babylon.geometry.ts#L374 This is the correct behavior. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted May 2, 2017 Author Share Posted May 2, 2017 3 minutes ago, adam said: I think it has to do with this line: https://github.com/BabylonJS/Babylon.js/blob/8e9cc34160fa1b507c1f73e791ed93a131a77378/src/Mesh/babylon.geometry.ts#L374 I think I get it. That statement checks to see if any other mesh is using that same geometry. If it is, remove the mesh from the list of active meshes but keep the geometry in memory 'cos its still being used Quote Link to comment Share on other sites More sharing options...
Raggar Posted May 2, 2017 Share Posted May 2, 2017 My mistake then 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.