Skip to content

Commit

Permalink
fix: issues with primitve meshes and neurons
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Sep 10, 2023
1 parent 6fb2e87 commit 70a1abb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion API/oursin/neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def set_shapes(neurons_list, shapes_list):
for i in range(len(neurons_list)):
neuron = neurons_list[i]
if neuron.in_unity:
neurons_shapes[neuron.id] = utils.sanitize_shape(shapes_list[i])
neurons_shapes[neuron.id] = shapes_list[i]
else:
warnings.warn(f"Neuron with id {neuron.id} does not exist in Unity, call create method first.")
client.sio.emit('SetNeuronShape', neurons_shapes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Transform:
m_GameObject: {fileID: 4726930313454754357}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
Expand Down Expand Up @@ -61,7 +61,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
- {fileID: 2100000, guid: 81bfceea20b892d44b814a1db0c2e7de, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
Expand Down
36 changes: 36 additions & 0 deletions UnityClient/Assets/Scenes/UnityMouseRenderer.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2835,6 +2835,37 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 803296948}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &805664570
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 805664571}
m_Layer: 6
m_Name: Primitives
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &805664571
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 805664570}
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: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &818490703
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -7421,6 +7452,7 @@ Transform:
- {fileID: 681682131}
- {fileID: 3977901844913398025}
- {fileID: 1500345431}
- {fileID: 805664571}
m_Father: {fileID: 1495091484}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -11144,6 +11176,10 @@ PrefabInstance:
propertyPath: m_RootOrder
value: 6
objectReference: {fileID: 0}
- target: {fileID: 5708727189844022269, guid: 819c72893569fa442b7683567f3569d6, type: 3}
propertyPath: _primitiveMeshParentT
value:
objectReference: {fileID: 805664571}
- target: {fileID: 5708727191346960128, guid: 819c72893569fa442b7683567f3569d6, type: 3}
propertyPath: m_Name
value: Lines
Expand Down
25 changes: 4 additions & 21 deletions UnityClient/Assets/Scripts/Managers/PrimitiveMeshManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ public class PrimitiveMeshManager : MonoBehaviour
{
//Keeping a dictionary mapping names of objects to the game object in schene
private Dictionary<string, MeshRenderer> _primMeshRenderers;
//log warning if string id alr exists (containskey())
//send warning back to python
//Client.logwarning("message");
[SerializeField] private GameObject _cubePrefab;
[SerializeField] private List<Material> _materials;
[SerializeField] private List<string> _materialNames;
[SerializeField] private Transform _primitiveMeshParentT;
private Dictionary<string, Material> _materialDictionary;

private void Awake()
Expand All @@ -26,11 +24,6 @@ private void Awake()
_materialDictionary.Add(_materialNames[i], _materials[i]);
}

}
// Start is called before the first frame update
void Start()
{

}

public void CreateMesh(List<string> meshes) //instantiates cube as default
Expand All @@ -40,7 +33,7 @@ void Start()
if (_primMeshRenderers.ContainsKey(mesh))
Client.LogWarning($"Mesh with id = {mesh} already exists.");

GameObject tempObject = Instantiate(_cubePrefab);
GameObject tempObject = Instantiate(_cubePrefab, _primitiveMeshParentT);
tempObject.name = $"primMesh_{mesh}";
_primMeshRenderers.Add(mesh, tempObject.GetComponent<MeshRenderer>());
tempObject.GetComponent<MeshRenderer>().material = _materialDictionary["default"];
Expand All @@ -63,23 +56,13 @@ public void DeleteMesh(List<string> meshes)
public void SetPosition(Dictionary<string, List<float>> meshPositions)
{
foreach (string meshName in meshPositions.Keys)
{// running through whole dictionary:
//if (_primMeshRenderers.ContainsKey(meshName))
//Client.LogWarning($"Mesh with id = {meshName} does not exist.");

{
List<float> data = meshPositions[meshName];
Vector3 position = new Vector3 (data[0], data[1], data[2]);

//CHECK IF KEY MESH NAME EXISTS (IF NOT SEND WARNING)

MeshRenderer tempMesh = _primMeshRenderers[meshName];

// Example of how a CoordinateSpace could be used to position this mesh
// CCFSpace tempCoordinateSpace = new CCFSpace();
// Example 1: User passed coordinates in CCF space
// Vector3 positionWorld = tempCoordinateSpace.Space2World(position);

tempMesh.transform.position = position;
tempMesh.transform.localPosition = new Vector3(-position[0] / 1000f, -position[2] / 1000f, position[1] / 1000f);
}
}

Expand Down

0 comments on commit 70a1abb

Please sign in to comment.