Jump to content

Export mesh to OBJ


Myjestic
 Share

Recommended Posts

Hi,

I have generated a mesh with more than 16k vertices and I want to import it  to meshlab to simplify it.

Now my first problem is, I need the mesh as OBJ File.

I found a link to the babylon asset convert tool, but the link does not work anymore.

Second attempt was to export the mesh as OBJ from my scene and I found the "babylon.objSerializer.js".

I don't know how to use it.

 

I included the js file after including my babylon.js file and the class is available know.

Here is my code so far:

var serializedScene = BABYLON.OBJ(maze);
download_to_OBJ("maze.obj",serializedScene);

function download_to_OBJ(filename, text) {
    var pom = document.createElement('a');
    pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    pom.setAttribute('download', filename);

    if (document.createEvent) {
        var event = document.createEvent('MouseEvents');
        event.initEvent('click', true, true);
        pom.dispatchEvent(event);
    }
    else {
        pom.click();
    }
}

 

Link to comment
Share on other sites

The OBJ serializer provides two static methods:

BABYLON.OBJExport.OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean)

and

BABYLON.OBJExport.MTL(mesh: Mesh)

Both returning a string (technically the content of your .obj and .mtl file).  So calling those functions, you will get two strings. you can console.log them, you can copy them (if it is a one-time thing) or download them (for example - https://stackoverflow.com/questions/21893463/javascript-to-download-string )

Link to comment
Share on other sites

Hi,

we don't include the obj exporter in the playground, and you pasted the code after the return, so this will anyhow never work.

Please check the signature I pasted - the first variable is an array of meshes. so in your case it would be:

BABYLON.OBJExport.OBJ([mymesh]);

the rest of the variables are optional and not needed.

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