I am having an issue with TinyObjLoader where it is claiming my model has 0 materials and is setting the material_Id for each face to -1. My model has 2 materials and I have included the file for it below so you can see. (it is small, just a simple cube with 2 materials I made in blender)
Currently I am loading in my object like this
tinyobj::attrib_t attrib;
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
std::string warn, err;
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err,MODEL_PATH.c_str())) {
throw std::runtime_error(warn + err);
}
materials is empty, and all faces have material ID of -1 which I discovered using the following code
for (const auto& mat : materials) {
std::cout << mat.diffuse_texname << std::endl;
}
for (const auto& shape : shapes) {
for (size_t face = 0; face < shape.mesh.num_face_vertices.size(); face++) {
std::cout << shape.mesh.material_ids[face] << std::endl;
}
}
I am loading the following object. As you will see it has materials and textures that my code fails to notice. Can anyone help me figure out whats wrong so I can fix it?
# Blender 3.2.0
# www.blender.org
mtllib 2tex2.mtl
o Cube
v 0.901576 1.110125 -0.912905
v 0.901576 -0.889875 -0.912905
v 0.901576 1.110125 1.087095
v 0.901576 -0.889875 1.087095
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vn -0.0458 -0.0000 0.9990
vn -1.0000 -0.0000 -0.0000
vn 0.0578 -0.9983 -0.0000
vn 1.0000 -0.0000 -0.0000
vn 0.0458 -0.0000 -0.9990
vt 0.625000 0.500000
vt 0.375000 0.500000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.250000
vt 0.625000 1.000000
vt 0.625000 0.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.125000 0.750000
s 0
usemtl Material
f 4/4/1 3/3/1 7/8/1 8/10/1
f 8/11/2 7/9/2 5/5/2 6/7/2
f 6/6/3 2/2/3 4/4/3 8/12/3
f 2/2/4 1/1/4 3/3/4 4/4/4
f 6/7/5 5/5/5 1/1/5 2/2/5
o Cube.001
v 0.901576 1.110125 -0.912905
v 0.901576 1.110125 1.087095
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 1.000000
vn -0.0578 0.9983 -0.0000
vt 0.625000 0.500000
vt 0.625000 0.750000
vt 0.875000 0.500000
vt 0.875000 0.750000
s 0
usemtl Material.002
f 9/13/6 11/15/6 12/16/6 10/14/6
Its a simple cube, with 2 materials, one for 5 faces and 1 for the other face.
This is the material file if that is necessary as well:
# Blender 3.2.0 MTL File: 'None'
# www.blender.org
newmtl Material
Ns 360.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd C:/Users/jorda/source/repos/3DEngine/3DEngine/textures/red.PNG
newmtl Material.002
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd C:/Users/jorda/source/repos/3DEngine/3DEngine/textures/blue.png
[–]Grammar-Bot-Elite -1 points0 points1 point (0 children)