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!
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 :
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?
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.
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?
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.
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.
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.
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.
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.
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.
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.
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.
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).
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...