tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url : tile_url,
clippingPlanes : new Cesium.ClippingPlaneCollection({
planes : [
new Cesium.Plane(new Cesium.Cartesian3(1.0, 0.0, 0.0), 0),
new Cesium.Plane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), 0),
new Cesium.Plane(new Cesium.Cartesian3(0.0, 1.0, 0.0), 0),
new Cesium.Plane(new Cesium.Cartesian3(0.0, -1.0, 0.0), 0),
new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, -1.0), 0)
],
unionClippingRegions : true
})
}));
tileset.debugShowBoundingVolume = viewModel.debugBoundingVolumesEnabled;
return tileset.readyPromise.then(function() {
let boundingSphere = tileset.boundingSphere;
let radius = boundingSphere.radius;
// viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.5, -0.2, radius * 4.0));
tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(boundingSphere.center);
tileset.readyPromise.then(function() {
let boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius * 2));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
});
for (let i = 0; i < clippingPlanes.length; ++i) {
let plane = clippingPlanes[i];
let planeEntity = viewer.entities.add({
position : boundingSphere.center,
plane : {
dimensions : new Cesium.Cartesian2(radius 2.5, radius 2.5),
material : Cesium.Color.WHITE.withAlpha(0.1),
plane : new Cesium.CallbackProperty(createPlaneUpdateFunction(plane, tileset.modelMatrix), false),
outline : true,
outlineColor : Cesium.Color.WHITE
}
});
planeEntities.push(planeEntity);
}
return tileset;
}).otherwise(function(error) {
console.log(error);
});
tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url : tile_url,
clippingPlanes : new Cesium.ClippingPlaneCollection({
planes : [
new Cesium.Plane(new Cesium.Cartesian3(1.0, 0.0, 0.0), 0
)
],
// unionClippingRegions : true
})
}));
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" } } ] } ] }}
tileset.clippingPlanes = new Cesium.ClippingPlaneCollection({ planes : clippingPlanes, unionClippingRegions : true, edgeColor: Cesium.Color.WHITE,
modelMatrix: Cesium.Matrix4.inverse(tileset._initialClippingPlanesOriginMatrix, new Cesium.Matrix4()) });