createPolylineGeometry.js 6.6 KB

1
  1. define(["./defaultValue-81eec7ed","./Matrix2-e3fb4559","./ArcType-fc72c06c","./arrayRemoveDuplicates-85770175","./Transforms-98ffa11d","./Cartesian3-7e9cc2ff","./Color-3aa7f38b","./ComponentDatatype-aaeec80f","./Check-741c5f3c","./GeometryAttribute-b025f9a8","./GeometryAttributes-32b29525","./IndexDatatype-f1e3f799","./Math-5f585871","./PolylinePipeline-de59c85a","./VertexFormat-d50a69ba","./Matrix4-d34187af","./RuntimeError-26acdd3b","./_commonjsHelpers-3aae1032-26891ab7","./combine-3c023bda","./WebGLConstants-508b9636","./EllipsoidGeodesic-6de45192","./EllipsoidRhumbLine-9c6b32ea","./IntersectionTests-73b87d72","./Plane-4f75b3df"],(function(e,t,o,r,n,a,i,l,s,c,p,d,u,y,f,m,h,C,g,_,b,A,E,P){"use strict";const x=[];function w(e,t,o,r,n){const a=x;let l;a.length=n;const s=o.red,c=o.green,p=o.blue,d=o.alpha,u=r.red,y=r.green,f=r.blue,m=r.alpha;if(i.Color.equals(o,r)){for(l=0;l<n;l++)a[l]=i.Color.clone(o);return a}const h=(u-s)/n,C=(y-c)/n,g=(f-p)/n,_=(m-d)/n;for(l=0;l<n;l++)a[l]=new i.Color(s+l*h,c+l*C,p+l*g,d+l*_);return a}function T(r){const n=(r=e.defaultValue(r,e.defaultValue.EMPTY_OBJECT)).positions,l=r.colors,s=e.defaultValue(r.width,1),c=e.defaultValue(r.colorsPerVertex,!1);this._positions=n,this._colors=l,this._width=s,this._colorsPerVertex=c,this._vertexFormat=f.VertexFormat.clone(e.defaultValue(r.vertexFormat,f.VertexFormat.DEFAULT)),this._arcType=e.defaultValue(r.arcType,o.ArcType.GEODESIC),this._granularity=e.defaultValue(r.granularity,u.CesiumMath.RADIANS_PER_DEGREE),this._ellipsoid=t.Ellipsoid.clone(e.defaultValue(r.ellipsoid,t.Ellipsoid.WGS84)),this._workerName="createPolylineGeometry";let p=1+n.length*a.Cartesian3.packedLength;p+=e.defined(l)?1+l.length*i.Color.packedLength:1,this.packedLength=p+t.Ellipsoid.packedLength+f.VertexFormat.packedLength+4}T.pack=function(o,r,n){let l;n=e.defaultValue(n,0);const s=o._positions;let c=s.length;for(r[n++]=c,l=0;l<c;++l,n+=a.Cartesian3.packedLength)a.Cartesian3.pack(s[l],r,n);const p=o._colors;for(c=e.defined(p)?p.length:0,r[n++]=c,l=0;l<c;++l,n+=i.Color.packedLength)i.Color.pack(p[l],r,n);return t.Ellipsoid.pack(o._ellipsoid,r,n),n+=t.Ellipsoid.packedLength,f.VertexFormat.pack(o._vertexFormat,r,n),n+=f.VertexFormat.packedLength,r[n++]=o._width,r[n++]=o._colorsPerVertex?1:0,r[n++]=o._arcType,r[n]=o._granularity,r};const k=t.Ellipsoid.clone(t.Ellipsoid.UNIT_SPHERE),D=new f.VertexFormat,V={positions:void 0,colors:void 0,ellipsoid:k,vertexFormat:D,width:void 0,colorsPerVertex:void 0,arcType:void 0,granularity:void 0};T.unpack=function(o,r,n){let l;r=e.defaultValue(r,0);let s=o[r++];const c=new Array(s);for(l=0;l<s;++l,r+=a.Cartesian3.packedLength)c[l]=a.Cartesian3.unpack(o,r);s=o[r++];const p=s>0?new Array(s):void 0;for(l=0;l<s;++l,r+=i.Color.packedLength)p[l]=i.Color.unpack(o,r);const d=t.Ellipsoid.unpack(o,r,k);r+=t.Ellipsoid.packedLength;const u=f.VertexFormat.unpack(o,r,D);r+=f.VertexFormat.packedLength;const y=o[r++],m=1===o[r++],h=o[r++],C=o[r];return e.defined(n)?(n._positions=c,n._colors=p,n._ellipsoid=t.Ellipsoid.clone(d,n._ellipsoid),n._vertexFormat=f.VertexFormat.clone(u,n._vertexFormat),n._width=y,n._colorsPerVertex=m,n._arcType=h,n._granularity=C,n):(V.positions=c,V.colors=p,V.width=y,V.colorsPerVertex=m,V.arcType=h,V.granularity=C,new T(V))};const v=new a.Cartesian3,L=new a.Cartesian3,F=new a.Cartesian3,G=new a.Cartesian3;return T.createGeometry=function(t){const s=t._width,f=t._vertexFormat;let m=t._colors;const h=t._colorsPerVertex,C=t._arcType,g=t._granularity,_=t._ellipsoid;let b,A,E;const P=[];let T=r.arrayRemoveDuplicates(t._positions,a.Cartesian3.equalsEpsilon,!1,P);if(e.defined(m)&&P.length>0){let e=0,t=P[0];m=m.filter((function(o,r){let n=!1;return n=h?r===t||0===r&&1===t:r+1===t,!n||(e++,t=P[e],!1)}))}let k=T.length;if(k<2||s<=0)return;if(C===o.ArcType.GEODESIC||C===o.ArcType.RHUMB){let t,r;C===o.ArcType.GEODESIC?(t=u.CesiumMath.chordLength(g,_.maximumRadius),r=y.PolylinePipeline.numberOfPoints):(t=g,r=y.PolylinePipeline.numberOfPointsRhumbLine);const n=y.PolylinePipeline.extractHeights(T,_);if(e.defined(m)){let e=1;for(b=0;b<k-1;++b)e+=r(T[b],T[b+1],t);const o=new Array(e);let n=0;for(b=0;b<k-1;++b){const a=T[b],l=T[b+1],s=m[b],c=r(a,l,t);if(h&&b<e){const e=w(0,0,s,m[b+1],c),t=e.length;for(A=0;A<t;++A)o[n++]=e[A]}else for(A=0;A<c;++A)o[n++]=i.Color.clone(s)}o[n]=i.Color.clone(m[m.length-1]),m=o,x.length=0}T=C===o.ArcType.GEODESIC?y.PolylinePipeline.generateCartesianArc({positions:T,minDistance:t,ellipsoid:_,height:n}):y.PolylinePipeline.generateCartesianRhumbArc({positions:T,granularity:t,ellipsoid:_,height:n})}k=T.length;const D=4*k-4,V=new Float64Array(3*D),O=new Float64Array(3*D),R=new Float64Array(3*D),I=new Float32Array(2*D),S=f.st?new Float32Array(2*D):void 0,B=e.defined(m)?new Uint8Array(4*D):void 0;let M,U=0,N=0,H=0,W=0;for(A=0;A<k;++A){let t,o;0===A?(M=v,a.Cartesian3.subtract(T[0],T[1],M),a.Cartesian3.add(T[0],M,M)):M=T[A-1],a.Cartesian3.clone(M,F),a.Cartesian3.clone(T[A],L),A===k-1?(M=v,a.Cartesian3.subtract(T[k-1],T[k-2],M),a.Cartesian3.add(T[k-1],M,M)):M=T[A+1],a.Cartesian3.clone(M,G),e.defined(B)&&(t=0===A||h?m[A]:m[A-1],A!==k-1&&(o=m[A]));const r=A===k-1?2:4;for(E=0===A?2:0;E<r;++E){a.Cartesian3.pack(L,V,U),a.Cartesian3.pack(F,O,U),a.Cartesian3.pack(G,R,U),U+=3;const r=E-2<0?-1:1;if(I[N++]=E%2*2-1,I[N++]=r*s,f.st&&(S[H++]=A/(k-1),S[H++]=Math.max(I[N-2],0)),e.defined(B)){const e=E<2?t:o;B[W++]=i.Color.floatToByte(e.red),B[W++]=i.Color.floatToByte(e.green),B[W++]=i.Color.floatToByte(e.blue),B[W++]=i.Color.floatToByte(e.alpha)}}}const Y=new p.GeometryAttributes;Y.position=new c.GeometryAttribute({componentDatatype:l.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:V}),Y.prevPosition=new c.GeometryAttribute({componentDatatype:l.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:O}),Y.nextPosition=new c.GeometryAttribute({componentDatatype:l.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:R}),Y.expandAndWidth=new c.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:I}),f.st&&(Y.st=new c.GeometryAttribute({componentDatatype:l.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:S})),e.defined(B)&&(Y.color=new c.GeometryAttribute({componentDatatype:l.ComponentDatatype.UNSIGNED_BYTE,componentsPerAttribute:4,values:B,normalize:!0}));const q=d.IndexDatatype.createTypedArray(D,6*k-6);let j=0,z=0;const J=k-1;for(A=0;A<J;++A)q[z++]=j,q[z++]=j+2,q[z++]=j+1,q[z++]=j+1,q[z++]=j+2,q[z++]=j+3,j+=4;return new c.Geometry({attributes:Y,indices:q,primitiveType:c.PrimitiveType.TRIANGLES,boundingSphere:n.BoundingSphere.fromPoints(T),geometryType:c.GeometryType.POLYLINES})},function(o,r){return e.defined(r)&&(o=T.unpack(o,r)),o._ellipsoid=t.Ellipsoid.clone(o._ellipsoid),T.createGeometry(o)}}));