1 |
- import{n as It}from"./deduplicate.b87c02b8.js";import{T as _}from"./InterleavedLayout.7e8c844d.js";import{O as u}from"./VertexAttribute.42396f25.js";import{C as D}from"./enums.2d9e6f64.js";import{t as At}from"./VertexElementDescriptor.1fdca6da.js";import{dj as nt,fq as ht,fr as Ot,G as W,fs as ot,ft as z,fu as St,fv as wt,fw as lt,fx as rt,fy as ut,fz as Tt,E,b7 as Et,fA as vt}from"./index.6c049565.js";function Y(t,e=0){const o=t.stride;return t.fieldNames.filter(s=>{const r=t.fields.get(s).optional;return!(r&&r.glPadding)}).map(s=>{const r=t.fields.get(s),c=r.constructor.ElementCount,g=$t(r.constructor.ElementType),a=r.offset,p=!(!r.optional||!r.optional.glNormalized);return new At(s,c,g,a,o,p,e)})}function $t(t){const e=Pt[t];if(e)return e;throw new Error("BufferType not supported in WebGL")}const Pt={u8:D.UNSIGNED_BYTE,u16:D.UNSIGNED_SHORT,u32:D.UNSIGNED_INT,i8:D.BYTE,i16:D.SHORT,i32:D.INT,f32:D.FLOAT},yt=_().vec3f(u.POSITION).u16(u.COMPONENTINDEX).u16(u.U16PADDING),Dt=_().vec2u8(u.SIDENESS);Y(Dt);const gt=_().vec3f(u.POSITION0).vec3f(u.POSITION1).u16(u.COMPONENTINDEX).u8(u.VARIANTOFFSET,{glNormalized:!0}).u8(u.VARIANTSTROKE).u8(u.VARIANTEXTENSION,{glNormalized:!0}).u8(u.U8PADDING,{glPadding:!0}).u16(u.U16PADDING,{glPadding:!0}),X=gt.clone().vec3f(u.NORMAL),K=gt.clone().vec3f(u.NORMALA).vec3f(u.NORMALB);u.POSITION0,u.POSITION1,u.COMPONENTINDEX,u.VARIANTOFFSET,u.VARIANTSTROKE,u.VARIANTEXTENSION,u.NORMAL,u.NORMALA,u.NORMALB,u.SIDENESS;const V=-1;var st;function Vt(t,e,o,s=Ft){const r=t.vertices.position,c=t.vertices.componentIndex,g=nt(s.anglePlanar),a=nt(s.angleSignificantEdge),p=Math.cos(a),f=Math.cos(g),l=k.edge,I=l.position0,A=l.position1,d=l.faceNormal0,v=l.faceNormal1,h=_t(t),$=xt(t),n=$.length/4,i=e.allocate(n);let m=0;const N=n,O=o.allocate(N);let T=0,P=0,S=0;const Q=ht(0,n),F=new Float32Array(n);Ot(F,(L,w,x)=>{r.getVec($[4*w+0],I),r.getVec($[4*w+1],A),x[w]=Tt(I,A)}),Q.sort((L,w)=>F[w]-F[L]);const Z=new Array,tt=new Array;for(let L=0;L<n;L++){const w=Q[L],x=F[w],B=$[4*w+0],dt=$[4*w+1],M=$[4*w+2],U=$[4*w+3],et=U===V;if(r.getVec(B,I),r.getVec(dt,A),et)W(d,h[3*M+0],h[3*M+1],h[3*M+2]),ot(v,d),l.componentIndex=c.get(B),l.cosAngle=z(d,v);else{if(W(d,h[3*M+0],h[3*M+1],h[3*M+2]),W(v,h[3*U+0],h[3*U+1],h[3*U+2]),l.componentIndex=c.get(B),l.cosAngle=z(d,v),Mt(l,f))continue;l.cosAngle<-.9999&&ot(v,d)}P+=x,S++,et||Lt(l,p)?(e.write(i,m++,l),Z.push(x)):Rt(l,g)&&(o.write(O,T++,l),tt.push(x))}const Nt=new Float32Array(Z.reverse()),pt=new Float32Array(tt.reverse());return{regular:{instancesData:e.trim(i,m),lodInfo:{lengths:Nt}},silhouette:{instancesData:o.trim(O,T),lodInfo:{lengths:pt}},averageEdgeLength:P/S}}function Lt(t,e){return t.cosAngle<e}function Mt(t,e){return t.cosAngle>e}function Rt(t,e){const o=St(t.cosAngle),s=k.fwd,r=k.ortho;return wt(s,t.position1,t.position0),o*(z(lt(r,t.faceNormal0,t.faceNormal1),s)>0?-1:1)>e}function xt(t){const e=t.faces.length/3,o=t.faces,s=t.neighbors;let r=0;for(let a=0;a<e;a++){const p=s[3*a+0],f=s[3*a+1],l=s[3*a+2],I=o[3*a+0],A=o[3*a+1],d=o[3*a+2];r+=p===V||I<A?1:0,r+=f===V||A<d?1:0,r+=l===V||d<I?1:0}const c=new Int32Array(4*r);let g=0;for(let a=0;a<e;a++){const p=s[3*a+0],f=s[3*a+1],l=s[3*a+2],I=o[3*a+0],A=o[3*a+1],d=o[3*a+2];(p===V||I<A)&&(c[g++]=I,c[g++]=A,c[g++]=a,c[g++]=p),(f===V||A<d)&&(c[g++]=A,c[g++]=d,c[g++]=a,c[g++]=f),(l===V||d<I)&&(c[g++]=d,c[g++]=I,c[g++]=a,c[g++]=l)}return c}function _t(t){const e=t.faces.length/3,o=t.vertices.position,s=t.faces,r=H.v0,c=H.v1,g=H.v2,a=new Float32Array(3*e);for(let p=0;p<e;p++){const f=s[3*p+0],l=s[3*p+1],I=s[3*p+2];o.getVec(f,r),o.getVec(l,c),o.getVec(I,g),rt(c,c,r),rt(g,g,r),lt(r,c,g),ut(r,r),a[3*p+0]=r[0],a[3*p+1]=r[1],a[3*p+2]=r[2]}return a}(function(t){t[t.SOLID=0]="SOLID",t[t.SKETCH=1]="SKETCH"})(st||(st={}));const k={edge:{position0:E(),position1:E(),faceNormal0:E(),faceNormal1:E(),componentIndex:0,cosAngle:0},ortho:E(),fwd:E()},H={v0:E(),v1:E(),v2:E()},Ft={anglePlanar:4,angleSignificantEdge:35};function it(t,e,o){const s=e/3,r=new Uint32Array(o+1),c=new Uint32Array(o+1),g=(n,i)=>{n<i?r[n+1]++:c[i+1]++};for(let n=0;n<s;n++){const i=t[3*n],m=t[3*n+1],N=t[3*n+2];g(i,m),g(m,N),g(N,i)}let a=0,p=0;for(let n=0;n<o;n++){const i=r[n+1],m=c[n+1];r[n+1]=a,c[n+1]=p,a+=i,p+=m}const f=new Uint32Array(6*s),l=r[o],I=(n,i,m)=>{if(n<i){const N=r[n+1]++;f[2*N]=i,f[2*N+1]=m}else{const N=c[i+1]++;f[2*l+2*N]=n,f[2*l+2*N+1]=m}};for(let n=0;n<s;n++){const i=t[3*n],m=t[3*n+1],N=t[3*n+2];I(i,m,n),I(m,N,n),I(N,i,n)}const A=(n,i)=>{const m=2*n,N=i-n;for(let O=1;O<N;O++){const T=f[m+2*O],P=f[m+2*O+1];let S=O-1;for(;S>=0&&f[m+2*S]>T;S--)f[m+2*S+2]=f[m+2*S],f[m+2*S+3]=f[m+2*S+1];f[m+2*S+2]=T,f[m+2*S+3]=P}};for(let n=0;n<o;n++)A(r[n],r[n+1]),A(l+c[n],l+c[n+1]);const d=new Int32Array(3*s),v=(n,i)=>n===t[3*i]?0:n===t[3*i+1]?1:n===t[3*i+2]?2:-1,h=(n,i)=>{const m=v(n,i);d[3*i+m]=-1},$=(n,i,m,N)=>{const O=v(n,i);d[3*i+O]=N;const T=v(m,N);d[3*N+T]=i};for(let n=0;n<o;n++){let i=r[n];const m=r[n+1];let N=c[n];const O=c[n+1];for(;i<m&&N<O;){const T=f[2*i],P=f[2*l+2*N];T===P?($(n,f[2*i+1],P,f[2*l+2*N+1]),i++,N++):T<P?(h(n,f[2*i+1]),i++):(h(P,f[2*l+2*N+1]),N++)}for(;i<m;)h(n,f[2*i+1]),i++;for(;N<O;)h(f[2*l+2*N],f[2*l+2*N+1]),N++}return d}class mt{updateSettings(e){this.settings=e,this._edgeHashFunction=e.reducedPrecision?bt:Ut}write(e,o,s){const r=this._edgeHashFunction(s);C.seed=r;const c=C.getIntRange(0,255),g=C.getIntRange(0,this.settings.variants-1),a=.7,p=C.getFloat(),f=255*(.5*Ct(-(1-Math.min(p/a,1))+Math.max(0,p-a)/(1-a),1.2)+.5);e.position0.setVec(o,s.position0),e.position1.setVec(o,s.position1),e.componentIndex.set(o,s.componentIndex),e.variantOffset.set(o,c),e.variantStroke.set(o,g),e.variantExtension.set(o,f)}trim(e,o){return e.slice(0,o)}}const J=new Float32Array(6),G=new Uint32Array(J.buffer),y=new Uint32Array(1);function Ut(t){const e=J;e[0]=t.position0[0],e[1]=t.position0[1],e[2]=t.position0[2],e[3]=t.position1[0],e[4]=t.position1[1],e[5]=t.position1[2],y[0]=5381;for(let o=0;o<G.length;o++)y[0]=31*y[0]+G[o];return y[0]}function bt(t){const e=J;e[0]=R(t.position0[0]),e[1]=R(t.position0[1]),e[2]=R(t.position0[2]),e[3]=R(t.position1[0]),e[4]=R(t.position1[1]),e[5]=R(t.position1[2]),y[0]=5381;for(let o=0;o<G.length;o++)y[0]=31*y[0]+G[o];return y[0]}const ct=1e4;function R(t){return Math.round(t*ct)/ct}function Ct(t,e){const o=t<0?-1:1;return Math.abs(t)**e*o}class q{constructor(){this._commonWriter=new mt}updateSettings(e){this._commonWriter.updateSettings(e)}allocate(e){return X.createBuffer(e)}write(e,o,s){this._commonWriter.write(e,o,s),vt(b,s.faceNormal0,s.faceNormal1),ut(b,b),e.normal.setVec(o,b)}trim(e,o){return this._commonWriter.trim(e,o)}}q.Layout=X,q.glLayout=Y(X,1);class j{constructor(){this._commonWriter=new mt}updateSettings(e){this._commonWriter.updateSettings(e)}allocate(e){return K.createBuffer(e)}write(e,o,s){this._commonWriter.write(e,o,s),e.normalA.setVec(o,s.faceNormal0),e.normalB.setVec(o,s.faceNormal1)}trim(e,o){return this._commonWriter.trim(e,o)}}j.Layout=K,j.glLayout=Y(K,1);const b=E(),C=new Et;function qt(t){const e=Gt(t.data,t.skipDeduplicate,t.indices,t.indicesLength);return at.updateSettings(t.writerSettings),ft.updateSettings(t.writerSettings),Vt(e,at,ft)}function Gt(t,e,o,s){if(e){const g=it(o,s,t.count);return new Bt(o,s,g,t)}const r=It(t.buffer,t.stride/4,{originalIndices:o,originalIndicesLength:s}),c=it(r.indices,s,r.uniqueCount);return{faces:r.indices,facesLength:r.indices.length,neighbors:c,vertices:yt.createView(r.buffer)}}class Bt{constructor(e,o,s,r){this.faces=e,this.facesLength=o,this.neighbors=s,this.vertices=r}}const at=new q,ft=new j,jt=_().vec3f(u.POSITION0).vec3f(u.POSITION1),Yt=_().vec3f(u.POSITION0).vec3f(u.POSITION1).u16(u.COMPONENTINDEX).u16(u.U16PADDING,{glPadding:!0});export{yt as A,jt as a,qt as f,Vt as h,Yt as m,Gt as u};
|