GeometryInstance

new Cesium.GeometryInstance(options)

几何实例化允许一个 Geometry 对象在多个不同位置定位并着色。 例如,一个 BoxGeometry 可以被实例化多次,每次使用不同的 modelMatrix 来改变其位置、旋转和缩放。
Name Type Description
options object 具有以下属性的对象:
Name Type Default Description
geometry Geometry | GeometryFactory 要实例化的几何体。
modelMatrix Matrix4 Matrix4.IDENTITY optional 将几何体从模型坐标转换到世界坐标的模型矩阵。
id object optional 用户定义的对象,当使用 Scene#pick 拾取实例或使用 Primitive#getGeometryInstanceAttributes 获取/设置每个实例的属性时返回。
attributes object optional 每个实例的属性,如下例所示的颜色或显示属性。
Example:
// 为盒子创建几何体,以及两个引用它的实例。
// 一个实例将盒子定位在底部并着色为水色。
// 另一个实例将盒子定位在顶部并着色为白色。
const geometry = Cesium.BoxGeometry.fromDimensions({
  vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,
  dimensions : new Cesium.Cartesian3(1000000.0, 1000000.0, 500000.0)
});
const instanceBottom = new Cesium.GeometryInstance({
  geometry : geometry,
  modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
    Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
  attributes : {
    color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
  },
  id : 'bottom'
});
const instanceTop = new Cesium.GeometryInstance({
  geometry : geometry,
  modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
    Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 3000000.0), new Cesium.Matrix4()),
  attributes : {
    color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
  },
  id : 'top'
});
See:

Members

每个实例的属性,如 ColorGeometryInstanceAttributeShowGeometryInstanceAttributeGeometry 属性随顶点变化;这些属性对于整个实例是常数。
Default Value: {}
正在被实例化的几何体。
拾取实例或用于获取/设置每个实例的属性时返回的用户定义对象。
Default Value: undefined
See:
将几何体从模型坐标转换到世界坐标的4x4变换矩阵。 当这是单位矩阵时,几何体在世界坐标(即地球的WGS84坐标)中绘制。 可以通过提供不同的变换矩阵(如 Transforms.eastNorthUpToFixedFrame 返回的矩阵)来使用局部参考系。
Default Value: Matrix4.IDENTITY
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.