Capítulo 827 de 859
Walking through the real-world friction of loading a .OBJ model: OBJ files carry no materials of their own, often need a companion .MTL file and separately-unpacked textures, and models exported without three.js in mind may need double-sided materials or auto-framing to display correctly.
OBJLoader: loads geometry from a .obj file; without materials supplied, it falls back to a default material and can throw errors referencing missing material names.MTLLoader + setMaterials(): loads a companion .mtl file's material definitions and hands them to the OBJLoader before loading the .obj, so named materials resolve correctly..mtl may reference texture files that were never exported separately — for Blender-sourced assets, "Unpack All Into Files" recovers them.THREE.DoubleSide.MTLLoader expects the norm keyword for normal maps; a .mtl file using the wrong keyword will misinterpret normal maps as bump maps, causing blocky-looking shading up close.function frameArea(sizeToFitOnScreen, boxSize, boxCenter, camera) {
const halfFovY = THREE.MathUtils.degToRad(camera.fov * .5);
const distance = (sizeToFitOnScreen * .5) / Math.tan(halfFovY);
const direction = new THREE.Vector3()
.subVectors(camera.position, boxCenter)
.normalize();
camera.position.copy(direction.multiplyScalar(distance).add(boxCenter));
camera.near = boxSize / 100;
camera.far = boxSize * 100;
camera.updateProjectionMatrix();
camera.lookAt(boxCenter.x, boxCenter.y, boxCenter.z);
}
.mtl file loaded via MTLLoader.setMaterials()..mtl file aren't guaranteed to be exported alongside it; check the source 3D tool for an "unpack embedded textures" option if they're missing.material.side = THREE.DoubleSide.MTLLoader specifically expects the norm keyword for normal maps; a mismatched keyword silently treats a normal map as a bump map.