GeometryInstance-97bd792f.js 4.6 KB

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