개선
This commit is contained in:
@@ -53,12 +53,15 @@ namespace SHI.modal
|
||||
private float _yawStart;
|
||||
private float _pitchStart;
|
||||
private Quaternion _modelStartRot;
|
||||
private Vector3 _modelStartPos; // RMB 드래그 시작 시 모델 위치
|
||||
private Vector3 _rmbPivot; // RMB 회전의 피벗(모델 중심)
|
||||
|
||||
private readonly Dictionary<Guid, GameObject> _idToObject = new Dictionary<Guid, GameObject>();
|
||||
private readonly Dictionary<GameObject, (Renderer[] rends, UnityEngine.Material[][] originals)> _matCache = new Dictionary<GameObject, (Renderer[], UnityEngine.Material[][])>();
|
||||
private GameObject? _root;
|
||||
private Guid? _focusedId;
|
||||
|
||||
|
||||
public async UniTask<IEnumerable<ModelDetailListItemData>> LoadModelAsync(string path, CancellationToken ct)
|
||||
{
|
||||
Debug.Log($"ModelDetailView.LoadModelAsync: {path}");
|
||||
@@ -345,8 +348,8 @@ namespace SHI.modal
|
||||
dist = Mathf.Clamp(dist, 1f, 1e4f);
|
||||
_viewCamera.transform.position = center + new Vector3(1, 0.5f, 1).normalized * dist;
|
||||
_viewCamera.transform.LookAt(center);
|
||||
_viewCamera.nearClipPlane = Mathf.Max(0.01f, dist - radius * 2f);
|
||||
_viewCamera.farClipPlane = dist + radius * 4f;
|
||||
//_viewCamera.nearClipPlane = Mathf.Max(0.01f, dist - radius * 2f);
|
||||
//_viewCamera.farClipPlane = dist + radius * 4f;
|
||||
|
||||
_orbitTarget = center;
|
||||
_orbitDistance = Vector3.Distance(_viewCamera.transform.position, _orbitTarget);
|
||||
@@ -530,7 +533,7 @@ namespace SHI.modal
|
||||
// 드래그 상태 전이 처리 (점프 방지)
|
||||
if (Input.GetMouseButtonDown(2)) { _mmbDragging = true; _mmbLastPos = Input.mousePosition; }
|
||||
if (Input.GetMouseButtonUp(2)) { _mmbDragging = false; }
|
||||
if (Input.GetMouseButtonDown(1)) { _rmbDragging = true; _rmbStartPos = Input.mousePosition; _yawStart = _yaw; _pitchStart = _pitch; if (_root != null) _modelStartRot = _root.transform.rotation; }
|
||||
if (Input.GetMouseButtonDown(1)) { _rmbDragging = true; _rmbStartPos = Input.mousePosition; _yawStart = _yaw; _pitchStart = _pitch; if (_root != null) { _modelStartRot = _root.transform.rotation; _modelStartPos = _root.transform.position; } _rmbPivot = _orbitTarget; }
|
||||
if (Input.GetMouseButtonUp(1)) { _rmbDragging = false; }
|
||||
|
||||
// 가운데 버튼: 모델 이동 (좌/우/상/하) - 카메라 기준, 픽셀 델타 기반
|
||||
@@ -565,7 +568,7 @@ namespace SHI.modal
|
||||
_orbitTarget += deltaZ;
|
||||
}
|
||||
|
||||
// 오른쪽 버튼: 모델 회전 (카메라 기준 yaw/pitch)
|
||||
// 오른쪽 버튼: 모델 회전 (카메라 기준 yaw/pitch) - 모델 중심(_orbitTarget) 기준으로 회전
|
||||
if (_rmbDragging && _root != null)
|
||||
{
|
||||
Vector3 cur = Input.mousePosition;
|
||||
@@ -573,10 +576,16 @@ namespace SHI.modal
|
||||
// 반전: 좌우/상하 모두 반대 방향으로 회전
|
||||
float yaw = -dpAbs.x * rotateDegPerPixel; // 좌우 반전
|
||||
float pitch = dpAbs.y * rotateDegPerPixel; // 위아래 반전
|
||||
// 카메라 기준 축으로 모델 회전
|
||||
|
||||
// 카메라 기준 축으로 회전 행렬 구성
|
||||
Quaternion yawQ = Quaternion.AngleAxis(yaw, _viewCamera.transform.up);
|
||||
Quaternion pitchQ = Quaternion.AngleAxis(pitch, _viewCamera.transform.right);
|
||||
_root.transform.rotation = yawQ * pitchQ * _modelStartRot;
|
||||
Quaternion r = yawQ * pitchQ;
|
||||
|
||||
// 피벗(_rmbPivot, 보통 모델 중심) 기준으로 위치+회전 동시 적용
|
||||
Vector3 startVec = _modelStartPos - _rmbPivot;
|
||||
_root.transform.position = _rmbPivot + r * startVec;
|
||||
_root.transform.rotation = r * _modelStartRot;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user