c++qtwavefrontqvector

Importing OBJ file in QtCreator


I'm new in using Qt Creator (version 4.10.0, based on Qt 5.13.1). I have taken the customitemgraph example and I would like to replace the existing .obj files with new ones. I have downloaded some free models from the web. Some of these work but others don't.

Here's two exemples.

An extract of the .obj file opened with notepad, which is working

...
vn 0.3531 -0.8627 -0.3620
vn 0.3815 -0.9243 -0.0148
usemtl Default_OBJ
s 1
f 1/1/1 2/2/2 3/3/3 4/4/4
f 2/2/2 5/5/5 6/6/6 3/3/3
f 4/4/4 3/3/3 7/7/7 8/8/8
...

a not working case:

...
vn -0.1013 -0.8959 -0.4325
vn -0.1003 -0.8978 -0.4287
usemtl Body
s 1
f 225536//133387 225537//133388 225544//133389 225543//133390
f 225537//133388 225538//133391 225545//133392 225544//133389
f 225538//133391 225539//133393 225546//133394 225545//133392
f 225539//133393 225540//133395 225547//133396 225546//133394
...

When it doesn't work the error message is:

tot 4ASSERT failure in QVector<T>::operator[]: "index out of range", file c:\Users\qt\work\install\include/QtCore/qvector.h, line 448

What I've tried

I have opened the .obj files with notepad and seen that in the working cases there is only one / character separating numbers, and in the not working cases there are // two slashes with no numbers in between. After substituting the double slashes with a single one nothing changes, the problem keeps showing.

I've tried some simple .obj files taken from here to diagnose the problem further but none of these examples works.

Am I missing something? Is there a way around this? Another way to use my .obj files inside this example? Thanks for the help.


Solution

  • I would suggest you to use QMesh from the Qt 3D module to render complex 3D files. Here you can find an example on how to use this class with .stl files but, if you dig through the documentation, you can find the parts where it uses .obj files.