console
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(80, innerWidth / innerHeight, 1, 1000);
camera.position.set(0, 5, 5);
scene.add(camera);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000);
renderer.shadowMap.enabled = true
document.body.appendChild(renderer.domElement);
const sphereGeometry = new THREE.SphereGeometry(1, 30, 20);
const standardMaterial = new THREE.MeshStandardMaterial({ color: 0xa50aaa });
const sphere = new THREE.Mesh(sphereGeometry, standardMaterial);
sphere.castShadow = true;
scene.add(sphere)
const planeGeometry = new THREE.PlaneGeometry(10, 10);
const planeMaterial = new THREE.MeshStandardMaterial({
color: 0xcccccc,
});
const plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.position.set(0, -1, 0);
plane.rotation.x = -Math.PI / 2;
plane.receiveShadow = true
scene.add(plane)
const light = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(light);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(10, 10, 10)
directionalLight.castShadow = true
scene.add(directionalLight);
let controls = new THREE.OrbitControls(camera, renderer.domElement)
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render()
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body style="margin:0;">
</body>
</html>