You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
233 lines
8.7 KiB
JavaScript
233 lines
8.7 KiB
JavaScript
/* This file is automatically rebuilt by the Cesium build process. */
|
|
define(['./arrayRemoveDuplicates-618d22a8', './Transforms-eb995198', './Cartesian2-44e93af5', './Check-285f6bfc', './ComponentDatatype-d4a0149c', './CoplanarPolygonGeometryLibrary-be90de6c', './when-f31b6bd1', './GeometryAttribute-cc0565cd', './GeometryAttributes-e973821e', './GeometryInstance-3f5c1f37', './GeometryPipeline-83d68cb3', './IndexDatatype-e20e62f1', './PolygonGeometryLibrary-d0239232', './Math-8c161f1c', './RuntimeError-c7c236f3', './WebGLConstants-34c08bc0', './OrientedBoundingBox-8f3c3305', './EllipsoidTangentPlane-ffd45139', './IntersectionTests-db497aaf', './Plane-16f95004', './AttributeCompression-e3a6496c', './EncodedCartesian3-58bad53b', './ArcType-13a53523', './EllipsoidRhumbLine-b65d3f48', './PolygonPipeline-0ced7860'], function (arrayRemoveDuplicates, Transforms, Cartesian2, Check, ComponentDatatype, CoplanarPolygonGeometryLibrary, when, GeometryAttribute, GeometryAttributes, GeometryInstance, GeometryPipeline, IndexDatatype, PolygonGeometryLibrary, _Math, RuntimeError, WebGLConstants, OrientedBoundingBox, EllipsoidTangentPlane, IntersectionTests, Plane, AttributeCompression, EncodedCartesian3, ArcType, EllipsoidRhumbLine, PolygonPipeline) { 'use strict';
|
|
|
|
function createGeometryFromPositions(positions) {
|
|
var length = positions.length;
|
|
var flatPositions = new Float64Array(length * 3);
|
|
var indices = IndexDatatype.IndexDatatype.createTypedArray(length, length * 2);
|
|
|
|
var positionIndex = 0;
|
|
var index = 0;
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
var position = positions[i];
|
|
flatPositions[positionIndex++] = position.x;
|
|
flatPositions[positionIndex++] = position.y;
|
|
flatPositions[positionIndex++] = position.z;
|
|
|
|
indices[index++] = i;
|
|
indices[index++] = (i + 1) % length;
|
|
}
|
|
|
|
var attributes = new GeometryAttributes.GeometryAttributes({
|
|
position: new GeometryAttribute.GeometryAttribute({
|
|
componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
|
|
componentsPerAttribute: 3,
|
|
values: flatPositions,
|
|
}),
|
|
});
|
|
|
|
return new GeometryAttribute.Geometry({
|
|
attributes: attributes,
|
|
indices: indices,
|
|
primitiveType: GeometryAttribute.PrimitiveType.LINES,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* A description of the outline of a polygon composed of arbitrary coplanar positions.
|
|
*
|
|
* @alias CoplanarPolygonOutlineGeometry
|
|
* @constructor
|
|
*
|
|
* @param {Object} options Object with the following properties:
|
|
* @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.
|
|
*
|
|
* @see CoplanarPolygonOutlineGeometry.createGeometry
|
|
*
|
|
* @example
|
|
* var polygonOutline = new Cesium.CoplanarPolygonOutlineGeometry({
|
|
* positions : Cesium.Cartesian3.fromDegreesArrayHeights([
|
|
* -90.0, 30.0, 0.0,
|
|
* -90.0, 30.0, 1000.0,
|
|
* -80.0, 30.0, 1000.0,
|
|
* -80.0, 30.0, 0.0
|
|
* ])
|
|
* });
|
|
* var geometry = Cesium.CoplanarPolygonOutlineGeometry.createGeometry(polygonOutline);
|
|
*/
|
|
function CoplanarPolygonOutlineGeometry(options) {
|
|
options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
|
|
var polygonHierarchy = options.polygonHierarchy;
|
|
//>>includeStart('debug', pragmas.debug);
|
|
Check.Check.defined("options.polygonHierarchy", polygonHierarchy);
|
|
//>>includeEnd('debug');
|
|
|
|
this._polygonHierarchy = polygonHierarchy;
|
|
this._workerName = "createCoplanarPolygonOutlineGeometry";
|
|
|
|
/**
|
|
* The number of elements used to pack the object into an array.
|
|
* @type {Number}
|
|
*/
|
|
this.packedLength =
|
|
PolygonGeometryLibrary.PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + 1;
|
|
}
|
|
|
|
/**
|
|
* A description of a coplanar polygon outline from an array of positions.
|
|
*
|
|
* @param {Object} options Object with the following properties:
|
|
* @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.
|
|
* @returns {CoplanarPolygonOutlineGeometry}
|
|
*/
|
|
CoplanarPolygonOutlineGeometry.fromPositions = function (options) {
|
|
options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
Check.Check.defined("options.positions", options.positions);
|
|
//>>includeEnd('debug');
|
|
|
|
var newOptions = {
|
|
polygonHierarchy: {
|
|
positions: options.positions,
|
|
},
|
|
};
|
|
return new CoplanarPolygonOutlineGeometry(newOptions);
|
|
};
|
|
|
|
/**
|
|
* Stores the provided instance into the provided array.
|
|
*
|
|
* @param {CoplanarPolygonOutlineGeometry} value The value to pack.
|
|
* @param {Number[]} array The array to pack into.
|
|
* @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
|
|
*
|
|
* @returns {Number[]} The array that was packed into
|
|
*/
|
|
CoplanarPolygonOutlineGeometry.pack = function (value, array, startingIndex) {
|
|
//>>includeStart('debug', pragmas.debug);
|
|
Check.Check.typeOf.object("value", value);
|
|
Check.Check.defined("array", array);
|
|
//>>includeEnd('debug');
|
|
|
|
startingIndex = when.defaultValue(startingIndex, 0);
|
|
|
|
startingIndex = PolygonGeometryLibrary.PolygonGeometryLibrary.packPolygonHierarchy(
|
|
value._polygonHierarchy,
|
|
array,
|
|
startingIndex
|
|
);
|
|
|
|
array[startingIndex] = value.packedLength;
|
|
|
|
return array;
|
|
};
|
|
|
|
var scratchOptions = {
|
|
polygonHierarchy: {},
|
|
};
|
|
/**
|
|
* Retrieves an instance from a packed array.
|
|
*
|
|
* @param {Number[]} array The packed array.
|
|
* @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
|
|
* @param {CoplanarPolygonOutlineGeometry} [result] The object into which to store the result.
|
|
* @returns {CoplanarPolygonOutlineGeometry} The modified result parameter or a new CoplanarPolygonOutlineGeometry instance if one was not provided.
|
|
*/
|
|
CoplanarPolygonOutlineGeometry.unpack = function (
|
|
array,
|
|
startingIndex,
|
|
result
|
|
) {
|
|
//>>includeStart('debug', pragmas.debug);
|
|
Check.Check.defined("array", array);
|
|
//>>includeEnd('debug');
|
|
|
|
startingIndex = when.defaultValue(startingIndex, 0);
|
|
|
|
var polygonHierarchy = PolygonGeometryLibrary.PolygonGeometryLibrary.unpackPolygonHierarchy(
|
|
array,
|
|
startingIndex
|
|
);
|
|
startingIndex = polygonHierarchy.startingIndex;
|
|
delete polygonHierarchy.startingIndex;
|
|
var packedLength = array[startingIndex];
|
|
|
|
if (!when.defined(result)) {
|
|
result = new CoplanarPolygonOutlineGeometry(scratchOptions);
|
|
}
|
|
|
|
result._polygonHierarchy = polygonHierarchy;
|
|
result.packedLength = packedLength;
|
|
|
|
return result;
|
|
};
|
|
|
|
/**
|
|
* Computes the geometric representation of an arbitrary coplanar polygon, including its vertices, indices, and a bounding sphere.
|
|
*
|
|
* @param {CoplanarPolygonOutlineGeometry} polygonGeometry A description of the polygon.
|
|
* @returns {Geometry|undefined} The computed vertices and indices.
|
|
*/
|
|
CoplanarPolygonOutlineGeometry.createGeometry = function (polygonGeometry) {
|
|
var polygonHierarchy = polygonGeometry._polygonHierarchy;
|
|
|
|
var outerPositions = polygonHierarchy.positions;
|
|
outerPositions = arrayRemoveDuplicates.arrayRemoveDuplicates(
|
|
outerPositions,
|
|
Cartesian2.Cartesian3.equalsEpsilon,
|
|
true
|
|
);
|
|
if (outerPositions.length < 3) {
|
|
return;
|
|
}
|
|
var isValid = CoplanarPolygonGeometryLibrary.CoplanarPolygonGeometryLibrary.validOutline(outerPositions);
|
|
if (!isValid) {
|
|
return undefined;
|
|
}
|
|
|
|
var polygons = PolygonGeometryLibrary.PolygonGeometryLibrary.polygonOutlinesFromHierarchy(
|
|
polygonHierarchy,
|
|
false
|
|
);
|
|
|
|
if (polygons.length === 0) {
|
|
return undefined;
|
|
}
|
|
|
|
var geometries = [];
|
|
|
|
for (var i = 0; i < polygons.length; i++) {
|
|
var geometryInstance = new GeometryInstance.GeometryInstance({
|
|
geometry: createGeometryFromPositions(polygons[i]),
|
|
});
|
|
geometries.push(geometryInstance);
|
|
}
|
|
|
|
var geometry = GeometryPipeline.GeometryPipeline.combineInstances(geometries)[0];
|
|
var boundingSphere = Transforms.BoundingSphere.fromPoints(polygonHierarchy.positions);
|
|
|
|
return new GeometryAttribute.Geometry({
|
|
attributes: geometry.attributes,
|
|
indices: geometry.indices,
|
|
primitiveType: geometry.primitiveType,
|
|
boundingSphere: boundingSphere,
|
|
});
|
|
};
|
|
|
|
function createCoplanarPolygonOutlineGeometry(polygonGeometry, offset) {
|
|
if (when.defined(offset)) {
|
|
polygonGeometry = CoplanarPolygonOutlineGeometry.unpack(
|
|
polygonGeometry,
|
|
offset
|
|
);
|
|
}
|
|
polygonGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(polygonGeometry._ellipsoid);
|
|
return CoplanarPolygonOutlineGeometry.createGeometry(polygonGeometry);
|
|
}
|
|
|
|
return createCoplanarPolygonOutlineGeometry;
|
|
|
|
});
|