poseoffset.js
1.79 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
import ARCS from '../engine/arcs.js';
import * as THREE from '../deps/three.js/index.js';
let PoseOffset;
PoseOffset = ARCS.Component.create(
function(config) {
let self = this;
config = config || {};
let pos, rot;
if (!config.position ) {
pos = new THREE.Vector3(0,0,0);
} else {
pos = new THREE.Vector3(
config.position.x,
config.position.y,
config.position.z
);
}
//let pos = config.position || new THREE.Vector3(0, 0, 0);
rot = config.rotation || new THREE.Quaternion(0, 0, 0, 1);
let tAnchor = new THREE.Matrix4();
tAnchor.makeRotationFromQuaternion(rot);
tAnchor.setPosition(pos);
tAnchor.invert();
this.setMatrix = function(m) {
let mat = new THREE.Matrix4();
//console.log(m);
if (Array.isArray(m)) {
mat.fromArray(m);
//mat.transpose();
mat.invert();
} else {
mat.copy(m);
}
mat.multiply(tAnchor);
console.log("poseoffset.sendMatrix", mat);
self.emit('sendMatrix', mat);
};
},
['setMatrix'],
['sendMatrix']
);
export default { PoseOffset: PoseOffset};
/*
ARCS.__lib__`
{
"components": {
"PoseOffset": {
"description": "Apply a pose offset to a matrix",
"keywords": [
"pose",
"offset",
"transformation"
]
}
},
"dependencies": ["three"],
"recipes": {
"from": "node_modules/three/three.module.js",
"to": "deps/three.js/index.js"
}
}
`;
*/