I\'ve imported an OBJ model with the following code:
var loader = new THREE.OBJLoader();
loader.addEventListener(\'load\', function (geometry) {
object = geo
I used SketchUp to produce my model. When I export from SketchUp to OBJ
file format the resulting zip includes a MTL
file;
This code will load both the MTL
file and the OBJ
file; when you scene.add(object)
after the successful load, the textures are automatically rendered (no need to assign to child.material.map
)
const loader = new OBJLoader(manager);
const materialsLoader = new MTLLoader(manager);
materialsLoader.load('models/obj/sketchup_export/d2e8bc61-6dd1-4554-b874-13b5364d656e.mtl', function (materialsCreator) {
// https://threejs.org/docs/#examples/en/loaders/OBJLoader.setMaterials
loader.setMaterials(materialsCreator);
loader.load('models/obj/sketchup_export/d2e8bc61-6dd1-4554-b874-13b5364d656e.obj', function (obj) {
object = obj;
}, onProgress, onError);
}, onProgress, onError);