I’m learning three js recently and I’m trying to mimic the scene which is present in below link by downloading the model
https://sketchfab.com/3d-models/ccity-building-set-1-a2d5c7bfcc2148fb8994864c43dfcc97
I’ve downloaded gltf model and tried to add shadows to all the children in the scene and it came like this. It’s not looking good and all the road surfaces also have shadows
So I’ve checked the details in gltf scene. and I’ve applied shadows only to surfaces which is not ConcreteSurfaces. Now it looks like this. Still surfaces on buildings are getting shadows and some of the buildings shadows are missing
Below is my code which I’m using.
var scene = new THREE.Scene();
const modelUrl = new URL('./assets/ground/scene.gltf', import.meta.url);
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(window.innerWidth, window.innerHeight);
// renderer.setClearColor(0xA3A3A3);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
renderer.gammaOutput = true;
renderer.gammaFactor = 2.2;
refContainer.current && refContainer.current.appendChild(renderer.domElement);
const orbit = new OrbitControls(camera, renderer.domElement);
camera.position.set(100, 100, -100);
// camera.updateMatrix();
orbit.update();
const ambientLight = new THREE.AmbientLight(0x333333);
scene.add(ambientLight);
var spotLight = new THREE.SpotLight( 0xFBCEB1, 10000 );
spotLight.position.set( -500, 200, 100 );
spotLight.angle = 0.4;
spotLight.penumbra = 0.05;
spotLight.decay = 1;
spotLight.distance = 2000;
spotLight.castShadow = true;
scene.add( spotLight );
spotLight.target.position.set( 3, 0, - 3 );
scene.add( spotLight.target );
const helper = new THREE.DirectionalLightHelper( spotLight, 5 );
scene.add( helper );
const assetLoader = new GLTFLoader();
assetLoader.load(modelUrl.href, function(gltf) {
const model = gltf.scene;
model.scale.set(0.01,0.01,0.01);
model.position.z = 100
model.position.x = 100
model.traverse( function( child ) {
if ( child.isMesh ) {
console.log(child)
var childName = child.name
if(!childName.includes('ConcreteBlock')) {
child.castShadow = true;
child.receiveShadow = true;
}
}
} );
scene.add(model);
}, undefined, function(error) {
console.error(error);
});
function animate() {
// requestAnimationFrame( animate );
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
animate();
How to identify the surfaces which needs shadows so that the scene looks like in the above link??? Am i doing it in right way??