CylinderGeometry-c1d3aa81.js 4.8 KB

1
  1. define(["exports","./GeometryOffsetAttribute-ed56ff58","./Transforms-99272364","./Matrix2-e3fb4559","./Cartesian3-7e9cc2ff","./ComponentDatatype-aaeec80f","./CylinderGeometryLibrary-4083111e","./defaultValue-81eec7ed","./Check-741c5f3c","./GeometryAttribute-088ad91d","./GeometryAttributes-32b29525","./IndexDatatype-f1e3f799","./Math-5f585871","./VertexFormat-d50a69ba"],(function(t,e,n,a,o,r,i,s,u,m,c,l,f,d){"use strict";const p=new a.Cartesian2,y=new o.Cartesian3,b=new o.Cartesian3,A=new o.Cartesian3,x=new o.Cartesian3;function g(t){const e=(t=s.defaultValue(t,s.defaultValue.EMPTY_OBJECT)).length,n=t.topRadius,a=t.bottomRadius,o=s.defaultValue(t.vertexFormat,d.VertexFormat.DEFAULT),r=s.defaultValue(t.slices,128);this._length=e,this._topRadius=n,this._bottomRadius=a,this._vertexFormat=d.VertexFormat.clone(o),this._slices=r,this._offsetAttribute=t.offsetAttribute,this._workerName="createCylinderGeometry"}g.packedLength=d.VertexFormat.packedLength+5,g.pack=function(t,e,n){return n=s.defaultValue(n,0),d.VertexFormat.pack(t._vertexFormat,e,n),n+=d.VertexFormat.packedLength,e[n++]=t._length,e[n++]=t._topRadius,e[n++]=t._bottomRadius,e[n++]=t._slices,e[n]=s.defaultValue(t._offsetAttribute,-1),e};const _=new d.VertexFormat,h={vertexFormat:_,length:void 0,topRadius:void 0,bottomRadius:void 0,slices:void 0,offsetAttribute:void 0};let C;g.unpack=function(t,e,n){e=s.defaultValue(e,0);const a=d.VertexFormat.unpack(t,e,_);e+=d.VertexFormat.packedLength;const o=t[e++],r=t[e++],i=t[e++],u=t[e++],m=t[e];return s.defined(n)?(n._vertexFormat=d.VertexFormat.clone(a,n._vertexFormat),n._length=o,n._topRadius=r,n._bottomRadius=i,n._slices=u,n._offsetAttribute=-1===m?void 0:m,n):(h.length=o,h.topRadius=r,h.bottomRadius=i,h.slices=u,h.offsetAttribute=-1===m?void 0:m,new g(h))},g.createGeometry=function(t){let u=t._length;const d=t._topRadius,g=t._bottomRadius,_=t._vertexFormat,h=t._slices;if(u<=0||d<0||g<0||0===d&&0===g)return;const C=h+h,F=h+C,v=C+C,w=i.CylinderGeometryLibrary.computePositions(u,d,g,h,!0),G=_.st?new Float32Array(2*v):void 0,V=_.normal?new Float32Array(3*v):void 0,D=_.tangent?new Float32Array(3*v):void 0,R=_.bitangent?new Float32Array(3*v):void 0;let T;const O=_.normal||_.tangent||_.bitangent;if(O){const t=_.tangent||_.bitangent;let e=0,n=0,a=0;const r=Math.atan2(g-d,u),i=y;i.z=Math.sin(r);const s=Math.cos(r);let m=A,c=b;for(T=0;T<h;T++){const r=T/h*f.CesiumMath.TWO_PI,u=s*Math.cos(r),l=s*Math.sin(r);O&&(i.x=u,i.y=l,t&&(m=o.Cartesian3.normalize(o.Cartesian3.cross(o.Cartesian3.UNIT_Z,i,m),m)),_.normal&&(V[e++]=i.x,V[e++]=i.y,V[e++]=i.z,V[e++]=i.x,V[e++]=i.y,V[e++]=i.z),_.tangent&&(D[n++]=m.x,D[n++]=m.y,D[n++]=m.z,D[n++]=m.x,D[n++]=m.y,D[n++]=m.z),_.bitangent&&(c=o.Cartesian3.normalize(o.Cartesian3.cross(i,m,c),c),R[a++]=c.x,R[a++]=c.y,R[a++]=c.z,R[a++]=c.x,R[a++]=c.y,R[a++]=c.z))}for(T=0;T<h;T++)_.normal&&(V[e++]=0,V[e++]=0,V[e++]=-1),_.tangent&&(D[n++]=1,D[n++]=0,D[n++]=0),_.bitangent&&(R[a++]=0,R[a++]=-1,R[a++]=0);for(T=0;T<h;T++)_.normal&&(V[e++]=0,V[e++]=0,V[e++]=1),_.tangent&&(D[n++]=1,D[n++]=0,D[n++]=0),_.bitangent&&(R[a++]=0,R[a++]=1,R[a++]=0)}const L=12*h-12,M=l.IndexDatatype.createTypedArray(v,L);let P=0,k=0;for(T=0;T<h-1;T++)M[P++]=k,M[P++]=k+2,M[P++]=k+3,M[P++]=k,M[P++]=k+3,M[P++]=k+1,k+=2;for(M[P++]=C-2,M[P++]=0,M[P++]=1,M[P++]=C-2,M[P++]=1,M[P++]=C-1,T=1;T<h-1;T++)M[P++]=C+T+1,M[P++]=C+T,M[P++]=C;for(T=1;T<h-1;T++)M[P++]=F,M[P++]=F+T,M[P++]=F+T+1;let z=0;if(_.st){const t=Math.max(d,g);for(T=0;T<v;T++){const e=o.Cartesian3.fromArray(w,3*T,x);G[z++]=(e.x+t)/(2*t),G[z++]=(e.y+t)/(2*t)}}const E=new c.GeometryAttributes;_.position&&(E.position=new m.GeometryAttribute({componentDatatype:r.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:w})),_.normal&&(E.normal=new m.GeometryAttribute({componentDatatype:r.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:V})),_.tangent&&(E.tangent=new m.GeometryAttribute({componentDatatype:r.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:D})),_.bitangent&&(E.bitangent=new m.GeometryAttribute({componentDatatype:r.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:R})),_.st&&(E.st=new m.GeometryAttribute({componentDatatype:r.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:G})),p.x=.5*u,p.y=Math.max(g,d);const N=new n.BoundingSphere(o.Cartesian3.ZERO,a.Cartesian2.magnitude(p));if(s.defined(t._offsetAttribute)){u=w.length;const n=new Uint8Array(u/3),a=t._offsetAttribute===e.GeometryOffsetAttribute.NONE?0:1;e.arrayFill(n,a),E.applyOffset=new m.GeometryAttribute({componentDatatype:r.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:1,values:n})}return new m.Geometry({attributes:E,indices:M,primitiveType:m.PrimitiveType.TRIANGLES,boundingSphere:N,offsetAttribute:t._offsetAttribute})},g.getUnitCylinder=function(){return s.defined(C)||(C=g.createGeometry(new g({topRadius:1,bottomRadius:1,length:1,vertexFormat:d.VertexFormat.POSITION_ONLY}))),C},t.CylinderGeometry=g}));