-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
32 lines (29 loc) · 1.09 KB
/
utils.ts
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
import * as THREE from 'three';
export function addCuboid(scene: THREE.Scene, position: THREE.Vector3): THREE.Mesh {
const geometry = new THREE.BoxGeometry(1, 1, 0.45);
const material = new THREE.MeshBasicMaterial({ color: 0x999966 });
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
mesh.position.set(position.x, position.y, position.z);
return mesh;
}
export function addSphere(scene: THREE.Scene, position: THREE.Vector3): THREE.Mesh {
const geometry = new THREE.SphereGeometry(0.2);
const material = new THREE.MeshBasicMaterial({ color: 0xff00ff });
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
mesh.position.set(position.x, position.y, position.z);
return mesh;
}
let lastFrameTime = 0;
let currFrameTime = 0;
export function deltaLoop(loop: any) {
function _loop(DOMHighResTimeStamp: number) {
lastFrameTime = currFrameTime;
currFrameTime = DOMHighResTimeStamp;
const deltaTime = currFrameTime - lastFrameTime;
loop(deltaTime);
requestAnimationFrame(_loop);
}
_loop(0);
}