diff --git a/src/hooks/surface/useSurfaceShapeBatch.js b/src/hooks/surface/useSurfaceShapeBatch.js index e42a7025..54721d94 100644 --- a/src/hooks/surface/useSurfaceShapeBatch.js +++ b/src/hooks/surface/useSurfaceShapeBatch.js @@ -1451,6 +1451,50 @@ export function useSurfaceShapeBatch({ isHidden, setIsHidden }) { // 그룹화할 객체들 배열 (currentObject + relatedObjects) const objectsToGroup = [currentObject, ...relatedObjects] + // 회전 카운트 초기화 및 최초 상태 저장 + if (!currentObject.rotationCount) { + currentObject.rotationCount = 0 + } + + // 최초 회전일 때 (rotationCount === 0) 원본 상태 저장 + if (currentObject.rotationCount === 0) { + objectsToGroup.forEach((obj) => { + if (!obj.originalState) { + obj.originalState = { + left: obj.left, + top: obj.top, + angle: obj.angle || 0, + points: obj.type === 'QPolygon' ? JSON.parse(JSON.stringify(obj.points)) : null, + scaleX: obj.scaleX || 1, + scaleY: obj.scaleY || 1, + } + } + }) + } + + // 회전 카운트 증가 (먼저 증가시켜서 목표 각도 계산) + currentObject.rotationCount = (currentObject.rotationCount + 1) % 4 + + // 목표 회전 각도 계산 (원본 기준) + const targetAngle = currentObject.rotationCount * 90 + + // 원본 상태로 먼저 복원한 후 목표 각도만큼 회전 + objectsToGroup.forEach((obj) => { + if (obj.originalState) { + // 원본 상태로 복원 + obj.set({ + left: obj.originalState.left, + top: obj.originalState.top, + angle: obj.originalState.angle, + scaleX: obj.originalState.scaleX, + scaleY: obj.originalState.scaleY, + }) + if (obj.originalState.points && obj.type === 'QPolygon') { + obj.set({ points: JSON.parse(JSON.stringify(obj.originalState.points)) }) + } + } + }) + // 기존 객체들을 캔버스에서 제거 objectsToGroup.forEach((obj) => canvas.remove(obj)) @@ -1463,12 +1507,8 @@ export function useSurfaceShapeBatch({ isHidden, setIsHidden }) { // 그룹을 캔버스에 추가 canvas.add(group) - // 현재 회전값에 90도 추가 - const currentAngle = group.angle || 0 - const newAngle = (currentAngle + 90) % 360 - - // 그룹 전체를 회전 - group.rotate(newAngle) + // 목표 각도로 회전 (원본 기준) + group.rotate(targetAngle) group.setCoords() // 그룹을 해제하고 개별 객체로 복원