-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.ts
More file actions
76 lines (59 loc) · 1.57 KB
/
Copy pathmain.ts
File metadata and controls
76 lines (59 loc) · 1.57 KB
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
import { Body, Joint, Scene } from '@node-3d/bullet';
const scene = new Scene();
// scene.on('gravity', (g) => console.log('gravity event', g));
scene.gravity = [0, -9.8, 0];
const plane = new Body({ scene });
plane.type = 'plane';
const bodyA = new Body({ scene });
bodyA.pos = [0, 100, 0];
bodyA.mass = 1;
const bodyB = new Body({ scene });
bodyB.pos = [0, 101, 0];
bodyB.mass = 1;
const joint = new Joint();
joint.minl = [0, 1, 0];
joint.maxl = [0, 1, 0];
// joint.on('a', (a) => console.log('joint A', a));
// joint.on('b', (a) => console.log('joint B', a));
joint.a = bodyA;
joint.b = bodyB;
console.log('scene =', scene);
console.log('plane =', plane);
console.log('A =', bodyA);
console.log('B =', bodyB);
console.log('JOINT =', joint);
// TODO
// const trace1 = new Trace({ scene, from: [0, 200, 0], to: [0, -10, 0] });
// console.log('TRACE 1', trace1);
// const trace2 = new Trace();
// console.log('TRACE 2', trace2);
const hitRes = scene.hit([0, 200, 0], [0, -10, 0]);
console.log('Body hit by ray:', hitRes);
const traceRes = scene.trace([0, 200, 0], [0, -10, 0]);
console.log(
'Ray traced bodies:',
traceRes.map((result) => result.body),
);
let prevTimeA = 0;
bodyA.on('update', (u) => {
const t = Date.now();
if (prevTimeA + 1000 > t) {
return;
}
prevTimeA = t;
console.log('Body A height:', u.pos.y);
});
let prevTimeJ = 0;
joint.on('update', (u) => {
const t = Date.now();
if (prevTimeJ + 1000 > t) {
return;
}
prevTimeJ = t;
console.log('Joint body heights:', u.posa.y, u.posb.y);
});
const frame = () => {
scene.update();
setTimeout(frame, 15);
};
frame();