С Gemini
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Схема света и тени 30 градусов</title>
<style>
html, body { margin: 0; padding: 0; overflow: hidden; width: 100%; height: 100%; background: #050510; }
canvas { display: block; width: 100vw; height: 100vh; }
</style>
</head>
<body>
<script type="importmap">
{
"imports": {
"three": "https://jsdelivr.net",
"three/addons/": "https://jsdelivr.net"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 8);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
const sphereGeo = new THREE.SphereGeometry(1.5, 64, 64);
const sphereMat = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.4,
metalness: 0.1
});
const sphere = new THREE.Mesh(sphereGeo, sphereMat);
sphere.castShadow = true;
sphere.receiveShadow = true;
scene.add(sphere);
const planeGeo = new THREE.PlaneGeometry(10, 10);
const planeMat = new THREE.MeshStandardMaterial({ color: 0x202535, roughness: 0.8 });
const plane = new THREE.Mesh(planeGeo, planeMat);
plane.position.y = -2;
plane.rotation.x = -Math.PI / 2;
plane.receiveShadow = true;
scene.add(plane);
const dirLight = new THREE.DirectionalLight(0xffffff, 1.2);
const angle = 30 * (Math.PI / 180);
dirLight.position.set(Math.sin(angle) * 5, Math.cos(angle) * 5, 2);
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 2048;
dirLight.shadow.mapSize.height = 2048;
dirLight.shadow.radius = 4;
scene.add(dirLight);
const ambientLight = new THREE.AmbientLight(0x050515, 0.15);
scene.add(ambientLight);
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
animate();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
Kristina Panasyuk с Gemini ;)
