Jump to content

Importing a mesh into a specified meshes array number


manta1000
 Share

Recommended Posts

Hi all, I am hoping someone on here can help me as I have given up trying to search for the answer.

 

I have a scene with 29 meshes and what I would like to achieve is to import a new mesh from another scene file into one of the already existing mesh locations e.g scene.meshes[0].

 

What I would like to know is, is this possible using ImportMesh and if so how would one achieve this, any help would be much appreciated.

 

Regards

Andy 

Link to comment
Share on other sites

Have you tried

 

BABYLON.SceneLoader.ImportMesh(meshName, rootUrl, sceneFileName, scene, function (meshes, particleSystems, skeletons) {

          scene.meshes[0] = meshes[0];

});

 

If you do not know the index of the mesh you want to replace but know the name you could try

 

scene.getMeshByName(name) = meshes[0];

Link to comment
Share on other sites

Have you tried

 

BABYLON.SceneLoader.ImportMesh(meshName, rootUrl, sceneFileName, scene, function (meshes, particleSystems, skeletons) {

          scene.meshes[0] = meshes[0];

});

 

If you do not know the index of the mesh you want to replace but know the name you could try

 

scene.getMeshByName(name) = meshes[0];

 

Hi Jonhk, thanks for replying. I have tried what you suggested but unfortunately I still have problems, what I am trying to achieve is this. I have developed a website that is selling different types of headboards for beds I have created the models in 3dsmax, there are 6 widths and 3 height to the headboards which are stored in a single babylon.js for each model.

 

When the user selects a different height or width I then want to import the model into the existing scene, but at the mo even after what you suggested the imported mesh gets put to the end of the meshes array and the mesh that was previously displayed does not get removed and is still visible. I have tried to figure this out but had no luck so far.

 

Is there a way I can remove or delete the current mesh before I import the new mesh.

 

Thanks 

Andy

Link to comment
Share on other sites

Hi Manta!  I have given some thought to your situation (oh no!)  :)

 

I would import ALL of the headboards at once, and then set each headboard.setEnabled(false);

 

Give each headboard a unique name.  Then... do not reference scene.meshes or newMeshes[] at all.

 

Instead, use...

 

var headboard = scene.getMeshByName("theheadboardname");

headboard.setEnabled(true);

...

 

(Like John mentioned, but used slightly differently)

 

Now you can turn these headboards on and off easily, and they are all nearby... ready to be displayed, positioned, rotated, scaled, etc... without needing any ongoing mesh loading.  You load them once, you load them all, and you set the extra ones disabled so they are not wasting performance. 

 

There is also a scene.getMeshById and numerous other type of scene.gets.  Of unique interest... is scene.getMeshesByTags ... our tags system is very powerful and has some excellent pattern-matching/regexp/wildcard searching features... but that might be overkill for you, Manta.

 

An interesting challenge for an interesting project, M.  Pretty cool!

 

Generally, you'll be using one variable LOTS:   

 

var theMeshThatImAdjusting = ??

 

Don't set it with scene.meshes[0] or newMeshes[0] or anything like that.  TRY to ALWAYS use... 

 

var theMeshThatImAdjusting = scene.getMeshByXXXXX("wantedmeshname"); 

 

Use your theMeshThatImAdjusting.setEnabled() to turn it on/off... as wanted, so no need to mesh.dispose().  The buyer might want to see ALL the headboards.... side by side... comparing... and you have all the headboards standing-by, ready to do that for the buyer.  Having all the headboards already imported... lets you do many more kinds of "store window displays" too, right?  Showrooms.  :)  Maybe your headboards dance with each other when nobody is watching.  :) 

 

Ok, maybe not that.

 

Good luck... keep us posted (but not bed posted).  ;)

Link to comment
Share on other sites

Hi again Johnx, Thanks again for replying and thanks for your help, I have found a way of doing what I wanted, there is probability a better way of doing this but this seems to work fine for me:

 

The line before  scene.meshes[0] = meshes[0]; I put the line scene.meshes[0].visibility = 0; and that seemed to do the trick, so I will mark this as answered.

 

Thanks again

Andy

Link to comment
Share on other sites

Actually Wingnut's solution is better and is one I am using in my project. Perhaps I should have thought through the problem rather than trying to just directly answer the question asked and giving a solution that really isn't one. I'd be very happy for you to swap the best answer to Wingnut's as it really is the better one. Also it seems that setting scene.meshes[0] to meshes[0] hasn't achieved anything that just setting scene.meshes[0].visibility =0 and importing your mesh wouldn't have achieved.

They say a little knowledge is a dangerous thing and I think in this case I have lead you up the wrong street.

scene.mesh[0].visibility = 0 means that the mesh is not seen but calculations are still applied to it during each rendering of the scene.

doing headboard.setEnabled(false) means that the mesh is not seen and no calculations are applied during the rendering.

Link to comment
Share on other sites

Thanks for both of your answers and I do see that wingnuts answer is probably the best way to go, it just means I will have to re-program some things to accommodate it but that shouldn't be a problem lol, so as you suggested JohnK i shall put wingnuts answer as solved, once I have finished the wedsite I shall post a link on here then maybe get peoples feedback which is always a good thing.

 

Regards

Andy  

Link to comment
Share on other sites

JohnK, you're just the coolest. What great graciousness and humility!  Definitely the sign of a class act.  Pretty cool.

 

Credits for solutions aren't important, are they?  What's important... is Manta... having some ideas/techniques to test and play-with, so his/her BJS project can keep moving.   Mission accomplished, I suspect.  :)

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