learning_cesium/XbsjCesium/Workers/CylinderGeometry-9b030fda.js

2 lines
4.7 KiB
JavaScript

define(["exports","./GeometryOffsetAttribute-6e5d8e16","./Transforms-251ff661","./Cartesian2-697a9954","./ComponentDatatype-417761a2","./CylinderGeometryLibrary-c6bbe161","./when-54335d57","./Check-f3fec9b0","./GeometryAttribute-7ca1c9e4","./GeometryAttributes-caa08d6c","./IndexDatatype-c134ea39","./Math-737a2579","./VertexFormat-acf45ede"],function(t,P,k,M,z,E,N,e,I,U,S,B,m){"use strict";var Y=new M.Cartesian2,Z=new M.Cartesian3,J=new M.Cartesian3,W=new M.Cartesian3,j=new M.Cartesian3;function u(t){var e=(t=N.defaultValue(t,N.defaultValue.EMPTY_OBJECT)).length,a=t.topRadius,r=t.bottomRadius,n=N.defaultValue(t.vertexFormat,m.VertexFormat.DEFAULT),o=N.defaultValue(t.slices,128);this._length=e,this._topRadius=a,this._bottomRadius=r,this._vertexFormat=m.VertexFormat.clone(n),this._slices=o,this._offsetAttribute=t.offsetAttribute,this._workerName="createCylinderGeometry"}u.packedLength=m.VertexFormat.packedLength+5,u.pack=function(t,e,a){return a=N.defaultValue(a,0),m.VertexFormat.pack(t._vertexFormat,e,a),a+=m.VertexFormat.packedLength,e[a++]=t._length,e[a++]=t._topRadius,e[a++]=t._bottomRadius,e[a++]=t._slices,e[a]=N.defaultValue(t._offsetAttribute,-1),e};var a,p=new m.VertexFormat,d={vertexFormat:p,length:void 0,topRadius:void 0,bottomRadius:void 0,slices:void 0,offsetAttribute:void 0};u.unpack=function(t,e,a){e=N.defaultValue(e,0);var r=m.VertexFormat.unpack(t,e,p);e+=m.VertexFormat.packedLength;var n=t[e++],o=t[e++],i=t[e++],s=t[e++],e=t[e];return N.defined(a)?(a._vertexFormat=m.VertexFormat.clone(r,a._vertexFormat),a._length=n,a._topRadius=o,a._bottomRadius=i,a._slices=s,a._offsetAttribute=-1===e?void 0:e,a):(d.length=n,d.topRadius=o,d.bottomRadius=i,d.slices=s,d.offsetAttribute=-1===e?void 0:e,new u(d))},u.createGeometry=function(t){var e=t._length,a=t._topRadius,r=t._bottomRadius,n=t._vertexFormat,o=t._slices;if(!(e<=0||a<0||r<0||0===a&&0===r)){var i=o+o,s=o+i,m=i+i,u=E.CylinderGeometryLibrary.computePositions(e,a,r,o,!0),p=n.st?new Float32Array(2*m):void 0,d=n.normal?new Float32Array(3*m):void 0,y=n.tangent?new Float32Array(3*m):void 0,f=n.bitangent?new Float32Array(3*m):void 0,l=n.normal||n.tangent||n.bitangent;if(l){var c=n.tangent||n.bitangent,b=0,v=0,A=0,g=Math.atan2(r-a,e),h=Z;h.z=Math.sin(g);for(var x=Math.cos(g),_=W,C=J,F=0;F<o;F++){var w=F/o*B.CesiumMath.TWO_PI,G=x*Math.cos(w),w=x*Math.sin(w);l&&(h.x=G,h.y=w,c&&(_=M.Cartesian3.normalize(M.Cartesian3.cross(M.Cartesian3.UNIT_Z,h,_),_)),n.normal&&(d[b++]=h.x,d[b++]=h.y,d[b++]=h.z,d[b++]=h.x,d[b++]=h.y,d[b++]=h.z),n.tangent&&(y[v++]=_.x,y[v++]=_.y,y[v++]=_.z,y[v++]=_.x,y[v++]=_.y,y[v++]=_.z),n.bitangent&&(C=M.Cartesian3.normalize(M.Cartesian3.cross(h,_,C),C),f[A++]=C.x,f[A++]=C.y,f[A++]=C.z,f[A++]=C.x,f[A++]=C.y,f[A++]=C.z))}for(F=0;F<o;F++)n.normal&&(d[b++]=0,d[b++]=0,d[b++]=-1),n.tangent&&(y[v++]=1,y[v++]=0,y[v++]=0),n.bitangent&&(f[A++]=0,f[A++]=-1,f[A++]=0);for(F=0;F<o;F++)n.normal&&(d[b++]=0,d[b++]=0,d[b++]=1),n.tangent&&(y[v++]=1,y[v++]=0,y[v++]=0),n.bitangent&&(f[A++]=0,f[A++]=1,f[A++]=0)}var D=S.IndexDatatype.createTypedArray(m,12*o-12),R=0,V=0;for(F=0;F<o-1;F++)D[R++]=V,D[R++]=V+2,D[R++]=V+3,D[R++]=V,D[R++]=V+3,D[R++]=V+1,V+=2;for(D[R++]=i-2,D[R++]=0,D[R++]=1,D[R++]=i-2,D[R++]=1,D[R++]=i-1,F=1;F<o-1;F++)D[R++]=i+F+1,D[R++]=i+F,D[R++]=i;for(F=1;F<o-1;F++)D[R++]=s,D[R++]=s+F,D[R++]=s+F+1;var T=0;if(n.st){var O=Math.max(a,r);for(F=0;F<m;F++){var L=M.Cartesian3.fromArray(u,3*F,j);p[T++]=(L.x+O)/(2*O),p[T++]=(L.y+O)/(2*O)}}g=new U.GeometryAttributes;n.position&&(g.position=new I.GeometryAttribute({componentDatatype:z.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:u})),n.normal&&(g.normal=new I.GeometryAttribute({componentDatatype:z.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:d})),n.tangent&&(g.tangent=new I.GeometryAttribute({componentDatatype:z.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:y})),n.bitangent&&(g.bitangent=new I.GeometryAttribute({componentDatatype:z.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:f})),n.st&&(g.st=new I.GeometryAttribute({componentDatatype:z.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:p})),Y.x=.5*e,Y.y=Math.max(r,a);r=new k.BoundingSphere(M.Cartesian3.ZERO,M.Cartesian2.magnitude(Y));return N.defined(t._offsetAttribute)&&(e=u.length,a=new Uint8Array(e/3),e=t._offsetAttribute===P.GeometryOffsetAttribute.NONE?0:1,P.arrayFill(a,e),g.applyOffset=new I.GeometryAttribute({componentDatatype:z.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:a})),new I.Geometry({attributes:g,indices:D,primitiveType:I.PrimitiveType.TRIANGLES,boundingSphere:r,offsetAttribute:t._offsetAttribute})}},u.getUnitCylinder=function(){return a=!N.defined(a)?u.createGeometry(new u({topRadius:1,bottomRadius:1,length:1,vertexFormat:m.VertexFormat.POSITION_ONLY})):a},t.CylinderGeometry=u});