From e34ba072a7320f937b88d12a4ee85428672b7b02 Mon Sep 17 00:00:00 2001 From: kim Date: Mon, 5 Oct 2026 23:06:56 +0900 Subject: [PATCH] =?UTF-8?q?feat(workshop):=20scad=203D=20=EB=B7=B0?= =?UTF-8?q?=EC=96=B4=20=E2=80=94=20import=20=ED=95=9C=20=EC=A4=84=EC=A7=9C?= =?UTF-8?q?=EB=A6=AC=20.scad=EB=8A=94=20STL=EC=9D=84=20=EC=A7=81=EC=A0=91?= =?UTF-8?q?=20=EC=9D=BD=EC=96=B4=20=EB=A9=B4=20=EC=83=89(vertexColors)=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C,=20=EB=8B=AB=ED=9E=88=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=80=20=EB=A9=94=EC=8B=9C=EB=8F=84=20=EC=97=B4=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- web-ui/html/scad-viewer.html | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/web-ui/html/scad-viewer.html b/web-ui/html/scad-viewer.html index f0971af..8f2c055 100644 --- a/web-ui/html/scad-viewer.html +++ b/web-ui/html/scad-viewer.html @@ -73,14 +73,29 @@ async function load(){ const base='/api/workshop/scad-stl?projectId='+encodeURIComponent(pid)+'&relPath='+encodeURIComponent(rel); document.getElementById('src').href='/api/files/workshop/'+encodeURIComponent(pid)+'/'+rel.split('/').map(encodeURIComponent).join('/'); try{ - const r=await fetch(base,{credentials:'include',headers:authH()}); + // import("x.stl"); 한 줄짜리 .scad면 OpenSCAD를 거치지 않고 그 STL을 그대로 읽는다(면 색 보존 + 닫히지 않은 메시도 OK). + let r=null; + try{ + const sr=await fetch(document.getElementById('src').href,{credentials:'include',headers:authH()}); + if(sr.ok){ + const code=(await sr.text()).replace(/\/\*[\s\S]*?\*\//g,'').replace(/\/\/.*$/gm,'').trim(); + const m=code.match(/^import\s*\(\s*"([^"]+\.stl)"\s*\)\s*;$/i); + if(m){ + const parts=rel.split('/').slice(0,-1); + for(const seg of m[1].split('/')){ if(seg==='..')parts.pop(); else if(seg&&seg!=='.')parts.push(seg); } + const fr=await fetch('/api/files/workshop/'+encodeURIComponent(pid)+'/'+parts.map(encodeURIComponent).join('/'),{credentials:'include',headers:authH()}); + if(fr.ok)r=fr; + } + } + }catch(e){ r=null; } + if(!r)r=await fetch(base,{credentials:'include',headers:authH()}); if(!r.ok){let d={};try{d=await r.json();}catch(e){} throw new Error((d.detail||d.error||('서버 오류 '+r.status)));} const buf=await r.arrayBuffer(); const dl=document.getElementById('dl'); dl.href=URL.createObjectURL(new Blob([buf],{type:'application/octet-stream'})); dl.download=(rel.split('/').pop()||'model').replace(/\.scad$/i,'')+'.stl'; const geo=new THREE.STLLoader().parse(buf); geo.computeVertexNormals(); geo.computeBoundingBox(); const bb=geo.boundingBox, size=new THREE.Vector3(); bb.getSize(size); - mesh=new THREE.Mesh(geo,new THREE.MeshStandardMaterial({color:0x6aa5e8,metalness:0.1,roughness:0.55,side:THREE.DoubleSide,flatShading:false})); + mesh=new THREE.Mesh(geo,new THREE.MeshStandardMaterial({color:geo.hasColors?0xffffff:0x6aa5e8,vertexColors:!!geo.hasColors,metalness:0.1,roughness:0.55,side:THREE.DoubleSide,flatShading:false})); scene.add(mesh); const edges=new THREE.LineSegments(new THREE.EdgesGeometry(geo,35),new THREE.LineBasicMaterial({color:0x1d3552,transparent:true,opacity:0.35})); mesh.add(edges);