let colors_pla = new Float32Array([ 1.0, 0.0, 0.0, 1.0, //红色 0.0, 1.0, 0.0, 1.0, //绿色 0.0, 0.0, 1.0, 1.0, //蓝色 ]);
//这里为了方便观察,把顶点坐标设置在地球的表面 let position = Cesium.Cartesian3.fromDegrees(119.56985, 34.20513, 10000);
let points_pla = new Float64Array([ position.x, position.y, position.z, position.x + 10, position.y, position.z, position.x + 10, position.y + 10, position.z, ])
let geometry = generateGeometry(points_pla,colors_pla,new Uint16Array([0, 1, 2]))
// let geometry = generateGeometry(instan.positions,instan.style.color,[0,1,2]) console.log('geometry',geometry)
//将geometry添加到场景中 let primitive = new Cesium.Primitive({ geometryInstances: geometry, appearance: new Cesium.PerInstanceColorAppearance({ flat: true, translucent: false, }), asynchronous: false, })
console.log(Cesium.SuperMapVersion, 'cesium版本号');//41409 cesium版本号
console.log('primitive',primitive) viewer.value.scene.primitives.add(primitive)
function generateGeometry(realPos, __colors, __indices){
/** * 构造 几何体的 内部属性 */
var attributes = new Cesium.GeometryAttributes({ position: new Cesium.GeometryAttribute({ componentDatatype: Cesium.ComponentDatatype.DOUBLE, componentsPerAttribute: 3, values: new Float64Array(realPos), }), color: new Cesium.GeometryAttribute({ componentDatatype: Cesium.ComponentDatatype.FLOAT, componentsPerAttribute: 4, values: new Float32Array(__colors), }), }) //包围球 var boundingSphere = Cesium.BoundingSphere.fromVertices( realPos, new Cesium.Cartesian3(0.0, 0.0, 0.0), 3 ) // console.log(boundingSphere) // 计算顶点法向量 var geometry = new Cesium.Geometry({ attributes: attributes, indices: __indices, primitiveType: Cesium.PrimitiveType.TRIANGLES, boundingSphere: boundingSphere, }) return geometry }