1 | ;
|
2 |
|
3 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; /*
|
4 | * Generate the global transforms of all the nodes in the graph. This works
|
5 | * recursively. Nodes don't necessarily have transforms, so these will pass
|
6 | * through the parent matrix, or use an identity matrix for top level nodes.
|
7 | *
|
8 | * Nodes don't have to auto-update, and will be skipped over.
|
9 | */
|
10 |
|
11 | Object.defineProperty(exports, "__esModule", {
|
12 | value: true
|
13 | });
|
14 | exports.walkAndUpdateTransforms = walkAndUpdateTransforms;
|
15 | exports.default = updateGlobalTransforms;
|
16 |
|
17 | var _update = require('../transform/update');
|
18 |
|
19 | var _update2 = _interopRequireDefault(_update);
|
20 |
|
21 | var _glMat = require('gl-mat4');
|
22 |
|
23 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
24 |
|
25 | var IDENTITY = (0, _glMat.identity)(Array(16));
|
26 |
|
27 | function walkAndUpdateTransforms(graph, children, parentMatrix) {
|
28 | for (var i = 0; i < children.length; i++) {
|
29 | var nextMatrix = parentMatrix;
|
30 | var node = children[i];
|
31 |
|
32 | if (_typeof(node.transform) === 'object') {
|
33 | if (node.transform.flags.autoUpdate) {
|
34 | (0, _update2.default)(node.transform);
|
35 |
|
36 | var localMatrix = node.transform.local;
|
37 | var globalMatrix = node.transform.global;
|
38 |
|
39 | (0, _glMat.multiply)(globalMatrix, parentMatrix, localMatrix);
|
40 | nextMatrix = globalMatrix;
|
41 | } else {
|
42 | nextMatrix = node.transform.global;
|
43 | }
|
44 | }
|
45 |
|
46 | walkAndUpdateTransforms(graph, graph.children.get(node), nextMatrix);
|
47 | }
|
48 | }
|
49 |
|
50 | function updateGlobalTransforms(scene, graph) {
|
51 | var children = graph.children.get(scene);
|
52 |
|
53 | // Start recursing through all the first level items in the scene
|
54 | // Provide an identity matrix as the base if no transform exists
|
55 | // Copy over the local transform to global
|
56 |
|
57 | for (var i = 0; i < children.length; i++) {
|
58 | var node = children[i];
|
59 | var nextMatrix = IDENTITY;
|
60 |
|
61 | if (_typeof(node.transform) === 'object') {
|
62 | if (node.transform.flags.autoUpdate) {
|
63 | (0, _update2.default)(node.transform);
|
64 | (0, _glMat.copy)(node.transform.global, node.transform.local);
|
65 | }
|
66 |
|
67 | nextMatrix = node.transform.global;
|
68 | }
|
69 |
|
70 | walkAndUpdateTransforms(graph, scene.children(node), nextMatrix);
|
71 | }
|
72 | } |
\ | No newline at end of file |