Jump to content

Cloning and Serializing Issue


Recommended Posts

This is a followup from a previous post where i was trying to clone a mesh and serialize the scene. http://www.html5gamedevs.com/topic/17024-cloning-an-imported-mesh-serialize-then-open-scene/


It turned out that when i clone and serialize a mesh they seem to attach themselves somehow to each other.


So here i clone a mesh, and move just the clone: http://www.babylonjs-playground.com/#1O8OKN


Works great! the clone moves seperate to the mesh.


Now i serialize the scene and save it to a file. When i load that scene, i can't move just the clone by itself anymore. They appear to be attached. http://www.babylonjs-playground.com/#JQE2O


The two meshes on top of each other, this can be confirmed in the debug layer. Does anyone have any suggestions on how to fix this? how to perhaps separate them? or even what is going on so i can try to understand it?


Currently all i can see is that both cloned meshes have the same ID. But they both have the same ID when i first clone it and it works great. But after i load it not so lucky.


Any ideas?



Link to comment
Share on other sites

Getting closer. It appears to be a serialization issue. When it reloads the meshes, all the meshes from the original object have the clone object equivilant as their parent. 


It is not like this right before serialization. So the issue appears to be in the babylon serializer for clones. I'll report back if i find anything. If anyone has insight to that which can help me please weigh in.



Link to comment
Share on other sites

Ok, it actually came down to how Babylon clones a Mesh.


It copies over the ID of the mesh from the old to the new. Then when it serializes and reloads, it causes the loader to misinterpret the proper parent.


I fixed this by adding:

 if (source) { ...       this.id = name + "." + source.id;     ...}

To babylon.mesh.ts constructor. Now every cloned mesh also gets a cloned unique id, not just a cloned unique name.

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.

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.


  • Recently Browsing   0 members

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