Need to render .obj + mtl 3d asset from zip archive. I’m using as examples examples/models/obj/male02 (obj + mtl + jpeg) and my example obj + mtl only
My loader setup looks like:
const objFile = Object.keys(zip.files).find(fileName => fileName.endsWith('.obj'));
const mtlFile = Object.keys(zip.files).find(fileName => fileName.endsWith('.mtl'));
if (objFile && mtlFile) {
const mtlContent = await zip.file(mtlFile).async('string');
const manager = new THREE.LoadingManager();
manager.onStart = function ( url, itemsLoaded, itemsTotal ) {
console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
};
manager.onLoad = function ( ) {
console.log( 'Loading complete!');
};
manager.onProgress = function ( url, itemsLoaded, itemsTotal ) {
console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
};
manager.onError = function ( ...rest ) {
console.log( 'There was an error loading ', rest );
};
const mtlLoader = new MTLLoader(manager).setPath(path);
const materials = mtlLoader.parse(mtlContent);
materials.preload();
console.log('mtls', materials);
// Extract and load .obj file
const objContent = await zip.file(objFile).async('string');
const objLoader = new OBJLoader();
objLoader.setMaterials(materials);
const object = objLoader.parse(objContent);
object.traverse((child) => {
if (child instanceof THREE.Mesh) {
child.material.side = THREE.DoubleSide;
}
});
console.log('async obj res', object);
return object;
}
I’m getting darks textures preview in both cases:
Original view by macos:
What could be wrong here?
Mine example:
objectmtlzip.zip (1.9 MB)
when I’m trying to render it via http://localhost:8083/examples/?q=obj#webgl_loader_obj_mtl it doesn’t work at all