Stalker Posted November 27, 2015 Share Posted November 27, 2015 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. Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted November 27, 2015 Share Posted November 27, 2015 Does the instance disappear when the mesh is out of the frustrum?(I think the frustrum check is made per mesh and not per instances.) Quote Link to comment Share on other sites More sharing options...
Stalker Posted November 27, 2015 Author Share Posted November 27, 2015 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 27, 2015 Share Posted November 27, 2015 The problem is the fact that you are reusing the material in both clones (running clone doesn't clone the material as well).Here is a working example : http://plnkr.co/edit/ytaLCOSNtECGaHm4UMXY?p=preview Stalker 1 Quote Link to comment Share on other sites More sharing options...
Stalker Posted November 27, 2015 Author Share Posted November 27, 2015 Thanks a lot! I blindly believed that clone clones entire structure.Is there any simple way of creating deep clone for material (including all submaterials)? Or is a loop the way? Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 28, 2015 Share Posted November 28, 2015 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. RaananW, WolfKodi, Stalker and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Stalker Posted November 28, 2015 Author Share Posted November 28, 2015 Instead of waiting I created the build myself and it works ! Thanks a lot! RaananW and Temechon 2 Quote Link to comment Share on other sites More sharing options...
Swiftwork Posted September 14, 2016 Share Posted September 14, 2016 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 Regards Swiftwork Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 14, 2016 Share Posted September 14, 2016 Hello this is because clones are sharing the same geometry (for performance reasons) But in your case you do not want that as you are using instances with clones. so simple fix: http://babylonjs-playground.com/#29SZC0#7 Quote Link to comment Share on other sites More sharing options...
Swiftwork Posted September 14, 2016 Share Posted September 14, 2016 It's always the simple things that get me, thank you for your aid @Deltakosh. Guess this necro will serve as a reference for others that face the same issue in the future! Quote Link to comment Share on other sites More sharing options...
Swiftwork Posted September 14, 2016 Share Posted September 14, 2016 (edited) 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 September 14, 2016 by Swiftwork Solved issue by adding clone.subMeshes = original.subMeshes Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 14, 2016 Share Posted September 14, 2016 yep you found the issue making a mesh unique resets its state 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.