Sandbox: loading obj never ends

OS: Windows 10
GPU: GTX 1050 2GB
Browser: Chrome and Firefox
Ver: Babylon.js v7.19.1
Url: https://sandbox.babylonjs.com/
Expected: Loaded successfully (or tell the user that it’s not supported)

Actual: Loading never ends

Model attached here:
lines_with_vt.zip (235 Bytes)

Your .obj file doesn’t have UVs. That’s why it doesn’t load the file. @sebavan @deltakosh should we support UVless OBJs?

Solution, export the OBJ with UVs:

The console displays an error.

3 Likes

We should (and to be honest I thought we were already:))

2 Likes

Ok, I’ll take care of it.

3 Likes

Love you to the moon and back :wink:

1 Like

We have a bigger issue here with the obj not just the Exception when there are no UVs.

The objLoader is faking lines by setting the mesh’s material wireframe to true.

It works when the obj contains l elements defined by exactly two vertices and the line doesn’t share vertices. This works with wireframe:

l 1 2
l 3 4
l 5 6

3 lines w/o vertex sharing.

However obj suport multiple vertices in the l element. Both examples produces a mesh with shared vertices.

l 1 2 3 4 5 6 1
l 1 2
l 2 3
l 3 4
l 4 5
l 5 6
l 6 1

wireframe is not applicable with these.

I’ll need to create a LineMesh/GreasedLineMesh from the l elements or should we draw the mesh in MATERIAL_LineListDrawMode. Which approach do you prefer guys?

Thanks!

@Deltakosh @sebavan

Probably the latter?

2 Likes

same

I’ll need to add new vertices to the resulting mesh. The number of vertices in the obj will be different as the number of vertices of the mesh on scene
since l 1 2 3 4 will result into

l 1 2
l 2-cloned 3
l 3-cloned 4

Are you OK with this?

No problem!

1 Like

Guys, I decided to choose the easiest way to make lines working.
No material change, no LINES mode rendering for the mesh. These parts remained untouched. So it still uses the wireframe trick to render the lines.

I just preprocess the lines elements from the OBJ. See the description:

Lines and polygons are described in terms of their points, while curves and surfaces are defined with control points and other information depending on the type of curve. The format supports rational and non-rational curves, including those based on Bezier, B-spline, Cardinal (Catmull-Rom splines), and Taylor equations.

Source, OBJ format: https://people.computing.clemson.edu/~dhouse/courses/405/docs/brief-obj-file-format.html

There could be other issues in the future. For example mixing lines and faces in one obj file are not supported. We don’t support curves.

Displays the OP’s OBJ file:

l 1/1 2/2
l 3/3 4/4
l 5/5 6/6 7/7 8/8 5/5

Also, if loading invalid (e.g. truncated) obj, it would still stuck there.

Oh so you want a visual feedback on the screen, like a messsage saying there was an error loading the file.

yeah but that’s not the engine goal :slight_smile:

In case of the sandbox, yes. In case of the api, Promise should be rejected, or onError callback should be called, in case of invalid (or unsupported) obj files

I could agree with that

1 Like

Added error message when trying to load a corrupted OBJ file:

3 Likes

Thanks, that fixes the loading of the file in the main thread, but:

  1. Loading bad obj file will still result in never-ending loading with error only in console.

    bad_obj.zip (225 Bytes)
  2. What about devs using babylon.js? Not all of them can use a global error listener to handle. Since most methods in OBJFileLoader returns Promise, the Promise should be rejected, instead of throwing uncaught errors.

Works for me locally. I’ll check what’s the issue.

I’ll create a PR for this.

1 Like

Interestingly when I load the Sandbox from the PR snapshot:

which registers this handler:

window.onunhandledrejection = (event) => {
    // eslint-disable-next-line no-console
    console.error("Unhandled promise rejection:", event.reason);

    return true;
};

after the page loads
window.onunhandledrejection is null.

Let’s wait for the PR merge and check the result.