dadiaar Posted July 20, 2016 Share Posted July 20, 2016 So in my scene I have several meshes I want to export exactly as they are. My idea was to clone all of them, baking using bakeCurrentTransformIntoVertices() and later Serialize them The problem I'm facing is that when I apply bake function to the clones, originals are affected: No baking clone: http://www.babylonjs-playground.com/#3FDSO#0 Baking: http://www.babylonjs-playground.com/#3FDSO#1 Am I missing a parameter? Is there any other way to achieve the same effect? Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 20, 2016 Share Posted July 20, 2016 When cloning a mesh you are using the same vertices to render the mesh. So when you bake the transformation to the vertices, you actually bake it to ALL objects that are using these vertex-buffers (or - all clones of the one single mesh). So tip 1 - don't clone and bake To do that you will have to duplicate the geometry, but then you lose all of the benefits of cloning. You can always "reset" the transformation of the other mesh (just reverse the transformation), but this is not a scalable solution. Quote Link to comment Share on other sites More sharing options...
dadiaar Posted July 20, 2016 Author Share Posted July 20, 2016 Yes, I solved it manually by reversing the transformations as you say, thanks. I just hope there is a cleaner way. What I can't through out my head yet is that baking affects them differently, It doesn't matter if they are cloning by value or reference (sharing resources), if both are affected, they may be affected the same way: I made another example removing everything except both spheres. The original red one with position.y += 1. If no baking, you will see only the blue one because they are overlapping: http://www.babylonjs-playground.com/#3FDSO#2 Baking the clone, only the original one is affected, moving to y+1: http://www.babylonjs-playground.com/#3FDSO#3 I understand why this happens now, but is this the expected behavoir? Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 24, 2016 Share Posted July 24, 2016 More than expected! This is the right behavior. Here is a "fix" for the baked sphere - http://www.babylonjs-playground.com/#3FDSO#4 You are moving one sphere up, then cloning another from it. Now both have the same position (y = 0). Then you bake the transformation to the 2nd sphere, which shares the geometry with the first one. which means that BOTH will be changed. To the transformation of the 2nd is baked to the 1st as well. To bring it back to "original" position, reset the transformation of the 1st. I have to say - baking transformation to cloned meshes will only cause you major problems following the reversed transformation. It seems very redundant. Why keeping reversed transformation, if you can actually have the "forward" transformation and not bake anything anywhere? 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.