NodeTransformationProperty.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import defaultValue from "../Core/defaultValue.js";
  2. import defined from "../Core/defined.js";
  3. import Event from "../Core/Event.js";
  4. import TranslationRotationScale from "../Core/TranslationRotationScale.js";
  5. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  6. import Property from "./Property.js";
  7. const defaultNodeTransformation = new TranslationRotationScale();
  8. /**
  9. * A {@link Property} that produces {@link TranslationRotationScale} data.
  10. * @alias NodeTransformationProperty
  11. * @constructor
  12. *
  13. * @param {Object} [options] Object with the following properties:
  14. * @param {Property|Cartesian3} [options.translation=Cartesian3.ZERO] A {@link Cartesian3} Property specifying the (x, y, z) translation to apply to the node.
  15. * @param {Property|Quaternion} [options.rotation=Quaternion.IDENTITY] A {@link Quaternion} Property specifying the (x, y, z, w) rotation to apply to the node.
  16. * @param {Property|Cartesian3} [options.scale=new Cartesian3(1.0, 1.0, 1.0)] A {@link Cartesian3} Property specifying the (x, y, z) scaling to apply to the node.
  17. */
  18. function NodeTransformationProperty(options) {
  19. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  20. this._definitionChanged = new Event();
  21. this._translation = undefined;
  22. this._translationSubscription = undefined;
  23. this._rotation = undefined;
  24. this._rotationSubscription = undefined;
  25. this._scale = undefined;
  26. this._scaleSubscription = undefined;
  27. this.translation = options.translation;
  28. this.rotation = options.rotation;
  29. this.scale = options.scale;
  30. }
  31. Object.defineProperties(NodeTransformationProperty.prototype, {
  32. /**
  33. * Gets a value indicating if this property is constant. A property is considered
  34. * constant if getValue always returns the same result for the current definition.
  35. * @memberof NodeTransformationProperty.prototype
  36. *
  37. * @type {Boolean}
  38. * @readonly
  39. */
  40. isConstant: {
  41. get: function () {
  42. return (
  43. Property.isConstant(this._translation) &&
  44. Property.isConstant(this._rotation) &&
  45. Property.isConstant(this._scale)
  46. );
  47. },
  48. },
  49. /**
  50. * Gets the event that is raised whenever the definition of this property changes.
  51. * The definition is considered to have changed if a call to getValue would return
  52. * a different result for the same time.
  53. * @memberof NodeTransformationProperty.prototype
  54. *
  55. * @type {Event}
  56. * @readonly
  57. */
  58. definitionChanged: {
  59. get: function () {
  60. return this._definitionChanged;
  61. },
  62. },
  63. /**
  64. * Gets or sets the {@link Cartesian3} Property specifying the (x, y, z) translation to apply to the node.
  65. * @memberof NodeTransformationProperty.prototype
  66. * @type {Property|undefined}
  67. * @default Cartesian3.ZERO
  68. */
  69. translation: createPropertyDescriptor("translation"),
  70. /**
  71. * Gets or sets the {@link Quaternion} Property specifying the (x, y, z, w) rotation to apply to the node.
  72. * @memberof NodeTransformationProperty.prototype
  73. * @type {Property|undefined}
  74. * @default Quaternion.IDENTITY
  75. */
  76. rotation: createPropertyDescriptor("rotation"),
  77. /**
  78. * Gets or sets the {@link Cartesian3} Property specifying the (x, y, z) scaling to apply to the node.
  79. * @memberof NodeTransformationProperty.prototype
  80. * @type {Property|undefined}
  81. * @default new Cartesian3(1.0, 1.0, 1.0)
  82. */
  83. scale: createPropertyDescriptor("scale"),
  84. });
  85. /**
  86. * Gets the value of the property at the provided time.
  87. *
  88. * @param {JulianDate} time The time for which to retrieve the value.
  89. * @param {TranslationRotationScale} [result] The object to store the value into, if omitted, a new instance is created and returned.
  90. * @returns {TranslationRotationScale} The modified result parameter or a new instance if the result parameter was not supplied.
  91. */
  92. NodeTransformationProperty.prototype.getValue = function (time, result) {
  93. if (!defined(result)) {
  94. result = new TranslationRotationScale();
  95. }
  96. result.translation = Property.getValueOrClonedDefault(
  97. this._translation,
  98. time,
  99. defaultNodeTransformation.translation,
  100. result.translation
  101. );
  102. result.rotation = Property.getValueOrClonedDefault(
  103. this._rotation,
  104. time,
  105. defaultNodeTransformation.rotation,
  106. result.rotation
  107. );
  108. result.scale = Property.getValueOrClonedDefault(
  109. this._scale,
  110. time,
  111. defaultNodeTransformation.scale,
  112. result.scale
  113. );
  114. return result;
  115. };
  116. /**
  117. * Compares this property to the provided property and returns
  118. * <code>true</code> if they are equal, <code>false</code> otherwise.
  119. *
  120. * @param {Property} [other] The other property.
  121. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  122. */
  123. NodeTransformationProperty.prototype.equals = function (other) {
  124. return (
  125. this === other ||
  126. (other instanceof NodeTransformationProperty &&
  127. Property.equals(this._translation, other._translation) &&
  128. Property.equals(this._rotation, other._rotation) &&
  129. Property.equals(this._scale, other._scale))
  130. );
  131. };
  132. export default NodeTransformationProperty;