From a29d709df5c0af6b2f699821eee1605f7092d45b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tobias=20Sch=C3=B6ner?= <tobias.stonehead@gmail.com>
Date: Fri, 3 Jun 2022 12:24:04 +0200
Subject: [PATCH] Torus mesh collider shared mesh now set in TorusGenerator.cs

Moved setting of collider shared mesh from FactSpawner to TorusGenerator
Also adjusted position of Torus Text
---
 Assets/Resources/Prefabs/Facts/Ring.prefab                | 4 ++--
 .../Scripts/InteractionEngine/FactHandling/FactSpawner.cs | 8 ++------
 Assets/Scripts/MeshGenerator/TorusGenerator.cs            | 3 +++
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/Assets/Resources/Prefabs/Facts/Ring.prefab b/Assets/Resources/Prefabs/Facts/Ring.prefab
index da4ef280..9d550071 100644
--- a/Assets/Resources/Prefabs/Facts/Ring.prefab
+++ b/Assets/Resources/Prefabs/Facts/Ring.prefab
@@ -35,8 +35,8 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
-  m_AnchoredPosition: {x: 0, y: 1}
-  m_SizeDelta: {x: 4, y: 1}
+  m_AnchoredPosition: {x: 0, y: 1.5}
+  m_SizeDelta: {x: 2, y: 0.5}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!23 &154494299464322201
 MeshRenderer:
diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs
index 54e40d0e..44ec5398 100644
--- a/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs
+++ b/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs
@@ -227,16 +227,12 @@ public Fact SpawnRing(Fact fact)
 
         string text = $"○{middlePointFact.Label}";
         tmpText.text = text;
-        //move TMP Text so it is on the edge of the circle
-        tmpText.rectTransform.position = tmpText.rectTransform.position - new Vector3(0, 0, -radius);
+        ////move TMP Text so it is on the edge of the circle
+        //tmpText.rectTransform.position = tmpText.rectTransform.position - new Vector3(0, 0, -radius);
 
         FactObj.URI = circleFact.Id;
         circleFact.Representation = ring;
 
-        //update MeshCollider to fit torus
-        MeshCollider meshCol = ring.GetComponentInChildren<MeshCollider>();
-        meshCol.sharedMesh = meshCol.gameObject.GetComponent<MeshFilter>().sharedMesh;
-
         return circleFact;
     }
 
diff --git a/Assets/Scripts/MeshGenerator/TorusGenerator.cs b/Assets/Scripts/MeshGenerator/TorusGenerator.cs
index 607f783b..95ef7746 100644
--- a/Assets/Scripts/MeshGenerator/TorusGenerator.cs
+++ b/Assets/Scripts/MeshGenerator/TorusGenerator.cs
@@ -25,6 +25,9 @@ protected override void GenerateShape()
         if (torusMesh.sharedMesh != null)
             torusMesh.sharedMesh.Clear();
         torusMesh.mesh = CreateMesh(CreateTorus(torusRadius, ringRadius, ringSegmentCount, segmentSideCount));
+
+        if (torusMesh.transform.TryGetComponent(out MeshCollider meshCol))
+            meshCol.sharedMesh = torusMesh.sharedMesh;
     }
 
     private static (Vector3[] vertices, int[] triangles) CreateTorus(float torusRadius, float ringRadius, int ringSegmentCount, int segmentSideCount)
-- 
GitLab