.obj import triangulation problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
crazy1k
Posts: 7
Joined: Sat Dec 19, 2015 1:13 pm

.obj import triangulation problem

Post by crazy1k »

Importing it with standart procedure:

Code: Select all

scene::ISceneNode * Import_1 = smgr->addMeshSceneNode(smgr->getMesh("d:\\1_test.obj"));
Compare the results in viewport with original model:
Image
I've highlighted edges with thick red lines.
Wrong triangulation, definitely. Any ideas how to fix that?
Last edited by crazy1k on Sat Dec 26, 2015 9:30 am, edited 2 times in total.
chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: .obj import triangulation problem

Post by chronologicaldot »

o_o Without knowing anything about the object file itself, we can't say anything (and your image isn't loading for me). If the file itself is improperly formatted, irrlicht won't load it "correctly", so that will depend on the exporter of whatever program you've made it with.

You can always check the bugs section to see if there are any current bugs for the .obj importer which may have affected this.

As a workaround, consider opening your mesh with Blender and exporting it as Collada or some other format that Irrlicht can open.
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: .obj import triangulation problem

Post by Cube_ »

image isn't loading for me either. (specifically it returns a 403, you can't view it unless logged in so it won't embed on the forums - nothing I can do about that)
please use a real image hosting service like imgur, tinypic, or similar. Dropbox clearly isn't working too well.
"this is not the bottleneck you are looking for"
crazy1k
Posts: 7
Joined: Sat Dec 19, 2015 1:13 pm

Re: .obj import triangulation problem

Post by crazy1k »

I've uploaded image to imgur and edited first message.
1_test.obj looks like this:

Code: Select all

 
v 1.24151432514 -9.8482503891 -1.21268820763
v 1.21961474419 -9.67453289032 2.21719646454
v -2.84848546982 -9.32577991486 2.21719646454
v -2.89963340759 -9.4932346344 -1.21268820763
v -1.41504085064 -9.82481765747 -1.21268820763
v -1.41717457771 -9.83963298798 1.08316206932
v 0.102934256196 -9.94063186646 1.08316206932
v 0.102779276669 -9.92566490173 -1.21268820763
f 1 2 3 4 5 6 7 8
 
3ds max and Rhinoceros opens this file just fine - result is equal to original, triangulation is fine. But when i load it into irrlicht - result is just square poly with no internal vertexes visible. Some sort of triangulation problem I think. I got same little problems in 3ds max for years, but solution there is to press "Retriangulate" button.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: .obj import triangulation problem

Post by mongoose7 »

I think you must use triangles. You have defined an irregular octahedron. The Irrlicht loader probably created a triangle fan. Anyway, triangulate before exporting.
crazy1k
Posts: 7
Joined: Sat Dec 19, 2015 1:13 pm

Re: .obj import triangulation problem

Post by crazy1k »

Trouble is, that this .obj is generated by my program. Irrlicht fails to import even simplier models, like 4-vertex poly shaped like an end of arrow. Is there a way to solve this using standart procedures of Irrlicht? Or shall I triangulate model (never done this stuff in programming) before writing this .obj file?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: .obj import triangulation problem

Post by hendu »

I agree with mongoose7. Use triangles.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: .obj import triangulation problem

Post by Mel »

Triangulate the model before exporting it, even if you store the models as polygons, and other programs will support it just fine, in Irrlicht the display will fall back to triangles, so it is better to just export triangles.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
crazy1k
Posts: 7
Joined: Sat Dec 19, 2015 1:13 pm

Re: .obj import triangulation problem

Post by crazy1k »

Ok, so now it's a question of right triangulation of irregular poly, dividing one poly into number of triangles. I believe that this is not a problem :)
Thank you folks, I'll try my best.
Kojack
Posts: 67
Joined: Sun Jan 20, 2008 2:39 am

Re: .obj import triangulation problem

Post by Kojack »

If you need a simple algorithm for turning concave polygons into triangles, have a look at Ear Clipping: http://www.geometrictools.com/Documenta ... ipping.pdf

Although be careful searching youtube or google image search for it, you'll get videos/pics of dogs having their ears cropped. :(
chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: .obj import triangulation problem

Post by chronologicaldot »

You can use Blender. The modifiers tab on the right-side panel allows you to add the modifier Triangulate (which, obviously, makes the mesh faces triangles). Just make sure to click "Apply" on the Modifier before exporting the mesh.
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: .obj import triangulation problem

Post by Cube_ »

or you could use edit mode, CTRL+F>quads to tris (or does it say triangulate? I never remember, I use the feature so rarely).
"this is not the bottleneck you are looking for"
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: .obj import triangulation problem

Post by CuteAlien »

Hm, this is an Irrlicht bug. f seems to define a face-outline and we don't handle it like that. It will work if you triangulate it yourself as others mentioned. But I guess wouldn't hurt to have real triangulation in Irrlicht as well. Not sure right now if I have some code for that with a compatible license, might be better to write it from scratch. And not certain if it belongs in meshmanipulator or geometrycreator (or lazy solution and just put it in the obj meshloader ... and in a few years it will be copy-pasted (with subtle errors) all over the place as usual...). Well, I could put it on my todo, but not sure I would get to it this decade, so if anyone else has free weekends - go for it!

edit: Irrlicht's triangulation in that place probably works for all convex polygons. And is faster for those as well than any algorithm triangulating concave polygons can be. So if you can split up your polygons to be convex that should be enough.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply