Add verification: src/model.js
This commit is contained in:
1 parent
c23ab468ad
commit
2fa7d13e94
1 file changed
+34
@@ -0,0 +1,34 @@
|
||||
// Build slab and hollow wall geometry from parsed DXF data.
|
||||
function createCatchpitModel({entities,dimensionTexts,outlineLayer,heightMm,baseThicknessMm,autoHeight}){
|
||||
const found=CatchpitDxf.closedLoops(entities,outlineLayer);
|
||||
if(!found.length)throw Error('외곽선을 찾지 못했습니다. LN_out 레이어를 확인하세요.');
|
||||
const dimLines=entities.filter(e=>e.layer==='DIM'&&e.type==='LINE'&&e.pts?.length===2);
|
||||
const candidates=found.map(poly=>({poly,dims:CatchpitDxf.loopDims(poly,dimLines,dimensionTexts),area:Math.abs(CatchpitDxf.area(poly))})).filter(c=>c.dims).sort((a,b)=>a.dims.score-b.dims.score||b.area-a.area);
|
||||
if(!candidates.length)throw Error('평면 외곽에 대응하는 가로·세로 DIM 치수를 찾지 못했습니다.');
|
||||
const chosen=candidates[0],outer=chosen.poly,minX=Math.min(...outer.map(p=>p.x)),minY=Math.min(...outer.map(p=>p.y));
|
||||
const insideLoops=found.filter(h=>h!==outer&&CatchpitDxf.inside(h[0],outer)).sort((a,b)=>Math.abs(CatchpitDxf.area(b))-Math.abs(CatchpitDxf.area(a)));
|
||||
if(!insideLoops.length)throw Error('벽체와 내부 공간을 분리하려면 평면도에 안쪽 경계선이 필요합니다.');
|
||||
const inner=insideLoops[0],scaleX=chosen.dims.scaleX*.001,scaleY=chosen.dims.scaleY*.001;
|
||||
let height=Number(heightMm)*.001,baseThickness=Number(baseThicknessMm)*.001,heightSource='manual';
|
||||
if(autoHeight){const used=chosen.dims.dyText;const vertical=dimensionTexts.filter(t=>Math.abs((((t.rotation%180)+180)%180)-90)<12&&t!==used).map(t=>({t,value:CatchpitDxf.dimValue(t.text)})).filter(v=>v.value&&v.value>=100).sort((a,b)=>b.value-a.value);if(vertical.length){height=vertical[0].value*.001;heightSource=`section DIM ${vertical[0].value} mm`;const slab=vertical.filter(v=>v.value<height*1000).sort((a,b)=>a.value-b.value)[0];if(slab)baseThickness=slab.value*.001}}
|
||||
if(!(height>0&&baseThickness>=0))throw Error('벽체 높이와 바닥 두께를 확인해 주세요.');
|
||||
const outerW=(Math.max(...outer.map(p=>p.x))-minX)*scaleX,outerH=(Math.max(...outer.map(p=>p.y))-minY)*scaleY,innerW=(Math.max(...inner.map(p=>p.x))-Math.min(...inner.map(p=>p.x)))*scaleX,innerH=(Math.max(...inner.map(p=>p.y))-Math.min(...inner.map(p=>p.y)))*scaleY;
|
||||
const wallThickness=((outerW-innerW)+(outerH-innerH))/4;
|
||||
const toModel=p=>({x:(p.x-minX)*scaleX,y:(p.y-minY)*scaleY});
|
||||
const parts=[{name:'바닥판',type:'base',footprint:outer.map(toModel),z0:-baseThickness,z1:0,color:'#3c9881',visible:true}];
|
||||
const edgePairs=[],unused=new Set(inner.map((_,i)=>i));
|
||||
for(let i=0;i<outer.length;i++){
|
||||
const a=outer[i],b=outer[(i+1)%outer.length],dx=b.x-a.x,dy=b.y-a.y,len=Math.hypot(dx,dy)||1;
|
||||
let best=-1,bestScore=Infinity;
|
||||
for(const k of unused){const q=inner[k],r=inner[(k+1)%inner.length],ex=r.x-q.x,ey=r.y-q.y,el=Math.hypot(ex,ey)||1,parallel=1-Math.abs((dx*ex+dy*ey)/(len*el)),dist=Math.hypot((a.x+b.x-q.x-r.x)/2,(a.y+b.y-q.y-r.y)/2);const score=parallel+dist/(len*2);if(score<bestScore){bestScore=score;best=k}}
|
||||
if(best<0)throw Error('안쪽 경계에서 벽체별 대응 구간을 찾지 못했습니다.');
|
||||
unused.delete(best);const q=inner[best],r=inner[(best+1)%inner.length],qa=Math.hypot(q.x-a.x,q.y-a.y)<=Math.hypot(r.x-a.x,r.y-a.y)?q:r;
|
||||
const innerStart=qa===q?best:(best+1)%inner.length,innerEnd=(innerStart+1)%inner.length;
|
||||
edgePairs.push({outerStart:i,outerEnd:(i+1)%outer.length,innerStart,innerEnd});
|
||||
}
|
||||
if(edgePairs.length<3)throw Error('평면 내부 경계에서 벽체를 만들 수 없습니다.');
|
||||
parts.push({name:'벽체',type:'wall',footprint:outer.map(toModel),innerFootprint:inner.map(toModel),edgePairs,z0:0,z1:height,color:'#438dcc',visible:true});
|
||||
return {modelData:{outer,inner,minX,minY,scaleX,scaleY,height,baseThickness,wallThickness,parts,dimX:chosen.dims.dx,dimY:chosen.dims.dy},heightSource};
|
||||
}
|
||||
|
||||
window.CatchpitModel={createCatchpitModel};
|
||||
Reference in new issue
Block a user