From afad284248211a67b4753e21e36e2ad4df3a7239 Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Mon, 30 Jan 2017 09:47:23 -0500
Subject: [PATCH 1/9] add show frustum planes to inspector
---
Source/Scene/DebugCameraPrimitive.js | 113 +++++++++++++++---
Source/Scene/FrameState.js | 4 +
Source/Scene/Scene.js | 42 +++++++
.../CesiumInspector/CesiumInspector.js | 9 ++
.../CesiumInspectorViewModel.js | 13 ++
5 files changed, 162 insertions(+), 19 deletions(-)
diff --git a/Source/Scene/DebugCameraPrimitive.js b/Source/Scene/DebugCameraPrimitive.js
index ffcf283e6cf1..7875b4930b3a 100644
--- a/Source/Scene/DebugCameraPrimitive.js
+++ b/Source/Scene/DebugCameraPrimitive.js
@@ -93,17 +93,13 @@ define([
}
var frustumCornersNDC = new Array(8);
- frustumCornersNDC[0] = new Cartesian4(-1.0, -1.0, -1.0, 1.0);
- frustumCornersNDC[1] = new Cartesian4(1.0, -1.0, -1.0, 1.0);
- frustumCornersNDC[2] = new Cartesian4(1.0, 1.0, -1.0, 1.0);
- frustumCornersNDC[3] = new Cartesian4(-1.0, 1.0, -1.0, 1.0);
- frustumCornersNDC[4] = new Cartesian4(-1.0, -1.0, 1.0, 1.0);
- frustumCornersNDC[5] = new Cartesian4(1.0, -1.0, 1.0, 1.0);
- frustumCornersNDC[6] = new Cartesian4(1.0, 1.0, 1.0, 1.0);
- frustumCornersNDC[7] = new Cartesian4(-1.0, 1.0, 1.0, 1.0);
+ frustumCornersNDC[0] = new Cartesian4(-1.0, -1.0, 1.0, 1.0);
+ frustumCornersNDC[1] = new Cartesian4(1.0, -1.0, 1.0, 1.0);
+ frustumCornersNDC[2] = new Cartesian4(1.0, 1.0, 1.0, 1.0);
+ frustumCornersNDC[3] = new Cartesian4(-1.0, 1.0, 1.0, 1.0);
var scratchMatrix = new Matrix4();
- var scratchFrustumCorners = new Array(8);
+ var scratchFrustumCorners = new Array(4);
for (var i = 0; i < 8; ++i) {
scratchFrustumCorners[i] = new Cartesian4();
}
@@ -130,14 +126,28 @@ define([
var viewProjection = Matrix4.multiply(projection, view, scratchMatrix);
var inverseViewProjection = Matrix4.inverse(viewProjection, scratchMatrix);
- var positions = new Float64Array(8 * 3);
- for (var i = 0; i < 8; ++i) {
- var corner = Cartesian4.clone(frustumCornersNDC[i], scratchFrustumCorners[i]);
- Matrix4.multiplyByVector(inverseViewProjection, corner, corner);
- Cartesian3.divideByScalar(corner, corner.w, corner); // Handle the perspective divide
- positions[i * 3] = corner.x;
- positions[i * 3 + 1] = corner.y;
- positions[i * 3 + 2] = corner.z;
+ var numFrustums = Math.max(1, Math.ceil(Math.log(frameState.far / frameState.near) / Math.log(frameState.farToNearRatio)));
+
+ var positions = new Float64Array(3 * 4 * (numFrustums + 1));
+ var f;
+ for (f = 0; f < numFrustums + 1; ++f) {
+ for (var i = 0; i < 4; ++i) {
+ var corner = Cartesian4.clone(frustumCornersNDC[i], scratchFrustumCorners[i]);
+
+ Matrix4.multiplyByVector(inverseViewProjection, corner, corner);
+ Cartesian3.divideByScalar(corner, corner.w, corner); // Handle the perspective divide
+ Cartesian3.subtract(corner, this._camera.positionWC, corner);
+ Cartesian3.normalize(corner, corner);
+
+ var d = frameState.near * Math.pow(frameState.farToNearRatio, f);
+ var fac = Cartesian3.dot(this._camera.directionWC, corner);
+ Cartesian3.multiplyByScalar(corner, d / fac, corner);
+ Cartesian3.add(corner, this._camera.positionWC, corner);
+
+ positions[12 * f + i * 3] = corner.x;
+ positions[12 * f + i * 3 + 1] = corner.y;
+ positions[12 * f + i * 3 + 2] = corner.z;
+ }
}
var boundingSphere = new BoundingSphere.fromVertices(positions);
@@ -149,8 +159,33 @@ define([
values : positions
});
+ var offset;
+
// Create the outline primitive
- var outlineIndices = new Uint16Array([0,1,1,2,2,3,3,0,0,4,4,7,7,3,7,6,6,2,2,1,1,5,5,4,5,6]);
+ var outlineIndices = new Uint16Array(8 * (2 * numFrustums + 1));
+ // build the far planes
+ for (f = 0; f < numFrustums + 1; ++f) {
+ outlineIndices[f * 8] = f * 4;
+ outlineIndices[f * 8 + 1] = f * 4 + 1;
+ outlineIndices[f * 8 + 2] = f * 4 + 1;
+ outlineIndices[f * 8 + 3] = f * 4 + 2;
+ outlineIndices[f * 8 + 4] = f * 4 + 2;
+ outlineIndices[f * 8 + 5] = f * 4 + 3;
+ outlineIndices[f * 8 + 6] = f * 4 + 3;
+ outlineIndices[f * 8 + 7] = f * 4;
+ }
+ // build the sides of the frustums
+ for (f = 0; f < numFrustums; ++f) {
+ offset = (numFrustums + 1 + f) * 8;
+ outlineIndices[offset] = f * 4;
+ outlineIndices[offset + 1] = f * 4 + 4;
+ outlineIndices[offset + 2] = f * 4 + 1;
+ outlineIndices[offset + 3] = f * 4 + 5;
+ outlineIndices[offset + 4] = f * 4 + 2;
+ outlineIndices[offset + 5] = f * 4 + 6;
+ outlineIndices[offset + 6] = f * 4 + 3;
+ outlineIndices[offset + 7] = f * 4 + 7;
+ }
this._outlinePrimitive = new Primitive({
geometryInstances : new GeometryInstance({
@@ -174,7 +209,47 @@ define([
});
// Create the planes primitive
- var planesIndices = new Uint16Array([4,5,6,4,6,7,5,1,2,5,2,6,7,6,2,7,2,3,0,1,5,0,5,4,0,4,7,0,7,3,1,0,3,1,3,2]);
+ var planesIndices = new Uint16Array(6 * (5 * numFrustums + 1));
+ // build the far planes
+ for (f = 0; f < numFrustums + 1; ++f) {
+ planesIndices[f * 6] = f * 4;
+ planesIndices[f * 6 + 1] = f * 4 + 1;
+ planesIndices[f * 6 + 2] = f * 4 + 2;
+ planesIndices[f * 6 + 3] = f * 4;
+ planesIndices[f * 6 + 4] = f * 4 + 2;
+ planesIndices[f * 6 + 5] = f * 4 + 3;
+ }
+ // build the sides of the frustums
+ for (f = 0; f < numFrustums; ++f) {
+ offset = (numFrustums + 1 + 4 * f) * 6;
+ planesIndices[offset] = 4 * f + 4;
+ planesIndices[offset + 1] = 4 * f;
+ planesIndices[offset + 2] = 4 * f + 3;
+ planesIndices[offset + 3] = 4 * f + 4;
+ planesIndices[offset + 4] = 4 * f + 3;
+ planesIndices[offset + 5] = 4 * f + 7;
+
+ planesIndices[offset + 6] = 4 * f + 4;
+ planesIndices[offset + 7] = 4 * f;
+ planesIndices[offset + 8] = 4 * f + 1;
+ planesIndices[offset + 9] = 4 * f + 4;
+ planesIndices[offset + 10] = 4 * f + 1;
+ planesIndices[offset + 11] = 4 * f + 5;
+
+ planesIndices[offset + 12] = 4 * f + 7;
+ planesIndices[offset + 13] = 4 * f + 3;
+ planesIndices[offset + 14] = 4 * f + 2;
+ planesIndices[offset + 15] = 4 * f + 7;
+ planesIndices[offset + 16] = 4 * f + 2;
+ planesIndices[offset + 17] = 4 * f + 6;
+
+ planesIndices[offset + 18] = 4 * f + 6;
+ planesIndices[offset + 19] = 4 * f + 2;
+ planesIndices[offset + 20] = 4 * f + 1;
+ planesIndices[offset + 21] = 4 * f + 6;
+ planesIndices[offset + 22] = 4 * f + 1;
+ planesIndices[offset + 23] = 4 * f + 5;
+ }
this._planesPrimitive = new Primitive({
geometryInstances : new GeometryInstance({
diff --git a/Source/Scene/FrameState.js b/Source/Scene/FrameState.js
index b29b83806062..674a4a7ea2d7 100644
--- a/Source/Scene/FrameState.js
+++ b/Source/Scene/FrameState.js
@@ -235,6 +235,10 @@ define([
* @default 0.0
*/
this.imagerySplitPosition = 0.0;
+
+ this.near = 1.0;
+ this.far = 1000.0;
+ this.farToNearRatio = 1000.0;
}
/**
diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js
index 1b60328e20f0..04f31486707a 100644
--- a/Source/Scene/Scene.js
+++ b/Source/Scene/Scene.js
@@ -42,6 +42,7 @@ define([
'./Camera',
'./CreditDisplay',
'./CullingVolume',
+ './DebugCameraPrimitive',
'./DepthPlane',
'./DeviceOrientationCameraController',
'./Fog',
@@ -109,6 +110,7 @@ define([
Camera,
CreditDisplay,
CullingVolume,
+ DebugCameraPrimitive,
DepthPlane,
DeviceOrientationCameraController,
Fog,
@@ -515,6 +517,9 @@ define([
*/
this.debugShowDepthFrustum = 1;
+ this._debugShowFrustumPlanes = false;
+ this._debugFrustumPlanes = undefined;
+
/**
* When true
, enables Fast Approximate Anti-aliasing even when order independent translucency
* is unsupported.
@@ -944,6 +949,40 @@ define([
}
},
+ /**
+ * This property is for debugging only; it is not for production use.
+ *
+ * When true
, draws primitives to show the boundaries of the camera frustum
+ *
+ *
+ * @type Boolean
+ *
+ * @default false
+ */
+ debugShowFrustumPlanes : {
+ get : function() {
+ return this._debugShowFrustumPlanes;
+ },
+
+ set : function(val) {
+ if (!val) {
+ if (defined(this._debugFrustumPlanes)) {
+ this.primitives.remove(this._debugFrustumPlanes);
+ this._debugFrustumPlanes = this._debugFrustumPlanes && !this._debugFrustumPlanes.isDestroyed() && this._debugFrustumPlanes.destroy();
+ }
+ } else if (val !== this._debugShowFrustumPlanes) {
+ this._debugFrustumPlanes = this._debugFrustumPlanes && !this._debugFrustumPlanes.isDestroyed() && this._debugFrustumPlanes.destroy();
+ this._debugFrustumPlanes = new DebugCameraPrimitive({
+ camera: this.camera,
+ updateOnChange: false
+ });
+ this._debugFrustumPlanes.update(this.frameState);
+ this.primitives.add(this._debugFrustumPlanes);
+ }
+ this._debugShowFrustumPlanes = val;
+ }
+ },
+
/**
* Gets whether or not the scene is optimized for 3D only viewing.
* @memberof Scene.prototype
@@ -1428,6 +1467,9 @@ define([
if (near !== Number.MAX_VALUE && (numFrustums !== numberOfFrustums || (frustumCommandsList.length !== 0 &&
(near < frustumCommandsList[0].near || far > frustumCommandsList[numberOfFrustums - 1].far)))) {
updateFrustums(near, far, farToNearRatio, numFrustums, frustumCommandsList, is2D, scene.nearToFarDistance2D);
+ frameState.near = near;
+ frameState.far = far;
+ frameState.farToNearRatio = farToNearRatio;
createPotentiallyVisibleSet(scene);
}
}
diff --git a/Source/Widgets/CesiumInspector/CesiumInspector.js b/Source/Widgets/CesiumInspector/CesiumInspector.js
index 923ead6b0980..ec0864d7daf6 100644
--- a/Source/Widgets/CesiumInspector/CesiumInspector.js
+++ b/Source/Widgets/CesiumInspector/CesiumInspector.js
@@ -80,6 +80,7 @@ define([
generalSection.className = 'cesium-cesiumInspector-section';
generalSection.setAttribute('data-bind', 'css: {"cesium-cesiumInspector-show" : generalVisible, "cesium-cesiumInspector-hide" : !generalVisible}');
panel.appendChild(generalSection);
+
var debugShowFrustums = document.createElement('div');
generalSection.appendChild(debugShowFrustums);
var frustumStats = document.createElement('div');
@@ -92,6 +93,14 @@ define([
debugShowFrustums.appendChild(document.createTextNode('Show Frustums'));
debugShowFrustums.appendChild(frustumStats);
+ var debugShowFrustumPlanes = document.createElement('div');
+ generalSection.appendChild(debugShowFrustumPlanes);
+ var frustumPlanesCheckbox = document.createElement('input');
+ frustumPlanesCheckbox.type = 'checkbox';
+ frustumPlanesCheckbox.setAttribute('data-bind', 'checked: frustumPlanes');
+ debugShowFrustumPlanes.appendChild(frustumPlanesCheckbox);
+ debugShowFrustumPlanes.appendChild(document.createTextNode('Show Frustum Planes'));
+
var performanceDisplay = document.createElement('div');
generalSection.appendChild(performanceDisplay);
var pdCheckbox = document.createElement('input');
diff --git a/Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js b/Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js
index 8eb93556173a..f5e5b55330ac 100644
--- a/Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js
+++ b/Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js
@@ -107,6 +107,13 @@ define([
*/
this.frustums = false;
+ /**
+ * Gets or sets the show frustum planes state. This property is observable.
+ * @type {Boolean}
+ * @default false
+ */
+ this.frustumPlanes = false;
+
/**
* Gets or sets the show performance display state. This property is observable.
* @type {Boolean}
@@ -305,6 +312,7 @@ define([
knockout.track(this, [
'frustums',
+ 'frustumPlanes',
'performance',
'shaderCacheText',
'primitiveBoundingSphere',
@@ -351,6 +359,10 @@ define([
that._scene.debugShowFrustums = val;
});
+ this._frustumPlanesSubscription = knockout.getObservable(this, 'frustumPlanes').subscribe(function(val) {
+ that._scene.debugShowFrustumPlanes = val;
+ });
+
this._performanceSubscription = knockout.getObservable(this, 'performance').subscribe(function(val) {
if (val) {
that._performanceDisplay = new PerformanceDisplay({
@@ -940,6 +952,7 @@ define([
CesiumInspectorViewModel.prototype.destroy = function() {
this._eventHandler.destroy();
this._frustumsSubscription.dispose();
+ this._frustumPlanesSubscription.dispose();
this._performanceSubscription.dispose();
this._primitiveBoundingSphereSubscription.dispose();
this._primitiveReferenceFrameSubscription.dispose();
From 58f287991492d0e565eb43631ac4f1493234f640 Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Mon, 30 Jan 2017 19:33:28 +0000
Subject: [PATCH 2/9] update CHANGES.md
---
CHANGES.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGES.md b/CHANGES.md
index 06b6e7e8cdf8..74ad19779154 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -36,6 +36,7 @@ Change Log
* Added 2D and Columbus View support for models using the RTC extension or whose vertices are in WGS84 coordinates. [#4922](https://github.com/AnalyticalGraphicsInc/cesium/pull/4922)
* Transparent parts of billboards, labels, and points no longer overwrite parts of the scene behind them. [#4886](https://github.com/AnalyticalGraphicsInc/cesium/pull/4886)
* Added `blendOption` property to `BillboardCollection`, `LabelCollection`, and `PointPrimitiveCollection`. The default is `BlendOption.OPAQUE_AND_TRANSLUCENT`; however, if all billboards, labels, or points are either completely opaque or completely translucent, `blendOption` can be changed to `BlendOption.OPAQUE` or `BlendOption.TRANSLUCENT`, respectively, to increase performance by up to 2x.
+* Added support to `DebugCameraPrimitive` to draw multifrustum planes. `CesiumInspector` also displays this toggle.
### 1.29 - 2017-01-02
From 9e575ccb6cf1ea7fb41174de9980813ecbcfcfff Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Tue, 31 Jan 2017 08:41:12 -0500
Subject: [PATCH 3/9] don't explicitly add draw commands; various fixes
---
Source/Scene/DebugCameraPrimitive.js | 18 +++++++--------
Source/Scene/FrameState.js | 9 +++++---
Source/Scene/Scene.js | 34 ++++++++++++++++------------
3 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/Source/Scene/DebugCameraPrimitive.js b/Source/Scene/DebugCameraPrimitive.js
index 7875b4930b3a..d162e7ca40f0 100644
--- a/Source/Scene/DebugCameraPrimitive.js
+++ b/Source/Scene/DebugCameraPrimitive.js
@@ -92,7 +92,7 @@ define([
this._planesPrimitive = undefined;
}
- var frustumCornersNDC = new Array(8);
+ var frustumCornersNDC = new Array(4);
frustumCornersNDC[0] = new Cartesian4(-1.0, -1.0, 1.0, 1.0);
frustumCornersNDC[1] = new Cartesian4(1.0, -1.0, 1.0, 1.0);
frustumCornersNDC[2] = new Cartesian4(1.0, 1.0, 1.0, 1.0);
@@ -100,7 +100,7 @@ define([
var scratchMatrix = new Matrix4();
var scratchFrustumCorners = new Array(4);
- for (var i = 0; i < 8; ++i) {
+ for (var i = 0; i < 4; ++i) {
scratchFrustumCorners[i] = new Cartesian4();
}
@@ -126,7 +126,8 @@ define([
var viewProjection = Matrix4.multiply(projection, view, scratchMatrix);
var inverseViewProjection = Matrix4.inverse(viewProjection, scratchMatrix);
- var numFrustums = Math.max(1, Math.ceil(Math.log(frameState.far / frameState.near) / Math.log(frameState.farToNearRatio)));
+ var frustumSplits = frameState.frustumSplits;
+ var numFrustums = frustumSplits.length - 1;
var positions = new Float64Array(3 * 4 * (numFrustums + 1));
var f;
@@ -139,9 +140,8 @@ define([
Cartesian3.subtract(corner, this._camera.positionWC, corner);
Cartesian3.normalize(corner, corner);
- var d = frameState.near * Math.pow(frameState.farToNearRatio, f);
var fac = Cartesian3.dot(this._camera.directionWC, corner);
- Cartesian3.multiplyByScalar(corner, d / fac, corner);
+ Cartesian3.multiplyByScalar(corner, frustumSplits[f] / fac, corner);
Cartesian3.add(corner, this._camera.positionWC, corner);
positions[12 * f + i * 3] = corner.x;
@@ -163,7 +163,7 @@ define([
// Create the outline primitive
var outlineIndices = new Uint16Array(8 * (2 * numFrustums + 1));
- // build the far planes
+ // Build the far planes
for (f = 0; f < numFrustums + 1; ++f) {
outlineIndices[f * 8] = f * 4;
outlineIndices[f * 8 + 1] = f * 4 + 1;
@@ -174,7 +174,7 @@ define([
outlineIndices[f * 8 + 6] = f * 4 + 3;
outlineIndices[f * 8 + 7] = f * 4;
}
- // build the sides of the frustums
+ // Build the sides of the frustums
for (f = 0; f < numFrustums; ++f) {
offset = (numFrustums + 1 + f) * 8;
outlineIndices[offset] = f * 4;
@@ -210,7 +210,7 @@ define([
// Create the planes primitive
var planesIndices = new Uint16Array(6 * (5 * numFrustums + 1));
- // build the far planes
+ // Build the far planes
for (f = 0; f < numFrustums + 1; ++f) {
planesIndices[f * 6] = f * 4;
planesIndices[f * 6 + 1] = f * 4 + 1;
@@ -219,7 +219,7 @@ define([
planesIndices[f * 6 + 4] = f * 4 + 2;
planesIndices[f * 6 + 5] = f * 4 + 3;
}
- // build the sides of the frustums
+ // Build the sides of the frustums
for (f = 0; f < numFrustums; ++f) {
offset = (numFrustums + 1 + 4 * f) * 6;
planesIndices[offset] = 4 * f + 4;
diff --git a/Source/Scene/FrameState.js b/Source/Scene/FrameState.js
index 674a4a7ea2d7..8025afce5fa6 100644
--- a/Source/Scene/FrameState.js
+++ b/Source/Scene/FrameState.js
@@ -236,9 +236,12 @@ define([
*/
this.imagerySplitPosition = 0.0;
- this.near = 1.0;
- this.far = 1000.0;
- this.farToNearRatio = 1000.0;
+ /**
+ * Distances to the near and far planes of the camera frustums
+ * @type {Number[]}
+ * @default [1.0, 1000.0]
+ */
+ this.frustumSplits = [1.0, 1000.0];
}
/**
diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js
index 04f31486707a..728ec214cc77 100644
--- a/Source/Scene/Scene.js
+++ b/Source/Scene/Scene.js
@@ -952,7 +952,7 @@ define([
/**
* This property is for debugging only; it is not for production use.
*
- * When true
, draws primitives to show the boundaries of the camera frustum
+ * When true
, draws outlines to show the boundaries of the camera frustums
*
*
* @type Boolean
@@ -963,23 +963,19 @@ define([
get : function() {
return this._debugShowFrustumPlanes;
},
-
- set : function(val) {
- if (!val) {
+ set : function(value) {
+ if (!value) {
if (defined(this._debugFrustumPlanes)) {
- this.primitives.remove(this._debugFrustumPlanes);
- this._debugFrustumPlanes = this._debugFrustumPlanes && !this._debugFrustumPlanes.isDestroyed() && this._debugFrustumPlanes.destroy();
+ this._debugFrustumPlanes = this._debugFrustumPlanes && this._debugFrustumPlanes.destroy();
}
- } else if (val !== this._debugShowFrustumPlanes) {
- this._debugFrustumPlanes = this._debugFrustumPlanes && !this._debugFrustumPlanes.isDestroyed() && this._debugFrustumPlanes.destroy();
+ } else if (value !== this._debugShowFrustumPlanes) {
+ this._debugFrustumPlanes = this._debugFrustumPlanes && this._debugFrustumPlanes.destroy();
this._debugFrustumPlanes = new DebugCameraPrimitive({
camera: this.camera,
updateOnChange: false
});
- this._debugFrustumPlanes.update(this.frameState);
- this.primitives.add(this._debugFrustumPlanes);
}
- this._debugShowFrustumPlanes = val;
+ this._debugShowFrustumPlanes = value;
}
},
@@ -1467,11 +1463,17 @@ define([
if (near !== Number.MAX_VALUE && (numFrustums !== numberOfFrustums || (frustumCommandsList.length !== 0 &&
(near < frustumCommandsList[0].near || far > frustumCommandsList[numberOfFrustums - 1].far)))) {
updateFrustums(near, far, farToNearRatio, numFrustums, frustumCommandsList, is2D, scene.nearToFarDistance2D);
- frameState.near = near;
- frameState.far = far;
- frameState.farToNearRatio = farToNearRatio;
createPotentiallyVisibleSet(scene);
}
+
+ var frustumSplits = frameState.frustumSplits;
+ frustumSplits.length = numFrustums + 1;
+ for (var j = 0; j < numFrustums; ++j) {
+ frustumSplits[j] = frustumCommandsList[j].near;
+ if (j === numFrustums - 1) {
+ frustumSplits[j + 1] = frustumCommandsList[j].far;
+ }
+ }
}
function getAttributeLocations(shaderProgram) {
@@ -2282,6 +2284,9 @@ define([
scene._groundPrimitives.update(frameState);
scene._primitives.update(frameState);
+ if (defined(scene._debugFrustumPlanes)) {
+ scene._debugFrustumPlanes.update(frameState)
+ }
updateShadowMaps(scene);
@@ -2938,6 +2943,7 @@ define([
this._sunPostProcess = this._sunPostProcess && this._sunPostProcess.destroy();
this._depthPlane = this._depthPlane && this._depthPlane.destroy();
this._transitioner.destroy();
+ this._debugFrustumPlanes = this._debugFrustumPlanes && this._debugFrustumPlanes.destroy();
if (defined(this._globeDepth)) {
this._globeDepth.destroy();
From 06c8f7c6ab2513a3e52e7625a2b2f2c904900b7b Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Wed, 1 Feb 2017 11:01:34 -0500
Subject: [PATCH 4/9] factor out index offsets
---
Source/Scene/DebugCameraPrimitive.js | 110 +++++++++++++++------------
1 file changed, 60 insertions(+), 50 deletions(-)
diff --git a/Source/Scene/DebugCameraPrimitive.js b/Source/Scene/DebugCameraPrimitive.js
index d162e7ca40f0..3bec71974541 100644
--- a/Source/Scene/DebugCameraPrimitive.js
+++ b/Source/Scene/DebugCameraPrimitive.js
@@ -159,32 +159,37 @@ define([
values : positions
});
- var offset;
+ var offset, idx;
// Create the outline primitive
var outlineIndices = new Uint16Array(8 * (2 * numFrustums + 1));
// Build the far planes
for (f = 0; f < numFrustums + 1; ++f) {
- outlineIndices[f * 8] = f * 4;
- outlineIndices[f * 8 + 1] = f * 4 + 1;
- outlineIndices[f * 8 + 2] = f * 4 + 1;
- outlineIndices[f * 8 + 3] = f * 4 + 2;
- outlineIndices[f * 8 + 4] = f * 4 + 2;
- outlineIndices[f * 8 + 5] = f * 4 + 3;
- outlineIndices[f * 8 + 6] = f * 4 + 3;
- outlineIndices[f * 8 + 7] = f * 4;
+ offset = f * 8;
+ idx = f * 4;
+
+ outlineIndices[offset] = idx;
+ outlineIndices[offset + 1] = idx + 1;
+ outlineIndices[offset + 2] = idx + 1;
+ outlineIndices[offset + 3] = idx + 2;
+ outlineIndices[offset + 4] = idx + 2;
+ outlineIndices[offset + 5] = idx + 3;
+ outlineIndices[offset + 6] = idx + 3;
+ outlineIndices[offset + 7] = idx;
}
// Build the sides of the frustums
for (f = 0; f < numFrustums; ++f) {
offset = (numFrustums + 1 + f) * 8;
- outlineIndices[offset] = f * 4;
- outlineIndices[offset + 1] = f * 4 + 4;
- outlineIndices[offset + 2] = f * 4 + 1;
- outlineIndices[offset + 3] = f * 4 + 5;
- outlineIndices[offset + 4] = f * 4 + 2;
- outlineIndices[offset + 5] = f * 4 + 6;
- outlineIndices[offset + 6] = f * 4 + 3;
- outlineIndices[offset + 7] = f * 4 + 7;
+ idx = f * 4;
+
+ outlineIndices[offset] = idx;
+ outlineIndices[offset + 1] = idx + 4;
+ outlineIndices[offset + 2] = idx + 1;
+ outlineIndices[offset + 3] = idx + 5;
+ outlineIndices[offset + 4] = idx + 2;
+ outlineIndices[offset + 5] = idx + 6;
+ outlineIndices[offset + 6] = idx + 3;
+ outlineIndices[offset + 7] = idx + 7;
}
this._outlinePrimitive = new Primitive({
@@ -212,43 +217,48 @@ define([
var planesIndices = new Uint16Array(6 * (5 * numFrustums + 1));
// Build the far planes
for (f = 0; f < numFrustums + 1; ++f) {
- planesIndices[f * 6] = f * 4;
- planesIndices[f * 6 + 1] = f * 4 + 1;
- planesIndices[f * 6 + 2] = f * 4 + 2;
- planesIndices[f * 6 + 3] = f * 4;
- planesIndices[f * 6 + 4] = f * 4 + 2;
- planesIndices[f * 6 + 5] = f * 4 + 3;
+ offset = f * 6;
+ idx = f * 4;
+
+ planesIndices[offset] = idx;
+ planesIndices[offset + 1] = idx + 1;
+ planesIndices[offset + 2] = idx + 2;
+ planesIndices[offset + 3] = idx;
+ planesIndices[offset + 4] = idx + 2;
+ planesIndices[offset + 5] = idx + 3;
}
// Build the sides of the frustums
for (f = 0; f < numFrustums; ++f) {
offset = (numFrustums + 1 + 4 * f) * 6;
- planesIndices[offset] = 4 * f + 4;
- planesIndices[offset + 1] = 4 * f;
- planesIndices[offset + 2] = 4 * f + 3;
- planesIndices[offset + 3] = 4 * f + 4;
- planesIndices[offset + 4] = 4 * f + 3;
- planesIndices[offset + 5] = 4 * f + 7;
-
- planesIndices[offset + 6] = 4 * f + 4;
- planesIndices[offset + 7] = 4 * f;
- planesIndices[offset + 8] = 4 * f + 1;
- planesIndices[offset + 9] = 4 * f + 4;
- planesIndices[offset + 10] = 4 * f + 1;
- planesIndices[offset + 11] = 4 * f + 5;
-
- planesIndices[offset + 12] = 4 * f + 7;
- planesIndices[offset + 13] = 4 * f + 3;
- planesIndices[offset + 14] = 4 * f + 2;
- planesIndices[offset + 15] = 4 * f + 7;
- planesIndices[offset + 16] = 4 * f + 2;
- planesIndices[offset + 17] = 4 * f + 6;
-
- planesIndices[offset + 18] = 4 * f + 6;
- planesIndices[offset + 19] = 4 * f + 2;
- planesIndices[offset + 20] = 4 * f + 1;
- planesIndices[offset + 21] = 4 * f + 6;
- planesIndices[offset + 22] = 4 * f + 1;
- planesIndices[offset + 23] = 4 * f + 5;
+ idx = f * 4;
+
+ planesIndices[offset] = idx + 4;
+ planesIndices[offset + 1] = idx;
+ planesIndices[offset + 2] = idx + 3;
+ planesIndices[offset + 3] = idx + 4;
+ planesIndices[offset + 4] = idx + 3;
+ planesIndices[offset + 5] = idx + 7;
+
+ planesIndices[offset + 6] = idx + 4;
+ planesIndices[offset + 7] = idx;
+ planesIndices[offset + 8] = idx + 1;
+ planesIndices[offset + 9] = idx + 4;
+ planesIndices[offset + 10] = idx + 1;
+ planesIndices[offset + 11] = idx + 5;
+
+ planesIndices[offset + 12] = idx + 7;
+ planesIndices[offset + 13] = idx + 3;
+ planesIndices[offset + 14] = idx + 2;
+ planesIndices[offset + 15] = idx + 7;
+ planesIndices[offset + 16] = idx + 2;
+ planesIndices[offset + 17] = idx + 6;
+
+ planesIndices[offset + 18] = idx + 6;
+ planesIndices[offset + 19] = idx + 2;
+ planesIndices[offset + 20] = idx + 1;
+ planesIndices[offset + 21] = idx + 6;
+ planesIndices[offset + 22] = idx + 1;
+ planesIndices[offset + 23] = idx + 5;
}
this._planesPrimitive = new Primitive({
From 495631e1bae101974cc6633b7706429db9477568 Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Wed, 1 Feb 2017 11:07:40 -0500
Subject: [PATCH 5/9] use empty frustumSplits by default
---
Source/Scene/FrameState.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Source/Scene/FrameState.js b/Source/Scene/FrameState.js
index 8025afce5fa6..f28094fd9c7b 100644
--- a/Source/Scene/FrameState.js
+++ b/Source/Scene/FrameState.js
@@ -239,9 +239,9 @@ define([
/**
* Distances to the near and far planes of the camera frustums
* @type {Number[]}
- * @default [1.0, 1000.0]
+ * @default []
*/
- this.frustumSplits = [1.0, 1000.0];
+ this.frustumSplits = [];
}
/**
From 4b7843a7dec1af82c478868a5b018c642d5d72ac Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Wed, 1 Feb 2017 11:32:59 -0500
Subject: [PATCH 6/9] move DebugCameraPrimitive creation to updatePrimitives
---
Source/Scene/Scene.js | 54 +++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 30 deletions(-)
diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js
index 3f0c21ddfc7c..121044ec8776 100644
--- a/Source/Scene/Scene.js
+++ b/Source/Scene/Scene.js
@@ -517,6 +517,17 @@ define([
*/
this.debugShowDepthFrustum = 1;
+ /**
+ * This property is for debugging only; it is not for production use.
+ *
+ * When true
, draws outlines to show the boundaries of the camera frustums
+ *
+ *
+ * @type Boolean
+ *
+ * @default false
+ */
+ this.debugShowFrustumPlanes = false;
this._debugShowFrustumPlanes = false;
this._debugFrustumPlanes = undefined;
@@ -949,36 +960,6 @@ define([
}
},
- /**
- * This property is for debugging only; it is not for production use.
- *
- * When true
, draws outlines to show the boundaries of the camera frustums
- *
- *
- * @type Boolean
- *
- * @default false
- */
- debugShowFrustumPlanes : {
- get : function() {
- return this._debugShowFrustumPlanes;
- },
- set : function(value) {
- if (!value) {
- if (defined(this._debugFrustumPlanes)) {
- this._debugFrustumPlanes = this._debugFrustumPlanes && this._debugFrustumPlanes.destroy();
- }
- } else if (value !== this._debugShowFrustumPlanes) {
- this._debugFrustumPlanes = this._debugFrustumPlanes && this._debugFrustumPlanes.destroy();
- this._debugFrustumPlanes = new DebugCameraPrimitive({
- camera: this.camera,
- updateOnChange: false
- });
- }
- this._debugShowFrustumPlanes = value;
- }
- },
-
/**
* Gets whether or not the scene is optimized for 3D only viewing.
* @memberof Scene.prototype
@@ -2284,6 +2265,19 @@ define([
scene._groundPrimitives.update(frameState);
scene._primitives.update(frameState);
+
+ if (scene.debugShowFrustumPlanes !== scene._debugShowFrustumPlanes) {
+ if (scene.debugShowFrustumPlanes) {
+ scene._debugFrustumPlanes = new DebugCameraPrimitive({
+ camera: scene.camera,
+ updateOnChange: false
+ });
+ } else {
+ scene._debugFrustumPlanes = scene._debugFrustumPlanes && scene._debugFrustumPlanes.destroy();
+ }
+ scene._debugShowFrustumPlanes = scene.debugShowFrustumPlanes;
+ }
+
if (defined(scene._debugFrustumPlanes)) {
scene._debugFrustumPlanes.update(frameState);
}
From 0b44434f91581606776a5f5973c6d2da3a19f8a0 Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Wed, 1 Feb 2017 11:37:55 -0500
Subject: [PATCH 7/9] update CHANGES.md
---
CHANGES.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/CHANGES.md b/CHANGES.md
index 7525cf39b234..0e6eaf80a102 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,6 +1,9 @@
Change Log
==========
+### 1.31 - 2017-03-01
+* Added support to `DebugCameraPrimitive` to draw multifrustum planes. The attribute `debugShowFrustumPlanes` of `Scene` and `frustumPlanes` of `CesiumInspector` toggles this. `FrameState` has been augmented to include `frustumSplits` which is a `Number[]` of the near/far planes of the camera frustums.
+
### 1.30 - 2017-02-01
* Deprecated
@@ -32,7 +35,6 @@ Change Log
* The attribute `perInstanceAttribute` of `DebugAppearance` has been made optional and defaults to `false`.
* Fixed a bug that would cause a crash when `debugShowFrustums` is enabled with OIT. [#4864](https://github.com/AnalyticalGraphicsInc/cesium/pull/4864)
* Added the ability to run the unit tests with a [WebGL Stub](https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/TestingGuide#run-with-webgl-stub), which makes all WebGL calls a noop and ignores test expectations that rely on reading back from WebGL. Use the web link from the main index.html or run with `npm run test-webgl-stub`.
-* Added support to `DebugCameraPrimitive` to draw multifrustum planes. `CesiumInspector` also displays this toggle.
### 1.29 - 2017-01-02
From 82b88a9768f3aff3b87338ec7bdbf60c93703bc2 Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Wed, 1 Feb 2017 12:23:48 -0500
Subject: [PATCH 8/9] use camera near/far planes if no splits created
---
Source/Scene/DebugCameraPrimitive.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/Source/Scene/DebugCameraPrimitive.js b/Source/Scene/DebugCameraPrimitive.js
index 3bec71974541..6f1f9d69e61b 100644
--- a/Source/Scene/DebugCameraPrimitive.js
+++ b/Source/Scene/DebugCameraPrimitive.js
@@ -105,7 +105,7 @@ define([
}
var scratchColor = new Color();
-
+ var scratchSplits = [1.0, 100000.0];
/**
* @private
*/
@@ -128,6 +128,12 @@ define([
var frustumSplits = frameState.frustumSplits;
var numFrustums = frustumSplits.length - 1;
+ if (numFrustums <= 0) {
+ frustumSplits = scratchSplits; // Use near and far planes if no splits created
+ frustumSplits[0] = this._camera.frustum.near;
+ frustumSplits[1] = this._camera.frustum.far;
+ numFrustums = 1;
+ }
var positions = new Float64Array(3 * 4 * (numFrustums + 1));
var f;
From 58783cb24664fb6bccf8428bc5e4405ee71549cf Mon Sep 17 00:00:00 2001
From: Austin Eng <213reeses@gmail.com>
Date: Thu, 2 Feb 2017 08:36:31 -0500
Subject: [PATCH 9/9] cleanup debug frustum update in scene. remove idx
abbreviation
---
Source/Scene/DebugCameraPrimitive.js | 116 +++++++++++++--------------
Source/Scene/Scene.js | 35 ++++----
2 files changed, 77 insertions(+), 74 deletions(-)
diff --git a/Source/Scene/DebugCameraPrimitive.js b/Source/Scene/DebugCameraPrimitive.js
index 6f1f9d69e61b..c282852684cd 100644
--- a/Source/Scene/DebugCameraPrimitive.js
+++ b/Source/Scene/DebugCameraPrimitive.js
@@ -165,37 +165,37 @@ define([
values : positions
});
- var offset, idx;
+ var offset, index;
// Create the outline primitive
var outlineIndices = new Uint16Array(8 * (2 * numFrustums + 1));
// Build the far planes
for (f = 0; f < numFrustums + 1; ++f) {
offset = f * 8;
- idx = f * 4;
-
- outlineIndices[offset] = idx;
- outlineIndices[offset + 1] = idx + 1;
- outlineIndices[offset + 2] = idx + 1;
- outlineIndices[offset + 3] = idx + 2;
- outlineIndices[offset + 4] = idx + 2;
- outlineIndices[offset + 5] = idx + 3;
- outlineIndices[offset + 6] = idx + 3;
- outlineIndices[offset + 7] = idx;
+ index = f * 4;
+
+ outlineIndices[offset] = index;
+ outlineIndices[offset + 1] = index + 1;
+ outlineIndices[offset + 2] = index + 1;
+ outlineIndices[offset + 3] = index + 2;
+ outlineIndices[offset + 4] = index + 2;
+ outlineIndices[offset + 5] = index + 3;
+ outlineIndices[offset + 6] = index + 3;
+ outlineIndices[offset + 7] = index;
}
// Build the sides of the frustums
for (f = 0; f < numFrustums; ++f) {
offset = (numFrustums + 1 + f) * 8;
- idx = f * 4;
-
- outlineIndices[offset] = idx;
- outlineIndices[offset + 1] = idx + 4;
- outlineIndices[offset + 2] = idx + 1;
- outlineIndices[offset + 3] = idx + 5;
- outlineIndices[offset + 4] = idx + 2;
- outlineIndices[offset + 5] = idx + 6;
- outlineIndices[offset + 6] = idx + 3;
- outlineIndices[offset + 7] = idx + 7;
+ index = f * 4;
+
+ outlineIndices[offset] = index;
+ outlineIndices[offset + 1] = index + 4;
+ outlineIndices[offset + 2] = index + 1;
+ outlineIndices[offset + 3] = index + 5;
+ outlineIndices[offset + 4] = index + 2;
+ outlineIndices[offset + 5] = index + 6;
+ outlineIndices[offset + 6] = index + 3;
+ outlineIndices[offset + 7] = index + 7;
}
this._outlinePrimitive = new Primitive({
@@ -224,47 +224,47 @@ define([
// Build the far planes
for (f = 0; f < numFrustums + 1; ++f) {
offset = f * 6;
- idx = f * 4;
-
- planesIndices[offset] = idx;
- planesIndices[offset + 1] = idx + 1;
- planesIndices[offset + 2] = idx + 2;
- planesIndices[offset + 3] = idx;
- planesIndices[offset + 4] = idx + 2;
- planesIndices[offset + 5] = idx + 3;
+ index = f * 4;
+
+ planesIndices[offset] = index;
+ planesIndices[offset + 1] = index + 1;
+ planesIndices[offset + 2] = index + 2;
+ planesIndices[offset + 3] = index;
+ planesIndices[offset + 4] = index + 2;
+ planesIndices[offset + 5] = index + 3;
}
// Build the sides of the frustums
for (f = 0; f < numFrustums; ++f) {
offset = (numFrustums + 1 + 4 * f) * 6;
- idx = f * 4;
-
- planesIndices[offset] = idx + 4;
- planesIndices[offset + 1] = idx;
- planesIndices[offset + 2] = idx + 3;
- planesIndices[offset + 3] = idx + 4;
- planesIndices[offset + 4] = idx + 3;
- planesIndices[offset + 5] = idx + 7;
-
- planesIndices[offset + 6] = idx + 4;
- planesIndices[offset + 7] = idx;
- planesIndices[offset + 8] = idx + 1;
- planesIndices[offset + 9] = idx + 4;
- planesIndices[offset + 10] = idx + 1;
- planesIndices[offset + 11] = idx + 5;
-
- planesIndices[offset + 12] = idx + 7;
- planesIndices[offset + 13] = idx + 3;
- planesIndices[offset + 14] = idx + 2;
- planesIndices[offset + 15] = idx + 7;
- planesIndices[offset + 16] = idx + 2;
- planesIndices[offset + 17] = idx + 6;
-
- planesIndices[offset + 18] = idx + 6;
- planesIndices[offset + 19] = idx + 2;
- planesIndices[offset + 20] = idx + 1;
- planesIndices[offset + 21] = idx + 6;
- planesIndices[offset + 22] = idx + 1;
- planesIndices[offset + 23] = idx + 5;
+ index = f * 4;
+
+ planesIndices[offset] = index + 4;
+ planesIndices[offset + 1] = index;
+ planesIndices[offset + 2] = index + 3;
+ planesIndices[offset + 3] = index + 4;
+ planesIndices[offset + 4] = index + 3;
+ planesIndices[offset + 5] = index + 7;
+
+ planesIndices[offset + 6] = index + 4;
+ planesIndices[offset + 7] = index;
+ planesIndices[offset + 8] = index + 1;
+ planesIndices[offset + 9] = index + 4;
+ planesIndices[offset + 10] = index + 1;
+ planesIndices[offset + 11] = index + 5;
+
+ planesIndices[offset + 12] = index + 7;
+ planesIndices[offset + 13] = index + 3;
+ planesIndices[offset + 14] = index + 2;
+ planesIndices[offset + 15] = index + 7;
+ planesIndices[offset + 16] = index + 2;
+ planesIndices[offset + 17] = index + 6;
+
+ planesIndices[offset + 18] = index + 6;
+ planesIndices[offset + 19] = index + 2;
+ planesIndices[offset + 20] = index + 1;
+ planesIndices[offset + 21] = index + 6;
+ planesIndices[offset + 22] = index + 1;
+ planesIndices[offset + 23] = index + 5;
}
this._planesPrimitive = new Primitive({
diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js
index 121044ec8776..7c0097d02a03 100644
--- a/Source/Scene/Scene.js
+++ b/Source/Scene/Scene.js
@@ -2215,6 +2215,24 @@ define([
}
}
+ function updateDebugFrustumPlanes(scene) {
+ if (scene.debugShowFrustumPlanes !== scene._debugShowFrustumPlanes) {
+ if (scene.debugShowFrustumPlanes) {
+ scene._debugFrustumPlanes = new DebugCameraPrimitive({
+ camera: scene.camera,
+ updateOnChange: false
+ });
+ } else {
+ scene._debugFrustumPlanes = scene._debugFrustumPlanes && scene._debugFrustumPlanes.destroy();
+ }
+ scene._debugShowFrustumPlanes = scene.debugShowFrustumPlanes;
+ }
+
+ if (defined(scene._debugFrustumPlanes)) {
+ scene._debugFrustumPlanes.update(frameState);
+ }
+ }
+
function updateShadowMaps(scene) {
var frameState = scene._frameState;
var shadowMaps = frameState.shadowMaps;
@@ -2266,22 +2284,7 @@ define([
scene._groundPrimitives.update(frameState);
scene._primitives.update(frameState);
- if (scene.debugShowFrustumPlanes !== scene._debugShowFrustumPlanes) {
- if (scene.debugShowFrustumPlanes) {
- scene._debugFrustumPlanes = new DebugCameraPrimitive({
- camera: scene.camera,
- updateOnChange: false
- });
- } else {
- scene._debugFrustumPlanes = scene._debugFrustumPlanes && scene._debugFrustumPlanes.destroy();
- }
- scene._debugShowFrustumPlanes = scene.debugShowFrustumPlanes;
- }
-
- if (defined(scene._debugFrustumPlanes)) {
- scene._debugFrustumPlanes.update(frameState);
- }
-
+ updateDebugFrustumPlanes(scene);
updateShadowMaps(scene);
if (scene._globe) {