using System; using System.Collections.Generic; using UnityEngine; /// /// ·Îº¿ÀÇ À̵¿ °æ·Î Æ÷ÀÎÆ®(Point/Marker)¸¦ 3D ¿ùµå »ó¿¡ ½Ã°¢ÀûÀ¸·Î »ý¼ºÇÏ°í °ü¸®ÇÏ´Â ºä Ŭ·¡½º /// Æ÷ÀÎÆ®ÀÇ »ý¼º(Instantiate), À§Ä¡ °»½Å, »èÁ¦, Àüü ´Ù½Ã ±×¸®±â ±â´ÉÀ» ´ã´ç /// public class PointManagerView : MonoBehaviour { [SerializeField] private GameObject pointPrefab; // 3D °ø°£¿¡ »ý¼ºµÉ Æ÷ÀÎÆ®(¸¶Ä¿) ÇÁ¸®ÆÕ private List activePoints = new List(); // ÇöÀç Ȱ¼ºÈ­µÈ Æ÷ÀÎÆ® °ÔÀÓ ¿ÀºêÁ§Æ®µéÀ» °ü¸®ÇÏ´Â ¸®½ºÆ® public Transform robotBaseTransform; // ·Îº¿ÁÂÇ¥ÀÇ ±âÁØÀÌ µÇ´Â Ãà À§Ä¡ [SerializeField] public GameObject movingAlert; // ·Îº¿ÀÌ À̵¿ ÁßÀÏ ¶§ »ç¿ëÀÚ¿¡°Ô °æ°í¸¦ ÁÖ´Â UI /// /// µå·¡±× ½Ã º¸¿©Áú ¹ÝÅõ¸í °í½ºÆ® ·Îº¿ÀÇ IK(Inverse Kinematics) Á¦¾î ³ëµå /// [SerializeField] [Tooltip("¹ÝÅõ¸í ·Îº¿ ¸ðµ¨ÀÇ IK")] public HybridInverseKinematicsNode kinematicsNode; void Start() { movingAlert.SetActive(false); } private Vector3 ConvertRobotDataToVector3(RobotData pose) { float x = Convert.ToSingle(pose.x / -1000.0); // Robot X(mm) -> Unity X(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); } /// /// ÁöÁ¤µÈ ·Îº¿ ÁÂÇ¥(Pose)¿¡ »õ·Î¿î Æ÷ÀÎÆ®(¸¶Ä¿)¸¦ »ý¼º /// /// Æ÷ÀÎÆ®ÀÇ À§Ä¡ µ¥ÀÌÅÍ /// ¸®½ºÆ® »óÀÇ À妽º (½Äº°¿ë) public void CreatePoint(RobotData pose, int index) { if(pointPrefab == null) { Debug.Log("¸¶Ä¿ ÇÁ¸®ÆÕÀÌ ÇÒ´çµÇÁö ¾Ê¾Ò½À´Ï´Ù."); return; } Vector3 position = ConvertRobotDataToVector3(pose); // º¯È¯µÈ ¿ùµå ÁÂÇ¥¿¡ »ý¼º GameObject pointObj = Instantiate(pointPrefab, position, Quaternion.identity, this.transform); Debug.Log($"¸¶Ä¿ ÇÁ¸®ÆÕ »ý¼ºµÊ, À§Ä¡: {position}"); Debug.Log($"·Îº¿ ±âÁØÁ¡(root ÁÂÇ¥): {robotBaseTransform.position}"); //pointObj.transform.localRotation = Quaternion.identity; activePoints.Add(pointObj); RobotPoint pointComponent = pointObj.GetComponent(); if (pointComponent != null) { pointComponent.pointIndex = activePoints.Count - 1; } else { Debug.LogError("pointÇÁ¸®ÆÕ¿¡ RobotPoint½ºÅ©¸³Æ®°¡ ¾øÀ½"); } } /// /// ƯÁ¤ À妽ºÀÇ Æ÷ÀÎÆ® À§Ä¡¸¦ °»½Å (½Ç½Ã°£ µå·¡±× µî) /// /// °»½ÅÇÒ Æ÷ÀÎÆ® À妽º /// »õ·Î¿î Unity ¿ùµå ÁÂÇ¥ public void UpdatePointPosition(int index, Vector3 pose) { if (index < 0 || index >= activePoints.Count) return; activePoints[index].transform.position = pose; } /// /// ƯÁ¤ À妽ºÀÇ Æ÷ÀÎÆ®¸¦ »èÁ¦ÇÏ°í ¸®½ºÆ®¿¡¼­ Á¦°Å /// public void DeletePoint(int index) { if (index < 0 || index >= activePoints.Count) return; Destroy(activePoints[index]); activePoints.RemoveAt(index); } /// /// ±âÁ¸ Æ÷ÀÎÆ®µéÀ» ¸ðµÎ Áö¿ì°í, ÁÖ¾îÁø µ¥ÀÌÅÍ ¸®½ºÆ®´ë·Î ´Ù½Ã ±×¸² /// (ÇÁ·Î±×·¥ ·Îµå, ¸®¼Â, ´ë±Ô¸ð º¯°æ ½Ã È£Ãâ) /// public void RedrawPoints(List poses) { foreach (var point in activePoints) Destroy(point); activePoints.Clear(); if (poses == null) return; for (int i= 0; i < poses.Count; i++) CreatePoint(poses[i], i); } }