123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- define(['exports', './when-8d13db60', './Check-70bec281', './Math-61ede240', './Cartographic-fe4be337', './Cartesian2-85064f09', './BoundingSphere-775c5788', './ComponentDatatype-5862616f', './GeometryAttribute-91704ebb', './PrimitiveType-97893bc7', './GeometryAttributes-aacecde6', './IndexDatatype-9435b55f', './GeometryOffsetAttribute-ca302482', './EllipseGeometryLibrary-08dbcdef'], function (exports, when, Check, _Math, Cartographic, Cartesian2, BoundingSphere, ComponentDatatype, GeometryAttribute, PrimitiveType, GeometryAttributes, IndexDatatype, GeometryOffsetAttribute, EllipseGeometryLibrary) { 'use strict';
- var scratchCartesian1 = new Cartographic.Cartesian3();
- var boundingSphereCenter = new Cartographic.Cartesian3();
- function computeEllipse(options) {
- var center = options.center;
- boundingSphereCenter = Cartographic.Cartesian3.multiplyByScalar(options.ellipsoid.geodeticSurfaceNormal(center, boundingSphereCenter), options.height, boundingSphereCenter);
- boundingSphereCenter = Cartographic.Cartesian3.add(center, boundingSphereCenter, boundingSphereCenter);
- var boundingSphere = new BoundingSphere.BoundingSphere(boundingSphereCenter, options.semiMajorAxis);
- var positions = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(options, false, true).outerPositions;
- var attributes = new GeometryAttributes.GeometryAttributes({
- position: new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
- componentsPerAttribute : 3,
- values : EllipseGeometryLibrary.EllipseGeometryLibrary.raisePositionsToHeight(positions, options, false)
- })
- });
- var length = positions.length / 3;
- var indices = IndexDatatype.IndexDatatype.createTypedArray(length, length * 2);
- var index = 0;
- for ( var i = 0; i < length; ++i) {
- indices[index++] = i;
- indices[index++] = (i + 1) % length;
- }
- return {
- boundingSphere : boundingSphere,
- attributes : attributes,
- indices : indices
- };
- }
- var topBoundingSphere = new BoundingSphere.BoundingSphere();
- var bottomBoundingSphere = new BoundingSphere.BoundingSphere();
- function computeExtrudedEllipse(options) {
- var center = options.center;
- var ellipsoid = options.ellipsoid;
- var semiMajorAxis = options.semiMajorAxis;
- var scaledNormal = Cartographic.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center, scratchCartesian1), options.height, scratchCartesian1);
- topBoundingSphere.center = Cartographic.Cartesian3.add(center, scaledNormal, topBoundingSphere.center);
- topBoundingSphere.radius = semiMajorAxis;
- scaledNormal = Cartographic.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center, scaledNormal), options.extrudedHeight, scaledNormal);
- bottomBoundingSphere.center = Cartographic.Cartesian3.add(center, scaledNormal, bottomBoundingSphere.center);
- bottomBoundingSphere.radius = semiMajorAxis;
- var positions = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(options, false, true).outerPositions;
- var attributes = new GeometryAttributes.GeometryAttributes({
- position: new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
- componentsPerAttribute : 3,
- values : EllipseGeometryLibrary.EllipseGeometryLibrary.raisePositionsToHeight(positions, options, true)
- })
- });
- positions = attributes.position.values;
- var boundingSphere = BoundingSphere.BoundingSphere.union(topBoundingSphere, bottomBoundingSphere);
- var length = positions.length/3;
- if (when.defined(options.offsetAttribute)) {
- var applyOffset = new Uint8Array(length);
- if (options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
- applyOffset = GeometryOffsetAttribute.arrayFill(applyOffset, 1, 0, length / 2);
- } else {
- var offsetValue = options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
- applyOffset = GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
- }
- attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
- componentsPerAttribute : 1,
- values: applyOffset
- });
- }
- var numberOfVerticalLines = when.defaultValue(options.numberOfVerticalLines, 16);
- numberOfVerticalLines = _Math.CesiumMath.clamp(numberOfVerticalLines, 0, length/2);
- var indices = IndexDatatype.IndexDatatype.createTypedArray(length, length * 2 + numberOfVerticalLines * 2);
- length /= 2;
- var index = 0;
- var i;
- for (i = 0; i < length; ++i) {
- indices[index++] = i;
- indices[index++] = (i + 1) % length;
- indices[index++] = i + length;
- indices[index++] = ((i + 1) % length) + length;
- }
- var numSide;
- if (numberOfVerticalLines > 0) {
- var numSideLines = Math.min(numberOfVerticalLines, length);
- numSide = Math.round(length / numSideLines);
- var maxI = Math.min(numSide * numberOfVerticalLines, length);
- for (i = 0; i < maxI; i += numSide) {
- indices[index++] = i;
- indices[index++] = i + length;
- }
- }
- return {
- boundingSphere : boundingSphere,
- attributes : attributes,
- indices : indices
- };
- }
-
- function EllipseOutlineGeometry(options) {
- options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
- var center = options.center;
- var ellipsoid = when.defaultValue(options.ellipsoid, Cartesian2.Ellipsoid.WGS84);
- var semiMajorAxis = options.semiMajorAxis;
- var semiMinorAxis = options.semiMinorAxis;
- var granularity = when.defaultValue(options.granularity, _Math.CesiumMath.RADIANS_PER_DEGREE);
-
- if (!when.defined(center)) {
- throw new Check.DeveloperError('center is required.');
- }
- if (!when.defined(semiMajorAxis)) {
- throw new Check.DeveloperError('semiMajorAxis is required.');
- }
- if (!when.defined(semiMinorAxis)) {
- throw new Check.DeveloperError('semiMinorAxis is required.');
- }
- if (semiMajorAxis < semiMinorAxis) {
- throw new Check.DeveloperError('semiMajorAxis must be greater than or equal to the semiMinorAxis.');
- }
- if (granularity <= 0.0) {
- throw new Check.DeveloperError('granularity must be greater than zero.');
- }
-
- var height = when.defaultValue(options.height, 0.0);
- var extrudedHeight = when.defaultValue(options.extrudedHeight, height);
- this._center = Cartographic.Cartesian3.clone(center);
- this._semiMajorAxis = semiMajorAxis;
- this._semiMinorAxis = semiMinorAxis;
- this._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid);
- this._rotation = when.defaultValue(options.rotation, 0.0);
- this._height = Math.max(extrudedHeight, height);
- this._granularity = granularity;
- this._extrudedHeight = Math.min(extrudedHeight, height);
- this._numberOfVerticalLines = Math.max(when.defaultValue(options.numberOfVerticalLines, 16), 0);
- this._offsetAttribute = options.offsetAttribute;
- this._workerName = 'createEllipseOutlineGeometry';
- }
-
- EllipseOutlineGeometry.packedLength = Cartographic.Cartesian3.packedLength + Cartesian2.Ellipsoid.packedLength + 8;
-
- EllipseOutlineGeometry.pack = function(value, array, startingIndex) {
-
- if (!when.defined(value)) {
- throw new Check.DeveloperError('value is required');
- }
- if (!when.defined(array)) {
- throw new Check.DeveloperError('array is required');
- }
-
- startingIndex = when.defaultValue(startingIndex, 0);
- Cartographic.Cartesian3.pack(value._center, array, startingIndex);
- startingIndex += Cartographic.Cartesian3.packedLength;
- Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
- startingIndex += Cartesian2.Ellipsoid.packedLength;
- array[startingIndex++] = value._semiMajorAxis;
- array[startingIndex++] = value._semiMinorAxis;
- array[startingIndex++] = value._rotation;
- array[startingIndex++] = value._height;
- array[startingIndex++] = value._granularity;
- array[startingIndex++] = value._extrudedHeight;
- array[startingIndex++] = value._numberOfVerticalLines;
- array[startingIndex] = when.defaultValue(value._offsetAttribute, -1);
- return array;
- };
- var scratchCenter = new Cartographic.Cartesian3();
- var scratchEllipsoid = new Cartesian2.Ellipsoid();
- var scratchOptions = {
- center : scratchCenter,
- ellipsoid : scratchEllipsoid,
- semiMajorAxis : undefined,
- semiMinorAxis : undefined,
- rotation : undefined,
- height : undefined,
- granularity : undefined,
- extrudedHeight : undefined,
- numberOfVerticalLines : undefined,
- offsetAttribute: undefined
- };
-
- EllipseOutlineGeometry.unpack = function(array, startingIndex, result) {
-
- if (!when.defined(array)) {
- throw new Check.DeveloperError('array is required');
- }
-
- startingIndex = when.defaultValue(startingIndex, 0);
- var center = Cartographic.Cartesian3.unpack(array, startingIndex, scratchCenter);
- startingIndex += Cartographic.Cartesian3.packedLength;
- var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
- startingIndex += Cartesian2.Ellipsoid.packedLength;
- var semiMajorAxis = array[startingIndex++];
- var semiMinorAxis = array[startingIndex++];
- var rotation = array[startingIndex++];
- var height = array[startingIndex++];
- var granularity = array[startingIndex++];
- var extrudedHeight = array[startingIndex++];
- var numberOfVerticalLines = array[startingIndex++];
- var offsetAttribute = array[startingIndex];
- if (!when.defined(result)) {
- scratchOptions.height = height;
- scratchOptions.extrudedHeight = extrudedHeight;
- scratchOptions.granularity = granularity;
- scratchOptions.rotation = rotation;
- scratchOptions.semiMajorAxis = semiMajorAxis;
- scratchOptions.semiMinorAxis = semiMinorAxis;
- scratchOptions.numberOfVerticalLines = numberOfVerticalLines;
- scratchOptions.offsetAttribute = offsetAttribute === -1 ? undefined : offsetAttribute;
- return new EllipseOutlineGeometry(scratchOptions);
- }
- result._center = Cartographic.Cartesian3.clone(center, result._center);
- result._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
- result._semiMajorAxis = semiMajorAxis;
- result._semiMinorAxis = semiMinorAxis;
- result._rotation = rotation;
- result._height = height;
- result._granularity = granularity;
- result._extrudedHeight = extrudedHeight;
- result._numberOfVerticalLines = numberOfVerticalLines;
- result._offsetAttribute = offsetAttribute === -1 ? undefined : offsetAttribute;
- return result;
- };
-
- EllipseOutlineGeometry.createGeometry = function(ellipseGeometry) {
- if ((ellipseGeometry._semiMajorAxis <= 0.0) || (ellipseGeometry._semiMinorAxis <= 0.0)) {
- return;
- }
- var height = ellipseGeometry._height;
- var extrudedHeight = ellipseGeometry._extrudedHeight;
- var extrude = !_Math.CesiumMath.equalsEpsilon(height, extrudedHeight, 0, _Math.CesiumMath.EPSILON2);
- ellipseGeometry._center = ellipseGeometry._ellipsoid.scaleToGeodeticSurface(ellipseGeometry._center, ellipseGeometry._center);
- var options = {
- center : ellipseGeometry._center,
- semiMajorAxis : ellipseGeometry._semiMajorAxis,
- semiMinorAxis : ellipseGeometry._semiMinorAxis,
- ellipsoid : ellipseGeometry._ellipsoid,
- rotation : ellipseGeometry._rotation,
- height : height,
- granularity : ellipseGeometry._granularity,
- numberOfVerticalLines : ellipseGeometry._numberOfVerticalLines
- };
- var geometry;
- if (extrude) {
- options.extrudedHeight = extrudedHeight;
- options.offsetAttribute = ellipseGeometry._offsetAttribute;
- geometry = computeExtrudedEllipse(options);
- } else {
- geometry = computeEllipse(options);
- if (when.defined(ellipseGeometry._offsetAttribute)) {
- var length = geometry.attributes.position.values.length;
- var applyOffset = new Uint8Array(length / 3);
- var offsetValue = ellipseGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
- GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
- geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
- componentsPerAttribute : 1,
- values: applyOffset
- });
- }
- }
- return new GeometryAttribute.Geometry({
- attributes : geometry.attributes,
- indices : geometry.indices,
- primitiveType : PrimitiveType.PrimitiveType.LINES,
- boundingSphere : geometry.boundingSphere,
- offsetAttribute : ellipseGeometry._offsetAttribute
- });
- };
- exports.EllipseOutlineGeometry = EllipseOutlineGeometry;
- });
|