frenchtoast747/webgl-obj-loader

cannot load .obj file

melfnt opened this issue · 6 comments

Hi everyone, I'm a noob in 3D graphics. I tried to load the model I attach
bb8.obj.zip
but it doesn't show up. I downloaded the model from http://tf3dm.com, and it seems to work in http://www.meshlabjs.net/

I cloned webgl-obj-loader and checked out in the gh-pages branch. Then I added my model in the models/ directory and makes the window.onload function in webgl.js load "bb8.obj" instead of "suzanne,obj" and the result is... that nothing appear on the pedestal
screen

I looked at the javascript console, and this is what I got:

    non well-formed tunnel_ceiling.obj:1:2
    non well-formed tunnel_walls.obj:1:2
    non well-formed room_walls.obj:1:2
    non well-formed room_ceiling.obj:1:2
    non well-formed room_floor.obj:1:2
    non well-formed room_tunnel_ceiling.obj:1:2
    non well-formed room_tunnel_walls.obj:1:2
    non well-formed room_wall_broken.obj:1:2
    non well-formed room_wall_unbroken.obj:1:2
    non well-formed bb8.obj:1:2
    non well-formed pedestal.obj:1:2
    non well-formed boulder.obj:1:2

A "non well formed" for each .obj files I tried to load (also for those that I didn't changed such as "boulder.obj"). I get the same errors on http://frenchtoast747.github.io/webgl-obj-loader/, but of course I can see suzanne on the pedestal.

I watched into the .obj files, and I saw that there were some missing lines in bb8.obj, that I added:

    o bb8.obj
    g default

but nothing changed.

I also noticed that the lines are in different order from the other files: in "suzanne.obj", there are a lot of lines that starts with "v", then a lot of lines that starts with "vn", then a lot of lines that starts with "f"
in "bb8.obj", there are a lot of lines that starts with "v", then a lot of lines that starts with "vn", then a lot of lines that starts with "vt", then a line that begins with "s" and finally lot of lines that begins with "f" and "s", mixed.
As I said before, I know nothing about the obj format, I can just guess that each line defines a vertex, and in the two files the lines order is different.
I wonder why webgl-obj-loader cannot load my .obj file, or as an alternative, can you please tell me how to reorder the lines in my file to get it loaded?

Thank you in advance,
Lucio

Update: I opened my .obj in Blender, and it shows up correctly. Then I exported it in .obj and I got this:
bb8_exported.obj.zip
Now, I can see the robot but it's too big, I'll resize it in some way.
screen

So why can't webgl-obj-loader load the first .obj I attached?

I'm not sure why the Blender exported OBJ model appears to be doing better than the 3DS Max exported file. The order in which the "v", "vt", and "vn" lines appear doesn't matter as long as they are grouped with their appropriate "f" section. The only thing that appears different between the two files is the the 3DS Max OBJ file contains a lot more material information; this may somehow be affecting the parser.

I will try to take a look at this as soon as I can, but for now at least you have a workaround of loading the OBJ file into Blender and re-exporting.

Ok, thank you.
Here is how the scaled robot .obj is shown in blender
blender
And here is how is shown if loaded by webgl-obj-loader
tunnel
The sphere it is sort of roughly approximated by disjoint triangles, is it normal?
And what about the "non well-formed" errors?

Hmm, I know for sure that I saw faces (f) with more than 3 vertices (usually there were 4). The loader currently only supports a maximum of 4, so maybe there are some faces with more than 4?

There is an issue (#25) to support N-gons, but it hasn't been worked yet.

Try exporting the model in Blender again, but this time select the check box for triangulating the faces. This will force the output to have exactly 3 vertices per face.

I will also have to check out the "non well-formed" errors.

Thanks for reporting this and for all of the detailed information!

Ok, thank you: with triangulated faces it show up perfectly. Now I can use it.
The only remaining problem is load the downloaded .obj, but the blender re-exporting workaround works just fine for now.