As I attempt to upload an OBJ file along with its associated MTL files into a WebGL scene using Three.js, I have encountered a perplexing issue. In my code, I have included global variables to track the loading progress of the OBJ and MTL files. Strangely, despite it being only one set of files, the "obj" variable is of type "Group" and contains two "children". The first child appears to consist solely of vertices, with an empty "faces" array. On the other hand, the second child contains both vertices and faces. Surprisingly, using just the data from the second child (geo[1]) produces the same result as using the entire obj.
This discrepancy raises questions about the underlying logic behind this behavior. Why does a single set of OBJ and MTL files produce an object with two children where one child lacks face information?
This issue is particularly significant for me because I intend to manipulate the vertices and faces to create a voxelized volume, necessitating direct access to the scene objects.
scapula = new THREE.OBJMTLLoader();
scapula.load('obj/scapulaTWO.obj', 'obj/scapulaTWO.mtl', function (object) {
// var material = new THREE.MeshFaceMaterial(materials);
var material = new THREE.MeshLambertMaterial({
color: 0xFFFF66
});
obj = object; //group
object.traverse(function (child) {
if (child instanceof THREE.Mesh) {
console.log(child instanceof THREE.Mesh)
geo[i] = child; //mesh
// apply custom material
child.material = material;
// enable casting shadows
child.castShadow = true;
child.receiveShadow = true;
i = i + 1;
}
});
scene.add(geo[1]);
});