Jump to content

How to Completely Dispose a mesh on collision detection?


Abdullah
 Share

Recommended Posts

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
}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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...