hit2501 Posted February 11, 2017 Share Posted February 11, 2017 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) { model01.dispose(); })); }); } 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) { model02.dispose(); })); }); } 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. Quote Link to comment Share on other sites More sharing options...
dbawel Posted February 12, 2017 Share Posted February 12, 2017 You're pushing multiple meshes into the same array. Look at function (newMeshes) in the code, and it is the same array. The way to solve this is to append the array or to create a different array to push the hierarchy into. DB Quote Link to comment Share on other sites More sharing options...
hit2501 Posted February 12, 2017 Author Share Posted February 12, 2017 Thank you dbawel, would you kindly show me a example?, sorry but I am still a noob working with babylon and my level of JavaScript os still basic. Once again thank you very much Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted February 12, 2017 Share Posted February 12, 2017 @hit2501 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) { model.dispose(); })); } hit2501 1 Quote Link to comment Share on other sites More sharing options...
hit2501 Posted February 12, 2017 Author Share Posted February 12, 2017 Thank you aWeirdo, "newMeshes[0]" works perfect. I must import and then dispose (according to the user) instead cloning because this must work with more than 20 medium-high detailed models and I think pre-loading could eat resources. Regards. 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.