3d-tiles & Clipping Planes

Hi Omar,

Fantastic advice as usual, thanks very much… We have made some progress, however I think we are getting something wrong with the inverse transformation? We can successfully trim the globe based on our polygon edges as seen above, but the tileset disappears entirely with the following code. Below the js snippet is an example tileset.json if it is of any help?

Thanks in advance,
Josh

let pts = positions;

let pointsLength = pts.length - 1;

let clippingPlanes = ;

for (let i = 0; i < pointsLength; ++i) {

let nextIndex = (i + 1) % pointsLength;

let midpoint = Cesium.Cartesian3.add(pts[i], pts[nextIndex], new Cesium.Cartesian3());

midpoint = Cesium.Cartesian3.multiplyByScalar(midpoint, 0.5, midpoint);

let up = Cesium.Cartesian3.normalize(midpoint, new Cesium.Cartesian3());

let right = Cesium.Cartesian3.subtract(pts[nextIndex], midpoint, new Cesium.Cartesian3());

right = Cesium.Cartesian3.normalize(right, right);

let normal = Cesium.Cartesian3.cross(right, up, new Cesium.Cartesian3());

normal = Cesium.Cartesian3.normalize(normal, normal);

let originCenteredPlane = new Cesium.Plane(normal, 0.0);

let distance = Cesium.Plane.getPointDistance(originCenteredPlane, midpoint);

clippingPlanes.push(new Cesium.ClippingPlane(normal, distance));

}

console.log(clippingPlanes);

viewer.scene.globe.clippingPlanes = new Cesium.ClippingPlaneCollection({

planes : clippingPlanes,

edgeColor: Cesium.Color.WHITE,

unionClippingRegions : true,

});

tileset.clippingPlanes = new Cesium.ClippingPlaneCollection({

planes : clippingPlanes,

unionClippingRegions : true,

edgeColor: Cesium.Color.WHITE,

modelMatrix: Cesium.Matrix4.inverse(tileset.root.computedTransform, new Cesium.Matrix4())

});

``

{

“asset”: {

“version”: “0.0”,

“gltfUpAxis”: “Y”

},

“geometricError”: 49.7341114741387997,

“root”: {

“boundingVolume”: {

“sphere”: [

-4632209.9893530942499638,

2581120.2956524640321732,

-3532187.1000989843159914,

49.7341114741387642

]

},

“refine”: “REPLACE”,

“geometricError”: 49.7341114741387997,

“children”: [

{

“boundingVolume”: {

“sphere”: [

-4632216.1126385899260640,

2581116.8207813599146903,

-3532179.5933731999248266,

18.6634587549551014

]

},

“geometricError”: 18.6634587549551014,

“children”: [

{

“boundingVolume”: {

“sphere”: [

-4632216.1126385899260640,

2581116.8207813599146903,

-3532179.5933731999248266,

18.6634587549551014

]

},

“geometricError”: 1,

“content”: {

“url”: “Data/Tile_2/Tile_2.json”

}

}

]

},

{

“boundingVolume”: {

“sphere”: [

-4632211.8696897998452187,

2581111.7691548001021147,

-3532189.5037792301736772,

11.4677779945705005

]

},

“geometricError”: 11.4677779945705005,

“children”: [

{

“boundingVolume”: {

“sphere”: [

-4632211.8696897998452187,

2581111.7691548001021147,

-3532189.5037792301736772,

11.4677779945705005

]

},

“geometricError”: 0.5000000000000000,

“content”: {

“url”: “Data/Tile_3/Tile_3.json”

}

}

]

},

{

“boundingVolume”: {

“sphere”: [

-4632203.1482633799314499,

2581123.9984698197804391,

-3532194.5363906701095402,

13.1519037570412998

]

},

“geometricError”: 13.1519037570412998,

“children”: [

{

“boundingVolume”: {

“sphere”: [

-4632203.1482633799314499,

2581123.9984698197804391,

-3532194.5363906701095402,

13.1519037570412998

]

},

“geometricError”: 0.5000000000000000,

“content”: {

“url”: “Data/Tile_5/Tile_5.json”

}

}

]

},

{

“boundingVolume”: {

“sphere”: [

-4632205.6490913899615407,

2581110.9178494098596275,

-3532203.7913987198844552,

16.8360943859069003

]

},

“geometricError”: 16.8360943859069003,

“children”: [

{

“boundingVolume”: {

“sphere”: [

-4632205.6490913899615407,

2581110.9178494098596275,

-3532203.7913987198844552,

16.8360943859069003

]

},

“geometricError”: 0.5000000000000000,

“content”: {

“url”: “Data/Tile_4/Tile_4.json”

}

}

]

},

{

“boundingVolume”: {

“sphere”: [

-4632223.5277511803433299,

2581119.7752239098772407,

-3532165.6262226500548422,

17.6053403882662991

]

},

“geometricError”: 17.6053403882662991,

“children”: [

{

“boundingVolume”: {

“sphere”: [

-4632223.5277511803433299,

2581119.7752239098772407,

-3532165.6262226500548422,

17.6053403882662991

]

},

“geometricError”: 1,

“content”: {

“url”: “Data/Tile_1/Tile_1.json”

}

}

]

},

{

“boundingVolume”: {

“sphere”: [

-4632196.2920495299622416,

2581123.8337095598690212,

-3532207.7433422501198947,

14.1507573095964005

]

},

“geometricError”: 14.1507573095964005,

“children”: [

{

“boundingVolume”: {

“sphere”: [

-4632196.2920495299622416,

2581123.8337095598690212,

-3532207.7433422501198947,

14.1507573095964005

]

},

“geometricError”: 0.5000000000000000,

“content”: {

“url”: “Data/Tile_6/Tile_6.json”

}

}

]

}

]

}

}

``