createPolylineVolumeGeometry.js 6.49 KB
Newer Older
Patrick's avatar
Patrick committed
1
/**
Patrick's avatar
Patrick committed
2
 * Cesium - https://github.com/CesiumGS/cesium
Patrick's avatar
Patrick committed
3
 *
Patrick's avatar
Patrick committed
4
 * Copyright 2011-2020 Cesium Contributors
Patrick's avatar
Patrick committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Columbus View (Pat. Pend.)
 *
 * Portions licensed separately.
Patrick's avatar
Patrick committed
21
 * See https://github.com/CesiumGS/cesium/blob/master/LICENSE.md for full licensing details.
Patrick's avatar
Patrick committed
22
 */
Patrick's avatar
Patrick committed
23
define(["./when-60b00257","./Check-4274a1fd","./Math-9d37f659","./Cartesian2-2951f601","./Transforms-53ff6d12","./RuntimeError-027c380a","./WebGLConstants-779bf0bc","./ComponentDatatype-a29c6075","./GeometryAttribute-2f728681","./GeometryAttributes-130e4d69","./AttributeCompression-a0720a96","./GeometryPipeline-7b394c2b","./EncodedCartesian3-c262bebc","./IndexDatatype-527cbd94","./IntersectionTests-57fe18b2","./Plane-df4a621e","./VertexFormat-6af5bab1","./arrayRemoveDuplicates-ac049603","./BoundingRectangle-762cb49e","./EllipsoidTangentPlane-f9b097b8","./EllipsoidRhumbLine-cbcd6a13","./PolygonPipeline-72c6abb2","./PolylineVolumeGeometryLibrary-a55f99d5","./EllipsoidGeodesic-0d3740b4","./PolylinePipeline-30fab084"],function(u,e,i,c,G,t,n,A,R,D,r,I,a,O,o,l,g,s,p,d,y,S,m,h,f){"use strict";var b={};function B(e,t){u.defined(b[e])||(b[e]=!0,console.warn(u.defaultValue(t,e)))}function v(e){var t=(e=u.defaultValue(e,u.defaultValue.EMPTY_OBJECT)).polylinePositions,n=e.shapePositions;this._positions=t,this._shape=n,this._ellipsoid=c.Ellipsoid.clone(u.defaultValue(e.ellipsoid,c.Ellipsoid.WGS84)),this._cornerType=u.defaultValue(e.cornerType,m.CornerType.ROUNDED),this._vertexFormat=g.VertexFormat.clone(u.defaultValue(e.vertexFormat,g.VertexFormat.DEFAULT)),this._granularity=u.defaultValue(e.granularity,i.CesiumMath.RADIANS_PER_DEGREE),this._workerName="createPolylineVolumeGeometry";var r=1+t.length*c.Cartesian3.packedLength;r+=1+n.length*c.Cartesian2.packedLength,this.packedLength=r+c.Ellipsoid.packedLength+g.VertexFormat.packedLength+2}B.geometryOutlines="Entity geometry outlines are unsupported on terrain. Outlines will be disabled. To enable outlines, disable geometry terrain clamping by explicitly setting height to 0.",B.geometryZIndex="Entity geometry with zIndex are unsupported when height or extrudedHeight are defined.  zIndex will be ignored",B.geometryHeightReference="Entity corridor, ellipse, polygon or rectangle with heightReference must also have a defined height.  heightReference will be ignored",B.geometryExtrudedHeightReference="Entity corridor, ellipse, polygon or rectangle with extrudedHeightReference must also have a defined extrudedHeight.  extrudedHeightReference will be ignored",v.pack=function(e,t,n){var r;n=u.defaultValue(n,0);var i=e._positions,a=i.length;for(t[n++]=a,r=0;r<a;++r,n+=c.Cartesian3.packedLength)c.Cartesian3.pack(i[r],t,n);var o=e._shape;for(a=o.length,t[n++]=a,r=0;r<a;++r,n+=c.Cartesian2.packedLength)c.Cartesian2.pack(o[r],t,n);return c.Ellipsoid.pack(e._ellipsoid,t,n),n+=c.Ellipsoid.packedLength,g.VertexFormat.pack(e._vertexFormat,t,n),n+=g.VertexFormat.packedLength,t[n++]=e._cornerType,t[n]=e._granularity,t};var E=c.Ellipsoid.clone(c.Ellipsoid.UNIT_SPHERE),P=new g.VertexFormat,_={polylinePositions:void 0,shapePositions:void 0,ellipsoid:E,vertexFormat:P,cornerType:void 0,granularity:void 0};v.unpack=function(e,t,n){var r;t=u.defaultValue(t,0);var i=e[t++],a=new Array(i);for(r=0;r<i;++r,t+=c.Cartesian3.packedLength)a[r]=c.Cartesian3.unpack(e,t);i=e[t++];var o=new Array(i);for(r=0;r<i;++r,t+=c.Cartesian2.packedLength)o[r]=c.Cartesian2.unpack(e,t);var l=c.Ellipsoid.unpack(e,t,E);t+=c.Ellipsoid.packedLength;var s=g.VertexFormat.unpack(e,t,P);t+=g.VertexFormat.packedLength;var p=e[t++],d=e[t];return u.defined(n)?(n._positions=a,n._shape=o,n._ellipsoid=c.Ellipsoid.clone(l,n._ellipsoid),n._vertexFormat=g.VertexFormat.clone(s,n._vertexFormat),n._cornerType=p,n._granularity=d,n):(_.polylinePositions=a,_.shapePositions=o,_.cornerType=p,_.granularity=d,new v(_))};var x=new p.BoundingRectangle;return v.createGeometry=function(e){var t=e._positions,n=s.arrayRemoveDuplicates(t,c.Cartesian3.equalsEpsilon),r=e._shape;if(r=m.PolylineVolumeGeometryLibrary.removeDuplicatesFromShape(r),!(n.length<2||r.length<3)){S.PolygonPipeline.computeWindingOrder2D(r)===S.WindingOrder.CLOCKWISE&&r.reverse();var i=p.BoundingRectangle.fromPoints(r,x);return function(e,t,n,r){var i=new D.GeometryAttributes;r.position&&(i.position=new R.GeometryAttribute({componentDatatype:A.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:e}));var a,o,l,s,p,d,u=t.length,c=e.length/3,g=(c-2*u)/(2*u),y=S.PolygonPipeline.triangulate(t),m=(g-1)*u*6+2*y.length,h=O.IndexDatatype.createTypedArray(c,m),f=2*u,b=0;for(a=0;a<g-1;a++){for(o=0;o<u-1;o++)d=(l=2*o+a*u*2)+f,p=(s=l+1)+f,h[b++]=s,h[b++]=l,h[b++]=p,h[b++]=p,h[b++]=l,h[b++]=d;p=(s=(l=2*u-2+a*u*2)+1)+f,d=l+f,h[b++]=s,h[b++]=l,h[b++]=p,h[b++]=p,h[b++]=l,h[b++]=d}if(r.st||r.tangent||r.bitangent){var v,E,P=new Float32Array(2*c),_=1/(g-1),x=1/n.height,k=n.height/2,C=0;for(a=0;a<g;a++){for(v=a*_,E=x*(t[0].y+k),P[C++]=v,P[C++]=E,o=1;o<u;o++)E=x*(t[o].y+k),P[C++]=v,P[C++]=E,P[C++]=v,P[C++]=E;E=x*(t[0].y+k),P[C++]=v,P[C++]=E}for(o=0;o<u;o++)v=0,E=x*(t[o].y+k),P[C++]=v,P[C++]=E;for(o=0;o<u;o++)v=(g-1)*_,E=x*(t[o].y+k),P[C++]=v,P[C++]=E;i.st=new R.GeometryAttribute({componentDatatype:A.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:new Float32Array(P)})}var V=c-2*u;for(a=0;a<y.length;a+=3){var L=y[a]+V,w=y[a+1]+V,F=y[a+2]+V;h[b++]=L,h[b++]=w,h[b++]=F,h[b++]=F+u,h[b++]=w+u,h[b++]=L+u}var T=new R.Geometry({attributes:i,indices:h,boundingSphere:G.BoundingSphere.fromVertices(e),primitiveType:R.PrimitiveType.TRIANGLES});if(r.normal&&(T=I.GeometryPipeline.computeNormal(T)),r.tangent||r.bitangent){try{T=I.GeometryPipeline.computeTangentAndBitangent(T)}catch(e){B("polyline-volume-tangent-bitangent","Unable to compute tangents and bitangents for polyline volume geometry")}r.tangent||(T.attributes.tangent=void 0),r.bitangent||(T.attributes.bitangent=void 0),r.st||(T.attributes.st=void 0)}return T}(m.PolylineVolumeGeometryLibrary.computePositions(n,r,i,e,!0),r,i,e._vertexFormat)}},function(e,t){return u.defined(t)&&(e=v.unpack(e,t)),e._ellipsoid=c.Ellipsoid.clone(e._ellipsoid),v.createGeometry(e)}});