createPolygonGeometry.js 15 KB

1
  1. define(["./defaultValue-81eec7ed","./Matrix2-e3fb4559","./ArcType-fc72c06c","./GeometryOffsetAttribute-ed56ff58","./BoundingRectangle-b88064b7","./Transforms-98ffa11d","./Cartesian3-7e9cc2ff","./Check-741c5f3c","./ComponentDatatype-aaeec80f","./EllipsoidGeodesic-6de45192","./EllipsoidTangentPlane-fa1337e1","./GeometryAttribute-b025f9a8","./GeometryInstance-ce434bcb","./GeometryPipeline-4b426993","./IndexDatatype-f1e3f799","./Math-5f585871","./Matrix4-d34187af","./PolygonGeometryLibrary-8f834b9d","./PolygonPipeline-6f83d8b1","./VertexFormat-d50a69ba","./_commonjsHelpers-3aae1032-26891ab7","./combine-3c023bda","./RuntimeError-26acdd3b","./WebGLConstants-508b9636","./AxisAlignedBoundingBox-37250ed6","./IntersectionTests-73b87d72","./Plane-4f75b3df","./AttributeCompression-e2e3f0dd","./EncodedCartesian3-aac44514","./arrayRemoveDuplicates-85770175","./EllipsoidRhumbLine-9c6b32ea","./GeometryAttributes-32b29525"],(function(e,t,o,i,n,r,a,s,l,c,u,p,m,y,g,d,h,f,b,_,P,x,C,w,T,I,A,E,v,G,O,V){"use strict";const F=new t.Cartographic,D=new t.Cartographic;function L(e,t,o,i){const n=i.cartesianToCartographic(e,F).height,r=i.cartesianToCartographic(t,D);r.height=n,i.cartographicToCartesian(r,t);const a=i.cartesianToCartographic(o,D);a.height=n-100,i.cartographicToCartesian(a,o)}const N=new n.BoundingRectangle,H=new a.Cartesian3,R=new a.Cartesian3,M=new a.Cartesian3,S=new a.Cartesian3,B=new a.Cartesian3,k=new a.Cartesian3;let z=new a.Cartesian3,W=new a.Cartesian3,Y=new a.Cartesian3;const U=new t.Cartesian2,j=new t.Cartesian2,Q=new a.Cartesian3,q=new r.Quaternion,K=new h.Matrix3,Z=new h.Matrix3;function J(o){const n=o.vertexFormat,s=o.geometry,c=o.shadowVolume,u=s.attributes.position.values;let m=u.length;const y=o.wall,g=o.top||y,f=o.bottom||y;if(n.st||n.normal||n.tangent||n.bitangent||c){const e=o.boundingRectangle,i=o.tangentPlane,b=o.ellipsoid,_=o.stRotation,P=o.perPositionHeight,x=U;x.x=e.x,x.y=e.y;const C=n.st?new Float32Array(m/3*2):void 0;let w;n.normal&&(w=P&&g&&!y?s.attributes.normal.values:new Float32Array(m));const T=n.tangent?new Float32Array(m):void 0,I=n.bitangent?new Float32Array(m):void 0,A=c?new Float32Array(m):void 0;let E=0,v=0,G=R,O=M,V=S,F=!0,D=K,N=Z;if(0!==_){let e=r.Quaternion.fromAxisAngle(i._plane.normal,_,q);D=h.Matrix3.fromQuaternion(e,D),e=r.Quaternion.fromAxisAngle(i._plane.normal,-_,q),N=h.Matrix3.fromQuaternion(e,N)}else D=h.Matrix3.clone(h.Matrix3.IDENTITY,D),N=h.Matrix3.clone(h.Matrix3.IDENTITY,N);let J=0,X=0;g&&f&&(J=m/2,X=m/3,m/=2);for(let r=0;r<m;r+=3){const s=a.Cartesian3.fromArray(u,r,Q);if(n.st){let o=h.Matrix3.multiplyByVector(D,s,H);o=b.scaleToGeodeticSurface(o,o);const n=i.projectPointOntoPlane(o,j);t.Cartesian2.subtract(n,x,n);const r=d.CesiumMath.clamp(n.x/e.width,0,1),a=d.CesiumMath.clamp(n.y/e.height,0,1);f&&(C[E+X]=r,C[E+1+X]=a),g&&(C[E]=r,C[E+1]=a),E+=2}if(n.normal||n.tangent||n.bitangent||c){const e=v+1,t=v+2;if(y){if(r+3<m){const e=a.Cartesian3.fromArray(u,r+3,B);if(F){const t=a.Cartesian3.fromArray(u,r+m,k);P&&L(s,e,t,b),a.Cartesian3.subtract(e,s,e),a.Cartesian3.subtract(t,s,t),G=a.Cartesian3.normalize(a.Cartesian3.cross(t,e,G),G),F=!1}a.Cartesian3.equalsEpsilon(e,s,d.CesiumMath.EPSILON10)&&(F=!0)}(n.tangent||n.bitangent)&&(V=b.geodeticSurfaceNormal(s,V),n.tangent&&(O=a.Cartesian3.normalize(a.Cartesian3.cross(V,G,O),O)))}else G=b.geodeticSurfaceNormal(s,G),(n.tangent||n.bitangent)&&(P&&(z=a.Cartesian3.fromArray(w,v,z),W=a.Cartesian3.cross(a.Cartesian3.UNIT_Z,z,W),W=a.Cartesian3.normalize(h.Matrix3.multiplyByVector(N,W,W),W),n.bitangent&&(Y=a.Cartesian3.normalize(a.Cartesian3.cross(z,W,Y),Y))),O=a.Cartesian3.cross(a.Cartesian3.UNIT_Z,G,O),O=a.Cartesian3.normalize(h.Matrix3.multiplyByVector(N,O,O),O),n.bitangent&&(V=a.Cartesian3.normalize(a.Cartesian3.cross(G,O,V),V)));n.normal&&(o.wall?(w[v+J]=G.x,w[e+J]=G.y,w[t+J]=G.z):f&&(w[v+J]=-G.x,w[e+J]=-G.y,w[t+J]=-G.z),(g&&!P||y)&&(w[v]=G.x,w[e]=G.y,w[t]=G.z)),c&&(y&&(G=b.geodeticSurfaceNormal(s,G)),A[v+J]=-G.x,A[e+J]=-G.y,A[t+J]=-G.z),n.tangent&&(o.wall?(T[v+J]=O.x,T[e+J]=O.y,T[t+J]=O.z):f&&(T[v+J]=-O.x,T[e+J]=-O.y,T[t+J]=-O.z),g&&(P?(T[v]=W.x,T[e]=W.y,T[t]=W.z):(T[v]=O.x,T[e]=O.y,T[t]=O.z))),n.bitangent&&(f&&(I[v+J]=V.x,I[e+J]=V.y,I[t+J]=V.z),g&&(P?(I[v]=Y.x,I[e]=Y.y,I[t]=Y.z):(I[v]=V.x,I[e]=V.y,I[t]=V.z))),v+=3}}n.st&&(s.attributes.st=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:C})),n.normal&&(s.attributes.normal=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:w})),n.tangent&&(s.attributes.tangent=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:T})),n.bitangent&&(s.attributes.bitangent=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:I})),c&&(s.attributes.extrudeDirection=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:A}))}if(o.extrude&&e.defined(o.offsetAttribute)){const e=u.length/3;let t=new Uint8Array(e);if(o.offsetAttribute===i.GeometryOffsetAttribute.TOP)g&&f||y?t=i.arrayFill(t,1,0,e/2):g&&(t=i.arrayFill(t,1));else{const e=o.offsetAttribute===i.GeometryOffsetAttribute.NONE?0:1;t=i.arrayFill(t,e)}s.attributes.applyOffset=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:t})}return s}const X=new t.Cartographic,$=new t.Cartographic,ee={westOverIDL:0,eastOverIDL:0};let te=new c.EllipsoidGeodesic;function oe(i,n,r,a,s){if(s=e.defaultValue(s,new t.Rectangle),!e.defined(i)||i.length<3)return s.west=0,s.north=0,s.south=0,s.east=0,s;if(r===o.ArcType.RHUMB)return t.Rectangle.fromCartesianArray(i,n,s);te.ellipsoid.equals(n)||(te=new c.EllipsoidGeodesic(void 0,void 0,n)),s.west=Number.POSITIVE_INFINITY,s.east=Number.NEGATIVE_INFINITY,s.south=Number.POSITIVE_INFINITY,s.north=Number.NEGATIVE_INFINITY,ee.westOverIDL=Number.POSITIVE_INFINITY,ee.eastOverIDL=Number.NEGATIVE_INFINITY;const l=1/d.CesiumMath.chordLength(a,n.maximumRadius),u=i.length;let p,m=n.cartesianToCartographic(i[0],$),y=X;for(let e=1;e<u;e++)p=y,y=m,m=n.cartesianToCartographic(i[e],p),te.setEndPoints(y,m),ne(te,l,s,ee);return p=y,y=m,m=n.cartesianToCartographic(i[0],p),te.setEndPoints(y,m),ne(te,l,s,ee),s.east-s.west>ee.eastOverIDL-ee.westOverIDL&&(s.west=ee.westOverIDL,s.east=ee.eastOverIDL,s.east>d.CesiumMath.PI&&(s.east=s.east-d.CesiumMath.TWO_PI),s.west>d.CesiumMath.PI&&(s.west=s.west-d.CesiumMath.TWO_PI)),s}const ie=new t.Cartographic;function ne(e,t,o,i){const n=e.surfaceDistance,r=Math.ceil(n*t),a=r>0?n/(r-1):Number.POSITIVE_INFINITY;let s=0;for(let t=0;t<r;t++){const t=e.interpolateUsingSurfaceDistance(s,ie);s+=a;const n=t.longitude,r=t.latitude;o.west=Math.min(o.west,n),o.east=Math.max(o.east,n),o.south=Math.min(o.south,r),o.north=Math.max(o.north,r);const l=n>=0?n:n+d.CesiumMath.TWO_PI;i.westOverIDL=Math.min(i.westOverIDL,l),i.eastOverIDL=Math.max(i.eastOverIDL,l)}}const re=[];function ae(e,t,o,i,n,r,a,s,l){const c={walls:[]};let p;if(r||a){const i=f.PolygonGeometryLibrary.createGeometryFromPositions(e,t,o,n,s,l),u=i.attributes.position.values,y=i.indices;let d,h;if(r&&a){const e=u.concat(u);d=e.length/3,h=g.IndexDatatype.createTypedArray(d,2*y.length),h.set(y);const t=y.length,o=d/2;for(p=0;p<t;p+=3){const e=h[p]+o,i=h[p+1]+o,n=h[p+2]+o;h[p+t]=n,h[p+1+t]=i,h[p+2+t]=e}if(i.attributes.position.values=e,n&&s.normal){const t=i.attributes.normal.values;i.attributes.normal.values=new Float32Array(e.length),i.attributes.normal.values.set(t)}i.indices=h}else if(a){for(d=u.length/3,h=g.IndexDatatype.createTypedArray(d,y.length),p=0;p<y.length;p+=3)h[p]=y[p+2],h[p+1]=y[p+1],h[p+2]=y[p];i.indices=h}c.topAndBottom=new m.GeometryInstance({geometry:i})}let y=i.outerRing,d=u.EllipsoidTangentPlane.fromPoints(y,e),h=d.projectPointsOntoPlane(y,re),_=b.PolygonPipeline.computeWindingOrder2D(h);_===b.WindingOrder.CLOCKWISE&&(y=y.slice().reverse());let P=f.PolygonGeometryLibrary.computeWallGeometry(y,e,o,n,l);c.walls.push(new m.GeometryInstance({geometry:P}));const x=i.holes;for(p=0;p<x.length;p++){let t=x[p];d=u.EllipsoidTangentPlane.fromPoints(t,e),h=d.projectPointsOntoPlane(t,re),_=b.PolygonPipeline.computeWindingOrder2D(h),_===b.WindingOrder.COUNTER_CLOCKWISE&&(t=t.slice().reverse()),P=f.PolygonGeometryLibrary.computeWallGeometry(t,e,o,n,l),c.walls.push(new m.GeometryInstance({geometry:P}))}return c}function se(i){const n=i.polygonHierarchy,r=e.defaultValue(i.vertexFormat,_.VertexFormat.DEFAULT),a=e.defaultValue(i.ellipsoid,t.Ellipsoid.WGS84),s=e.defaultValue(i.granularity,d.CesiumMath.RADIANS_PER_DEGREE),l=e.defaultValue(i.stRotation,0),c=e.defaultValue(i.perPositionHeight,!1),u=c&&e.defined(i.extrudedHeight);let p=e.defaultValue(i.height,0),m=e.defaultValue(i.extrudedHeight,p);if(!u){const e=Math.max(p,m);m=Math.min(p,m),p=e}this._vertexFormat=_.VertexFormat.clone(r),this._ellipsoid=t.Ellipsoid.clone(a),this._granularity=s,this._stRotation=l,this._height=p,this._extrudedHeight=m,this._closeTop=e.defaultValue(i.closeTop,!0),this._closeBottom=e.defaultValue(i.closeBottom,!0),this._polygonHierarchy=n,this._perPositionHeight=c,this._perPositionHeightExtrude=u,this._shadowVolume=e.defaultValue(i.shadowVolume,!1),this._workerName="createPolygonGeometry",this._offsetAttribute=i.offsetAttribute,this._arcType=e.defaultValue(i.arcType,o.ArcType.GEODESIC),this._rectangle=void 0,this._textureCoordinateRotationPoints=void 0,this.packedLength=f.PolygonGeometryLibrary.computeHierarchyPackedLength(n)+t.Ellipsoid.packedLength+_.VertexFormat.packedLength+12}se.fromPositions=function(t){return new se({polygonHierarchy:{positions:(t=e.defaultValue(t,e.defaultValue.EMPTY_OBJECT)).positions},height:t.height,extrudedHeight:t.extrudedHeight,vertexFormat:t.vertexFormat,stRotation:t.stRotation,ellipsoid:t.ellipsoid,granularity:t.granularity,perPositionHeight:t.perPositionHeight,closeTop:t.closeTop,closeBottom:t.closeBottom,offsetAttribute:t.offsetAttribute,arcType:t.arcType})},se.pack=function(o,i,n){return n=e.defaultValue(n,0),n=f.PolygonGeometryLibrary.packPolygonHierarchy(o._polygonHierarchy,i,n),t.Ellipsoid.pack(o._ellipsoid,i,n),n+=t.Ellipsoid.packedLength,_.VertexFormat.pack(o._vertexFormat,i,n),n+=_.VertexFormat.packedLength,i[n++]=o._height,i[n++]=o._extrudedHeight,i[n++]=o._granularity,i[n++]=o._stRotation,i[n++]=o._perPositionHeightExtrude?1:0,i[n++]=o._perPositionHeight?1:0,i[n++]=o._closeTop?1:0,i[n++]=o._closeBottom?1:0,i[n++]=o._shadowVolume?1:0,i[n++]=e.defaultValue(o._offsetAttribute,-1),i[n++]=o._arcType,i[n]=o.packedLength,i};const le=t.Ellipsoid.clone(t.Ellipsoid.UNIT_SPHERE),ce=new _.VertexFormat,ue={polygonHierarchy:{}};return se.unpack=function(o,i,n){i=e.defaultValue(i,0);const r=f.PolygonGeometryLibrary.unpackPolygonHierarchy(o,i);i=r.startingIndex,delete r.startingIndex;const a=t.Ellipsoid.unpack(o,i,le);i+=t.Ellipsoid.packedLength;const s=_.VertexFormat.unpack(o,i,ce);i+=_.VertexFormat.packedLength;const l=o[i++],c=o[i++],u=o[i++],p=o[i++],m=1===o[i++],y=1===o[i++],g=1===o[i++],d=1===o[i++],h=1===o[i++],b=o[i++],P=o[i++],x=o[i];return e.defined(n)||(n=new se(ue)),n._polygonHierarchy=r,n._ellipsoid=t.Ellipsoid.clone(a,n._ellipsoid),n._vertexFormat=_.VertexFormat.clone(s,n._vertexFormat),n._height=l,n._extrudedHeight=c,n._granularity=u,n._stRotation=p,n._perPositionHeightExtrude=m,n._perPositionHeight=y,n._closeTop=g,n._closeBottom=d,n._shadowVolume=h,n._offsetAttribute=-1===b?void 0:b,n._arcType=P,n.packedLength=x,n},se.computeRectangle=function(i,n){const r=e.defaultValue(i.granularity,d.CesiumMath.RADIANS_PER_DEGREE),a=e.defaultValue(i.arcType,o.ArcType.GEODESIC),s=i.polygonHierarchy,l=e.defaultValue(i.ellipsoid,t.Ellipsoid.WGS84);return oe(s.positions,l,a,r,n)},se.createGeometry=function(t){const o=t._vertexFormat,n=t._ellipsoid,a=t._granularity,s=t._stRotation,c=t._polygonHierarchy,h=t._perPositionHeight,_=t._closeTop,P=t._closeBottom,x=t._arcType;let C=c.positions;if(C.length<3)return;const w=u.EllipsoidTangentPlane.fromPoints(C,n),T=f.PolygonGeometryLibrary.polygonsFromHierarchy(c,w.projectPointsOntoPlane.bind(w),!h,n),I=T.hierarchy,A=T.polygons;if(0===I.length)return;C=I[0].outerRing;const E=f.PolygonGeometryLibrary.computeBoundingRectangle(w.plane.normal,w.projectPointOntoPlane.bind(w),C,s,N),v=[],G=t._height,O=t._extrudedHeight,V={perPositionHeight:h,vertexFormat:o,geometry:void 0,tangentPlane:w,boundingRectangle:E,ellipsoid:n,stRotation:s,bottom:!1,top:!0,wall:!1,extrude:!1,arcType:x};let F;if(t._perPositionHeightExtrude||!d.CesiumMath.equalsEpsilon(G,O,0,d.CesiumMath.EPSILON2))for(V.extrude=!0,V.top=_,V.bottom=P,V.shadowVolume=t._shadowVolume,V.offsetAttribute=t._offsetAttribute,F=0;F<A.length;F++){const e=ae(n,A[F],a,I[F],h,_,P,o,x);let t;_&&P?(t=e.topAndBottom,V.geometry=f.PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(t.geometry,G,O,n,h)):_?(t=e.topAndBottom,t.geometry.attributes.position.values=b.PolygonPipeline.scaleToGeodeticHeight(t.geometry.attributes.position.values,G,n,!h),V.geometry=t.geometry):P&&(t=e.topAndBottom,t.geometry.attributes.position.values=b.PolygonPipeline.scaleToGeodeticHeight(t.geometry.attributes.position.values,O,n,!0),V.geometry=t.geometry),(_||P)&&(V.wall=!1,t.geometry=J(V),v.push(t));const i=e.walls;V.wall=!0;for(let e=0;e<i.length;e++){const t=i[e];V.geometry=f.PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(t.geometry,G,O,n,h),t.geometry=J(V),v.push(t)}}else for(F=0;F<A.length;F++){const r=new m.GeometryInstance({geometry:f.PolygonGeometryLibrary.createGeometryFromPositions(n,A[F],a,h,o,x)});if(r.geometry.attributes.position.values=b.PolygonPipeline.scaleToGeodeticHeight(r.geometry.attributes.position.values,G,n,!h),V.geometry=r.geometry,r.geometry=J(V),e.defined(t._offsetAttribute)){const e=r.geometry.attributes.position.values.length,o=new Uint8Array(e/3),n=t._offsetAttribute===i.GeometryOffsetAttribute.NONE?0:1;i.arrayFill(o,n),r.geometry.attributes.applyOffset=new p.GeometryAttribute({componentDatatype:l.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:o})}v.push(r)}const D=y.GeometryPipeline.combineInstances(v)[0];D.attributes.position.values=new Float64Array(D.attributes.position.values),D.indices=g.IndexDatatype.createTypedArray(D.attributes.position.values.length/3,D.indices);const L=D.attributes,H=r.BoundingSphere.fromVertices(L.position.values);return o.position||delete L.position,new p.Geometry({attributes:L,indices:D.indices,primitiveType:D.primitiveType,boundingSphere:H,offsetAttribute:t._offsetAttribute})},se.createShadowVolume=function(e,t,o){const i=e._granularity,n=e._ellipsoid,r=t(i,n),a=o(i,n);return new se({polygonHierarchy:e._polygonHierarchy,ellipsoid:n,stRotation:e._stRotation,granularity:i,perPositionHeight:!1,extrudedHeight:r,height:a,vertexFormat:_.VertexFormat.POSITION_ONLY,shadowVolume:!0,arcType:e._arcType})},Object.defineProperties(se.prototype,{rectangle:{get:function(){if(!e.defined(this._rectangle)){const e=this._polygonHierarchy.positions;this._rectangle=oe(e,this._ellipsoid,this._arcType,this._granularity)}return this._rectangle}},textureCoordinateRotationPoints:{get:function(){return e.defined(this._textureCoordinateRotationPoints)||(this._textureCoordinateRotationPoints=function(e){const t=-e._stRotation;if(0===t)return[0,0,0,1,1,0];const o=e._ellipsoid,i=e._polygonHierarchy.positions,n=e.rectangle;return p.Geometry._textureCoordinateRotationPoints(i,t,o,n)}(this)),this._textureCoordinateRotationPoints}}}),function(o,i){return e.defined(i)&&(o=se.unpack(o,i)),o._ellipsoid=t.Ellipsoid.clone(o._ellipsoid),se.createGeometry(o)}}));