Skip to content

Commit a611d1e

Browse files
committed
Merge pull request #2513 from AnalyticalGraphicsInc/corridor
Straight CorridorGeometry.
2 parents ac7547f + 200042c commit a611d1e

5 files changed

+63
-2
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Change Log
1919
* `InfoBox` sanitization now relies on [iframe sandboxing](http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/). This allows for much more content to be displayed in the InfoBox (and still be secure).
2020
* Added `InfoBox.frame` which is the instance of the iframe that is used to host description content. Sanitization can be controlled via the frame's `sandbox` attribute. See the above link for additional information.
2121
* Fixed incorrect ellipse texture coordinates. [#2363](https://github.com/AnalyticalGraphicsInc/cesium/issues/2363) and [#2465](https://github.com/AnalyticalGraphicsInc/cesium/issues/2465)
22+
* Fixed a bug that would cause incorrect geometry for long Corridors and Polyline Volumes. [#2513](https://github.com/AnalyticalGraphicsInc/cesium/issues/2513)
2223
* Fixed a bug in imagery loading that could cause some or all of the globe to be missing when using an imagery layer that does not cover the entire globe.
2324
* Fixed some styling issues with `InfoBox` and `BaseLayerPicker` caused by using Bootstrap with Cesium. [#2487](https://github.com/AnalyticalGraphicsInc/cesium/issues/2479)
2425
* Added support for rendering a water effect on Quantized-Mesh terrain tiles.

Source/Core/CorridorGeometryLibrary.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ define([
160160
return positions;
161161
}
162162

163+
var scratchForwardProjection = new Cartesian3();
164+
var scratchBackwardProjection = new Cartesian3();
165+
163166
/**
164167
* @private
165168
*/
@@ -207,7 +210,17 @@ define([
207210
nextPosition = positions[i + 1];
208211
forward = Cartesian3.normalize(Cartesian3.subtract(nextPosition, position, forward), forward);
209212
cornerDirection = Cartesian3.normalize(Cartesian3.add(forward, backward, cornerDirection), cornerDirection);
210-
var doCorner = !Cartesian3.equalsEpsilon(Cartesian3.negate(cornerDirection, scratch1), normal, CesiumMath.EPSILON2);
213+
214+
var forwardProjection = Cartesian3.multiplyByScalar(normal, Cartesian3.dot(forward, normal), scratchForwardProjection);
215+
Cartesian3.subtract(forward, forwardProjection, forwardProjection);
216+
Cartesian3.normalize(forwardProjection, forwardProjection);
217+
218+
var backwardProjection = Cartesian3.multiplyByScalar(normal, Cartesian3.dot(backward, normal), scratchBackwardProjection);
219+
Cartesian3.subtract(backward, backwardProjection, backwardProjection);
220+
Cartesian3.normalize(backwardProjection, backwardProjection);
221+
222+
var doCorner = !CesiumMath.equalsEpsilon(Math.abs(Cartesian3.dot(forwardProjection, backwardProjection)), 1.0, CesiumMath.EPSILON1);
223+
211224
if (doCorner) {
212225
cornerDirection = Cartesian3.cross(cornerDirection, normal, cornerDirection);
213226
cornerDirection = Cartesian3.cross(normal, cornerDirection, cornerDirection);

Source/Core/PolylineVolumeGeometryLibrary.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ define([
290290
return cleanedPositions;
291291
};
292292

293+
var scratchForwardProjection = new Cartesian3();
294+
var scratchBackwardProjection = new Cartesian3();
295+
293296
PolylineVolumeGeometryLibrary.computePositions = function(positions, shape2D, boundingRectangle, geometry, duplicatePoints) {
294297
var ellipsoid = geometry._ellipsoid;
295298
var heights = scaleToSurface(positions, ellipsoid);
@@ -338,7 +341,17 @@ define([
338341
cornerDirection = Cartesian3.add(forward, backward, cornerDirection);
339342
cornerDirection = Cartesian3.normalize(cornerDirection, cornerDirection);
340343
surfaceNormal = ellipsoid.geodeticSurfaceNormal(position, surfaceNormal);
341-
var doCorner = !Cartesian3.equalsEpsilon(Cartesian3.negate(cornerDirection, scratch1), surfaceNormal, CesiumMath.EPSILON2);
344+
345+
var forwardProjection = Cartesian3.multiplyByScalar(surfaceNormal, Cartesian3.dot(forward, surfaceNormal), scratchForwardProjection);
346+
Cartesian3.subtract(forward, forwardProjection, forwardProjection);
347+
Cartesian3.normalize(forwardProjection, forwardProjection);
348+
349+
var backwardProjection = Cartesian3.multiplyByScalar(surfaceNormal, Cartesian3.dot(backward, surfaceNormal), scratchBackwardProjection);
350+
Cartesian3.subtract(backward, backwardProjection, backwardProjection);
351+
Cartesian3.normalize(backwardProjection, backwardProjection);
352+
353+
var doCorner = !CesiumMath.equalsEpsilon(Math.abs(Cartesian3.dot(forwardProjection, backwardProjection)), 1.0, CesiumMath.EPSILON1);
354+
342355
if (doCorner) {
343356
cornerDirection = Cartesian3.cross(cornerDirection, surfaceNormal, cornerDirection);
344357
cornerDirection = Cartesian3.cross(surfaceNormal, cornerDirection, cornerDirection);

Specs/Core/CorridorGeometrySpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ defineSuite([
180180
expect(m.indices.length).toEqual(3 * 8);
181181
});
182182

183+
it('computes straight corridors', function() {
184+
var m = CorridorGeometry.createGeometry(new CorridorGeometry({
185+
vertexFormat : VertexFormat.POSITION_ONLY,
186+
positions : Cartesian3.fromDegreesArray([
187+
-67.655, 0.0,
188+
-67.655, 15.0,
189+
-67.655, 20.0
190+
]),
191+
cornerType: CornerType.BEVELED,
192+
width : 400000,
193+
granularity : Math.PI / 6.0
194+
}));
195+
196+
expect(m.attributes.position.values.length).toEqual(3 * 4);
197+
expect(m.indices.length).toEqual(3 * 2);
198+
});
199+
183200
var positions = Cartesian3.fromDegreesArray([
184201
90.0, -30.0,
185202
90.0, -31.0

Specs/Core/PolylineVolumeGeometrySpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ defineSuite([
169169
expect(m.indices.length).toEqual(3 * (8 * 2 + 4 * 7 * 2 + 4));
170170
});
171171

172+
it('computes straight volume', function() {
173+
var m = PolylineVolumeGeometry.createGeometry(new PolylineVolumeGeometry({
174+
vertexFormat : VertexFormat.POSITION_ONLY,
175+
polylinePositions : Cartesian3.fromDegreesArray([
176+
-67.655, 0.0,
177+
-67.655, 15.0,
178+
-67.655, 20.0
179+
]),
180+
cornerType: CornerType.BEVELED,
181+
shapePositions: shape,
182+
granularity : Math.PI / 6.0
183+
}));
184+
185+
expect(m.attributes.position.values.length).toEqual(3 * 32);
186+
expect(m.indices.length).toEqual(3 * 20);
187+
});
188+
172189
var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)];
173190
var volumeShape = [new Cartesian2(0.0, 0.0), new Cartesian2(1.0, 0.0), new Cartesian2(0.0, 1.0)];
174191
var volume = new PolylineVolumeGeometry({

0 commit comments

Comments
 (0)