I am trying to draw a triangle and rotate with an snglle. I use React, cesium, resium with javascript.
I tries to use chatgpt to find a way but always get an error (tried Primitive etc)
Do you have a simple code that you know that works with which I czn use to draw triangle?
Thanks
Here’s Sample code
const {
BoundingSphere,
Cartesian3,
Color,
ColorGeometryInstanceAttribute,
ComponentDatatype,
GeometryAttribute,
GeometryInstance,
PerInstanceColorAppearance,
Primitive,
PrimitiveType,
Viewer
} = window.Cesium;
const viewer = new Viewer("cesiumContainer", {});
const firstVertex = Cartesian3.fromDegrees(-115.0, 37.0);
const secondVertex = Cartesian3.fromDegrees(-115.0, 32.0);
const thirdVertex = Cartesian3.fromDegrees(-107.0, 33.0);
const positions = [firstVertex, secondVertex, thirdVertex];
const rawPositions = [
firstVertex.x,
firstVertex.y,
firstVertex.z,
secondVertex.x,
secondVertex.y,
secondVertex.z,
thirdVertex.x,
thirdVertex.y,
thirdVertex.z
];
const index = [0, 1, 2];
const position = new GeometryAttribute({
componentDatatype: ComponentDatatype.DOUBLE,
componentsPerAttribute: 3,
values: new Float64Array(rawPositions)
});
const trianglePrimitive = new Primitive({
geometryInstances: new GeometryInstance({
geometry: new Cesium.Geometry({
attributes: {
position: position
// normal: normal,
// st: st
},
indices: new Uint16Array(index),
primitiveType: PrimitiveType.TRIANGLES,
boundingSphere: BoundingSphere.fromVertices(rawPositions)
}),
attributes: {
color: ColorGeometryInstanceAttribute.fromColor(Color.RED)
}
}),
appearance: new PerInstanceColorAppearance({
flat: true,
closed: true,
translucent: false
}),
asynchronous: false
});
viewer.scene.primitives.add(trianglePrimitive);