Export meshes to object file

Hello, I would like export this meshes from my cars constructor method to an obj-file.

image

I used this command to convert the meshes:
console.log(BABYLON.OBJExport.OBJ(meshes));

and copied the console output to this file:

constructor_car_1.zip (51.1 KB)

but when I use the https://sandbox.babylonjs.com/ I get only this:

image

Can someone give me a hand to guide me thru the darkness to light please?

Hi. As usually, we need a pg :slight_smile:

Hi MarianG, thank you for your help.

Here is the same problem.

https://www.babylonjs-playground.com/debug#M5FP9H

I have meshes with parents (hinges) which I try to export as an obj-file.

First I exported only the meshes (without parent),
then with parents… but … no.

If I export a single sphere all is fine. positive test successfull.

Open the console and click on “Copy” to get the output of OBJExport.OBJ() and copy it into a file. use that file on the sandbox. you’ll see only one cube!
image

Well this seem to be a bug!

I’ve decimated the problem to the essential.

var hinge = BABYLON.MeshBuilder.CreateBox(“turtle”, {
width: 1, height: 1, depth: 1}, scene);

        var mesh = BABYLON.MeshBuilder.CreateBox("turtle", {
                width: 10, height: 20, depth: 30}, scene);
            
        mesh.parent = hinge;            
        mesh.position.y += 10 /2;
        mesh.position.z += 10 /2;
        mesh.rotation.y = Math.PI / 2;                
        
        
        meshes.push(hinge);
        meshes.push(mesh);
        
        // export mesh to obj!
        console.log(BABYLON.OBJExport.OBJ(meshes));

The object file should show the hinge and the box as here shown:
image

but it doesn’t!

The inspector shows in the the x-ray-mode the hinge in the box:
image

How can I work arround this problem? Is there a simple function to set the parent to null with still keeping the current position of the child-mesh?

When I export my little example with the scene saver
https://doc.babylonjs.com/resources/save_babylon

Example:
https://www.babylonjs-playground.com/#1AGCWP#1

then I receive this message on uploading to the sandbox:
image

Hmm…I was able to export that playground and load into sandbox without issue :thinking:

Do you mean the example link above? That works! It has no parent-child-relations.

Hi. Ok, I think I got the issue,… I had the same issue few time ago. And the issue is related to names. When you create the boxes, try to name them consecutive, like turtle1, turtle2 and so one, because when you export the scene as obj or babylon all the parent-child relationships are broke, and because of this is the error with maximum call stack. Is like an infinite loop. Hope this will help.

Yep, this was :
https://www.babylonjs-playground.com/debug#M5FP9H#2
Cheers!:beers:

2 Likes

Thank you brother!

I can sleep peacefully tonight… but… I am so excited when new ideas stream thru my spirit if things run smooth! :smiley:

3 Likes

Thanks for the insight @MarianG!