Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Icosahedron to the built-in shapes #7

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 94 additions & 27 deletions Assets/Prefabs/CameraRig.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -9358,7 +9358,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 224991721833942628}
- component: {fileID: 33931078607798932}
- component: {fileID: 23400739857238160}
- component: {fileID: 222863757601499486}
- component: {fileID: 114889146673854390}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -35422,7 +35414,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 224353535023853912}
- component: {fileID: 33894183074636898}
- component: {fileID: 23779459973462100}
- component: {fileID: 222675228110726036}
- component: {fileID: 114756877966986152}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -46856,7 +46839,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 224792478581430570}
- component: {fileID: 33180587196729598}
- component: {fileID: 23689086375512880}
- component: {fileID: 222656296281821840}
- component: {fileID: 114302973119263724}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
1 change: 1 addition & 0 deletions Assets/Scripts/model/controller/ShapeToolheadAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/// <summary>
Expand Down
88 changes: 46 additions & 42 deletions Assets/Scripts/model/core/Primitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +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 };
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;
Expand All @@ -44,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<int>[] ICOSAHEDRON_FACES = {
// Faces around point 0.
new List<int> { 0, 11, 5 },
new List<int> { 0, 5, 1 },
new List<int> { 0, 1, 7 },
new List<int> { 0, 7, 10 },
new List<int> { 0, 10, 11 },

// Faces adjacent to point 0.
new List<int> { 1, 5, 9 },
new List<int> { 5, 11, 4 },
new List<int> { 11, 10, 2 },
new List<int> { 10, 7, 6 },
new List<int> { 7, 1, 8 },

// Faces around point 3.
new List<int> { 3, 9, 4 },
new List<int> { 3, 4, 2 },
new List<int> { 3, 2, 6 },
new List<int> { 3, 6, 8 },
new List<int> { 3, 8, 9 },

// Faces adjacent to point 3.
new List<int> { 4, 9, 5 },
new List<int> { 2, 4, 11 },
new List<int> { 6, 2, 10 },
new List<int> { 8, 6, 7 },
new List<int> { 9, 8, 1 }};
// Faces around point 0.
new List<int> { 0, 11, 5 },
new List<int> { 0, 5, 1 },
new List<int> { 0, 1, 7 },
new List<int> { 0, 7, 10 },
new List<int> { 0, 10, 11 },

// Faces adjacent to point 0.
new List<int> { 1, 5, 9 },
new List<int> { 5, 11, 4 },
new List<int> { 11, 10, 2 },
new List<int> { 10, 7, 6 },
new List<int> { 7, 1, 8 },

// Faces around point 3.
new List<int> { 3, 9, 4 },
new List<int> { 3, 4, 2 },
new List<int> { 3, 2, 6 },
new List<int> { 3, 6, 8 },
new List<int> { 3, 8, 9 },

// Faces adjacent to point 3.
new List<int> { 4, 9, 5 },
new List<int> { 2, 4, 11 },
new List<int> { 6, 2, 10 },
new List<int> { 8, 6, 7 },
new List<int> { 9, 8, 1 }
};

public static MMesh BuildPrimitive(Shape shape, Vector3 scale, Vector3 offset, int id, int material)
{
Expand All @@ -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 AxisAlignedIcosphere(id, offset, scale, material, 0);
default:
return AxisAlignedBox(id, offset, scale, material);
}
Expand Down
Loading