/
ModelNode.js
135 lines (125 loc) · 3.77 KB
/
ModelNode.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import defineProperties from '../Core/defineProperties.js';
import Matrix4 from '../Core/Matrix4.js';
/**
* A model node with a transform for user-defined animations. A glTF asset can
* contain animations that target a node's transform. This class allows
* changing a node's transform externally so animation can be driven by another
* source, not just an animation in the glTF asset.
* <p>
* Use {@link Model#getNode} to create an instance.
* </p>
*
* @alias ModelNode
* @internalConstructor
* @class
*
* @example
* var node = model.getNode('LOD3sp');
* node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);
*
* @see Model#getNode
*/
function ModelNode(model, node, runtimeNode, id, matrix) {
this._model = model;
this._runtimeNode = runtimeNode;
this._name = node.name;
this._id = id;
/**
* @private
*/
this.useMatrix = false;
this._show = true;
this._matrix = Matrix4.clone(matrix);
this._originalMatrix = Matrix4.clone(matrix);
}
defineProperties(ModelNode.prototype, {
/**
* The value of the <code>name</code> property of this node.
*
* @memberof ModelNode.prototype
*
* @type {String}
* @readonly
*/
name : {
get : function() {
return this._name;
}
},
/**
* The index of the node.
*
* @memberof ModelNode.prototype
*
* @type {String}
* @readonly
*/
id : {
get : function() {
return this._id;
}
},
/**
* Determines if this node and its children will be shown.
*
* @memberof ModelNode.prototype
* @type {Boolean}
*
* @default true
*/
show : {
get : function() {
return this._show;
},
set : function(value) {
if (this._show !== value) {
this._show = value;
this._model._perNodeShowDirty = true;
}
}
},
/**
* The node's 4x4 matrix transform from its local coordinates to
* its parent's.
* <p>
* For changes to take effect, this property must be assigned to;
* setting individual elements of the matrix will not work.
* </p>
*
* @memberof ModelNode.prototype
* @type {Matrix4}
*/
matrix : {
get : function() {
return this._matrix;
},
set : function(value) {
this._matrix = Matrix4.clone(value, this._matrix);
this.useMatrix = true;
var model = this._model;
model._cesiumAnimationsDirty = true;
this._runtimeNode.dirtyNumber = model._maxDirtyNumber;
}
},
/**
* Gets the node's original 4x4 matrix transform from its local coordinates to
* its parent's, without any node transformations or articulations applied.
*
* @memberof ModelNode.prototype
* @type {Matrix4}
*/
originalMatrix : {
get : function() {
return this._originalMatrix;
}
}
});
/**
* @private
*/
ModelNode.prototype.setMatrix = function(matrix) {
// Update matrix but do not set the dirty flag since this is used internally
// to keep the matrix in-sync during a glTF animation.
Matrix4.clone(matrix, this._matrix);
};
export default ModelNode;