Clipping Google photorealistic tiles does'nt work

I have a polygon which I use to clip the 3D Tileset. and the clipping works for all other tileset except Google photorealistic tiles. Can anybody explain why is this happening.
existing code of clipping

 tileset.clippingPlanes = new Cesium.ClippingPlaneCollection({
    planes: clippingPlanes,
    edgeColor: Cesium.Color.WHITE,
    unionClippingRegions: false,
    enabled: true,
    // model matrix for tileset.root.computedTransform identity
    modelMatrix: Cesium.Matrix4.inverse(
      tileset._initialClippingPlanesOriginMatrix,
      new Cesium.Matrix4()
    ),
    /*
    // model matrix for tileset.root.computedTransform with value  
    modelMatrix: Cesium.Matrix4.inverse(
      tileset.root.computedTransform,
      new Cesium.Matrix4()
    ), */
  })
2 Likes

using cesium 1.92

1 Like

Hi @saadat2930, can you provide a Sandcastle link demonstrating the problem? It is hard to understand the problem from your snippet, since it doesn’t show how clippingPlanes was defined.

1 Like

Hi @jjhembd
Thanks, the issue was on my side. here is my working code for anyone clipping 3d tileset using geojson.

const clipTileSet = async (tileset: any) => {
    const clockwiseCheck = booleanClockwise(lot.geoJSON.geometry.coordinates[0]);
    const coordinates: any[] = [];
    if (clockwiseCheck) {
      for (let i = lot.geoJSON.geometry.coordinates[0].length - 1; i > 0; i--) {
        coordinates.push(lot.geoJSON.geometry.coordinates[0][i]);
      }
    } else {
      lot.geoJSON.geometry.coordinates[0].forEach((coords, index) => {
        if (index !== lot.geoJSON.geometry.coordinates[0].length - 1) {
          coordinates.push([coords[0], coords[1]]);
        }
      });
    }
    const hole_pts: any[] = [];
    const pts: any[] = [];
    coordinates.forEach((coords, index) => {
      //@ts-expect-error
      hole_pts.push(new Cartesian3.fromDegrees(coords[0], coords[1]));
    });
    const terrainPositions = await getTerrElevationforPoints(viewer, hole_pts);
    terrainPositions.forEach((coords, index) => {
      //@ts-expect-error
      pts.push(new Cartesian3.fromRadians(coords.longitude, coords.latitude, coords.height));
    });
    const clippingPlanes = [];
    const pointsLength = pts.length - 1;
    for (let i = 0; i < pointsLength; ++i) {
      const nextIndex = (i + 1) % pointsLength;
      let midpoint = Cartesian3.add(pts[i], pts[nextIndex], new Cartesian3());
      midpoint = Cartesian3.multiplyByScalar(midpoint, 0.5, midpoint);
      const up = Cartesian3.normalize(midpoint, new Cartesian3());
      let right = Cartesian3.subtract(pts[nextIndex], midpoint, new Cartesian3());
      right = Cartesian3.normalize(right, right);
      let normal = Cartesian3.cross(right, up, new Cartesian3());
      normal = Cartesian3.normalize(normal, normal);
      /*       const originCenteredPlane = new Plane(normal, 0.0);
      const distance = Plane.getPointDistance(originCenteredPlane, midpoint);
      clippingPlanes.push(new ClippingPlane(normal, distance)); */
      //@ts-expect-error
      const plane: any = new Plane.fromPointNormal(midpoint, normal);
      const clippingPlane: any = ClippingPlane.fromPlane(plane);
      clippingPlanes.push(clippingPlane);
    }

    if (globe) {
      globe.clippingPlanes = new ClippingPlaneCollection({
        planes: clippingPlanes,
        edgeColor: Color.WHITE,
      });
    }
    tileset.clippingPlanes = new ClippingPlaneCollection({
      planes: clippingPlanes,
      edgeColor: Color.WHITE,
      unionClippingRegions: false,
      enabled: true,
      modelMatrix: Matrix4.inverse(tileset._initialClippingPlanesOriginMatrix, new Matrix4()),
    });
  };
1 Like

Is there anyway to clip/mask an area of the Google photorealistic tiles? Or does this code work with Google photorealistic tiles?
I have a new 3D building that I’m showing, but the trees are sticking through it currently. Thanks!