Geometry 用于描述三维空间中的几何形状,比如点、线、面等。每种几何形状都有其对应的 Geometry 类来表示。
Geometry 类PointGeometry:点PolylineGeometry:线PolygonGeometry:面EllipseGeometry:椭圆RectangleGeometry:矩形vertices类型:Array<number>,默认值:[]
用于描述几何形状的顶点集合,每三个数字表示一个顶点的坐标。如 PointGeometry 的 vertices 只需要一个三元组,表示点的位置。
indices类型:Array<number>,默认值:[]
用于描述如何将 vertices 中的顶点组合成几何形状,每三个数字表示一个三角形的顶点索引。如 PolylineGeometry 的 indices 表示的是线段所连接的顶点的索引。
primitiveType类型:Number,默认值:undefined
用于描述几何形状的渲染方式,可选值有 cesium.PrimitiveType.POINTS(点)、cesium.PrimitiveType.LINES(线)、cesium.PrimitiveType.TRIANGLES(三角形)等。如 PointGeometry 的 primitiveType 是 cesium.PrimitiveType.POINTS。
createGeometry()用于创建一个 Geometry 实例。
const geometry = Cesium.Geometry.createGeometry(new Cesium.PointGeometry({
position: Cesium.Cartesian3.ZERO
}));
computeBoundingSphere()用于计算几何形状的包围球(Bounding Sphere)。
const sphere = geometry.computeBoundingSphere();
computeBoundingBox()用于计算几何形状的包围盒(Bounding Box)。
const box = geometry.computeBoundingBox();
fromPositions()根据一组 Cartesian3 类型的位置构建 Geometry 实例。
const positions = [new Cesium.Cartesian3(0, 0, 0), new Cesium.Cartesian3(1, 1, 1)];
const geometry = Cesium.PolylineGeometry.fromPositions({
positions: positions
});
pack()将 Geometry 实例打包成二进制流,便于传输和保存。
const geometryData = Cesium.PolygonGeometry.pack(geometry);
unpack()将二进制流还原为 Geometry 实例。
const geometry = Cesium.PolygonGeometry.unpack(geometryData);