Closed iyenal closed 4 years ago
Hashmap implementation that handles the material IDs is broken, as it firstly work well with like 1500 triangles,
Could you post reproducible .obj(and .mtl) file?
Hi, For sure, you'll find both of them in this archive: https://mega.nz/file/HQslFYrb#SnVobW74RlGAlqWzHeyw4sM6KGGi57KZPkxgiUWcqds The models are exported from Blender, and it happens with the model without materials too. Thanks so much for looking in that :)
I have tested with your .obj, but material_ids works well.
printf("Texture mat ID = %d\n", attrib.material_ids[face_offset + 1])
You should not use face_offset
to access material_ids since material id is provided per-face manner. With address sanitizer, you'll get an out-of-bounds access error.
I have added an comment how to access material_ids
I have checked that solution, but I get weird results. I splitted the vertex buffer on multiple ones for each shape, and each shape have its own material. However inside 1 shape, I could get multiple Material IDs, which shouldn't be possible.
I could get multiple Material IDs
.obj can have multiple material ids(per-face material). If you use tinyobjloader-c for OpenGL/DirectX application, you first need to re-arrange vertex data by iterating material ids.
Got it, thanks. For now so using a workaround to instead to get per-face material IDs, use per-object materials by merging them before-hand. Thanks again.
Hi,
Well firstly I am very grateful to the developers of the C version of Tinyobjloader, and Tinyobjloader itself being a real lifesaver. So I've been experimenting the library for my own usage, and recently started to add materials support to my program. However, it looks like the Hashmap implementation that handles the material IDs is broken, as it firstly work well with like 1500 triangles, but then returns a large random number that doesn't seem correct.
It happened on 2 different models, with relatively low numbers of materials (2 and 6), and so by printing
printf("Texture mat ID = %d\n", attrib.material_ids[face_offset + 1]);
on every triangle, and at some (random) point in a middle of a shape, the material_id starts to behave strangely:I hope this can be fixed, and I would to thank you very much for all what have been already done :)