From a88c3b46a8250ceb2a8475896fdda6156136fd6d Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Thu, 27 Jun 2024 12:32:58 +0100 Subject: [PATCH 1/3] Quick test of a adding a new shape to the shape tool --- .../controller/ShapeToolheadAnimation.cs | 1 + Assets/Scripts/model/core/Primitives.cs | 60 ++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/model/controller/ShapeToolheadAnimation.cs b/Assets/Scripts/model/controller/ShapeToolheadAnimation.cs index fd0ed708..8b3b3dfb 100644 --- a/Assets/Scripts/model/controller/ShapeToolheadAnimation.cs +++ b/Assets/Scripts/model/controller/ShapeToolheadAnimation.cs @@ -32,6 +32,7 @@ void Start() { mockShapes[Primitives.Shape.CYLINDER] = ObjectFinder.ObjectById("ID_Cylinder"); mockShapes[Primitives.Shape.TORUS] = ObjectFinder.ObjectById("ID_Torus"); mockShapes[Primitives.Shape.SPHERE] = ObjectFinder.ObjectById("ID_Sphere"); + mockShapes[Primitives.Shape.ICOSAHEDRON] = ObjectFinder.ObjectById("ID_Icosahedron"); } /// diff --git a/Assets/Scripts/model/core/Primitives.cs b/Assets/Scripts/model/core/Primitives.cs index 30393f25..0c60eca6 100644 --- a/Assets/Scripts/model/core/Primitives.cs +++ b/Assets/Scripts/model/core/Primitives.cs @@ -26,7 +26,7 @@ namespace com.google.apps.peltzer.client.model.core { public class Primitives { // Note: the Shape enum is used to index things, so it should always start at 0 and count up // without skipping numbers. Do not define items to have arbitrary values. You will have a bad time. - public enum Shape { CONE, SPHERE, CUBE, CYLINDER, TORUS }; + public enum Shape { CONE, SPHERE, CUBE, CYLINDER, TORUS, ICOSAHEDRON }; private const int LINES_OF_LATITUDE = 8; private const int LINES_OF_LONGITUDE = 12; public static readonly int NUM_SHAPES = Enum.GetValues(typeof(Shape)).Length; @@ -98,6 +98,8 @@ public static MMesh BuildPrimitive(Shape shape, Vector3 scale, Vector3 offset, i return AxisAlignedUVSphere(LINES_OF_LONGITUDE, LINES_OF_LATITUDE, id, offset, scale, material); case Shape.TORUS: return Torus(id, offset, scale, material); + case Shape.ICOSAHEDRON: + return Icosahedron(id, offset, scale, material); default: return AxisAlignedBox(id, offset, scale, material); } @@ -140,6 +142,62 @@ public static MMesh AxisAlignedBox( return new MMesh(id, center, Quaternion.identity, vertices, faces.ToDictionary(f => f.id)); } + + /// + /// Create an icosahedron + /// + /// Id for the mesh. + /// Center of the icosahedron. + /// Scale of icosahedron. + /// Material id for the mesh. + /// An MMesh that renders an icosahedron. + public static MMesh Icosahedron( + int id, Vector3 center, Vector3 scale, int materialId) { + FaceProperties faceProperties = new FaceProperties(materialId); + Dictionary vertices = new Dictionary + { + // Vertices for an icosahedron of unit radius + {0, new Vertex(0, new Vector3(-0.1f, GOLDEN_RATIO_SCALED, 0))}, + {1, new Vertex(1, new Vector3(0.1f, GOLDEN_RATIO_SCALED, 0))}, + {2, new Vertex(2, new Vector3(-0.1f, -GOLDEN_RATIO_SCALED, 0))}, + {3, new Vertex(3, new Vector3(0.1f, -GOLDEN_RATIO_SCALED, 0))}, + {4, new Vertex(4, new Vector3(0, -0.1f, GOLDEN_RATIO_SCALED))}, + {5, new Vertex(5, new Vector3(0, 0.1f, GOLDEN_RATIO_SCALED))}, + {6, new Vertex(6, new Vector3(0, -0.1f, -GOLDEN_RATIO_SCALED))}, + {7, new Vertex(7, new Vector3(0, 0.1f, -GOLDEN_RATIO_SCALED))}, + {8, new Vertex(8, new Vector3(GOLDEN_RATIO_SCALED, 0, -0.1f))}, + {9, new Vertex(9, new Vector3(GOLDEN_RATIO_SCALED, 0, 0.1f))}, + {10, new Vertex(10, new Vector3(-GOLDEN_RATIO_SCALED, 0, -0.1f))}, + {11, new Vertex(11, new Vector3(-GOLDEN_RATIO_SCALED, 0, 0.1f))} + }; + + var faces = new List + { + new Face(0, new List{0, 1, 4}.AsReadOnly(), vertices, faceProperties), + new Face(1, new List{0, 4, 5}.AsReadOnly(), vertices, faceProperties), + new Face(2, new List{0, 5, 10}.AsReadOnly(), vertices, faceProperties), + new Face(3, new List{0, 10, 11}.AsReadOnly(), vertices, faceProperties), + new Face(4, new List{0, 11, 1}.AsReadOnly(), vertices, faceProperties), + new Face(5, new List{1, 5, 9}.AsReadOnly(), vertices, faceProperties), + new Face(6, new List{1, 9, 8}.AsReadOnly(), vertices, faceProperties), + new Face(7, new List{1, 8, 4}.AsReadOnly(), vertices, faceProperties), + new Face(8, new List{2, 3, 6}.AsReadOnly(), vertices, faceProperties), + new Face(9, new List{2, 6, 7}.AsReadOnly(), vertices, faceProperties), + new Face(10, new List{2, 7, 11}.AsReadOnly(), vertices, faceProperties), + new Face(11, new List{2, 11, 10}.AsReadOnly(), vertices, faceProperties), + new Face(12, new List{2, 10, 3}.AsReadOnly(), vertices, faceProperties), + new Face(13, new List{3, 9, 8}.AsReadOnly(), vertices, faceProperties), + new Face(14, new List{3, 8, 6}.AsReadOnly(), vertices, faceProperties), + new Face(15, new List{3, 6, 9}.AsReadOnly(), vertices, faceProperties), + new Face(16, new List{4, 8, 7}.AsReadOnly(), vertices, faceProperties), + new Face(17, new List{4, 7, 5}.AsReadOnly(), vertices, faceProperties), + new Face(18, new List{5, 7, 11}.AsReadOnly(), vertices, faceProperties), + new Face(19, new List{5, 11, 9}.AsReadOnly(), vertices, faceProperties) + + }; + return new MMesh(id, center, Quaternion.identity, vertices, faces.ToDictionary(f => f.id)); + } + /// /// Create an axis-aligned cylinder, with 'height' on the y-axis and 'radius' on the x and z axes. /// The ids for the start vertices will be from 0 to SLICES-1 and for the end, SLICES to SLICES*2-1. From a468f2b06270f9fde5b936a443732617b07e3117 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Thu, 27 Jun 2024 13:49:37 +0100 Subject: [PATCH 2/3] Restore the changes prior to reformatting --- .../controller/ShapeToolheadAnimation.cs | 1 + Assets/Scripts/model/core/Primitives.cs | 61 ++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/model/controller/ShapeToolheadAnimation.cs b/Assets/Scripts/model/controller/ShapeToolheadAnimation.cs index dad40b3a..612fef1f 100644 --- a/Assets/Scripts/model/controller/ShapeToolheadAnimation.cs +++ b/Assets/Scripts/model/controller/ShapeToolheadAnimation.cs @@ -35,6 +35,7 @@ void Start() mockShapes[Primitives.Shape.CYLINDER] = ObjectFinder.ObjectById("ID_Cylinder"); mockShapes[Primitives.Shape.TORUS] = ObjectFinder.ObjectById("ID_Torus"); mockShapes[Primitives.Shape.SPHERE] = ObjectFinder.ObjectById("ID_Sphere"); + mockShapes[Primitives.Shape.ICOSAHEDRON] = ObjectFinder.ObjectById("ID_Icosahedron"); } /// diff --git a/Assets/Scripts/model/core/Primitives.cs b/Assets/Scripts/model/core/Primitives.cs index 897f3096..e8b37411 100644 --- a/Assets/Scripts/model/core/Primitives.cs +++ b/Assets/Scripts/model/core/Primitives.cs @@ -28,7 +28,9 @@ public class Primitives { // Note: the Shape enum is used to index things, so it should always start at 0 and count up // without skipping numbers. Do not define items to have arbitrary values. You will have a bad time. - public enum Shape { CONE, SPHERE, CUBE, CYLINDER, TORUS }; + public enum Shape { CONE, SPHERE, CUBE, CYLINDER, TORUS, + ICOSAHEDRON + }; private const int LINES_OF_LATITUDE = 8; private const int LINES_OF_LONGITUDE = 12; public static readonly int NUM_SHAPES = Enum.GetValues(typeof(Shape)).Length; @@ -102,6 +104,8 @@ public static MMesh BuildPrimitive(Shape shape, Vector3 scale, Vector3 offset, i return AxisAlignedUVSphere(LINES_OF_LONGITUDE, LINES_OF_LATITUDE, id, offset, scale, material); case Shape.TORUS: return Torus(id, offset, scale, material); + case Shape.ICOSAHEDRON: + return Icosahedron(id, offset, scale, material); default: return AxisAlignedBox(id, offset, scale, material); } @@ -663,5 +667,60 @@ public static MMesh Torus(int id, Vector3 center, Vector3 scale, int materialId) return new MMesh(id, center, Quaternion.identity, vertices, faces); } + + /// + /// Create an icosahedron + /// + /// Id for the mesh. + /// Center of the icosahedron. + /// Scale of icosahedron. + /// Material id for the mesh. + /// An MMesh that renders an icosahedron. + public static MMesh Icosahedron( + int id, Vector3 center, Vector3 scale, int materialId) { + FaceProperties faceProperties = new FaceProperties(materialId); + Dictionary vertices = new Dictionary + { + // Vertices for an icosahedron of unit radius + {0, new Vertex(0, new Vector3(-0.1f, GOLDEN_RATIO_SCALED, 0))}, + {1, new Vertex(1, new Vector3(0.1f, GOLDEN_RATIO_SCALED, 0))}, + {2, new Vertex(2, new Vector3(-0.1f, -GOLDEN_RATIO_SCALED, 0))}, + {3, new Vertex(3, new Vector3(0.1f, -GOLDEN_RATIO_SCALED, 0))}, + {4, new Vertex(4, new Vector3(0, -0.1f, GOLDEN_RATIO_SCALED))}, + {5, new Vertex(5, new Vector3(0, 0.1f, GOLDEN_RATIO_SCALED))}, + {6, new Vertex(6, new Vector3(0, -0.1f, -GOLDEN_RATIO_SCALED))}, + {7, new Vertex(7, new Vector3(0, 0.1f, -GOLDEN_RATIO_SCALED))}, + {8, new Vertex(8, new Vector3(GOLDEN_RATIO_SCALED, 0, -0.1f))}, + {9, new Vertex(9, new Vector3(GOLDEN_RATIO_SCALED, 0, 0.1f))}, + {10, new Vertex(10, new Vector3(-GOLDEN_RATIO_SCALED, 0, -0.1f))}, + {11, new Vertex(11, new Vector3(-GOLDEN_RATIO_SCALED, 0, 0.1f))} + }; + + var faces = new List + { + new Face(0, new List{0, 1, 4}.AsReadOnly(), vertices, faceProperties), + new Face(1, new List{0, 4, 5}.AsReadOnly(), vertices, faceProperties), + new Face(2, new List{0, 5, 10}.AsReadOnly(), vertices, faceProperties), + new Face(3, new List{0, 10, 11}.AsReadOnly(), vertices, faceProperties), + new Face(4, new List{0, 11, 1}.AsReadOnly(), vertices, faceProperties), + new Face(5, new List{1, 5, 9}.AsReadOnly(), vertices, faceProperties), + new Face(6, new List{1, 9, 8}.AsReadOnly(), vertices, faceProperties), + new Face(7, new List{1, 8, 4}.AsReadOnly(), vertices, faceProperties), + new Face(8, new List{2, 3, 6}.AsReadOnly(), vertices, faceProperties), + new Face(9, new List{2, 6, 7}.AsReadOnly(), vertices, faceProperties), + new Face(10, new List{2, 7, 11}.AsReadOnly(), vertices, faceProperties), + new Face(11, new List{2, 11, 10}.AsReadOnly(), vertices, faceProperties), + new Face(12, new List{2, 10, 3}.AsReadOnly(), vertices, faceProperties), + new Face(13, new List{3, 9, 8}.AsReadOnly(), vertices, faceProperties), + new Face(14, new List{3, 8, 6}.AsReadOnly(), vertices, faceProperties), + new Face(15, new List{3, 6, 9}.AsReadOnly(), vertices, faceProperties), + new Face(16, new List{4, 8, 7}.AsReadOnly(), vertices, faceProperties), + new Face(17, new List{4, 7, 5}.AsReadOnly(), vertices, faceProperties), + new Face(18, new List{5, 7, 11}.AsReadOnly(), vertices, faceProperties), + new Face(19, new List{5, 11, 9}.AsReadOnly(), vertices, faceProperties) + + }; + return new MMesh(id, center, Quaternion.identity, vertices, faces.ToDictionary(f => f.id)); + } } } From bc02e615dffdd024d25025b1aaf77f089010fd7c Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Thu, 27 Jun 2024 14:24:04 +0100 Subject: [PATCH 3/3] Add an Icosahedron primitive --- Assets/Prefabs/CameraRig.prefab | 121 +++++++++++++++----- Assets/Scripts/model/core/Primitives.cs | 145 ++++++++---------------- 2 files changed, 139 insertions(+), 127 deletions(-) diff --git a/Assets/Prefabs/CameraRig.prefab b/Assets/Prefabs/CameraRig.prefab index ace8f5c1..1580aa61 100644 --- a/Assets/Prefabs/CameraRig.prefab +++ b/Assets/Prefabs/CameraRig.prefab @@ -9358,7 +9358,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 224991721833942628} - - component: {fileID: 33931078607798932} - component: {fileID: 23400739857238160} - component: {fileID: 222863757601499486} - component: {fileID: 114889146673854390} @@ -9388,14 +9387,6 @@ RectTransform: m_AnchoredPosition: {x: -0.0000049592927, y: 0.51994324} m_SizeDelta: {x: 148.4, y: 32.67} m_Pivot: {x: 0.5, y: 0.5} ---- !u!33 &33931078607798932 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1125421002062496} - m_Mesh: {fileID: 0} --- !u!23 &23400739857238160 MeshRenderer: m_ObjectHideFlags: 0 @@ -27050,6 +27041,7 @@ Transform: - {fileID: 4142224838695494} - {fileID: 4499153807668788} - {fileID: 4488566617152198} + - {fileID: 2674856114974116345} m_Father: {fileID: 4458942072854162} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -35422,7 +35414,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 224353535023853912} - - component: {fileID: 33894183074636898} - component: {fileID: 23779459973462100} - component: {fileID: 222675228110726036} - component: {fileID: 114756877966986152} @@ -35452,14 +35443,6 @@ RectTransform: m_AnchoredPosition: {x: -0.00038269162, y: 0.002600002} m_SizeDelta: {x: 148.4, y: 32.67} m_Pivot: {x: 0.5, y: 0.5} ---- !u!33 &33894183074636898 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1490861234011590} - m_Mesh: {fileID: 0} --- !u!23 &23779459973462100 MeshRenderer: m_ObjectHideFlags: 0 @@ -46856,7 +46839,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 224792478581430570} - - component: {fileID: 33180587196729598} - component: {fileID: 23689086375512880} - component: {fileID: 222656296281821840} - component: {fileID: 114302973119263724} @@ -46886,14 +46868,6 @@ RectTransform: m_AnchoredPosition: {x: 0.000000015832484, y: 0.51995945} m_SizeDelta: {x: 148.4, y: 32.67} m_Pivot: {x: 0.5, y: 0.5} ---- !u!33 &33180587196729598 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1631856206869138} - m_Mesh: {fileID: 0} --- !u!23 &23689086375512880 MeshRenderer: m_ObjectHideFlags: 0 @@ -72375,3 +72349,96 @@ MonoBehaviour: _SortingLayer: 0 _SortingLayerID: 0 _SortingOrder: 0 +--- !u!1 &5181794319663275375 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2674856114974116345} + - component: {fileID: 7081471672610052149} + - component: {fileID: 6836010759666660914} + - component: {fileID: 7151145942401920378} + m_Layer: 10 + m_Name: ID_Icosahedron + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!4 &2674856114974116345 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5181794319663275375} + m_LocalRotation: {x: 0.7071068, y: 0.00000006050855, z: 0.000000008354488, w: 0.70710677} + m_LocalPosition: {x: 0.00030002737, y: 0.0039000195, z: 0.031499982} + m_LocalScale: {x: 0.05, y: 0.05, z: 0.05} + m_Children: [] + m_Father: {fileID: 4776689306038126} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &7081471672610052149 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5181794319663275375} + m_Mesh: {fileID: 4300000, guid: 8f63658e7c8574ed587fa33d6ddded97, type: 2} +--- !u!23 &6836010759666660914 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5181794319663275375} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: d06ae5e60c379dc4484da7d362750c97, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!114 &7151145942401920378 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5181794319663275375} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ea4c1758a03182643917b8d44c97d323, type: 3} + m_Name: + m_EditorClassIdentifier: + rend: {fileID: 6836010759666660914} diff --git a/Assets/Scripts/model/core/Primitives.cs b/Assets/Scripts/model/core/Primitives.cs index e8b37411..158155af 100644 --- a/Assets/Scripts/model/core/Primitives.cs +++ b/Assets/Scripts/model/core/Primitives.cs @@ -28,9 +28,7 @@ public class Primitives { // Note: the Shape enum is used to index things, so it should always start at 0 and count up // without skipping numbers. Do not define items to have arbitrary values. You will have a bad time. - public enum Shape { CONE, SPHERE, CUBE, CYLINDER, TORUS, - ICOSAHEDRON - }; + public enum Shape { CONE, SPHERE, CUBE, CYLINDER, TORUS, ICOSAHEDRON }; private const int LINES_OF_LATITUDE = 8; private const int LINES_OF_LONGITUDE = 12; public static readonly int NUM_SHAPES = Enum.GetValues(typeof(Shape)).Length; @@ -46,49 +44,51 @@ public enum Shape { CONE, SPHERE, CUBE, CYLINDER, TORUS, private static readonly float GOLDEN_RATIO_SCALED = 0.1618033988749895f; private static readonly Vector3[] ICOSAHEDRON_POINTS = { - new Vector3(-0.1f, GOLDEN_RATIO_SCALED, 0), - new Vector3(0.1f, GOLDEN_RATIO_SCALED, 0), - new Vector3(-0.1f, -GOLDEN_RATIO_SCALED, 0), - new Vector3(0.1f, -GOLDEN_RATIO_SCALED, 0), - - new Vector3(0, -0.1f, GOLDEN_RATIO_SCALED), - new Vector3(0, 0.1f, GOLDEN_RATIO_SCALED), - new Vector3(0, -0.1f, -GOLDEN_RATIO_SCALED), - new Vector3(0, 0.1f, -GOLDEN_RATIO_SCALED), - - new Vector3(GOLDEN_RATIO_SCALED, 0, -0.1f), - new Vector3(GOLDEN_RATIO_SCALED, 0, 0.1f), - new Vector3(-GOLDEN_RATIO_SCALED, 0, -0.1f), - new Vector3(-GOLDEN_RATIO_SCALED, 0, 0.1f)}; + new Vector3(-0.1f, GOLDEN_RATIO_SCALED, 0), + new Vector3(0.1f, GOLDEN_RATIO_SCALED, 0), + new Vector3(-0.1f, -GOLDEN_RATIO_SCALED, 0), + new Vector3(0.1f, -GOLDEN_RATIO_SCALED, 0), + + new Vector3(0, -0.1f, GOLDEN_RATIO_SCALED), + new Vector3(0, 0.1f, GOLDEN_RATIO_SCALED), + new Vector3(0, -0.1f, -GOLDEN_RATIO_SCALED), + new Vector3(0, 0.1f, -GOLDEN_RATIO_SCALED), + + new Vector3(GOLDEN_RATIO_SCALED, 0, -0.1f), + new Vector3(GOLDEN_RATIO_SCALED, 0, 0.1f), + new Vector3(-GOLDEN_RATIO_SCALED, 0, -0.1f), + new Vector3(-GOLDEN_RATIO_SCALED, 0, 0.1f) + }; private static readonly List[] ICOSAHEDRON_FACES = { - // Faces around point 0. - new List { 0, 11, 5 }, - new List { 0, 5, 1 }, - new List { 0, 1, 7 }, - new List { 0, 7, 10 }, - new List { 0, 10, 11 }, - - // Faces adjacent to point 0. - new List { 1, 5, 9 }, - new List { 5, 11, 4 }, - new List { 11, 10, 2 }, - new List { 10, 7, 6 }, - new List { 7, 1, 8 }, - - // Faces around point 3. - new List { 3, 9, 4 }, - new List { 3, 4, 2 }, - new List { 3, 2, 6 }, - new List { 3, 6, 8 }, - new List { 3, 8, 9 }, - - // Faces adjacent to point 3. - new List { 4, 9, 5 }, - new List { 2, 4, 11 }, - new List { 6, 2, 10 }, - new List { 8, 6, 7 }, - new List { 9, 8, 1 }}; + // Faces around point 0. + new List { 0, 11, 5 }, + new List { 0, 5, 1 }, + new List { 0, 1, 7 }, + new List { 0, 7, 10 }, + new List { 0, 10, 11 }, + + // Faces adjacent to point 0. + new List { 1, 5, 9 }, + new List { 5, 11, 4 }, + new List { 11, 10, 2 }, + new List { 10, 7, 6 }, + new List { 7, 1, 8 }, + + // Faces around point 3. + new List { 3, 9, 4 }, + new List { 3, 4, 2 }, + new List { 3, 2, 6 }, + new List { 3, 6, 8 }, + new List { 3, 8, 9 }, + + // Faces adjacent to point 3. + new List { 4, 9, 5 }, + new List { 2, 4, 11 }, + new List { 6, 2, 10 }, + new List { 8, 6, 7 }, + new List { 9, 8, 1 } + }; public static MMesh BuildPrimitive(Shape shape, Vector3 scale, Vector3 offset, int id, int material) { @@ -105,7 +105,7 @@ public static MMesh BuildPrimitive(Shape shape, Vector3 scale, Vector3 offset, i case Shape.TORUS: return Torus(id, offset, scale, material); case Shape.ICOSAHEDRON: - return Icosahedron(id, offset, scale, material); + return AxisAlignedIcosphere(id, offset, scale, material, 0); default: return AxisAlignedBox(id, offset, scale, material); } @@ -667,60 +667,5 @@ public static MMesh Torus(int id, Vector3 center, Vector3 scale, int materialId) return new MMesh(id, center, Quaternion.identity, vertices, faces); } - - /// - /// Create an icosahedron - /// - /// Id for the mesh. - /// Center of the icosahedron. - /// Scale of icosahedron. - /// Material id for the mesh. - /// An MMesh that renders an icosahedron. - public static MMesh Icosahedron( - int id, Vector3 center, Vector3 scale, int materialId) { - FaceProperties faceProperties = new FaceProperties(materialId); - Dictionary vertices = new Dictionary - { - // Vertices for an icosahedron of unit radius - {0, new Vertex(0, new Vector3(-0.1f, GOLDEN_RATIO_SCALED, 0))}, - {1, new Vertex(1, new Vector3(0.1f, GOLDEN_RATIO_SCALED, 0))}, - {2, new Vertex(2, new Vector3(-0.1f, -GOLDEN_RATIO_SCALED, 0))}, - {3, new Vertex(3, new Vector3(0.1f, -GOLDEN_RATIO_SCALED, 0))}, - {4, new Vertex(4, new Vector3(0, -0.1f, GOLDEN_RATIO_SCALED))}, - {5, new Vertex(5, new Vector3(0, 0.1f, GOLDEN_RATIO_SCALED))}, - {6, new Vertex(6, new Vector3(0, -0.1f, -GOLDEN_RATIO_SCALED))}, - {7, new Vertex(7, new Vector3(0, 0.1f, -GOLDEN_RATIO_SCALED))}, - {8, new Vertex(8, new Vector3(GOLDEN_RATIO_SCALED, 0, -0.1f))}, - {9, new Vertex(9, new Vector3(GOLDEN_RATIO_SCALED, 0, 0.1f))}, - {10, new Vertex(10, new Vector3(-GOLDEN_RATIO_SCALED, 0, -0.1f))}, - {11, new Vertex(11, new Vector3(-GOLDEN_RATIO_SCALED, 0, 0.1f))} - }; - - var faces = new List - { - new Face(0, new List{0, 1, 4}.AsReadOnly(), vertices, faceProperties), - new Face(1, new List{0, 4, 5}.AsReadOnly(), vertices, faceProperties), - new Face(2, new List{0, 5, 10}.AsReadOnly(), vertices, faceProperties), - new Face(3, new List{0, 10, 11}.AsReadOnly(), vertices, faceProperties), - new Face(4, new List{0, 11, 1}.AsReadOnly(), vertices, faceProperties), - new Face(5, new List{1, 5, 9}.AsReadOnly(), vertices, faceProperties), - new Face(6, new List{1, 9, 8}.AsReadOnly(), vertices, faceProperties), - new Face(7, new List{1, 8, 4}.AsReadOnly(), vertices, faceProperties), - new Face(8, new List{2, 3, 6}.AsReadOnly(), vertices, faceProperties), - new Face(9, new List{2, 6, 7}.AsReadOnly(), vertices, faceProperties), - new Face(10, new List{2, 7, 11}.AsReadOnly(), vertices, faceProperties), - new Face(11, new List{2, 11, 10}.AsReadOnly(), vertices, faceProperties), - new Face(12, new List{2, 10, 3}.AsReadOnly(), vertices, faceProperties), - new Face(13, new List{3, 9, 8}.AsReadOnly(), vertices, faceProperties), - new Face(14, new List{3, 8, 6}.AsReadOnly(), vertices, faceProperties), - new Face(15, new List{3, 6, 9}.AsReadOnly(), vertices, faceProperties), - new Face(16, new List{4, 8, 7}.AsReadOnly(), vertices, faceProperties), - new Face(17, new List{4, 7, 5}.AsReadOnly(), vertices, faceProperties), - new Face(18, new List{5, 7, 11}.AsReadOnly(), vertices, faceProperties), - new Face(19, new List{5, 11, 9}.AsReadOnly(), vertices, faceProperties) - - }; - return new MMesh(id, center, Quaternion.identity, vertices, faces.ToDictionary(f => f.id)); - } } }