1. A concise explanation of the problem you're experiencing.
When custom Geometry, the color corresponding to the attributes in the attributes attribute is what I set, and I set the PerInstanceColorAppearance and EllipsoidSurfaceAppearance errors.
Error is as follows
Appearance/Geometry mismatch. The appearance requires vertex shader attribute input 'compressedAttributes', which was not computed as part of the Geometry. Use the appearance's vertexFormat property when constructing the geometry.
2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
The code for the coordinates and color of each point has been written, but it is too long and is not written here. The data has been tested correctly. You can use geometry without st. The following is the method of loading, I don't know why this will be wrong.
var positions = new Float64Array(6 * 2 * 3 * 3);
var colors = new Float64Array(6 * 2 * 3 * 4);
var attributes = new Cesium.GeometryAttributes({
position: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.DOUBLE,
componentsPerAttribute: 3,
values: positions
}),
color: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.UNSIGEND_SHORT,
componentsPerAttribute: 4,
values: colors
})
})
var geometry = new Cesium.Geometry({
attributes: attributes,
indices: indices,
primitiveType: Cesium.PrimitiveType.TRIANGLES,
vertexFormat: new Cesium.VertexFormat({
position: true,
color: true
})
boundingSphere: Cesium.BoundingSphere.fromPoints(ps)
});
viewer.scene.primitives.add(new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: geometry
}),
asynchronous: false,
appearance: new Cesium.PerInstanceColorAppearance()
}))
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
I want to implement a cube, 6 faces are different colors, please tell me how to use the color attribute of the attributes in Geometry
4. The Cesium version you're using, your operating system and browser.
Cesium1.54
windows64
Google Chrome
Sorry, I accidentally posted a link to the localhost Sandcastle. This is the hosted one:
It looks like the problem is that your geometry isn’t computing normals but the appearance expects it by default. I discovered this by first passing compressVertices: false in the Primitive constructor, and then I could see the missing normals error. You can’t directly choose the vertex format of the PerInstanceColorAppearance, but if you set flat : true it will use a vertexFormat that doesn’t have normals. So just change:
appearance: new Cesium.PerInstanceColorAppearance()
``
into:
appearance: new Cesium.PerInstanceColorAppearance({
According to the method you said, there is no error, but the geometry that appears is white, not the effect I want. I added random color values to each vertex, and I hope that the effect is that the colors of each face are different. Please tell me how to change this code to achieve, thank you!