From 58becf0dea1515ae2e50d70d3813f9a4aaff25d0 Mon Sep 17 00:00:00 2001 From: Dan Birman Date: Sun, 10 Sep 2023 10:46:30 -0700 Subject: [PATCH] fix: fixing the line renderer to create properly and position correctly --- API/oursin/lines.py | 39 +++++++++++------- .../Prefabs/Objects/LineRenderer.prefab | 3 +- .../Assets/Scenes/UnityMouseRenderer.unity | 40 +++++++++++++++++++ .../Scripts/Managers/LineRendererManager.cs | 33 ++++++++------- 4 files changed, 85 insertions(+), 30 deletions(-) diff --git a/API/oursin/lines.py b/API/oursin/lines.py index 645c66df..995d470b 100644 --- a/API/oursin/lines.py +++ b/API/oursin/lines.py @@ -8,17 +8,11 @@ counter = 0 class Line: - def __init__(self, position= [0.0,0.0,0.0], color= '#FFFFFF'): + def __init__(self, position= [[0.0,0.0,0.0]], color= '#FFFFFF'): self.create() - position = utils.sanitize_vector3(position) - self.position = position - client.sio.emit('SetLinePosition', {self.id: position}) - - - color = utils.sanitize_color(color) - self.color = color - client.sio.emit('SetLineColor',{self.id: color}) + self.set_position(position) + self.set_color(color) def create(self): """Creates lines @@ -54,19 +48,21 @@ def set_position(self, position): Parameters ---------- - position : list of three floats - vertex positions of the line + position : list of vector3 [[ap,ml,dv],[ap,ml,dv]] + vertex positions of the line in the ReferenceAtlas space (um) Examples -------- - >>>l1.set_position([0, 0, 0]) + >>>l1.set_position([[0, 0, 0],[13200,11400,8000]]) """ if self.in_unity == False: raise Exception("Line does not exist in Unity, call create method first.") - position = utils.sanitize_vector3(position) + for i, vec3 in enumerate(position): + position[i] = utils.sanitize_vector3(vec3) self.position = position - client.sio.emit('SetLinePosition', {self.id: position}) + + client.sio.emit('SetLinePosition', {self.id: self.position}) def set_color(self, color): """Set the color of line renderer @@ -87,6 +83,21 @@ def set_color(self, color): self.color = color client.sio.emit('SetLineColor',{self.id: color}) +def create (n): + """Create Line objects + + Parameters + ---------- + n : int + Number of objects to create + """ + lines_list = [] + + for i in range(n): + line = Line() + lines_list.append(line) + + return lines_list def delete (lines_list): """Deletes lines diff --git a/UnityClient/Assets/Prefabs/Objects/LineRenderer.prefab b/UnityClient/Assets/Prefabs/Objects/LineRenderer.prefab index 57417820..22d55da2 100644 --- a/UnityClient/Assets/Prefabs/Objects/LineRenderer.prefab +++ b/UnityClient/Assets/Prefabs/Objects/LineRenderer.prefab @@ -75,10 +75,9 @@ LineRenderer: m_SortingOrder: 0 m_Positions: - {x: 0, y: 0, z: 0} - - {x: 0, y: 0, z: 1} m_Parameters: serializedVersion: 3 - widthMultiplier: 1 + widthMultiplier: 0.1 widthCurve: serializedVersion: 2 m_Curve: diff --git a/UnityClient/Assets/Scenes/UnityMouseRenderer.unity b/UnityClient/Assets/Scenes/UnityMouseRenderer.unity index 9a75abe4..a207fabf 100644 --- a/UnityClient/Assets/Scenes/UnityMouseRenderer.unity +++ b/UnityClient/Assets/Scenes/UnityMouseRenderer.unity @@ -6392,6 +6392,37 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1500345430 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1500345431} + m_Layer: 11 + m_Name: Lines + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1500345431 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1500345430} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 5.7, y: 4, z: -6.6} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1690469968} + m_RootOrder: 10 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1502391541 PrefabInstance: m_ObjectHideFlags: 0 @@ -7389,6 +7420,7 @@ Transform: - {fileID: 1716532781} - {fileID: 681682131} - {fileID: 3977901844913398025} + - {fileID: 1500345431} m_Father: {fileID: 1495091484} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -11116,6 +11148,14 @@ PrefabInstance: propertyPath: m_Name value: Lines objectReference: {fileID: 0} + - target: {fileID: 5708727191346960130, guid: 819c72893569fa442b7683567f3569d6, type: 3} + propertyPath: _lineRendererParentT + value: + objectReference: {fileID: 1500345431} + - target: {fileID: 5708727191346960130, guid: 819c72893569fa442b7683567f3569d6, type: 3} + propertyPath: _lineRendererPrefabGO + value: + objectReference: {fileID: 4722965623523888344, guid: c63cb033a009f0e429193c9b63cc8ade, type: 3} - target: {fileID: 5708727191740990016, guid: 819c72893569fa442b7683567f3569d6, type: 3} propertyPath: m_RootOrder value: 6 diff --git a/UnityClient/Assets/Scripts/Managers/LineRendererManager.cs b/UnityClient/Assets/Scripts/Managers/LineRendererManager.cs index 53f88afa..bade97ad 100644 --- a/UnityClient/Assets/Scripts/Managers/LineRendererManager.cs +++ b/UnityClient/Assets/Scripts/Managers/LineRendererManager.cs @@ -6,9 +6,16 @@ public class LineRendererManager : MonoBehaviour { + #region Public + [SerializeField] private GameObject _lineRendererPrefabGO; + [SerializeField] private Transform _lineRendererParentT; + #endregion + + #region Private + + #endregion //Keep a dictionary that maps string names to line renderer components private Dictionary _lineRenderers; - [SerializeField] private GameObject _lineRendererPrefab; private void Awake() { @@ -17,20 +24,19 @@ private void Awake() private void Start() { - /* CreateLine(new List { "l1", "l2" }); - DeleteLine(new List { "l2" }); + //CreateLine(new List { "l1", "l2" }); + //DeleteLine(new List { "l2" }); - Dictionary> temp = new(); - List tempPositions = new(); - tempPositions.Add(new Vector3(0, 0, 0)); - tempPositions.Add(new Vector3(1,2,3)); - tempPositions.Add(new Vector3(4, 4, 4)); - temp.Add("l1", tempPositions); + //Dictionary>> temp = new(); + //List> tempPositions = new(); + //tempPositions.Add(new List() { 0, 0, 0 }); + //tempPositions.Add(new List() { 13200, 11400, 8000 }); + //temp.Add("l1", tempPositions); - SetLinePosition(temp); + //SetLinePosition(temp); - SetLineColor("l1", Color.blue);*/ + //SetLineColor("l1", Color.blue); } public void CreateLine(List lines) @@ -38,7 +44,7 @@ public void CreateLine(List lines) //instantiating game object w line renderer component foreach(string line in lines) { - GameObject tempObject = Instantiate(_lineRendererPrefab); + GameObject tempObject = Instantiate(_lineRendererPrefabGO, _lineRendererParentT); tempObject.name = $"lineRenderer_{line}"; _lineRenderers.Add(line, tempObject.GetComponent()); //in theory, creates new entry to the dictionary with the name of the line [line] and associates it with a new Game Object @@ -70,8 +76,7 @@ public void SetLinePosition(Dictionary>> linePositions) for(int i= 0; i position = data[i]; - Vector3 tempVector = new Vector3(position[0], position[1], position[2]); - posvectors[i] = tempVector; + posvectors[i] = new Vector3(-position[0] / 1000f, -position[2] / 1000f, position[1] / 1000f) + _lineRendererParentT.position; } LineRenderer tempLine = _lineRenderers[lineName]; tempLine.positionCount = linePositions[lineName].Count;