2025-11-06 20:14:27 +09:00
|
|
|
|
using System;
|
2025-10-30 09:31:05 +09:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-19 18:38:48 +09:00
|
|
|
|
public class PointManagerView : MonoBehaviour
|
2025-10-30 09:31:05 +09:00
|
|
|
|
{
|
2025-11-06 20:14:27 +09:00
|
|
|
|
[SerializeField] private GameObject pointPrefab;
|
2025-10-30 09:31:05 +09:00
|
|
|
|
private List<GameObject> activePoints = new List<GameObject>();
|
2025-11-21 13:18:03 +09:00
|
|
|
|
public Transform robotBaseTransform; // <20>κ<EFBFBD><CEBA><EFBFBD>ǥ<EFBFBD><C7A5> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ǵ<EFBFBD> <20><> <20><>ġ
|
2025-10-30 09:31:05 +09:00
|
|
|
|
|
2025-11-06 20:14:27 +09:00
|
|
|
|
[SerializeField] public GameObject movingAlert;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IK")]
|
|
|
|
|
|
public HybridInverseKinematicsNode kinematicsNode;
|
|
|
|
|
|
|
2025-11-07 16:26:43 +09:00
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
movingAlert.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-06 20:14:27 +09:00
|
|
|
|
private Vector3 ConvertRobotDataToVector3(RobotData pose)
|
2025-10-30 09:31:05 +09:00
|
|
|
|
{
|
2025-11-25 15:15:54 +09:00
|
|
|
|
float x = Convert.ToSingle(pose.x / -1000.0); // Robot X(mm) -> Unity X(m)
|
2025-11-06 20:14:27 +09:00
|
|
|
|
float y = Convert.ToSingle(pose.z / 1000.0); // Robot Z(mm) -> Unity Y(m)
|
|
|
|
|
|
float z = Convert.ToSingle(pose.y / -1000.0); // Robot Y(mm) -> Unity Z(m)
|
|
|
|
|
|
return new Vector3(x, y, z);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-25 15:15:54 +09:00
|
|
|
|
private Quaternion ConvertRobotDataToQuaternion(RobotData pose)
|
|
|
|
|
|
{
|
|
|
|
|
|
float rx = pose.rx;
|
|
|
|
|
|
float ry = pose.z;
|
|
|
|
|
|
float rz = pose.y;
|
|
|
|
|
|
|
|
|
|
|
|
return Quaternion.Euler(pose.rx, -pose.rz, pose.ry);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-06 20:14:27 +09:00
|
|
|
|
public void CreatePoint(RobotData pose, int index)
|
|
|
|
|
|
{
|
2025-11-25 15:15:54 +09:00
|
|
|
|
if(pointPrefab == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("<22><>Ŀ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ҵ<EFBFBD><D2B4><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-27 19:05:25 +09:00
|
|
|
|
Vector3 position = ConvertRobotDataToVector3(pose);
|
2025-11-25 15:15:54 +09:00
|
|
|
|
//Quaternion localRot = ConvertRobotDataToQuaternion(pose);
|
2025-11-21 13:18:03 +09:00
|
|
|
|
|
2025-11-25 15:15:54 +09:00
|
|
|
|
//Vector3 toolOffset = new Vector3(0.681004044f, -0.221942063f, -0.447616011f);
|
|
|
|
|
|
//Vector3 rotatedOffset = localRot * toolOffset;
|
|
|
|
|
|
//Vector3 finalLocalPos = localPos + rotatedOffset;
|
|
|
|
|
|
|
2025-11-27 19:05:25 +09:00
|
|
|
|
//Vector3 worldPos = localPos;
|
|
|
|
|
|
////Quaternion worldRot = localRot;
|
2025-11-25 15:15:54 +09:00
|
|
|
|
|
2025-11-27 19:05:25 +09:00
|
|
|
|
//// <20>κ<EFBFBD> Base<73><65> <20>ִٸ<D6B4>, <20><><EFBFBD><EFBFBD> <20><>ǥ<EFBFBD><C7A5> <20><><EFBFBD><EFBFBD> <20><>ǥ<EFBFBD><C7A5> <20><>ȯ
|
|
|
|
|
|
//if (robotBaseTransform != null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// worldPos = robotBaseTransform.TransformPoint(localPos);
|
|
|
|
|
|
// //worldRot = robotBaseTransform.rotation * localRot;
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Debug.LogWarning("PointManagerView: RobotBaseTransform<72><6D> <20>Ҵ<EFBFBD><D2B4><EFBFBD><EFBFBD><EFBFBD> <20>ʾ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>˴ϴ<CBB4>.");
|
|
|
|
|
|
//}
|
2025-11-21 13:18:03 +09:00
|
|
|
|
|
|
|
|
|
|
// <20><>ȯ<EFBFBD><C8AF> <20><><EFBFBD><EFBFBD> <20><>ǥ<EFBFBD><C7A5> <20><><EFBFBD><EFBFBD>
|
2025-11-27 19:05:25 +09:00
|
|
|
|
GameObject pointObj = Instantiate(pointPrefab, position, Quaternion.identity, this.transform);
|
|
|
|
|
|
Debug.Log($"<22><>Ŀ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>ġ: {position}");
|
|
|
|
|
|
Debug.Log($"<22>κ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(root <20><>ǥ): {robotBaseTransform.position}");
|
2025-11-25 15:15:54 +09:00
|
|
|
|
|
|
|
|
|
|
//pointObj.transform.localRotation = Quaternion.identity;
|
2025-10-30 09:31:05 +09:00
|
|
|
|
activePoints.Add(pointObj);
|
2025-11-06 20:14:27 +09:00
|
|
|
|
|
|
|
|
|
|
RobotPoint pointComponent = pointObj.GetComponent<RobotPoint>();
|
|
|
|
|
|
if (pointComponent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
pointComponent.pointIndex = activePoints.Count - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("point<6E><74><EFBFBD><EFBFBD><EFBFBD>տ<EFBFBD> RobotPoint<6E><74>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD>");
|
|
|
|
|
|
}
|
2025-10-30 09:31:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-10 19:14:16 +09:00
|
|
|
|
public void UpdatePointPosition(int index, Vector3 pose)
|
2025-10-30 09:31:05 +09:00
|
|
|
|
{
|
|
|
|
|
|
if (index < 0 || index >= activePoints.Count) return;
|
2025-11-10 19:14:16 +09:00
|
|
|
|
activePoints[index].transform.position = pose;
|
2025-10-30 09:31:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeletePoint(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (index < 0 || index >= activePoints.Count) return;
|
|
|
|
|
|
Destroy(activePoints[index]);
|
|
|
|
|
|
activePoints.RemoveAt(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RedrawPoints(List<RobotData> poses)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var point in activePoints) Destroy(point);
|
|
|
|
|
|
activePoints.Clear();
|
2025-11-06 20:14:27 +09:00
|
|
|
|
if (poses == null) return;
|
|
|
|
|
|
for (int i= 0; i < poses.Count; i++) CreatePoint(poses[i], i);
|
2025-10-30 09:31:05 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|