Files
HDRobotics/Assets/Scripts/View/PathLineView.cs

70 lines
2.0 KiB
C#
Raw Normal View History

2025-11-06 20:14:27 +09:00
using System;
2025-10-30 09:31:05 +09:00
using System.Collections.Generic;
2025-11-06 20:14:27 +09:00
using System.Linq;
2025-10-30 09:31:05 +09:00
using UnityEngine;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD>
public interface IPathLineView
{
}
[RequireComponent(typeof(LineRenderer))]
public class PathLineView : MonoBehaviour, IPathLineView
{
private LineRenderer lineRenderer;
void Awake()
{
lineRenderer = GetComponent<LineRenderer>();
2025-11-06 20:14:27 +09:00
// Line Renderer <20><20><><EFBFBD><EFBFBD>
lineRenderer.startWidth = 0.01f;
lineRenderer.endWidth = 0.01f;
lineRenderer.material = new Material(Shader.Find("Legacy Shaders/Particles/Alpha Blended Premultiply"));
lineRenderer.startColor = Color.cyan;
lineRenderer.endColor = Color.cyan;
2025-10-30 09:31:05 +09:00
}
2025-11-06 20:14:27 +09:00
private Vector3 ConvertRobotDataToVector3(RobotData pose)
{
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);
}
/// <summary>
/// <20><><EFBFBD>α׷<CEB1><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>մ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>׸<EFBFBD>
/// </summary>
2025-10-30 09:31:05 +09:00
public void DrawPath(List<RobotData> poses)
{
if (poses == null || poses.Count < 2)
{
2025-11-06 20:14:27 +09:00
lineRenderer.positionCount = 0; // <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> 2<><32> <20≯<EFBFBD><CCB8≯<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
2025-10-30 09:31:05 +09:00
return;
}
2025-11-06 20:14:27 +09:00
Vector3[] positions = poses.Select(ConvertRobotDataToVector3).ToArray();
lineRenderer.positionCount = positions.Length;
lineRenderer.SetPositions(positions);
}
// <20>ǽð<C7BD> <20><><EFBFBD><EFBFBD> <20>׸<EFBFBD><D7B8><EFBFBD>
public void DrawPath(List<RobotData> poses, int modifiedIndex, RobotData tempPose)
{
if (poses == null || poses.Count < 2 ||
modifiedIndex < 0 || modifiedIndex >= poses.Count)
2025-10-30 09:31:05 +09:00
{
2025-11-06 20:14:27 +09:00
DrawPath(poses);
return;
2025-10-30 09:31:05 +09:00
}
2025-11-06 20:14:27 +09:00
Vector3[] positions = poses.Select(ConvertRobotDataToVector3).ToArray();
positions[modifiedIndex] = ConvertRobotDataToVector3(tempPose);
lineRenderer.positionCount = positions.Length;
lineRenderer.SetPositions(positions);
2025-10-30 09:31:05 +09:00
}
}