Skip to content

Commit

Permalink
fix: fixing the line renderer to create properly and position correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Sep 10, 2023
1 parent f07caa5 commit 58becf0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 30 deletions.
39 changes: 25 additions & 14 deletions API/oursin/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions UnityClient/Assets/Prefabs/Objects/LineRenderer.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions UnityClient/Assets/Scenes/UnityMouseRenderer.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
33 changes: 19 additions & 14 deletions UnityClient/Assets/Scripts/Managers/LineRendererManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, LineRenderer> _lineRenderers;
[SerializeField] private GameObject _lineRendererPrefab;

private void Awake()
{
Expand All @@ -17,28 +24,27 @@ private void Awake()

private void Start()
{
/* CreateLine(new List<string> { "l1", "l2" });
DeleteLine(new List<string> { "l2" });
//CreateLine(new List<string> { "l1", "l2" });
//DeleteLine(new List<string> { "l2" });

Dictionary<string, List<Vector3>> temp = new();
List<Vector3> 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<string, List<List<float>>> temp = new();
//List<List<float>> tempPositions = new();
//tempPositions.Add(new List<float>() { 0, 0, 0 });
//tempPositions.Add(new List<float>() { 13200, 11400, 8000 });
//temp.Add("l1", tempPositions);

SetLinePosition(temp);
//SetLinePosition(temp);


SetLineColor("l1", Color.blue);*/
//SetLineColor("l1", Color.blue);
}

public void CreateLine(List<string> 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<LineRenderer>());
//in theory, creates new entry to the dictionary with the name of the line [line] and associates it with a new Game Object
Expand Down Expand Up @@ -70,8 +76,7 @@ public void SetLinePosition(Dictionary<string, List<List<float>>> linePositions)
for(int i= 0; i<data.Count; i++)
{
List<float> 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;
Expand Down

0 comments on commit 58becf0

Please sign in to comment.