原文链接及内容

效果如下图所示:

示例代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const viewer = new Cesium.Viewer("cesiumContainer");

try {
const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(75343, {
customShader: new Cesium.CustomShader({
/**
* 光照模型:
* - UNLIT: unlight,即无光照
* - PBR: 使用基于物理的渲染光照计算。这包括 PBR 金属粗糙度和 PBR 镜面光泽度。
*/
lightingModel: Cesium.LightingModel.UNLIT,
//根据与相机的距离对瓦片进行着色
fragmentShaderText: `
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
{
material.diffuse = vec3(0.0, 0.0, 1.0);
material.diffuse.g = -fsInput.attributes.positionEC.z / 1.0e4;
}
`,
}),
});
viewer.scene.primitives.add(tileset);
} catch (error) {
console.log(`瓦片加载出现错误: ${error}`);
}

const initialPosition = Cesium.Cartesian3.fromDegrees(
-74.01881302800248,
40.69114333714821,
753,
);
const initialOrientation = new Cesium.HeadingPitchRoll.fromDegrees(
21.27879878293835,
-21.34390550872461,
0.0716951918898415,
);
viewer.scene.camera.setView({
destination: initialPosition,
orientation: initialOrientation,
endTransform: Cesium.Matrix4.IDENTITY,
});