Hi,
I created a model with blender. I was successfully able to export the corresponding obj into my Three JS canvas.
Now I’m working on loading the MTL file from my Blender Export.
The weird thing is that for like a split second, it successfully displays the model with the textures applied appropriately on my Three js canvas, and then it suddenly crashes and errors.
This is the error:
TypeError: Cannot set property 'value' of undefined
initMaterial
node_modules/three/build/three.module.js:16198
16195 |
16196 | if (material.lights) {
16197 | // wire up the material to this renderer's lighting state>
16198 | uniforms.ambientLightColor.value = lights.state.ambient;
| ^ 16199 | uniforms.directionalLights.value = lights.state.directional;
16200 | uniforms.spotLights.value = lights.state.spot;
16201 | uniforms.rectAreaLights.value = lights.state.rectArea;
I am working in React JS so my code might look a little wonky, but here it is:
var mtlLoader = new MTLLoader();
mtlLoader.load( mtl, material => {
material.preload();
var loader = new this.THREE.OBJLoader();
loader.setMaterials( material );
loader.load( obj,
object => {
console.log("entered into the stage");
this.treeHead = object;
this.treeHead.position.y += 30;
this.scene.add(this.treeHead);
this.start()
},
xhr => {console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );},
error => {console.log("Error! ", error);}
);
},
xhr => {},
error => {}
);
I don’t really understand why its working for only half a second and then crashing.
Your help would be much appreciated!