-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
93 lines (77 loc) · 2.91 KB
/
index.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import * as THREE from "three";
import { OrbitControls } from "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js";
import { EffectComposer } from "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/postprocessing/EffectComposer.js";
import { RenderPass } from "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/postprocessing/RenderPass.js";
import { UnrealBloomPass } from "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/postprocessing/UnrealBloomPass.js";
const w = window.innerWidth;
const h = window.innerHeight;
const render = new THREE.WebGLRenderer({ antialias: true, alpha: true });
render.setSize(w, h);
render.setClearColor(0x000000, 1);
render.shadowMap.enabled = true;
document.body.appendChild(render.domElement);
const fov = 75;
const aspect = w / h;
const near = 0.1;
const far = 10;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.z = 2;
const scene = new THREE.Scene();
const controls = new OrbitControls(camera, render.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.03;
const groundGeo = new THREE.PlaneGeometry(10, 10);
const groundMat = new THREE.MeshStandardMaterial({ color: 0xaaaaaa, side: THREE.DoubleSide });
const ground = new THREE.Mesh(groundGeo, groundMat);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const geo = new THREE.IcosahedronGeometry(1.0, 2);
const mat = new THREE.MeshStandardMaterial({
color: 0x00ff,
metalness: 0.8,
roughness: 0.6,
flatShading: true,
});
const mesh = new THREE.Mesh(geo, mat);
mesh.castShadow = true;
scene.add(mesh);
const wireMat = new THREE.MeshBasicMaterial({
color: 0x00ff,
wireframe: true,
});
const wireMesh = new THREE.Mesh(geo, wireMat);
wireMesh.scale.setScalar(1.001);
mesh.add(wireMesh);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.8); // Reduced intensity
dirLight.position.set(5, 5, 5);
dirLight.castShadow = true;
scene.add(dirLight);
const hemLight = new THREE.HemisphereLight(0x0099ff, 0x00aa00, 0.5); // Adjusted intensity
scene.add(hemLight);
const pointLight = new THREE.PointLight(0xff9900, 0.5, 100); // Reduced intensity
pointLight.position.set(2, 2, 2);
scene.add(pointLight);
const composer = new EffectComposer(render);
const renderPass = new RenderPass(scene, camera);
composer.addPass(renderPass);
const bloomPass = new UnrealBloomPass();
bloomPass.threshold = 0.2;
bloomPass.strength = 1.5;
bloomPass.radius = 0.5;
composer.addPass(bloomPass);
function animate(t = 0) {
requestAnimationFrame(animate);
mesh.rotation.y = t * 0.0008;
composer.render();
controls.update();
}
animate();
window.addEventListener('resize', () => {
const w = window.innerWidth;
const h = window.innerHeight;
render.setSize(w, h);
composer.setSize(w, h);
camera.aspect = w / h;
camera.updateProjectionMatrix();
});