Jump to content

Loading obj file


Tomm Huth
 Share

Recommended Posts

I'm trying to load a simple obj file exported from Blender, but I'm having a hard time and the docs aren't really helping. I've tried

SceneLoader.ImportMesh(["rock1"], "./","rock1.obj", scene, function (meshes) {
console.log(meshes)
});

But what are the params supposed to be here? I have one single file named "rock1.obj" located at root "/". But then Babylonjs tries to get this:

 GET http://localhost:3000/rock1.obj.manifest?1540314526858  
 GET http://localhost:3000/rock1.mtl 

Even when 

SceneLoader.IsPluginForExtensionAvailable(".obj")

return true. I dont want to automatically add the mesh just get it and store it for future use. 

Also am I forced to load scenes for every object? 

The same thing happens when I use

let loader = new AssetsManager(scene);
loader.useDefaultLoadingScreen = false; // Set to false to remove the default loading
let mesh_loaded_task = loader.addMeshTask("s", "rock1.obj", "/", "rock1.obj");
 
mesh_loaded_task.onSuccess = function (task) {
task.loadedMeshes.forEach(function(m) {
console.log("Loaded!");
m.position = BABYLON.Vector3.Zero();
});
};
mesh_loaded_task.onError = console.error
 
loader.load()

But what is the last parameter of addMeshTask supposed to be -- sceneFilename??

 

Link to comment
Share on other sites

You can use the asset container to load a mesh without it being added to the scene by default.

http://playground.babylonjs.com/#L6IE5L#1

I obj's can have a manifest and mtl file associated with them so the obj plugin will look for those and if it doesn't find them it should still load the obj.

You shouldn't need to create a new scene for every object but you should have at least one scene.

Link to comment
Share on other sites

@trevordev see my last edit. 

Babylon never hits my rock1.obj file at all, and fails with the following error

"Unable to import meshes from ./: importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse" SyntaxError: Unexpected token < in JSON at position 0

Link to comment
Share on other sites

Seems like there is a bug here with 

SceneLoader.LoadAssetContainerAsync

The promise never resolves, but somehow the mesh is added to my scene (I haven't even passed   thru my scene anywhere, so don't know how it knows that). It also complains alot about not finding the mtl file

 

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