I successfully loaded an OBJ file along with MTL file textures using OBJMTLLoader. The code I used was borrowed from .
The primary object, a man in a business suit with hair, hands, and shoes, is displayed correctly with all the textures applied, such as eyes, mouth, tie, and buttons.
Upon loading, the object is represented as a THREE.Group with 10 children. Each child contains further THREE.Object3D elements with multiple THREE.Mesh objects.
Below is the JavaScript code snippet I used to load the OBJ and MTL files:
//==================================================
function SOW_F_Load_OBJMTL_Model ( givenFilespec, mtlFilespec, givenName, givenScene, givenHexColorStr, posX, posY, posZ, rotX, rotY, rotZ, scaleX, scaleY, scaleZ )
{
THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
var ObjMtl_loader = new THREE.OBJMTLLoader();
ObjMtl_loader.load( givenFilespec, mtlFilespec, SOW_F_make_LoadedOBJ_Handler ( givenName, givenScene, givenHexColorStr, posX, posY, posZ, rotX, rotY, rotZ, scaleX, scaleY, scaleZ ) );
}
}
//=============================================
function SOW_F_make_LoadedOBJMTL_Handler( givenName, givenScene, givenHexColorStr, posX, posY, posZ, rotX, rotY, rotZ, scaleX, scaleY, scaleZ )
{
return function ( object )
{
object.position.set( posX, posY, posZ );
object.rotation.set( rotX, rotY, rotZ );
object.name = givenName;
object.scale.set( scaleX, scaleY, scaleZ );
givenScene.add( object );
object.traverse ( function ( child )
{
if ( child instanceof THREE.Mesh )
{
child.userData.rootObject = object;
//... following are for when material doesn't load
child.geometry.computeFaceNormals();
child.geometry.computeVertexNormals();
child.geometry.normalsNeedUpdate = true;
}
}
)
object.updateMatrix(); //... without this the next command is not effective.
xxx = SOW_F_grob_Add_to_Target_Set( object );
};
}
Despite the successful loading, I encountered a problem with object picking not reporting the correct name of the intersected object when loaded via OBJMTLLoader. It either displays the name of a texture material or nothing at all.
Interestingly, object picking functions as expected on mesh objects that I manually create in my THREE.js code.
I attempted to apply the fixes recommended in Picking Object3D loaded via OBJMTLLoader, such as including the following line in the intersection picking code:
var intersects = ray.intersectObjects( scene.children, true );
and in the object child processing code:
child.userData.rootObject = object;
However, these solutions did not resolve the issue.
If anyone has suggestions on how I can ensure that object picking accurately reports the parent object of an object loaded via OBJMTLLoader, I would greatly appreciate the guidance.