2 lines
5.5 KiB
JavaScript
2 lines
5.5 KiB
JavaScript
/* 2020-9-22 15:23:25 | 版权所有 军懋国兴 */
|
|
define(["exports","./when-cbf8cd21","./Check-35e1a91d","./Math-69007a69","./Cartesian2-43e3a3be","./Transforms-2d1ac5ec","./ComponentDatatype-607c9a0c","./GeometryAttribute-2303bbfb","./GeometryAttributes-90846c5f","./IndexDatatype-79bb407c","./GeometryOffsetAttribute-9c676324","./VertexFormat-fe64931e","./CylinderGeometryLibrary-ea3f4c29"],function(e,I,m,U,S,q,B,Y,Z,J,W,f,j){"use strict";var H=new S.Cartesian2,K=new S.Cartesian3,Q=new S.Cartesian3,X=new S.Cartesian3,$=new S.Cartesian3;function d(e){var t=(e=I.defaultValue(e,I.defaultValue.EMPTY_OBJECT)).length,r=e.topRadius,a=e.bottomRadius,o=I.defaultValue(e.vertexFormat,f.VertexFormat.DEFAULT),n=I.defaultValue(e.slices,128);if(!I.defined(t))throw new m.DeveloperError("options.length must be defined.");if(!I.defined(r))throw new m.DeveloperError("options.topRadius must be defined.");if(!I.defined(a))throw new m.DeveloperError("options.bottomRadius must be defined.");if(n<3)throw new m.DeveloperError("options.slices must be greater than or equal to 3.");if(I.defined(e.offsetAttribute)&&e.offsetAttribute===W.GeometryOffsetAttribute.TOP)throw new m.DeveloperError("GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry.");this._length=t,this._topRadius=r,this._bottomRadius=a,this._vertexFormat=f.VertexFormat.clone(o),this._slices=n,this._offsetAttribute=e.offsetAttribute,this._workerName="createCylinderGeometry"}d.packedLength=f.VertexFormat.packedLength+5,d.pack=function(e,t,r){if(!I.defined(e))throw new m.DeveloperError("value is required");if(!I.defined(t))throw new m.DeveloperError("array is required");return r=I.defaultValue(r,0),f.VertexFormat.pack(e._vertexFormat,t,r),r+=f.VertexFormat.packedLength,t[r++]=e._length,t[r++]=e._topRadius,t[r++]=e._bottomRadius,t[r++]=e._slices,t[r]=I.defaultValue(e._offsetAttribute,-1),t};var t,p=new f.VertexFormat,l={vertexFormat:p,length:void 0,topRadius:void 0,bottomRadius:void 0,slices:void 0,offsetAttribute:void 0};d.unpack=function(e,t,r){if(!I.defined(e))throw new m.DeveloperError("array is required");t=I.defaultValue(t,0);var a=f.VertexFormat.unpack(e,t,p);t+=f.VertexFormat.packedLength;var o=e[t++],n=e[t++],i=e[t++],s=e[t++],u=e[t];return I.defined(r)?(r._vertexFormat=f.VertexFormat.clone(a,r._vertexFormat),r._length=o,r._topRadius=n,r._bottomRadius=i,r._slices=s,r._offsetAttribute=-1===u?void 0:u,r):(l.length=o,l.topRadius=n,l.bottomRadius=i,l.slices=s,l.offsetAttribute=-1===u?void 0:u,new d(l))},d.createGeometry=function(e){var t=e._length,r=e._topRadius,a=e._bottomRadius,o=e._vertexFormat,n=e._slices;if(!(t<=0||r<0||a<0||0===r&&0===a)){var i=n+n,s=n+i,u=i+i,m=j.CylinderGeometryLibrary.computePositions(t,r,a,n,!0),f=o.st?new Float32Array(2*u):void 0,d=o.normal?new Float32Array(3*u):void 0,p=o.tangent?new Float32Array(3*u):void 0,l=o.bitangent?new Float32Array(3*u):void 0,y=o.normal||o.tangent||o.bitangent;if(y){var b=o.tangent||o.bitangent,c=0,v=0,A=0,h=Math.atan2(a-r,t),w=K;w.z=Math.sin(h);for(var g=Math.cos(h),x=X,_=Q,C=0;C<n;C++){var F=C/n*U.CesiumMath.TWO_PI,D=g*Math.cos(F),G=g*Math.sin(F);y&&(w.x=D,w.y=G,b&&(x=S.Cartesian3.normalize(S.Cartesian3.cross(S.Cartesian3.UNIT_Z,w,x),x)),o.normal&&(d[c++]=w.x,d[c++]=w.y,d[c++]=w.z,d[c++]=w.x,d[c++]=w.y,d[c++]=w.z),o.tangent&&(p[v++]=x.x,p[v++]=x.y,p[v++]=x.z,p[v++]=x.x,p[v++]=x.y,p[v++]=x.z),o.bitangent&&(_=S.Cartesian3.normalize(S.Cartesian3.cross(w,x,_),_),l[A++]=_.x,l[A++]=_.y,l[A++]=_.z,l[A++]=_.x,l[A++]=_.y,l[A++]=_.z))}for(C=0;C<n;C++)o.normal&&(d[c++]=0,d[c++]=0,d[c++]=-1),o.tangent&&(p[v++]=1,p[v++]=0,p[v++]=0),o.bitangent&&(l[A++]=0,l[A++]=-1,l[A++]=0);for(C=0;C<n;C++)o.normal&&(d[c++]=0,d[c++]=0,d[c++]=1),o.tangent&&(p[v++]=1,p[v++]=0,p[v++]=0),o.bitangent&&(l[A++]=0,l[A++]=1,l[A++]=0)}var R=12*n-12,O=J.IndexDatatype.createTypedArray(u,R),T=0,V=0;for(C=0;C<n-1;C++)O[T++]=V,O[T++]=V+2,O[T++]=V+3,O[T++]=V,O[T++]=V+3,O[T++]=V+1,V+=2;for(O[T++]=i-2,O[T++]=0,O[T++]=1,O[T++]=i-2,O[T++]=1,O[T++]=i-1,C=1;C<n-1;C++)O[T++]=i+C+1,O[T++]=i+C,O[T++]=i;for(C=1;C<n-1;C++)O[T++]=s,O[T++]=s+C,O[T++]=s+C+1;var E=0;if(o.st){var L=Math.max(r,a);for(C=0;C<u;C++){var P=S.Cartesian3.fromArray(m,3*C,$);f[E++]=(P.x+L)/(2*L),f[E++]=(P.y+L)/(2*L)}}var k=new Z.GeometryAttributes;o.position&&(k.position=new Y.GeometryAttribute({componentDatatype:B.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:m})),o.normal&&(k.normal=new Y.GeometryAttribute({componentDatatype:B.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:d})),o.tangent&&(k.tangent=new Y.GeometryAttribute({componentDatatype:B.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:p})),o.bitangent&&(k.bitangent=new Y.GeometryAttribute({componentDatatype:B.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:l})),o.st&&(k.st=new Y.GeometryAttribute({componentDatatype:B.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:f})),H.x=.5*t,H.y=Math.max(a,r);var M,z,N=new q.BoundingSphere(S.Cartesian3.ZERO,S.Cartesian2.magnitude(H));return I.defined(e._offsetAttribute)&&(t=m.length,M=new Uint8Array(t/3),z=e._offsetAttribute===W.GeometryOffsetAttribute.NONE?0:1,W.arrayFill(M,z),k.applyOffset=new Y.GeometryAttribute({componentDatatype:B.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:M})),new Y.Geometry({attributes:k,indices:O,primitiveType:Y.PrimitiveType.TRIANGLES,boundingSphere:N,offsetAttribute:e._offsetAttribute})}},d.getUnitCylinder=function(){return I.defined(t)||(t=d.createGeometry(new d({topRadius:1,bottomRadius:1,length:1,vertexFormat:f.VertexFormat.POSITION_ONLY}))),t},e.CylinderGeometry=d}); |