NodeTransformationProperty.js 5.5 KB

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