Jump to content

Baking clone is affecting the original


dadiaar
 Share

Recommended Posts

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:

Am I missing a parameter? Is there any other way to achieve the same effect?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

I understand why this happens now, but is this the expected behavoir?

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...