挖洞
loading
虽然我不明白地形挖洞有什么应用,但既然 cesium 有这个能力,three-tile 也需要有。
挖洞是利用了 threejs 的 clipping 功能,用四个剪裁面围成一个矩形实现,当然你也可以剪裁出其它形状的洞。
ts
viewer.renderer.localClippingEnabled = true;
const bounds = [108.6880874, 33.921995, 108.882408, 34.057271];
const sw = map.geo2world(new THREE.Vector3(bounds[0], bounds[1]));
const ne = map.geo2world(new THREE.Vector3(bounds[2], bounds[3]));
const clipPlanes = [new THREE.Plane(new THREE.Vector3(-1, 0, 0), sw.x), new THREE.Plane(new THREE.Vector3(1, 0, 0), -ne.x), new THREE.Plane(new THREE.Vector3(0, 0, 1), -sw.z), new THREE.Plane(new THREE.Vector3(0, 0, -1), ne.z)];
map.addEventListener("tile-loaded", (evt) => {
const materails = evt.tile.model?.material;
materails?.forEach((m) => {
m.clipIntersection = true;
m.clippingPlanes = clipPlanes;
});
});