diff --git a/CHANGES.md b/CHANGES.md index 01f042c81fed..f85e84649901 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,9 @@ Change Log Beta Releases ------------- +### b21 - 2013-10-01 +* Added `CorridorOutlineGeometry`. + ### b20 - 2013-09-03 _This releases fixes 2D and other issues with Chrome 29.0.1547.57 ([#1002](https://github.com/AnalyticalGraphicsInc/cesium/issues/1002) and [#1047](https://github.com/AnalyticalGraphicsInc/cesium/issues/1047))._ @@ -59,7 +62,7 @@ var geometry = BoxGeometry.createGeometry(box); * Replaced `createPickFragmentShaderSource` with `createShaderSource`. * Renamed `PolygonPipeline.earClip2D` to `PolygonPipeline.triangulate`. * Added outline geometries. [#1021](https://github.com/AnalyticalGraphicsInc/cesium/pull/1021). -* Added `CorridorGeometry` and `CorridorOutlineGeometry`. +* Added `CorridorGeometry`. * Added `Billboard.scaleByDistance` and `NearFarScalar` to control billboard minimum/maximum scale based on camera distance. * Added `EllipsoidGeodesic`. * Added `PolylinePipeline.scaleToSurface`. diff --git a/Source/Core/CorridorGeometry.js b/Source/Core/CorridorGeometry.js index 707e91cab1a9..be95084c17c1 100644 --- a/Source/Core/CorridorGeometry.js +++ b/Source/Core/CorridorGeometry.js @@ -410,8 +410,7 @@ define([ return { attributes : attributes, - indices : indices, - boundingSphere : BoundingSphere.fromVertices(finalPositions) + indices : indices }; } @@ -567,7 +566,6 @@ define([ var extrudedHeight = params.extrudedHeight; var attributes = attr.attributes; var indices = attr.indices; - var boundingSphere = attr.boundingSphere; var positions = attributes.position.values; var length = positions.length; var newPositions = new Float64Array(length * 6); @@ -582,7 +580,6 @@ define([ newPositions.set(positions); newPositions.set(extrudedPositions, length); newPositions.set(wallPositions, length * 2); - boundingSphere = BoundingSphere.fromVertices(positions, undefined, 3, boundingSphere); attributes.position.values = newPositions; length /= 3; @@ -619,8 +616,7 @@ define([ return { attributes : attributes, - indices : newIndices, - boundingSphere : boundingSphere + indices : newIndices }; } @@ -716,20 +712,19 @@ define([ } else { var computedPositions = CorridorGeometryLibrary.computePositions(params); attr = combine(computedPositions, vertexFormat, ellipsoid); - if (!vertexFormat.position) { - attr.attributes.position.values = undefined; - } else { - attr.attributes.position.values = new Float64Array(PolylinePipeline.scaleToGeodeticHeight(attr.attributes.position.values, height, ellipsoid, attr.attributes.position.values)); - } - + attr.attributes.position.values = new Float64Array(PolylinePipeline.scaleToGeodeticHeight(attr.attributes.position.values, height, ellipsoid, attr.attributes.position.values)); } var attributes = attr.attributes; + var boundingSphere = BoundingSphere.fromVertices(attributes.position.values, undefined, 3); + if (!vertexFormat.position) { + attr.attributes.position.values = undefined; + } return new Geometry({ attributes : attributes, indices : attr.indices, primitiveType : PrimitiveType.TRIANGLES, - boundingSphere : attr.boundingSphere + boundingSphere : boundingSphere }); }; diff --git a/Source/Core/CorridorGeometryLibrary.js b/Source/Core/CorridorGeometryLibrary.js index 2fa3a4a7270b..5389bb904c22 100644 --- a/Source/Core/CorridorGeometryLibrary.js +++ b/Source/Core/CorridorGeometryLibrary.js @@ -22,7 +22,7 @@ define([ "use strict"; /** - * private + * @private */ var CorridorGeometryLibrary = {}; @@ -47,6 +47,9 @@ define([ var originScratch = new Cartesian3(); var nextScratch = new Cartesian3(); var prevScratch = new Cartesian3(); + /** + * @private + */ CorridorGeometryLibrary.angleIsGreaterThanPi = function(forward, backward, position, ellipsoid) { var tangentPlane = new EllipsoidTangentPlane(position, ellipsoid); var origin = tangentPlane.projectPointOntoPlane(position, originScratch); @@ -61,6 +64,9 @@ define([ var quaterion = new Quaternion(); var rotMatrix = new Matrix3(); + /** + * @private + */ CorridorGeometryLibrary.computeRoundCorner = function (cornerPoint, startPoint, endPoint, cornerType, leftIsOutside, ellipsoid) { var angle = Cartesian3.angleBetween(startPoint.subtract(cornerPoint, scratch1), endPoint.subtract(cornerPoint, scratch2)); var granularity = (cornerType.value === CornerType.BEVELED.value) ? 1 : Math.ceil(angle / CesiumMath.toRadians(5)) + 1; @@ -91,6 +97,9 @@ define([ return array; }; + /** + * @private + */ CorridorGeometryLibrary.addEndCaps = function (calculatedPositions, width, ellipsoid) { var cornerPoint = cartesian1; var startPoint = cartesian2; @@ -113,6 +122,9 @@ define([ return [firstEndCap, lastEndCap]; }; + /** + * @private + */ CorridorGeometryLibrary.computeMiteredCorner = function (position, startPoint, leftCornerDirection, lastPoint, leftIsOutside, granularity, ellipsoid) { var cornerPoint = scratch1; if (leftIsOutside) { @@ -124,6 +136,9 @@ define([ return [cornerPoint.x, cornerPoint.y, cornerPoint.z, lastPoint.x, lastPoint.y, lastPoint.z]; }; + /** + * @private + */ CorridorGeometryLibrary.addAttribute = function (attribute, value, front, back) { var x = value.x; var y = value.y; @@ -140,7 +155,7 @@ define([ } }; - CorridorGeometryLibrary.addShiftedPositions = function(positions, left, scalar, calculatedPositions) { + function addShiftedPositions (positions, left, scalar, calculatedPositions) { var rightPositions = new Array(positions.length); var leftPositions = new Array(positions.length); var scaledLeft = left.multiplyByScalar(scalar, scratch1); @@ -163,8 +178,11 @@ define([ calculatedPositions.push(rightPositions, leftPositions); return calculatedPositions; - }; + } + /** + * @private + */ CorridorGeometryLibrary.computePositions = function (params) { var granularity = params.granularity; var positions = params.positions; @@ -222,7 +240,7 @@ define([ scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]); scaleArray2[1] = Cartesian3.clone(center, scaleArray2[1]); subdividedPositions = PolylinePipeline.scaleToSurface(scaleArray2, granularity, ellipsoid); - calculatedPositions = CorridorGeometryLibrary.addShiftedPositions(subdividedPositions, left, width, calculatedPositions); + calculatedPositions = addShiftedPositions(subdividedPositions, left, width, calculatedPositions); if (saveAttributes) { calculatedLefts.push(left.x, left.y, left.z); calculatedNormals.push(normal.x, normal.y, normal.z); @@ -243,7 +261,7 @@ define([ scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]); scaleArray2[1] = Cartesian3.clone(center, scaleArray2[1]); subdividedPositions = PolylinePipeline.scaleToSurface(scaleArray2, granularity, ellipsoid); - calculatedPositions = CorridorGeometryLibrary.addShiftedPositions(subdividedPositions, left, width, calculatedPositions); + calculatedPositions = addShiftedPositions(subdividedPositions, left, width, calculatedPositions); if (saveAttributes) { calculatedLefts.push(left.x, left.y, left.z); calculatedNormals.push(normal.x, normal.y, normal.z); @@ -267,7 +285,7 @@ define([ scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]); scaleArray2[1] = Cartesian3.clone(position, scaleArray2[1]); subdividedPositions = PolylinePipeline.scaleToSurface(scaleArray2, granularity, ellipsoid); - calculatedPositions = CorridorGeometryLibrary.addShiftedPositions(subdividedPositions, left, width, calculatedPositions); + calculatedPositions = addShiftedPositions(subdividedPositions, left, width, calculatedPositions); if (saveAttributes) { calculatedLefts.push(left.x, left.y, left.z); calculatedNormals.push(normal.x, normal.y, normal.z); diff --git a/Source/Core/CorridorOutlineGeometry.js b/Source/Core/CorridorOutlineGeometry.js index d0cd9c939748..05cc1623d462 100644 --- a/Source/Core/CorridorOutlineGeometry.js +++ b/Source/Core/CorridorOutlineGeometry.js @@ -54,7 +54,7 @@ define([ for (i = 0; i < positions.length; i += 2) { length = positions[i].length - 3; leftCount += length; //subtracting 3 to account for duplicate points at corners - indicesLength += length/3*4; + indicesLength += length / 3 * 4; rightCount += positions[i + 1].length - 3; } leftCount += 3; //add back count for end positions @@ -65,11 +65,11 @@ define([ if (defined(leftSide)) { length = leftSide.length; leftCount += length; - indicesLength += length/3*2; + indicesLength += length / 3 * 2; } else { length = corners[i].rightPositions.length; rightCount += length; - indicesLength += length/3*2; + indicesLength += length / 3 * 2; } } @@ -88,15 +88,15 @@ define([ var back = size - 1; var UL, LL, UR, LR; var rightPos, leftPos; - var halfLength = endPositionLength/2; + var halfLength = endPositionLength / 2; - var indices = IndexDatatype.createTypedArray(size/3, indicesLength + 4); + var indices = IndexDatatype.createTypedArray(size / 3, indicesLength + 4); var index = 0; - indices[index++] = front/3; - indices[index++] = (back-2)/3; + indices[index++] = front / 3; + indices[index++] = (back - 2) / 3; if (addEndPositions) { // add rounded end - wallIndices.push(front/3); + wallIndices.push(front / 3); leftPos = cartesian1; rightPos = cartesian2; var firstEndPositions = endPositions[0]; @@ -106,9 +106,9 @@ define([ CorridorGeometryLibrary.addAttribute(finalPositions, rightPos, front); CorridorGeometryLibrary.addAttribute(finalPositions, leftPos, undefined, back); - LL = front/3; + LL = front / 3; LR = LL + 1; - UL = (back-2)/3; + UL = (back - 2) / 3; UR = UL - 1; indices[index++] = UL; indices[index++] = UR; @@ -121,24 +121,23 @@ define([ } var posIndex = 0; - var rightEdge = positions[posIndex++]; //add first two edges + var rightEdge = positions[posIndex++]; //add first two edges var leftEdge = positions[posIndex++]; finalPositions.set(rightEdge, front); finalPositions.set(leftEdge, back - leftEdge.length + 1); length = leftEdge.length - 3; - wallIndices.push(front/3, (back-2)/3); - for(i = 0; i < length; i+=3) { - LL = front/3; + wallIndices.push(front / 3, (back - 2) / 3); + for (i = 0; i < length; i += 3) { + LL = front / 3; LR = LL + 1; - UL = (back-2)/3; + UL = (back - 2) / 3; UR = UL - 1; indices[index++] = UL; indices[index++] = UR; indices[index++] = LL; indices[index++] = LR; - front += 3; back -= 3; } @@ -154,27 +153,27 @@ define([ back -= 3; start = UR; wallIndices.push(start, LR); - for (j = 0; j < l.length/3; j++) { - outsidePoint = Cartesian3.fromArray(l, j*3, outsidePoint); + for (j = 0; j < l.length / 3; j++) { + outsidePoint = Cartesian3.fromArray(l, j * 3, outsidePoint); indices[index++] = start - j - 1; indices[index++] = start - j; CorridorGeometryLibrary.addAttribute(finalPositions, outsidePoint, undefined, back); back -= 3; } - wallIndices.push(start - Math.floor(l.length/6), (back-2)/3 + 1); + wallIndices.push(start - Math.floor(l.length / 6), (back - 2) / 3 + 1); front += 3; } else { front += 3; start = LR; wallIndices.push(start, UR); - for (j = 0; j < r.length/3; j++) { - outsidePoint = Cartesian3.fromArray(r, j*3, outsidePoint); + for (j = 0; j < r.length / 3; j++) { + outsidePoint = Cartesian3.fromArray(r, j * 3, outsidePoint); indices[index++] = start + j; indices[index++] = start + j + 1; CorridorGeometryLibrary.addAttribute(finalPositions, outsidePoint, front); front += 3; } - wallIndices.push(start + Math.floor(r.length/6), front/3 - 1); + wallIndices.push(start + Math.floor(r.length / 6), front / 3 - 1); back -= 3; } rightEdge = positions[posIndex++]; @@ -185,10 +184,10 @@ define([ finalPositions.set(leftEdge, back - leftEdge.length + 1); length = leftEdge.length - 3; - for(j = 0; j < leftEdge.length; j+=3) { - LR = front/3; + for (j = 0; j < leftEdge.length; j += 3) { + LR = front / 3; LL = LR - 1; - UR = (back-2)/3; + UR = (back - 2) / 3; UL = UR + 1; indices[index++] = UL; indices[index++] = UR; @@ -199,10 +198,10 @@ define([ } front -= 3; back += 3; - wallIndices.push(front/3, (back-2)/3); + wallIndices.push(front / 3, (back - 2) / 3); } - if (addEndPositions) { // add rounded end + if (addEndPositions) { // add rounded end front += 3; back -= 3; leftPos = cartesian1; @@ -214,9 +213,9 @@ define([ CorridorGeometryLibrary.addAttribute(finalPositions, leftPos, undefined, back); CorridorGeometryLibrary.addAttribute(finalPositions, rightPos, front); - LR = front/3; + LR = front / 3; LL = LR - 1; - UR = (back-2)/3; + UR = (back - 2) / 3; UL = UR + 1; indices[index++] = UL; indices[index++] = UR; @@ -227,11 +226,11 @@ define([ back -= 3; } } - indices[index++] = front/3; - indices[index++] = (back-2)/3; + indices[index++] = front / 3; + indices[index++] = (back - 2) / 3; if (i === 0) { - wallIndices.push(front/3, (back-2)/3); + wallIndices.push(front / 3, (back - 2) / 3); } attributes.position = new GeometryAttribute({ @@ -241,10 +240,9 @@ define([ }); return { - attributes: attributes, - indices: indices, - boundingSphere: BoundingSphere.fromVertices(finalPositions), - wallIndices: wallIndices + attributes : attributes, + indices : indices, + wallIndices : wallIndices }; } @@ -257,7 +255,6 @@ define([ var extrudedHeight = params.extrudedHeight; var attributes = attr.attributes; var indices = attr.indices; - var boundingSphere = attr.boundingSphere; var positions = attributes.position.values; var length = positions.length; var extrudedPositions = new Float64Array(length); @@ -268,7 +265,6 @@ define([ extrudedPositions = PolylinePipeline.scaleToGeodeticHeight(extrudedPositions, extrudedHeight, ellipsoid); newPositions.set(positions); newPositions.set(extrudedPositions, length); - boundingSphere = BoundingSphere.fromVertices(positions, undefined, 3, boundingSphere); attributes.position.values = newPositions; length /= 3; @@ -277,7 +273,7 @@ define([ var newIndices = IndexDatatype.createTypedArray(newPositions.length / 3, (iLength + wallIndices.length) * 2); newIndices.set(indices); var index = iLength; - for (i = 0; i < iLength; i+=2) { // bottom indices + for (i = 0; i < iLength; i += 2) { // bottom indices var v0 = indices[i]; var v1 = indices[i + 1]; newIndices[index++] = v0 + length; @@ -293,20 +289,19 @@ define([ } return { - attributes: attributes, - indices: newIndices, - boundingSphere: boundingSphere + attributes : attributes, + indices : newIndices }; } /** - * A description of a corridor. + * A description of a corridor outline. * * @alias CorridorOutlineGeometry * @constructor * - * @param {Array} options.positions An array of {Cartesain3} positions that define the center of the corridor. - * @param {Number} options.width The distance between the edges of the corridor. + * @param {Array} options.positions An array of {Cartesain3} positions that define the center of the corridor outline. + * @param {Number} options.width The distance between the edges of the corridor outline. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer. * @param {Number} [options.height=0] The distance between the ellipsoid surface and the positions. @@ -369,12 +364,12 @@ define([ } var ellipsoid = corridorOutlineGeometry._ellipsoid; var params = { - ellipsoid: ellipsoid, - positions: cleanPositions, - width: corridorOutlineGeometry._width, - cornerType: corridorOutlineGeometry._cornerType, - granularity: corridorOutlineGeometry._granularity, - saveAttributes: false + ellipsoid : ellipsoid, + positions : cleanPositions, + width : corridorOutlineGeometry._width, + cornerType : corridorOutlineGeometry._cornerType, + granularity : corridorOutlineGeometry._granularity, + saveAttributes : false }; var attr; if (extrude) { @@ -390,12 +385,13 @@ define([ attr.attributes.position.values = new Float64Array(PolylinePipeline.scaleToGeodeticHeight(attr.attributes.position.values, height, ellipsoid)); } var attributes = attr.attributes; + var boundingSphere = BoundingSphere.fromVertices(attributes.position.values, undefined, 3); return new Geometry({ attributes : attributes, - indices : IndexDatatype.createTypedArray(attributes.position.values.length/3, attr.indices), + indices : attr.indices, primitiveType : PrimitiveType.LINES, - boundingSphere : attr.boundingSphere + boundingSphere : boundingSphere }); };