calculating clean normals in meshes with duplicate vertices

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
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

calculating clean normals in meshes with duplicate vertices

Post by zillion42 »

Hi,

well, basically, can it be done ? I spent a good part of the day finding a method to remove duplicate vertices faster than

Code: Select all

->getMeshManipulator()->createMeshWelded
which seems pretty O(n²) brute force to me, but I guess there is no other way...

The problem is that for a terrain kind of mesh basically the method

Code: Select all

for (u32 i=0; i<currentIndices->size(); i+=3) 
		{
			u32 index1 = currentIndices->operator[](i+0);
			u32 index2 = currentIndices->operator[](i+1);
			u32 index3 = currentIndices->operator[](i+2);

			const core::vector3df normal = core::plane3d<f32>(currentVertices->operator[](index1).Pos,
															  currentVertices->operator[](index2).Pos,
															  currentVertices->operator[](index3).Pos).Normal;
			
			currentVertices->operator[](index1).Normal += normal;
			currentVertices->operator[](index2).Normal += normal; 
			currentVertices->operator[](index3).Normal += normal;
		}
would work just fine, if triangles would share vertices. But since that is not the case it can't ever work since most tri's have their own friggin 3 vertices, and the normal vector cant be added together for the unshared planes.
If you turn on debug data normals you can see 2 normals sticking out of each vertice... Maybe I'm just little overworked and tired, but I dont see the light here...

Thx in advance...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Post by hendu »

If brute force fails, add more cores ;) That loop looks like it would parallelize really easily with openmp, so you could get a nice speedup on a quad.
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

:lol: :lol: :lol:
oh god, I divided my icosahedron to level 9, which actually even renders with about 0.2 fps, of course it will never need to render as a whole later, but because it takes so long to generate I thought write it to file...

now I'm waiting for quite some time already and the filesize has just passed 420 MB

going to edit this post and report final size...

But in fact, generating takes considerable less time than writing
and needless to say that welding points in that mesh will never finish...
:lol:
EDIT:
filesize has just exceeded total ram usage with windows... :)
EDIT2:
ok final stat and a good laugh... sorry been definitely working to long
Size on Disk: 1,05 GB (1.137.520.640 bytes)
going to drink some beer now...
EDIT3:
I've spent some time with exporting various small and big :) models now in irrmesh and obj format. To the result that none of the obj's was ever readable by maya and none of the objects in general was readable again by irrlicht... :(

and back to the original question... does anyone know a way to make meshes with duplicate vertices smooth in the sense of properly calculating normals ?
Mikhail9
Posts: 54
Joined: Mon Jun 29, 2009 8:41 am

Post by Mikhail9 »

zillion42 wrote:...because it takes so long to generate I thought write it to file... But in fact, generating takes considerable less time than writing
Been there, learned that. It's always a surprise, but sometimes caching just doesn't help.

You're working a hard problem. Please share the solution if you find one.
Post Reply