我想用銫繪製三角形,其中每個頂點是具有(lon,lat,alt)的地理點以及具有不同顏色的每個頂點。但我收到錯誤。我是Cesium的新手,我想我必須做的是定義一個幾何實例並將其附加到場景中。我的代碼是:使用銫繪製三角形時出現錯誤
var viewer = new Cesium.Viewer('cesiumContainer');
var mypositions = Cesium.Cartesian3.fromDegreesArrayHeights([104.317776, 31.59491, 10,
105.317776, 32.59491, 20,
106.317776, 33.59491, 30]);
var pos = new Float64Array(mypositions);
var geometry = new Cesium.Geometry({
attributes: {
position: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.FLOAT,
componentsPerAttribute: 3,
values: pos
}),
normal: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.FLOAT,
componentsPerAttribute: 3,
values: new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0])
})
},
indices: new Uint32Array([0, 1, 2]),
primitiveType: Cesium.PrimitiveType.TRIANGLES,
boundingSphere: Cesium.BoundingSphere.fromVertices(pos)
});
var myInstance = new Cesium.GeometryInstance({
geometry: geometry,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED)
},
show : new Cesium.ShowGeometryInstanceAttribute(true)
});
viewer.scene.primitives.add(new Cesium.Primitive({
geometryInstances: [myInstance],
appearance: new Cesium.PerInstanceColorAppearance({
closed: true,
translucent: false
})
}));
但後來我得到我的網頁上的錯誤:
DeveloperError: All attribute lists must have the same number of attributes.
我想知道我做錯了,我怎麼能解決這個問題呢?