PolylineVolumeGeometry表示一条带有体积的折线。
const geometry = new Cesium.PolylineVolumeGeometry({
positions: Cesium.Cartesian3[],
shape: Cesium.Cartesian2[],
cornerType: Cesium.CornerType,
granularity: number
});
positions:表示折线路径上的点的位置数组,类型为Cartesian3[]。shape:表示断面形状的二维位置数组,类型为Cartesian2[]。cornerType:表示折线拐角的类型,类型为CornerType。granularity:表示细节等级,类型为number,默认为0.1。PolylineVolumeGeometry将一组点和一个二维断面形状定义为路径,可以创建具有两端形状的三维物体。使用positions来定义路径,使用shape定义截面形状。
cornerType可能有三个值:ROUNDED(圆角)、MITERED(斜接)和BEVELED(斜角)。默认值为MITERED。
granularity控制生成物体的细节程度,值越小细节越高,默认值为0.1。
const positions = [
new Cesium.Cartesian3(-100000, 0, 0),
new Cesium.Cartesian3(0, 100000, 0),
new Cesium.Cartesian3(100000, 0, 0)
];
const shape = [new Cesium.Cartesian2(-10000, -20000),
new Cesium.Cartesian2(0, 20000),
new Cesium.Cartesian2(10000, -20000)];
const volumeGeometry = new Cesium.PolylineVolumeGeometry({
positions: positions,
shape: shape,
cornerType: Cesium.CornerType.ROUNDED,
granularity: 0.01
});
const primitive = new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: volumeGeometry,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED)
}
}),
appearance: new Cesium.PerInstanceColorAppearance()
});
viewer.scene.primitives.add(primitive);
上述代码创建了一条折线路径,路径上有三个点,每个点的位置使用Cartesian3类型描述。此外,定义了一组截面形状,即断面的形状,使用Cartesian2类型描述,将其赋给shape。
创建了一个PolylineVolumeGeometry对象,并将上述路径和截面形状传入。指定了旋转拐角样式为圆角,细节程度为0.01。最后,创建了一个Primitive,使用该PolylineVolumeGeometry创建了一个GeoemtryInstance,并将其添加到Primitive实例中。这个Primitive被添加到场景的primitives列表中。
packedLength:按照指定格式将对象序列化时需要的字节长度。pack(value, array, startingIndex):将数据压缩到数组中.unpack(array, startingIndex, result):从数组中检索压缩的数据,并解压缩成对象的形式。