Jump to content

How to dispose meshes of the same Imported model


Recommended Posts

Hi everyone!

I must import multiple meshes (on every click) from the same source with the option to dispose when I click on it, like this:

function import_model_1() {
                BABYLON.SceneLoader.ImportMesh("", "babylon/", "modelA.babylon", scene, function (newMeshes) {
                    var model01 = scene.getMeshByName("name_here"); 
                    model01.actionManager = new BABYLON.ActionManager(scene);
                    model01.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function (evt) {

function import_model_2() {
                BABYLON.SceneLoader.ImportMesh("", "babylon/", "modelA.babylon", scene, function (newMeshes) {
                    var model02 = scene.getMeshByName("name_here"); 
                    model02.actionManager = new BABYLON.ActionManager(scene);
                    model02.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function (evt) {

And this work fine when loading the mesh but when I want to dispose the 2 (or more) models the ".dispose();" function only works one time, but when I change the first line for another model like:

BABYLON.SceneLoader.ImportMesh("", "babylon/", "modelB.babylon", scene, function (newMeshes) {

The ".dispose();" function works perfect.

Anybody knows how can I make it work with the same imported mesh ("modelA.babylon")???

Thank you all.


Link to comment
Share on other sites


You shouldn't import the same model several times.
Here's one way that should work.

// First, we pre-load the model
var baseModel;

BABYLON.SceneLoader.ImportMesh("", "babylon/", "modelA.babylon", scene, function (newMeshes) {

 baseModel = newMeshes[0]; 
 baseModel.isVisible = false;


function import_model() {
     // Clone baseModel.
 var model = baseModel.clone('clone_baseModel');
     // Make Visible
     model.isVisible = true;
     // Set a position, change x y z.
     model.position = new BABYLON.Vector3(x, y, z);
     // Add actionManager
     model.actionManager = new BABYLON.ActionManager(scene);
     model.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function (evt) {


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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...