-
Notifications
You must be signed in to change notification settings - Fork 0
/
eyes.js
85 lines (61 loc) · 2 KB
/
eyes.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
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
const container = document.querySelector('#allInTheFish');
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
85, window.innerWidth / window.innerHeight , 0.1, 1000
); //fov, aspect, near, far
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.domElement.id = "bithch";
container.appendChild(renderer.domElement);
//(depth, up-down ,left-right)
camera.position.set(4,0,0)
camera.lookAt(0,0,0);
const loader = new GLTFLoader();
let model;
let instances = [];
loader.load('model/fish2.glb', function(gltf) {
model = gltf.scene;
// scene.add(model);
const rows = 5;
const cols = 5;
for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
const instance = model.clone();
instance.position.set(-4, j, i);
instances.push(instance);
scene.add(instance);
}
}
console.log(instances);
}, undefined, function(error) {
console.error('error loading: ', error);
});
function animate() {
requestAnimationFrame(animate);
instances.forEach(instance => {
instance.rotation.set(0, mouse.x*1.5, mouse.y*1.5);
//the solution to thy problem
});
renderer.render(scene, camera);
};
animate();
const light = new THREE.AmbientLight(0xffffff, 1);
scene.add(light);
const hlp = new THREE.AxesHelper(1);
scene.add(hlp);
scene.background = new THREE.Color(0xaaaaaa);
const mouse = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
function onMouseMove(event) {
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
}
window.addEventListener('mousemove', onMouseMove);
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});