Error loading obj file

Hello!

It seems that trying to import this .obj file (in babylonjs sandbox), it can’t be read and I can’t understand the error in console. It works fine in other 3d viewers.

The error is the following:
solidParser.ts:212 Uncaught TypeError: Cannot read properties of undefined (reading ‘x’)
at e._unwrapData (solidParser.ts:212:76)
at e.parse (solidParser.ts:745:22)
at e._parseSolid (objFileLoader.ts:242:21)
at e.importMeshAsync (objFileLoader.ts:156:21)
at e.loadAsync (objFileLoader.ts:178:21)
at sceneLoader.ts:1050:26
at f (sceneLoader.ts:571:13)
at o.onload (fileTools.ts:369:9)
aaa.zip (1.1 MB)

Hello! It seems this file is a bit malformed, because it doesn’t have any UV data (which would be lines starting with vt):

But the face data is specified as if there was UV data:

the expected format here would be the f 1//1 2//2 etc...

The other viewers are probably trying to fix this under the hood by assuming that, if you have a face in the f 1/1 2/2... format, but there are no UV coordinates, then the second index refers to the normals instead of the UVs. Should we do the same @sebavan ? We could perform this correction by default, or throw an error in the default case, and pass an option to correct.

3 Likes

That would be the cherry on the cake :cherries: :smile: Though, I think the current behavior is quite expected. No UV, no tex projection == no money, no candy, no cando :crazy_face: :rofl: I actually encountered this before while being careless with my assets and in fine, I’m fine with it the way it is (of course, personal opinion only).

I would suggest to do it only if this happens frequently in some tools creating obj :slight_smile:

@Daniel_Bozzolan where did you get your file from ?

The file comes from a user input for which i’d like to use babylonJs as a viewer.
We have no control over the generation of the file. :slightly_smiling_face:

May be you could have control over the user? I.E. providing some guidelines for import files?
Simple suggestion of course. Don’t mind me :face_with_hand_over_mouth: and meanwhile, have a great day :sunglasses:

Do you have a lot of input files like this from various users ? and could you ask them for the sources ?