// 创建平面
const planeGeometry = new Cesium.PlaneGeometry({
vertexFormat: Cesium.VertexFormat.POSITION_AND_ST, // 位置和UV
});
const geometry = Cesium.PlaneGeometry.createGeometry(planeGeometry);
// [3]-----[2]
// | |
// [0]-----[1]
geometry.attributes.colors = new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.FLOAT,
componentsPerAttribute: 3,
values: [
1,0,0,
0,1,0,
1,1,0,
0,0,1,
],
});
// 创建材质
const material = new Cesium.Material({
fabric: {
uniforms: {
// color2: new Cesium.Color(.0, 1.0, 0.0, 1.0),
// image: "../../public/images/marker.png"
},
source: `
czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);
// vec2 st = materialInput.st;
// vec4 colorImage = texture(image, st);
// material.alpha = colorImage.a;
// material.diffuse = colorImage.rgb;
return material;
}`
},
});
const center = Cesium.Cartesian3.fromDegrees(106, 26, 10)
const translateMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
const dimensions = new Cesium.Cartesian3(400.0, 400.0, 1.0);
const scaleMatrix = Cesium.Matrix4.fromScale(dimensions);
const modelMatrix = new Cesium.Matrix4();
Cesium.Matrix4.multiply(translateMatrix, scaleMatrix, modelMatrix);
const plane = new Cesium.Primitive({
asynchronous: false,
geometryInstances: new Cesium.GeometryInstance({
geometry: geometry,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.BLUE)
},
modelMatrix
}),
appearance: new Cesium.MaterialAppearance({
material: material,
vertexShaderSource: `
in vec3 position3DHigh;
in vec3 position3DLow;
in vec3 normal;
in vec2 st;
in float batchId;
// instance attribute
in vec4 color;
// geometry attribute
in vec4 colors;
out vec3 v_positionEC;
out vec3 v_normalEC;
out vec2 v_st;
out vec4 v_color;
void main() {
vec4 p = czm_computePosition();
v_positionEC = (czm_modelViewRelativeToEye * p).xyz;
v_normalEC = czm_normal * normal;
v_st = st;
v_color = colors;
gl_Position = czm_modelViewProjectionRelativeToEye * p;
}
`,
fragmentShaderSource: `
in vec2 v_st;
in vec4 v_color;
void main() {
out_FragColor = vec4(v_color.rgb, 1.);
}
`
}),
show: true,
})
viewer.scene.primitives.add(plane);
04-26
04-03
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交