Jump to content

Best practice for disposing of resources in custom class?


inteja
 Share

Recommended Posts

If I have a TS class called say MyThing that creates various Meshes, LineMeshes and Textures and adds to the scene, what (if anything) do I need to do to dispose of all the resources these MyThing objects use?

If the MyThing class extends BABYLON.Mesh, calling myThing.dispose() does nothing. If I write a method MyThing.dispose() I am able to dispose of individual Meshes which are each associated with a member, but I'm running into problems pushing LineMeshes onto an array so that I can dispose of those within a loop in my dispose() method.

Hope this makes sense. 

Link to comment
Share on other sites

Found a solution, not sure if it's best practice though. Basically I extended TransformNode, created and parented meshes to it, then dispose() just works.

class MyThing extends BABYLON.TransformNode {

  // ...

  constructor(name, scene) {

    // ...

    let mesh1 = new BABYLON.Mesh('mesh1', scene);
    mesh1.parent = this;

    let mesh2 = new BABYLON.Mesh('mesh2', scene);
    mesh2.parent = this;

    let lines1 = BABYLON.Mesh.CreateLines("lines1", points, scene);
    lines1.parent = this;
  }

}

 

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