createRectangleGeometry.js 15 KB

1
  1. define(["./when-4bbc8319","./Matrix2-ccd5b911","./GeometryOffsetAttribute-1772960d","./Transforms-d5c6ad6e","./RuntimeError-346a3079","./ComponentDatatype-93750d1a","./GeometryAttribute-c30799b8","./GeometryAttributes-7827a6c2","./GeometryInstance-5f4fe82b","./GeometryPipeline-548e76d2","./IndexDatatype-b7d979a6","./PolygonPipeline-83fb62b0","./RectangleGeometryLibrary-48d34d36","./VertexFormat-71718faa","./combine-83860057","./WebGLConstants-1c8239cc","./AttributeCompression-1f045b73","./EncodedCartesian3-08b8d980","./IntersectionTests-4d6f5c54","./Plane-18bb00f8","./EllipsoidRhumbLine-aa9e6266"],function(Q,W,J,p,t,j,Z,r,K,$,tt,et,S,at,e,a,n,i,o,s,l){"use strict";var rt=new W.Cartesian3,nt=new W.Cartesian3,it=new W.Cartesian3,ot=new W.Cartesian3,d=new W.Rectangle,I=new W.Cartesian2,g=new p.BoundingSphere,y=new p.BoundingSphere;function st(t,e){var a=new Z.Geometry({attributes:new r.GeometryAttributes,primitiveType:Z.PrimitiveType.TRIANGLES});return a.attributes.position=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:e.positions}),t.normal&&(a.attributes.normal=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.normals})),t.tangent&&(a.attributes.tangent=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.tangents})),t.bitangent&&(a.attributes.bitangent=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.bitangents})),a}var lt=new W.Cartesian3,ut=new W.Cartesian3;function ct(t,e){var a=t._vertexFormat,r=t._ellipsoid,n=e.height,i=e.width,o=e.northCap,s=e.southCap,l=0,u=n,c=n,t=0;o&&(--c,t+=l=1),s&&(--u,--c,t+=1),t+=i*c;for(var m=a.position?new Float64Array(3*t):void 0,p=a.st?new Float32Array(2*t):void 0,d=0,g=0,y=rt,f=I,h=Number.MAX_VALUE,b=Number.MAX_VALUE,v=-Number.MAX_VALUE,_=-Number.MAX_VALUE,A=l;A<u;++A)for(var x=0;x<i;++x)S.RectangleGeometryLibrary.computePosition(e,r,a.st,A,x,y,f),m[d++]=y.x,m[d++]=y.y,m[d++]=y.z,a.st&&(p[g++]=f.x,p[g++]=f.y,h=Math.min(h,f.x),b=Math.min(b,f.y),v=Math.max(v,f.x),_=Math.max(_,f.y));if(o&&(S.RectangleGeometryLibrary.computePosition(e,r,a.st,0,0,y,f),m[d++]=y.x,m[d++]=y.y,m[d++]=y.z,a.st&&(p[g++]=f.x,p[g++]=f.y,h=f.x,b=f.y,v=f.x,_=f.y)),s&&(S.RectangleGeometryLibrary.computePosition(e,r,a.st,n-1,0,y,f),m[d++]=y.x,m[d++]=y.y,m[d]=y.z,a.st&&(p[g++]=f.x,p[g]=f.y,h=Math.min(h,f.x),b=Math.min(b,f.y),v=Math.max(v,f.x),_=Math.max(_,f.y))),a.st&&(h<0||b<0||1<v||1<_))for(var w=0;w<p.length;w+=2)p[w]=(p[w]-h)/(v-h),p[w+1]=(p[w+1]-b)/(_-b);l=function(t,e,a,r){var n=t.length,i=e.normal?new Float32Array(n):void 0,o=e.tangent?new Float32Array(n):void 0,s=e.bitangent?new Float32Array(n):void 0,l=0,u=ot,c=it,m=nt;if(e.normal||e.tangent||e.bitangent)for(var p=0;p<n;p+=3){var d=W.Cartesian3.fromArray(t,p,rt),g=l+1,y=l+2,m=a.geodeticSurfaceNormal(d,m);(e.tangent||e.bitangent)&&(W.Cartesian3.cross(W.Cartesian3.UNIT_Z,m,c),W.Matrix3.multiplyByVector(r,c,c),W.Cartesian3.normalize(c,c),e.bitangent&&W.Cartesian3.normalize(W.Cartesian3.cross(m,c,u),u)),e.normal&&(i[l]=m.x,i[g]=m.y,i[y]=m.z),e.tangent&&(o[l]=c.x,o[g]=c.y,o[y]=c.z),e.bitangent&&(s[l]=u.x,s[g]=u.y,s[y]=u.z),l+=3}return st(e,{positions:t,normals:i,tangents:o,bitangents:s})}(m,a,r,e.tangentRotationMatrix),n=6*(i-1)*(c-1);o&&(n+=3*(i-1)),s&&(n+=3*(i-1));for(var C=tt.IndexDatatype.createTypedArray(t,n),R=0,E=0,F=0;F<c-1;++F){for(var G=0;G<i-1;++G){var P=R,V=P+i,L=V+1,D=P+1;C[E++]=P,C[E++]=V,C[E++]=D,C[E++]=D,C[E++]=V,C[E++]=L,++R}++R}if(o||s){var M,T,O=t-1,N=t-1;if(o&&s&&(O=t-2),R=0,o)for(F=0;F<i-1;F++)T=(M=R)+1,C[E++]=O,C[E++]=M,C[E++]=T,++R;if(s)for(R=(c-1)*i,F=0;F<i-1;F++)T=(M=R)+1,C[E++]=M,C[E++]=N,C[E++]=T,++R}return l.indices=C,a.st&&(l.attributes.st=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:p})),l}function mt(t,e,a,r,n){return t[e++]=r[a],t[e++]=r[a+1],t[e++]=r[a+2],t[e++]=n[a],t[e++]=n[a+1],t[e]=n[a+2],t}function pt(t,e,a,r){return t[e++]=r[a],t[e++]=r[a+1],t[e++]=r[a],t[e]=r[a+1],t}var dt=new at.VertexFormat;function f(t,e){var a=t._shadowVolume,r=t._offsetAttribute,n=t._vertexFormat,i=t._extrudedHeight,o=t._surfaceHeight,s=t._ellipsoid,l=e.height,u=e.width;a&&((b=at.VertexFormat.clone(n,dt)).normal=!0,t._vertexFormat=b);var c=ct(t,e);a&&(t._vertexFormat=n);var m=et.PolygonPipeline.scaleToGeodeticHeight(c.attributes.position.values,o,s,!1),p=2*(z=(m=new Float64Array(m)).length),d=new Float64Array(p);d.set(m);var g=et.PolygonPipeline.scaleToGeodeticHeight(c.attributes.position.values,i,s);d.set(g,z),c.attributes.position.values=d;var y,f,h,b=n.normal?new Float32Array(p):void 0,t=n.tangent?new Float32Array(p):void 0,o=n.bitangent?new Float32Array(p):void 0,i=n.st?new Float32Array(p/3*2):void 0;if(n.normal){for(f=c.attributes.normal.values,b.set(f),_=0;_<z;_++)f[_]=-f[_];b.set(f,z),c.attributes.normal.values=b}if(a){f=c.attributes.normal.values,n.normal||(c.attributes.normal=void 0);for(var v=new Float32Array(p),_=0;_<z;_++)f[_]=-f[_];v.set(f,z),c.attributes.extrudeDirection=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:v})}d=Q.defined(r);if(d&&(b=z/3*2,v=new Uint8Array(b),v=r===J.GeometryOffsetAttribute.TOP?J.arrayFill(v,1,0,b/2):(h=r===J.GeometryOffsetAttribute.NONE?0:1,J.arrayFill(v,h)),c.attributes.applyOffset=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:v})),n.tangent){var A=c.attributes.tangent.values;for(t.set(A),_=0;_<z;_++)A[_]=-A[_];t.set(A,z),c.attributes.tangent.values=t}n.bitangent&&(E=c.attributes.bitangent.values,o.set(E),o.set(E,z),c.attributes.bitangent.values=o),n.st&&(y=c.attributes.st.values,i.set(y),i.set(y,z/3*2),c.attributes.st.values=i);var x=c.indices,w=x.length,C=z/3,R=tt.IndexDatatype.createTypedArray(p/3,2*w);for(R.set(x),_=0;_<w;_+=3)R[_+w]=x[_+2]+C,R[_+1+w]=x[_+1]+C,R[_+2+w]=x[_]+C;c.indices=R;var t=e.northCap,E=e.southCap,o=l,i=2,p=0,e=4,l=4;t&&(--i,--o,p+=1,e-=2,--l),E&&(--i,--o,p+=1,e-=2,--l);var l=2*((p+=i*u+2*o-e)+l),F=new Float64Array(3*l),G=a?new Float32Array(3*l):void 0,P=d?new Uint8Array(l):void 0,V=n.st?new Float32Array(2*l):void 0,L=r===J.GeometryOffsetAttribute.TOP;d&&!L&&(h=r===J.GeometryOffsetAttribute.ALL?1:0,P=J.arrayFill(P,h));var D=0,M=0,T=0,O=0,N=u*o;for(_=0;_<N;_+=u)F=mt(F,D,I=3*_,m,g),D+=6,n.st&&(V=pt(V,M,2*_,y),M+=4),a&&(T+=3,G[T++]=f[I],G[T++]=f[I+1],G[T++]=f[I+2]),L&&(P[O++]=1,O+=1);if(E){var S=t?1+N:N,I=3*S;for(_=0;_<2;_++)F=mt(F,D,I,m,g),D+=6,n.st&&(V=pt(V,M,2*S,y),M+=4),a&&(T+=3,G[T++]=f[I],G[T++]=f[I+1],G[T++]=f[I+2]),L&&(P[O++]=1,O+=1)}else for(_=N-u;_<N;_++)F=mt(F,D,I=3*_,m,g),D+=6,n.st&&(V=pt(V,M,2*_,y),M+=4),a&&(T+=3,G[T++]=f[I],G[T++]=f[I+1],G[T++]=f[I+2]),L&&(P[O++]=1,O+=1);for(_=N-1;0<_;_-=u)F=mt(F,D,I=3*_,m,g),D+=6,n.st&&(V=pt(V,M,2*_,y),M+=4),a&&(T+=3,G[T++]=f[I],G[T++]=f[I+1],G[T++]=f[I+2]),L&&(P[O++]=1,O+=1);if(t){var k=N;for(I=3*k,_=0;_<2;_++)F=mt(F,D,I,m,g),D+=6,n.st&&(V=pt(V,M,2*k,y),M+=4),a&&(T+=3,G[T++]=f[I],G[T++]=f[I+1],G[T++]=f[I+2]),L&&(P[O++]=1,O+=1)}else for(_=u-1;0<=_;_--)F=mt(F,D,I=3*_,m,g),D+=6,n.st&&(V=pt(V,M,2*_,y),M+=4),a&&(T+=3,G[T++]=f[I],G[T++]=f[I+1],G[T++]=f[I+2]),L&&(P[O++]=1,O+=1);s=function(t,e,a){var r=t.length,n=e.normal?new Float32Array(r):void 0,i=e.tangent?new Float32Array(r):void 0,o=e.bitangent?new Float32Array(r):void 0,s=0,l=0,u=0,c=!0,m=ot,p=it,d=nt;if(e.normal||e.tangent||e.bitangent)for(var g=0;g<r;g+=6){var y,f=W.Cartesian3.fromArray(t,g,rt),h=W.Cartesian3.fromArray(t,(g+6)%r,lt);c&&(y=W.Cartesian3.fromArray(t,(g+3)%r,ut),W.Cartesian3.subtract(h,f,h),W.Cartesian3.subtract(y,f,y),d=W.Cartesian3.normalize(W.Cartesian3.cross(y,h,d),d),c=!1),W.Cartesian3.equalsEpsilon(h,f,j.CesiumMath.EPSILON10)&&(c=!0),(e.tangent||e.bitangent)&&(m=a.geodeticSurfaceNormal(f,m),e.tangent&&(p=W.Cartesian3.normalize(W.Cartesian3.cross(m,d,p),p))),e.normal&&(n[s++]=d.x,n[s++]=d.y,n[s++]=d.z,n[s++]=d.x,n[s++]=d.y,n[s++]=d.z),e.tangent&&(i[l++]=p.x,i[l++]=p.y,i[l++]=p.z,i[l++]=p.x,i[l++]=p.y,i[l++]=p.z),e.bitangent&&(o[u++]=m.x,o[u++]=m.y,o[u++]=m.z,o[u++]=m.x,o[u++]=m.y,o[u++]=m.z)}return st(e,{positions:t,normals:n,tangents:i,bitangents:o})}(F,n,s);n.st&&(s.attributes.st=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:V})),a&&(s.attributes.extrudeDirection=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:G})),d&&(s.attributes.applyOffset=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:P}));var H=tt.IndexDatatype.createTypedArray(l,6*p),z=F.length/3,B=0;for(_=0;_<z-1;_+=2){var U,Y=((U=_)+2)%z,q=W.Cartesian3.fromArray(F,3*U,lt),X=W.Cartesian3.fromArray(F,3*Y,ut);W.Cartesian3.equalsEpsilon(q,X,j.CesiumMath.EPSILON10)||(X=(2+(q=(U+1)%z))%z,H[B++]=U,H[B++]=q,H[B++]=Y,H[B++]=Y,H[B++]=q,H[B++]=X)}return s.indices=H,(s=$.GeometryPipeline.combineInstances([new K.GeometryInstance({geometry:c}),new K.GeometryInstance({geometry:s})]))[0]}var u=[new W.Cartesian3,new W.Cartesian3,new W.Cartesian3,new W.Cartesian3],h=new W.Cartographic,b=new W.Cartographic;function c(t,e,a,r,n){if(0===a)return W.Rectangle.clone(t,n);var i=S.RectangleGeometryLibrary.computeOptions(t,e,a,0,d,h),t=i.height,e=i.width,a=u;return S.RectangleGeometryLibrary.computePosition(i,r,!1,0,0,a[0]),S.RectangleGeometryLibrary.computePosition(i,r,!1,0,e-1,a[1]),S.RectangleGeometryLibrary.computePosition(i,r,!1,t-1,0,a[2]),S.RectangleGeometryLibrary.computePosition(i,r,!1,t-1,e-1,a[3]),W.Rectangle.fromCartesianArray(a,r,n)}function v(t){var e=(t=Q.defaultValue(t,Q.defaultValue.EMPTY_OBJECT)).rectangle,a=Q.defaultValue(t.height,0),r=Q.defaultValue(t.extrudedHeight,a);this._rectangle=W.Rectangle.clone(e),this._granularity=Q.defaultValue(t.granularity,j.CesiumMath.RADIANS_PER_DEGREE),this._ellipsoid=W.Ellipsoid.clone(Q.defaultValue(t.ellipsoid,W.Ellipsoid.WGS84)),this._surfaceHeight=Math.max(a,r),this._rotation=Q.defaultValue(t.rotation,0),this._stRotation=Q.defaultValue(t.stRotation,0),this._vertexFormat=at.VertexFormat.clone(Q.defaultValue(t.vertexFormat,at.VertexFormat.DEFAULT)),this._extrudedHeight=Math.min(a,r),this._shadowVolume=Q.defaultValue(t.shadowVolume,!1),this._workerName="createRectangleGeometry",this._offsetAttribute=t.offsetAttribute,this._rotatedRectangle=void 0,this._textureCoordinateRotationPoints=void 0}v.packedLength=W.Rectangle.packedLength+W.Ellipsoid.packedLength+at.VertexFormat.packedLength+7,v.pack=function(t,e,a){return a=Q.defaultValue(a,0),W.Rectangle.pack(t._rectangle,e,a),a+=W.Rectangle.packedLength,W.Ellipsoid.pack(t._ellipsoid,e,a),a+=W.Ellipsoid.packedLength,at.VertexFormat.pack(t._vertexFormat,e,a),a+=at.VertexFormat.packedLength,e[a++]=t._granularity,e[a++]=t._surfaceHeight,e[a++]=t._rotation,e[a++]=t._stRotation,e[a++]=t._extrudedHeight,e[a++]=t._shadowVolume?1:0,e[a]=Q.defaultValue(t._offsetAttribute,-1),e};var _=new W.Rectangle,A=W.Ellipsoid.clone(W.Ellipsoid.UNIT_SPHERE),x={rectangle:_,ellipsoid:A,vertexFormat:dt,granularity:void 0,height:void 0,rotation:void 0,stRotation:void 0,extrudedHeight:void 0,shadowVolume:void 0,offsetAttribute:void 0};v.unpack=function(t,e,a){e=Q.defaultValue(e,0);var r=W.Rectangle.unpack(t,e,_);e+=W.Rectangle.packedLength;var n=W.Ellipsoid.unpack(t,e,A);e+=W.Ellipsoid.packedLength;var i=at.VertexFormat.unpack(t,e,dt);e+=at.VertexFormat.packedLength;var o=t[e++],s=t[e++],l=t[e++],u=t[e++],c=t[e++],m=1===t[e++],e=t[e];return Q.defined(a)?(a._rectangle=W.Rectangle.clone(r,a._rectangle),a._ellipsoid=W.Ellipsoid.clone(n,a._ellipsoid),a._vertexFormat=at.VertexFormat.clone(i,a._vertexFormat),a._granularity=o,a._surfaceHeight=s,a._rotation=l,a._stRotation=u,a._extrudedHeight=c,a._shadowVolume=m,a._offsetAttribute=-1===e?void 0:e,a):(x.granularity=o,x.height=s,x.rotation=l,x.stRotation=u,x.extrudedHeight=c,x.shadowVolume=m,x.offsetAttribute=-1===e?void 0:e,new v(x))},v.computeRectangle=function(t,e){var a=(t=Q.defaultValue(t,Q.defaultValue.EMPTY_OBJECT)).rectangle,r=Q.defaultValue(t.granularity,j.CesiumMath.RADIANS_PER_DEGREE),n=Q.defaultValue(t.ellipsoid,W.Ellipsoid.WGS84);return c(a,r,Q.defaultValue(t.rotation,0),n,e)};var w=new W.Matrix3,C=new p.Quaternion,R=new W.Cartographic;v.createGeometry=function(t){if(!j.CesiumMath.equalsEpsilon(t._rectangle.north,t._rectangle.south,j.CesiumMath.EPSILON10)&&!j.CesiumMath.equalsEpsilon(t._rectangle.east,t._rectangle.west,j.CesiumMath.EPSILON10)){var e=t._rectangle,a=t._ellipsoid,r=t._rotation,n=t._stRotation,i=t._vertexFormat,o=S.RectangleGeometryLibrary.computeOptions(e,t._granularity,r,n,d,h,b),s=w;0!==n||0!==r?(c=W.Rectangle.center(e,R),m=a.geodeticSurfaceNormalCartographic(c,lt),p.Quaternion.fromAxisAngle(m,-n,C),W.Matrix3.fromQuaternion(C,s)):W.Matrix3.clone(W.Matrix3.IDENTITY,s);var l,u,c=t._surfaceHeight,m=t._extrudedHeight,n=!j.CesiumMath.equalsEpsilon(c,m,0,j.CesiumMath.EPSILON2);return o.lonScalar=1/t._rectangle.width,o.latScalar=1/t._rectangle.height,o.tangentRotationMatrix=s,e=t._rectangle,c=n?(l=f(t,o),n=p.BoundingSphere.fromRectangle3D(e,a,c,y),u=p.BoundingSphere.fromRectangle3D(e,a,m,g),p.BoundingSphere.union(n,u)):((l=ct(t,o)).attributes.position.values=et.PolygonPipeline.scaleToGeodeticHeight(l.attributes.position.values,c,a,!1),Q.defined(t._offsetAttribute)&&(u=l.attributes.position.values.length,o=new Uint8Array(u/3),u=t._offsetAttribute===J.GeometryOffsetAttribute.NONE?0:1,J.arrayFill(o,u),l.attributes.applyOffset=new Z.GeometryAttribute({componentDatatype:j.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:o})),p.BoundingSphere.fromRectangle3D(e,a,c)),i.position||delete l.attributes.position,new Z.Geometry({attributes:l.attributes,indices:l.indices,primitiveType:l.primitiveType,boundingSphere:c,offsetAttribute:t._offsetAttribute})}},v.createShadowVolume=function(t,e,a){var r=t._granularity,n=t._ellipsoid,e=e(r,n),a=a(r,n);return new v({rectangle:t._rectangle,rotation:t._rotation,ellipsoid:n,stRotation:t._stRotation,granularity:r,extrudedHeight:a,height:e,vertexFormat:at.VertexFormat.POSITION_ONLY,shadowVolume:!0})};var m=new W.Rectangle,E=[new W.Cartesian2,new W.Cartesian2,new W.Cartesian2],F=new W.Matrix2,G=new W.Cartographic;return Object.defineProperties(v.prototype,{rectangle:{get:function(){return Q.defined(this._rotatedRectangle)||(this._rotatedRectangle=c(this._rectangle,this._granularity,this._rotation,this._ellipsoid)),this._rotatedRectangle}},textureCoordinateRotationPoints:{get:function(){return Q.defined(this._textureCoordinateRotationPoints)||(this._textureCoordinateRotationPoints=function(t){if(0===t._stRotation)return[0,0,0,1,1,0];var e=W.Rectangle.clone(t._rectangle,m),a=t._granularity,r=t._ellipsoid,e=c(e,a,t._rotation-t._stRotation,r,m),n=E;n[0].x=e.west,n[0].y=e.south,n[1].x=e.west,n[1].y=e.north,n[2].x=e.east,n[2].y=e.south;for(var i=t.rectangle,o=W.Matrix2.fromRotation(t._stRotation,F),s=W.Rectangle.center(i,G),l=0;l<3;++l){var u=n[l];u.x-=s.longitude,u.y-=s.latitude,W.Matrix2.multiplyByVector(o,u,u),u.x+=s.longitude,u.y+=s.latitude,u.x=(u.x-i.west)/i.width,u.y=(u.y-i.south)/i.height}return a=n[0],r=n[1],e=n[2],t=new Array(6),W.Cartesian2.pack(a,t),W.Cartesian2.pack(r,t,2),W.Cartesian2.pack(e,t,4),t}(this)),this._textureCoordinateRotationPoints}}}),function(t,e){return(t=Q.defined(e)?v.unpack(t,e):t)._ellipsoid=W.Ellipsoid.clone(t._ellipsoid),t._rectangle=W.Rectangle.clone(t._rectangle),v.createGeometry(t)}});