Trying to create a shadow for an object,
There is a THREE.SpotLight as the light source in the scene
Below is the code snippet for MTLLoader() and OBJLoader()
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setBaseUrl('assets/');
mtlLoader.setPath('assets/');
mtlLoader.load('komoda.mtl', function (materials) {
materials.preload();
materials.materials.lambert2SG.map.magFilter = THREE.NearestFilter;
materials.materials.lambert2SG.map.minFilter = THREE.LinearFilter;
materials.materials.lambert3SG.map.magFilter = THREE.NearestFilter;
materials.materials.lambert3SG.map.minFilter = THREE.LinearFilter;
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('assets/');
objLoader.load('komoda.obj', function (object) {
object.castShadow = true;
object.receiveShadow = true;
scene.add(object);
});
});
Full JavaScript code can be found here:
Check out the online example at:
Thank you for your help!
EDIT: Added jsfiddle link, but unable to load materials on jsfiddle
https://jsfiddle.net/fcb9qoco/23/
Thanks again!
EDIT 2: Issue resolved - There were two problems, one being spotLight.shadow.camera.near = 500;
The correct value should have been 10, so spotLight.shadow.camera.near = 10;
Special thanks to @gaitat
The second issue was that the plane object did not have receiveShadow = true;
Now it does, thanks to @Jim Tang