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)
ClippingPlane objects instead of Plane.But there will be new problems,The dynamic change of distance or normal ,tileset doesn't changevar allClippingPlanes = [ 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) ];
var midPoint = self.viewer.entities.add({
position : midPosition,
point : {
pixelSize : 0
}
});
tileset.clippingPlanes = new Cesium.ClippingPlaneCollection({ modelMatrix : midPoint.computeModelMatrix(Cesium.JulianDate.now()), planes : allClippingPlanes, edgeWidth : 1.0, edgeColor : Color.WHITE });
The source file is too large, I cut part of it to upload.
var scratchPlane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0);
function createPlaneUpdateFunction(plane, transform) {
return function () {
plane.distance = targetY;
return Cesium.Plane.transform(plane, transform, scratchPlane);
};
}
var tileset;
function loadTileset(url) {
var clippingPlanes = [
new Cesium.Plane(new Cesium.Cartesian3(0.0, -1,0.0), -10.0)
];
tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url : "../../../data/Tileset/Tileset1/tileset.json",
clippingPlanes : new Cesium.ClippingPlaneCollection({
planes : clippingPlanes,
edgeWidth : viewModel.edgeStylingEnabled ? 1.0 : 0.0
})
}));
tileset.debugShowBoundingVolume = viewModel.debugBoundingVolumesEnabled;
return tileset.readyPromise.then(function() {
var boundingSphere = tileset.boundingSphere;
var 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() {
var boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius * 2));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
});
for (var i = 0; i < clippingPlanes.length; ++i) {
var plane = clippingPlanes[i];
var 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);
});
}Then I replace Plane with clippingPlane
You need to pull far and try several times
var viewer = new Cesium.Viewer('cesiumContainer');
var tileset = new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(3836)
});
viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset);
tileset.readyPromise.then(function(tileset) {
var clippingPlanes = [
new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, -1.0, 0), -100.0)
];
tileset.clippingPlanes = new Cesium.ClippingPlaneCollection({
planes : clippingPlanes,
edgeWidth :1
});
});
document.getElementById("removeClip").addEventListener('click',function(){
tileset.clippingPlanes.removeAll();
});
document.getElementById("addClip").addEventListener('click',function(){
var clippingPlanes = [
new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, -1.0, 0), -100.0)
];
tileset.clippingPlanes = new Cesium.ClippingPlaneCollection({
planes : clippingPlanes,
edgeWidth :1
});
});
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"> <button id="removeClip" style="position:'absolute';top:140px;left:40px;">remove</button>
<button id="addClip" style="position:'absolute';top:140px;left:60px;">add</button></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>