You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cesium/Cesium/Workers/createPolylineGeometry.js

2 lines
6.2 KiB
JavaScript

define(["./when-208fe5b0","./Cartesian2-8417ca3d","./ArcType-dc1c5aee","./arrayRemoveDuplicates-0f62a181","./Transforms-a73b3b3b","./Color-b0d12252","./ComponentDatatype-9204e9f6","./Check-d18af7c4","./GeometryAttribute-04a19cfe","./GeometryAttributes-b0b294d8","./IndexDatatype-d47ad6f6","./Math-4e53b694","./PolylinePipeline-28f5feec","./VertexFormat-e8cbf5b3","./RuntimeError-7f634f5d","./WebGLConstants-76bb35d1","./EllipsoidGeodesic-8015072b","./EllipsoidRhumbLine-28521929","./IntersectionTests-7d224a2f","./Plane-4aa8974d"],function(Y,q,z,J,j,K,Q,e,X,Z,$,ee,te,y,t,r,a,o,n,i){"use strict";var re=[];function m(e){var t=(e=Y.defaultValue(e,Y.defaultValue.EMPTY_OBJECT)).positions,r=e.colors,a=Y.defaultValue(e.width,1),o=Y.defaultValue(e.colorsPerVertex,!1);this._positions=t,this._colors=r,this._width=a,this._colorsPerVertex=o,this._vertexFormat=y.VertexFormat.clone(Y.defaultValue(e.vertexFormat,y.VertexFormat.DEFAULT)),this._arcType=Y.defaultValue(e.arcType,z.ArcType.GEODESIC),this._granularity=Y.defaultValue(e.granularity,ee.CesiumMath.RADIANS_PER_DEGREE),this._ellipsoid=q.Ellipsoid.clone(Y.defaultValue(e.ellipsoid,q.Ellipsoid.WGS84)),this._workerName="createPolylineGeometry";t=1+t.length*q.Cartesian3.packedLength;t+=Y.defined(r)?1+r.length*K.Color.packedLength:1,this.packedLength=t+q.Ellipsoid.packedLength+y.VertexFormat.packedLength+4}m.pack=function(e,t,r){var a;r=Y.defaultValue(r,0);var o=e._positions,n=o.length;for(t[r++]=n,a=0;a<n;++a,r+=q.Cartesian3.packedLength)q.Cartesian3.pack(o[a],t,r);var i=e._colors,n=Y.defined(i)?i.length:0;for(t[r++]=n,a=0;a<n;++a,r+=K.Color.packedLength)K.Color.pack(i[a],t,r);return q.Ellipsoid.pack(e._ellipsoid,t,r),r+=q.Ellipsoid.packedLength,y.VertexFormat.pack(e._vertexFormat,t,r),r+=y.VertexFormat.packedLength,t[r++]=e._width,t[r++]=e._colorsPerVertex?1:0,t[r++]=e._arcType,t[r]=e._granularity,t};var f=q.Ellipsoid.clone(q.Ellipsoid.UNIT_SPHERE),h=new y.VertexFormat,C={positions:void 0,colors:void 0,ellipsoid:f,vertexFormat:h,width:void 0,colorsPerVertex:void 0,arcType:void 0,granularity:void 0};m.unpack=function(e,t,r){t=Y.defaultValue(t,0);for(var a=e[t++],o=new Array(a),n=0;n<a;++n,t+=q.Cartesian3.packedLength)o[n]=q.Cartesian3.unpack(e,t);var i=0<(a=e[t++])?new Array(a):void 0;for(n=0;n<a;++n,t+=K.Color.packedLength)i[n]=K.Color.unpack(e,t);var l=q.Ellipsoid.unpack(e,t,f);t+=q.Ellipsoid.packedLength;var s=y.VertexFormat.unpack(e,t,h);t+=y.VertexFormat.packedLength;var p=e[t++],d=1===e[t++],c=e[t++],u=e[t];return Y.defined(r)?(r._positions=o,r._colors=i,r._ellipsoid=q.Ellipsoid.clone(l,r._ellipsoid),r._vertexFormat=y.VertexFormat.clone(s,r._vertexFormat),r._width=p,r._colorsPerVertex=d,r._arcType=c,r._granularity=u,r):(C.positions=o,C.colors=i,C.width=p,C.colorsPerVertex=d,C.arcType=c,C.granularity=u,new m(C))};var ae=new q.Cartesian3,oe=new q.Cartesian3,ne=new q.Cartesian3,ie=new q.Cartesian3;return m.createGeometry=function(e){var t=e._width,r=e._vertexFormat,a=e._colors,o=e._colorsPerVertex,n=e._arcType,i=e._granularity,l=e._ellipsoid,s=J.arrayRemoveDuplicates(e._positions,q.Cartesian3.equalsEpsilon);if(!((E=s.length)<2||t<=0)){if(n===z.ArcType.GEODESIC||n===z.ArcType.RHUMB){var p,d=n===z.ArcType.GEODESIC?(p=ee.CesiumMath.chordLength(i,l.maximumRadius),te.PolylinePipeline.numberOfPoints):(p=i,te.PolylinePipeline.numberOfPointsRhumbLine),c=te.PolylinePipeline.extractHeights(s,l);if(Y.defined(a)){for(var u=1,y=0;y<E-1;++y)u+=d(s[y],s[y+1],p);var m=new Array(u),f=0;for(y=0;y<E-1;++y){var h=s[y],C=s[y+1],v=a[y],g=d(h,C,p);if(o&&y<u)for(var _=function(e,t,r){var a=re;a.length=r;var o=e.red,n=e.green,i=e.blue,l=e.alpha,s=t.red,p=t.green,d=t.blue,c=t.alpha;if(K.Color.equals(e,t)){for(h=0;h<r;h++)a[h]=K.Color.clone(e);return a}for(var u=(s-o)/r,y=(p-n)/r,m=(d-i)/r,f=(c-l)/r,h=0;h<r;h++)a[h]=new K.Color(o+h*u,n+h*y,i+h*m,l+h*f);return a}(v,a[y+1],g),b=_.length,A=0;A<b;++A)m[f++]=_[A];else for(A=0;A<g;++A)m[f++]=K.Color.clone(v)}m[f]=K.Color.clone(a[a.length-1]),a=m,re.length=0}s=n===z.ArcType.GEODESIC?te.PolylinePipeline.generateCartesianArc({positions:s,minDistance:p,ellipsoid:l,height:c}):te.PolylinePipeline.generateCartesianRhumbArc({positions:s,granularity:p,ellipsoid:l,height:c})}var E,P,w,T,l=4*(E=s.length)-4,x=new Float64Array(3*l),k=new Float64Array(3*l),D=new Float64Array(3*l),V=new Float32Array(2*l),L=r.st?new Float32Array(2*l):void 0,F=Y.defined(a)?new Uint8Array(4*l):void 0,G=0,O=0,R=0,I=0;for(A=0;A<E;++A){0===A?(q.Cartesian3.subtract(s[0],s[1],P=ae),q.Cartesian3.add(s[0],P,P)):P=s[A-1],q.Cartesian3.clone(P,ne),q.Cartesian3.clone(s[A],oe),A===E-1?(q.Cartesian3.subtract(s[E-1],s[E-2],P=ae),q.Cartesian3.add(s[E-1],P,P)):P=s[A+1],q.Cartesian3.clone(P,ie),Y.defined(F)&&(w=0===A||o?a[A]:a[A-1],A!==E-1&&(T=a[A]));for(var S=A===E-1?2:4,B=0===A?2:0;B<S;++B){q.Cartesian3.pack(oe,x,G),q.Cartesian3.pack(ne,k,G),q.Cartesian3.pack(ie,D,G),G+=3;var U=B-2<0?-1:1;V[O++]=B%2*2-1,V[O++]=U*t,r.st&&(L[R++]=A/(E-1),L[R++]=Math.max(V[O-2],0)),Y.defined(F)&&(F[I++]=K.Color.floatToByte((U=B<2?w:T).red),F[I++]=K.Color.floatToByte(U.green),F[I++]=K.Color.floatToByte(U.blue),F[I++]=K.Color.floatToByte(U.alpha))}}c=new Z.GeometryAttributes;c.position=new X.GeometryAttribute({componentDatatype:Q.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:x}),c.prevPosition=new X.GeometryAttribute({componentDatatype:Q.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:k}),c.nextPosition=new X.GeometryAttribute({componentDatatype:Q.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:D}),c.expandAndWidth=new X.GeometryAttribute({componentDatatype:Q.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:V}),r.st&&(c.st=new X.GeometryAttribute({componentDatatype:Q.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:L})),Y.defined(F)&&(c.color=new X.GeometryAttribute({componentDatatype:Q.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:4,values:F,normalize:!0}));var N=$.IndexDatatype.createTypedArray(l,6*E-6),M=0,H=0,W=E-1;for(A=0;A<W;++A)N[H++]=M,N[H++]=M+2,N[H++]=M+1,N[H++]=M+1,N[H++]=M+2,N[H++]=M+3,M+=4;return new X.Geometry({attributes:c,indices:N,primitiveType:X.PrimitiveType.TRIANGLES,boundingSphere:j.BoundingSphere.fromPoints(s),geometryType:X.GeometryType.POLYLINES})}},function(e,t){return(e=Y.defined(t)?m.unpack(e,t):e)._ellipsoid=q.Ellipsoid.clone(e._ellipsoid),m.createGeometry(e)}});