ModelNode.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*global define*/
  2. define([
  3. '../Core/defaultValue',
  4. '../Core/defineProperties',
  5. '../Core/Matrix4'
  6. ], function(
  7. defaultValue,
  8. defineProperties,
  9. Matrix4) {
  10. "use strict";
  11. /**
  12. * A model node with a transform for user-defined animations. A glTF asset can
  13. * contain animations that target a node's transform. This class allows
  14. * changing a node's transform externally so animation can be driven by another
  15. * source, not just an animation in the glTF asset.
  16. * <p>
  17. * Use {@link Model#getNode} to create an instance.
  18. * </p>
  19. *
  20. * @alias ModelNode
  21. * @internalConstructor
  22. *
  23. * @see Model#getNode
  24. *
  25. * @example
  26. * var node = model.getNode('LOD3sp');
  27. * node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);
  28. */
  29. var ModelNode = function(model, node, runtimeNode, id, matrix) {
  30. this._model = model;
  31. this._runtimeNode = runtimeNode;
  32. this._name = node.name;
  33. this._id = id;
  34. /**
  35. * @private
  36. */
  37. this.useMatrix = false;
  38. this._show = true;
  39. this._matrix = Matrix4.clone(matrix);
  40. };
  41. defineProperties(ModelNode.prototype, {
  42. /**
  43. * The value of the <code>name</code> property of this node. This is the
  44. * name assigned by the artist when the asset is created. This can be
  45. * different than the name of the node property ({@link ModelNode#id}),
  46. * which is internal to glTF.
  47. *
  48. * @memberof ModelNode.prototype
  49. *
  50. * @type {String}
  51. * @readonly
  52. */
  53. name : {
  54. get : function() {
  55. return this._name;
  56. }
  57. },
  58. /**
  59. * The name of the glTF JSON property for this node. This is guaranteed
  60. * to be unique among all nodes. It may not match the node's <code>
  61. * name</code> property (@link ModelNode#name), which is assigned by
  62. * the artist when the asset is created.
  63. *
  64. * @memberof ModelNode.prototype
  65. *
  66. * @type {String}
  67. * @readonly
  68. */
  69. id : {
  70. get : function() {
  71. return this._id;
  72. }
  73. },
  74. /**
  75. * Determines if this node and its children will be shown.
  76. *
  77. * @memberof ModelNode.prototype
  78. * @type {Boolean}
  79. *
  80. * @default true
  81. */
  82. show : {
  83. get : function() {
  84. return this._show;
  85. },
  86. set : function(value) {
  87. if (this._show !== value) {
  88. this._show = value;
  89. this._model._perNodeShowDirty = true;
  90. }
  91. }
  92. },
  93. /**
  94. * The node's 4x4 matrix transform from its local coordinates to
  95. * its parent's.
  96. * <p>
  97. * For changes to take effect, this property must be assigned to;
  98. * setting individual elements of the matrix will not work.
  99. * </p>
  100. *
  101. * @memberof ModelNode.prototype
  102. * @type {Matrix4}
  103. */
  104. matrix : {
  105. get : function() {
  106. return this._matrix;
  107. },
  108. set : function(value) {
  109. this._matrix = Matrix4.clone(value, this._matrix);
  110. this.useMatrix = true;
  111. var model = this._model;
  112. model._cesiumAnimationsDirty = true;
  113. this._runtimeNode.dirtyNumber = model._maxDirtyNumber;
  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. return ModelNode;
  126. });