ModelNode.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import defineProperties from '../Core/defineProperties.js';
  2. import Matrix4 from '../Core/Matrix4.js';
  3. /**
  4. * A model node with a transform for user-defined animations. A glTF asset can
  5. * contain animations that target a node's transform. This class allows
  6. * changing a node's transform externally so animation can be driven by another
  7. * source, not just an animation in the glTF asset.
  8. * <p>
  9. * Use {@link Model#getNode} to create an instance.
  10. * </p>
  11. *
  12. * @alias ModelNode
  13. * @internalConstructor
  14. * @class
  15. *
  16. * @example
  17. * var node = model.getNode('LOD3sp');
  18. * node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);
  19. *
  20. * @see Model#getNode
  21. */
  22. function ModelNode(model, node, runtimeNode, id, matrix) {
  23. this._model = model;
  24. this._runtimeNode = runtimeNode;
  25. this._name = node.name;
  26. this._id = id;
  27. /**
  28. * @private
  29. */
  30. this.useMatrix = false;
  31. this._show = true;
  32. this._matrix = Matrix4.clone(matrix);
  33. this._originalMatrix = Matrix4.clone(matrix);
  34. }
  35. defineProperties(ModelNode.prototype, {
  36. /**
  37. * The value of the <code>name</code> property of this node.
  38. *
  39. * @memberof ModelNode.prototype
  40. *
  41. * @type {String}
  42. * @readonly
  43. */
  44. name : {
  45. get : function() {
  46. return this._name;
  47. }
  48. },
  49. /**
  50. * The index of the node.
  51. *
  52. * @memberof ModelNode.prototype
  53. *
  54. * @type {String}
  55. * @readonly
  56. */
  57. id : {
  58. get : function() {
  59. return this._id;
  60. }
  61. },
  62. /**
  63. * Determines if this node and its children will be shown.
  64. *
  65. * @memberof ModelNode.prototype
  66. * @type {Boolean}
  67. *
  68. * @default true
  69. */
  70. show : {
  71. get : function() {
  72. return this._show;
  73. },
  74. set : function(value) {
  75. if (this._show !== value) {
  76. this._show = value;
  77. this._model._perNodeShowDirty = true;
  78. }
  79. }
  80. },
  81. /**
  82. * The node's 4x4 matrix transform from its local coordinates to
  83. * its parent's.
  84. * <p>
  85. * For changes to take effect, this property must be assigned to;
  86. * setting individual elements of the matrix will not work.
  87. * </p>
  88. *
  89. * @memberof ModelNode.prototype
  90. * @type {Matrix4}
  91. */
  92. matrix : {
  93. get : function() {
  94. return this._matrix;
  95. },
  96. set : function(value) {
  97. this._matrix = Matrix4.clone(value, this._matrix);
  98. this.useMatrix = true;
  99. var model = this._model;
  100. model._cesiumAnimationsDirty = true;
  101. this._runtimeNode.dirtyNumber = model._maxDirtyNumber;
  102. }
  103. },
  104. /**
  105. * Gets the node's original 4x4 matrix transform from its local coordinates to
  106. * its parent's, without any node transformations or articulations applied.
  107. *
  108. * @memberof ModelNode.prototype
  109. * @type {Matrix4}
  110. */
  111. originalMatrix : {
  112. get : function() {
  113. return this._originalMatrix;
  114. }
  115. }
  116. });
  117. /**
  118. * @private
  119. */
  120. ModelNode.prototype.setMatrix = function(matrix) {
  121. // Update matrix but do not set the dirty flag since this is used internally
  122. // to keep the matrix in-sync during a glTF animation.
  123. Matrix4.clone(matrix, this._matrix);
  124. };
  125. export default ModelNode;