createRectangleGeometry.js 16 KB

1
  1. define(["./defaultValue-81eec7ed","./Matrix2-e3fb4559","./GeometryOffsetAttribute-ed56ff58","./Transforms-98ffa11d","./Cartesian3-7e9cc2ff","./Check-741c5f3c","./ComponentDatatype-aaeec80f","./GeometryAttribute-b025f9a8","./GeometryAttributes-32b29525","./GeometryInstance-ce434bcb","./GeometryPipeline-4b426993","./IndexDatatype-f1e3f799","./Math-5f585871","./Matrix4-d34187af","./PolygonPipeline-6f83d8b1","./RectangleGeometryLibrary-193b0cdb","./VertexFormat-d50a69ba","./_commonjsHelpers-3aae1032-26891ab7","./combine-3c023bda","./RuntimeError-26acdd3b","./WebGLConstants-508b9636","./AttributeCompression-e2e3f0dd","./EncodedCartesian3-aac44514","./IntersectionTests-73b87d72","./Plane-4f75b3df","./EllipsoidRhumbLine-9c6b32ea"],(function(t,e,n,a,o,r,i,s,l,u,c,m,d,p,g,y,f,h,b,_,A,x,w,C,v,R){"use strict";const E=new o.Cartesian3,F=new o.Cartesian3,G=new o.Cartesian3,P=new o.Cartesian3,V=new e.Rectangle,L=new e.Cartesian2,D=new a.BoundingSphere,M=new a.BoundingSphere;function T(t,e){const n=new s.Geometry({attributes:new l.GeometryAttributes,primitiveType:s.PrimitiveType.TRIANGLES});return n.attributes.position=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:e.positions}),t.normal&&(n.attributes.normal=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.normals})),t.tangent&&(n.attributes.tangent=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.tangents})),t.bitangent&&(n.attributes.bitangent=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.bitangents})),n}const O=new o.Cartesian3,N=new o.Cartesian3;function S(t,e){const n=t._vertexFormat,a=t._ellipsoid,r=e.height,l=e.width,u=e.northCap,c=e.southCap;let d=0,g=r,f=r,h=0;u&&(d=1,f-=1,h+=1),c&&(g-=1,f-=1,h+=1),h+=l*f;const b=n.position?new Float64Array(3*h):void 0,_=n.st?new Float32Array(2*h):void 0;let A=0,x=0;const w=E,C=L;let v=Number.MAX_VALUE,R=Number.MAX_VALUE,V=-Number.MAX_VALUE,D=-Number.MAX_VALUE;for(let t=d;t<g;++t)for(let o=0;o<l;++o)y.RectangleGeometryLibrary.computePosition(e,a,n.st,t,o,w,C),b[A++]=w.x,b[A++]=w.y,b[A++]=w.z,n.st&&(_[x++]=C.x,_[x++]=C.y,v=Math.min(v,C.x),R=Math.min(R,C.y),V=Math.max(V,C.x),D=Math.max(D,C.y));if(u&&(y.RectangleGeometryLibrary.computePosition(e,a,n.st,0,0,w,C),b[A++]=w.x,b[A++]=w.y,b[A++]=w.z,n.st&&(_[x++]=C.x,_[x++]=C.y,v=C.x,R=C.y,V=C.x,D=C.y)),c&&(y.RectangleGeometryLibrary.computePosition(e,a,n.st,r-1,0,w,C),b[A++]=w.x,b[A++]=w.y,b[A]=w.z,n.st&&(_[x++]=C.x,_[x]=C.y,v=Math.min(v,C.x),R=Math.min(R,C.y),V=Math.max(V,C.x),D=Math.max(D,C.y))),n.st&&(v<0||R<0||V>1||D>1))for(let t=0;t<_.length;t+=2)_[t]=(_[t]-v)/(V-v),_[t+1]=(_[t+1]-R)/(D-R);const M=function(t,e,n,a){const r=t.length,i=e.normal?new Float32Array(r):void 0,s=e.tangent?new Float32Array(r):void 0,l=e.bitangent?new Float32Array(r):void 0;let u=0;const c=P,m=G;let d=F;if(e.normal||e.tangent||e.bitangent)for(let g=0;g<r;g+=3){const r=o.Cartesian3.fromArray(t,g,E),y=u+1,f=u+2;d=n.geodeticSurfaceNormal(r,d),(e.tangent||e.bitangent)&&(o.Cartesian3.cross(o.Cartesian3.UNIT_Z,d,m),p.Matrix3.multiplyByVector(a,m,m),o.Cartesian3.normalize(m,m),e.bitangent&&o.Cartesian3.normalize(o.Cartesian3.cross(d,m,c),c)),e.normal&&(i[u]=d.x,i[y]=d.y,i[f]=d.z),e.tangent&&(s[u]=m.x,s[y]=m.y,s[f]=m.z),e.bitangent&&(l[u]=c.x,l[y]=c.y,l[f]=c.z),u+=3}return T(e,{positions:t,normals:i,tangents:s,bitangents:l})}(b,n,a,e.tangentRotationMatrix);let O=6*(l-1)*(f-1);u&&(O+=3*(l-1)),c&&(O+=3*(l-1));const N=m.IndexDatatype.createTypedArray(h,O);let S,I=0,k=0;for(S=0;S<f-1;++S){for(let t=0;t<l-1;++t){const t=I,e=t+l,n=e+1,a=t+1;N[k++]=t,N[k++]=e,N[k++]=a,N[k++]=a,N[k++]=e,N[k++]=n,++I}++I}if(u||c){let t=h-1;const e=h-1;let n,a;if(u&&c&&(t=h-2),I=0,u)for(S=0;S<l-1;S++)n=I,a=n+1,N[k++]=t,N[k++]=n,N[k++]=a,++I;if(c)for(I=(f-1)*l,S=0;S<l-1;S++)n=I,a=n+1,N[k++]=n,N[k++]=e,N[k++]=a,++I}return M.indices=N,n.st&&(M.attributes.st=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:_})),M}function I(t,e,n,a,o){return t[e++]=a[n],t[e++]=a[n+1],t[e++]=a[n+2],t[e++]=o[n],t[e++]=o[n+1],t[e]=o[n+2],t}function k(t,e,n,a){return t[e++]=a[n],t[e++]=a[n+1],t[e++]=a[n],t[e]=a[n+1],t}const H=new f.VertexFormat;function z(e,a){const r=e._shadowVolume,l=e._offsetAttribute,p=e._vertexFormat,y=e._extrudedHeight,h=e._surfaceHeight,b=e._ellipsoid,_=a.height,A=a.width;let x;if(r){const t=f.VertexFormat.clone(p,H);t.normal=!0,e._vertexFormat=t}const w=S(e,a);r&&(e._vertexFormat=p);let C=g.PolygonPipeline.scaleToGeodeticHeight(w.attributes.position.values,h,b,!1);C=new Float64Array(C);let v=C.length;const R=2*v,V=new Float64Array(R);V.set(C);const L=g.PolygonPipeline.scaleToGeodeticHeight(w.attributes.position.values,y,b);V.set(L,v),w.attributes.position.values=V;const D=p.normal?new Float32Array(R):void 0,M=p.tangent?new Float32Array(R):void 0,z=p.bitangent?new Float32Array(R):void 0,B=p.st?new Float32Array(R/3*2):void 0;let U,Y,q;if(p.normal){for(Y=w.attributes.normal.values,D.set(Y),x=0;x<v;x++)Y[x]=-Y[x];D.set(Y,v),w.attributes.normal.values=D}if(r){Y=w.attributes.normal.values,p.normal||(w.attributes.normal=void 0);const t=new Float32Array(R);for(x=0;x<v;x++)Y[x]=-Y[x];t.set(Y,v),w.attributes.extrudeDirection=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:t})}const X=t.defined(l);if(X){const t=v/3*2;let e=new Uint8Array(t);l===n.GeometryOffsetAttribute.TOP?e=n.arrayFill(e,1,0,t/2):(q=l===n.GeometryOffsetAttribute.NONE?0:1,e=n.arrayFill(e,q)),w.attributes.applyOffset=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:e})}if(p.tangent){const t=w.attributes.tangent.values;for(M.set(t),x=0;x<v;x++)t[x]=-t[x];M.set(t,v),w.attributes.tangent.values=M}if(p.bitangent){const t=w.attributes.bitangent.values;z.set(t),z.set(t,v),w.attributes.bitangent.values=z}p.st&&(U=w.attributes.st.values,B.set(U),B.set(U,v/3*2),w.attributes.st.values=B);const Q=w.indices,W=Q.length,j=v/3,J=m.IndexDatatype.createTypedArray(R/3,2*W);for(J.set(Q),x=0;x<W;x+=3)J[x+W]=Q[x+2]+j,J[x+1+W]=Q[x+1]+j,J[x+2+W]=Q[x]+j;w.indices=J;const Z=a.northCap,K=a.southCap;let $=_,tt=2,et=0,nt=4,at=4;Z&&(tt-=1,$-=1,et+=1,nt-=2,at-=1),K&&(tt-=1,$-=1,et+=1,nt-=2,at-=1),et+=tt*A+2*$-nt;const ot=2*(et+at);let rt=new Float64Array(3*ot);const it=r?new Float32Array(3*ot):void 0;let st=X?new Uint8Array(ot):void 0,lt=p.st?new Float32Array(2*ot):void 0;const ut=l===n.GeometryOffsetAttribute.TOP;X&&!ut&&(q=l===n.GeometryOffsetAttribute.ALL?1:0,st=n.arrayFill(st,q));let ct=0,mt=0,dt=0,pt=0;const gt=A*$;let yt;for(x=0;x<gt;x+=A)yt=3*x,rt=I(rt,ct,yt,C,L),ct+=6,p.st&&(lt=k(lt,mt,2*x,U),mt+=4),r&&(dt+=3,it[dt++]=Y[yt],it[dt++]=Y[yt+1],it[dt++]=Y[yt+2]),ut&&(st[pt++]=1,pt+=1);if(K){const t=Z?gt+1:gt;for(yt=3*t,x=0;x<2;x++)rt=I(rt,ct,yt,C,L),ct+=6,p.st&&(lt=k(lt,mt,2*t,U),mt+=4),r&&(dt+=3,it[dt++]=Y[yt],it[dt++]=Y[yt+1],it[dt++]=Y[yt+2]),ut&&(st[pt++]=1,pt+=1)}else for(x=gt-A;x<gt;x++)yt=3*x,rt=I(rt,ct,yt,C,L),ct+=6,p.st&&(lt=k(lt,mt,2*x,U),mt+=4),r&&(dt+=3,it[dt++]=Y[yt],it[dt++]=Y[yt+1],it[dt++]=Y[yt+2]),ut&&(st[pt++]=1,pt+=1);for(x=gt-1;x>0;x-=A)yt=3*x,rt=I(rt,ct,yt,C,L),ct+=6,p.st&&(lt=k(lt,mt,2*x,U),mt+=4),r&&(dt+=3,it[dt++]=Y[yt],it[dt++]=Y[yt+1],it[dt++]=Y[yt+2]),ut&&(st[pt++]=1,pt+=1);if(Z){const t=gt;for(yt=3*t,x=0;x<2;x++)rt=I(rt,ct,yt,C,L),ct+=6,p.st&&(lt=k(lt,mt,2*t,U),mt+=4),r&&(dt+=3,it[dt++]=Y[yt],it[dt++]=Y[yt+1],it[dt++]=Y[yt+2]),ut&&(st[pt++]=1,pt+=1)}else for(x=A-1;x>=0;x--)yt=3*x,rt=I(rt,ct,yt,C,L),ct+=6,p.st&&(lt=k(lt,mt,2*x,U),mt+=4),r&&(dt+=3,it[dt++]=Y[yt],it[dt++]=Y[yt+1],it[dt++]=Y[yt+2]),ut&&(st[pt++]=1,pt+=1);let ft=function(t,e,n){const a=t.length,r=e.normal?new Float32Array(a):void 0,i=e.tangent?new Float32Array(a):void 0,s=e.bitangent?new Float32Array(a):void 0;let l=0,u=0,c=0,m=!0,p=P,g=G,y=F;if(e.normal||e.tangent||e.bitangent)for(let f=0;f<a;f+=6){const h=o.Cartesian3.fromArray(t,f,E),b=o.Cartesian3.fromArray(t,(f+6)%a,O);if(m){const e=o.Cartesian3.fromArray(t,(f+3)%a,N);o.Cartesian3.subtract(b,h,b),o.Cartesian3.subtract(e,h,e),y=o.Cartesian3.normalize(o.Cartesian3.cross(e,b,y),y),m=!1}o.Cartesian3.equalsEpsilon(b,h,d.CesiumMath.EPSILON10)&&(m=!0),(e.tangent||e.bitangent)&&(p=n.geodeticSurfaceNormal(h,p),e.tangent&&(g=o.Cartesian3.normalize(o.Cartesian3.cross(p,y,g),g))),e.normal&&(r[l++]=y.x,r[l++]=y.y,r[l++]=y.z,r[l++]=y.x,r[l++]=y.y,r[l++]=y.z),e.tangent&&(i[u++]=g.x,i[u++]=g.y,i[u++]=g.z,i[u++]=g.x,i[u++]=g.y,i[u++]=g.z),e.bitangent&&(s[c++]=p.x,s[c++]=p.y,s[c++]=p.z,s[c++]=p.x,s[c++]=p.y,s[c++]=p.z)}return T(e,{positions:t,normals:r,tangents:i,bitangents:s})}(rt,p,b);p.st&&(ft.attributes.st=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:lt})),r&&(ft.attributes.extrudeDirection=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:it})),X&&(ft.attributes.applyOffset=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:st}));const ht=m.IndexDatatype.createTypedArray(ot,6*et);let bt,_t,At,xt;v=rt.length/3;let wt=0;for(x=0;x<v-1;x+=2){bt=x,xt=(bt+2)%v;const t=o.Cartesian3.fromArray(rt,3*bt,O),e=o.Cartesian3.fromArray(rt,3*xt,N);o.Cartesian3.equalsEpsilon(t,e,d.CesiumMath.EPSILON10)||(_t=(bt+1)%v,At=(_t+2)%v,ht[wt++]=bt,ht[wt++]=_t,ht[wt++]=xt,ht[wt++]=xt,ht[wt++]=_t,ht[wt++]=At)}return ft.indices=ht,ft=c.GeometryPipeline.combineInstances([new u.GeometryInstance({geometry:w}),new u.GeometryInstance({geometry:ft})]),ft[0]}const B=[new o.Cartesian3,new o.Cartesian3,new o.Cartesian3,new o.Cartesian3],U=new e.Cartographic,Y=new e.Cartographic;function q(t,n,a,o,r){if(0===a)return e.Rectangle.clone(t,r);const i=y.RectangleGeometryLibrary.computeOptions(t,n,a,0,V,U),s=i.height,l=i.width,u=B;return y.RectangleGeometryLibrary.computePosition(i,o,!1,0,0,u[0]),y.RectangleGeometryLibrary.computePosition(i,o,!1,0,l-1,u[1]),y.RectangleGeometryLibrary.computePosition(i,o,!1,s-1,0,u[2]),y.RectangleGeometryLibrary.computePosition(i,o,!1,s-1,l-1,u[3]),e.Rectangle.fromCartesianArray(u,o,r)}function X(n){const a=(n=t.defaultValue(n,t.defaultValue.EMPTY_OBJECT)).rectangle,o=t.defaultValue(n.height,0),r=t.defaultValue(n.extrudedHeight,o);this._rectangle=e.Rectangle.clone(a),this._granularity=t.defaultValue(n.granularity,d.CesiumMath.RADIANS_PER_DEGREE),this._ellipsoid=e.Ellipsoid.clone(t.defaultValue(n.ellipsoid,e.Ellipsoid.WGS84)),this._surfaceHeight=Math.max(o,r),this._rotation=t.defaultValue(n.rotation,0),this._stRotation=t.defaultValue(n.stRotation,0),this._vertexFormat=f.VertexFormat.clone(t.defaultValue(n.vertexFormat,f.VertexFormat.DEFAULT)),this._extrudedHeight=Math.min(o,r),this._shadowVolume=t.defaultValue(n.shadowVolume,!1),this._workerName="createRectangleGeometry",this._offsetAttribute=n.offsetAttribute,this._rotatedRectangle=void 0,this._textureCoordinateRotationPoints=void 0}X.packedLength=e.Rectangle.packedLength+e.Ellipsoid.packedLength+f.VertexFormat.packedLength+7,X.pack=function(n,a,o){return o=t.defaultValue(o,0),e.Rectangle.pack(n._rectangle,a,o),o+=e.Rectangle.packedLength,e.Ellipsoid.pack(n._ellipsoid,a,o),o+=e.Ellipsoid.packedLength,f.VertexFormat.pack(n._vertexFormat,a,o),o+=f.VertexFormat.packedLength,a[o++]=n._granularity,a[o++]=n._surfaceHeight,a[o++]=n._rotation,a[o++]=n._stRotation,a[o++]=n._extrudedHeight,a[o++]=n._shadowVolume?1:0,a[o]=t.defaultValue(n._offsetAttribute,-1),a};const Q=new e.Rectangle,W=e.Ellipsoid.clone(e.Ellipsoid.UNIT_SPHERE),j={rectangle:Q,ellipsoid:W,vertexFormat:H,granularity:void 0,height:void 0,rotation:void 0,stRotation:void 0,extrudedHeight:void 0,shadowVolume:void 0,offsetAttribute:void 0};X.unpack=function(n,a,o){a=t.defaultValue(a,0);const r=e.Rectangle.unpack(n,a,Q);a+=e.Rectangle.packedLength;const i=e.Ellipsoid.unpack(n,a,W);a+=e.Ellipsoid.packedLength;const s=f.VertexFormat.unpack(n,a,H);a+=f.VertexFormat.packedLength;const l=n[a++],u=n[a++],c=n[a++],m=n[a++],d=n[a++],p=1===n[a++],g=n[a];return t.defined(o)?(o._rectangle=e.Rectangle.clone(r,o._rectangle),o._ellipsoid=e.Ellipsoid.clone(i,o._ellipsoid),o._vertexFormat=f.VertexFormat.clone(s,o._vertexFormat),o._granularity=l,o._surfaceHeight=u,o._rotation=c,o._stRotation=m,o._extrudedHeight=d,o._shadowVolume=p,o._offsetAttribute=-1===g?void 0:g,o):(j.granularity=l,j.height=u,j.rotation=c,j.stRotation=m,j.extrudedHeight=d,j.shadowVolume=p,j.offsetAttribute=-1===g?void 0:g,new X(j))},X.computeRectangle=function(n,a){const o=(n=t.defaultValue(n,t.defaultValue.EMPTY_OBJECT)).rectangle,r=t.defaultValue(n.granularity,d.CesiumMath.RADIANS_PER_DEGREE),i=t.defaultValue(n.ellipsoid,e.Ellipsoid.WGS84);return q(o,r,t.defaultValue(n.rotation,0),i,a)};const J=new p.Matrix3,Z=new a.Quaternion,K=new e.Cartographic;X.createGeometry=function(o){if(d.CesiumMath.equalsEpsilon(o._rectangle.north,o._rectangle.south,d.CesiumMath.EPSILON10)||d.CesiumMath.equalsEpsilon(o._rectangle.east,o._rectangle.west,d.CesiumMath.EPSILON10))return;let r=o._rectangle;const l=o._ellipsoid,u=o._rotation,c=o._stRotation,m=o._vertexFormat,f=y.RectangleGeometryLibrary.computeOptions(r,o._granularity,u,c,V,U,Y),h=J;if(0!==c||0!==u){const t=e.Rectangle.center(r,K),n=l.geodeticSurfaceNormalCartographic(t,O);a.Quaternion.fromAxisAngle(n,-c,Z),p.Matrix3.fromQuaternion(Z,h)}else p.Matrix3.clone(p.Matrix3.IDENTITY,h);const b=o._surfaceHeight,_=o._extrudedHeight,A=!d.CesiumMath.equalsEpsilon(b,_,0,d.CesiumMath.EPSILON2);let x,w;if(f.lonScalar=1/o._rectangle.width,f.latScalar=1/o._rectangle.height,f.tangentRotationMatrix=h,r=o._rectangle,A){x=z(o,f);const t=a.BoundingSphere.fromRectangle3D(r,l,b,M),e=a.BoundingSphere.fromRectangle3D(r,l,_,D);w=a.BoundingSphere.union(t,e)}else{if(x=S(o,f),x.attributes.position.values=g.PolygonPipeline.scaleToGeodeticHeight(x.attributes.position.values,b,l,!1),t.defined(o._offsetAttribute)){const t=x.attributes.position.values.length,e=new Uint8Array(t/3),a=o._offsetAttribute===n.GeometryOffsetAttribute.NONE?0:1;n.arrayFill(e,a),x.attributes.applyOffset=new s.GeometryAttribute({componentDatatype:i.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:e})}w=a.BoundingSphere.fromRectangle3D(r,l,b)}return m.position||delete x.attributes.position,new s.Geometry({attributes:x.attributes,indices:x.indices,primitiveType:x.primitiveType,boundingSphere:w,offsetAttribute:o._offsetAttribute})},X.createShadowVolume=function(t,e,n){const a=t._granularity,o=t._ellipsoid,r=e(a,o),i=n(a,o);return new X({rectangle:t._rectangle,rotation:t._rotation,ellipsoid:o,stRotation:t._stRotation,granularity:a,extrudedHeight:i,height:r,vertexFormat:f.VertexFormat.POSITION_ONLY,shadowVolume:!0})};const $=new e.Rectangle,tt=[new e.Cartesian2,new e.Cartesian2,new e.Cartesian2],et=new e.Matrix2,nt=new e.Cartographic;return Object.defineProperties(X.prototype,{rectangle:{get:function(){return t.defined(this._rotatedRectangle)||(this._rotatedRectangle=q(this._rectangle,this._granularity,this._rotation,this._ellipsoid)),this._rotatedRectangle}},textureCoordinateRotationPoints:{get:function(){return t.defined(this._textureCoordinateRotationPoints)||(this._textureCoordinateRotationPoints=function(t){if(0===t._stRotation)return[0,0,0,1,1,0];const n=e.Rectangle.clone(t._rectangle,$),a=t._granularity,o=t._ellipsoid,r=q(n,a,t._rotation-t._stRotation,o,$),i=tt;i[0].x=r.west,i[0].y=r.south,i[1].x=r.west,i[1].y=r.north,i[2].x=r.east,i[2].y=r.south;const s=t.rectangle,l=e.Matrix2.fromRotation(t._stRotation,et),u=e.Rectangle.center(s,nt);for(let t=0;t<3;++t){const n=i[t];n.x-=u.longitude,n.y-=u.latitude,e.Matrix2.multiplyByVector(l,n,n),n.x+=u.longitude,n.y+=u.latitude,n.x=(n.x-s.west)/s.width,n.y=(n.y-s.south)/s.height}const c=i[0],m=i[1],d=i[2],p=new Array(6);return e.Cartesian2.pack(c,p),e.Cartesian2.pack(m,p,2),e.Cartesian2.pack(d,p,4),p}(this)),this._textureCoordinateRotationPoints}}}),function(n,a){return t.defined(a)&&(n=X.unpack(n,a)),n._ellipsoid=e.Ellipsoid.clone(n._ellipsoid),n._rectangle=e.Rectangle.clone(n._rectangle),X.createGeometry(n)}}));