Jump to content

Everything disappears if mesh is cloned and instanced


Stalker
 Share

Recommended Posts

Hi!

 

I'm trying to create various units for different players, each player can have multiple units, all from the same model.

Because materials can't be per instance, only per mesh (WebGL limitation if I know correctly), I create a clone of a model for each player, change the material and afterwards I'm doing instancing from those clones.

 

My problem is, that when I do this everything disappears (first it flickers and completely blank scene afterwards). Everything is visible again if bounding boxes are turned back on, but instances from clones aren't shown, only bounding boxes are at correct locations (attached first image). What am I doing wrong that this happens or is a bug?

 

A minimal example on plunkr: http://plnkr.co/edit/yOaBtmu9NaOQpoULo6pv?p=preview

 

EDIT: Example uses BJS version 2.2, but 2.3 suffers for the same problem.

EDIT2: Added second image that renders exactly the same scene, the only difference is checked option for bounding boxed in debug layer.

post-17157-0-16048900-1448642530_thumb.p

post-17157-0-04625300-1448648009_thumb.j

Link to comment
Share on other sites

Instance checking is per frustum I believe.

And the problem is a little beyond just mesh and instance, because everything (also ground and other completely unrelated things) are missing :(. I attached an image to original post, where exact scene is rendered with bounding boxes on and off. 

Link to comment
Share on other sites

You can use material.clone("newmat") : http://doc.babylonjs.com/classes/2.2/MultiMaterial#clone-name-rarr-multimaterial-classes-2-2-multimaterial-

However, it won't clone all submaterial. Maybe this could be added easily in the engine. I'll think about it.

 

Edit: I added a new parameter in MultiMaterial.clone (waiting for approval). You will be able to use it in the next nightly build.

Basically, you can use it like this: 

myMultiMaterial.clone("newname", true);

This will clone the multimaterial and also clone all of its submaterials.

Link to comment
Share on other sites

  • 9 months later...

Hi and excuse me for necroing an old post, however I seem to be facing a similar issue and the suggested solution seems ineffective for me. Only the last cloned mesh is able to create instances.

Here is a playground demonstrating the issue http://babylonjs-playground.com/#29SZC0#6 (try removing the 3rd instance)

I hope it isn't just my naivety that is the problem :D

Regards Swiftwork

Link to comment
Share on other sites

I jumped the gun a little, It seems as if the mesh loses its multimaterial or uv mapping if makeGeometryUnique() is called. Is this intended? Can it be avoided? I am trying to achieve a "carbon copy" of the original mesh with all preferences intact as sort of a base for future instancing.

Edit:

I don't fully understand what I am doing yet but it seem as if the issue with mulitmaterials can be solved by re-referencing or copying the original model's subMeshes, which appears to be have been lost or removed when makeGeometryUnique() is called.
http://babylonjs-playground.com/#29SZC0#8

Edited by Swiftwork
Solved issue by adding clone.subMeshes = original.subMeshes
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...