I'm currently tackling a project in which I want to enable a .OBJ model loaded from OBJLoader.js to cast a shadow from a spotlight. The light successfully casts shadows from other regular objects, however, the .OBJ model doesn't seem to be casting any shadows.
One potential issue that may be causing this problem is as follows: When these regular objects are generated by clicking on the floor, they are added to the Objects[] array, allowing them to be clickable for adding more objects on top of them. The .OBJ model is also added to this array, but it appears that I can't click on it to add models on top of it; almost as if the raycaster isn't detecting it.
I will provide all of my code below, as the root of the issue might be hiding somewhere unexpected.
You can view a working link HERE
Feel free to try clicking on the floor to observe how other objects do cast shadows.
Any suggestions or ideas? Mr.Doob, are you out there? :)
ps: It's strange that in my browser, the provided link is redirecting to a suspicious site called "4safe.in". You might have to copy and paste the link instead...
Just to cover all bases, here's a snippet of the code that likely contains the source of the problem.
renderer.shadowMapEnabled = true;///////////////////////////////////////////// RENDERER /// <------------Renderer and lights set up to cast shadows
light.castShadow = true;
light.shadowDarkness = 1;
renderer.shadowMapSoft = true;
floor.receiveShadow = true;
var texture = new THREE.Texture();
var loader = new THREE.ImageLoader();
loader.addEventListener( 'load', function ( event ) {
texture.image = event.content;
texture.needsUpdate = true;
} );
loader.load( 'modeltest/ash_uvgrid01.jpg' );
// model
var loader = new THREE.OBJLoader();
loader.addEventListener( 'load', function ( event ) {
var newModel = event.content;
newModel.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material.map = texture;
}
} );
newModel.position.set (200,30,0);
newModel.castShadow = true;///////////////////////////// <------ This doesn't seem to be working.
scene.add( newModel );
objects.push( newModel );/////////////////////////////// <------ Another HINT: because of this, the raycaster SHOULD allow us to click the model and create a new block. But we can't.
});
loader.load( 'modeltest/male02.obj' );