Playground
Three.js
3D 그래픽 및 WebGL 렌더링
scene.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Three.js 3D Playground // Scene const scene = new THREE.Scene(); scene.background = new THREE.Color(0x1a1a2e); // Camera const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); camera.position.z = 5; // Renderer const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setPixelRatio(window.devicePixelRatio); document.body.appendChild(renderer.domElement); // Lighting scene.add(new THREE.AmbientLight(0x404040, 3)); const dirLight = new THREE.DirectionalLight(0xffffff, 1.5); dirLight.position.set(5, 5, 5); scene.add(dirLight); // Objects const cube = new THREE.Mesh( new THREE.BoxGeometry(1, 1, 1), new THREE.MeshStandardMaterial({ color: 0x6366f1 }) ); scene.add(cube); const torus = new THREE.Mesh( new THREE.TorusGeometry(0.7, 0.25, 16, 100), new THREE.MeshStandardMaterial({ color: 0xf472b6 }) ); torus.position.x = 2.5; scene.add(torus); const sphere = new THREE.Mesh( new THREE.SphereGeometry(0.6, 32, 32), new THREE.MeshStandardMaterial({ color: 0x34d399 }) ); sphere.position.x = -2.5; scene.add(sphere); // Animation function animate() { requestAnimationFrame(animate); cube.rotation.x += 0.01; cube.rotation.y += 0.01; torus.rotation.x += 0.02; torus.rotation.y += 0.01; sphere.rotation.y += 0.015; renderer.render(scene, camera); } animate(); // Resize window.addEventListener('resize', () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); });
Preview
Console
Three.js
scene.js
UTF-8
Ln 1, Col 1
Spaces: 2