learning_cesium/XbsjCesium/Workers/createCoplanarPolygonGeomet...

2 lines
6.1 KiB
JavaScript

define(["./arrayRemoveDuplicates-db90b85c","./BoundingRectangle-f46bca91","./Transforms-251ff661","./Cartesian2-697a9954","./Check-f3fec9b0","./ComponentDatatype-417761a2","./CoplanarPolygonGeometryLibrary-6ea2bc18","./when-54335d57","./GeometryAttribute-7ca1c9e4","./GeometryAttributes-caa08d6c","./GeometryInstance-1bb3fb4a","./GeometryPipeline-1dd54e44","./IndexDatatype-c134ea39","./Math-737a2579","./PolygonGeometryLibrary-e3208a07","./PolygonPipeline-1048742e","./VertexFormat-acf45ede","./RuntimeError-88a32665","./WebGLConstants-4739ce15","./OrientedBoundingBox-d1fd9cf8","./EllipsoidTangentPlane-ae33ec6a","./AxisAlignedBoundingBox-dcfdb7a9","./IntersectionTests-3e34a0aa","./Plane-d4cb7bb3","./AttributeCompression-ab5c33b7","./EncodedCartesian3-0ae9fe5e","./ArcType-2b58731c","./EllipsoidRhumbLine-e5c51fa7"],function(h,e,L,E,t,T,f,l,D,_,C,v,k,V,x,R,s,a,n,r,o,i,p,c,y,u,m,d){"use strict";var I=new E.Cartesian3,P=new e.BoundingRectangle,M=new E.Cartesian2,B=new E.Cartesian2,A=new E.Cartesian3,w=new E.Cartesian3,F=new E.Cartesian3,G=new E.Cartesian3,H=new E.Cartesian3,O=new E.Cartesian3,z=new L.Quaternion,S=new L.Matrix3,N=new L.Matrix3,Q=new E.Cartesian3;function g(e){var t=(e=l.defaultValue(e,l.defaultValue.EMPTY_OBJECT)).polygonHierarchy,a=l.defaultValue(e.vertexFormat,s.VertexFormat.DEFAULT);this._vertexFormat=s.VertexFormat.clone(a),this._polygonHierarchy=t,this._stRotation=l.defaultValue(e.stRotation,0),this._ellipsoid=E.Ellipsoid.clone(l.defaultValue(e.ellipsoid,E.Ellipsoid.WGS84)),this._workerName="createCoplanarPolygonGeometry",this.packedLength=x.PolygonGeometryLibrary.computeHierarchyPackedLength(t)+s.VertexFormat.packedLength+E.Ellipsoid.packedLength+2}g.fromPositions=function(e){return new g({polygonHierarchy:{positions:(e=l.defaultValue(e,l.defaultValue.EMPTY_OBJECT)).positions},vertexFormat:e.vertexFormat,stRotation:e.stRotation,ellipsoid:e.ellipsoid})},g.pack=function(e,t,a){return a=l.defaultValue(a,0),a=x.PolygonGeometryLibrary.packPolygonHierarchy(e._polygonHierarchy,t,a),E.Ellipsoid.pack(e._ellipsoid,t,a),a+=E.Ellipsoid.packedLength,s.VertexFormat.pack(e._vertexFormat,t,a),a+=s.VertexFormat.packedLength,t[a++]=e._stRotation,t[a]=e.packedLength,t};var b=E.Ellipsoid.clone(E.Ellipsoid.UNIT_SPHERE),j=new s.VertexFormat,U={polygonHierarchy:{}};return g.unpack=function(e,t,a){t=l.defaultValue(t,0);var n=x.PolygonGeometryLibrary.unpackPolygonHierarchy(e,t);t=n.startingIndex,delete n.startingIndex;var r=E.Ellipsoid.unpack(e,t,b);t+=E.Ellipsoid.packedLength;var o=s.VertexFormat.unpack(e,t,j);t+=s.VertexFormat.packedLength;var i=e[t++],t=e[t];return(a=!l.defined(a)?new g(U):a)._polygonHierarchy=n,a._ellipsoid=E.Ellipsoid.clone(r,a._ellipsoid),a._vertexFormat=s.VertexFormat.clone(o,a._vertexFormat),a._stRotation=i,a.packedLength=t,a},g.createGeometry=function(e){var t=e._vertexFormat,a=e._polygonHierarchy,n=e._stRotation,r=a.positions;if(!((r=h.arrayRemoveDuplicates(r,E.Cartesian3.equalsEpsilon,!0)).length<3)){var o=A,i=w,l=F,s=H,p=O;if(f.CoplanarPolygonGeometryLibrary.computeProjectTo2DArguments(r,G,s,p)){o=E.Cartesian3.cross(s,p,o);o=E.Cartesian3.normalize(o,o),E.Cartesian3.equalsEpsilon(G,E.Cartesian3.ZERO,V.CesiumMath.EPSILON6)||(c=e._ellipsoid.geodeticSurfaceNormal(G,Q),E.Cartesian3.dot(o,c)<0&&(o=E.Cartesian3.negate(o,o),s=E.Cartesian3.negate(s,s)));var c=f.CoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction(G,s,p),y=f.CoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction(G,s,p);t.tangent&&(i=E.Cartesian3.clone(s,i)),t.bitangent&&(l=E.Cartesian3.clone(p,l));var a=x.PolygonGeometryLibrary.polygonsFromHierarchy(a,c,!1),c=a.hierarchy,u=a.polygons;if(0!==c.length){for(var r=c[0].outerRing,a=L.BoundingSphere.fromPoints(r),m=x.PolygonGeometryLibrary.computeBoundingRectangle(o,y,r,n,P),d=[],g=0;g<u.length;g++){var b=new C.GeometryInstance({geometry:function(e,t,a,n,r,o,i,l){var s=e.positions,p=R.PolygonPipeline.triangulate(e.positions2D,e.holes);p.length<3&&(p=[0,1,2]),(e=k.IndexDatatype.createTypedArray(s.length,p.length)).set(p);var c=S;0!==n?(p=L.Quaternion.fromAxisAngle(o,n,z),c=L.Matrix3.fromQuaternion(p,c),(t.tangent||t.bitangent)&&(p=L.Quaternion.fromAxisAngle(o,-n,z),m=L.Matrix3.fromQuaternion(p,N),i=E.Cartesian3.normalize(L.Matrix3.multiplyByVector(m,i,i),i),t.bitangent&&(l=E.Cartesian3.normalize(E.Cartesian3.cross(o,i,l),l)))):c=L.Matrix3.clone(L.Matrix3.IDENTITY,c);var y=B;t.st&&(y.x=a.x,y.y=a.y);for(var u=s.length,m=3*u,d=new Float64Array(m),g=t.normal?new Float32Array(m):void 0,b=t.tangent?new Float32Array(m):void 0,h=t.bitangent?new Float32Array(m):void 0,f=t.st?new Float32Array(2*u):void 0,C=0,v=0,x=0,P=0,A=0,w=0;w<u;w++){var F,G=s[w];d[C++]=G.x,d[C++]=G.y,d[C++]=G.z,t.st&&(F=r(L.Matrix3.multiplyByVector(c,G,I),M),E.Cartesian2.subtract(F,y,F),G=V.CesiumMath.clamp(F.x/a.width,0,1),F=V.CesiumMath.clamp(F.y/a.height,0,1),f[A++]=G,f[A++]=F),t.normal&&(g[v++]=o.x,g[v++]=o.y,g[v++]=o.z),t.tangent&&(b[P++]=i.x,b[P++]=i.y,b[P++]=i.z),t.bitangent&&(h[x++]=l.x,h[x++]=l.y,h[x++]=l.z)}return m=new _.GeometryAttributes,t.position&&(m.position=new D.GeometryAttribute({componentDatatype:T.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:d})),t.normal&&(m.normal=new D.GeometryAttribute({componentDatatype:T.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:g})),t.tangent&&(m.tangent=new D.GeometryAttribute({componentDatatype:T.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:b})),t.bitangent&&(m.bitangent=new D.GeometryAttribute({componentDatatype:T.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:h})),t.st&&(m.st=new D.GeometryAttribute({componentDatatype:T.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:f})),new D.Geometry({attributes:m,indices:e,primitiveType:D.PrimitiveType.TRIANGLES})}(u[g],t,m,n,y,o,i,l)});d.push(b)}c=v.GeometryPipeline.combineInstances(d)[0];c.attributes.position.values=new Float64Array(c.attributes.position.values),c.indices=k.IndexDatatype.createTypedArray(c.attributes.position.values.length/3,c.indices);r=c.attributes;return t.position||delete r.position,new D.Geometry({attributes:r,indices:c.indices,primitiveType:c.primitiveType,boundingSphere:a})}}}},function(e,t){return l.defined(t)&&(e=g.unpack(e,t)),g.createGeometry(e)}});