-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathobject3d.ts
52 lines (45 loc) · 1.28 KB
/
object3d.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Matrix4, Vector3 } from '../matrix';
export class Object3D {
uuid: number;
name: string;
id: string;
children: Array<Object3D>;
matrix: Matrix4;
matrixWorld: Matrix4;
parent: Object3D;
reflow: boolean;
constructor(name, parent) {
this.uuid = Math.floor(Date.now() * Math.random());
this.name = name;
this.children = [];
this.matrix = new Matrix4();
this.matrixWorld = new Matrix4();
this.parent = parent;
}
getPosition() {
return new Float32Array([this.matrixWorld.elements[12], this.matrixWorld.elements[13], this.matrixWorld.elements[14]]);
}
setPosition(translation, rotation, scale) {
if (rotation) {
this.matrix.makeRotationFromQuaternion(rotation);
}
if (scale) {
this.matrix.scale(new Vector3(scale));
}
if (translation) {
this.matrix.setTranslate(new Vector3(translation));
}
}
setMatrix(matrix) {
this.matrix.set(matrix);
}
setMatrixWorld(matrix) {
this.matrixWorld.set(matrix);
}
updateMatrix() {
const m = new Matrix4();
m.multiply(this.parent.matrixWorld);
m.multiply(this.matrix);
this.setMatrixWorld(m.elements);
}
}