Jump to content

Recommended way to import a OBJ/STL to an existing scene?


Recommended Posts

Hi Folks,

What is the recommended way to import the content of an OBJ/STL into an existing scene? I need the meshes and the materials as well. Below are the three ways I found in the official tutorials.

I think that the first one cannot be used in my case as it creates a new scene.  

So besides the first one, what is the difference between the second one and third one? Can they import the associated materials as well?

BABYLON.SceneLoader.Load("/assets/", "batman.obj", engine, function (newScene) { 
   // ...
var loader = new BABYLON.AssetsManager(scene);
var batman = loader.addMeshTask("batman", "", "assets/", "batman.obj");
BABYLON.SceneLoader.ImportMesh("batmanface", "batman.obj", scene, function (meshes) { 
   // ...
Link to comment
Share on other sites

I would say it depends on how you want them loaded.  The AssetManager can be used to, for example, have a splash screen that shows the assets load progress before starting your scene you can be sure that you have all your assets.  It has an onFinished event you can handle (https://doc.babylonjs.com/classes/3.1/assetsmanager#onfinish-tasks-iassettask-gt-void).

The SceneLoader.ImportMesh (https://doc.babylonjs.com/classes/3.1/sceneloader#static-importmesh-meshnames-rooturl-scenefilename-scene-onsuccess-onprogress-onerror-rarr-void) has also a progress method, but I would say it's more useful dynamically.

If you have materials on your obj, then you will see the material files being loaded asynchronously.  Watch for timing issues on materials.

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