@sienci/gviewer 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{GCodeSVGRenderer-DrPQRfLG.js → GCodeSVGRenderer-BIdf-Kth.js} +3 -3
- package/dist/{GCodeSVGRenderer-ZnJwBJPk.cjs → GCodeSVGRenderer-CsdiqRFx.cjs} +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/viewer.cjs +1 -1
- package/dist/viewer.js +7 -7
- package/package.json +1 -1
|
@@ -107,7 +107,7 @@ const YA = {
|
|
|
107
107
|
cutting: "#3e85c7",
|
|
108
108
|
laser: "#a855f7",
|
|
109
109
|
processed: "#6b7280",
|
|
110
|
-
boundingBox: "#
|
|
110
|
+
boundingBox: "#e2e8f0",
|
|
111
111
|
machineBed: "#fbbf24",
|
|
112
112
|
machineBedKeepout: "#df3b3b",
|
|
113
113
|
grid: { major: "#2f3840", minor: "#1f252b" },
|
|
@@ -433,10 +433,10 @@ function SP(r, Q) {
|
|
|
433
433
|
r.clone(),
|
|
434
434
|
new a.Color(Q.render.theme.colors.boundingBox)
|
|
435
435
|
), t = A.material;
|
|
436
|
-
return t.transparent = !0, t.opacity = 0.
|
|
436
|
+
return t.transparent = !0, t.opacity = 0.65, t.depthWrite = !1, t.linewidth = 2, B.add(A), Q.boundingBox.labels && B.add(...YP(r.clone(), Q)), B;
|
|
437
437
|
}
|
|
438
438
|
function YP(r, Q) {
|
|
439
|
-
const B = Q.render.theme.colors.boundingBox, A = 0.
|
|
439
|
+
const B = Q.render.theme.colors.boundingBox, A = 0.8, t = (U) => Math.abs(U) < 1e-9 ? "0" : U.toFixed(3), P = (U) => Q.units === "in" ? `${t(U / IP)} in` : `${t(U)} mm`, e = r.min, i = r.max, s = (U) => LQ(U, B, { size: 4, opacity: A }), v = s(P(e.x)), c = s(P(i.x)), n = s(P(e.y)), T = s(P(i.y)), z = s(P(e.z)), w = s(P(i.z)), o = new a.Vector3();
|
|
440
440
|
r.getSize(o);
|
|
441
441
|
const E = Math.max(2, Math.max(o.x, o.y, o.z) * 0.02), k = (e.x + i.x) / 2, h = (e.y + i.y) / 2;
|
|
442
442
|
return v.position.set(e.x - E, h, e.z - E), c.position.set(i.x + E, h, e.z - E), n.position.set(k, e.y - E, e.z - E), T.position.set(k, i.y + E, e.z - E), z.position.set(k, h, e.z - E), w.position.set(k, h, i.z + E), [v, c, n, T, z, w];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const DP=require("three"),uP=require("three/examples/jsm/controls/OrbitControls.js"),SQ=require("./gviewer.cjs"),CP=require("three/examples/jsm/loaders/STLLoader.js");function dP(r){const Q=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const B in r)if(B!=="default"){const A=Object.getOwnPropertyDescriptor(r,B);Object.defineProperty(Q,B,A.get?A:{enumerable:!0,get:()=>r[B]})}}return Q.default=r,Object.freeze(Q)}const a=dP(DP);function NP(r){const Q=[];let B=null;for(const A of r.specs){if(A.positions.length===0||A.opacity<=0)continue;const t=A.positions.length/3,P=A.colors?A.colors.slice():ht(A.kind,t,r.options),e=new Float32Array(P.length);e.set(P);const i=new a.BufferGeometry;i.setAttribute("position",new a.BufferAttribute(A.positions,3));const s=new a.BufferAttribute(e,3);s.setUsage(a.DynamicDrawUsage),i.setAttribute("color",s),i.computeBoundingBox();const v=new a.LineBasicMaterial({vertexColors:!0,transparent:!0,opacity:A.opacity}),c=new a.LineSegments(i,v);r.scene.add(c),Q.push({line:c,baseColors:P,simColors:e,prefixEndVertex:A.prefixEndVertex,totalVertices:t,greyCursorVertex:0,kind:A.kind,cutBucketIndex:A.cutBucketIndex,workerColors:A.colors?P:void 0}),i.boundingBox&&(B=B?B.union(i.boundingBox):i.boundingBox.clone())}return{streams:Q,bounds:B}}function OP(r,Q){for(const B of Q)r.remove(B.line),B.line.geometry.dispose(),B.line.material.dispose()}function LP(r,Q){for(const B of r){if(B.workerColors)continue;const A=ht(B.kind,B.totalVertices,Q);B.baseColors=A,B.simColors.set(A),B.greyCursorVertex=0;const t=B.line.geometry.getAttribute("color");t.clearUpdateRanges(),t.addUpdateRange(0,B.simColors.length),t.needsUpdate=!0}}function MP(r){const Q=tA(r.options.render.theme.rapidOpacity??.3);for(const B of r.streams){const A=B.line.material;if(B.kind==="rapid"){A.opacity=Q;continue}A.opacity=FP({bucketIndex:B.cutBucketIndex??0,bucketCount:r.cutBucketCount,baseOpacity:r.options.render.theme.opacity})}}function HP(r){const Q=r.stream.totalVertices,B=Math.max(0,Math.min(Q,Math.floor(r.nextCursorVertex))),A=Math.max(0,Math.min(Q,Math.floor(r.stream.greyCursorVertex)));if(B===A)return;const t=r.stream.line.geometry.getAttribute("color"),P=jP(r.options),e=Math.min(A,B),i=Math.max(A,B);if(B>A)for(let s=A;s<B;s+=1){const v=s*3;r.stream.simColors[v]=P.r,r.stream.simColors[v+1]=P.g,r.stream.simColors[v+2]=P.b}else{const s=B*3,v=A*3;r.stream.simColors.set(r.stream.baseColors.subarray(s,v),s)}t.clearUpdateRanges(),t.addUpdateRange(e*3,(i-e)*3),t.needsUpdate=!0,r.stream.greyCursorVertex=B}function ht(r,Q,B){const A=B.render.theme.colors,t=B.mode.laser?A.laser??A.cutting:A.cutting,P=new a.Color(r==="rapid"?A.rapid:t),e=new Float32Array(Q*3);for(let i=0;i<Q;i+=1){const s=i*3;e[s]=P.r,e[s+1]=P.g,e[s+2]=P.b}return e}function jP(r){const Q=r.render.theme.colors,B=new a.Color(r.render.theme.background),A=new a.Color(Q.processed??Q.cutting),t=B.clone().lerp(A,.65);return{r:t.r,g:t.g,b:t.b}}function FP(r){if(r.bucketCount<=1)return tA(r.baseOpacity);const Q=r.bucketIndex/(r.bucketCount-1);return tA(r.baseOpacity*Q)}function tA(r){return Number.isFinite(r)?Math.max(0,Math.min(1,r)):0}const PA={background:"#111827",opacity:.9,rapidOpacity:.3,colors:{rapid:"#0ef6ae",cutting:"#3e85c7",laser:"#a855f7",processed:"#6b7280",boundingBox:"#77a9d7",machineBed:"#fbbf24",machineBedKeepout:"#df3b3b",grid:{major:"#2f3840",minor:"#1f252b"},axes:{x:"#df3b3b",y:"#06b881",z:"#295d8d"}}},kt={units:"mm",mode:{laser:!1,sim3d:!1},sim3d:{toolDiameter:6.35,resolution:256,showToolpath:!1,erosionPasses:2},bit:{enabled:!0,type:"drill",size:4.05,opacity:.9,tweenMs:140,colorSource:"cutting",color:PA.colors.cutting,spinRpm:300},progress:{mode:"grey"},grid:{sizeX:1e3,sizeY:1e3,axisDepth:200,labels:!0,bounds:null},boundingBox:{visible:!1,labels:!1},machineBed:{visible:!1,min:null,max:null,keepout:null},geometry:{arcSegments:30,batching:{progressEveryLines:5e3,yieldEveryLines:5e4}},render:{antialias:!0,theme:PA},camera:{fov:45,focusDurationMs:900,orbit:{enableDamping:!0},initialPosition:{x:0,y:-200,z:200}}};async function GP(r,Q,B,A){var M,b,j;const t=Math.max(2,Math.floor(B)),P=(A==null?void 0:A.arcSegments)??30,e=(A==null?void 0:A.checkpointEveryLines)??2e3,i=((M=A==null?void 0:A.batch)==null?void 0:M.yieldEveryLines)??1e4,s=((b=A==null?void 0:A.batch)==null?void 0:b.shouldAbort)??(()=>!1),v=(j=A==null?void 0:A.batch)==null?void 0:j.onProgress;if(r.length===0){const O={xMin:-1,xMax:1,yMin:-1,yMax:1,zTop:1,zBot:0},G=new Float32Array(t*t).fill(O.zTop),f=new Map;return f.set(0,new Float32Array(G)),{moves:[],checkpoints:f,slabBounds:O,resolution:t,toolRadius:Q}}let c=1/0,n=-1/0,T=1/0,z=-1/0,w=1/0,o=-1/0;const E=new SQ.GCodeVirtualizer({onLinearMove(O){if(O.modals.motion==="G0")return;const G=O.transformedStart??O.start,f=O.transformedEnd??O.end;for(const H of[G,f])H.X<c&&(c=H.X),H.X>n&&(n=H.X),H.Y<T&&(T=H.Y),H.Y>z&&(z=H.Y),H.Z<w&&(w=H.Z),H.Z>o&&(o=H.Z)},onArcMove(O){const G=O.transformedStart??O.start,f=O.transformedEnd??O.end,H=O.transformedMax??O.max;for(const F of[G,f,H])F.X<c&&(c=F.X),F.X>n&&(n=F.X),F.Y<T&&(T=F.Y),F.Y>z&&(z=F.Y),F.Z<w&&(w=F.Z),F.Z>o&&(o=F.Z)}});for(const O of r)E.processLine(O);isFinite(c)||(c=-1,n=1,T=-1,z=1,w=0,o=0),c===n&&(c-=Q*2,n+=Q*2),T===z&&(T-=Q*2,z+=Q*2),c-=Q,n+=Q,T-=Q,z+=Q;const k=o;let h=w-Q;h>=k&&(h=k-1);const U={xMin:c,xMax:n,yMin:T,yMax:z,zTop:k,zBot:h},D=new Float32Array(t*t).fill(k),l=new Map;l.set(0,new Float32Array(D));const N=[];let u=0,d=0;const C=new SQ.GCodeVirtualizer({onLinearMove(O){const G=O.transformedStart??O.start,f=O.transformedEnd??O.end,H={lineIndex:d,x0:G.X,y0:G.Y,z0:G.Z,x1:f.X,y1:f.Y,z1:f.Z};N.push(H),eA(H,D,U,Q,t)},onArcMove(O){const G=O.transformedStart??O.start,f=O.transformedEnd??O.end,H=O.transformedCenter??O.center,F=fP(G,f,H,O.plane,O.motion,P);for(const J of F){const _={lineIndex:d,...J};N.push(_),eA(_,D,U,Q,t)}}});for(let O=0;O<r.length&&!s();O++){d=O;const G=r[O];G!==void 0&&C.processLine(G),O-u>=e&&(l.set(O,new Float32Array(D)),u=O),O%i===0&&O>0&&(v==null||v(O,r.length),await new Promise(f=>setTimeout(f,0)))}return v==null||v(r.length,r.length),{moves:N,checkpoints:l,slabBounds:U,resolution:t,toolRadius:Q}}function eA(r,Q,B,A,t){const P=(B.xMax-B.xMin)/t,e=(B.yMax-B.yMin)/t,i=Math.hypot(r.x1-r.x0,r.y1-r.y0),s=Math.max(.001,Math.min(P,e)*.5),v=Math.max(1,Math.ceil(i/s)),c=Math.ceil(A/P),n=Math.ceil(A/e),T=A*A;for(let z=0;z<=v;z++){const w=z/v,o=r.x0+(r.x1-r.x0)*w,E=r.y0+(r.y1-r.y0)*w,k=r.z0+(r.z1-r.z0)*w,h=Math.floor((o-B.xMin)/P),U=Math.floor((E-B.yMin)/e);for(let D=-c;D<=c;D++){const l=h+D;if(l<0||l>=t)continue;const N=B.xMin+(l+.5)*P,u=(N-o)*(N-o);if(!(u>T))for(let d=-n;d<=n;d++){const C=U+d;if(C<0||C>=t)continue;const M=B.yMin+(C+.5)*e;if(u+(M-E)*(M-E)>T)continue;const j=C*t+l;Q[j]>k&&(Q[j]=k)}}}}function yB(r,Q){let B=0;for(const P of Q.checkpoints.keys())P<=r&&P>B&&(B=P);const A=Q.checkpoints.get(B),t=A?new Float32Array(A):new Float32Array(Q.resolution*Q.resolution).fill(Q.slabBounds.zTop);for(const P of Q.moves)P.lineIndex>B&&P.lineIndex<=r&&eA(P,t,Q.slabBounds,Q.toolRadius,Q.resolution);return t}function IB(r,Q,B,A){if(B<=0)return;const t=.001,P=Q*Q,e=new Float32Array(P);for(let i=0;i<B;i++){e.set(r);for(let s=0;s<Q;s++)for(let v=0;v<Q;v++){if(e[s*Q+v]<A-t)continue;let n=A;for(let T=-1;T<=1;T++){const z=s+T;if(!(z<0||z>=Q))for(let w=-1;w<=1;w++){if(w===0&&T===0)continue;const o=v+w;if(o<0||o>=Q)continue;const E=e[z*Q+o];E<n&&(n=E)}}n<A-t&&(r[s*Q+v]=n)}}}function fP(r,Q,B,A,t,P){const e=Math.max(1,P);let i,s,v;A==="G18"?(i="Z",s="X",v="Y"):A==="G19"?(i="Y",s="Z",v="X"):(i="X",s="Y",v="Z");const c=Math.hypot(r[i]-B[i],r[s]-B[s]),n=Math.atan2(r[s]-B[s],r[i]-B[i]),T=Math.atan2(Q[s]-B[s],Q[i]-B[i]);let z;t==="G2"?(z=T-n,z>0&&(z-=Math.PI*2)):(z=T-n,z<0&&(z+=Math.PI*2));const w=[];let o={...r};for(let E=1;E<=e;E++){const k=E/e,h=n+z*k,U=k,D=B[i]+c*Math.cos(h),l=B[s]+c*Math.sin(h),N=r[v]+(Q[v]-r[v])*U,u={X:0,Y:0,Z:0};u[i]=D,u[s]=l,u[v]=N,w.push({x0:o.X,y0:o.Y,z0:o.Z,x1:u.X,y1:u.Y,z1:u.Z}),o=u}return w}let CB=null;function bP(){if(CB)return CB;const r=512,Q=document.createElement("canvas");Q.width=r,Q.height=r;const B=Q.getContext("2d");B.fillStyle="#8B5E3C",B.fillRect(0,0,r,r);const A=Math.floor(40+Math.random()*20);for(let t=0;t<A;t++){const P=Math.random()*r,e=1+Math.random()*2,i=Math.floor(139+(Math.random()-.5)*40),s=Math.floor(94+(Math.random()-.5)*30),v=Math.floor(60+(Math.random()-.5)*20);B.strokeStyle=`rgb(${i},${s},${v})`,B.lineWidth=e,B.beginPath(),B.moveTo(0,P),B.lineTo(r,P),B.stroke()}for(let t=0;t<300;t++){const P=Math.random()*r,e=Math.random()*r,i=20+Math.random()*60,s=(Math.random()-.5)*.3,v=Math.floor(100+Math.random()*80),c=Math.floor(60+Math.random()*50),n=Math.floor(30+Math.random()*40);B.strokeStyle=`rgba(${v},${c},${n},0.35)`,B.lineWidth=.5+Math.random()*1,B.beginPath(),B.moveTo(P,e),B.quadraticCurveTo(P+i*.5*Math.cos(s),e+i*.5*Math.sin(s)*.1,P+i*Math.cos(s*.5),e+i*.15),B.stroke()}return CB=new a.CanvasTexture(Q),CB}function gP(r,Q){const B=new a.Group;B.name="gviewer:sim3d-slab";const A=r.xMax-r.xMin,t=r.yMax-r.yMin,P=r.zTop-r.zBot,e=(r.xMin+r.xMax)/2,i=(r.yMin+r.yMax)/2,s=(r.zBot+r.zTop)/2,v=bP();v.wrapS=a.RepeatWrapping,v.wrapT=a.RepeatWrapping,v.repeat.set(A/100,t/100);const c=new a.MeshStandardMaterial({map:v,roughness:.85,metalness:0,side:a.FrontSide}),n=new a.MeshStandardMaterial({color:8016432,roughness:.9,metalness:0,side:a.DoubleSide}),T=new a.MeshStandardMaterial({color:7030822,roughness:.9,metalness:0}),z=new a.PlaneGeometry(A,t,Q-1,Q-1),w=Q*Q,o=new Float32Array(w*3),E=z.attributes.position;for(let j=0;j<w;j++)o[j*3]=E.getX(j),o[j*3+1]=E.getY(j),o[j*3+2]=0;const k=new a.BufferAttribute(o,3);k.usage=a.DynamicDrawUsage,z.setAttribute("position",k),z.computeVertexNormals();const h=new a.Mesh(z,c);h.name="gviewer:sim3d-top",h.position.set(e,i,r.zTop),B.add(h);const U=new a.PlaneGeometry(A,P);U.rotateX(Math.PI/2);const D=new a.Mesh(U,n);D.position.set(e,r.yMax,s),B.add(D);const l=new a.PlaneGeometry(A,P);l.rotateX(Math.PI/2);const N=new a.Mesh(l,n);N.position.set(e,r.yMin,s),B.add(N);const u=new a.PlaneGeometry(P,t);u.rotateY(-Math.PI/2);const d=new a.Mesh(u,n);d.position.set(r.xMax,i,s),B.add(d);const C=new a.PlaneGeometry(P,t);C.rotateY(-Math.PI/2);const M=new a.Mesh(C,n);M.position.set(r.xMin,i,s),B.add(M);const b=new a.Mesh(new a.PlaneGeometry(A,t),T);return b.position.set(e,i,r.zBot),B.add(b),{group:B,topMesh:h,topPositionAttr:k,slabBounds:r,resolution:Q}}function SB(r,Q){const{topPositionAttr:B,slabBounds:A,resolution:t}=r,P=t*t;for(let e=0;e<P;e++){const i=Math.floor(e/t),s=e%t,v=(t-1-i)*t+s;B.setZ(e,Q[v]-A.zTop)}B.needsUpdate=!0,r.topMesh.geometry.computeVertexNormals()}function pP(r){r.group.traverse(Q=>{if(Q instanceof a.Mesh){Q.geometry.dispose();const B=Q.material;Array.isArray(B)?B.forEach(A=>{A.map&&A.map.dispose(),A.dispose()}):(B.map&&B.map.dispose(),B.dispose())}})}class lt{constructor(Q){this.onSelectView=Q.onSelectView,this.faceButtons=new Map,this.root=document.createElement("div"),this.root.className="gViewer-viewcube",this.cube=document.createElement("div"),this.cube.className="gViewer-viewcube__cube",this.root.appendChild(this.cube);const B=[{view:"front",className:"gViewer-viewcube__face--front",label:"Front"},{view:"back",className:"gViewer-viewcube__face--back",label:"Back"},{view:"left",className:"gViewer-viewcube__face--left",label:"Left"},{view:"right",className:"gViewer-viewcube__face--right",label:"Right"},{view:"top",className:"gViewer-viewcube__face--top",label:"Top"},{view:"bottom",className:"gViewer-viewcube__face--bottom",label:"Bottom"}];for(const A of B){const t=document.createElement("button");t.type="button",t.className=`gViewer-viewcube__face ${A.className}`,t.textContent=A.label,t.addEventListener("click",()=>this.onSelectView(A.view)),this.cube.appendChild(t),this.faceButtons.set(A.view,t)}Q.container.appendChild(this.root)}setActiveFace(Q){for(const[B,A]of this.faceButtons.entries())B===Q?A.classList.add("is-active"):A.classList.remove("is-active")}setRotationMatrix3d(Q){const B=Array.from({length:16},(A,t)=>{const P=Q[t]??0;return Number.isFinite(P)?String(Math.abs(P)<1e-12?0:Number(P.toFixed(8))):"0"});this.cube.style.transform=`matrix3d(${B.join(",")})`}dispose(){this.root.remove()}}function LQ(r,Q,B={}){const{opacity:A=1,size:t=10}=B,P=new a.Object3D,e=100,i=document.createElement("canvas"),s=i.getContext("2d");if(!s)throw new Error("Missing canvas 2D context.");s.font=`normal ${e}px Arial`;const c=s.measureText(r).width;i.width=c,i.height=e,s.font=`normal ${e}px Arial`,s.textAlign="center",s.textBaseline="middle",s.fillStyle=Q,s.fillText(r,c/2,e/2);const n=new a.Texture(i);n.needsUpdate=!0,n.minFilter=a.LinearFilter;const T=new a.SpriteMaterial({map:n,transparent:!0,opacity:A});P.textHeight=t,P.textWidth=c/e*P.textHeight,B.textAlign==="left"?P.position.x=(B.x??0)+(P.textWidth??0)/2:B.textAlign==="right"?P.position.x=(B.x??0)-(P.textWidth??0)/2:P.position.x=B.x??0,B.textBaseline==="top"?P.position.y=(B.y??0)-(P.textHeight??0)/2:B.textBaseline==="bottom"?P.position.y=(B.y??0)+(P.textHeight??0)/2:P.position.y=B.y??0,P.position.z=B.z??0;const z=new a.Sprite(T);return z.scale.set(c/e*t,t,1),P.add(z),P}function mP(r){r.traverse(Q=>{var A;if(!(Q instanceof a.Sprite))return;const B=Q.material;(A=B.map)==null||A.dispose(),B.dispose()})}const xP=25.4;function yP(r,Q){const B=new a.Group,A=new a.Box3Helper(r.clone(),new a.Color(Q.render.theme.colors.boundingBox)),t=A.material;return t.transparent=!0,t.opacity=.12,t.depthWrite=!1,B.add(A),Q.boundingBox.labels&&B.add(...IP(r.clone(),Q)),B}function IP(r,Q){const B=Q.render.theme.colors.boundingBox,A=.32,t=U=>Math.abs(U)<1e-9?"0":U.toFixed(3),P=U=>Q.units==="in"?`${t(U/xP)} in`:`${t(U)} mm`,e=r.min,i=r.max,s=U=>LQ(U,B,{size:4,opacity:A}),v=s(P(e.x)),c=s(P(i.x)),n=s(P(e.y)),T=s(P(i.y)),z=s(P(e.z)),w=s(P(i.z)),o=new a.Vector3;r.getSize(o);const E=Math.max(2,Math.max(o.x,o.y,o.z)*.02),k=(e.x+i.x)/2,h=(e.y+i.y)/2;return v.position.set(e.x-E,h,e.z-E),c.position.set(i.x+E,h,e.z-E),n.position.set(k,e.y-E,e.z-E),T.position.set(k,i.y+E,e.z-E),z.position.set(k,h,e.z-E),w.position.set(k,h,i.z+E),[v,c,n,T,z,w]}function SP(r){r.traverse(Q=>{var B;if(Q instanceof a.LineSegments||Q instanceof a.Line){Q.geometry.dispose();const A=Q.material;Array.isArray(A)?A.forEach(t=>t.dispose()):A.dispose();return}if(Q instanceof a.Sprite){const A=Q.material;(B=A.map)==null||B.dispose(),A.dispose()}})}function VA(r,Q,B){const A=new Float32Array([r.x,r.y,0,Q.x,r.y,0,Q.x,Q.y,0,r.x,Q.y,0,r.x,r.y,0]),t=new a.BufferGeometry;t.setAttribute("position",new a.BufferAttribute(A,3));const P=new a.LineBasicMaterial({color:new a.Color(B),transparent:!0,opacity:.35,depthWrite:!1});return new a.LineLoop(t,P)}function YP(r,Q,B,A=10){const t=[],P=r.x-Q.y,e=Q.x-r.y;for(let v=P;v<=e;v+=A){const c=Math.max(r.x,r.y+v),n=Math.min(Q.x,Q.y+v);n>c&&t.push(c,c-v,0,n,n-v,0)}const i=new a.BufferGeometry;i.setAttribute("position",new a.BufferAttribute(new Float32Array(t),3));const s=new a.LineBasicMaterial({color:new a.Color(B),transparent:!0,opacity:.35,depthWrite:!1});return new a.LineSegments(i,s)}function VP(r,Q,B,A){const t=new a.Group;if(t.add(VA(r,Q,B.render.theme.colors.machineBed)),A){const P=B.render.theme.colors.machineBedKeepout;t.add(VA(A.min,A.max,P)),t.add(YP(A.min,A.max,P))}return t}function JP(r){r.traverse(Q=>{if(Q instanceof a.LineSegments||Q instanceof a.Line){Q.geometry.dispose();const B=Q.material;Array.isArray(B)?B.forEach(A=>A.dispose()):B.dispose()}})}function RP(r){const Q=window.getComputedStyle(r);(Q.position==="static"||!Q.position)&&(r.style.position="relative"),r.style.overflow||(r.style.overflow="hidden")}function XP(r){if(r<.5)return 4*r*r*r;const Q=-2*r+2;return 1-Q*Q*Q/2}function JA(r){const Q=new a.Vector3,B={right:new a.Vector3(1,0,0),left:new a.Vector3(-1,0,0),front:new a.Vector3(0,-1,0),back:new a.Vector3(0,1,0),top:new a.Vector3(0,0,1),bottom:new a.Vector3(0,0,-1)};switch(r){case"front":Q.copy(B.front);break;case"back":Q.copy(B.back);break;case"left":Q.copy(B.left);break;case"right":Q.copy(B.right);break;case"top":Q.copy(B.top);break;case"bottom":Q.copy(B.bottom);break;case"front-top-left":Q.copy(B.front).add(B.top).add(B.left);break;case"front-top-right":Q.copy(B.front).add(B.top).add(B.right);break;case"front-bottom-left":Q.copy(B.front).add(B.bottom).add(B.left);break;case"front-bottom-right":Q.copy(B.front).add(B.bottom).add(B.right);break;case"back-top-left":Q.copy(B.back).add(B.top).add(B.left);break;case"back-top-right":Q.copy(B.back).add(B.top).add(B.right);break;case"back-bottom-left":Q.copy(B.back).add(B.bottom).add(B.left);break;case"back-bottom-right":Q.copy(B.back).add(B.bottom).add(B.right);break;default:Q.copy(B.front);break}return Q.normalize()}function KP(r,Q){const B=r.x-Q.x,A=r.y-Q.y,t=r.z-Q.z,P=Math.abs(B),e=Math.abs(A),i=Math.abs(t);return i>=P&&i>=e?t>=0?"top":"bottom":P>=e?B>=0?"right":"left":A>=0?"back":"front"}const Ut=25.4;function lA(r){if(r.bounds)return{minX:r.bounds.min.x,maxX:r.bounds.max.x,minY:r.bounds.min.y,maxY:r.bounds.max.y};const Q=Math.max(1,r.sizeXMm)/2,B=Math.max(1,r.sizeYMm)/2;return{minX:-Q,maxX:Q,minY:-B,maxY:B}}function ZP(r){const{minX:Q,maxX:B,minY:A,maxY:t}=lA(r),P=r.units==="mm"?10:Ut,e=[],i=[],s=(w,o,E,k,h)=>{h.push(w,o,0,E,k,0)},v=Math.ceil(A/P)*P,c=Math.floor(t/P)*P;for(let w=v;w<=c+1e-6;w+=P)s(Q,w,B,w,Math.abs(w)<1e-6?e:i);const n=Math.ceil(Q/P)*P,T=Math.floor(B/P)*P;for(let w=n;w<=T+1e-6;w+=P)s(w,A,w,t,Math.abs(w)<1e-6?e:i);const z=new a.Group;return i.length>0&&z.add(RA(i,r.theme.colors.grid.minor,.25)),e.length>0&&z.add(RA(e,r.theme.colors.grid.major,.4)),z}function RA(r,Q,B){const A=new a.BufferGeometry;A.setAttribute("position",new a.Float32BufferAttribute(r,3));const t=new a.LineBasicMaterial({color:new a.Color(Q),transparent:!0,opacity:B,depthWrite:!1});return new a.LineSegments(A,t)}function WP(r){r.traverse(Q=>{if(!(Q instanceof a.LineSegments))return;Q.geometry.dispose();const B=Q.material;Array.isArray(B)?B.forEach(A=>A.dispose()):B.dispose()})}function qP(r){const Q=new a.Group,{minX:B,maxX:A,minY:t,maxY:P}=lA({sizeXMm:r.sizeXWorld,sizeYMm:r.sizeYWorld,bounds:r.bounds}),e=Math.max(1,r.depthWorld),i=Math.max(1,Math.min(Math.max(A-B,P-t)/24,30)),s=i*.6,v=k=>new a.LineDashedMaterial({color:new a.Color(k),dashSize:i,gapSize:s,transparent:!0,opacity:.75,depthWrite:!1}),c=new a.Line(new a.BufferGeometry().setFromPoints([new a.Vector3(B,0,0),new a.Vector3(A,0,0)]),v(r.theme.colors.axes.x));c.computeLineDistances();const n=new a.Line(new a.BufferGeometry().setFromPoints([new a.Vector3(0,t,0),new a.Vector3(0,P,0)]),v(r.theme.colors.axes.y));n.computeLineDistances();const T=new a.Line(new a.BufferGeometry().setFromPoints([new a.Vector3(0,0,0),new a.Vector3(0,0,e)]),v(r.theme.colors.axes.z));T.computeLineDistances(),Q.add(c,n,T);const z=Math.max(2,i),w=LQ("X",r.theme.colors.axes.x,{size:5});w.position.set(A+z,0,0);const o=LQ("Y",r.theme.colors.axes.y,{size:5});o.position.set(0,P+z,0);const E=LQ("Z",r.theme.colors.axes.z,{size:5});return E.position.set(0,0,e+z),Q.add(w,o,E),Q}function _P(r){r.traverse(Q=>{var B;if(Q instanceof a.Line){Q.geometry.dispose();const A=Q.material;Array.isArray(A)?A.forEach(t=>t.dispose()):A.dispose();return}if(Q instanceof a.Sprite){const A=Q.material;(B=A.map)==null||B.dispose(),A.dispose()}})}function $P(r){const Q=new a.Group,{minX:B,maxX:A,minY:t,maxY:P}=lA(r),e=r.units==="mm"?10:1,i=e*2,s=r.units==="mm"?1:Ut,v=.5,c=4,n=.1,T=5,z=r.theme.colors.axes.x,w=r.theme.colors.axes.y,o={opacity:v,size:c};for(let E=e;;E+=i){const k=E*s;if(k>A+1e-6)break;const h=LQ(String(E),z,o);h.position.set(k,T,n),Q.add(h)}for(let E=e;;E+=i){const k=E*s;if(-k<B-1e-6)break;const h=LQ(String(-E),z,o);h.position.set(-k,T,n),Q.add(h)}for(let E=e;;E+=i){const k=E*s;if(k>P+1e-6)break;const h=LQ(String(E),w,o);h.position.set(-T,k,n),Q.add(h)}for(let E=e;;E+=i){const k=E*s;if(-k<t-1e-6)break;const h=LQ(String(-E),w,o);h.position.set(-T,-k,n),Q.add(h)}return Q}function CQ(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function Dt(r,Q){r.prototype=Object.create(Q.prototype),r.prototype.constructor=r,r.__proto__=Q}/*!
|
|
1
|
+
"use strict";const DP=require("three"),uP=require("three/examples/jsm/controls/OrbitControls.js"),SQ=require("./gviewer.cjs"),CP=require("three/examples/jsm/loaders/STLLoader.js");function dP(r){const Q=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const B in r)if(B!=="default"){const A=Object.getOwnPropertyDescriptor(r,B);Object.defineProperty(Q,B,A.get?A:{enumerable:!0,get:()=>r[B]})}}return Q.default=r,Object.freeze(Q)}const a=dP(DP);function NP(r){const Q=[];let B=null;for(const A of r.specs){if(A.positions.length===0||A.opacity<=0)continue;const t=A.positions.length/3,P=A.colors?A.colors.slice():ht(A.kind,t,r.options),e=new Float32Array(P.length);e.set(P);const i=new a.BufferGeometry;i.setAttribute("position",new a.BufferAttribute(A.positions,3));const s=new a.BufferAttribute(e,3);s.setUsage(a.DynamicDrawUsage),i.setAttribute("color",s),i.computeBoundingBox();const v=new a.LineBasicMaterial({vertexColors:!0,transparent:!0,opacity:A.opacity}),c=new a.LineSegments(i,v);r.scene.add(c),Q.push({line:c,baseColors:P,simColors:e,prefixEndVertex:A.prefixEndVertex,totalVertices:t,greyCursorVertex:0,kind:A.kind,cutBucketIndex:A.cutBucketIndex,workerColors:A.colors?P:void 0}),i.boundingBox&&(B=B?B.union(i.boundingBox):i.boundingBox.clone())}return{streams:Q,bounds:B}}function OP(r,Q){for(const B of Q)r.remove(B.line),B.line.geometry.dispose(),B.line.material.dispose()}function LP(r,Q){for(const B of r){if(B.workerColors)continue;const A=ht(B.kind,B.totalVertices,Q);B.baseColors=A,B.simColors.set(A),B.greyCursorVertex=0;const t=B.line.geometry.getAttribute("color");t.clearUpdateRanges(),t.addUpdateRange(0,B.simColors.length),t.needsUpdate=!0}}function MP(r){const Q=tA(r.options.render.theme.rapidOpacity??.3);for(const B of r.streams){const A=B.line.material;if(B.kind==="rapid"){A.opacity=Q;continue}A.opacity=FP({bucketIndex:B.cutBucketIndex??0,bucketCount:r.cutBucketCount,baseOpacity:r.options.render.theme.opacity})}}function HP(r){const Q=r.stream.totalVertices,B=Math.max(0,Math.min(Q,Math.floor(r.nextCursorVertex))),A=Math.max(0,Math.min(Q,Math.floor(r.stream.greyCursorVertex)));if(B===A)return;const t=r.stream.line.geometry.getAttribute("color"),P=jP(r.options),e=Math.min(A,B),i=Math.max(A,B);if(B>A)for(let s=A;s<B;s+=1){const v=s*3;r.stream.simColors[v]=P.r,r.stream.simColors[v+1]=P.g,r.stream.simColors[v+2]=P.b}else{const s=B*3,v=A*3;r.stream.simColors.set(r.stream.baseColors.subarray(s,v),s)}t.clearUpdateRanges(),t.addUpdateRange(e*3,(i-e)*3),t.needsUpdate=!0,r.stream.greyCursorVertex=B}function ht(r,Q,B){const A=B.render.theme.colors,t=B.mode.laser?A.laser??A.cutting:A.cutting,P=new a.Color(r==="rapid"?A.rapid:t),e=new Float32Array(Q*3);for(let i=0;i<Q;i+=1){const s=i*3;e[s]=P.r,e[s+1]=P.g,e[s+2]=P.b}return e}function jP(r){const Q=r.render.theme.colors,B=new a.Color(r.render.theme.background),A=new a.Color(Q.processed??Q.cutting),t=B.clone().lerp(A,.65);return{r:t.r,g:t.g,b:t.b}}function FP(r){if(r.bucketCount<=1)return tA(r.baseOpacity);const Q=r.bucketIndex/(r.bucketCount-1);return tA(r.baseOpacity*Q)}function tA(r){return Number.isFinite(r)?Math.max(0,Math.min(1,r)):0}const PA={background:"#111827",opacity:.9,rapidOpacity:.3,colors:{rapid:"#0ef6ae",cutting:"#3e85c7",laser:"#a855f7",processed:"#6b7280",boundingBox:"#e2e8f0",machineBed:"#fbbf24",machineBedKeepout:"#df3b3b",grid:{major:"#2f3840",minor:"#1f252b"},axes:{x:"#df3b3b",y:"#06b881",z:"#295d8d"}}},kt={units:"mm",mode:{laser:!1,sim3d:!1},sim3d:{toolDiameter:6.35,resolution:256,showToolpath:!1,erosionPasses:2},bit:{enabled:!0,type:"drill",size:4.05,opacity:.9,tweenMs:140,colorSource:"cutting",color:PA.colors.cutting,spinRpm:300},progress:{mode:"grey"},grid:{sizeX:1e3,sizeY:1e3,axisDepth:200,labels:!0,bounds:null},boundingBox:{visible:!1,labels:!1},machineBed:{visible:!1,min:null,max:null,keepout:null},geometry:{arcSegments:30,batching:{progressEveryLines:5e3,yieldEveryLines:5e4}},render:{antialias:!0,theme:PA},camera:{fov:45,focusDurationMs:900,orbit:{enableDamping:!0},initialPosition:{x:0,y:-200,z:200}}};async function GP(r,Q,B,A){var M,b,j;const t=Math.max(2,Math.floor(B)),P=(A==null?void 0:A.arcSegments)??30,e=(A==null?void 0:A.checkpointEveryLines)??2e3,i=((M=A==null?void 0:A.batch)==null?void 0:M.yieldEveryLines)??1e4,s=((b=A==null?void 0:A.batch)==null?void 0:b.shouldAbort)??(()=>!1),v=(j=A==null?void 0:A.batch)==null?void 0:j.onProgress;if(r.length===0){const O={xMin:-1,xMax:1,yMin:-1,yMax:1,zTop:1,zBot:0},G=new Float32Array(t*t).fill(O.zTop),f=new Map;return f.set(0,new Float32Array(G)),{moves:[],checkpoints:f,slabBounds:O,resolution:t,toolRadius:Q}}let c=1/0,n=-1/0,T=1/0,z=-1/0,w=1/0,o=-1/0;const E=new SQ.GCodeVirtualizer({onLinearMove(O){if(O.modals.motion==="G0")return;const G=O.transformedStart??O.start,f=O.transformedEnd??O.end;for(const H of[G,f])H.X<c&&(c=H.X),H.X>n&&(n=H.X),H.Y<T&&(T=H.Y),H.Y>z&&(z=H.Y),H.Z<w&&(w=H.Z),H.Z>o&&(o=H.Z)},onArcMove(O){const G=O.transformedStart??O.start,f=O.transformedEnd??O.end,H=O.transformedMax??O.max;for(const F of[G,f,H])F.X<c&&(c=F.X),F.X>n&&(n=F.X),F.Y<T&&(T=F.Y),F.Y>z&&(z=F.Y),F.Z<w&&(w=F.Z),F.Z>o&&(o=F.Z)}});for(const O of r)E.processLine(O);isFinite(c)||(c=-1,n=1,T=-1,z=1,w=0,o=0),c===n&&(c-=Q*2,n+=Q*2),T===z&&(T-=Q*2,z+=Q*2),c-=Q,n+=Q,T-=Q,z+=Q;const k=o;let h=w-Q;h>=k&&(h=k-1);const U={xMin:c,xMax:n,yMin:T,yMax:z,zTop:k,zBot:h},D=new Float32Array(t*t).fill(k),l=new Map;l.set(0,new Float32Array(D));const N=[];let u=0,d=0;const C=new SQ.GCodeVirtualizer({onLinearMove(O){const G=O.transformedStart??O.start,f=O.transformedEnd??O.end,H={lineIndex:d,x0:G.X,y0:G.Y,z0:G.Z,x1:f.X,y1:f.Y,z1:f.Z};N.push(H),eA(H,D,U,Q,t)},onArcMove(O){const G=O.transformedStart??O.start,f=O.transformedEnd??O.end,H=O.transformedCenter??O.center,F=fP(G,f,H,O.plane,O.motion,P);for(const J of F){const _={lineIndex:d,...J};N.push(_),eA(_,D,U,Q,t)}}});for(let O=0;O<r.length&&!s();O++){d=O;const G=r[O];G!==void 0&&C.processLine(G),O-u>=e&&(l.set(O,new Float32Array(D)),u=O),O%i===0&&O>0&&(v==null||v(O,r.length),await new Promise(f=>setTimeout(f,0)))}return v==null||v(r.length,r.length),{moves:N,checkpoints:l,slabBounds:U,resolution:t,toolRadius:Q}}function eA(r,Q,B,A,t){const P=(B.xMax-B.xMin)/t,e=(B.yMax-B.yMin)/t,i=Math.hypot(r.x1-r.x0,r.y1-r.y0),s=Math.max(.001,Math.min(P,e)*.5),v=Math.max(1,Math.ceil(i/s)),c=Math.ceil(A/P),n=Math.ceil(A/e),T=A*A;for(let z=0;z<=v;z++){const w=z/v,o=r.x0+(r.x1-r.x0)*w,E=r.y0+(r.y1-r.y0)*w,k=r.z0+(r.z1-r.z0)*w,h=Math.floor((o-B.xMin)/P),U=Math.floor((E-B.yMin)/e);for(let D=-c;D<=c;D++){const l=h+D;if(l<0||l>=t)continue;const N=B.xMin+(l+.5)*P,u=(N-o)*(N-o);if(!(u>T))for(let d=-n;d<=n;d++){const C=U+d;if(C<0||C>=t)continue;const M=B.yMin+(C+.5)*e;if(u+(M-E)*(M-E)>T)continue;const j=C*t+l;Q[j]>k&&(Q[j]=k)}}}}function yB(r,Q){let B=0;for(const P of Q.checkpoints.keys())P<=r&&P>B&&(B=P);const A=Q.checkpoints.get(B),t=A?new Float32Array(A):new Float32Array(Q.resolution*Q.resolution).fill(Q.slabBounds.zTop);for(const P of Q.moves)P.lineIndex>B&&P.lineIndex<=r&&eA(P,t,Q.slabBounds,Q.toolRadius,Q.resolution);return t}function IB(r,Q,B,A){if(B<=0)return;const t=.001,P=Q*Q,e=new Float32Array(P);for(let i=0;i<B;i++){e.set(r);for(let s=0;s<Q;s++)for(let v=0;v<Q;v++){if(e[s*Q+v]<A-t)continue;let n=A;for(let T=-1;T<=1;T++){const z=s+T;if(!(z<0||z>=Q))for(let w=-1;w<=1;w++){if(w===0&&T===0)continue;const o=v+w;if(o<0||o>=Q)continue;const E=e[z*Q+o];E<n&&(n=E)}}n<A-t&&(r[s*Q+v]=n)}}}function fP(r,Q,B,A,t,P){const e=Math.max(1,P);let i,s,v;A==="G18"?(i="Z",s="X",v="Y"):A==="G19"?(i="Y",s="Z",v="X"):(i="X",s="Y",v="Z");const c=Math.hypot(r[i]-B[i],r[s]-B[s]),n=Math.atan2(r[s]-B[s],r[i]-B[i]),T=Math.atan2(Q[s]-B[s],Q[i]-B[i]);let z;t==="G2"?(z=T-n,z>0&&(z-=Math.PI*2)):(z=T-n,z<0&&(z+=Math.PI*2));const w=[];let o={...r};for(let E=1;E<=e;E++){const k=E/e,h=n+z*k,U=k,D=B[i]+c*Math.cos(h),l=B[s]+c*Math.sin(h),N=r[v]+(Q[v]-r[v])*U,u={X:0,Y:0,Z:0};u[i]=D,u[s]=l,u[v]=N,w.push({x0:o.X,y0:o.Y,z0:o.Z,x1:u.X,y1:u.Y,z1:u.Z}),o=u}return w}let CB=null;function bP(){if(CB)return CB;const r=512,Q=document.createElement("canvas");Q.width=r,Q.height=r;const B=Q.getContext("2d");B.fillStyle="#8B5E3C",B.fillRect(0,0,r,r);const A=Math.floor(40+Math.random()*20);for(let t=0;t<A;t++){const P=Math.random()*r,e=1+Math.random()*2,i=Math.floor(139+(Math.random()-.5)*40),s=Math.floor(94+(Math.random()-.5)*30),v=Math.floor(60+(Math.random()-.5)*20);B.strokeStyle=`rgb(${i},${s},${v})`,B.lineWidth=e,B.beginPath(),B.moveTo(0,P),B.lineTo(r,P),B.stroke()}for(let t=0;t<300;t++){const P=Math.random()*r,e=Math.random()*r,i=20+Math.random()*60,s=(Math.random()-.5)*.3,v=Math.floor(100+Math.random()*80),c=Math.floor(60+Math.random()*50),n=Math.floor(30+Math.random()*40);B.strokeStyle=`rgba(${v},${c},${n},0.35)`,B.lineWidth=.5+Math.random()*1,B.beginPath(),B.moveTo(P,e),B.quadraticCurveTo(P+i*.5*Math.cos(s),e+i*.5*Math.sin(s)*.1,P+i*Math.cos(s*.5),e+i*.15),B.stroke()}return CB=new a.CanvasTexture(Q),CB}function gP(r,Q){const B=new a.Group;B.name="gviewer:sim3d-slab";const A=r.xMax-r.xMin,t=r.yMax-r.yMin,P=r.zTop-r.zBot,e=(r.xMin+r.xMax)/2,i=(r.yMin+r.yMax)/2,s=(r.zBot+r.zTop)/2,v=bP();v.wrapS=a.RepeatWrapping,v.wrapT=a.RepeatWrapping,v.repeat.set(A/100,t/100);const c=new a.MeshStandardMaterial({map:v,roughness:.85,metalness:0,side:a.FrontSide}),n=new a.MeshStandardMaterial({color:8016432,roughness:.9,metalness:0,side:a.DoubleSide}),T=new a.MeshStandardMaterial({color:7030822,roughness:.9,metalness:0}),z=new a.PlaneGeometry(A,t,Q-1,Q-1),w=Q*Q,o=new Float32Array(w*3),E=z.attributes.position;for(let j=0;j<w;j++)o[j*3]=E.getX(j),o[j*3+1]=E.getY(j),o[j*3+2]=0;const k=new a.BufferAttribute(o,3);k.usage=a.DynamicDrawUsage,z.setAttribute("position",k),z.computeVertexNormals();const h=new a.Mesh(z,c);h.name="gviewer:sim3d-top",h.position.set(e,i,r.zTop),B.add(h);const U=new a.PlaneGeometry(A,P);U.rotateX(Math.PI/2);const D=new a.Mesh(U,n);D.position.set(e,r.yMax,s),B.add(D);const l=new a.PlaneGeometry(A,P);l.rotateX(Math.PI/2);const N=new a.Mesh(l,n);N.position.set(e,r.yMin,s),B.add(N);const u=new a.PlaneGeometry(P,t);u.rotateY(-Math.PI/2);const d=new a.Mesh(u,n);d.position.set(r.xMax,i,s),B.add(d);const C=new a.PlaneGeometry(P,t);C.rotateY(-Math.PI/2);const M=new a.Mesh(C,n);M.position.set(r.xMin,i,s),B.add(M);const b=new a.Mesh(new a.PlaneGeometry(A,t),T);return b.position.set(e,i,r.zBot),B.add(b),{group:B,topMesh:h,topPositionAttr:k,slabBounds:r,resolution:Q}}function SB(r,Q){const{topPositionAttr:B,slabBounds:A,resolution:t}=r,P=t*t;for(let e=0;e<P;e++){const i=Math.floor(e/t),s=e%t,v=(t-1-i)*t+s;B.setZ(e,Q[v]-A.zTop)}B.needsUpdate=!0,r.topMesh.geometry.computeVertexNormals()}function pP(r){r.group.traverse(Q=>{if(Q instanceof a.Mesh){Q.geometry.dispose();const B=Q.material;Array.isArray(B)?B.forEach(A=>{A.map&&A.map.dispose(),A.dispose()}):(B.map&&B.map.dispose(),B.dispose())}})}class lt{constructor(Q){this.onSelectView=Q.onSelectView,this.faceButtons=new Map,this.root=document.createElement("div"),this.root.className="gViewer-viewcube",this.cube=document.createElement("div"),this.cube.className="gViewer-viewcube__cube",this.root.appendChild(this.cube);const B=[{view:"front",className:"gViewer-viewcube__face--front",label:"Front"},{view:"back",className:"gViewer-viewcube__face--back",label:"Back"},{view:"left",className:"gViewer-viewcube__face--left",label:"Left"},{view:"right",className:"gViewer-viewcube__face--right",label:"Right"},{view:"top",className:"gViewer-viewcube__face--top",label:"Top"},{view:"bottom",className:"gViewer-viewcube__face--bottom",label:"Bottom"}];for(const A of B){const t=document.createElement("button");t.type="button",t.className=`gViewer-viewcube__face ${A.className}`,t.textContent=A.label,t.addEventListener("click",()=>this.onSelectView(A.view)),this.cube.appendChild(t),this.faceButtons.set(A.view,t)}Q.container.appendChild(this.root)}setActiveFace(Q){for(const[B,A]of this.faceButtons.entries())B===Q?A.classList.add("is-active"):A.classList.remove("is-active")}setRotationMatrix3d(Q){const B=Array.from({length:16},(A,t)=>{const P=Q[t]??0;return Number.isFinite(P)?String(Math.abs(P)<1e-12?0:Number(P.toFixed(8))):"0"});this.cube.style.transform=`matrix3d(${B.join(",")})`}dispose(){this.root.remove()}}function LQ(r,Q,B={}){const{opacity:A=1,size:t=10}=B,P=new a.Object3D,e=100,i=document.createElement("canvas"),s=i.getContext("2d");if(!s)throw new Error("Missing canvas 2D context.");s.font=`normal ${e}px Arial`;const c=s.measureText(r).width;i.width=c,i.height=e,s.font=`normal ${e}px Arial`,s.textAlign="center",s.textBaseline="middle",s.fillStyle=Q,s.fillText(r,c/2,e/2);const n=new a.Texture(i);n.needsUpdate=!0,n.minFilter=a.LinearFilter;const T=new a.SpriteMaterial({map:n,transparent:!0,opacity:A});P.textHeight=t,P.textWidth=c/e*P.textHeight,B.textAlign==="left"?P.position.x=(B.x??0)+(P.textWidth??0)/2:B.textAlign==="right"?P.position.x=(B.x??0)-(P.textWidth??0)/2:P.position.x=B.x??0,B.textBaseline==="top"?P.position.y=(B.y??0)-(P.textHeight??0)/2:B.textBaseline==="bottom"?P.position.y=(B.y??0)+(P.textHeight??0)/2:P.position.y=B.y??0,P.position.z=B.z??0;const z=new a.Sprite(T);return z.scale.set(c/e*t,t,1),P.add(z),P}function mP(r){r.traverse(Q=>{var A;if(!(Q instanceof a.Sprite))return;const B=Q.material;(A=B.map)==null||A.dispose(),B.dispose()})}const xP=25.4;function yP(r,Q){const B=new a.Group,A=new a.Box3Helper(r.clone(),new a.Color(Q.render.theme.colors.boundingBox)),t=A.material;return t.transparent=!0,t.opacity=.65,t.depthWrite=!1,t.linewidth=2,B.add(A),Q.boundingBox.labels&&B.add(...IP(r.clone(),Q)),B}function IP(r,Q){const B=Q.render.theme.colors.boundingBox,A=.8,t=U=>Math.abs(U)<1e-9?"0":U.toFixed(3),P=U=>Q.units==="in"?`${t(U/xP)} in`:`${t(U)} mm`,e=r.min,i=r.max,s=U=>LQ(U,B,{size:4,opacity:A}),v=s(P(e.x)),c=s(P(i.x)),n=s(P(e.y)),T=s(P(i.y)),z=s(P(e.z)),w=s(P(i.z)),o=new a.Vector3;r.getSize(o);const E=Math.max(2,Math.max(o.x,o.y,o.z)*.02),k=(e.x+i.x)/2,h=(e.y+i.y)/2;return v.position.set(e.x-E,h,e.z-E),c.position.set(i.x+E,h,e.z-E),n.position.set(k,e.y-E,e.z-E),T.position.set(k,i.y+E,e.z-E),z.position.set(k,h,e.z-E),w.position.set(k,h,i.z+E),[v,c,n,T,z,w]}function SP(r){r.traverse(Q=>{var B;if(Q instanceof a.LineSegments||Q instanceof a.Line){Q.geometry.dispose();const A=Q.material;Array.isArray(A)?A.forEach(t=>t.dispose()):A.dispose();return}if(Q instanceof a.Sprite){const A=Q.material;(B=A.map)==null||B.dispose(),A.dispose()}})}function VA(r,Q,B){const A=new Float32Array([r.x,r.y,0,Q.x,r.y,0,Q.x,Q.y,0,r.x,Q.y,0,r.x,r.y,0]),t=new a.BufferGeometry;t.setAttribute("position",new a.BufferAttribute(A,3));const P=new a.LineBasicMaterial({color:new a.Color(B),transparent:!0,opacity:.35,depthWrite:!1});return new a.LineLoop(t,P)}function YP(r,Q,B,A=10){const t=[],P=r.x-Q.y,e=Q.x-r.y;for(let v=P;v<=e;v+=A){const c=Math.max(r.x,r.y+v),n=Math.min(Q.x,Q.y+v);n>c&&t.push(c,c-v,0,n,n-v,0)}const i=new a.BufferGeometry;i.setAttribute("position",new a.BufferAttribute(new Float32Array(t),3));const s=new a.LineBasicMaterial({color:new a.Color(B),transparent:!0,opacity:.35,depthWrite:!1});return new a.LineSegments(i,s)}function VP(r,Q,B,A){const t=new a.Group;if(t.add(VA(r,Q,B.render.theme.colors.machineBed)),A){const P=B.render.theme.colors.machineBedKeepout;t.add(VA(A.min,A.max,P)),t.add(YP(A.min,A.max,P))}return t}function JP(r){r.traverse(Q=>{if(Q instanceof a.LineSegments||Q instanceof a.Line){Q.geometry.dispose();const B=Q.material;Array.isArray(B)?B.forEach(A=>A.dispose()):B.dispose()}})}function RP(r){const Q=window.getComputedStyle(r);(Q.position==="static"||!Q.position)&&(r.style.position="relative"),r.style.overflow||(r.style.overflow="hidden")}function XP(r){if(r<.5)return 4*r*r*r;const Q=-2*r+2;return 1-Q*Q*Q/2}function JA(r){const Q=new a.Vector3,B={right:new a.Vector3(1,0,0),left:new a.Vector3(-1,0,0),front:new a.Vector3(0,-1,0),back:new a.Vector3(0,1,0),top:new a.Vector3(0,0,1),bottom:new a.Vector3(0,0,-1)};switch(r){case"front":Q.copy(B.front);break;case"back":Q.copy(B.back);break;case"left":Q.copy(B.left);break;case"right":Q.copy(B.right);break;case"top":Q.copy(B.top);break;case"bottom":Q.copy(B.bottom);break;case"front-top-left":Q.copy(B.front).add(B.top).add(B.left);break;case"front-top-right":Q.copy(B.front).add(B.top).add(B.right);break;case"front-bottom-left":Q.copy(B.front).add(B.bottom).add(B.left);break;case"front-bottom-right":Q.copy(B.front).add(B.bottom).add(B.right);break;case"back-top-left":Q.copy(B.back).add(B.top).add(B.left);break;case"back-top-right":Q.copy(B.back).add(B.top).add(B.right);break;case"back-bottom-left":Q.copy(B.back).add(B.bottom).add(B.left);break;case"back-bottom-right":Q.copy(B.back).add(B.bottom).add(B.right);break;default:Q.copy(B.front);break}return Q.normalize()}function KP(r,Q){const B=r.x-Q.x,A=r.y-Q.y,t=r.z-Q.z,P=Math.abs(B),e=Math.abs(A),i=Math.abs(t);return i>=P&&i>=e?t>=0?"top":"bottom":P>=e?B>=0?"right":"left":A>=0?"back":"front"}const Ut=25.4;function lA(r){if(r.bounds)return{minX:r.bounds.min.x,maxX:r.bounds.max.x,minY:r.bounds.min.y,maxY:r.bounds.max.y};const Q=Math.max(1,r.sizeXMm)/2,B=Math.max(1,r.sizeYMm)/2;return{minX:-Q,maxX:Q,minY:-B,maxY:B}}function ZP(r){const{minX:Q,maxX:B,minY:A,maxY:t}=lA(r),P=r.units==="mm"?10:Ut,e=[],i=[],s=(w,o,E,k,h)=>{h.push(w,o,0,E,k,0)},v=Math.ceil(A/P)*P,c=Math.floor(t/P)*P;for(let w=v;w<=c+1e-6;w+=P)s(Q,w,B,w,Math.abs(w)<1e-6?e:i);const n=Math.ceil(Q/P)*P,T=Math.floor(B/P)*P;for(let w=n;w<=T+1e-6;w+=P)s(w,A,w,t,Math.abs(w)<1e-6?e:i);const z=new a.Group;return i.length>0&&z.add(RA(i,r.theme.colors.grid.minor,.25)),e.length>0&&z.add(RA(e,r.theme.colors.grid.major,.4)),z}function RA(r,Q,B){const A=new a.BufferGeometry;A.setAttribute("position",new a.Float32BufferAttribute(r,3));const t=new a.LineBasicMaterial({color:new a.Color(Q),transparent:!0,opacity:B,depthWrite:!1});return new a.LineSegments(A,t)}function WP(r){r.traverse(Q=>{if(!(Q instanceof a.LineSegments))return;Q.geometry.dispose();const B=Q.material;Array.isArray(B)?B.forEach(A=>A.dispose()):B.dispose()})}function qP(r){const Q=new a.Group,{minX:B,maxX:A,minY:t,maxY:P}=lA({sizeXMm:r.sizeXWorld,sizeYMm:r.sizeYWorld,bounds:r.bounds}),e=Math.max(1,r.depthWorld),i=Math.max(1,Math.min(Math.max(A-B,P-t)/24,30)),s=i*.6,v=k=>new a.LineDashedMaterial({color:new a.Color(k),dashSize:i,gapSize:s,transparent:!0,opacity:.75,depthWrite:!1}),c=new a.Line(new a.BufferGeometry().setFromPoints([new a.Vector3(B,0,0),new a.Vector3(A,0,0)]),v(r.theme.colors.axes.x));c.computeLineDistances();const n=new a.Line(new a.BufferGeometry().setFromPoints([new a.Vector3(0,t,0),new a.Vector3(0,P,0)]),v(r.theme.colors.axes.y));n.computeLineDistances();const T=new a.Line(new a.BufferGeometry().setFromPoints([new a.Vector3(0,0,0),new a.Vector3(0,0,e)]),v(r.theme.colors.axes.z));T.computeLineDistances(),Q.add(c,n,T);const z=Math.max(2,i),w=LQ("X",r.theme.colors.axes.x,{size:5});w.position.set(A+z,0,0);const o=LQ("Y",r.theme.colors.axes.y,{size:5});o.position.set(0,P+z,0);const E=LQ("Z",r.theme.colors.axes.z,{size:5});return E.position.set(0,0,e+z),Q.add(w,o,E),Q}function _P(r){r.traverse(Q=>{var B;if(Q instanceof a.Line){Q.geometry.dispose();const A=Q.material;Array.isArray(A)?A.forEach(t=>t.dispose()):A.dispose();return}if(Q instanceof a.Sprite){const A=Q.material;(B=A.map)==null||B.dispose(),A.dispose()}})}function $P(r){const Q=new a.Group,{minX:B,maxX:A,minY:t,maxY:P}=lA(r),e=r.units==="mm"?10:1,i=e*2,s=r.units==="mm"?1:Ut,v=.5,c=4,n=.1,T=5,z=r.theme.colors.axes.x,w=r.theme.colors.axes.y,o={opacity:v,size:c};for(let E=e;;E+=i){const k=E*s;if(k>A+1e-6)break;const h=LQ(String(E),z,o);h.position.set(k,T,n),Q.add(h)}for(let E=e;;E+=i){const k=E*s;if(-k<B-1e-6)break;const h=LQ(String(-E),z,o);h.position.set(-k,T,n),Q.add(h)}for(let E=e;;E+=i){const k=E*s;if(k>P+1e-6)break;const h=LQ(String(E),w,o);h.position.set(-T,k,n),Q.add(h)}for(let E=e;;E+=i){const k=E*s;if(-k<t-1e-6)break;const h=LQ(String(-E),w,o);h.position.set(-T,-k,n),Q.add(h)}return Q}function CQ(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function Dt(r,Q){r.prototype=Object.create(Q.prototype),r.prototype.constructor=r,r.__proto__=Q}/*!
|
|
2
2
|
* GSAP 3.15.0
|
|
3
3
|
* https://gsap.com
|
|
4
4
|
*
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react"),V=require("./GCodeSVGRenderer-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react"),V=require("./GCodeSVGRenderer-CsdiqRFx.cjs");function G(a){const d=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const s in a)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(a,s);Object.defineProperty(d,s,i.get?i:{enumerable:!0,get:()=>a[s]})}}return d.default=a,Object.freeze(d)}const o=G(w),C=o.forwardRef(function(d,s){const{id:i,options:l,callbacks:c,className:m,style:f}=d,u=o.useRef(null),r=o.useRef(null);return o.useEffect(()=>{const e=u.current;if(!e)return;const p=new V.GCodeViewer({id:i,container:e,options:l,callbacks:c});return r.current=p,()=>{r.current=null,p.dispose()}},[i]),o.useEffect(()=>{var e;(e=r.current)==null||e.setOptions(l??{})},[l]),o.useEffect(()=>{var e;(e=r.current)==null||e.setCallbacks(c??{})},[c]),o.useImperativeHandle(s,()=>{const e=()=>{const t=r.current;if(!t)throw new Error("GCodeViewer is not ready.");return t};return{get id(){return i},setCallbacks(t){e().setCallbacks(t)},snapCameraToView(t,n){e().snapCameraToView(t,n)},setRotateEnabled(t){e().setRotateEnabled(t)},screenToWorld(t,n,F){return e().screenToWorld(t,n,F)},setBitPosition(t,n){e().setBitPosition(t,n)},setBitVisible(t){e().setBitVisible(t)},setBitSpinning(t){e().setBitSpinning(t)},setToolpathRotationA(t){e().setToolpathRotationA(t)},hideUntilLine(t,n){e().hideUntilLine(t,n)},seekToLine(t,n){e().seekToLine(t,n)},showAll(){e().showAll()},resetColors(){e().resetColors()},loadFromUrl(t,n){return e().loadFromUrl(t,n)},loadFromFile(t){return e().loadFromFile(t)},loadFromText(t){return e().loadFromText(t)},loadFromLines(t){return e().loadFromLines(t)},loadFromWorkerData(t){return e().loadFromWorkerData(t)},unload(){e().unload()},setOptions(t){e().setOptions(t)},getOptions(){return e().getOptions()},resize(){e().resize()},focusToModel(){e().focusToModel()},resetCamera(){e().resetCamera()},getBounds(){return e().getBounds()},dispose(){e().dispose()}}},[i]),o.createElement("div",{ref:u,className:m,style:f})}),g=o.forwardRef(function(d,s){const{id:i,options:l,className:c,style:m}=d,f=o.useRef(null),u=o.useRef(null);return o.useEffect(()=>{const r=f.current;if(!r)return;const e=new V.GCodeSVGRenderer(r,l);return u.current=e,()=>{u.current=null,e.dispose()}},[]),o.useEffect(()=>{var r;l&&((r=u.current)==null||r.setOptions(l))},[l]),o.useImperativeHandle(s,()=>{const r=()=>{const e=u.current;if(!e)throw new Error("GCodeSVGRenderer is not ready.");return e};return{loadFromLines:e=>r().loadFromLines(e),loadFromFile:e=>r().loadFromFile(e),loadFromText:e=>r().loadFromText(e),loadFromWorkerData:e=>r().loadFromWorkerData(e),loadFromPrecomputedGroups:e=>r().loadFromPrecomputedGroups(e),clear:()=>r().clear(),resetView:()=>r().resetView(),setOptions:e=>r().setOptions(e),setProjectionMode:e=>r().setProjectionMode(e),setBitPosition:e=>r().setBitPosition(e),setBitVisible:e=>r().setBitVisible(e),getSVGElement:()=>r().getSVGElement(),dispose:()=>r().dispose()}},[]),o.createElement("div",{ref:f,className:c,style:{width:"100%",height:"100%",...m}})});exports.GCodeSVGVisualizer=g;exports.GCodeVisualizer=C;
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as o from "react";
|
|
2
|
-
import { a as w, G as V } from "./GCodeSVGRenderer-
|
|
2
|
+
import { a as w, G as V } from "./GCodeSVGRenderer-BIdf-Kth.js";
|
|
3
3
|
const G = o.forwardRef(
|
|
4
4
|
function(u, c) {
|
|
5
5
|
const { id: a, options: n, callbacks: l, className: m, style: d } = u, i = o.useRef(null), r = o.useRef(null);
|
package/dist/viewer.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./GCodeSVGRenderer-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./GCodeSVGRenderer-CsdiqRFx.cjs"),a={dark:{background:"#111827",opacity:.9,rapidOpacity:.3,colors:{rapid:"#0ef6ae",cutting:"#3e85c7",laser:"#a855f7",processed:"#6b7280",boundingBox:"#e2e8f0",machineBed:"#f5a623",machineBedKeepout:"#df3b3b",grid:{major:"#77a9d7",minor:"#3e6e9e"},axes:{x:"#df3b3b",y:"#06b881",z:"#295d8d"}}},light:{background:"#e5e7eb",opacity:.9,rapidOpacity:.3,colors:{rapid:"#295d8d",cutting:"#111827",laser:"#FF0000",processed:"#9ca3af",boundingBox:"#4b5563",machineBed:"#b45309",machineBedKeepout:"#df3b3b",grid:{major:"#295d8d",minor:"#5191cc"},axes:{x:"#df3b3b",y:"#06b881",z:"#295d8d"}}},"flexoki-dark":{background:"#100f0f",opacity:.9,rapidOpacity:.3,colors:{rapid:"#DA702C",cutting:"#3AA99F",laser:"#8B7EC8",processed:"#6f6e69",boundingBox:"#cecdc3",machineBed:"#ffcc66",machineBedKeepout:"#d14d41",grid:{major:"#a89984",minor:"#6f6e69"},axes:{x:"#d14d41",y:"#879a39",z:"#4385be"}}},"tokyo-night":{background:"#1a1b26",opacity:.9,rapidOpacity:.3,colors:{rapid:"#ff9e64",cutting:"#7dcfff",laser:"#bb9af7",processed:"#565f89",boundingBox:"#c0caf5",machineBed:"#e0af68",machineBedKeepout:"#f7768e",grid:{major:"#7aa2f7",minor:"#414868"},axes:{x:"#f7768e",y:"#9ece6a",z:"#7aa2f7"}}},"gruvbox-light":{background:"#fbf1c7",opacity:.9,rapidOpacity:.3,colors:{rapid:"#d65d0e",cutting:"#3c3836",laser:"#b16286",processed:"#928374",boundingBox:"#7c6f64",machineBed:"#d79921",machineBedKeepout:"#cc241d",grid:{major:"#7c6f64",minor:"#a89984"},axes:{x:"#cc241d",y:"#98971a",z:"#458588"}}},"ayu-dark":{background:"#0b0e14",opacity:.9,rapidOpacity:.3,colors:{rapid:"#FFA659",cutting:"#73D0FF",laser:"#DFBFFF",processed:"#6E7C8F",boundingBox:"#CBCCC6",machineBed:"#FFD173",machineBedKeepout:"#F28779",grid:{major:"#77a9d7",minor:"#3e6590"},axes:{x:"#F28779",y:"#D5FF80",z:"#5CCFE6"}}},"ayu-light":{background:"#fafafa",opacity:.9,rapidOpacity:.3,colors:{rapid:"#FA8D3E",cutting:"#22A4E6",laser:"#A37ACC",processed:"#ADAEB1",boundingBox:"#5C6773",machineBed:"#F2AE49",machineBedKeepout:"#F07171",grid:{major:"#5c6773",minor:"#9aacba"},axes:{x:"#F07171",y:"#86B300",z:"#55B4D4"}}}};exports.GCodeSVGRenderer=e.GCodeSVGRenderer;exports.GCodeViewer=e.GCodeViewer;exports.ViewCube=e.ViewCube;exports.defaultGCodeViewerOptions=e.defaultGCodeViewerOptions;exports.defaultGCodeViewerTheme=e.defaultGCodeViewerTheme;exports.gCodeViewerThemePresets=a;
|
package/dist/viewer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as o, a as i, V as c, d as r, b as n } from "./GCodeSVGRenderer-
|
|
1
|
+
import { G as o, a as i, V as c, d as r, b as n } from "./GCodeSVGRenderer-BIdf-Kth.js";
|
|
2
2
|
const e = {
|
|
3
3
|
dark: {
|
|
4
4
|
background: "#111827",
|
|
@@ -9,7 +9,7 @@ const e = {
|
|
|
9
9
|
cutting: "#3e85c7",
|
|
10
10
|
laser: "#a855f7",
|
|
11
11
|
processed: "#6b7280",
|
|
12
|
-
boundingBox: "#
|
|
12
|
+
boundingBox: "#e2e8f0",
|
|
13
13
|
machineBed: "#f5a623",
|
|
14
14
|
machineBedKeepout: "#df3b3b",
|
|
15
15
|
grid: { major: "#77a9d7", minor: "#3e6e9e" },
|
|
@@ -25,7 +25,7 @@ const e = {
|
|
|
25
25
|
cutting: "#111827",
|
|
26
26
|
laser: "#FF0000",
|
|
27
27
|
processed: "#9ca3af",
|
|
28
|
-
boundingBox: "#
|
|
28
|
+
boundingBox: "#4b5563",
|
|
29
29
|
machineBed: "#b45309",
|
|
30
30
|
machineBedKeepout: "#df3b3b",
|
|
31
31
|
grid: { major: "#295d8d", minor: "#5191cc" },
|
|
@@ -41,7 +41,7 @@ const e = {
|
|
|
41
41
|
cutting: "#3AA99F",
|
|
42
42
|
laser: "#8B7EC8",
|
|
43
43
|
processed: "#6f6e69",
|
|
44
|
-
boundingBox: "#
|
|
44
|
+
boundingBox: "#cecdc3",
|
|
45
45
|
machineBed: "#ffcc66",
|
|
46
46
|
machineBedKeepout: "#d14d41",
|
|
47
47
|
grid: { major: "#a89984", minor: "#6f6e69" },
|
|
@@ -57,7 +57,7 @@ const e = {
|
|
|
57
57
|
cutting: "#7dcfff",
|
|
58
58
|
laser: "#bb9af7",
|
|
59
59
|
processed: "#565f89",
|
|
60
|
-
boundingBox: "#
|
|
60
|
+
boundingBox: "#c0caf5",
|
|
61
61
|
machineBed: "#e0af68",
|
|
62
62
|
machineBedKeepout: "#f7768e",
|
|
63
63
|
grid: { major: "#7aa2f7", minor: "#414868" },
|
|
@@ -73,7 +73,7 @@ const e = {
|
|
|
73
73
|
cutting: "#3c3836",
|
|
74
74
|
laser: "#b16286",
|
|
75
75
|
processed: "#928374",
|
|
76
|
-
boundingBox: "#
|
|
76
|
+
boundingBox: "#7c6f64",
|
|
77
77
|
machineBed: "#d79921",
|
|
78
78
|
machineBedKeepout: "#cc241d",
|
|
79
79
|
grid: { major: "#7c6f64", minor: "#a89984" },
|
|
@@ -89,7 +89,7 @@ const e = {
|
|
|
89
89
|
cutting: "#73D0FF",
|
|
90
90
|
laser: "#DFBFFF",
|
|
91
91
|
processed: "#6E7C8F",
|
|
92
|
-
boundingBox: "#
|
|
92
|
+
boundingBox: "#CBCCC6",
|
|
93
93
|
machineBed: "#FFD173",
|
|
94
94
|
machineBedKeepout: "#F28779",
|
|
95
95
|
grid: { major: "#77a9d7", minor: "#3e6590" },
|