Files
sdk4.0/static/Cesium/Workers/createCoplanarPolygonGeometry.js
2025-07-03 13:54:01 +08:00

26 lines
7.8 KiB
JavaScript

/**
* @license
* Cesium - https://github.com/CesiumGS/cesium
* Version 1.98
*
* Copyright 2011-2022 Cesium Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Columbus View (Pat. Pend.)
*
* Portions licensed separately.
* See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
*/
define(["./arrayRemoveDuplicates-fd3a3f4e","./BoundingRectangle-af4243d8","./Transforms-c9e418cb","./Matrix2-cf4c6e69","./ComponentDatatype-9b23164a","./CoplanarPolygonGeometryLibrary-8aced7d2","./defaultValue-50f7432c","./GeometryAttribute-b84ffce6","./GeometryAttributes-8bab1b25","./GeometryInstance-a6a77e5a","./GeometryPipeline-9c11a3d1","./IndexDatatype-ceed713e","./PolygonGeometryLibrary-7558e2c7","./PolygonPipeline-13f0bfa4","./VertexFormat-fa0c27e8","./combine-8462e002","./RuntimeError-48e1f06d","./WebGLConstants-58abc51a","./OrientedBoundingBox-ac687fc0","./EllipsoidTangentPlane-2597ceda","./AxisAlignedBoundingBox-ae9b3d82","./IntersectionTests-d662a125","./Plane-b9f0711b","./AttributeCompression-b4dfdf5f","./EncodedCartesian3-0b8c686b","./ArcType-24f44850","./EllipsoidRhumbLine-0cc30625"],(function(e,t,n,o,a,r,i,s,l,c,y,p,u,d,m,g,f,b,C,h,x,P,A,L,w,G,F){"use strict";const v=new o.Cartesian3,E=new t.BoundingRectangle,_=new o.Cartesian2,T=new o.Cartesian2,k=new o.Cartesian3,D=new o.Cartesian3,V=new o.Cartesian3,R=new o.Cartesian3,H=new o.Cartesian3,I=new o.Cartesian3,M=new n.Quaternion,B=new o.Matrix3,O=new o.Matrix3,z=new o.Cartesian3;function S(e,t,r,c,y,u,m,g,f){const b=e.positions;let C=d.PolygonPipeline.triangulate(e.positions2D,e.holes);C.length<3&&(C=[0,1,2]);const h=p.IndexDatatype.createTypedArray(b.length,C.length);h.set(C);let x=B;if(0!==c){let e=n.Quaternion.fromAxisAngle(m,c,M);if(x=o.Matrix3.fromQuaternion(e,x),t.tangent||t.bitangent){e=n.Quaternion.fromAxisAngle(m,-c,M);const a=o.Matrix3.fromQuaternion(e,O);g=o.Cartesian3.normalize(o.Matrix3.multiplyByVector(a,g,g),g),t.bitangent&&(f=o.Cartesian3.normalize(o.Cartesian3.cross(m,g,f),f))}}else x=o.Matrix3.clone(o.Matrix3.IDENTITY,x);const P=T;t.st&&(P.x=r.x,P.y=r.y);const A=b.length,L=3*A,w=new Float64Array(L),G=t.normal?new Float32Array(L):void 0,F=t.tangent?new Float32Array(L):void 0,E=t.bitangent?new Float32Array(L):void 0,k=t.st?new Float32Array(2*A):void 0;let D=0,V=0,R=0,H=0,I=0;for(let e=0;e<A;e++){const n=b[e];if(w[D++]=n.x,w[D++]=n.y,w[D++]=n.z,t.st)if(i.defined(y)&&y.positions.length===A)k[I++]=y.positions[e].x,k[I++]=y.positions[e].y;else{const e=u(o.Matrix3.multiplyByVector(x,n,v),_);o.Cartesian2.subtract(e,P,e);const t=a.CesiumMath.clamp(e.x/r.width,0,1),i=a.CesiumMath.clamp(e.y/r.height,0,1);k[I++]=t,k[I++]=i}t.normal&&(G[V++]=m.x,G[V++]=m.y,G[V++]=m.z),t.tangent&&(F[H++]=g.x,F[H++]=g.y,F[H++]=g.z),t.bitangent&&(E[R++]=f.x,E[R++]=f.y,E[R++]=f.z)}const z=new l.GeometryAttributes;return t.position&&(z.position=new s.GeometryAttribute({componentDatatype:a.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:w})),t.normal&&(z.normal=new s.GeometryAttribute({componentDatatype:a.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:G})),t.tangent&&(z.tangent=new s.GeometryAttribute({componentDatatype:a.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:F})),t.bitangent&&(z.bitangent=new s.GeometryAttribute({componentDatatype:a.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:E})),t.st&&(z.st=new s.GeometryAttribute({componentDatatype:a.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:k})),new s.Geometry({attributes:z,indices:h,primitiveType:s.PrimitiveType.TRIANGLES})}function N(e){const t=(e=i.defaultValue(e,i.defaultValue.EMPTY_OBJECT)).polygonHierarchy,n=e.textureCoordinates,a=i.defaultValue(e.vertexFormat,m.VertexFormat.DEFAULT);this._vertexFormat=m.VertexFormat.clone(a),this._polygonHierarchy=t,this._stRotation=i.defaultValue(e.stRotation,0),this._ellipsoid=o.Ellipsoid.clone(i.defaultValue(e.ellipsoid,o.Ellipsoid.WGS84)),this._workerName="createCoplanarPolygonGeometry",this._textureCoordinates=n,this.packedLength=u.PolygonGeometryLibrary.computeHierarchyPackedLength(t,o.Cartesian3)+m.VertexFormat.packedLength+o.Ellipsoid.packedLength+(i.defined(n)?u.PolygonGeometryLibrary.computeHierarchyPackedLength(n,o.Cartesian2):1)+2}N.fromPositions=function(e){return new N({polygonHierarchy:{positions:(e=i.defaultValue(e,i.defaultValue.EMPTY_OBJECT)).positions},vertexFormat:e.vertexFormat,stRotation:e.stRotation,ellipsoid:e.ellipsoid,textureCoordinates:e.textureCoordinates})},N.pack=function(e,t,n){return n=i.defaultValue(n,0),n=u.PolygonGeometryLibrary.packPolygonHierarchy(e._polygonHierarchy,t,n,o.Cartesian3),o.Ellipsoid.pack(e._ellipsoid,t,n),n+=o.Ellipsoid.packedLength,m.VertexFormat.pack(e._vertexFormat,t,n),n+=m.VertexFormat.packedLength,t[n++]=e._stRotation,i.defined(e._textureCoordinates)?n=u.PolygonGeometryLibrary.packPolygonHierarchy(e._textureCoordinates,t,n,o.Cartesian2):t[n++]=-1,t[n++]=e.packedLength,t};const Q=o.Ellipsoid.clone(o.Ellipsoid.UNIT_SPHERE),j=new m.VertexFormat,U={polygonHierarchy:{}};return N.unpack=function(e,t,n){t=i.defaultValue(t,0);const a=u.PolygonGeometryLibrary.unpackPolygonHierarchy(e,t,o.Cartesian3);t=a.startingIndex,delete a.startingIndex;const r=o.Ellipsoid.unpack(e,t,Q);t+=o.Ellipsoid.packedLength;const s=m.VertexFormat.unpack(e,t,j);t+=m.VertexFormat.packedLength;const l=e[t++],c=-1===e[t]?void 0:u.PolygonGeometryLibrary.unpackPolygonHierarchy(e,t,o.Cartesian2);i.defined(c)?(t=c.startingIndex,delete c.startingIndex):t++;const y=e[t++];return i.defined(n)||(n=new N(U)),n._polygonHierarchy=a,n._ellipsoid=o.Ellipsoid.clone(r,n._ellipsoid),n._vertexFormat=m.VertexFormat.clone(s,n._vertexFormat),n._stRotation=l,n._textureCoordinates=c,n.packedLength=y,n},N.createGeometry=function(t){const l=t._vertexFormat,d=t._polygonHierarchy,m=t._stRotation,g=t._textureCoordinates,f=i.defined(g);let b=d.positions;if(b=e.arrayRemoveDuplicates(b,o.Cartesian3.equalsEpsilon,!0),b.length<3)return;let C=k,h=D,x=V,P=H;const A=I;if(!r.CoplanarPolygonGeometryLibrary.computeProjectTo2DArguments(b,R,P,A))return;if(C=o.Cartesian3.cross(P,A,C),C=o.Cartesian3.normalize(C,C),!o.Cartesian3.equalsEpsilon(R,o.Cartesian3.ZERO,a.CesiumMath.EPSILON6)){const e=t._ellipsoid.geodeticSurfaceNormal(R,z);o.Cartesian3.dot(C,e)<0&&(C=o.Cartesian3.negate(C,C),P=o.Cartesian3.negate(P,P))}const L=r.CoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction(R,P,A),w=r.CoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction(R,P,A);l.tangent&&(h=o.Cartesian3.clone(P,h)),l.bitangent&&(x=o.Cartesian3.clone(A,x));const G=u.PolygonGeometryLibrary.polygonsFromHierarchy(d,f,L,!1),F=G.hierarchy,v=G.polygons,_=f?u.PolygonGeometryLibrary.polygonsFromHierarchy(g,!0,(function(e){return e}),!1).polygons:void 0;if(0===F.length)return;b=F[0].outerRing;const T=n.BoundingSphere.fromPoints(b),M=u.PolygonGeometryLibrary.computeBoundingRectangle(C,w,b,m,E),B=[];for(let e=0;e<v.length;e++){const t=new c.GeometryInstance({geometry:S(v[e],l,M,m,f?_[e]:void 0,w,C,h,x)});B.push(t)}const O=y.GeometryPipeline.combineInstances(B)[0];O.attributes.position.values=new Float64Array(O.attributes.position.values),O.indices=p.IndexDatatype.createTypedArray(O.attributes.position.values.length/3,O.indices);const N=O.attributes;return l.position||delete N.position,new s.Geometry({attributes:N,indices:O.indices,primitiveType:O.primitiveType,boundingSphere:T})},function(e,t){return i.defined(t)&&(e=N.unpack(e,t)),N.createGeometry(e)}}));