Abdullah Posted March 30, 2017 Share Posted March 30, 2017 How to dispose a material on run time and dynamically create again. I want when my sphere material collide with floor material my sphere material should dispose completely and I want to create a new sphere material again. @Deltakosh @Wingnut @Dad72 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 30, 2017 Share Posted March 30, 2017 To dispose a mesh sphere.dispose(); For create sphere var sphere = BABYLON.Mesh.CreateSphere("sphere", 16, 2, scene); Use sphere.intersectsMesh(ground, false) for to detect the collision with the ground Exemple : var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene); var sphere = BABYLON.Mesh.CreateSphere("sphere", 16, 2, scene); if(sphere.intersectsMesh(ground, false)) { sphere.dispose(); // dispose sphere sphere = BABYLON.Mesh.CreateSphere("sphere", 16, 2, scene);// create again sphere } Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 30, 2017 Share Posted March 30, 2017 Yep, well said, @Dad72. And for materials, there is also a dispose(). But I THINK (speculate)... that if you create a replacement material, and then set mesh.material = replacementMaterial... that will replace the previous material. Then, I think the JS garbage collection (GC) system... will dispose the old material for you. (Clear ALL variables and properties of "references-to" the old material... when you are finished using it.) Not sure about the GC situation, though. Test/read to verify. Hope this helps. Quote Link to comment Share on other sites More sharing options...
adam Posted March 30, 2017 Share Posted March 30, 2017 If possible, it would be more efficient to hide the sphere material and reuse it. Quote Link to comment Share on other sites More sharing options...
Raggar Posted March 30, 2017 Share Posted March 30, 2017 I think there is a difference between the title and the content of the thread. I think he means only the material, although the title says otherwise. So in @Dad72's example, instead of creating a new sphere, create a new material and either dispose the old one, or let the GC do the job (Something I have absolutely No knowledge of). Would saying oldmaterial = ""; be enough, assuming you don't have other references to the material? Wingnut 1 Quote Link to comment Share on other sites More sharing options...
BangTao Posted March 30, 2017 Share Posted March 30, 2017 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 30, 2017 Share Posted March 30, 2017 Pretty! Good grinding code... yet tootie frootie. heh Yeah, @Abdullah, did you mean "mesh" like in the thread title, or "material" like in the post? Can you fix one of them... for us? thx! Quote Link to comment Share on other sites More sharing options...
Abdullah Posted March 30, 2017 Author Share Posted March 30, 2017 Thank you all for replying, My bad I meant "material", I want to dynamically dispose material and re create it whenever i detect collision Quote if(sphere.intersectsMesh(ground, false) 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.