createMeshWelded

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

createMeshWelded

Post by asparagusx »

Hallo

I have been trying to use the function createMeshWelded to create a mesh with all duplicate vertices removed. At closer inspection, except in unusual cases, I do not believe that this function will actually remove ANY vertices. In the code the following test is done :

Code: Select all

					if ( v[i].Pos.equals( v[j].Pos, tolerance) &&
						 v[i].Normal.equals( v[j].Normal, tolerance) &&
						 v[i].TCoords.equals( v[j].TCoords ) &&
						(v[i].Color == v[j].Color) )
to establish if a vertex is a duplicate. In almost all cases, normals of vertices will point in different directions, texture coordinates are going to different in most case etc. Am I correct in my understanding of what this function is supposed to do e.g. build a mesh with duplicate vertices removed or has this function some other purpose?

Anton
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

well if the normals are different then you may not want to weld the vertices because then that would screw up lighting for the mesh as the normals are different for a reason.

maybe the function should have a bool parameter which allows you to ignore the normals if you wish to do so.
Image Image Image
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

The problem that I have is that I am importing (lets say) .3DS models into my application. This is coming in as a set of IMesh buffers, which is basically just a set of triangles, which of course duplicates a number of vertices. As an example, I loaded a model , which had 47000 vertices in it. In actual fact, the number of unique vertices are only about 7000. What I am trying to do is :

a) Reduce the number of duplicate vertices
b) Smooth the model, by sharing vertex normals

As it stands, I will need to introduce some kind of flag as you suggested - do you think this should go into the SVN trunk?

Anton
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Well you could do this all in a modelling program rather than in irrlicht i should think. Unless your project is some kind of model editor of course.

But the irrlicht functions should also work as good as a modeller i think so if they can be updated they should.

If you can patch irrlicht to add this functionality then you can always submit the patch for inclusion into the engine and the devs will decide whether it's a good idea or not.
Image Image Image
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

My app is a CAD modeller and I use Irrlicht to import external models e.g. .3DS files. I do have functionality to weld a mesh within the application, but what I was trying to do was to import the mesh (as a 'welded' mesh), which reduces overhead significantly. I will have a look at adding the required functionality to createMeshWelded.

Anton
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

We could take an average of the normals, but which texture coords and colour do you propose using?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

I basically do not think that the CreateMeshWeld function will do what I am expecting. I was trying to use Irrlicht to generated a mesh, which only consisted of unique vertices, but I think I will need to use my own routines for that. I have my own DCEL Mesh structure and texture and normals are stored elsewhere. It might overall be useful to modify CreateMeshWelded to only check for vertex position rather than all the vertex components (as an option). Looking at the code in more detail, there are certainly some optimisations needed as well.

Thanks

Anton
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

asparagusx wrote:I basically do not think that the CreateMeshWeld function will do what I am expecting.
We can make it do what you're expecting, if you let us know what you expect regarding choosing a normal, texture co-ordinates and colour for the single vertex. ;)

asparagusx wrote:Looking at the code in more detail, there are certainly some optimisations needed as well.
Super, patches are always welcome.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

This function works well with meshes from the X loader which create duplicated vertices, for example earth.x and our old friend Mr Dwarf. The problem you're seeing with 3DS (and possibly other) meshes is that iirc the smoothing groups are ignored, so you're stuck with face normals which is rather ugly.

When I originally added this function Travis recommended we rename it to something to do with removing duplicated vertices rather than claiming that we weld the mesh, which I admit it doesn't do.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

bitplane wrote:our old friend Mr Dwarf.
I'm pretty sure dwarf.x is a chick. You need to check for the Adam's apple. Boy, did I learn that one the hard way.

bitplane wrote:When I originally added this function Travis recommended we rename it to something to do with removing duplicated vertices rather than claiming that we weld the mesh, which I admit it doesn't do.
Change it for 1.5 or punt to 2.0?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I don't see the need for a rename, because this method is also called 'weld' in other engines.
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

My original requirement was to simply generate a list of vertices (Position only), which are unique in a mesh. I stumbled upon this function, thinking that it would help me, but I can see the need for this function. It certainly creates a mesh with no duplicates including normals, texture coordinates etc. In my DCEL structure, I want to simply maintain a list of unique vertices in the mesh, with other data structured (half edges) connecting the vertices to provide face information. I do think that 'weld' in the function name is confusing.

Anton
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

hybrid wrote:I don't see the need for a rename, because this method is also called 'weld' in other engines.
asparagusx wrote:I do think that 'weld' in the function name is confusing.
I agree. Vertex welding takes normals and texture coordinates into account when joining vertices. Vertices are joined if the position and texture coordinates are close. The vertex normals, position and tcoords are all averaged. I'm not sure what should happen to the vertex color, but it is probably averaged also.

This function just removes 'duplicate' vertices. Duplicate vertices have the same color and tcoords, and the normal needs and position need to be similar.

The engine should probably provide both methods as there are scenerios when one behavior is perferred over the other.

Travis
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Here is a point in case. This .3DS model, contains (if memory serves correct) approx 47000 vertices, however the actual number of unique vertices are approx 7000 (simply imported as a series of triangles). What I was trying to do (in this cases I am not worried about texture coordinates etc.) was to import the model using getMesh and then converting it to a 'simplified' mesh using createMeshWelded and I can then use the model further in my app (and texture and colour it if needed). I do not believe createMeshWelded removed any vertices (as per discussion above).

http://www.cad-essence.com/genes1s/beercan.3ds

Anton
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I'm not against another version of the weld function which takes more parameters and acts e.g. as proposed by vitek. So maybe add two more epsilon values and a boolean to enable interpolation of values or not. Patches are welcome.
BTW: The 3ds might still not look as expected after a different welding process, maybe simply try another format instead...
Post Reply