bmh_cesium/public/lib/cesiumjs/CesiumUnminified/Workers/createCoplanarPolygonGeometry.js
2025-03-10 07:23:50 +08:00

2 lines
6.3 KiB
JavaScript

/* 2020-9-22 15:23:25 | 版权所有 军懋国兴 */
define(["./when-cbf8cd21","./Check-35e1a91d","./Math-69007a69","./Cartesian2-43e3a3be","./Transforms-2d1ac5ec","./RuntimeError-f4c64df1","./WebGLConstants-95ceb4e9","./ComponentDatatype-607c9a0c","./GeometryAttribute-2303bbfb","./GeometryAttributes-90846c5f","./AttributeCompression-ea810287","./GeometryPipeline-1ea64cde","./EncodedCartesian3-29a09d7b","./IndexDatatype-79bb407c","./IntersectionTests-459f6f08","./Plane-46b5436f","./VertexFormat-fe64931e","./GeometryInstance-6264cc0f","./arrayRemoveDuplicates-d96adeb6","./BoundingRectangle-943d30f6","./EllipsoidTangentPlane-b5927ee3","./OrientedBoundingBox-5e0b7a7c","./CoplanarPolygonGeometryLibrary-77345aa0","./ArcType-2b58731c","./EllipsoidRhumbLine-357c11e7","./PolygonPipeline-2ee85025","./PolygonGeometryLibrary-bcb33f68"],function(l,p,V,R,I,e,t,M,H,B,a,w,n,O,r,o,c,A,F,i,s,y,G,u,m,z,L){"use strict";var S=new R.Cartesian3,E=new i.BoundingRectangle,N=new R.Cartesian2,Q=new R.Cartesian2,k=new R.Cartesian3,T=new R.Cartesian3,D=new R.Cartesian3,_=new R.Cartesian3,j=new R.Cartesian3,U=new R.Cartesian3,Y=new I.Quaternion,q=new I.Matrix3,J=new I.Matrix3,W=new R.Cartesian3;function d(e){var t=(e=l.defaultValue(e,l.defaultValue.EMPTY_OBJECT)).polygonHierarchy;p.Check.defined("options.polygonHierarchy",t);var a=l.defaultValue(e.vertexFormat,c.VertexFormat.DEFAULT);this._vertexFormat=c.VertexFormat.clone(a),this._polygonHierarchy=t,this._stRotation=l.defaultValue(e.stRotation,0),this._ellipsoid=R.Ellipsoid.clone(l.defaultValue(e.ellipsoid,R.Ellipsoid.WGS84)),this._workerName="createCoplanarPolygonGeometry",this.packedLength=L.PolygonGeometryLibrary.computeHierarchyPackedLength(t)+c.VertexFormat.packedLength+R.Ellipsoid.packedLength+2}d.fromPositions=function(e){return e=l.defaultValue(e,l.defaultValue.EMPTY_OBJECT),p.Check.defined("options.positions",e.positions),new d({polygonHierarchy:{positions:e.positions},vertexFormat:e.vertexFormat,stRotation:e.stRotation,ellipsoid:e.ellipsoid})},d.pack=function(e,t,a){return p.Check.typeOf.object("value",e),p.Check.defined("array",t),a=l.defaultValue(a,0),a=L.PolygonGeometryLibrary.packPolygonHierarchy(e._polygonHierarchy,t,a),R.Ellipsoid.pack(e._ellipsoid,t,a),a+=R.Ellipsoid.packedLength,c.VertexFormat.pack(e._vertexFormat,t,a),a+=c.VertexFormat.packedLength,t[a++]=e._stRotation,t[a]=e.packedLength,t};var g=R.Ellipsoid.clone(R.Ellipsoid.UNIT_SPHERE),b=new c.VertexFormat,h={polygonHierarchy:{}};return d.unpack=function(e,t,a){p.Check.defined("array",e),t=l.defaultValue(t,0);var n=L.PolygonGeometryLibrary.unpackPolygonHierarchy(e,t);t=n.startingIndex,delete n.startingIndex;var r=R.Ellipsoid.unpack(e,t,g);t+=R.Ellipsoid.packedLength;var o=c.VertexFormat.unpack(e,t,b);t+=c.VertexFormat.packedLength;var i=e[t++],s=e[t];return l.defined(a)||(a=new d(h)),a._polygonHierarchy=n,a._ellipsoid=R.Ellipsoid.clone(r,a._ellipsoid),a._vertexFormat=c.VertexFormat.clone(o,a._vertexFormat),a._stRotation=i,a.packedLength=s,a},d.createGeometry=function(e){var t=e._vertexFormat,a=e._polygonHierarchy,n=e._stRotation,r=a.positions;if(!((r=F.arrayRemoveDuplicates(r,R.Cartesian3.equalsEpsilon,!0)).length<3)){var o=k,i=T,s=D,l=j,p=U;if(G.CoplanarPolygonGeometryLibrary.computeProjectTo2DArguments(r,_,l,p)){var c,o=R.Cartesian3.cross(l,p,o);o=R.Cartesian3.normalize(o,o),R.Cartesian3.equalsEpsilon(_,R.Cartesian3.ZERO,V.CesiumMath.EPSILON6)||(c=e._ellipsoid.geodeticSurfaceNormal(_,W),R.Cartesian3.dot(o,c)<0&&(o=R.Cartesian3.negate(o,o),l=R.Cartesian3.negate(l,l)));var y=G.CoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction(_,l,p),u=G.CoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction(_,l,p);t.tangent&&(i=R.Cartesian3.clone(l,i)),t.bitangent&&(s=R.Cartesian3.clone(p,s));var m=L.PolygonGeometryLibrary.polygonsFromHierarchy(a,y,!1),d=m.hierarchy,g=m.polygons;if(0!==d.length){r=d[0].outerRing;for(var b=I.BoundingSphere.fromPoints(r),h=L.PolygonGeometryLibrary.computeBoundingRectangle(o,u,r,n,E),v=[],f=0;f<g.length;f++){var C=new A.GeometryInstance({geometry:function(e,t,a,n,r,o,i,s){var l=e.positions,p=z.PolygonPipeline.triangulate(e.positions2D,e.holes);p.length<3&&(p=[0,1,2]);var c=O.IndexDatatype.createTypedArray(l.length,p.length);c.set(p);var y,u,m=q;0!==n?(y=I.Quaternion.fromAxisAngle(o,n,Y),m=I.Matrix3.fromQuaternion(y,m),(t.tangent||t.bitangent)&&(y=I.Quaternion.fromAxisAngle(o,-n,Y),u=I.Matrix3.fromQuaternion(y,J),i=R.Cartesian3.normalize(I.Matrix3.multiplyByVector(u,i,i),i),t.bitangent&&(s=R.Cartesian3.normalize(R.Cartesian3.cross(o,i,s),s)))):m=I.Matrix3.clone(I.Matrix3.IDENTITY,m);var d=Q;t.st&&(d.x=a.x,d.y=a.y);for(var g=l.length,b=3*g,h=new Float64Array(b),v=t.normal?new Float32Array(b):void 0,f=t.tangent?new Float32Array(b):void 0,C=t.bitangent?new Float32Array(b):void 0,x=t.st?new Float32Array(2*g):void 0,P=0,w=0,A=0,F=0,G=0,L=0;L<g;L++){var E,k,T,D=l[L];h[P++]=D.x,h[P++]=D.y,h[P++]=D.z,t.st&&(E=r(I.Matrix3.multiplyByVector(m,D,S),N),R.Cartesian2.subtract(E,d,E),k=V.CesiumMath.clamp(E.x/a.width,0,1),T=V.CesiumMath.clamp(E.y/a.height,0,1),x[G++]=k,x[G++]=T),t.normal&&(v[w++]=o.x,v[w++]=o.y,v[w++]=o.z),t.tangent&&(f[F++]=i.x,f[F++]=i.y,f[F++]=i.z),t.bitangent&&(C[A++]=s.x,C[A++]=s.y,C[A++]=s.z)}var _=new B.GeometryAttributes;return t.position&&(_.position=new H.GeometryAttribute({componentDatatype:M.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:h})),t.normal&&(_.normal=new H.GeometryAttribute({componentDatatype:M.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:v})),t.tangent&&(_.tangent=new H.GeometryAttribute({componentDatatype:M.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:f})),t.bitangent&&(_.bitangent=new H.GeometryAttribute({componentDatatype:M.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:C})),t.st&&(_.st=new H.GeometryAttribute({componentDatatype:M.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:x})),new H.Geometry({attributes:_,indices:c,primitiveType:H.PrimitiveType.TRIANGLES})}(g[f],t,h,n,u,o,i,s)});v.push(C)}var x=w.GeometryPipeline.combineInstances(v)[0];x.attributes.position.values=new Float64Array(x.attributes.position.values),x.indices=O.IndexDatatype.createTypedArray(x.attributes.position.values.length/3,x.indices);var P=x.attributes;return t.position||delete P.position,new H.Geometry({attributes:P,indices:x.indices,primitiveType:x.primitiveType,boundingSphere:b})}}}},function(e,t){return l.defined(t)&&(e=d.unpack(e,t)),d.createGeometry(e)}});