-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepth_test.js
56 lines (43 loc) · 1.37 KB
/
depth_test.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
let scene, camera, renderer;
let geometry, material, mesh;
let clones = 5;
let depth = 1;
let xShift = 0;
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
geometry = new THREE.BoxGeometry(1, 1, 1);
material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
for (let i = 0; i < clones; i++) {
mesh = new THREE.Mesh(geometry, material);
mesh.position.x = i * 2;
scene.add(mesh);
}
camera.position.z = 5;
document.getElementById('depthSlider').addEventListener('input', (event) => {
handleDepthSliderChange(event.target.value);
});
document.getElementById('positionSlider').addEventListener('input', (event) => {
handlePositionSliderChange(event.target.value);
});
}
function animate() {
requestAnimationFrame(animate);
for (let i = 0; i < clones; i++) {
const obj = scene.children[i];
obj.position.x = i * 2 + xShift;
obj.scale.set(depth, depth, depth);
}
renderer.render(scene, camera);
}
function handleDepthSliderChange(value) {
depth = value;
}
function handlePositionSliderChange(value) {
xShift = value;
}