Skip to content

Commit 6d55f29

Browse files
authored
Merge pull request #6201 from likangning93/clippingPlanesByTexture
Increase max clipping planes using textures
2 parents 4ad27a4 + 31c548b commit 6d55f29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2660
-700
lines changed

Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848

4949
// Add a clipping plane, a plane geometry to show the representation of the
5050
// plane, and control the magnitude of the plane distance with the mouse.
51-
// Clipping planes are not currently supported in Internet Explorer.
5251

5352
var viewer = new Cesium.Viewer('cesiumContainer', {
5453
infoBox: false,
@@ -103,7 +102,7 @@
103102
}
104103
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
105104

106-
var scratchPlane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0);
105+
var scratchPlane = new Cesium.ClippingPlane(Cesium.Cartesian3.UNIT_X, 0.0);
107106
function createPlaneUpdateFunction(plane, transform) {
108107
return function () {
109108
plane.distance = targetY;
@@ -114,7 +113,7 @@
114113
var tileset;
115114
function loadTileset(url) {
116115
var clippingPlanes = [
117-
new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, -1.0), -100.0)
116+
new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 0.0, -1.0), -100.0)
118117
];
119118

120119
tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
@@ -156,7 +155,7 @@
156155
var modelEntityClippingPlanes;
157156
function loadModel(url) {
158157
var clippingPlanes = [
159-
new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, -1.0), -100.0)
158+
new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 0.0, -1.0), -100.0)
160159
];
161160

