PDA

View Full Version : Ways around loading libraries like ASSIMP that doesn't support geometric instancing?



tmason
10-14-2014, 02:42 AM
Hello,

So I use ASSIMP for loading in geometry and all works great; however ASSIMP doesn't support geometric instancing. So if a scene has ten chairs, for example, they all come across with their own mesh data, etc.

Obviously a big pain and a huge drain on resources.

Has anyone come up with a way around this for loading libraries like ASSIMP? Is there an easy comparison I could do? I am intermediate with OpenGL so if explained I can try my best to implement whatever technique/etc. suggested.

Thank you for your time.

carsten neumann
10-14-2014, 03:57 AM
I'm not terribly familiar with assimp, but looking at their data structures, aiScene (http://assimp.sourceforge.net/lib_html/structai_scene.html) has a list of aiMesh objects that the aiNodes (http://assimp.sourceforge.net/lib_html/structai_node.html) refer to, so that means the mesh data needs to be stored only once. What is your source format? My suspicion would be that the source format does duplicate the mesh data and assimp simply does not attempt to undo that.

To eliminate the duplicate mesh data yourself you need to be able to compare two meshes for equality. Unless you want to also catch "exotic cases" like two meshes having the same positions but stored in a different order, or even having the same triangles stored in a different order, you can just go through the attributes of the mesh and check if those are the same. In theory that can be expensive because you could have two meshes with a million points each that only differ in the position of the last point, but for most it should be fairly quick to conclude that they are different.

If you expect to have a large number of (big) identical meshes you could first compute a hash value for each mesh to find candidates that are likely the same (i.e. those with the same hash value):
- compute a hash value over all attributes of a each mesh
- for meshes with the same hash value check if they indeed are the same (and it is not just a hash collision), i.e. compare all their attributes
- keep only one copy of the duplicate meshes and replace all uses of the others with the canonical copy