模型旋转预览
This commit is contained in:
@@ -25,7 +25,7 @@ namespace NBF
|
||||
int _width;
|
||||
int _height;
|
||||
bool _cacheTexture;
|
||||
Vector3 _rotating;
|
||||
// Vector3 _rotating;
|
||||
|
||||
const int RENDER_LAYER = 0;
|
||||
const int HIDDEN_LAYER = 10;
|
||||
@@ -80,7 +80,7 @@ namespace NBF
|
||||
ViewerSettings = settings;
|
||||
|
||||
Object prefab = Resources.Load(model);
|
||||
if(prefab == null) return;
|
||||
if (prefab == null) return;
|
||||
GameObject go = ((GameObject)Object.Instantiate(prefab));
|
||||
var joint = go.GetComponent<Joint>();
|
||||
if (joint != null)
|
||||
@@ -111,7 +111,7 @@ namespace NBF
|
||||
_model = null;
|
||||
}
|
||||
|
||||
_rotating = Vector3.zero;
|
||||
// _rotating = Vector3.zero;
|
||||
}
|
||||
|
||||
|
||||
@@ -205,11 +205,11 @@ namespace NBF
|
||||
|
||||
void Render(object param = null)
|
||||
{
|
||||
if (_rotating != Vector3.zero && this.modelRoot != null)
|
||||
{
|
||||
// 使用 Quaternion 来避免欧拉角带来的问题
|
||||
modelRoot.Rotate(_rotating, Space.World);
|
||||
}
|
||||
// if (_rotating != Vector3.zero && this.modelRoot != null)
|
||||
// {
|
||||
// // 使用 Quaternion 来避免欧拉角带来的问题
|
||||
// modelRoot.Rotate(_rotating, Space.World);
|
||||
// }
|
||||
|
||||
SetLayer(_root.gameObject, RENDER_LAYER);
|
||||
|
||||
@@ -236,18 +236,51 @@ namespace NBF
|
||||
|
||||
#region 旋转
|
||||
|
||||
public void StartRotate(Vector3 delta)
|
||||
// 在 ModelViewRenderImage 中添加新字段
|
||||
private Vector2 _lastMousePosition;
|
||||
|
||||
private bool _isDragging;
|
||||
|
||||
public void StartRotate(Vector2 currentMousePosition)
|
||||
{
|
||||
_rotating = delta;
|
||||
_lastMousePosition = currentMousePosition;
|
||||
_isDragging = true;
|
||||
}
|
||||
|
||||
public void UpdateRotation(Vector2 currentMousePosition)
|
||||
{
|
||||
if (!_isDragging || modelRoot == null || _camera == null) return;
|
||||
|
||||
Vector2 delta = currentMousePosition - _lastMousePosition;
|
||||
|
||||
// 使用适中的灵敏度
|
||||
float sensitivity = 0.2f;
|
||||
float rotX = -delta.y * sensitivity;
|
||||
float rotY = -delta.x * sensitivity;
|
||||
|
||||
Quaternion yRotation = Quaternion.AngleAxis(rotY, _camera.transform.up);
|
||||
Quaternion xRotation = Quaternion.AngleAxis(rotX, _camera.transform.right);
|
||||
|
||||
// 组合旋转并应用
|
||||
modelRoot.rotation = yRotation * xRotation * modelRoot.rotation;
|
||||
|
||||
_lastMousePosition = currentMousePosition;
|
||||
}
|
||||
|
||||
public void StopRotate()
|
||||
{
|
||||
_rotating = Vector3.zero;
|
||||
_isDragging = false;
|
||||
}
|
||||
|
||||
// 重置到初始状态的方法
|
||||
public void ResetToInitialRotation()
|
||||
{
|
||||
modelRoot.localRotation = Quaternion.identity;
|
||||
_isDragging = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region MyRegion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user