162161
modelEntityClippingPlanes = new Cesium.ClippingPlaneCollection({

Apps/Sandcastle/gallery/Terrain Clipping Planes.html

+4-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
'use strict';
4141
//Sandcastle_Begin
4242
// Use clipping planes to selectively hide parts of the globe surface.
43-
// Clipping planes are not currently supported in Internet Explorer.
4443

4544
var viewer = new Cesium.Viewer('cesiumContainer', {
4645
skyAtmosphere: false,
@@ -74,10 +73,10 @@
7473
globe.clippingPlanes = new Cesium.ClippingPlaneCollection({
7574
modelMatrix : entity.computeModelMatrix(Cesium.JulianDate.now()),
7675
planes : [
77-
new Cesium.Plane(new Cesium.Cartesian3( 1.0, 0.0, 0.0), -700.0),
78-
new Cesium.Plane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), -700.0),
79-
new Cesium.Plane(new Cesium.Cartesian3( 0.0, 1.0, 0.0), -700.0),
80-
new Cesium.Plane(new Cesium.Cartesian3( 0.0, -1.0, 0.0), -700.0)
76+
new Cesium.ClippingPlane(new Cesium.Cartesian3( 1.0, 0.0, 0.0), -700.0),
77+
new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), -700.0),
78+
new Cesium.ClippingPlane(new Cesium.Cartesian3( 0.0, 1.0, 0.0), -700.0),
79+
new Cesium.ClippingPlane(new Cesium.Cartesian3( 0.0, -1.0, 0.0), -700.0)
8180
],
8281
edgeWidth: 1.0,
8382
edgeColor: Cesium.Color.WHITE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
7+
<meta name="description" content="Use Viewer to start building new applications or easily embed Cesium into existing applications.">
8+
<meta name="cesium-sandcastle-labels" content="Beginner, Showcases">
9+
<title>Cesium Demo</title>
10+
<script type="text/javascript" src="../Sandcastle-header.js"></script>
11+
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
12+
<script type="text/javascript">
13+
if(typeof require === "function") {
14+
require.config({
15+
baseUrl : '../../../Source',
16+
waitSeconds : 120
17+
});
18+
}
19+
</script>
20+
</head>
21+
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
22+
<style>
23+
@import url(../templates/bucket.css);
24+
</style>
25+
<div id="cesiumContainer" class="fullSize"></div>
26+
<div id="loadingOverlay"><h1>Loading...</h1></div>
27+
<div id="toolbar">
28+
<table><tbody>
29+
<tr>
30+
<td>Distance</td>
31+
<td>
32+
<input type="range" min="-100.0" max="100.0" step="1.0" data-bind="value: cylinderRadius, valueUpdate: 'input'">
33+
<input type="text" size="5" data-bind="value: cylinderRadius">
34+
</td>
35+
<td>Plane Count</td>
36+
<td>
37+
<input type="range" min="1" max="128" step="1" data-bind="value: planeCount, valueUpdate: 'input'">
38+
<input type="text" size="5" data-bind="value: planeCount">
39+
</td>
40+
</tr>
41+
</tbody></table>
42+
<select data-bind="options: exampleTypes, value: currentExampleType"></select>
43+
</div>
44+
<script id="cesium_sandcastle_script">
45+
function startup(Cesium) {
46+
'use strict';
47+
//Sandcastle_Begin
48+
var viewer = new Cesium.Viewer('cesiumContainer', {
49+
infoBox: false,
50+
selectionIndicator: false,
51+
shouldAnimate : true,
52+
projectionPicker : true
53+
});
54+
55+
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
56+
url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
57+
requestWaterMask : true,
58+
requestVertexNormals : true
59+
});
60+
viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin);
61+
62+
var globe = viewer.scene.globe;
63+
globe.depthTestAgainstTerrain = true;
64+
65+
var cylinderRadius = -20.0;
66+
var radiusMultiplier = 1.0;
67+
68+
var steps = 32;
69+
var clippingPlanes = [];
70+
var modelEntityClippingPlanes;
71+
var clippingModeUnion = false;
72+
var enabled = true;
73+
74+
var clipObjects = ['model', 'b3dm', 'pnts', 'i3dm', 'terrain'];
75+
var viewModel = {
76+
cylinderRadius : cylinderRadius,
77+
exampleTypes : clipObjects,
78+
currentExampleType : clipObjects[0],
79+
planeCount : steps
80+
};
81+
82+
Cesium.knockout.track(viewModel);
83+
84+
var toolbar = document.getElementById('toolbar');
85+
Cesium.knockout.applyBindings(viewModel, toolbar);
86+
87+
Cesium.knockout.getObservable(viewModel, 'cylinderRadius').subscribe(
88+
function(newValue) {
89+
cylinderRadius = parseFloat(viewModel.cylinderRadius);
90+
updatePlanes();
91+
}
92+
);
93+
94+
Cesium.knockout.getObservable(viewModel, 'planeCount').subscribe(
95+
function(newValue) {
96+
var newSteps = parseFloat(viewModel.planeCount);
97+
if (newSteps !== steps) {
98+
steps = newSteps;
99+
modelEntityClippingPlanes.removeAll();
100+
computePlanes();
101+
}
102+
}
103+
);
104+
105+
var scene = viewer.scene;
106+
var planeEntities = [];
107+
var selectedPlane;
108+
109+
function updatePlanes() {
110+
for (var i = 0; i < clippingPlanes.length; i++) {
111+
var plane = clippingPlanes[i];
112+
plane.distance = cylinderRadius * radiusMultiplier;
113+
}
114+
}
115+
116+
function computePlanes() {
117+
var stepDegrees = 6.28319 / steps;
118+
clippingPlanes = [];
119+
120+
for (var i = 0; i < steps; i++) {
121+
var angle = i * stepDegrees;
122+
var dir = new Cesium.Cartesian3();
123+
dir.x = 1.0;
124+
dir.y = Math.tan(angle);
125+
if (angle > 1.57079632679) {
126+
dir.x = -1.0;
127+
dir.y *= -1.0;
128+
}
129+
if (angle > 3.14159265359) {
130+
dir.x = -1.0;
131+
dir.y = dir.y;
132+
}
133+
if (angle > 4.71238898038) {
134+
dir.x = 1.0;
135+
dir.y = -dir.y;
136+
}
137+
Cesium.Cartesian3.normalize(dir, dir);
138+
var newPlane = new Cesium.ClippingPlane(dir, cylinderRadius * radiusMultiplier);
139+
modelEntityClippingPlanes.add(newPlane);
140+
clippingPlanes.push(newPlane);
141+
}
142+
}
143+
144+
function createClippingPlanes(modelMatrix) {
145+
modelEntityClippingPlanes = new Cesium.ClippingPlaneCollection({
146+
modelMatrix : Cesium.defined(modelMatrix) ? modelMatrix : Cesium.Matrix4.IDENTITY,
147+
edgeWidth: 2.0,
148+
edgeColor: Cesium.Color.WHITE,
149+
unionClippingRegions : clippingModeUnion,
150+
enabled : enabled
151+
});
152+
computePlanes();
153+
}
154+
155+
function updateClippingPlanes() {
156+
return modelEntityClippingPlanes;
157+
}
158+
159+
var modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb';
160+
var agiHqUrl = Cesium.IonResource.fromAssetId(3836);
161+
var instancedUrl = Cesium.IonResource.fromAssetId(3876);
162+
var pointCloudUrl = Cesium.IonResource.fromAssetId(3844);
163+
164+
function loadModel(url) {
165+
createClippingPlanes();
166+
var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 300.0);
167+
var heading = 0.0;
168+
var pitch = 0.0;
169+
var roll = 0.0;
170+
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
171+
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
172+
var entity = viewer.entities.add({
173+
name : url,
174+
position : position,
175+
orientation : orientation,
176+
model : {
177+
uri : url,
178+
scale : 20,
179+
minimumPixelSize : 100.0,
180+
clippingPlanes : new Cesium.CallbackProperty(updateClippingPlanes, false)
181+
}
182+
});
183+
viewer.trackedEntity = entity;
184+
}
185+
186+
var tileset;
187+
function loadTileset(url) {
188+
createClippingPlanes();
189+
tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
190+
url : url,
191+
clippingPlanes : modelEntityClippingPlanes
192+
}));
193+
194+
return tileset.readyPromise.then(function() {
195+
var boundingSphere = tileset.boundingSphere;
196+
197+
var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
198+
var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
199+
var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 100.0);
200+
var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
201+
tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
202+
203+
var radius = boundingSphere.radius;
204+
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.2, radius * 4.0));
205+
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
206+
}).otherwise(function(error) {
207+
throw(error);
208+
});
209+
}
210+
211+
loadModel(modelUrl);
212+
213+
Cesium.knockout.getObservable(viewModel, 'currentExampleType').subscribe(function(newValue) {
214+
reset();
215+
216+
if (newValue === clipObjects[0]) {
217+
// Model
218+
loadModel(modelUrl);
219+
} else if (newValue === clipObjects[1]) {
220+
// B3dm photogrammetry
221+
agiHqUrl.then(function(resource) {
222+
return loadTileset(resource);
223+
});
224+
} else if (newValue === clipObjects[2]) {
225+
// Point clouds
226+
radiusMultiplier = 20.0;
227+
pointCloudUrl.then(function(resource) {
228+
return loadTileset(resource);
229+
}).then(function() {
230+
tileset.pointCloudShading.attenuation = true;
231+
});
232+
} else if (newValue === clipObjects[3]) {
233+
// i3dm
234+
instancedUrl.then(function(resource) {
235+
return loadTileset(resource);
236+
}).then(function() {
237+
tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center);
238+
});
239+
} else if (newValue === clipObjects[4]) {
240+
// Terrain
241+
var position = Cesium.Cartesian3.fromRadians(-2.0872979473351286, 0.6596620013036164, 2380.0);
242+
var entity = viewer.entities.add({
243+
position : position,
244+
model : {
245+
uri : '../../SampleData/models/CesiumMan/Cesium_Man.glb',
246+
minimumPixelSize : 128,
247+
scale : 40
248+
}
249+
});
250+
viewer.trackedEntity = entity;
251+
createClippingPlanes(entity.computeModelMatrix(Cesium.JulianDate.now()));
252+
globe.clippingPlanes = modelEntityClippingPlanes;
253+
}
254+
updatePlanes();
255+
});
256+
257+
function reset() {
258+
radiusMultiplier = 1.0;
259+
viewModel.cylinderRadius = cylinderRadius;
260+
viewer.entities.removeAll();
261+
viewer.scene.primitives.removeAll();
262+
globe.clippingPlanes = undefined; // destroy Globe clipping planes, if any
263+
modelEntityClippingPlanes = undefined;
264+
}
265+
266+
Sandcastle.addToggleButton('union', clippingModeUnion, function(checked) {
267+
clippingModeUnion = checked;
268+
modelEntityClippingPlanes.unionClippingRegions = clippingModeUnion;
269+
});
270+
271+
Sandcastle.addToggleButton('enabled', enabled, function(checked) {
272+
enabled = checked;
273+
modelEntityClippingPlanes.enabled = enabled;
274+
});
275+
276+
//Sandcastle_End
277+
Sandcastle.finishedLoading();
278+
}
279+
if (typeof Cesium !== "undefined") {
280+
startup(Cesium);
281+
} else if (typeof require === "function") {
282+
require(["Cesium"], startup);
283+
}
284+
</script>
285+
</body>
286+
</html>
Loading

