Files
td_official/public/Cesium/Workers/createRectangleGeometry.js

26 lines
16 KiB
JavaScript
Raw Permalink Normal View History

2025-06-18 19:56:54 +08:00
/**
* @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(["./defaultValue-50f7432c","./Matrix2-cf4c6e69","./Transforms-c9e418cb","./ComponentDatatype-9b23164a","./GeometryAttribute-b84ffce6","./GeometryAttributes-8bab1b25","./GeometryInstance-a6a77e5a","./GeometryOffsetAttribute-490bc2c9","./GeometryPipeline-9c11a3d1","./IndexDatatype-ceed713e","./PolygonPipeline-13f0bfa4","./RectangleGeometryLibrary-9f12e096","./VertexFormat-fa0c27e8","./RuntimeError-48e1f06d","./combine-8462e002","./WebGLConstants-58abc51a","./AttributeCompression-b4dfdf5f","./EncodedCartesian3-0b8c686b","./IntersectionTests-d662a125","./Plane-b9f0711b","./EllipsoidRhumbLine-0cc30625"],(function(t,e,n,a,o,r,i,s,l,u,c,m,p,d,g,y,f,h,b,_,A){"use strict";const x=new e.Cartesian3,w=new e.Cartesian3,C=new e.Cartesian3,v=new e.Cartesian3,R=new e.Rectangle,E=new e.Cartesian2,G=new n.BoundingSphere,F=new n.BoundingSphere;function P(t,e){const n=new o.Geometry({attributes:new r.GeometryAttributes,primitiveType:o.PrimitiveType.TRIANGLES});return n.attributes.position=new o.GeometryAttribute({componentDatatype:a.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:e.positions}),t.normal&&(n.attributes.normal=new o.GeometryAttribute({componentDatatype:a.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.normals})),t.tangent&&(n.attributes.tangent=new o.GeometryAttribute({componentDatatype:a.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.tangents})),t.bitangent&&(n.attributes.bitangent=new o.GeometryAttribute({componentDatatype:a.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:e.bitangents})),n}const V=new e.Cartesian3,L=new e.Cartesian3;function D(t,n){const r=t._vertexFormat,i=t._ellipsoid,s=n.height,l=n.width,c=n.northCap,p=n.southCap;let d=0,g=s,y=s,f=0;c&&(d=1,y-=1,f+=1),p&&(g-=1,y-=1,f+=1),f+=l*y;const h=r.position?new Float64Array(3*f):void 0,b=r.st?new Float32Array(2*f):void 0;let _=0,A=0;const R=x,G=E;let F=Number.MAX_VALUE,V=Number.MAX_VALUE,L=-Number.MAX_VALUE,D=-Number.MAX_VALUE;for(let t=d;t<g;++t)for(let e=0;e<l;++e)m.RectangleGeometryLibrary.computePosition(n,i,r.st,t,e,R,G),h[_++]=R.x,h[_++]=R.y,h[_++]=R.z,r.st&&(b[A++]=G.x,b[A++]=G.y,F=Math.min(F,G.x),V=Math.min(V,G.y),L=Math.max(L,G.x),D=Math.max(D,G.y));if(c&&(m.RectangleGeometryLibrary.computePosition(n,i,r.st,0,0,R,G),h[_++]=R.x,h[_++]=R.y,h[_++]=R.z,r.st&&(b[A++]=G.x,b[A++]=G.y,F=G.x,V=G.y,L=G.x,D=G.y)),p&&(m.RectangleGeometryLibrary.computePosition(n,i,r.st,s-1,0,R,G),h[_++]=R.x,h[_++]=R.y,h[_]=R.z,r.st&&(b[A++]=G.x,b[A]=G.y,F=Math.min(F,G.x),V=Math.min(V,G.y),L=Math.max(L,G.x),D=Math.max(D,G.y))),r.st&&(F<0||V<0||L>1||D>1))for(let t=0;t<b.length;t+=2)b[t]=(b[t]-F)/(L-F),b[t+1]=(b[t+1]-V)/(D-V);const M=function(t,n,a,o){const r=t.length,i=n.normal?new Float32Array(r):void 0,s=n.tangent?new Float32Array(r):void 0,l=n.bitangent?new Float32Array(r):void 0;let u=0;const c=v,m=C;let p=w;if(n.normal||n.tangent||n.bitangent)for(let d=0;d<r;d+=3){const r=e.Cartesian3.fromArray(t,d,x),g=u+1,y=u+2;p=a.geodeticSurfaceNormal(r,p),(n.tangent||n.bitangent)&&(e.Cartesian3.cross(e.Cartesian3.UNIT_Z,p,m),e.Matrix3.multiplyByVector(o,m,m),e.Cartesian3.normalize(m,m),n.bitangent&&e.Cartesian3.normalize(e.Cartesian3.cross(p,m,c),c)),n.normal&&(i[u]=p.x,i[g]=p.y,i[y]=p.z),n.tangent&&(s[u]=m.x,s[g]=m.y,s[y]=m.z),n.bitangent&&(l[u]=c.x,l[g]=c.y,l[y]=c.z),u+=3}return P(n,{positions:t,normals:i,tangents:s,bitangents:l})}(h,r,i,n.tangentRotationMatrix);let T=6*(l-1)*(y-1);c&&(T+=3*(l-1)),p&&(T+=3*(l-1));const O=u.IndexDatatype.createTypedArray(f,T);let N,S=0,I=0;for(N=0;N<y-1;++N){for(let t=0;t<l-1;++t){const t=S,e=t+l,n=e+1,a=t+1;O[I++]=t,O[I++]=e,O[I++]=a,O[I++]=a,O[I++]=e,O[I++]=n,++S}++S}if(c||p){let t=f-1;const e=f-1;let n,a;if(c&&p&&(t=f-2),S=0,c)for(N=0;N<l-1;N++)n=S,a=n+1,O[I++]=t,O[I++]=n,O[I++]=a,++S;if(p)for(S=(y-1)*l,N=0;N<l-1;N++)n=S,a=n+1,O[I++]=n,O[I++]=e,O[I++]=a,++S}return M.indices=O,r.st&&(M.attributes.st=new o.GeometryAttribute({componentDatatype:a.ComponentDatatype.FLOAT,componentsPerAttribute:2,values:b})),M}function M(t,e,n,a,o){return t[e++]=a[n],t[e++]=a[n+1],t[e++]=a[n+2],t[e++]=o[n],t[e++]=o[n+1],t[e]=o[n+2],t}