nytimes / three-loader-3dtiles

This is a Three.js loader module for handling OGC 3D Tiles, created by Cesium. It currently supports the two main formats, Batched 3D Model (b3dm) - based on glTF Point cloud.
Other
454 stars 64 forks source link

About Clipping 3dtiles #165

Open AHSss opened 4 months ago

AHSss commented 4 months ago

I want Clip the model,Here is what I tried

const clipPlanes = [
    new THREE.Plane(new THREE.Vector3(1, 0, 0), -50),
    new THREE.Plane(new THREE.Vector3(-1, 0, 0), -50),
    new THREE.Plane(new THREE.Vector3(0, 0, -1), -10),
    new THREE.Plane(new THREE.Vector3(0, 0, 1), -10),
]
const animate = () => {
    deltaTime.value = colck.getDelta()
    if (tilesRuntime.value) {
        console.log(tilesRuntime.value)
        scene.traverse((obj: any) => {
            if (obj.type == "Mesh") {
                if (obj.material.length > 1) {
                    obj.material.forEach((element: any) => {
                        element.clippingPlanes = clipPlanes;
                        element.clipIntersection = true;
                    });
                } else {
                    obj.material.clippingPlanes = clipPlanes;
                    obj.material.clipIntersection = true;
                }
            }
        })
        tilesRuntime.value.update(deltaTime.value, renderer, camera)
    }
    renderer.render(scene, camera);
    requestAnimationFrame(animate);
}

I got the effect I wanted, but I put the clip's code in the animate, This may seem like a poor performance. Is there a better way?@wanyanyan @Avnerus image

Avnerus commented 4 months ago

Hi! Check the contentPostProcess option. It allows you to run a callback after each tile mesh is processed.

Even more efficient would be to avoid downloading tiles that are in the clipping range, but that requires hooking into the loaders.gl traversal.