Files
cad-Integration/text-to-cad-main/skills/cad-viewer/scripts/viewer/dist/assets/BufferGeometryUtils-xu92ooFc.js
T
2026-07-22 13:48:46 +08:00

3 lines
13 KiB
JavaScript

import{a as H,b as q,I as J,c as et,d as rt,B as nt,V as I,T as ot,e as j,f as st}from"./three.module-BB51Dq4E.js";function at(t,o,i=!0){if(!o||!o.isReady)throw new Error("BufferGeometryUtils: Initialized MikkTSpace library required.");if(!t.hasAttribute("position")||!t.hasAttribute("normal")||!t.hasAttribute("uv"))throw new Error('BufferGeometryUtils: Tangents require "position", "normal", and "uv" attributes.');function u(e){if(e.normalized||e.isInterleavedBufferAttribute){const s=new Float32Array(e.count*e.itemSize);for(let c=0,m=0;c<e.count;c++)s[m++]=e.getX(c),s[m++]=e.getY(c),e.itemSize>2&&(s[m++]=e.getZ(c));return s}return e.array instanceof Float32Array?e.array:new Float32Array(e.array)}const n=t.index?t.toNonIndexed():t,a=o.generateTangents(u(n.attributes.position),u(n.attributes.normal),u(n.attributes.uv));if(i)for(let e=3;e<a.length;e+=4)a[e]*=-1;return n.setAttribute("tangent",new H(a,4)),t!==n&&t.copy(n),t}function it(t,o=!1){const i=t[0].index!==null,u=new Set(Object.keys(t[0].attributes)),n=new Set(Object.keys(t[0].morphAttributes)),a={},e={},s=t[0].morphTargetsRelative,c=new nt;let m=0;for(let r=0;r<t.length;++r){const l=t[r];let w=0;if(i!==(l.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+r+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in l.attributes){if(!u.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+r+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;a[f]===void 0&&(a[f]=[]),a[f].push(l.attributes[f]),w++}if(w!==u.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+r+". Make sure all geometries have the same number of attributes."),null;if(s!==l.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+r+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in l.morphAttributes){if(!n.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+r+". .morphAttributes must be consistent throughout all geometries."),null;e[f]===void 0&&(e[f]=[]),e[f].push(l.morphAttributes[f])}if(o){let f;if(i)f=l.index.count;else if(l.attributes.position!==void 0)f=l.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+r+". The geometry must have either an index or a position attribute"),null;c.addGroup(m,f,r),m+=f}}if(i){let r=0;const l=[];for(let w=0;w<t.length;++w){const f=t[w].index;for(let g=0;g<f.count;++g)l.push(f.getX(g)+r);r+=t[w].attributes.position.count}c.setIndex(l)}for(const r in a){const l=O(a[r]);if(!l)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+r+" attribute."),null;c.setAttribute(r,l)}for(const r in e){const l=e[r][0].length;if(l===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[r]=[];for(let w=0;w<l;++w){const f=[];for(let d=0;d<e[r].length;++d)f.push(e[r][d][w]);const g=O(f);if(!g)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+r+" morphAttribute."),null;c.morphAttributes[r].push(g)}}return c}function O(t){let o,i,u,n=-1,a=0;for(let m=0;m<t.length;++m){const r=t[m];if(r.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(o===void 0&&(o=r.array.constructor),o!==r.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(i===void 0&&(i=r.itemSize),i!==r.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(u===void 0&&(u=r.normalized),u!==r.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(n===-1&&(n=r.gpuType),n!==r.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;a+=r.array.length}const e=new o(a);let s=0;for(let m=0;m<t.length;++m)e.set(t[m].array,s),s+=t[m].array.length;const c=new H(e,i,u);return n!==void 0&&(c.gpuType=n),c}function lt(t){return t.isInstancedInterleavedBufferAttribute||t.isInterleavedBufferAttribute?W(t):t.isInstancedBufferAttribute?new J().copy(t):new H().copy(t)}function ct(t){let o,i=0,u=0;for(let m=0,r=t.length;m<r;++m){const l=t[m];if(o===void 0&&(o=l.array.constructor),o!==l.array.constructor)return console.error("AttributeBuffers of different types cannot be interleaved"),null;i+=l.array.length,u+=l.itemSize}const n=new et(new o(i),u);let a=0;const e=[],s=["getX","getY","getZ","getW"],c=["setX","setY","setZ","setW"];for(let m=0,r=t.length;m<r;m++){const l=t[m],w=l.itemSize,f=l.count,g=new rt(n,w,a,l.normalized);e.push(g),a+=w;for(let d=0;d<f;d++)for(let E=0;E<w;E++)g[c[E]](d,l[s[E]](d))}return e}function W(t){const o=t.data.array.constructor,i=t.count,u=t.itemSize,n=t.normalized,a=new o(i*u);let e;t.isInstancedInterleavedBufferAttribute?e=new J(a,u,n,t.meshPerAttribute):e=new H(a,u,n);for(let s=0;s<i;s++)e.setX(s,t.getX(s)),u>=2&&e.setY(s,t.getY(s)),u>=3&&e.setZ(s,t.getZ(s)),u>=4&&e.setW(s,t.getW(s));return e}function ft(t){const o=t.attributes,i=t.morphTargets,u=new Map;for(const n in o){const a=o[n];a.isInterleavedBufferAttribute&&(u.has(a)||u.set(a,W(a)),o[n]=u.get(a))}for(const n in i){const a=i[n];a.isInterleavedBufferAttribute&&(u.has(a)||u.set(a,W(a)),i[n]=u.get(a))}}function mt(t){let o=0;for(const u in t.attributes){const n=t.getAttribute(u);o+=n.count*n.itemSize*n.array.BYTES_PER_ELEMENT}const i=t.getIndex();return o+=i?i.count*i.itemSize*i.array.BYTES_PER_ELEMENT:0,o}function dt(t,o=1e-4){o=Math.max(o,Number.EPSILON);const i={},u=t.getIndex(),n=t.getAttribute("position"),a=u?u.count:n.count;let e=0;const s=Object.keys(t.attributes),c={},m={},r=[],l=["getX","getY","getZ","getW"],w=["setX","setY","setZ","setW"];for(let b=0,B=s.length;b<B;b++){const A=s[b],p=t.attributes[A];c[A]=new H(new p.array.constructor(p.count*p.itemSize),p.itemSize,p.normalized);const z=t.morphAttributes[A];z&&(m[A]=new H(new z.array.constructor(z.count*z.itemSize),z.itemSize,z.normalized))}const f=o*.5,g=Math.log10(1/o),d=Math.pow(10,g),E=f*d;for(let b=0;b<a;b++){const B=u?u.getX(b):b;let A="";for(let p=0,z=s.length;p<z;p++){const y=s[p],h=t.getAttribute(y),T=h.itemSize;for(let G=0;G<T;G++)A+=`${~~(h[l[G]](B)*d+E)},`}if(A in i)r.push(i[A]);else{for(let p=0,z=s.length;p<z;p++){const y=s[p],h=t.getAttribute(y),T=t.morphAttributes[y],G=h.itemSize,U=c[y],M=m[y];for(let v=0;v<G;v++){const S=l[v],V=w[v];if(U[V](e,h[S](B)),T)for(let R=0,P=T.length;R<P;R++)M[R][V](e,T[R][S](B))}}i[A]=e,r.push(e),e++}}const x=t.clone();for(const b in t.attributes){const B=c[b];if(x.setAttribute(b,new H(B.array.slice(0,e*B.itemSize),B.itemSize,B.normalized)),b in m)for(let A=0;A<m[b].length;A++){const p=m[b][A];x.morphAttributes[b][A]=new H(p.array.slice(0,e*p.itemSize),p.itemSize,p.normalized)}}return x.setIndex(r),x}function ht(t,o){if(o===ot)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),t;if(o===j||o===st){let i=t.getIndex();if(i===null){const e=[],s=t.getAttribute("position");if(s!==void 0){for(let c=0;c<s.count;c++)e.push(c);t.setIndex(e),i=t.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t}const u=i.count-2,n=[];if(o===j)for(let e=1;e<=u;e++)n.push(i.getX(0)),n.push(i.getX(e)),n.push(i.getX(e+1));else for(let e=0;e<u;e++)e%2===0?(n.push(i.getX(e)),n.push(i.getX(e+1)),n.push(i.getX(e+2))):(n.push(i.getX(e+2)),n.push(i.getX(e+1)),n.push(i.getX(e)));n.length/3!==u&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const a=t.clone();return a.setIndex(n),a.clearGroups(),a}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",o),t}function pt(t){const o=new I,i=new I,u=new I,n=new I,a=new I,e=new I,s=new I,c=new I,m=new I;function r(F,Z,C,Q,k,_,D,X){o.fromBufferAttribute(Z,k),i.fromBufferAttribute(Z,_),u.fromBufferAttribute(Z,D);const $=F.morphTargetInfluences;if(C&&$){s.set(0,0,0),c.set(0,0,0),m.set(0,0,0);for(let Y=0,tt=C.length;Y<tt;Y++){const N=$[Y],L=C[Y];N!==0&&(n.fromBufferAttribute(L,k),a.fromBufferAttribute(L,_),e.fromBufferAttribute(L,D),Q?(s.addScaledVector(n,N),c.addScaledVector(a,N),m.addScaledVector(e,N)):(s.addScaledVector(n.sub(o),N),c.addScaledVector(a.sub(i),N),m.addScaledVector(e.sub(u),N)))}o.add(s),i.add(c),u.add(m)}F.isSkinnedMesh&&(F.applyBoneTransform(k,o),F.applyBoneTransform(_,i),F.applyBoneTransform(D,u)),X[k*3+0]=o.x,X[k*3+1]=o.y,X[k*3+2]=o.z,X[_*3+0]=i.x,X[_*3+1]=i.y,X[_*3+2]=i.z,X[D*3+0]=u.x,X[D*3+1]=u.y,X[D*3+2]=u.z}const l=t.geometry,w=t.material;let f,g,d;const E=l.index,x=l.attributes.position,b=l.morphAttributes.position,B=l.morphTargetsRelative,A=l.attributes.normal,p=l.morphAttributes.position,z=l.groups,y=l.drawRange;let h,T,G,U,M,v,S;const V=new Float32Array(x.count*x.itemSize),R=new Float32Array(A.count*A.itemSize);if(E!==null)if(Array.isArray(w))for(h=0,G=z.length;h<G;h++)for(M=z[h],v=Math.max(M.start,y.start),S=Math.min(M.start+M.count,y.start+y.count),T=v,U=S;T<U;T+=3)f=E.getX(T),g=E.getX(T+1),d=E.getX(T+2),r(t,x,b,B,f,g,d,V),r(t,A,p,B,f,g,d,R);else for(v=Math.max(0,y.start),S=Math.min(E.count,y.start+y.count),h=v,G=S;h<G;h+=3)f=E.getX(h),g=E.getX(h+1),d=E.getX(h+2),r(t,x,b,B,f,g,d,V),r(t,A,p,B,f,g,d,R);else if(Array.isArray(w))for(h=0,G=z.length;h<G;h++)for(M=z[h],v=Math.max(M.start,y.start),S=Math.min(M.start+M.count,y.start+y.count),T=v,U=S;T<U;T+=3)f=T,g=T+1,d=T+2,r(t,x,b,B,f,g,d,V),r(t,A,p,B,f,g,d,R);else for(v=Math.max(0,y.start),S=Math.min(x.count,y.start+y.count),h=v,G=S;h<G;h+=3)f=h,g=h+1,d=h+2,r(t,x,b,B,f,g,d,V),r(t,A,p,B,f,g,d,R);const P=new q(V,3),K=new q(R,3);return{positionAttribute:x,normalAttribute:A,morphedPositionAttribute:P,morphedNormalAttribute:K}}function gt(t){if(t.groups.length===0)return console.warn("THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge."),t;let o=t.groups;if(o=o.sort((e,s)=>e.materialIndex!==s.materialIndex?e.materialIndex-s.materialIndex:e.start-s.start),t.getIndex()===null){const e=t.getAttribute("position"),s=[];for(let c=0;c<e.count;c+=3)s.push(c,c+1,c+2);t.setIndex(s)}const i=t.getIndex(),u=[];for(let e=0;e<o.length;e++){const s=o[e],c=s.start,m=c+s.count;for(let r=c;r<m;r++)u.push(i.getX(r))}t.dispose(),t.setIndex(u);let n=0;for(let e=0;e<o.length;e++){const s=o[e];s.start=n,n+=s.count}let a=o[0];t.groups=[a];for(let e=1;e<o.length;e++){const s=o[e];a.materialIndex===s.materialIndex?a.count+=s.count:(a=s,t.groups.push(a))}return t}function bt(t,o=Math.PI/3){const i=Math.cos(o),u=(1+1e-10)*100,n=[new I,new I,new I],a=new I,e=new I,s=new I,c=new I;function m(d){const E=~~(d.x*u),x=~~(d.y*u),b=~~(d.z*u);return`${E},${x},${b}`}const r=t.index?t.toNonIndexed():t,l=r.attributes.position,w={};for(let d=0,E=l.count/3;d<E;d++){const x=3*d,b=n[0].fromBufferAttribute(l,x+0),B=n[1].fromBufferAttribute(l,x+1),A=n[2].fromBufferAttribute(l,x+2);a.subVectors(A,B),e.subVectors(b,B);const p=new I().crossVectors(a,e).normalize();for(let z=0;z<3;z++){const y=n[z],h=m(y);h in w||(w[h]=[]),w[h].push(p)}}const f=new Float32Array(l.count*3),g=new H(f,3,!1);for(let d=0,E=l.count/3;d<E;d++){const x=3*d,b=n[0].fromBufferAttribute(l,x+0),B=n[1].fromBufferAttribute(l,x+1),A=n[2].fromBufferAttribute(l,x+2);a.subVectors(A,B),e.subVectors(b,B),s.crossVectors(a,e).normalize();for(let p=0;p<3;p++){const z=n[p],y=m(z),h=w[y];c.set(0,0,0);for(let T=0,G=h.length;T<G;T++){const U=h[T];s.dot(U)>i&&c.add(U)}c.normalize(),g.setXYZ(x+p,c.x,c.y,c.z)}}return r.setAttribute("normal",g),r}function At(t,o=!1){return console.warn("THREE.BufferGeometryUtils: mergeBufferGeometries() has been renamed to mergeGeometries()."),it(t,o)}function wt(t){return console.warn("THREE.BufferGeometryUtils: mergeBufferAttributes() has been renamed to mergeAttributes()."),O(t)}export{at as computeMikkTSpaceTangents,pt as computeMorphedAttributes,lt as deepCloneAttribute,W as deinterleaveAttribute,ft as deinterleaveGeometry,mt as estimateBytesUsed,ct as interleaveAttributes,O as mergeAttributes,wt as mergeBufferAttributes,At as mergeBufferGeometries,it as mergeGeometries,gt as mergeGroups,dt as mergeVertices,bt as toCreasedNormals,ht as toTrianglesDrawMode};
//# sourceMappingURL=BufferGeometryUtils-xu92ooFc.js.map