-
Notifications
You must be signed in to change notification settings - Fork 0
/
getMeshes.js
44 lines (40 loc) · 1.25 KB
/
getMeshes.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
import * as THREE from "three";
function getBody() {
const size = 0.5;
const range = 2;
let x = Math.random() * range - range * 0.5;
let y = Math.random() * range - range * 0.5 + 0;
let z = Math.random() * range - range * 0.5;
const geometry = new THREE.IcosahedronGeometry(size, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
const wireMat = new THREE.MeshBasicMaterial({
color: 0x000,
wireframe: true
});
const wireMesh = new THREE.Mesh(geometry, wireMat);
wireMesh.scale.setScalar(1.001);
mesh.add(wireMesh);
return { mesh };
}
function getMouseBall() {
const mouseSize = 0.25;
const geometry = new THREE.IcosahedronGeometry(mouseSize, 8);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0xffffff,
});
const mouseLight = new THREE.PointLight(0xffffff, 2);
const mouseMesh = new THREE.Mesh(geometry, material);
mouseMesh.add(mouseLight);
function update(mousePos) {
let { x, y, z } = { x: mousePos.x * 5, y: mousePos.y * 5, z: 1 };
mouseMesh.position.set(x, y, z);
}
return { mesh: mouseMesh, update };
}
export { getBody, getMouseBall };