GeometryInstance-3db1d31b.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.95
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(['exports', './defaultValue-97284df2', './RuntimeError-4f8ec8a2', './Matrix2-9e1c22e2'], (function (exports, defaultValue, RuntimeError, Matrix2) { 'use strict';
  26. /**
  27. * Geometry instancing allows one {@link Geometry} object to be positions in several
  28. * different locations and colored uniquely. For example, one {@link BoxGeometry} can
  29. * be instanced several times, each with a different <code>modelMatrix</code> to change
  30. * its position, rotation, and scale.
  31. *
  32. * @alias GeometryInstance
  33. * @constructor
  34. *
  35. * @param {Object} options Object with the following properties:
  36. * @param {Geometry|GeometryFactory} options.geometry The geometry to instance.
  37. * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The model matrix that transforms to transform the geometry from model to world coordinates.
  38. * @param {Object} [options.id] A user-defined object to return when the instance is picked with {@link Scene#pick} or get/set per-instance attributes with {@link Primitive#getGeometryInstanceAttributes}.
  39. * @param {Object} [options.attributes] Per-instance attributes like a show or color attribute shown in the example below.
  40. *
  41. *
  42. * @example
  43. * // Create geometry for a box, and two instances that refer to it.
  44. * // One instance positions the box on the bottom and colored aqua.
  45. * // The other instance positions the box on the top and color white.
  46. * const geometry = Cesium.BoxGeometry.fromDimensions({
  47. * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,
  48. * dimensions : new Cesium.Cartesian3(1000000.0, 1000000.0, 500000.0)
  49. * });
  50. * const instanceBottom = new Cesium.GeometryInstance({
  51. * geometry : geometry,
  52. * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
  53. * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
  54. * attributes : {
  55. * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
  56. * },
  57. * id : 'bottom'
  58. * });
  59. * const instanceTop = new Cesium.GeometryInstance({
  60. * geometry : geometry,
  61. * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
  62. * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 3000000.0), new Cesium.Matrix4()),
  63. * attributes : {
  64. * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
  65. * },
  66. * id : 'top'
  67. * });
  68. *
  69. * @see Geometry
  70. */
  71. function GeometryInstance(options) {
  72. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  73. //>>includeStart('debug', pragmas.debug);
  74. if (!defaultValue.defined(options.geometry)) {
  75. throw new RuntimeError.DeveloperError("options.geometry is required.");
  76. }
  77. //>>includeEnd('debug');
  78. /**
  79. * The geometry being instanced.
  80. *
  81. * @type Geometry
  82. *
  83. * @default undefined
  84. */
  85. this.geometry = options.geometry;
  86. /**
  87. * The 4x4 transformation matrix that transforms the geometry from model to world coordinates.
  88. * When this is the identity matrix, the geometry is drawn in world coordinates, i.e., Earth's WGS84 coordinates.
  89. * Local reference frames can be used by providing a different transformation matrix, like that returned
  90. * by {@link Transforms.eastNorthUpToFixedFrame}.
  91. *
  92. * @type Matrix4
  93. *
  94. * @default Matrix4.IDENTITY
  95. */
  96. this.modelMatrix = Matrix2.Matrix4.clone(
  97. defaultValue.defaultValue(options.modelMatrix, Matrix2.Matrix4.IDENTITY)
  98. );
  99. /**
  100. * User-defined object returned when the instance is picked or used to get/set per-instance attributes.
  101. *
  102. * @type Object
  103. *
  104. * @default undefined
  105. *
  106. * @see Scene#pick
  107. * @see Primitive#getGeometryInstanceAttributes
  108. */
  109. this.id = options.id;
  110. /**
  111. * Used for picking primitives that wrap geometry instances.
  112. *
  113. * @private
  114. */
  115. this.pickPrimitive = options.pickPrimitive;
  116. /**
  117. * Per-instance attributes like {@link ColorGeometryInstanceAttribute} or {@link ShowGeometryInstanceAttribute}.
  118. * {@link Geometry} attributes varying per vertex; these attributes are constant for the entire instance.
  119. *
  120. * @type Object
  121. *
  122. * @default undefined
  123. */
  124. this.attributes = defaultValue.defaultValue(options.attributes, {});
  125. /**
  126. * @private
  127. */
  128. this.westHemisphereGeometry = undefined;
  129. /**
  130. * @private
  131. */
  132. this.eastHemisphereGeometry = undefined;
  133. }
  134. exports.GeometryInstance = GeometryInstance;
  135. }));
  136. //# sourceMappingURL=GeometryInstance-3db1d31b.js.map