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-06 20:14:27 +09:00
|
|
|
|
float x = Convert.ToSingle(pose.x / -1000.0); // mm -> m
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CreatePoint(RobotData pose, int index)
|
|
|
|
|
|
{
|
2025-11-21 13:18:03 +09:00
|
|
|
|
Vector3 localPos = ConvertRobotDataToVector3(pose);
|
|
|
|
|
|
Vector3 worldPos = localPos;
|
|
|
|
|
|
|
|
|
|
|
|
// <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);
|
|
|
|
|
|
}
|
|
|
|
|
|
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>.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȯ<EFBFBD><C8AF> <20><><EFBFBD><EFBFBD> <20><>ǥ<EFBFBD><C7A5> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
GameObject pointObj = Instantiate(pointPrefab, worldPos, Quaternion.identity, this.transform);
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|