feat: STL 편집기 — 회전·뒤집기·거울 축을 STL 기준으로, 뷰포트에 X/Y/Z 축 라벨 표시
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7520e183b1
commit
393a82279b
1 file changed
+36
-7
@@ -71,8 +71,8 @@
|
||||
// 아니라 three 원점에 둔다.
|
||||
const grid = new THREE.GridHelper(500, 50, 0x666666, 0x333333);
|
||||
scene.add(grid);
|
||||
// 축 헬퍼(Red=X, Green=Y, Blue=Z) — three 좌표계 시각화.
|
||||
scene.add(new THREE.AxesHelper(80));
|
||||
// STL 좌표 축(X=빨강, Y=초록, Z=파랑) + 라벨. three 축으로는 STL X=x, STL Y=-z, STL Z=y.
|
||||
addStlAxes(80);
|
||||
|
||||
// 구멍 위치 마커(작은 구) — 기본 숨김.
|
||||
holeMarker = new THREE.Mesh(
|
||||
@@ -94,6 +94,31 @@
|
||||
animate();
|
||||
}
|
||||
|
||||
function makeAxisLabel(text, color) {
|
||||
const c = document.createElement('canvas'); c.width = c.height = 64;
|
||||
const g = c.getContext('2d');
|
||||
g.font = 'bold 44px sans-serif'; g.textAlign = 'center'; g.textBaseline = 'middle';
|
||||
g.fillStyle = color; g.fillText(text, 32, 34);
|
||||
const sp = new THREE.Sprite(new THREE.SpriteMaterial({ map: new THREE.CanvasTexture(c), depthTest: false, transparent: true }));
|
||||
sp.scale.set(14, 14, 1);
|
||||
sp.renderOrder = 10;
|
||||
return sp;
|
||||
}
|
||||
function addStlAxes(len) {
|
||||
const axes = [
|
||||
{ name: 'X', color: '#ff4d4d', dir: new THREE.Vector3(1, 0, 0) },
|
||||
{ name: 'Y', color: '#4dff4d', dir: new THREE.Vector3(0, 0, -1) },
|
||||
{ name: 'Z', color: '#5c8dff', dir: new THREE.Vector3(0, 1, 0) },
|
||||
];
|
||||
axes.forEach(({ name, color, dir }) => {
|
||||
const geo = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(0, 0, 0), dir.clone().multiplyScalar(len)]);
|
||||
scene.add(new THREE.Line(geo, new THREE.LineBasicMaterial({ color })));
|
||||
const lbl = makeAxisLabel(name, color);
|
||||
lbl.position.copy(dir).multiplyScalar(len + 9);
|
||||
scene.add(lbl);
|
||||
});
|
||||
}
|
||||
|
||||
function resize() {
|
||||
if (!renderer || !vpEl) return;
|
||||
const w = vpEl.clientWidth, h = vpEl.clientHeight;
|
||||
@@ -197,7 +222,8 @@
|
||||
const rz = (parseFloat(panelEl.querySelector('#ce-rz').value) || 0) * Math.PI / 180;
|
||||
const sc = Math.max(0.01, parseFloat(panelEl.querySelector('#ce-scale').value) || 1);
|
||||
mesh.position.set(nx, nz, -ny); // threeX=nativeX, threeY=nativeZ, threeZ=-nativeY
|
||||
mesh.rotation.set(rx, ry, rz);
|
||||
// 패널 회전은 STL 축 기준(X=X, Y=three -Z, Z=three Y): rx→three.x, rz(STL Z)→three.y, ry(STL Y)→three.z 부호반전.
|
||||
mesh.rotation.set(rx, rz, -ry);
|
||||
// 배율(균일) — 거울 버튼이 scale 일부 축을 -로 만들 수 있으므로, 입력은 절댓값 배율로 취급해
|
||||
// 각 축 절댓값을 sc 로 맞추되 부호는 보존.
|
||||
mesh.scale.x = Math.sign(mesh.scale.x || 1) * sc;
|
||||
@@ -228,19 +254,22 @@
|
||||
const ny = panelEl.querySelector('#ce-y'); if (ny) ny.value = (-mesh.position.z).toFixed(2);
|
||||
const nz = panelEl.querySelector('#ce-z'); if (nz) nz.value = mesh.position.y.toFixed(2);
|
||||
const rx = panelEl.querySelector('#ce-rx'); if (rx) rx.value = (mesh.rotation.x * 180 / Math.PI).toFixed(1);
|
||||
const ry = panelEl.querySelector('#ce-ry'); if (ry) ry.value = (mesh.rotation.y * 180 / Math.PI).toFixed(1);
|
||||
const rz = panelEl.querySelector('#ce-rz'); if (rz) rz.value = (mesh.rotation.z * 180 / Math.PI).toFixed(1);
|
||||
const ry = panelEl.querySelector('#ce-ry'); if (ry) ry.value = (-mesh.rotation.z * 180 / Math.PI).toFixed(1);
|
||||
const rz = panelEl.querySelector('#ce-rz'); if (rz) rz.value = (mesh.rotation.y * 180 / Math.PI).toFixed(1);
|
||||
const sc = panelEl.querySelector('#ce-scale'); if (sc) sc.value = Math.abs(mesh.scale.x).toFixed(2);
|
||||
}
|
||||
|
||||
// 패널 라벨은 STL 축 기준 — three 축으로 변환(STL Y=three Z, STL Z=three Y).
|
||||
const STL_TO_THREE = { x: 'x', y: 'z', z: 'y' };
|
||||
function flipAxis(ax) {
|
||||
if (!mesh) return;
|
||||
mesh.rotation[ax] += Math.PI;
|
||||
mesh.rotation[STL_TO_THREE[ax]] += Math.PI;
|
||||
refreshPanel();
|
||||
}
|
||||
function mirrorAxis(ax) {
|
||||
if (!mesh) return;
|
||||
mesh.scale[ax] = -mesh.scale[ax];
|
||||
const a3 = STL_TO_THREE[ax];
|
||||
mesh.scale[a3] = -mesh.scale[a3];
|
||||
refreshPanel();
|
||||
}
|
||||
function centerModel() {
|
||||
|
||||
Reference in new issue
Block a user