GeometryInstance-34d9e21e.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. define(['exports', './defaultValue-fe22d8c0', './Check-6ede7e26', './Matrix2-e1298525'], (function (exports, defaultValue, Check, Matrix2) { 'use strict';
  2. /**
  3. * Geometry instancing allows one {@link Geometry} object to be positions in several
  4. * different locations and colored uniquely. For example, one {@link BoxGeometry} can
  5. * be instanced several times, each with a different <code>modelMatrix</code> to change
  6. * its position, rotation, and scale.
  7. *
  8. * @alias GeometryInstance
  9. * @constructor
  10. *
  11. * @param {object} options Object with the following properties:
  12. * @param {Geometry|GeometryFactory} options.geometry The geometry to instance.
  13. * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The model matrix that transforms to transform the geometry from model to world coordinates.
  14. * @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}.
  15. * @param {object} [options.attributes] Per-instance attributes like a show or color attribute shown in the example below.
  16. *
  17. *
  18. * @example
  19. * // Create geometry for a box, and two instances that refer to it.
  20. * // One instance positions the box on the bottom and colored aqua.
  21. * // The other instance positions the box on the top and color white.
  22. * const geometry = Cesium.BoxGeometry.fromDimensions({
  23. * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,
  24. * dimensions : new Cesium.Cartesian3(1000000.0, 1000000.0, 500000.0)
  25. * });
  26. * const instanceBottom = new Cesium.GeometryInstance({
  27. * geometry : geometry,
  28. * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
  29. * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
  30. * attributes : {
  31. * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
  32. * },
  33. * id : 'bottom'
  34. * });
  35. * const instanceTop = new Cesium.GeometryInstance({
  36. * geometry : geometry,
  37. * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
  38. * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 3000000.0), new Cesium.Matrix4()),
  39. * attributes : {
  40. * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
  41. * },
  42. * id : 'top'
  43. * });
  44. *
  45. * @see Geometry
  46. */
  47. function GeometryInstance(options) {
  48. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  49. //>>includeStart('debug', pragmas.debug);
  50. if (!defaultValue.defined(options.geometry)) {
  51. throw new Check.DeveloperError("options.geometry is required.");
  52. }
  53. //>>includeEnd('debug');
  54. /**
  55. * The geometry being instanced.
  56. *
  57. * @type Geometry
  58. *
  59. * @default undefined
  60. */
  61. this.geometry = options.geometry;
  62. /**
  63. * The 4x4 transformation matrix that transforms the geometry from model to world coordinates.
  64. * When this is the identity matrix, the geometry is drawn in world coordinates, i.e., Earth's WGS84 coordinates.
  65. * Local reference frames can be used by providing a different transformation matrix, like that returned
  66. * by {@link Transforms.eastNorthUpToFixedFrame}.
  67. *
  68. * @type Matrix4
  69. *
  70. * @default Matrix4.IDENTITY
  71. */
  72. this.modelMatrix = Matrix2.Matrix4.clone(
  73. defaultValue.defaultValue(options.modelMatrix, Matrix2.Matrix4.IDENTITY)
  74. );
  75. /**
  76. * User-defined object returned when the instance is picked or used to get/set per-instance attributes.
  77. *
  78. * @type {object}
  79. *
  80. * @default undefined
  81. *
  82. * @see Scene#pick
  83. * @see Primitive#getGeometryInstanceAttributes
  84. */
  85. this.id = options.id;
  86. /**
  87. * Used for picking primitives that wrap geometry instances.
  88. *
  89. * @private
  90. */
  91. this.pickPrimitive = options.pickPrimitive;
  92. /**
  93. * Per-instance attributes like {@link ColorGeometryInstanceAttribute} or {@link ShowGeometryInstanceAttribute}.
  94. * {@link Geometry} attributes varying per vertex; these attributes are constant for the entire instance.
  95. *
  96. * @type {object}
  97. *
  98. * @default undefined
  99. */
  100. this.attributes = defaultValue.defaultValue(options.attributes, {});
  101. /**
  102. * @private
  103. */
  104. this.westHemisphereGeometry = undefined;
  105. /**
  106. * @private
  107. */
  108. this.eastHemisphereGeometry = undefined;
  109. }
  110. exports.GeometryInstance = GeometryInstance;
  111. }));