I have a requirement to display a complete image of a polygon on terrain and 3D Tiles. Since the polygon is irregular, I need to define textureCoordinates. However, after adding them, the ClassificationType.BOTHbecomes ineffective.
const entity = new Cesium.Entity({
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return new Cesium.PolygonHierarchy(positions);
}, false),
material: new Cesium.ImageMaterialProperty({
image: image1,
transparent: true,
}),
classificationType: Cesium.ClassificationType.BOTH,
extrudedHeight: 0,
height: 0,
textureCoordinates: new Cesium.PolygonHierarchy([
new Cesium.Cartesian2(0, 0),
new Cesium.Cartesian2(1, 0),
new Cesium.Cartesian2(1, 1),
new Cesium.Cartesian2(0, 1),
]),
},
});
viewer.entities.add(entity);
Another test: using a primitive and also adding textureCoordinates. The terrain and 3D Tiles are covered, but the material is not displayed completely.
// I need custom display effects, so I defined a shader.
const appearance = new Cesium.MaterialAppearance({
material: const material = new Cesium.Material({
fabric: {
type: “custom1”,
uniforms: {
image: image1,
},
source: shader1,
},
translucent: false,
}),
});
const uvs = [0, 0, 1, 0, 1, 1, 0, 1];
const textureCoordPositions = ;
for (let i = 0; i < positions.length; i++) {
const u = uvs[i * 2];
const v = uvs[i * 2 + 1];
textureCoordPositions.push(new Cesium.Cartesian2(u, v));
}
let instance = new Cesium.GeometryInstance({
geometry: new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy(positions),
extrudedHeight: 0,
perPositionHeight: true,
vertexFormat:
Cesium.MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat,
textureCoordinates: {
positions: [
new Cesium.Cartesian2(0, 0),
new Cesium.Cartesian2(1, 0),
new Cesium.Cartesian2(1, 1),
new Cesium.Cartesian2(0, 1),
],
},
}),
});
const primitive = new Cesium.GroundPrimitive({
appearance: this.appearance,
geometryInstances: instance,
asynchronous: false,
});
viewer.scene.primitives.add(primitive);
The core issue is still that terrain draping and textureCoordinatescannot be enabled simultaneously.
I prefer primitive, it can customize the shape through material
How to solve this problem?