CHANGES.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ Change Log
33

44
### 1.44 - 2018-04-02
55

6+
##### Deprecated :hourglass_flowing_sand:
7+
* `ClippingPlaneCollection` is now supported in Internet Explorer, so `ClippingPlaneCollection.isSupported` has been deprecated and will be removed in Cesium 1.45.
8+
* `ClippingPlaneCollection` should now be used with `ClippingPlane` objects instead of `Plane`. Use of `Plane` objects has been deprecated and will be removed in Cesium 1.45.
9+
610
##### Additions :tada:
711
* Added support for glTF models with [Draco geometry compression](https://github.com/fanzhanggoogle/glTF/blob/KHR_mesh_compression/extensions/Khronos/KHR_draco_mesh_compression/README.md).
12+
* `ClippingPlaneCollection` updates [#6201](https://github.com/AnalyticalGraphicsInc/cesium/pull/6201)
13+
* Removed the 6-clipping-plane limit.
14+
* Added support for Internet Explorer.
15+
* Added a `ClippingPlane` object to be used with `ClippingPlaneCollection`.
816

917
##### Fixes :wrench:
1018
* Fixed support of glTF-supplied tangent vectors. [#6302](https://github.com/AnalyticalGraphicsInc/cesium/pull/6302)
1119
* Fixed improper zoom during model load failure. [#6305](https://github.com/AnalyticalGraphicsInc/cesium/pull/6305)
1220

1321
#### Additions :tada:
14-
* Updated `WebMapServiceImageryProvider` so it can take an srs or crs string to pass to the resource query parameters based on the WMS version. [#6223](https://github.com/AnalyticalGraphicsInc/cesium/issues/6223)
22+
* Updated `WebMapServiceImageryProvider` so it can take an srs or crs string to pass to the resource query parameters based on the WMS version. [#6223](https://github.com/AnalyticalGraphicsInc/cesium/issues/6223)
1523

1624
### 1.43 - 2018-03-01
1725

0 commit comments

Comments
 (0)