createPolygonGeometry.js 15 KB

1
  1. define(["./when-92c6cf3c","./Rectangle-bab7abf0","./ArcType-31298545","./arrayFill-0358accf","./BoundingRectangle-418864a2","./buildModuleUrl-3d15f25c","./Cartesian2-6033fa5d","./Cartographic-67e73ef9","./Check-52a7d806","./ComponentDatatype-81047f82","./EllipsoidGeodesic-04ac0e77","./EllipsoidTangentPlane-53184efd","./GeometryAttribute-ef657318","./GeometryInstance-da5e91bc","./GeometryOffsetAttribute-b4d599f5","./GeometryPipeline-f4eddf07","./IndexDatatype-4c0e98b8","./Math-92c3b5f7","./PrimitiveType-cdfe443e","./PolygonGeometryLibrary-7c66403e","./PolygonPipeline-b86e8785","./VertexFormat-f496a3f1","./WindingOrder-1b9c8a87","./Intersect-b97e930a","./Event-3390cd7d","./RuntimeError-c6a62a80","./WebGLConstants-71f10989","./Cartesian4-ad128b5d","./IntersectionTests-a42760d9","./Plane-f8d22530","./FeatureDetection-067cb23c","./AttributeCompression-49f7b62a","./EncodedCartesian3-b86c8d65","./arrayRemoveDuplicates-f7eaafa2","./EllipsoidRhumbLine-8847d1a1","./GeometryAttributes-7f66ea53"],(function(t,e,o,r,i,n,a,s,l,u,p,c,d,g,h,y,m,f,_,v,b,T,w,x,A,P,E,I,C,H,N,O,R,D,F,G){"use strict";var L=new s.t$1,B=new s.t$1;function S(t,e,o,r){var i=r.cartesianToCartographic(t,L).height,n=r.cartesianToCartographic(e,B);n.height=i,r.cartographicToCartesian(n,e);var a=r.cartesianToCartographic(o,B);a.height=i-100,r.cartographicToCartesian(a,o)}var V=new i.f,k=new s.t,z=new s.t,M=new s.t,W=new s.t,U=new s.t,Y=new s.t,j=new s.t,$=new s.t,q=new s.t,K=new a.o,Q=new a.o,Z=new s.t,J=new d.n,X=new _.p,tt=new _.p;function et(e){var o=e.vertexFormat,i=e.geometry,n=e.shadowVolume,l=i.attributes.position.values,p=l.length,c=e.wall,g=e.top,y=e.bottom;if(o.st||o.normal||o.tangent||o.bitangent||n){var m=e.boundingRectangle,v=e.tangentPlane,b=e.ellipsoid,T=e.stRotation,w=e.perPositionHeight,x=K;x.x=m.x,x.y=m.y;var A,P=e.isComputeTexCoord?new Float32Array(p):new Float32Array(p/3*2),E=o.st?P:void 0;o.normal&&(A=w&&g&&!c?i.attributes.normal.values:new Float32Array(p));var I=o.tangent?new Float32Array(p):void 0,C=o.bitangent?new Float32Array(p):void 0,H=n?new Float32Array(p):void 0,N=0,O=0,R=z,D=M,F=W,G=!0,L=X,B=tt;if(0!==T){var V=d.n.fromAxisAngle(v._plane.normal,T,J);L=_.p.fromQuaternion(V,L),V=d.n.fromAxisAngle(v._plane.normal,-T,J),B=_.p.fromQuaternion(V,B)}else L=_.p.clone(_.p.IDENTITY,L),B=_.p.clone(_.p.IDENTITY,B);var et=0;(g&&y||c)&&(et=p/2,p/=2);var ot=1,rt=[];if(o.st&&c&&e.isComputeTexCoord){let t=[...e.outerPositions,e.outerPositions[0]];for(let e=1;e<t.length;e++){ot+=s.t.distance(t[e-1],t[e]),rt.push(ot)}}for(var it=0;it<p;it+=3){var nt=s.t.fromArray(l,it,Z);if(o.st){var at=_.p.multiplyByVector(L,nt,k);at=b.scaleToGeodeticSurface(at,at);var st=v.projectPointOntoPlane(at,Q);a.o.subtract(st,x,st);var lt=f.e.clamp(st.x/m.width,0,1),ut=f.e.clamp(st.y/m.height,0,1);if(c&&ot>1){let t=Math.ceil(it/6)-1;lt=rt[t]?rt[t]/ot:0,E[N]=1-lt,E[N+1]=1,E[N+2]=0,E[N+et]=1-lt,E[N+1+et]=0,E[N+2+et]=0}y&&(E[N+et]=lt,E[N+1+et]=ut,e.isComputeTexCoord&&(E[N+2+et]=-1)),g&&(E[N]=lt,E[N+1]=ut,e.isComputeTexCoord&&(E[N+2]=1)),e.isComputeTexCoord?N+=3:N+=2}if(o.normal||o.tangent||o.bitangent||n){var pt=O+1,ct=O+2;if(c){if(it+3<p){var dt=s.t.fromArray(l,it+3,U);if(G){var gt=s.t.fromArray(l,it+p,Y);w&&S(nt,dt,gt,b),s.t.subtract(dt,nt,dt),s.t.subtract(gt,nt,gt),R=s.t.normalize(s.t.cross(gt,dt,R),R),G=!1}s.t.equalsEpsilon(dt,nt,f.e.EPSILON10)&&(G=!0)}(o.tangent||o.bitangent)&&(F=b.geodeticSurfaceNormal(nt,F),o.tangent&&(D=s.t.normalize(s.t.cross(F,R,D),D)))}else R=b.geodeticSurfaceNormal(nt,R),(o.tangent||o.bitangent)&&(w&&(j=s.t.fromArray(A,O,j),$=s.t.cross(s.t.UNIT_Z,j,$),$=s.t.normalize(_.p.multiplyByVector(B,$,$),$),o.bitangent&&(q=s.t.normalize(s.t.cross(j,$,q),q))),D=s.t.cross(s.t.UNIT_Z,R,D),D=s.t.normalize(_.p.multiplyByVector(B,D,D),D),o.bitangent&&(F=s.t.normalize(s.t.cross(R,D,F),F)));o.normal&&(e.wall?(A[O+et]=R.x,A[pt+et]=R.y,A[ct+et]=R.z):y&&(A[O+et]=-R.x,A[pt+et]=-R.y,A[ct+et]=-R.z),(g&&!w||c)&&(A[O]=R.x,A[pt]=R.y,A[ct]=R.z)),n&&(c&&(R=b.geodeticSurfaceNormal(nt,R)),H[O+et]=-R.x,H[pt+et]=-R.y,H[ct+et]=-R.z),o.tangent&&(e.wall?(I[O+et]=D.x,I[pt+et]=D.y,I[ct+et]=D.z):y&&(I[O+et]=-D.x,I[pt+et]=-D.y,I[ct+et]=-D.z),g&&(w?(I[O]=$.x,I[pt]=$.y,I[ct]=$.z):(I[O]=D.x,I[pt]=D.y,I[ct]=D.z))),o.bitangent&&(y&&(C[O+et]=F.x,C[pt+et]=F.y,C[ct+et]=F.z),g&&(w?(C[O]=q.x,C[pt]=q.y,C[ct]=q.z):(C[O]=F.x,C[pt]=F.y,C[ct]=F.z))),O+=3}}o.st&&(i.attributes.st=new d.o({componentDatatype:u.ComponentDatatype.FLOAT,componentsPerAttribute:e.isComputeTexCoord?3:2,values:E})),o.normal&&(i.attributes.normal=new d.o({componentDatatype:u.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:A})),o.tangent&&(i.attributes.tangent=new d.o({componentDatatype:u.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:I})),o.bitangent&&(i.attributes.bitangent=new d.o({componentDatatype:u.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:C})),n&&(i.attributes.extrudeDirection=new d.o({componentDatatype:u.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:H}))}if(e.extrude&&t.e(e.offsetAttribute)){var ht=l.length/3,yt=new Uint8Array(ht);if(e.offsetAttribute===h.z.TOP)g&&y||c?yt=r.d(yt,1,0,ht/2):g&&(yt=r.d(yt,1));else{var mt=e.offsetAttribute===h.z.NONE?0:1;yt=r.d(yt,mt)}i.attributes.applyOffset=new d.o({componentDatatype:u.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:yt})}return i}var ot=new s.t$1,rt=new s.t$1,it={west:0,east:0},nt=new p.E;function at(r,i,n,a,s){if(s=t.u(s,new e.h),!t.e(r)||r.length<3)return s.west=0,s.north=0,s.south=0,s.east=0,s;if(n===o.L.RHUMB)return e.h.fromCartesianArray(r,i,s);nt.ellipsoid.equals(i)||(nt=new p.E(void 0,void 0,i)),s.west=Number.POSITIVE_INFINITY,s.east=Number.NEGATIVE_INFINITY,s.south=Number.POSITIVE_INFINITY,s.north=Number.NEGATIVE_INFINITY,it.west=Number.POSITIVE_INFINITY,it.east=Number.NEGATIVE_INFINITY;for(var l,u=1/f.e.chordLength(a,i.maximumRadius),c=r.length,d=i.cartesianToCartographic(r[0],rt),g=ot,h=1;h<c;h++)l=g,g=d,d=i.cartesianToCartographic(r[h],l),nt.setEndPoints(g,d),lt(nt,u,s,it);return l=g,g=d,d=i.cartesianToCartographic(r[0],l),nt.setEndPoints(g,d),lt(nt,u,s,it),s.east-s.west>it.west-it.east&&(s.east=it.east,s.west=it.west),s}var st=new s.t$1;function lt(t,e,o,r){for(var i=t.surfaceDistance,n=Math.ceil(i*e),a=n>0?i/(n-1):Number.POSITIVE_INFINITY,s=0,l=0;l<n;l++){var u=t.interpolateUsingSurfaceDistance(s,st);s+=a;var p=u.longitude,c=u.latitude;o.west=Math.min(o.west,p),o.east=Math.max(o.east,p),o.south=Math.min(o.south,c),o.north=Math.max(o.north,c),r.west=p>0?Math.min(p,r.west):r.west,r.east=p<0?Math.max(p,r.east):r.east}}var ut=[];function pt(t,e,o,r,i,n,a,s,l,u,p){var d,h={walls:[]};if(n||a){var y,f,_=v.y.createGeometryFromPositions(t,e,o,i,s,l),T=_.attributes.position.values,x=_.indices;if(n&&a){var A=T.concat(T);y=A.length/3,(f=m.IndexDatatype.createTypedArray(y,2*x.length)).set(x);var P=x.length,E=y/2;for(d=0;d<P;d+=3){var I=f[d]+E,C=f[d+1]+E,H=f[d+2]+E;f[d+P]=H,f[d+1+P]=C,f[d+2+P]=I}if(_.attributes.position.values=A,i&&s.normal){var N=_.attributes.normal.values;_.attributes.normal.values=new Float32Array(A.length),_.attributes.normal.values.set(N)}_.indices=f}else if(a){for(y=T.length/3,f=m.IndexDatatype.createTypedArray(y,x.length),d=0;d<x.length;d+=3)f[d]=x[d+2],f[d+1]=x[d+1],f[d+2]=x[d];_.indices=f}h.topAndBottom=new g.d({geometry:_})}var O,R=r.outerRing,D=c.f.fromPoints(R,t),F=D.projectPointsOntoPlane(R,ut),G=b.A.computeWindingOrder2D(F);G===w.W.CLOCKWISE&&(R=R.slice().reverse()),u&&(O=v.y.computeWallGeometry(R,t,o,i,l,p),h.walls.push(new g.d({geometry:O})));var L=r.holes;for(d=0;d<L.length;d++){var B=L[d];F=(D=c.f.fromPoints(B,t)).projectPointsOntoPlane(B,ut),(G=b.A.computeWindingOrder2D(F))===w.W.COUNTER_CLOCKWISE&&(B=B.slice().reverse()),O=v.y.computeWallGeometry(B,t,o,i,l),h.walls.push(new g.d({geometry:O}))}return h}function ct(r){if(l.o.typeOf.object("options",r),l.o.typeOf.object("options.polygonHierarchy",r.polygonHierarchy),t.e(r.perPositionHeight)&&r.perPositionHeight&&t.e(r.height))throw new l.t("Cannot use both options.perPositionHeight and options.height");if(t.e(r.arcType)&&r.arcType!==o.L.GEODESIC&&r.arcType!==o.L.RHUMB)throw new l.t("Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.");var i=r.polygonHierarchy,n=t.u(r.vertexFormat,T.n.DEFAULT),a=t.u(r.ellipsoid,e.t.WGS84),s=t.u(r.granularity,f.e.RADIANS_PER_DEGREE),u=t.u(r.stRotation,0),p=t.u(r.perPositionHeight,!1),c=p&&t.e(r.extrudedHeight),d=t.u(r.height,0),g=t.u(r.extrudedHeight,d);if(!c){var h=Math.max(d,g);g=Math.min(d,g),d=h}this._vertexFormat=T.n.clone(n),this._ellipsoid=e.t.clone(a),this._granularity=s,this._stRotation=u,this._height=d,this._extrudedHeight=g,this._closeTop=t.u(r.closeTop,!0),this._closeBottom=t.u(r.closeBottom,!0),this._extrudeOutering=t.u(r.extrudeOutering,!0),this._polygonHierarchy=i,this._perPositionHeight=p,this._perPositionHeightExtrude=c,this._shadowVolume=t.u(r.shadowVolume,!1),this._workerName="createPolygonGeometry",this._offsetAttribute=r.offsetAttribute,this._arcType=t.u(r.arcType,o.L.GEODESIC),this._groundBottomAltitude=t.u(r.groundBottomAltitude,0),this._groundExtrudedHeight=t.u(r.groundExtrudedHeight,0),this._rectangle=void 0,this._textureCoordinateRotationPoints=void 0,this._isComputeTexCoord=r.isComputeTexCoord,this._isWall=t.u(r.isWall,!1),this.packedLength=v.y.computeHierarchyPackedLength(i)+e.t.packedLength+T.n.packedLength+12}ct.fromPositions=function(e){return e=t.u(e,t.u.EMPTY_OBJECT),l.o.defined("options.positions",e.positions),new ct({polygonHierarchy:{positions:e.positions},height:e.height,extrudedHeight:e.extrudedHeight,vertexFormat:e.vertexFormat,stRotation:e.stRotation,ellipsoid:e.ellipsoid,granularity:e.granularity,perPositionHeight:e.perPositionHeight,closeTop:e.closeTop,closeBottom:e.closeBottom,offsetAttribute:e.offsetAttribute,arcType:e.arcType,isComputeTexCoord:e.isComputeTexCoord,isWall:e.isWall})},ct.pack=function(o,r,i){return l.o.typeOf.object("value",o),l.o.defined("array",r),i=t.u(i,0),i=v.y.packPolygonHierarchy(o._polygonHierarchy,r,i),e.t.pack(o._ellipsoid,r,i),i+=e.t.packedLength,T.n.pack(o._vertexFormat,r,i),i+=T.n.packedLength,r[i++]=o._height,r[i++]=o._extrudedHeight,r[i++]=o._granularity,r[i++]=o._stRotation,r[i++]=o._perPositionHeightExtrude?1:0,r[i++]=o._perPositionHeight?1:0,r[i++]=o._closeTop?1:0,r[i++]=o._closeBottom?1:0,r[i++]=o._shadowVolume?1:0,r[i++]=t.u(o._offsetAttribute,-1),r[i++]=o._arcType,r[i]=o.packedLength,r};var dt=e.t.clone(e.t.UNIT_SPHERE),gt=new T.n,ht={polygonHierarchy:{}};return ct.unpack=function(o,r,i){l.o.defined("array",o),r=t.u(r,0);var n=v.y.unpackPolygonHierarchy(o,r);r=n.startingIndex,delete n.startingIndex;var a=e.t.unpack(o,r,dt);r+=e.t.packedLength;var s=T.n.unpack(o,r,gt);r+=T.n.packedLength;var u=o[r++],p=o[r++],c=o[r++],d=o[r++],g=1===o[r++],h=1===o[r++],y=1===o[r++],m=1===o[r++],f=1===o[r++],_=o[r++],b=o[r++],w=o[r];return t.e(i)||(i=new ct(ht)),i._polygonHierarchy=n,i._ellipsoid=e.t.clone(a,i._ellipsoid),i._vertexFormat=T.n.clone(s,i._vertexFormat),i._height=u,i._extrudedHeight=p,i._granularity=c,i._stRotation=d,i._perPositionHeightExtrude=g,i._perPositionHeight=h,i._closeTop=y,i._closeBottom=m,i._shadowVolume=f,i._offsetAttribute=-1===_?void 0:_,i._arcType=b,i.packedLength=w,i},ct.computeRectangle=function(r,i){l.o.typeOf.object("options",r),l.o.typeOf.object("options.polygonHierarchy",r.polygonHierarchy);var n=t.u(r.granularity,f.e.RADIANS_PER_DEGREE),a=t.u(r.arcType,o.L.GEODESIC);if(a!==o.L.GEODESIC&&a!==o.L.RHUMB)throw new l.t("Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.");var s=r.polygonHierarchy,u=t.u(r.ellipsoid,e.t.WGS84);return at(s.positions,u,a,n,i)},ct.createGeometry=function(e){var o=e._vertexFormat,i=e._ellipsoid,a=e._granularity,s=e._stRotation,l=e._polygonHierarchy,p=e._perPositionHeight,_=e._closeTop,T=e._closeBottom,w=e._arcType,x=l.positions;if(!(x.length<3)){var A=c.f.fromPoints(x,i),P=v.y.polygonsFromHierarchy(l,A.projectPointsOntoPlane.bind(A),!p,i),E=P.hierarchy,I=P.polygons;if(0!==E.length){x=E[0].outerRing;var C,H=v.y.computeBoundingRectangle(A.plane.normal,A.projectPointOntoPlane.bind(A),x,s,V),N=[],O=e._height,R=e._extrudedHeight,D=e._perPositionHeightExtrude||!f.e.equalsEpsilon(O,R,0,f.e.EPSILON2),F={perPositionHeight:p,vertexFormat:o,geometry:void 0,tangentPlane:A,boundingRectangle:H,ellipsoid:i,stRotation:s,bottom:!1,top:!0,wall:!1,extrude:!1,arcType:w,outerPositions:x,isComputeTexCoord:e._isComputeTexCoord};if(D)for(F.extrude=!0,F.top=_,F.bottom=T,F.shadowVolume=e._shadowVolume,F.offsetAttribute=e._offsetAttribute,C=0;C<I.length;C++){var G,L=pt(i,I[C],a,E[C],p,_,T,o,w,e._extrudeOutering,e._isWall);_&&T?(G=L.topAndBottom,F.geometry=v.y.scaleToGeodeticHeightExtruded(G.geometry,O,R,i,p)):_?((G=L.topAndBottom).geometry.attributes.position.values=b.A.scaleToGeodeticHeight(G.geometry.attributes.position.values,O,i,!p),F.geometry=G.geometry):T&&((G=L.topAndBottom).geometry.attributes.position.values=b.A.scaleToGeodeticHeight(G.geometry.attributes.position.values,R,i,!0),F.geometry=G.geometry),(_||T)&&(F.wall=!1,G.geometry=et(F),N.push(G));var B=L.walls;F.wall=!0;for(var S=0;S<B.length;S++){var k=B[S];F.top=!1,F.bottom=!1,F.geometry=v.y.scaleToGeodeticHeightExtruded(k.geometry,O,R,i,p),k.geometry=et(F),N.push(k)}}else for(C=0;C<I.length;C++){var z=new g.d({geometry:v.y.createGeometryFromPositions(i,I[C],a,p,o,w)});if(z.geometry.attributes.position.values=b.A.scaleToGeodeticHeight(z.geometry.attributes.position.values,O,i,!p),F.geometry=z.geometry,z.geometry=et(F),t.e(e._offsetAttribute)){var M=z.geometry.attributes.position.values.length,W=new Uint8Array(M/3),U=e._offsetAttribute===h.z.NONE?0:1;r.d(W,U),z.geometry.attributes.applyOffset=new d.o({componentDatatype:u.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:W})}N.push(z)}var Y=y.k.combineInstances(N)[0];Y.attributes.position.values=new Float64Array(Y.attributes.position.values),Y.indices=m.IndexDatatype.createTypedArray(Y.attributes.position.values.length/3,Y.indices);var j=Y.attributes,$=n.i.fromVertices(j.position.values);return o.position||delete j.position,new d.I({attributes:j,indices:Y.indices,primitiveType:Y.primitiveType,boundingSphere:$,offsetAttribute:e._offsetAttribute})}}},ct.createShadowVolume=function(t,e,o){var r=t._granularity,i=t._ellipsoid,n=t._groundBottomAltitude+t._groundExtrudedHeight,a=t._groundBottomAltitude?t._groundBottomAltitude:e(r,i),s=n!==t._groundBottomAltitude?n:o(r,i);return new ct({polygonHierarchy:t._polygonHierarchy,ellipsoid:i,stRotation:t._stRotation,granularity:r,perPositionHeight:!1,extrudedHeight:a,height:s,vertexFormat:T.n.POSITION_ONLY,shadowVolume:!0,arcType:t._arcType})},Object.defineProperties(ct.prototype,{rectangle:{get:function(){if(!t.e(this._rectangle)){var e=this._polygonHierarchy.positions;this._rectangle=at(e,this._ellipsoid,this._arcType,this._granularity)}return this._rectangle}},textureCoordinateRotationPoints:{get:function(){return t.e(this._textureCoordinateRotationPoints)||(this._textureCoordinateRotationPoints=function(t){var e=-t._stRotation;if(0===e)return[0,0,0,1,1,0];var o=t._ellipsoid,r=t._polygonHierarchy.positions,i=t.rectangle;return d.I._textureCoordinateRotationPoints(r,e,o,i)}(this)),this._textureCoordinateRotationPoints}}}),function(o,r){return t.e(r)&&(o=ct.unpack(o,r)),o._ellipsoid=e.t.clone(o._ellipsoid),ct.createGeometry(o)}}));