createCoplanarPolygonGeometry.js 6.3 KB

1
  1. define(["./arrayRemoveDuplicates-85770175","./BoundingRectangle-b88064b7","./Transforms-98ffa11d","./Matrix2-e3fb4559","./Cartesian3-7e9cc2ff","./Check-741c5f3c","./ComponentDatatype-aaeec80f","./CoplanarPolygonGeometryLibrary-d95ab18f","./defaultValue-81eec7ed","./GeometryAttribute-b025f9a8","./GeometryAttributes-32b29525","./GeometryInstance-ce434bcb","./GeometryPipeline-4b426993","./IndexDatatype-f1e3f799","./Math-5f585871","./Matrix4-d34187af","./PolygonGeometryLibrary-8f834b9d","./PolygonPipeline-6f83d8b1","./VertexFormat-d50a69ba","./_commonjsHelpers-3aae1032-26891ab7","./combine-3c023bda","./RuntimeError-26acdd3b","./WebGLConstants-508b9636","./OrientedBoundingBox-3db45505","./EllipsoidTangentPlane-fa1337e1","./AxisAlignedBoundingBox-37250ed6","./IntersectionTests-73b87d72","./Plane-4f75b3df","./AttributeCompression-e2e3f0dd","./EncodedCartesian3-aac44514","./ArcType-fc72c06c","./EllipsoidRhumbLine-9c6b32ea"],(function(e,t,n,o,a,r,i,s,l,c,p,y,u,m,d,g,b,f,h,x,C,P,A,w,F,G,L,E,v,T,D,_){"use strict";const V=new a.Cartesian3,k=new t.BoundingRectangle,R=new o.Cartesian2,M=new o.Cartesian2,I=new a.Cartesian3,B=new a.Cartesian3,H=new a.Cartesian3,O=new a.Cartesian3,z=new a.Cartesian3,S=new a.Cartesian3,N=new n.Quaternion,Q=new g.Matrix3,j=new g.Matrix3,U=new a.Cartesian3;function Y(e,t,r,s,l,y,u,b){const h=e.positions;let x=f.PolygonPipeline.triangulate(e.positions2D,e.holes);x.length<3&&(x=[0,1,2]);const C=m.IndexDatatype.createTypedArray(h.length,x.length);C.set(x);let P=Q;if(0!==s){let e=n.Quaternion.fromAxisAngle(y,s,N);if(P=g.Matrix3.fromQuaternion(e,P),t.tangent||t.bitangent){e=n.Quaternion.fromAxisAngle(y,-s,N);const o=g.Matrix3.fromQuaternion(e,j);u=a.Cartesian3.normalize(g.Matrix3.multiplyByVector(o,u,u),u),t.bitangent&&(b=a.Cartesian3.normalize(a.Cartesian3.cross(y,u,b),b))}}else P=g.Matrix3.clone(g.Matrix3.IDENTITY,P);const A=M;t.st&&(A.x=r.x,A.y=r.y);const w=h.length,F=3*w,G=new Float64Array(F),L=t.normal?new Float32Array(F):void 0,E=t.tangent?new Float32Array(F):void 0,v=t.bitangent?new Float32Array(F):void 0,T=t.st?new Float32Array(2*w):void 0;let D=0,_=0,k=0,I=0,B=0;for(let e=0;e<w;e++){const n=h[e];if(G[D++]=n.x,G[D++]=n.y,G[D++]=n.z,t.st){const e=l(g.Matrix3.multiplyByVector(P,n,V),R);o.Cartesian2.subtract(e,A,e);const t=d.CesiumMath.clamp(e.x/r.width,0,1),a=d.CesiumMath.clamp(e.y/r.height,0,1);T[B++]=t,T[B++]=a}t.normal&&(L[_++]=y.x,L[_++]=y.y,L[_++]=y.z),t.tangent&&(E[I++]=u.x,E[I++]=u.y,E[I++]=u.z),t.bitangent&&(v[k++]=b.x,v[k++]=b.y,v[k++]=b.z)}const H=new p.GeometryAttributes;return t.position&&(H.position=new c.GeometryAttribute({componentDatatype:i.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:G})),t.normal&&(H.normal=new c.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:L})),t.tangent&&(H.tangent=new c.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:E})),t.bitangent&&(H.bitangent=new c.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:v})),t.st&&(H.st=new c.GeometryAttribute({componentDatatype:i.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:T})),new c.Geometry({attributes:H,indices:C,primitiveType:c.PrimitiveType.TRIANGLES})}function q(e){const t=(e=l.defaultValue(e,l.defaultValue.EMPTY_OBJECT)).polygonHierarchy,n=l.defaultValue(e.vertexFormat,h.VertexFormat.DEFAULT);this._vertexFormat=h.VertexFormat.clone(n),this._polygonHierarchy=t,this._stRotation=l.defaultValue(e.stRotation,0),this._ellipsoid=o.Ellipsoid.clone(l.defaultValue(e.ellipsoid,o.Ellipsoid.WGS84)),this._workerName="createCoplanarPolygonGeometry",this.packedLength=b.PolygonGeometryLibrary.computeHierarchyPackedLength(t)+h.VertexFormat.packedLength+o.Ellipsoid.packedLength+2}q.fromPositions=function(e){return new q({polygonHierarchy:{positions:(e=l.defaultValue(e,l.defaultValue.EMPTY_OBJECT)).positions},vertexFormat:e.vertexFormat,stRotation:e.stRotation,ellipsoid:e.ellipsoid})},q.pack=function(e,t,n){return n=l.defaultValue(n,0),n=b.PolygonGeometryLibrary.packPolygonHierarchy(e._polygonHierarchy,t,n),o.Ellipsoid.pack(e._ellipsoid,t,n),n+=o.Ellipsoid.packedLength,h.VertexFormat.pack(e._vertexFormat,t,n),n+=h.VertexFormat.packedLength,t[n++]=e._stRotation,t[n]=e.packedLength,t};const J=o.Ellipsoid.clone(o.Ellipsoid.UNIT_SPHERE),W=new h.VertexFormat,Z={polygonHierarchy:{}};return q.unpack=function(e,t,n){t=l.defaultValue(t,0);const a=b.PolygonGeometryLibrary.unpackPolygonHierarchy(e,t);t=a.startingIndex,delete a.startingIndex;const r=o.Ellipsoid.unpack(e,t,J);t+=o.Ellipsoid.packedLength;const i=h.VertexFormat.unpack(e,t,W);t+=h.VertexFormat.packedLength;const s=e[t++],c=e[t];return l.defined(n)||(n=new q(Z)),n._polygonHierarchy=a,n._ellipsoid=o.Ellipsoid.clone(r,n._ellipsoid),n._vertexFormat=h.VertexFormat.clone(i,n._vertexFormat),n._stRotation=s,n.packedLength=c,n},q.createGeometry=function(t){const o=t._vertexFormat,r=t._polygonHierarchy,i=t._stRotation;let l=r.positions;if(l=e.arrayRemoveDuplicates(l,a.Cartesian3.equalsEpsilon,!0),l.length<3)return;let p=I,g=B,f=H,h=z;const x=S;if(!s.CoplanarPolygonGeometryLibrary.computeProjectTo2DArguments(l,O,h,x))return;if(p=a.Cartesian3.cross(h,x,p),p=a.Cartesian3.normalize(p,p),!a.Cartesian3.equalsEpsilon(O,a.Cartesian3.ZERO,d.CesiumMath.EPSILON6)){const e=t._ellipsoid.geodeticSurfaceNormal(O,U);a.Cartesian3.dot(p,e)<0&&(p=a.Cartesian3.negate(p,p),h=a.Cartesian3.negate(h,h))}const C=s.CoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction(O,h,x),P=s.CoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction(O,h,x);o.tangent&&(g=a.Cartesian3.clone(h,g)),o.bitangent&&(f=a.Cartesian3.clone(x,f));const A=b.PolygonGeometryLibrary.polygonsFromHierarchy(r,C,!1),w=A.hierarchy,F=A.polygons;if(0===w.length)return;l=w[0].outerRing;const G=n.BoundingSphere.fromPoints(l),L=b.PolygonGeometryLibrary.computeBoundingRectangle(p,P,l,i,k),E=[];for(let e=0;e<F.length;e++){const t=new y.GeometryInstance({geometry:Y(F[e],o,L,i,P,p,g,f)});E.push(t)}const v=u.GeometryPipeline.combineInstances(E)[0];v.attributes.position.values=new Float64Array(v.attributes.position.values),v.indices=m.IndexDatatype.createTypedArray(v.attributes.position.values.length/3,v.indices);const T=v.attributes;return o.position||delete T.position,new c.Geometry({attributes:T,indices:v.indices,primitiveType:v.primitiveType,boundingSphere:G})},function(e,t){return l.defined(t)&&(e=q.unpack(e,t)),q.createGeometry(e)}}));