The problem of loading obj file by Babylon?

Why is the position of the model bulge in blender and Babylon different? As shown in the figure, how can I solve this problem? The precondition is that I need to use obj file?

(babylon)
(blender)

Would be great if you could share a repro of it so the community could dig into it ?

You’re right, testing with 2.81 by exporting using default settings, it’s flipped. I can’t succeed to setup right axys export settings.

Blender:

20191218-15h03m13s-Blender C__Users_AXEON_Desktop_tmp_untitled.blend
20191218-15h01m13s-Blender File View

Sandbox:

20191218-15h03m09s-Babylon.js - untitled.obj - Firefox Nightly

untitled.zip (133.1 KB)

@Drigax, any clues ???

Offhand, i’d guess it’s our old pal the coordinate system transform mucking up our geometry on import. @Vinc3r are there any differences if you use a left or right handed system in babylon before importing?

I have a few things I need to handle today, but I’ll try to take a closer look at this if I have some extra time.

2 Likes

I recall we had the same kind of problem in a post some days ago, and it ended up to set the scene to be right handed before loading.

[EDIT] Well, it was for GTLF, so not sure if that applies… [/EDIT]

Using these export options I got the correct orientation when exporting:
image

3 Likes

I did, but the problem didn’t get solved

Could you share your .blend file so someone can have a look at it?

This is weird. I am working on a project for the company, and they recently asked why do their models show up mirrored in the viewer. I believe that the format of the file used in the viewer was also OBJ. And I think that file is exported from SolidWorks.

scene.useRightHandedSystem(That’s the answer)

scene.useRightHandedSystem(That’s the answer)

In my test scene when I use rightHand it flips my normals :smiley: (but the model is alright)

image

Note that after setting sideOrientation it’s fine:

scene.materials.forEach(function(mtl){
    mtl.sideOrientation = BABYLON.Material.ClockWiseSideOrientation;
});

image

3 Likes

Unlike glTF, OBJ doesn’t specify what winding order to use for triangles, so the OBJ loader just picks one. Same goes for coordinate system. Perhaps we should add a flag to OBJ load options?

So does this mean it’s unpredictable which one?

Effectively yes. This is one of the reasons why glTF exists.

I think .obj is right handed.
https://www.google.com/search?q=obj+file+right+handed&oq=obj+file+right+handed&aqs=chrome..69i57.11759j1j7&sourceid=chrome&ie=UTF-8

Per wikipedia “Vertices are stored in a counter-clockwise order by default”

Sorry and thanks, my understanding maybe is not accurate. I try to be accurate, but looks like I am not here. I’ve searched for obj specification many times and never found anything concrete. The quote from Wikipedia is the most vague to me. What does “by default” mean?

Sounds like either Blender is outputting something wrong or Babylon OBJ loader is wrong here?

1 Like

I was loading an OBJ file into Babylon and it was turning up mirrored.
The file loads ok in Blender but then Blender is right handed.
Maybe the Babylon OBJ loader needs fixing?
See attached file.
Try loading this in https://sandbox.babylonjs.com/
OBJ.zip (3.2 KB)

Yeah but what by default means? Does that mean it could be stored differently. The point is that some objs load correctly (because they are stored as LH) and some don’t

We have options to force OBJLoader to change its default behavior: https://doc.babylonjs.com/how_to/obj

My question is: can we detect which feature to turn on/off?