├── .gitattributes ├── .gitignore ├── Assets ├── Procedural Primitives.meta └── Procedural Primitives │ ├── Materials.meta │ ├── Materials │ ├── DebugTexture.mat │ └── DebugTexture.mat.meta │ ├── Release Notes.txt │ ├── Release Notes.txt.meta │ ├── Scenes.meta │ ├── Scenes │ ├── TestScene.unity │ └── TestScene.unity.meta │ ├── Scripts.meta │ ├── Scripts │ ├── EnumComboBox.cs │ ├── EnumComboBox.cs.meta │ ├── GUIHelper.cs │ ├── GUIHelper.cs.meta │ ├── GameObjectExtensions.cs │ ├── GameObjectExtensions.cs.meta │ ├── InGameMenu.cs │ ├── InGameMenu.cs.meta │ ├── MeshExtensions.cs │ ├── MeshExtensions.cs.meta │ ├── MouseCamera.cs │ ├── MouseCamera.cs.meta │ ├── Popup.cs │ ├── Popup.cs.meta │ ├── Primitive.cs │ ├── Primitive.cs.meta │ ├── PrimitiveType.cs │ ├── PrimitiveType.cs.meta │ ├── ProceduralPrimitivesMenu.cs │ └── ProceduralPrimitivesMenu.cs.meta │ ├── Textures.meta │ ├── Textures │ ├── DebugTexture.jpg │ └── DebugTexture.jpg.meta │ ├── readme.txt │ └── readme.txt.meta ├── LICENSE.md ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore the Unity Library folder 2 | Library/ 3 | 4 | # Ignore the Unity obj folder 5 | obj/ 6 | 7 | # Ignore the Unity Temp folder 8 | Temp/ 9 | 10 | # Ignore the Visual Studio files that are automatically generated by Unity 11 | *.sln 12 | *.csproj 13 | *.suo 14 | 15 | # Ignore the MonoDevelop .userprefs file 16 | *.userprefs 17 | 18 | # Ignore the StyleCop files 19 | Settings.StyleCop 20 | StyleCop.Cache 21 | 22 | # Ignore the Unity asset store tools folder 23 | Assets/AssetStoreTools/ 24 | 25 | # Ignore Notepad++ backup files 26 | *.bak -------------------------------------------------------------------------------- /Assets/Procedural Primitives.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69c5a9abc014e9e4199e07622fdd3b65 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6afaea6f12b4af4f8476d244988b49b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Materials/DebugTexture.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 5 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: DebugTexture 10 | m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 5 13 | m_CustomRenderQueue: -1 14 | m_SavedProperties: 15 | serializedVersion: 2 16 | m_TexEnvs: 17 | data: 18 | first: 19 | name: _MainTex 20 | second: 21 | m_Texture: {fileID: 2800000, guid: fb86416915e887d4a81ae3497b50eeb3, type: 3} 22 | m_Scale: {x: 1, y: 1} 23 | m_Offset: {x: 0, y: 0} 24 | m_Floats: {} 25 | m_Colors: 26 | data: 27 | first: 28 | name: _Color 29 | second: {r: 1, g: 1, b: 1, a: 1} 30 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Materials/DebugTexture.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57e9ee814a02b164d81a3ee059c6a655 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Release Notes.txt: -------------------------------------------------------------------------------- 1 | 2.1 (April 2015) 2 | - Updated to Unity 5.0.0 3 | 4 | 2.0 (January 2014) 5 | - Rewrote all methods from scratch as extention methods for Unity Mesh and GameObject classes 6 | - Added new test scene to show complete configurability during runtime 7 | - Added Circle, Ring, Torus, Torus Knot, and Lathe shapes 8 | - Added ability to change the number of subdivisions along all three axes of a Box shape 9 | - Added ability to toggle on/off the end caps of a Cylinder shape 10 | - Added ability to set angles in order to produce partial Sphere shapes 11 | 12 | 1.2 (September 12, 2011) 13 | - Changed custom Editor Window to have a smaller range on the sliders to prevent the vertex count from exceeding 65,000 and throwing an error. 14 | 15 | 1.1 (August 22, 2011) 16 | - Added a custom Editor Window that allows creation of the shapes inside of the Editor itself. 17 | 18 | 1.0 (June 28, 2011) 19 | - Initial Release 20 | - Added Cylinder (Cone), Box, Sphere, and Plane shapes 21 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Release Notes.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d3df615e1c4d5a47bfb06fb2ffa79ee 3 | TextScriptImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca6c622963c743b4090e4627f3690bbd 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scenes/TestScene.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | SceneSettings: 5 | m_ObjectHideFlags: 0 6 | m_PVSData: 7 | m_PVSObjectsArray: [] 8 | m_PVSPortalsArray: [] 9 | m_OcclusionBakeSettings: 10 | smallestOccluder: 5 11 | smallestHole: .25 12 | backfaceThreshold: 100 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 6 17 | m_Fog: 0 18 | m_FogColor: {r: .5, g: .5, b: .5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: .00999999978 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: .200000003, g: .200000003, b: .200000003, a: 1} 24 | m_AmbientEquatorColor: {r: .200000003, g: .200000003, b: .200000003, a: 1} 25 | m_AmbientGroundColor: {r: .200000003, g: .200000003, b: .200000003, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 3 28 | m_SkyboxMaterial: {fileID: 0} 29 | m_HaloStrength: .5 30 | m_FlareStrength: 1 31 | m_FlareFadeSpeed: 3 32 | m_HaloTexture: {fileID: 0} 33 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 34 | m_DefaultReflectionMode: 0 35 | m_DefaultReflectionResolution: 128 36 | m_ReflectionBounces: 1 37 | m_ReflectionIntensity: 1 38 | m_CustomReflection: {fileID: 0} 39 | m_Sun: {fileID: 0} 40 | --- !u!127 &3 41 | LevelGameManager: 42 | m_ObjectHideFlags: 0 43 | --- !u!157 &4 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 5 47 | m_GIWorkflowMode: 1 48 | m_LightmapsMode: 1 49 | m_GISettings: 50 | serializedVersion: 2 51 | m_BounceScale: 1 52 | m_IndirectOutputScale: 1 53 | m_AlbedoBoost: 1 54 | m_TemporalCoherenceThreshold: 1 55 | m_EnvironmentLightingMode: 0 56 | m_EnableBakedLightmaps: 1 57 | m_EnableRealtimeLightmaps: 0 58 | m_LightmapEditorSettings: 59 | serializedVersion: 3 60 | m_Resolution: 1 61 | m_BakeResolution: 50 62 | m_TextureWidth: 1024 63 | m_TextureHeight: 1024 64 | m_AOMaxDistance: 1 65 | m_Padding: 2 66 | m_CompAOExponent: 0 67 | m_LightmapParameters: {fileID: 0} 68 | m_TextureCompression: 0 69 | m_FinalGather: 0 70 | m_FinalGatherRayCount: 1024 71 | m_LightmapSnapshot: {fileID: 0} 72 | m_RuntimeCPUUsage: 25 73 | --- !u!196 &5 74 | NavMeshSettings: 75 | serializedVersion: 2 76 | m_ObjectHideFlags: 0 77 | m_BuildSettings: 78 | serializedVersion: 2 79 | agentRadius: .5 80 | agentHeight: 2 81 | agentSlope: 45 82 | agentClimb: .400000006 83 | ledgeDropHeight: 0 84 | maxJumpAcrossDistance: 0 85 | accuratePlacement: 0 86 | minRegionArea: 2 87 | cellSize: .166666657 88 | manualCellSize: 0 89 | m_NavMeshData: {fileID: 0} 90 | --- !u!1 &1021991872 91 | GameObject: 92 | m_ObjectHideFlags: 0 93 | m_PrefabParentObject: {fileID: 0} 94 | m_PrefabInternal: {fileID: 0} 95 | serializedVersion: 4 96 | m_Component: 97 | - 4: {fileID: 1021991874} 98 | - 132: {fileID: 1021991873} 99 | m_Layer: 0 100 | m_Name: GUI Text 101 | m_TagString: Untagged 102 | m_Icon: {fileID: 0} 103 | m_NavMeshLayer: 0 104 | m_StaticEditorFlags: 0 105 | m_IsActive: 1 106 | --- !u!132 &1021991873 107 | GUIText: 108 | m_ObjectHideFlags: 0 109 | m_PrefabParentObject: {fileID: 0} 110 | m_PrefabInternal: {fileID: 0} 111 | m_GameObject: {fileID: 1021991872} 112 | m_Enabled: 1 113 | serializedVersion: 3 114 | m_Text: Right click and drag mouse to rotate camera. 115 | m_Anchor: 4 116 | m_Alignment: 1 117 | m_PixelOffset: {x: 0, y: 0} 118 | m_LineSpacing: 1 119 | m_TabSize: 4 120 | m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} 121 | m_Material: {fileID: 0} 122 | m_FontSize: 0 123 | m_FontStyle: 0 124 | m_Color: 125 | serializedVersion: 2 126 | rgba: 4294967295 127 | m_PixelCorrect: 1 128 | m_RichText: 1 129 | --- !u!4 &1021991874 130 | Transform: 131 | m_ObjectHideFlags: 0 132 | m_PrefabParentObject: {fileID: 0} 133 | m_PrefabInternal: {fileID: 0} 134 | m_GameObject: {fileID: 1021991872} 135 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 136 | m_LocalPosition: {x: .5, y: .980000019, z: 0} 137 | m_LocalScale: {x: 1, y: 1, z: 1} 138 | m_Children: [] 139 | m_Father: {fileID: 0} 140 | m_RootOrder: 0 141 | --- !u!1 &1053814053 142 | GameObject: 143 | m_ObjectHideFlags: 0 144 | m_PrefabParentObject: {fileID: 0} 145 | m_PrefabInternal: {fileID: 0} 146 | serializedVersion: 4 147 | m_Component: 148 | - 4: {fileID: 1053814059} 149 | - 20: {fileID: 1053814058} 150 | - 92: {fileID: 1053814057} 151 | - 124: {fileID: 1053814056} 152 | - 81: {fileID: 1053814055} 153 | - 114: {fileID: 1053814060} 154 | - 114: {fileID: 1053814054} 155 | m_Layer: 0 156 | m_Name: Main Camera 157 | m_TagString: MainCamera 158 | m_Icon: {fileID: 0} 159 | m_NavMeshLayer: 0 160 | m_StaticEditorFlags: 0 161 | m_IsActive: 1 162 | --- !u!114 &1053814054 163 | MonoBehaviour: 164 | m_ObjectHideFlags: 0 165 | m_PrefabParentObject: {fileID: 0} 166 | m_PrefabInternal: {fileID: 0} 167 | m_GameObject: {fileID: 1053814053} 168 | m_Enabled: 1 169 | m_EditorHideFlags: 0 170 | m_Script: {fileID: 11500000, guid: 5248d864ac095a749b0d8e1fc073a8fd, type: 3} 171 | m_Name: 172 | m_EditorClassIdentifier: 173 | target: {fileID: 0} 174 | distance: 10 175 | xSpeed: 250 176 | ySpeed: 120 177 | yMinLimit: -20 178 | yMaxLimit: 80 179 | --- !u!81 &1053814055 180 | AudioListener: 181 | m_ObjectHideFlags: 0 182 | m_PrefabParentObject: {fileID: 0} 183 | m_PrefabInternal: {fileID: 0} 184 | m_GameObject: {fileID: 1053814053} 185 | m_Enabled: 1 186 | --- !u!124 &1053814056 187 | Behaviour: 188 | m_ObjectHideFlags: 0 189 | m_PrefabParentObject: {fileID: 0} 190 | m_PrefabInternal: {fileID: 0} 191 | m_GameObject: {fileID: 1053814053} 192 | m_Enabled: 1 193 | --- !u!92 &1053814057 194 | Behaviour: 195 | m_ObjectHideFlags: 0 196 | m_PrefabParentObject: {fileID: 0} 197 | m_PrefabInternal: {fileID: 0} 198 | m_GameObject: {fileID: 1053814053} 199 | m_Enabled: 1 200 | --- !u!20 &1053814058 201 | Camera: 202 | m_ObjectHideFlags: 0 203 | m_PrefabParentObject: {fileID: 0} 204 | m_PrefabInternal: {fileID: 0} 205 | m_GameObject: {fileID: 1053814053} 206 | m_Enabled: 1 207 | serializedVersion: 2 208 | m_ClearFlags: 1 209 | m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438} 210 | m_NormalizedViewPortRect: 211 | serializedVersion: 2 212 | x: 0 213 | y: 0 214 | width: 1 215 | height: 1 216 | near clip plane: .300000012 217 | far clip plane: 1000 218 | field of view: 60 219 | orthographic: 0 220 | orthographic size: 5 221 | m_Depth: -1 222 | m_CullingMask: 223 | serializedVersion: 2 224 | m_Bits: 4294967295 225 | m_RenderingPath: -1 226 | m_TargetTexture: {fileID: 0} 227 | m_TargetDisplay: 0 228 | m_HDR: 0 229 | m_OcclusionCulling: 1 230 | m_StereoConvergence: 10 231 | m_StereoSeparation: .0219999999 232 | --- !u!4 &1053814059 233 | Transform: 234 | m_ObjectHideFlags: 0 235 | m_PrefabParentObject: {fileID: 0} 236 | m_PrefabInternal: {fileID: 0} 237 | m_GameObject: {fileID: 1053814053} 238 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 239 | m_LocalPosition: {x: 0, y: 0, z: -10} 240 | m_LocalScale: {x: 1, y: 1, z: 1} 241 | m_Children: [] 242 | m_Father: {fileID: 0} 243 | m_RootOrder: 1 244 | --- !u!114 &1053814060 245 | MonoBehaviour: 246 | m_ObjectHideFlags: 0 247 | m_PrefabParentObject: {fileID: 0} 248 | m_PrefabInternal: {fileID: 0} 249 | m_GameObject: {fileID: 1053814053} 250 | m_Enabled: 1 251 | m_EditorHideFlags: 0 252 | m_Script: {fileID: 11500000, guid: d3275c2e3072b9e4795516381548c4d4, type: 3} 253 | m_Name: 254 | m_EditorClassIdentifier: 255 | material: {fileID: 2100000, guid: 57e9ee814a02b164d81a3ee059c6a655, type: 2} 256 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scenes/TestScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86611fa213c255d4ba62654bbe09d2f8 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f662bf59edc17b842b7bbb5330ede8f3 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/EnumComboBox.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | // Popup list created by Eric Haines 4 | // ComboBox Extended by Hyungseok Seo.(Jerry) sdragoon@nate.com 5 | // 6 | // ----------------------------------------------- 7 | // This code working like ComboBox Control. 8 | // I just changed some part of code, 9 | // because I want to seperate ComboBox button and List. 10 | // ( You can see the result of this code from Description's last picture ) 11 | // ----------------------------------------------- 12 | // 13 | // === usage ====================================== 14 | // 15 | // public class SomeClass : MonoBehaviour 16 | // { 17 | // GUIContent[] comboBoxList; 18 | // private ComboBox comboBoxControl = new ComboBox(); 19 | // private GUIStyle listStyle = new GUIStyle(); 20 | // 21 | // private void Start() 22 | // { 23 | // comboBoxList = new GUIContent[5]; 24 | // comboBoxList[0] = new GUIContent("Thing 1"); 25 | // comboBoxList[1] = new GUIContent("Thing 2"); 26 | // comboBoxList[2] = new GUIContent("Thing 3"); 27 | // comboBoxList[3] = new GUIContent("Thing 4"); 28 | // comboBoxList[4] = new GUIContent("Thing 5"); 29 | // 30 | // listStyle.normal.textColor = Color.white; 31 | // listStyle.onHover.background = 32 | // listStyle.hover.background = new Texture2D(2, 2); 33 | // listStyle.padding.left = 34 | // listStyle.padding.right = 35 | // listStyle.padding.top = 36 | // listStyle.padding.bottom = 4; 37 | // } 38 | // 39 | // private void OnGUI () 40 | // { 41 | // int selectedItemIndex = comboBoxControl.GetSelectedItemIndex(); 42 | // selectedItemIndex = comboBoxControl.List( 43 | // new Rect(50, 100, 100, 20), comboBoxList[selectedItemIndex].text, comboBoxList, listStyle ); 44 | // GUI.Label( new Rect(50, 70, 400, 21), 45 | // "You picked " + comboBoxList[selectedItemIndex].text + "!" ); 46 | // } 47 | // } 48 | // 49 | // ================================================= 50 | 51 | using UnityEngine; 52 | 53 | public class EnumComboBox 54 | { 55 | private static int useControlID = -1; 56 | private bool isClickedComboButton = false; 57 | 58 | private int selectedItemIndex = 0; 59 | 60 | public System.Enum List(Rect rect, System.Enum selected, GUIStyle listStyle) 61 | { 62 | return List(rect, selected, "button", "box", listStyle); 63 | } 64 | 65 | public System.Enum List(Rect rect, System.Enum selected, GUIStyle buttonStyle, GUIStyle boxStyle, 66 | GUIStyle listStyle) 67 | { 68 | bool done = false; 69 | int controlID = GUIUtility.GetControlID(FocusType.Passive); 70 | 71 | switch (Event.current.GetTypeForControl(controlID)) 72 | { 73 | case EventType.mouseUp: 74 | { 75 | if (isClickedComboButton) 76 | { 77 | done = true; 78 | } 79 | } 80 | break; 81 | } 82 | 83 | if (GUI.Button(rect, selected.ToString(), buttonStyle)) 84 | { 85 | if (useControlID == -1) 86 | { 87 | useControlID = controlID; 88 | isClickedComboButton = false; 89 | } 90 | 91 | if (useControlID != controlID) 92 | { 93 | useControlID = controlID; 94 | } 95 | isClickedComboButton = true; 96 | } 97 | 98 | // turn the enumeration names into GUI Content 99 | string[] names = System.Enum.GetNames(selected.GetType()); 100 | //selectedItemIndex = names. 101 | 102 | GUIContent[] listContent = new GUIContent[names.Length]; 103 | for (int i = 0; i < names.Length; i++) 104 | { 105 | listContent[i] = new GUIContent(names[i]); 106 | 107 | // set the index based upon the passed in selected enumeration 108 | if (names[i] == selected.ToString()) 109 | { 110 | selectedItemIndex = i; 111 | } 112 | } 113 | 114 | if (isClickedComboButton) 115 | { 116 | Rect listRect = new Rect(rect.x, rect.y + listStyle.CalcHeight(listContent[0], 1.0f), 117 | rect.width, listStyle.CalcHeight(listContent[0], 1.0f)*listContent.Length); 118 | 119 | GUI.Box(listRect, "", boxStyle); 120 | int newSelectedItemIndex = GUI.SelectionGrid(listRect, selectedItemIndex, listContent, 1, listStyle); 121 | if (newSelectedItemIndex != selectedItemIndex) 122 | selectedItemIndex = newSelectedItemIndex; 123 | } 124 | 125 | if (done) 126 | isClickedComboButton = false; 127 | 128 | //return selectedItemIndex; 129 | return (System.Enum) System.Enum.Parse(selected.GetType(), names[selectedItemIndex]); 130 | } 131 | 132 | // public int GetSelectedItemIndex() 133 | // { 134 | // return selectedItemIndex; 135 | // } 136 | } 137 | } -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/EnumComboBox.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2bd7a3df830fd64a9b9ee81481af65c 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/GUIHelper.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | using UnityEngine; 4 | 5 | public static class GUILayoutHelper 6 | { 7 | private static float MaxLabelWidth = 130; 8 | private static float MinSliderWidth = 40; 9 | 10 | public static float Slider(string label, float value, float leftValue, float rightValue) 11 | { 12 | GUILayout.BeginHorizontal(); 13 | // force the width of the label to prevent the slider from changing size 14 | GUILayout.Label(string.Format("{0}{1:F2}", label, value), GUILayout.MaxWidth(MaxLabelWidth)); 15 | float newValue = GUILayout.HorizontalSlider(value, leftValue, rightValue, GUILayout.MinWidth(MinSliderWidth)); 16 | GUILayout.EndHorizontal(); 17 | 18 | return newValue; 19 | } 20 | 21 | public static int IntSlider(string label, int value, int leftValue, int rightValue) 22 | { 23 | GUILayout.BeginHorizontal(); 24 | // force the width of the label to prevent the slider from changing size 25 | GUILayout.Label(string.Format("{0}{1}", label, value), GUILayout.MaxWidth(MaxLabelWidth)); 26 | int newValue = 27 | (int) GUILayout.HorizontalSlider(value, leftValue, rightValue, GUILayout.MinWidth(MinSliderWidth)); 28 | GUILayout.EndHorizontal(); 29 | 30 | return newValue; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/GUIHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 03b2a88076ea66c4cbc6d9164a323369 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/GameObjectExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | using UnityEngine; 4 | 5 | /// 6 | /// Holds extension methods for a Unity . 7 | /// 8 | public static class GameObjectExtensions 9 | { 10 | /// 11 | /// Adds a to the and assigns it the given . 12 | /// 13 | /// The to add the to. 14 | /// The to assign. 15 | /// The newly created and added . 16 | public static MeshFilter AddMeshFilter(this GameObject gameObject, Mesh mesh) 17 | { 18 | MeshFilter meshFilter = gameObject.AddComponent(); 19 | meshFilter.sharedMesh = mesh; 20 | 21 | return meshFilter; 22 | } 23 | 24 | /// 25 | /// Adds a to the and disables shadows on it. 26 | /// 27 | /// The to add the to. 28 | /// The newly created and added . 29 | public static MeshRenderer AddMeshRenderer(this GameObject gameObject) 30 | { 31 | MeshRenderer meshRenderer = gameObject.AddComponent(); 32 | meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On; 33 | meshRenderer.receiveShadows = false; 34 | 35 | return meshRenderer; 36 | } 37 | 38 | /// 39 | /// Adds a to the , disables shadows on it, and assigns it the given . 40 | /// 41 | /// The to add the to. 42 | /// The to assign. 43 | /// The newly created and added . 44 | public static MeshRenderer AddMeshRenderer(this GameObject gameObject, Material material) 45 | { 46 | MeshRenderer meshRenderer = gameObject.AddMeshRenderer(); 47 | meshRenderer.sharedMaterial = material; 48 | 49 | return meshRenderer; 50 | } 51 | 52 | /// 53 | /// Adds a to the , disables shadows on it, assigns it the given , adds 54 | /// a (if there isn't one), and assigns it the given . 55 | /// 56 | /// The to add the to. 57 | /// The to assign. 58 | /// The to assign. 59 | /// The newly created and added . 60 | public static MeshRenderer AddMeshRenderer(this GameObject gameObject, Material material, Mesh mesh) 61 | { 62 | // add a MeshFilter automatically, if there isn't already one 63 | MeshFilter meshFilter = gameObject.GetComponent(); 64 | if (meshFilter == null) 65 | { 66 | gameObject.AddMeshFilter(mesh); 67 | } 68 | else 69 | { 70 | meshFilter.sharedMesh = mesh; 71 | } 72 | 73 | return gameObject.AddMeshRenderer(material); 74 | } 75 | 76 | /// 77 | /// Creates a that has a box , a . 78 | /// 79 | /// The to add the to. 80 | /// Radius of the circle. Value should be greater than or equal to 0.0f. 81 | /// The number of segments making up the circle. Value should be greater than or equal to 3. 82 | /// The starting angle of the circle. Usually 0. 83 | /// The angular size of the circle. 2 pi is a full circle. Pi is a half circle. 84 | public static void CreateCircle(this GameObject gameObject, float radius, int segments, float startAngle, 85 | float angularSize) 86 | { 87 | Mesh mesh = new Mesh(); 88 | mesh.CreateCircle(radius, segments, startAngle, angularSize); 89 | 90 | //gameObject.name = "Circle"; 91 | 92 | Shader shader = Shader.Find("Diffuse"); 93 | gameObject.AddMeshRenderer(new Material(shader), mesh); 94 | } 95 | 96 | public static void CreatePlane(this GameObject gameObject, float width, float height, int widthSegments, 97 | int heightSegments) 98 | { 99 | Mesh mesh = new Mesh(); 100 | mesh.CreatePlane(width, height, widthSegments, heightSegments); 101 | 102 | //gameObject.name = "Plane"; 103 | 104 | Shader shader = Shader.Find("Diffuse"); 105 | gameObject.AddMeshRenderer(new Material(shader), mesh); 106 | } 107 | 108 | public static void CreateBox(this GameObject gameObject, float width, float height, float depth, 109 | int widthSegments, int heightSegments, int depthSegments) 110 | { 111 | Mesh mesh = new Mesh(); 112 | mesh.CreateBox(width, height, depth, widthSegments, heightSegments, depthSegments); 113 | 114 | //gameObject.name = "Box"; 115 | 116 | Shader shader = Shader.Find("Diffuse"); 117 | gameObject.AddMeshRenderer(new Material(shader), mesh); 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/GameObjectExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02d1c5cd0b313334cbf645ce820013ff 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/InGameMenu.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | 6 | public class InGameMenu : MonoBehaviour 7 | { 8 | public Material material; 9 | 10 | private PrimitiveType primitiveType = PrimitiveType.Box; 11 | private PrimitiveType prevPrimitiveType = PrimitiveType.Box; 12 | 13 | // box, plane 14 | private float width = 5; 15 | private float height = 5; 16 | private float depth = 5; 17 | private int widthDivisions = 10; 18 | private int heightDivisions = 10; 19 | private int depthDivisions = 10; 20 | 21 | // sphere 22 | private float radius = 2.5f; 23 | private int stacks = 20; 24 | private int slices = 20; 25 | private float phiStart = 0; 26 | private float phiLength = 2*Mathf.PI; 27 | private float thetaStart = 0; 28 | private float thetaLength = Mathf.PI; 29 | 30 | // cylinder 31 | private float topRadius = 1; 32 | private float bottomRadius = 1; 33 | private float length = 5; 34 | private bool openEnded = false; 35 | 36 | // circle 37 | private int segments = 20; 38 | private float startAngle = 0; 39 | private float angularSize = 2*Mathf.PI; 40 | 41 | // ring 42 | private float innerRadius = 3; 43 | private float outerRadius = 5; 44 | private int phiSegments = 20; 45 | 46 | // torus 47 | private float tube = 1; 48 | private int radialSegments = 50; 49 | private int tubularSegments = 20; 50 | private float arc = 2*Mathf.PI; 51 | 52 | // torus knot 53 | private int p = 2; 54 | private int q = 3; 55 | private float heightScale = 1; 56 | 57 | private GUIStyle listStyle; 58 | private EnumComboBox comboBoxControl = new EnumComboBox(); 59 | 60 | private GameObject shape; 61 | private MeshFilter filter; 62 | private MouseCamera mouseCamera; 63 | 64 | private bool wireframe; 65 | 66 | private List points = new List(); // {new }; 67 | 68 | private void Start() 69 | { 70 | listStyle = new GUIStyle(); 71 | listStyle.normal.textColor = Color.white; 72 | 73 | var texture = new Texture2D(2, 2); 74 | listStyle.hover.background = texture; 75 | listStyle.onHover.background = texture; 76 | 77 | listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4; 78 | 79 | shape = new GameObject("Test Shape"); 80 | shape.CreateBox(width, height, depth, widthDivisions, heightDivisions, depthDivisions); 81 | shape.GetComponent().sharedMaterial = material; 82 | 83 | filter = shape.GetComponent(); 84 | GL.wireframe = true; 85 | 86 | mouseCamera = GetComponent(); 87 | mouseCamera.target = shape.transform; 88 | 89 | for (var i = 0; i < 50; i ++) 90 | { 91 | //points.Add(new Vector3(Mathf.Sin( i * 0.2f ) * Mathf.Sin( i * 0.1f ) * 15 + 50, 0, ( i - 5.0f ) * 2.0f ) ); 92 | points.Add(new Vector3(Mathf.Sin(i*0.2f)*Mathf.Sin(i*0.1f)*15, 0, (i - 5.0f)*2.0f)); 93 | //points.Add(new Vector3(Mathf.Sin(i * 0.4f) * Mathf.Sin(i * 0.2f) * 1, 0, (i-2) * 2.0f)); 94 | } 95 | } 96 | 97 | private void OnPreRender() 98 | { 99 | GL.wireframe = wireframe; 100 | } 101 | 102 | private void OnPostRender() 103 | { 104 | GL.wireframe = false; 105 | } 106 | 107 | private void OnGUI() 108 | { 109 | points.Clear(); 110 | for (var i = 0; i < 50; i ++) 111 | { 112 | points.Add(new Vector3(Mathf.Sin(i*0.2f)*Mathf.Sin(i*0.1f)*15 + 50, 0, (i - 25.0f)*2.0f)); 113 | //points.Add(new Vector3(Mathf.Sin(i * 0.2f) * Mathf.Sin(i * 0.1f) * 15 + 40, 0, i)); 114 | //points.Add(new Vector3(Mathf.Sin(i * 0.4f) * Mathf.Sin(i * 0.2f) * 1, 0, (i-2) * 2.0f)); 115 | } 116 | 117 | GUILayout.Label("Primitive Type: ", GUILayout.MinWidth(500)); 118 | primitiveType = 119 | (PrimitiveType) comboBoxControl.List(new Rect(100, 2, 100, 20), prevPrimitiveType, listStyle); 120 | 121 | if (primitiveType != prevPrimitiveType) 122 | { 123 | // if it's a 2D shape, reset the camera position so it is visible 124 | if (primitiveType == PrimitiveType.Circle || 125 | primitiveType == PrimitiveType.Plane || 126 | primitiveType == PrimitiveType.Ring) 127 | { 128 | Camera.main.transform.localPosition = new Vector3(0, 0, -10); 129 | Camera.main.transform.localRotation = Quaternion.identity; 130 | 131 | mouseCamera.UpdateAngles(); 132 | } 133 | 134 | if (prevPrimitiveType == PrimitiveType.Lathe) 135 | { 136 | shape.transform.localScale = Vector3.one; 137 | //Camera.main.transform.localPosition = new Vector3(0, 0, -10); 138 | //Camera.main.transform.localRotation = Quaternion.identity; 139 | 140 | //mouseCamera.UpdateAngles(); 141 | } 142 | 143 | if (primitiveType == PrimitiveType.Lathe) 144 | { 145 | shape.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); 146 | //Camera.main.transform.localPosition = new Vector3(0, 0, -10); 147 | //Camera.main.transform.localRotation = Quaternion.identity; 148 | 149 | //mouseCamera.UpdateAngles(); 150 | } 151 | 152 | prevPrimitiveType = primitiveType; 153 | } 154 | 155 | wireframe = GUILayout.Toggle(wireframe, " Wireframe"); 156 | 157 | switch (primitiveType) 158 | { 159 | case PrimitiveType.Box: 160 | width = GUILayoutHelper.Slider("Width: ", width, 0.01f, 10); 161 | height = GUILayoutHelper.Slider("Height: ", height, 0.01f, 10); 162 | depth = GUILayoutHelper.Slider("Depth: ", depth, 0.01f, 10); 163 | widthDivisions = GUILayoutHelper.IntSlider("Width Divisions: ", widthDivisions, 1, 75); 164 | heightDivisions = GUILayoutHelper.IntSlider("Height Divisions: ", heightDivisions, 1, 75); 165 | depthDivisions = GUILayoutHelper.IntSlider("Depth Divisions: ", depthDivisions, 1, 75); 166 | break; 167 | case PrimitiveType.Circle: 168 | radius = GUILayoutHelper.Slider("Radius: ", radius, 0.01f, 5); 169 | segments = GUILayoutHelper.IntSlider("Segments: ", segments, 3, 50); 170 | startAngle = GUILayoutHelper.Slider("Start Angle: ", startAngle, 0.0f, Mathf.PI*2); 171 | angularSize = GUILayoutHelper.Slider("Angular Size: ", angularSize, 0.0f, Mathf.PI*2); 172 | break; 173 | case PrimitiveType.Cylinder: 174 | bottomRadius = GUILayoutHelper.Slider("Bottom Radius: ", bottomRadius, 0.0f, 10); 175 | topRadius = GUILayoutHelper.Slider("Top Radius: ", topRadius, 0.0f, 10); 176 | length = GUILayoutHelper.Slider("Length: ", length, 0.01f, 10); 177 | stacks = GUILayoutHelper.IntSlider("Stacks: ", stacks, 1, 100); 178 | slices = GUILayoutHelper.IntSlider("Slices: ", slices, 2, 100); 179 | openEnded = GUILayout.Toggle(openEnded, " Open Ended"); 180 | break; 181 | case PrimitiveType.Lathe: 182 | //radius = GUILayoutHelper.Slider("Radius: ", radius, 0.01f, 5); 183 | segments = GUILayoutHelper.IntSlider("Segments: ", segments, 3, 50); 184 | startAngle = GUILayoutHelper.Slider("Start Angle: ", startAngle, 0.0f, Mathf.PI*2); 185 | angularSize = GUILayoutHelper.Slider("Angular Size: ", angularSize, 0.0f, Mathf.PI*2); 186 | break; 187 | case PrimitiveType.Plane: 188 | width = GUILayoutHelper.Slider("Width: ", width, 0.01f, 10); 189 | height = GUILayoutHelper.Slider("Height: ", height, 0.01f, 10); 190 | widthDivisions = GUILayoutHelper.IntSlider("Width Divisions: ", widthDivisions, 1, 100); 191 | heightDivisions = GUILayoutHelper.IntSlider("Height Divisions: ", heightDivisions, 1, 100); 192 | break; 193 | case PrimitiveType.Ring: 194 | innerRadius = GUILayoutHelper.Slider("Inner Radius: ", innerRadius, 0.01f, 15); 195 | outerRadius = GUILayoutHelper.Slider("Outer Radius: ", outerRadius, 0.01f, 15); 196 | segments = GUILayoutHelper.IntSlider("Theta Segments: ", segments, 3, 50); 197 | phiSegments = GUILayoutHelper.IntSlider("Phi Segments: ", phiSegments, 1, 50); 198 | startAngle = GUILayoutHelper.Slider("Start Angle: ", startAngle, 0.0f, Mathf.PI*2); 199 | angularSize = GUILayoutHelper.Slider("Angular Size: ", angularSize, 0.0f, Mathf.PI*2); 200 | break; 201 | case PrimitiveType.Sphere: 202 | radius = GUILayoutHelper.Slider("Radius: ", radius, 0.01f, 5); 203 | stacks = GUILayoutHelper.IntSlider("Stacks: ", stacks, 1, 100); 204 | slices = GUILayoutHelper.IntSlider("Slices: ", slices, 1, 100); 205 | phiStart = GUILayoutHelper.Slider("Phi Start: ", phiStart, 0.0f, 2*Mathf.PI); 206 | phiLength = GUILayoutHelper.Slider("Phi Length: ", phiLength, 0.0f, 2*Mathf.PI); 207 | thetaStart = GUILayoutHelper.Slider("Theta Start: ", thetaStart, 0.0f, Mathf.PI); 208 | thetaLength = GUILayoutHelper.Slider("Theta Length: ", thetaLength, 0.0f, Mathf.PI); 209 | break; 210 | case PrimitiveType.Torus: 211 | radius = GUILayoutHelper.Slider("Radius: ", radius, 0.01f, 5); 212 | tube = GUILayoutHelper.Slider("Tube Radius: ", tube, 0.01f, 5); 213 | radialSegments = GUILayoutHelper.IntSlider("Radial Segments: ", radialSegments, 8, 100); 214 | tubularSegments = GUILayoutHelper.IntSlider("Tubular Segments: ", tubularSegments, 6, 100); 215 | arc = GUILayoutHelper.Slider("Arc: ", arc, 0.0f, 2*Mathf.PI); 216 | break; 217 | case PrimitiveType.TorusKnot: 218 | radius = GUILayoutHelper.Slider("Radius: ", radius, 0.01f, 5); 219 | tube = GUILayoutHelper.Slider("Tube Radius: ", tube, 0.01f, 5); 220 | radialSegments = GUILayoutHelper.IntSlider("Radial Segments: ", radialSegments, 8, 100); 221 | tubularSegments = GUILayoutHelper.IntSlider("Tubular Segments: ", tubularSegments, 6, 100); 222 | p = GUILayoutHelper.IntSlider("P: ", p, 1, 10); 223 | q = GUILayoutHelper.IntSlider("Q: ", q, 1, 10); 224 | heightScale = GUILayoutHelper.Slider("Height Scale: ", heightScale, 0.0f, 2.0f); 225 | break; 226 | } 227 | 228 | //primitiveType = (PrimitiveType)comboBoxControl.List(new Rect(100, 2, 100, 20), primitiveType, listStyle); 229 | 230 | //if (GUILayout.Button("Create")) 231 | { 232 | switch (primitiveType) 233 | { 234 | case PrimitiveType.Box: 235 | filter.sharedMesh.CreateBox(width, height, depth, widthDivisions, heightDivisions, 236 | depthDivisions); 237 | break; 238 | case PrimitiveType.Circle: 239 | filter.sharedMesh.CreateCircle(radius, segments, startAngle, angularSize); 240 | break; 241 | case PrimitiveType.Cylinder: 242 | filter.sharedMesh.CreateCylinder(topRadius, bottomRadius, length, slices, stacks, openEnded); 243 | break; 244 | case PrimitiveType.Lathe: 245 | filter.sharedMesh.CreateLathe(points, segments, startAngle, angularSize); 246 | break; 247 | case PrimitiveType.Plane: 248 | filter.sharedMesh.CreatePlane(width, height, widthDivisions, heightDivisions); 249 | break; 250 | case PrimitiveType.Ring: 251 | filter.sharedMesh.CreateRing(innerRadius, outerRadius, segments, phiSegments, startAngle, 252 | angularSize); 253 | break; 254 | case PrimitiveType.Sphere: 255 | filter.sharedMesh.CreateSphere(radius, slices, stacks, phiStart, phiLength, thetaStart, 256 | thetaLength); 257 | break; 258 | case PrimitiveType.Torus: 259 | filter.sharedMesh.CreateTorus(radius, tube, radialSegments, tubularSegments, arc); 260 | break; 261 | case PrimitiveType.TorusKnot: 262 | filter.sharedMesh.CreateTorusKnot(radius, tube, radialSegments, tubularSegments, p, q, 263 | heightScale); 264 | break; 265 | } 266 | } 267 | 268 | } 269 | 270 | } 271 | } -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/InGameMenu.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d3275c2e3072b9e4795516381548c4d4 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/MeshExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | 7 | /// 8 | /// Holds extension methods for a Unity . 9 | /// 10 | public static class MeshExtensions 11 | { 12 | /// 13 | /// The formatted path to a asset. 14 | /// 15 | private const string MeshPath = "Assets/Meshes/{0}.asset"; 16 | 17 | /// 18 | /// Serializes the out to the hard drive as an asset. This only works in the Editor and will do nothing at runtime. 19 | /// 20 | /// The to create the asset from. 21 | public static void CreateAsset(this Mesh mesh) 22 | { 23 | #if UNITY_EDITOR 24 | // Detect if Meshes folder exists and create it if it does not 25 | if (!Directory.Exists(Application.dataPath + "/Meshes")) 26 | { 27 | UnityEditor.AssetDatabase.CreateFolder("Assets", "Meshes"); 28 | } 29 | 30 | UnityEditor.AssetDatabase.CreateAsset(mesh, string.Format(MeshPath, mesh.name)); 31 | #endif 32 | } 33 | 34 | /// 35 | /// Fills this with vertices forming a 3D box. 36 | /// 37 | /// The to fill with vertices. 38 | /// Radius of the circle. Value should be greater than or equal to 0.0f. 39 | /// The number of segments making up the circle. Value should be greater than or equal to 3. 40 | /// The starting angle of the circle. Usually 0. 41 | /// The angular size of the circle. 2 pi is a full circle. Pi is a half circle. 42 | public static void CreateBox(this Mesh mesh, float width, float height, float depth, int widthSegments, 43 | int heightSegments, int depthSegments) 44 | { 45 | mesh.name = "Box"; 46 | mesh.Clear(); 47 | 48 | List uvs = new List(); 49 | List vertices = new List(); 50 | List triangles = new List(); 51 | 52 | var width_half = width/2.0f; 53 | var height_half = height/2.0f; 54 | var depth_half = depth/2.0f; 55 | 56 | BuildBoxSide(ref vertices, ref uvs, ref triangles, 2, 1, -1, -1, depth, height, width_half, widthSegments, 57 | heightSegments, depthSegments); // px 58 | BuildBoxSide(ref vertices, ref uvs, ref triangles, 2, 1, 1, -1, depth, height, -width_half, widthSegments, 59 | heightSegments, depthSegments); // nx 60 | BuildBoxSide(ref vertices, ref uvs, ref triangles, 0, 2, 1, 1, width, depth, height_half, widthSegments, 61 | heightSegments, depthSegments); // py 62 | BuildBoxSide(ref vertices, ref uvs, ref triangles, 0, 2, 1, -1, width, depth, -height_half, widthSegments, 63 | heightSegments, depthSegments); // ny 64 | BuildBoxSide(ref vertices, ref uvs, ref triangles, 0, 1, 1, -1, width, height, depth_half, widthSegments, 65 | heightSegments, depthSegments); // pz 66 | BuildBoxSide(ref vertices, ref uvs, ref triangles, 0, 1, -1, -1, width, height, -depth_half, widthSegments, 67 | heightSegments, depthSegments); // nz 68 | 69 | //this.computeCentroids(); 70 | //this.mergeVertices(); 71 | 72 | mesh.vertices = vertices.ToArray(); 73 | //mesh.normals = normals; 74 | mesh.uv = uvs.ToArray(); 75 | mesh.triangles = triangles.ToArray(); 76 | 77 | mesh.RecalculateNormals(); 78 | //mesh.RecalculateBounds(); 79 | } 80 | 81 | /// 82 | /// Helper method used to build a side of a box. 83 | /// 84 | /// Vertices. 85 | /// Uvs. 86 | /// Triangles. 87 | /// U. 88 | /// V. 89 | /// Udir. 90 | /// Vdir. 91 | /// Width. 92 | /// Height. 93 | /// Depth. 94 | /// Width segments. 95 | /// Height segments. 96 | /// Depth segments. 97 | private static void BuildBoxSide(ref List vertices, ref List uvs, ref List triangles, 98 | int u, int v, int udir, int vdir, float width, float height, float depth, int widthSegments, 99 | int heightSegments, int depthSegments) 100 | { 101 | int w = 2; 102 | int ix; 103 | int iy; 104 | var gridX = widthSegments; 105 | var gridY = heightSegments; 106 | var width_half = width/2.0f; 107 | var height_half = height/2.0f; 108 | var offset = vertices.Count; 109 | 110 | if ((u == 0 && v == 1) || (u == 1 && v == 0)) 111 | { 112 | w = 2; 113 | } 114 | else if ((u == 0 && v == 2) || (u == 2 && v == 0)) 115 | { 116 | w = 1; 117 | gridY = depthSegments; 118 | } 119 | else if ((u == 2 && v == 1) || (u == 1 && v == 2)) 120 | { 121 | w = 0; 122 | gridX = depthSegments; 123 | } 124 | 125 | var gridX1 = gridX + 1; 126 | var gridY1 = gridY + 1; 127 | var segment_width = width/gridX; 128 | var segment_height = height/gridY; 129 | var normal = new Vector3(); 130 | 131 | normal[w] = depth > 0 ? 1 : - 1; 132 | 133 | for (iy = 0; iy < gridY1; iy ++) 134 | { 135 | for (ix = 0; ix < gridX1; ix ++) 136 | { 137 | var vector = new Vector3(); 138 | vector[u] = (ix*segment_width - width_half)*udir; 139 | vector[v] = (iy*segment_height - height_half)*vdir; 140 | vector[w] = depth; 141 | 142 | var uv = new Vector2(1.0f - (float) ix/gridX, 1.0f - (float) iy/gridY); 143 | 144 | vertices.Add(vector); 145 | uvs.Add(uv); 146 | } 147 | } 148 | 149 | for (iy = 0; iy < gridY; iy++) 150 | { 151 | for (ix = 0; ix < gridX; ix++) 152 | { 153 | var a = ix + gridX1*iy; 154 | var b = ix + gridX1*(iy + 1); 155 | var c = (ix + 1) + gridX1*(iy + 1); 156 | var d = (ix + 1) + gridX1*iy; 157 | 158 | triangles.Add(a + offset); 159 | triangles.Add(b + offset); 160 | triangles.Add(d + offset); 161 | 162 | triangles.Add(b + offset); 163 | triangles.Add(c + offset); 164 | triangles.Add(d + offset); 165 | } 166 | } 167 | } 168 | 169 | /// 170 | /// Fills this with vertices forming a 2D circle. 171 | /// 172 | /// The to fill with vertices. 173 | /// Top radius of the cylinder. Value should be greater than or equal to 0.0f. 174 | /// The number of segments making up the circle. Value should be greater than or equal to 3. 175 | /// The starting angle of the circle. Usually 0. 176 | /// The angular size of the circle. 2 pi is a full circle. Pi is a half circle. 177 | public static void CreateCylinder(this Mesh mesh, float topRadius, float bottomRadius, float height, 178 | int radialSegments, int heightSegments, bool openEnded) 179 | { 180 | mesh.name = "Cylinder"; 181 | mesh.Clear(); 182 | 183 | List uvs = new List(); 184 | List vertices = new List(); 185 | List triangles = new List(); 186 | 187 | var heightHalf = height/2; 188 | int y; 189 | 190 | List> verticesLists = new List>(); 191 | List> uvsLists = new List>(); 192 | 193 | for (y = 0; y <= heightSegments; y++) 194 | { 195 | List verticesRow = new List(); 196 | List uvsRow = new List(); 197 | 198 | var v = y/(float) heightSegments; 199 | var radius = v*(bottomRadius - topRadius) + topRadius; 200 | 201 | for (int x = 0; x <= radialSegments; x++) 202 | { 203 | float u = (float) x/(float) radialSegments; 204 | 205 | var vertex = new Vector3(); 206 | vertex.x = radius*Mathf.Sin(u*Mathf.PI*2.0f); 207 | vertex.y = - v*height + heightHalf; 208 | vertex.z = radius*Mathf.Cos(u*Mathf.PI*2.0f); 209 | 210 | vertices.Add(vertex); 211 | uvs.Add(new Vector2(1 - u, 1 - v)); 212 | 213 | verticesRow.Add(vertices.Count - 1); 214 | uvsRow.Add(new Vector2(u, 1 - v)); 215 | } 216 | 217 | verticesLists.Add(verticesRow); 218 | uvsLists.Add(uvsRow); 219 | } 220 | 221 | var tanTheta = (bottomRadius - topRadius)/height; 222 | Vector3 na; 223 | Vector3 nb; 224 | 225 | 226 | 227 | for (int x = 0; x < radialSegments; x++) 228 | { 229 | if (topRadius != 0) 230 | { 231 | na = vertices[verticesLists[0][x]]; 232 | nb = vertices[verticesLists[0][x + 1]]; 233 | } 234 | else 235 | { 236 | na = vertices[verticesLists[1][x]]; 237 | nb = vertices[verticesLists[1][x + 1]]; 238 | } 239 | 240 | // normalize? 241 | na.y = (Mathf.Sqrt(na.x*na.x + na.z*na.z)*tanTheta); 242 | nb.y = (Mathf.Sqrt(nb.x*nb.x + nb.z*nb.z)*tanTheta); 243 | 244 | for (y = 0; y < heightSegments; y++) 245 | { 246 | var v1 = verticesLists[y][x]; 247 | var v2 = verticesLists[y + 1][x]; 248 | var v3 = verticesLists[y + 1][x + 1]; 249 | var v4 = verticesLists[y][x + 1]; 250 | 251 | //var n1 = na; 252 | //var n2 = na; 253 | //var n3 = nb; 254 | //var n4 = nb; 255 | 256 | triangles.Add(v1); 257 | triangles.Add(v2); 258 | triangles.Add(v4); 259 | 260 | triangles.Add(v2); 261 | triangles.Add(v3); 262 | triangles.Add(v4); 263 | } 264 | 265 | } 266 | 267 | // top cap 268 | if (!openEnded && topRadius > 0) 269 | { 270 | vertices.Add(new Vector3(0, heightHalf, 0)); 271 | //uvs.Add(new Vector2(uvsLists[0][0 + 1].x, 0)); 272 | uvs.Add(new Vector2(0.5f, 0)); 273 | 274 | for (int x = 0; x < radialSegments; x ++) 275 | { 276 | var v1 = verticesLists[0][x]; 277 | var v2 = verticesLists[0][x + 1]; 278 | var v3 = vertices.Count - 1; 279 | 280 | //var n1 = new Vector3( 0, 1, 0 ); 281 | //var n2 = new Vector3( 0, 1, 0 ); 282 | //var n3 = new Vector3( 0, 1, 0 ); 283 | 284 | //var uv1 = uvsLists[ 0 ][ x ]; 285 | //var uv2 = uvsLists[ 0 ][ x + 1 ]; 286 | //var uv3 = new Vector2( uv2.x, 0 ); 287 | 288 | triangles.Add(v1); 289 | triangles.Add(v2); 290 | triangles.Add(v3); 291 | } 292 | } 293 | 294 | // bottom cap 295 | if (!openEnded && bottomRadius > 0) 296 | { 297 | vertices.Add(new Vector3(0, - heightHalf, 0)); 298 | uvs.Add(new Vector2(0.5f, 1)); 299 | 300 | for (int x = 0; x < radialSegments; x++) 301 | { 302 | var v1 = verticesLists[y][x + 1]; 303 | var v2 = verticesLists[y][x]; 304 | var v3 = vertices.Count - 1; 305 | 306 | //var n1 = new Vector3( 0, - 1, 0 ); 307 | //var n2 = new Vector3( 0, - 1, 0 ); 308 | //var n3 = new Vector3( 0, - 1, 0 ); 309 | 310 | //var uv1 = uvsLists[ y ][ x + 1 ]; 311 | //var uv2 = uvsLists[ y ][ x ]; 312 | //var uv3 = new Vector2( uv2.x, 1 ); 313 | 314 | triangles.Add(v1); 315 | triangles.Add(v2); 316 | triangles.Add(v3); 317 | } 318 | } 319 | 320 | mesh.vertices = vertices.ToArray(); 321 | //mesh.normals = normals; 322 | mesh.uv = uvs.ToArray(); 323 | mesh.triangles = triangles.ToArray(); 324 | 325 | mesh.RecalculateNormals(); 326 | //mesh.RecalculateBounds(); 327 | } 328 | 329 | /// 330 | /// Fills this with vertices forming a 2D circle. 331 | /// 332 | /// The to fill with vertices. 333 | /// Radius of the circle. Value should be greater than or equal to 0.0f. 334 | /// The number of segments making up the circle. Value should be greater than or equal to 3. 335 | /// The starting angle of the circle. Usually 0. 336 | /// The angular size of the circle. 2 pi is a full circle. Pi is a half circle. 337 | public static void CreateCircle(this Mesh mesh, float radius, int segments, float startAngle, float angularSize) 338 | { 339 | mesh.name = "Circle"; 340 | mesh.Clear(); 341 | 342 | List uvs = new List(); 343 | List vertices = new List(); 344 | List triangles = new List(); 345 | 346 | vertices.Add(Vector3.zero); 347 | uvs.Add(new Vector2(0.5f, 0.5f)); 348 | 349 | float stepAngle = angularSize/segments; 350 | 351 | for (int i = 0; i <= segments; i++) 352 | { 353 | var vertex = new Vector3(); 354 | float angle = startAngle + stepAngle*i; 355 | 356 | //Debug.Log(string.Format("{0}: {1}", i, angle)); 357 | vertex.x = radius*Mathf.Cos(angle); 358 | vertex.y = radius*Mathf.Sin(angle); 359 | 360 | vertices.Add(vertex); 361 | uvs.Add(new Vector2((vertex.x/radius + 1)/2, (vertex.y/radius + 1)/2)); 362 | } 363 | 364 | //var n = new Vector3(0, 0, 1); 365 | 366 | for (int i = 1; i <= segments; i++) 367 | { 368 | triangles.Add(i + 1); 369 | triangles.Add(i); 370 | triangles.Add(0); 371 | } 372 | 373 | mesh.vertices = vertices.ToArray(); 374 | //mesh.normals = normals; 375 | mesh.uv = uvs.ToArray(); 376 | mesh.triangles = triangles.ToArray(); 377 | 378 | mesh.RecalculateNormals(); 379 | //mesh.RecalculateBounds(); 380 | } 381 | 382 | public static void CreateLathe(this Mesh mesh, List points, int segments, float phiStart, 383 | float phiLength) 384 | { 385 | mesh.name = "Lathe"; 386 | mesh.Clear(); 387 | 388 | List uvs = new List(); 389 | List vertices = new List(); 390 | List triangles = new List(); 391 | 392 | ////var inversePointLength = 1.0f / ( points.Count - 1 ); 393 | var inverseSegments = 1.0f/segments; 394 | 395 | for (var i = 0; i <= segments; i++) 396 | { 397 | var phi = phiStart + i*inverseSegments*phiLength; 398 | 399 | var c = Mathf.Cos(phi); 400 | var s = Mathf.Sin(phi); 401 | 402 | for (var j = 0; j < points.Count; j++) 403 | { 404 | var pt = points[j]; 405 | 406 | var vertex = new Vector3(); 407 | 408 | vertex.x = c*pt.x - s*pt.y; 409 | vertex.y = s*pt.x + c*pt.y; 410 | vertex.z = pt.z; 411 | 412 | vertices.Add(vertex); 413 | uvs.Add(new Vector2(i*inverseSegments, j*inverseSegments)); 414 | } 415 | } 416 | 417 | var np = points.Count; 418 | 419 | for (var i = 0; i < segments; i++) 420 | { 421 | for (var j = 0; j < points.Count - 1; j++) 422 | { 423 | var baseP = j + np*i; 424 | var a = baseP; 425 | var b = baseP + np; 426 | var c = baseP + 1 + np; 427 | var d = baseP + 1; 428 | 429 | // var u0 = i * inverseSegments; 430 | // var v0 = j * inversePointLength; 431 | // var u1 = u0 + inverseSegments; 432 | // var v1 = v0 + inversePointLength; 433 | 434 | triangles.Add(a); 435 | triangles.Add(b); 436 | triangles.Add(d); 437 | 438 | triangles.Add(b); 439 | triangles.Add(c); 440 | triangles.Add(d); 441 | 442 | // this.faces.push( new THREE.Face3( a, b, d ) ); 443 | // 444 | // this.faceVertexUvs[ 0 ].push( [ 445 | // 446 | // new THREE.Vector2( u0, v0 ), 447 | // new THREE.Vector2( u1, v0 ), 448 | // new THREE.Vector2( u0, v1 ) 449 | // 450 | // ] ); 451 | // 452 | // this.faces.push( new THREE.Face3( b, c, d ) ); 453 | // 454 | // this.faceVertexUvs[ 0 ].push( [ 455 | // 456 | // new THREE.Vector2( u1, v0 ), 457 | // new THREE.Vector2( u1, v1 ), 458 | // new THREE.Vector2( u0, v1 ) 459 | // 460 | // ] ); 461 | 462 | 463 | } 464 | 465 | } 466 | 467 | mesh.vertices = vertices.ToArray(); 468 | //mesh.normals = normals; 469 | mesh.uv = uvs.ToArray(); 470 | mesh.triangles = triangles.ToArray(); 471 | 472 | mesh.RecalculateNormals(); 473 | //mesh.RecalculateBounds(); 474 | } 475 | 476 | /// 477 | /// Fills this with vertices forming a 2D circle. 478 | /// 479 | /// The to fill with vertices. 480 | /// Radius of the circle. Value should be greater than or equal to 0.0f. 481 | /// The number of segments making up the circle. Value should be greater than or equal to 3. 482 | /// The starting angle of the circle. Usually 0. 483 | /// The angular size of the circle. 2 pi is a full circle. Pi is a half circle. 484 | public static void CreateSphere(this Mesh mesh, float radius, int widthSegments, int heightSegments, 485 | float phiStart, float phiLength, float thetaStart, float thetaLength) 486 | { 487 | mesh.name = "Sphere"; 488 | mesh.Clear(); 489 | 490 | List uvs = new List(); 491 | List vertices = new List(); 492 | List triangles = new List(); 493 | 494 | int x, y; 495 | 496 | List> verticesLists = new List>(); 497 | List> uvsLists = new List>(); 498 | 499 | for (y = 0; y <= heightSegments; y ++) 500 | { 501 | List verticesRow = new List(); 502 | List uvsRow = new List(); 503 | 504 | for (x = 0; x <= widthSegments; x ++) 505 | { 506 | var u = x/(float) widthSegments; 507 | var v = y/(float) heightSegments; 508 | 509 | var vertex = new Vector3(); 510 | vertex.x = - radius*Mathf.Cos(phiStart + u*phiLength)*Mathf.Sin(thetaStart + v*thetaLength); 511 | vertex.y = radius*Mathf.Cos(thetaStart + v*thetaLength); 512 | vertex.z = radius*Mathf.Sin(phiStart + u*phiLength)*Mathf.Sin(thetaStart + v*thetaLength); 513 | 514 | vertices.Add(vertex); 515 | uvs.Add(new Vector2(u, 1 - v)); 516 | 517 | verticesRow.Add(vertices.Count - 1); 518 | uvsRow.Add(new Vector2(u, 1 - v)); 519 | } 520 | 521 | verticesLists.Add(verticesRow); 522 | uvsLists.Add(uvsRow); 523 | } 524 | 525 | for (y = 0; y < heightSegments; y ++) 526 | { 527 | for (x = 0; x < widthSegments; x ++) 528 | { 529 | var v1 = verticesLists[y][x + 1]; 530 | var v2 = verticesLists[y][x]; 531 | var v3 = verticesLists[y + 1][x]; 532 | var v4 = verticesLists[y + 1][x + 1]; 533 | 534 | // normalize 535 | //var n1 = vertices[ v1 ]; 536 | //var n2 = vertices[ v2 ]; 537 | //var n3 = vertices[ v3 ]; 538 | //var n4 = vertices[ v4 ]; 539 | 540 | var uv1 = uvsLists[y][x + 1]; 541 | var uv2 = uvsLists[y][x]; 542 | var uv3 = uvsLists[y + 1][x]; 543 | var uv4 = uvsLists[y + 1][x + 1]; 544 | 545 | if (Mathf.Abs(vertices[v1].y) == radius) 546 | { 547 | uv1.x = (uv1.x + uv2.x)/2; 548 | 549 | triangles.Add(v1); 550 | triangles.Add(v3); 551 | triangles.Add(v4); 552 | 553 | //this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) ); 554 | //this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] ); 555 | } 556 | else if (Mathf.Abs(vertices[v3].y) == radius) 557 | { 558 | uv3.x = (uv3.x + uv4.x)/2; 559 | 560 | triangles.Add(v1); 561 | triangles.Add(v2); 562 | triangles.Add(v3); 563 | 564 | //this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) ); 565 | //this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] ); 566 | } 567 | else 568 | { 569 | triangles.Add(v1); 570 | triangles.Add(v2); 571 | triangles.Add(v4); 572 | 573 | triangles.Add(v2); 574 | triangles.Add(v3); 575 | triangles.Add(v4); 576 | 577 | //this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) ); 578 | //this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] ); 579 | 580 | //this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) ); 581 | //this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] ); 582 | } 583 | } 584 | } 585 | 586 | mesh.vertices = vertices.ToArray(); 587 | //mesh.normals = normals; 588 | mesh.uv = uvs.ToArray(); 589 | mesh.triangles = triangles.ToArray(); 590 | 591 | mesh.RecalculateNormals(); 592 | //mesh.RecalculateBounds(); 593 | } 594 | 595 | /// 596 | /// Fills this with vertices forming a 2D circle. 597 | /// 598 | /// The to fill with vertices. 599 | /// Radius of the circle. Value should be greater than or equal to 0.0f. 600 | /// The number of segments making up the circle. Value should be greater than or equal to 3. 601 | /// The starting angle of the circle. Usually 0. 602 | /// The angular size of the circle. 2 pi is a full circle. Pi is a half circle. 603 | public static void CreateTorus(this Mesh mesh, float radius, float tube, int radialSegments, int tubularSegments, 604 | float arc) 605 | { 606 | mesh.name = "Torus"; 607 | mesh.Clear(); 608 | 609 | List uvs = new List(); 610 | List vertices = new List(); 611 | List normals = new List(); 612 | List triangles = new List(); 613 | 614 | var center = new Vector3(); 615 | 616 | for (var j = 0; j <= radialSegments; j++) 617 | { 618 | for (var i = 0; i <= tubularSegments; i++) 619 | { 620 | var u = i/(float) tubularSegments*arc; 621 | var v = j/(float) radialSegments*Mathf.PI*2.0f; 622 | 623 | center.x = radius*Mathf.Cos(u); 624 | center.y = radius*Mathf.Sin(u); 625 | 626 | var vertex = new Vector3(); 627 | vertex.x = (radius + tube*Mathf.Cos(v))*Mathf.Cos(u); 628 | vertex.y = (radius + tube*Mathf.Cos(v))*Mathf.Sin(u); 629 | vertex.z = tube*Mathf.Sin(v); 630 | 631 | vertices.Add(vertex); 632 | 633 | uvs.Add(new Vector2(i/(float) tubularSegments, j/(float) radialSegments)); 634 | Vector3 normal = vertex - center; 635 | normal.Normalize(); 636 | normals.Add(normal); 637 | } 638 | } 639 | 640 | 641 | for (var j = 1; j <= radialSegments; j++) 642 | { 643 | for (var i = 1; i <= tubularSegments; i++) 644 | { 645 | var a = (tubularSegments + 1)*j + i - 1; 646 | var b = (tubularSegments + 1)*(j - 1) + i - 1; 647 | var c = (tubularSegments + 1)*(j - 1) + i; 648 | var d = (tubularSegments + 1)*j + i; 649 | 650 | triangles.Add(a); 651 | triangles.Add(b); 652 | triangles.Add(d); 653 | 654 | triangles.Add(b); 655 | triangles.Add(c); 656 | triangles.Add(d); 657 | } 658 | 659 | } 660 | 661 | mesh.vertices = vertices.ToArray(); 662 | mesh.normals = normals.ToArray(); 663 | mesh.uv = uvs.ToArray(); 664 | mesh.triangles = triangles.ToArray(); 665 | } 666 | 667 | public static void CreateTorusKnot(this Mesh mesh, float radius, float tube, int radialSegments, 668 | int tubularSegments) 669 | { 670 | mesh.CreateTorusKnot(radius, tube, radialSegments, tubularSegments, 2, 3, 1); 671 | } 672 | 673 | /// 674 | /// Fills this with vertices forming a 2D circle. 675 | /// 676 | /// The to fill with vertices. 677 | /// Radius of the circle. Value should be greater than or equal to 0.0f. 678 | /// The number of segments making up the circle. Value should be greater than or equal to 3. 679 | /// The starting angle of the circle. Usually 0. 680 | /// The angular size of the circle. 2 pi is a full circle. Pi is a half circle. 681 | public static void CreateTorusKnot(this Mesh mesh, float radius, float tube, int radialSegments, 682 | int tubularSegments, int p, int q, float heightScale) 683 | { 684 | mesh.name = "TorusKnot"; 685 | mesh.Clear(); 686 | 687 | List uvs = new List(); 688 | List vertices = new List(); 689 | ////List normals = new List(); 690 | List triangles = new List(); 691 | 692 | int[][] grid = new int[radialSegments][]; 693 | 694 | var tang = new Vector3(); 695 | var n = new Vector3(); 696 | var bitan = new Vector3(); 697 | 698 | for (var i = 0; i < radialSegments; ++i) 699 | { 700 | grid[i] = new int[tubularSegments]; 701 | var u = i/(float) radialSegments*2.0f*p*Mathf.PI; 702 | var p1 = GetPos(u, q, p, radius, heightScale); 703 | var p2 = GetPos(u + 0.01f, q, p, radius, heightScale); 704 | //tang.subVectors( p2, p1 ); 705 | tang = p2 - p1; 706 | //n.addVectors( p2, p1 ); 707 | n = p2 + p1; 708 | 709 | //bitan.crossVectors( tang, n ); 710 | bitan = Vector3.Cross(tang, n); 711 | //n.crossVectors( bitan, tang ); 712 | n = Vector3.Cross(bitan, tang); 713 | bitan.Normalize(); 714 | n.Normalize(); 715 | 716 | for (var j = 0; j < tubularSegments; ++j) 717 | { 718 | var v = j/(float) tubularSegments*2.0f*Mathf.PI; 719 | var cx = -tube*Mathf.Cos(v); // TODO: Hack: Negating it so it faces outside. 720 | var cy = tube*Mathf.Sin(v); 721 | 722 | var pos = new Vector3(); 723 | pos.x = p1.x + cx*n.x + cy*bitan.x; 724 | pos.y = p1.y + cx*n.y + cy*bitan.y; 725 | pos.z = p1.z + cx*n.z + cy*bitan.z; 726 | 727 | vertices.Add(pos); 728 | uvs.Add(new Vector2(i/(float) radialSegments, j/(float) tubularSegments)); 729 | 730 | grid[i][j] = vertices.Count - 1; 731 | } 732 | 733 | } 734 | 735 | for (var i = 0; i < radialSegments; ++i) 736 | { 737 | for (var j = 0; j < tubularSegments; ++j) 738 | { 739 | var ip = (i + 1)%radialSegments; 740 | var jp = (j + 1)%tubularSegments; 741 | 742 | var a = grid[i][j]; 743 | var b = grid[ip][j]; 744 | var c = grid[ip][jp]; 745 | var d = grid[i][jp]; 746 | 747 | ////var uva = new Vector2( i / (float)radialSegments, j / (float)tubularSegments ); 748 | ////var uvb = new Vector2( ( i + 1 ) / (float)radialSegments, j / (float)tubularSegments ); 749 | ////var uvc = new Vector2( ( i + 1 ) / (float)radialSegments, ( j + 1 ) / (float)tubularSegments ); 750 | ////var uvd = new Vector2( i / (float)radialSegments, ( j + 1 ) / (float)tubularSegments ); 751 | 752 | triangles.Add(a); 753 | triangles.Add(b); 754 | triangles.Add(d); 755 | 756 | triangles.Add(b); 757 | triangles.Add(c); 758 | triangles.Add(d); 759 | 760 | ////this.faces.push( new THREE.Face3( a, b, d ) ); 761 | ////this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] ); 762 | 763 | ////this.faces.push( new THREE.Face3( b, c, d ) ); 764 | ////this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] ); 765 | } 766 | } 767 | 768 | mesh.vertices = vertices.ToArray(); 769 | //mesh.normals = normals.ToArray(); 770 | mesh.uv = uvs.ToArray(); 771 | mesh.triangles = triangles.ToArray(); 772 | } 773 | 774 | private static Vector3 GetPos(float u, float in_q, float in_p, float radius, float heightScale) 775 | { 776 | var cu = Mathf.Cos(u); 777 | var su = Mathf.Sin(u); 778 | var quOverP = in_q/in_p*u; 779 | var cs = Mathf.Cos(quOverP); 780 | 781 | var tx = radius*(2.0f + cs)*0.5f*cu; 782 | var ty = radius*(2.0f + cs)*su*0.5f; 783 | var tz = heightScale*radius*Mathf.Sin(quOverP)*0.5f; 784 | 785 | return new Vector3(tx, ty, tz); 786 | } 787 | 788 | /// 789 | /// Fills this with vertices forming a 2D plane. 790 | /// 791 | /// The to fill with vertices. 792 | /// Width of the plane. Value should be greater than or equal to 0.0f. 793 | /// Height of the plane. Value should be greater than or equal to 0.0f. 794 | /// The number of subdivisions along the width direction. 795 | /// The number of subdivisions along the height direction. 796 | public static void CreatePlane(this Mesh mesh, float width, float height, int widthSegments, int heightSegments) 797 | { 798 | mesh.name = "Plane"; 799 | mesh.Clear(); 800 | 801 | List uvs = new List(); 802 | List vertices = new List(); 803 | List triangles = new List(); 804 | 805 | var width_half = width/2.0f; 806 | var height_half = height/2.0f; 807 | 808 | var gridX = widthSegments; 809 | var gridZ = heightSegments; 810 | 811 | var gridX1 = gridX + 1; 812 | var gridZ1 = gridZ + 1; 813 | 814 | var segment_width = width/gridX; 815 | var segment_height = height/gridZ; 816 | 817 | //var normal = new Vector3(0, 0, 1); 818 | 819 | for (int iz = 0; iz < gridZ1; iz ++) 820 | { 821 | for (int ix = 0; ix < gridX1; ix ++) 822 | { 823 | var x = ix*segment_width - width_half; 824 | var y = iz*segment_height - height_half; 825 | 826 | var uv = new Vector2((float) ix/gridX, 1.0f - (float) iz/gridZ); 827 | 828 | vertices.Add(new Vector3(x, -y, 0)); 829 | uvs.Add(uv); 830 | } 831 | } 832 | 833 | for (int iz = 0; iz < gridZ; iz++) 834 | { 835 | for (int ix = 0; ix < gridX; ix++) 836 | { 837 | var a = ix + gridX1*iz; 838 | var b = ix + gridX1*(iz + 1); 839 | var c = (ix + 1) + gridX1*(iz + 1); 840 | var d = (ix + 1) + gridX1*iz; 841 | 842 | //var uva = new Vector2( ix / gridX, 1 - iz / gridZ ); 843 | //var uvb = new Vector2( ix / gridX, 1 - ( iz + 1 ) / gridZ ); 844 | //var uvc = new Vector2( ( ix + 1 ) / gridX, 1 - ( iz + 1 ) / gridZ ); 845 | //var uvd = new Vector2( ( ix + 1 ) / gridX, 1 - iz / gridZ ); 846 | 847 | triangles.Add(a); 848 | triangles.Add(d); 849 | triangles.Add(b); 850 | 851 | triangles.Add(b); 852 | triangles.Add(d); 853 | triangles.Add(c); 854 | } 855 | } 856 | 857 | mesh.vertices = vertices.ToArray(); 858 | //mesh.normals = normals; 859 | mesh.uv = uvs.ToArray(); 860 | mesh.triangles = triangles.ToArray(); 861 | 862 | mesh.RecalculateNormals(); 863 | //mesh.RecalculateBounds(); 864 | } 865 | 866 | public static void CreateRing(this Mesh mesh, float innerRadius, float outerRadius, int thetaSegments, 867 | int phiSegments, float thetaStart, float thetaLength) 868 | { 869 | mesh.name = "Ring"; 870 | mesh.Clear(); 871 | 872 | List uvs = new List(); 873 | List vertices = new List(); 874 | List triangles = new List(); 875 | 876 | float radius = innerRadius; 877 | float radiusStep = ((outerRadius - innerRadius)/phiSegments); 878 | 879 | for (int i = 0; i <= phiSegments; i++) // concentric circles inside ring 880 | { 881 | for (int o = 0; o <= thetaSegments; o++) // number of segments per circle 882 | { 883 | var vertex = new Vector3(); 884 | var segment = thetaStart + o/(float) thetaSegments*thetaLength; 885 | 886 | vertex.x = radius*Mathf.Cos(segment); 887 | vertex.y = radius*Mathf.Sin(segment); 888 | 889 | vertices.Add(vertex); 890 | uvs.Add(new Vector2((vertex.x/outerRadius + 1)/2.0f, (vertex.y/outerRadius + 1)/2.0f)); 891 | } 892 | 893 | radius += radiusStep; 894 | } 895 | 896 | ////var n = new Vector3( 0, 0, 1 ); 897 | 898 | for (int i = 0; i < phiSegments; i++) // concentric circles inside ring 899 | { 900 | var thetaSegment = i*thetaSegments; 901 | 902 | for (int o = 0; o <= thetaSegments; o++) // number of segments per circle 903 | { 904 | var segment = o + thetaSegment; 905 | 906 | var v1 = segment + i; 907 | var v2 = segment + thetaSegments + i; 908 | var v3 = segment + thetaSegments + 1 + i; 909 | 910 | // prevent from connecting the start and end when not drawing a full ring 911 | if (o > 0) 912 | { 913 | triangles.Add(v1); 914 | triangles.Add(v3); 915 | triangles.Add(v2); 916 | } 917 | 918 | // prevent from connecting the start and end when not drawing a full ring 919 | if (o < thetaSegments) 920 | { 921 | v1 = segment + i; 922 | v2 = segment + thetaSegments + 1 + i; 923 | v3 = segment + 1 + i; 924 | 925 | triangles.Add(v1); 926 | triangles.Add(v3); 927 | triangles.Add(v2); 928 | } 929 | } 930 | } 931 | 932 | 933 | mesh.vertices = vertices.ToArray(); 934 | //mesh.normals = normals; 935 | mesh.uv = uvs.ToArray(); 936 | mesh.triangles = triangles.ToArray(); 937 | 938 | mesh.RecalculateNormals(); 939 | //mesh.RecalculateBounds(); 940 | } 941 | 942 | 943 | 944 | 945 | /// 946 | /// Adds Barycentric coordinates to each vertex in the uv2 field of the . 947 | /// 948 | /// The to add the barycentric coordinates to. 949 | public static void AddBarycentricCoordinates(this Mesh mesh) 950 | { 951 | int[] triangles = mesh.triangles; 952 | 953 | //Vector2[] bary = new Vector2[mesh.vertices.Length]; 954 | Vector4[] bary = new Vector4[mesh.vertices.Length]; 955 | 956 | // force them all to unused value 957 | for (int i = 0; i < bary.Length; i++) 958 | { 959 | bary[i] = Vector4.one; 960 | } 961 | 962 | Vector4 z = new Vector4(0, 0, 1, 0); 963 | Vector4 y = new Vector4(0, 1, 0, 0); 964 | Vector4 x = new Vector4(1, 0, 0, 0); 965 | 966 | bool zUsed = false; 967 | bool yUsed = false; 968 | bool xUsed = false; 969 | 970 | bool vert1Used = false; 971 | bool vert2Used = false; 972 | bool vert3Used = false; 973 | 974 | for (int i = 0; i < triangles.Length; i += 3) 975 | { 976 | Vector4 vert1 = bary[triangles[i]]; 977 | Vector4 vert2 = bary[triangles[i + 1]]; 978 | Vector4 vert3 = bary[triangles[i + 2]]; 979 | 980 | zUsed = vert1 == z || vert2 == z || vert3 == z; 981 | yUsed = vert1 == y || vert2 == y || vert3 == y; 982 | xUsed = vert1 == x || vert2 == x || vert3 == x; 983 | 984 | vert1Used = vert1 != z && vert1 != y && vert1 != x; 985 | vert2Used = vert2 != z && vert2 != y && vert2 != x; 986 | vert3Used = vert3 != z && vert3 != y && vert3 != x; 987 | 988 | if (!zUsed) 989 | { 990 | if (vert1Used) 991 | { 992 | vert1 = z; 993 | vert1Used = false; 994 | } 995 | else if (vert2Used) 996 | { 997 | vert2 = z; 998 | vert2Used = false; 999 | } 1000 | else if (vert3Used) 1001 | { 1002 | vert3 = z; 1003 | vert3Used = false; 1004 | } 1005 | } 1006 | 1007 | if (!yUsed) 1008 | { 1009 | if (vert1Used) 1010 | { 1011 | vert1 = y; 1012 | vert1Used = false; 1013 | } 1014 | else if (vert2Used) 1015 | { 1016 | vert2 = y; 1017 | vert2Used = false; 1018 | } 1019 | else if (vert3Used) 1020 | { 1021 | vert3 = y; 1022 | vert3Used = false; 1023 | } 1024 | } 1025 | 1026 | if (!xUsed) 1027 | { 1028 | if (vert1Used) 1029 | { 1030 | vert1 = x; 1031 | } 1032 | else if (vert2Used) 1033 | { 1034 | vert2 = x; 1035 | } 1036 | else if (vert3Used) 1037 | { 1038 | vert3 = x; 1039 | } 1040 | } 1041 | 1042 | if (vert1 == vert2 || vert1 == vert3 || vert2 == vert3) 1043 | { 1044 | Debug.Log("Error!"); 1045 | } 1046 | 1047 | bary[triangles[i]] = vert1; 1048 | bary[triangles[i + 1]] = vert2; 1049 | bary[triangles[i + 2]] = vert3; 1050 | 1051 | zUsed = false; 1052 | yUsed = false; 1053 | xUsed = false; 1054 | } 1055 | 1056 | //mesh.uv2 = bary; 1057 | mesh.tangents = bary; 1058 | } 1059 | } 1060 | } -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/MeshExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c07e20cf92b2dd94586d015454223b53 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/MouseCamera.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | using UnityEngine; 4 | 5 | public class MouseCamera : MonoBehaviour 6 | { 7 | public Transform target; 8 | public float distance = 10.0f; 9 | 10 | public float xSpeed = 250.0f; 11 | public float ySpeed = 120.0f; 12 | 13 | public float yMinLimit = -20f; 14 | public float yMaxLimit = 80f; 15 | 16 | private float x; 17 | private float y; 18 | 19 | private void Start() 20 | { 21 | var angles = transform.eulerAngles; 22 | x = angles.y; 23 | y = angles.x; 24 | 25 | // Make the rigid body not change rotation 26 | if (GetComponent()) 27 | GetComponent().freezeRotation = true; 28 | } 29 | 30 | public void UpdateAngles() 31 | { 32 | var angles = transform.eulerAngles; 33 | x = angles.y; 34 | y = angles.x; 35 | } 36 | 37 | private void LateUpdate() 38 | { 39 | if (target && Input.GetKey(KeyCode.Mouse1)) 40 | { 41 | x += Input.GetAxis("Mouse X")*xSpeed*0.02f; 42 | y -= Input.GetAxis("Mouse Y")*ySpeed*0.02f; 43 | 44 | y = ClampAngle(y, yMinLimit, yMaxLimit); 45 | 46 | var rotation = Quaternion.Euler(y, x, 0); 47 | var position = rotation*new Vector3(0.0f, 0.0f, -distance) + target.position; 48 | 49 | transform.rotation = rotation; 50 | transform.position = position; 51 | } 52 | } 53 | 54 | private static float ClampAngle(float angle, float min, float max) 55 | { 56 | if (angle < -360) 57 | angle += 360; 58 | if (angle > 360) 59 | angle -= 360; 60 | return Mathf.Clamp(angle, min, max); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/MouseCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5248d864ac095a749b0d8e1fc073a8fd 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/Popup.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | using UnityEngine; 4 | 5 | public class Popup 6 | { 7 | private static int popupListHash = "PopupList".GetHashCode(); 8 | 9 | public delegate void ListCallBack(); 10 | 11 | public static bool List(Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, 12 | GUIContent[] list, GUIStyle listStyle) 13 | { 14 | return List(position, ref showList, ref listEntry, buttonContent, list, "button", "box", listStyle, null); 15 | } 16 | 17 | public static bool List(Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, 18 | GUIContent[] list, GUIStyle listStyle, ListCallBack callBack) 19 | { 20 | return List(position, ref showList, ref listEntry, buttonContent, list, "button", "box", listStyle, callBack); 21 | } 22 | 23 | public static bool List(Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, 24 | GUIContent[] list, GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle, ListCallBack callBack) 25 | { 26 | int controlID = GUIUtility.GetControlID(popupListHash, FocusType.Passive); 27 | bool done = false; 28 | switch (Event.current.GetTypeForControl(controlID)) 29 | { 30 | case EventType.mouseDown: 31 | if (position.Contains(Event.current.mousePosition)) 32 | { 33 | GUIUtility.hotControl = controlID; 34 | showList = true; 35 | } 36 | break; 37 | case EventType.mouseUp: 38 | if (showList) 39 | { 40 | done = true; 41 | 42 | if (callBack != null) 43 | { 44 | callBack(); 45 | } 46 | } 47 | break; 48 | } 49 | 50 | GUI.Label(position, buttonContent, buttonStyle); 51 | if (showList) 52 | { 53 | string[] text = new string[list.Length]; 54 | for (int i = 0; i < list.Length; i++) 55 | { 56 | text[i] = list[i].text; 57 | } 58 | 59 | Rect listRect = new Rect(position.x, position.y, position.width, list.Length*20); 60 | GUI.Box(listRect, "", boxStyle); 61 | listEntry = GUI.SelectionGrid(listRect, listEntry, text, 1, listStyle); 62 | } 63 | if (done) 64 | { 65 | showList = false; 66 | } 67 | return done; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/Popup.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8d28c78ac2e6a0b4998a1385e1e86b9e 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/Primitive.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | using System; 4 | using UnityEngine; 5 | 6 | /// 7 | /// Defines static creation methods that procedurally create 3D primitive shapes like spheres, boxes, cones, planes, and cylinders. 8 | /// 9 | /// DEPRECATED! 10 | /// 11 | /// Please use the extension methods in MeshExtensions and GameObjectExtensions to programatically create primitives now. 12 | /// This is being left in as a reference for how things used to work, and to aid in backwards compatibility with old versions. 13 | /// 14 | public static class Primitive 15 | { 16 | #region Meshes 17 | 18 | /// 19 | /// Creates a filled with vertices forming a box. 20 | /// 21 | /// Width of the box, along the x-axis. 22 | /// Height of the box, along the y-axis. 23 | /// Depth of the box, along the z-axis. 24 | /// A filled with vertices forming a box. 25 | public static Mesh CreateBoxMesh(float width, float height, float depth) 26 | { 27 | Mesh mesh = new Mesh(); 28 | mesh.name = "BoxMesh"; 29 | 30 | // Because the box is centered at the origin, need to divide by two to find the + and - offsets 31 | width = width/2.0f; 32 | height = height/2.0f; 33 | depth = depth/2.0f; 34 | 35 | Vector3[] boxVertices = new Vector3[36]; 36 | Vector3[] boxNormals = new Vector3[36]; 37 | Vector2[] boxUVs = new Vector2[36]; 38 | 39 | Vector3 topLeftFront = new Vector3(-width, height, depth); 40 | Vector3 bottomLeftFront = new Vector3(-width, -height, depth); 41 | Vector3 topRightFront = new Vector3(width, height, depth); 42 | Vector3 bottomRightFront = new Vector3(width, -height, depth); 43 | Vector3 topLeftBack = new Vector3(-width, height, -depth); 44 | Vector3 topRightBack = new Vector3(width, height, -depth); 45 | Vector3 bottomLeftBack = new Vector3(-width, -height, -depth); 46 | Vector3 bottomRightBack = new Vector3(width, -height, -depth); 47 | 48 | Vector2 textureTopLeft = new Vector2(0.0f, 0.0f); 49 | Vector2 textureTopRight = new Vector2(1.0f, 0.0f); 50 | Vector2 textureBottomLeft = new Vector2(0.0f, 1.0f); 51 | Vector2 textureBottomRight = new Vector2(1.0f, 1.0f); 52 | 53 | Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f); 54 | Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f); 55 | Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f); 56 | Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f); 57 | Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f); 58 | Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f); 59 | 60 | // Front face. 61 | boxVertices[0] = topLeftFront; 62 | boxNormals[0] = frontNormal; 63 | boxUVs[0] = textureTopLeft; 64 | boxVertices[1] = bottomLeftFront; 65 | boxNormals[1] = frontNormal; 66 | boxUVs[1] = textureBottomLeft; 67 | boxVertices[2] = topRightFront; 68 | boxNormals[2] = frontNormal; 69 | boxUVs[2] = textureTopRight; 70 | boxVertices[3] = bottomLeftFront; 71 | boxNormals[3] = frontNormal; 72 | boxUVs[3] = textureBottomLeft; 73 | boxVertices[4] = bottomRightFront; 74 | boxNormals[4] = frontNormal; 75 | boxUVs[4] = textureBottomRight; 76 | boxVertices[5] = topRightFront; 77 | boxNormals[5] = frontNormal; 78 | boxUVs[5] = textureTopRight; 79 | 80 | // Back face. 81 | boxVertices[6] = topLeftBack; 82 | boxNormals[6] = backNormal; 83 | boxUVs[6] = textureTopRight; 84 | boxVertices[7] = topRightBack; 85 | boxNormals[7] = backNormal; 86 | boxUVs[7] = textureTopLeft; 87 | boxVertices[8] = bottomLeftBack; 88 | boxNormals[8] = backNormal; 89 | boxUVs[8] = textureBottomRight; 90 | boxVertices[9] = bottomLeftBack; 91 | boxNormals[9] = backNormal; 92 | boxUVs[9] = textureBottomRight; 93 | boxVertices[10] = topRightBack; 94 | boxNormals[10] = backNormal; 95 | boxUVs[10] = textureTopLeft; 96 | boxVertices[11] = bottomRightBack; 97 | boxNormals[11] = backNormal; 98 | boxUVs[11] = textureBottomLeft; 99 | 100 | // Top face. 101 | boxVertices[12] = topLeftFront; 102 | boxNormals[12] = topNormal; 103 | boxUVs[12] = textureBottomLeft; 104 | boxVertices[13] = topRightBack; 105 | boxNormals[13] = topNormal; 106 | boxUVs[13] = textureTopRight; 107 | boxVertices[14] = topLeftBack; 108 | boxNormals[14] = topNormal; 109 | boxUVs[14] = textureTopLeft; 110 | boxVertices[15] = topLeftFront; 111 | boxNormals[15] = topNormal; 112 | boxUVs[15] = textureBottomLeft; 113 | boxVertices[16] = topRightFront; 114 | boxNormals[16] = topNormal; 115 | boxUVs[16] = textureBottomRight; 116 | boxVertices[17] = topRightBack; 117 | boxNormals[17] = topNormal; 118 | boxUVs[17] = textureTopRight; 119 | 120 | // Bottom face. 121 | boxVertices[18] = bottomLeftFront; 122 | boxNormals[18] = bottomNormal; 123 | boxUVs[18] = textureTopLeft; 124 | boxVertices[19] = bottomLeftBack; 125 | boxNormals[19] = bottomNormal; 126 | boxUVs[19] = textureBottomLeft; 127 | boxVertices[20] = bottomRightBack; 128 | boxNormals[20] = bottomNormal; 129 | boxUVs[20] = textureBottomRight; 130 | boxVertices[21] = bottomLeftFront; 131 | boxNormals[21] = bottomNormal; 132 | boxUVs[21] = textureTopLeft; 133 | boxVertices[22] = bottomRightBack; 134 | boxNormals[22] = bottomNormal; 135 | boxUVs[22] = textureBottomRight; 136 | boxVertices[23] = bottomRightFront; 137 | boxNormals[23] = bottomNormal; 138 | boxUVs[23] = textureTopRight; 139 | 140 | // Left face. 141 | boxVertices[24] = topLeftFront; 142 | boxNormals[24] = leftNormal; 143 | boxUVs[24] = textureTopRight; 144 | boxVertices[25] = bottomLeftBack; 145 | boxNormals[25] = leftNormal; 146 | boxUVs[25] = textureBottomLeft; 147 | boxVertices[26] = bottomLeftFront; 148 | boxNormals[26] = leftNormal; 149 | boxUVs[26] = textureBottomRight; 150 | boxVertices[27] = topLeftBack; 151 | boxNormals[27] = leftNormal; 152 | boxUVs[27] = textureTopLeft; 153 | boxVertices[28] = bottomLeftBack; 154 | boxNormals[28] = leftNormal; 155 | boxUVs[28] = textureBottomLeft; 156 | boxVertices[29] = topLeftFront; 157 | boxNormals[29] = leftNormal; 158 | boxUVs[29] = textureTopRight; 159 | 160 | // Right face. 161 | boxVertices[30] = topRightFront; 162 | boxNormals[30] = rightNormal; 163 | boxUVs[30] = textureTopLeft; 164 | boxVertices[31] = bottomRightFront; 165 | boxNormals[31] = rightNormal; 166 | boxUVs[31] = textureBottomLeft; 167 | boxVertices[32] = bottomRightBack; 168 | boxNormals[32] = rightNormal; 169 | boxUVs[32] = textureBottomRight; 170 | boxVertices[33] = topRightBack; 171 | boxNormals[33] = rightNormal; 172 | boxUVs[33] = textureTopRight; 173 | boxVertices[34] = topRightFront; 174 | boxNormals[34] = rightNormal; 175 | boxUVs[34] = textureTopLeft; 176 | boxVertices[35] = bottomRightBack; 177 | boxNormals[35] = rightNormal; 178 | boxUVs[35] = textureBottomRight; 179 | 180 | mesh.vertices = boxVertices; 181 | mesh.normals = boxNormals; 182 | mesh.uv = boxUVs; 183 | //mesh.triangles = CreateIndexBuffer(vertexCount, indexCount, slices); 184 | mesh.triangles = new int[] 185 | { 186 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 187 | 29, 30, 31, 32, 33, 34, 35 188 | }; 189 | 190 | return mesh; 191 | } 192 | 193 | /// 194 | /// Creates a filled with vertices forming a plane. 195 | /// 196 | /// The width of the plane, along the X axis. 197 | /// The depth of the plane, along the Z axis. 198 | /// The number of divisions along the X axis. 199 | /// The number of divisions along the Z axis. 200 | /// A filled with vertices forming a plane. 201 | public static Mesh CreatePlaneMesh(float width, float depth, int widthDivisions, int depthDivisions) 202 | { 203 | if (widthDivisions < 1 || depthDivisions < 1) 204 | return null; 205 | 206 | Mesh mesh = new Mesh(); 207 | mesh.name = "PlaneMesh"; 208 | 209 | float widthStep = width/widthDivisions; 210 | float depthStep = depth/depthDivisions; 211 | float halfWidth = width/2.0f; 212 | float halfDepth = depth/2.0f; 213 | 214 | int vertexCount = (widthDivisions + 1)*(depthDivisions + 1); 215 | 216 | Vector3[] planeVertices = new Vector3[vertexCount]; 217 | Vector3[] planeNormals = new Vector3[vertexCount]; 218 | Vector2[] planeUVs = new Vector2[vertexCount]; 219 | 220 | int currentVertex = 0; 221 | 222 | for (float currentX = -halfWidth; currentX <= halfWidth; currentX += widthStep) 223 | { 224 | for (float currentZ = -halfDepth; currentZ <= halfDepth; currentZ += depthStep) 225 | { 226 | planeVertices[currentVertex] = new Vector3(currentX, 0, currentZ); 227 | planeNormals[currentVertex] = Vector3.up; 228 | planeUVs[currentVertex] = new Vector2(1 - (currentX + halfWidth)/width, 229 | 1 - (currentZ + halfDepth)/depth); 230 | 231 | currentVertex++; 232 | } 233 | } 234 | 235 | int[] indices = new int[widthDivisions*depthDivisions*2*3]; 236 | int currentIndex = 0; 237 | 238 | int index = 0; 239 | for (int row = 0; row < depthDivisions; row++) 240 | { 241 | for (int column = 0; column < widthDivisions; column++) 242 | { 243 | //index, index + 1, index + widthDivisions 244 | //index + 1, index + widthDivisions + 1, index + widthDivisions; 245 | 246 | indices[currentIndex++] = index; 247 | indices[currentIndex++] = index + 1; 248 | indices[currentIndex++] = index + widthDivisions + 1; 249 | 250 | indices[currentIndex++] = index + 1; 251 | indices[currentIndex++] = index + widthDivisions + 2; 252 | indices[currentIndex++] = index + widthDivisions + 1; 253 | 254 | index++; 255 | } 256 | 257 | index++; 258 | } 259 | 260 | mesh.vertices = planeVertices; 261 | mesh.normals = planeNormals; 262 | mesh.uv = planeUVs; 263 | mesh.triangles = indices; 264 | 265 | return mesh; 266 | } 267 | 268 | /// 269 | /// Creates a filled with vertices forming a sphere. 270 | /// 271 | /// 272 | /// The values are as follows: 273 | /// Vertex Count = slices * (stacks - 1) + 2 274 | /// Triangle Count = slices * (stacks - 1) * 2 275 | /// 276 | /// Default sphere mesh in Unity has a radius of 0.5 with 20 slices and 20 stacks. 277 | /// 278 | /// Radius of the sphere. This value should be greater than or equal to 0.0f. 279 | /// Number of slices around the Y axis. 280 | /// Number of stacks along the Y axis. Should be 2 or greater. (stack of 1 is just a cylinder) 281 | public static Mesh CreateSphereMesh(float radius, int slices, int stacks) 282 | { 283 | Mesh mesh = new Mesh(); 284 | mesh.name = "SphereMesh"; 285 | 286 | float sliceStep = (float) Math.PI*2.0f/slices; 287 | float stackStep = (float) Math.PI/stacks; 288 | int vertexCount = slices*(stacks - 1) + 2; 289 | int triangleCount = slices*(stacks - 1)*2; 290 | int indexCount = triangleCount*3; 291 | 292 | Vector3[] sphereVertices = new Vector3[vertexCount]; 293 | Vector3[] sphereNormals = new Vector3[vertexCount]; 294 | Vector2[] sphereUVs = new Vector2[vertexCount]; 295 | 296 | int currentVertex = 0; 297 | sphereVertices[currentVertex] = new Vector3(0, -radius, 0); 298 | sphereNormals[currentVertex] = Vector3.down; 299 | currentVertex++; 300 | float stackAngle = (float) Math.PI - stackStep; 301 | for (int i = 0; i < stacks - 1; i++) 302 | { 303 | float sliceAngle = 0; 304 | for (int j = 0; j < slices; j++) 305 | { 306 | //NOTE: y and z were switched from normal spherical coordinates because the sphere is "oriented" along the Y axis as opposed to the Z axis 307 | float x = (float) (radius*Math.Sin(stackAngle)*Math.Cos(sliceAngle)); 308 | float y = (float) (radius*Math.Cos(stackAngle)); 309 | float z = (float) (radius*Math.Sin(stackAngle)*Math.Sin(sliceAngle)); 310 | 311 | Vector3 position = new Vector3(x, y, z); 312 | sphereVertices[currentVertex] = position; 313 | sphereNormals[currentVertex] = Vector3.Normalize(position); 314 | sphereUVs[currentVertex] = 315 | new Vector2((float) (Math.Sin(sphereNormals[currentVertex].x)/Math.PI + 0.5f), 316 | (float) (Math.Sin(sphereNormals[currentVertex].y)/Math.PI + 0.5f)); 317 | 318 | currentVertex++; 319 | 320 | sliceAngle += sliceStep; 321 | } 322 | stackAngle -= stackStep; 323 | } 324 | sphereVertices[currentVertex] = new Vector3(0, radius, 0); 325 | sphereNormals[currentVertex] = Vector3.up; 326 | 327 | mesh.vertices = sphereVertices; 328 | mesh.normals = sphereNormals; 329 | mesh.uv = sphereUVs; 330 | mesh.triangles = CreateIndexBuffer(vertexCount, indexCount, slices); 331 | 332 | return mesh; 333 | } 334 | 335 | /// 336 | /// Creates a filled with vertices forming a cylinder. 337 | /// 338 | /// 339 | /// The values are as follows: 340 | /// Vertex Count = slices * (stacks + 1) + 2 341 | /// Primitive Count = slices * (stacks + 1) * 2 342 | /// 343 | /// Radius at the negative Y end. Value should be greater than or equal to 0.0f. 344 | /// Radius at the positive Y end. Value should be greater than or equal to 0.0f. 345 | /// Length of the cylinder along the Y-axis. 346 | /// Number of slices about the Y axis. 347 | /// Number of stacks along the Y axis. 348 | public static Mesh CreateCylinderMesh(float bottomRadius, float topRadius, float length, int slices, int stacks) 349 | { 350 | // if both the top and bottom have a radius of zero, just return null, because invalid 351 | if (bottomRadius <= 0 && topRadius <= 0) 352 | { 353 | return null; 354 | } 355 | 356 | Mesh mesh = new Mesh(); 357 | mesh.name = "CylinderMesh"; 358 | float sliceStep = (float) Math.PI*2.0f/slices; 359 | float heightStep = length/stacks; 360 | float radiusStep = (topRadius - bottomRadius)/stacks; 361 | float currentHeight = -length/2; 362 | int vertexCount = (stacks + 1)*slices + 2; //cone = stacks * slices + 1 363 | int triangleCount = (stacks + 1)*slices*2; //cone = stacks * slices * 2 + slices 364 | int indexCount = triangleCount*3; 365 | float currentRadius = bottomRadius; 366 | 367 | Vector3[] cylinderVertices = new Vector3[vertexCount]; 368 | Vector3[] cylinderNormals = new Vector3[vertexCount]; 369 | Vector2[] cylinderUVs = new Vector2[vertexCount]; 370 | 371 | // Start at the bottom of the cylinder 372 | int currentVertex = 0; 373 | cylinderVertices[currentVertex] = new Vector3(0, currentHeight, 0); 374 | cylinderNormals[currentVertex] = Vector3.down; 375 | currentVertex++; 376 | for (int i = 0; i <= stacks; i++) 377 | { 378 | float sliceAngle = 0; 379 | for (int j = 0; j < slices; j++) 380 | { 381 | float x = currentRadius*(float) Math.Cos(sliceAngle); 382 | float y = currentHeight; 383 | float z = currentRadius*(float) Math.Sin(sliceAngle); 384 | 385 | Vector3 position = new Vector3(x, y, z); 386 | cylinderVertices[currentVertex] = position; 387 | cylinderNormals[currentVertex] = Vector3.Normalize(position); 388 | cylinderUVs[currentVertex] = 389 | new Vector2((float) (Math.Sin(cylinderNormals[currentVertex].x)/Math.PI + 0.5f), 390 | (float) (Math.Sin(cylinderNormals[currentVertex].y)/Math.PI + 0.5f)); 391 | 392 | currentVertex++; 393 | 394 | sliceAngle += sliceStep; 395 | } 396 | currentHeight += heightStep; 397 | currentRadius += radiusStep; 398 | } 399 | cylinderVertices[currentVertex] = new Vector3(0, length/2, 0); 400 | cylinderNormals[currentVertex] = Vector3.up; 401 | currentVertex++; 402 | 403 | mesh.vertices = cylinderVertices; 404 | mesh.normals = cylinderNormals; 405 | mesh.uv = cylinderUVs; 406 | mesh.triangles = CreateIndexBuffer(vertexCount, indexCount, slices); 407 | 408 | return mesh; 409 | } 410 | 411 | /// 412 | /// Creates an index buffer for spherical shapes like Spheres, Cylinders, and Cones. 413 | /// 414 | /// The total number of vertices making up the shape. 415 | /// The total number of indices making up the shape. 416 | /// The number of slices about the Y axis. 417 | /// The index buffer containing the index data for the shape. 418 | private static int[] CreateIndexBuffer(int vertexCount, int indexCount, int slices) 419 | { 420 | int[] indices = new int[indexCount]; 421 | int currentIndex = 0; 422 | 423 | // Bottom circle/cone of shape 424 | for (int i = 1; i <= slices; i++) 425 | { 426 | indices[currentIndex++] = i; 427 | indices[currentIndex++] = 0; 428 | if (i - 1 == 0) 429 | indices[currentIndex++] = i + slices - 1; 430 | else 431 | indices[currentIndex++] = i - 1; 432 | } 433 | 434 | // Middle sides of shape 435 | for (int i = 1; i < vertexCount - slices - 1; i++) 436 | { 437 | indices[currentIndex++] = i + slices; 438 | indices[currentIndex++] = i; 439 | if ((i - 1)%slices == 0) 440 | indices[currentIndex++] = i + slices + slices - 1; 441 | else 442 | indices[currentIndex++] = i + slices - 1; 443 | 444 | indices[currentIndex++] = i; 445 | if ((i - 1)%slices == 0) 446 | indices[currentIndex++] = i + slices - 1; 447 | else 448 | indices[currentIndex++] = i - 1; 449 | if ((i - 1)%slices == 0) 450 | indices[currentIndex++] = i + slices + slices - 1; 451 | else 452 | indices[currentIndex++] = i + slices - 1; 453 | } 454 | 455 | // Top circle/cone of shape 456 | for (int i = vertexCount - slices - 1; i < vertexCount - 1; i++) 457 | { 458 | indices[currentIndex++] = i; 459 | if ((i - 1)%slices == 0) 460 | indices[currentIndex++] = i + slices - 1; 461 | else 462 | indices[currentIndex++] = i - 1; 463 | indices[currentIndex++] = vertexCount - 1; 464 | } 465 | 466 | return indices; 467 | } 468 | 469 | #endregion 470 | 471 | #region GameObjects 472 | 473 | /// 474 | /// Creates a that has a box , a , and 475 | /// a . 476 | /// 477 | /// Width of the box, along the x-axis. 478 | /// Height of the box, along the y-axis. 479 | /// Depth of the box, along the z-axis. 480 | /// A new containing a cylinder , , and 481 | public static GameObject CreateBoxGameObject(float width, float height, float depth) 482 | { 483 | Mesh mesh = CreateBoxMesh(width, height, depth); 484 | 485 | GameObject gameObject = new GameObject("Box"); 486 | MeshFilter meshFilter = gameObject.AddComponent(); 487 | meshFilter.mesh = mesh; 488 | 489 | BoxCollider collider = gameObject.AddComponent(); 490 | collider.size = new Vector3(width, height, depth); 491 | gameObject.AddComponent(); 492 | 493 | Shader shader = Shader.Find("Diffuse"); 494 | gameObject.GetComponent().material = new Material(shader); 495 | 496 | return gameObject; 497 | } 498 | 499 | /// 500 | /// Creates a that has a sphere , a , and 501 | /// a just like the built-in sphere object. The difference is you can change the 502 | /// quality of the mesh based on the given parameters. 503 | /// 504 | /// The radius of the sphere mesh. (Built-in is 0.5) 505 | /// The number of slices (divisions around the Y axis) making up the sphere mesh. (Built-in is 20) 506 | /// The number of stacks (division along the Y axis) making up the sphere mesh. (Built-in is 20) 507 | /// A new containing a sphere , , and 508 | public static GameObject CreateSphereGameObject(float radius, int slices, int stacks) 509 | { 510 | Mesh mesh = CreateSphereMesh(radius, slices, stacks); 511 | 512 | GameObject gameObject = new GameObject("Sphere"); 513 | MeshFilter meshFilter = gameObject.AddComponent(); 514 | meshFilter.mesh = mesh; 515 | 516 | SphereCollider collider = gameObject.AddComponent(); 517 | collider.radius = radius; 518 | gameObject.AddComponent(); 519 | 520 | Shader shader = Shader.Find("Diffuse"); 521 | gameObject.GetComponent().material = new Material(shader); 522 | 523 | return gameObject; 524 | } 525 | 526 | /// 527 | /// Creates a that has a cylinder , a , and 528 | /// a . 529 | /// 530 | /// Radius at the negative Y end. Value should be greater than or equal to 0.0f. 531 | /// Radius at the positive Y end. Value should be greater than or equal to 0.0f. 532 | /// Length of the cylinder along the Y-axis. 533 | /// Number of slices about the Y axis. 534 | /// Number of stacks along the Y axis. 535 | /// A new containing a cylinder , , and 536 | public static GameObject CreateCylinderGameObject(float bottomRadius, float topRadius, float length, int slices, 537 | int stacks) 538 | { 539 | Mesh mesh = CreateCylinderMesh(bottomRadius, topRadius, length, slices, stacks); 540 | 541 | GameObject gameObject = new GameObject("Cylinder"); 542 | MeshFilter meshFilter = gameObject.AddComponent(); 543 | meshFilter.mesh = mesh; 544 | 545 | MeshCollider collider = gameObject.AddComponent(); 546 | collider.sharedMesh = mesh; 547 | collider.convex = true; 548 | gameObject.AddComponent(); 549 | 550 | Shader shader = Shader.Find("Diffuse"); 551 | gameObject.GetComponent().material = new Material(shader); 552 | 553 | return gameObject; 554 | } 555 | 556 | /// 557 | /// Creates a that has a plane , a , and 558 | /// a . 559 | /// 560 | /// The width of the plane, along the X axis. 561 | /// The depth of the plane, along the Z axis. 562 | /// The number of divisions along the X axis. 563 | /// The number of divisions along the Z axis. 564 | /// A new containing a plane , , and 565 | public static GameObject CreatePlaneGameObject(float width, float depth, int widthDivisions, int depthDivisions) 566 | { 567 | Mesh mesh = CreatePlaneMesh(width, depth, widthDivisions, depthDivisions); 568 | 569 | GameObject gameObject = new GameObject("Plane"); 570 | MeshFilter meshFilter = gameObject.AddComponent(); 571 | meshFilter.mesh = mesh; 572 | 573 | MeshCollider collider = gameObject.AddComponent(); 574 | collider.sharedMesh = mesh; 575 | collider.convex = false; 576 | gameObject.AddComponent(); 577 | 578 | Shader shader = Shader.Find("Diffuse"); 579 | gameObject.GetComponent().material = new Material(shader); 580 | 581 | return gameObject; 582 | } 583 | 584 | #endregion 585 | } 586 | } -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/Primitive.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da0f69bfe6385594aa9b74d709213ed8 3 | labels: 4 | - procedural 5 | - primitive 6 | - C# 7 | - mesh 8 | - collider 9 | - cone 10 | - cylinder 11 | - box 12 | - plane 13 | - sphere 14 | MonoImporter: 15 | serializedVersion: 2 16 | defaultReferences: [] 17 | executionOrder: 0 18 | icon: {instanceID: 0} 19 | userData: 20 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/PrimitiveType.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | /// 4 | /// The type of a . 5 | /// 6 | public enum PrimitiveType 7 | { 8 | // 3D 9 | Box, 10 | Cylinder, 11 | Lathe, 12 | Sphere, 13 | Torus, 14 | TorusKnot, 15 | 16 | // 2D 17 | Circle, 18 | Plane, 19 | Ring 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/PrimitiveType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8eac9400ca97d0647b8d4905b5a8497c 3 | labels: 4 | - procedural 5 | - primitive 6 | - C# 7 | - mesh 8 | - collider 9 | - cone 10 | - cylinder 11 | - box 12 | - plane 13 | - sphere 14 | MonoImporter: 15 | serializedVersion: 2 16 | defaultReferences: [] 17 | executionOrder: 0 18 | icon: {instanceID: 0} 19 | userData: 20 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/ProceduralPrimitivesMenu.cs: -------------------------------------------------------------------------------- 1 | namespace ProceduralPrimitives 2 | { 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | /// 7 | /// DEPRECATED! 8 | /// 9 | /// Please use the extension methods in MeshExtensions and GameObjectExtensions to programatically create primitives now. 10 | /// This is being left in as a reference for how things used to work, and to aid in backwards compatibility with old versions. 11 | /// 12 | public class ProceduralPrimitivesMenu : EditorWindow 13 | { 14 | PrimitiveType primitiveType = PrimitiveType.Box; 15 | 16 | float width = 1; 17 | float height = 1; 18 | float depth = 1; 19 | 20 | int widthDivisions = 10; 21 | int depthDivisions = 10; 22 | 23 | float radius = 0.5f; 24 | int stacks = 20; 25 | int slices = 20; 26 | 27 | float topRadius = 0.5f; 28 | float bottomRadius = 0.5f; 29 | float length = 1; 30 | 31 | [MenuItem("GameObject/Create Other/Procedural Primitive")] 32 | public static void ShowWindow() 33 | { 34 | GetWindow(); 35 | } 36 | 37 | void OnGUI() 38 | { 39 | GUILayout.Label("Create Procedural Primitive", EditorStyles.boldLabel); 40 | 41 | primitiveType = (PrimitiveType)EditorGUILayout.EnumPopup("Select shape: ", primitiveType); 42 | 43 | switch (primitiveType) 44 | { 45 | case PrimitiveType.Box: 46 | width = EditorGUILayout.Slider("Width: ", width, 0.01f, 1000); 47 | height = EditorGUILayout.Slider("Height: ", height, 0.01f, 1000); 48 | depth = EditorGUILayout.Slider("Depth: ", depth, 0.01f, 1000); 49 | break; 50 | case PrimitiveType.Cylinder: 51 | bottomRadius = EditorGUILayout.Slider("Bottom Radius: ", bottomRadius, 0.0f, 1000); 52 | topRadius = EditorGUILayout.Slider("Top Radius: ", topRadius, 0.0f, 1000); 53 | length = EditorGUILayout.Slider("Length: ", length, 0.01f, 1000); 54 | stacks = EditorGUILayout.IntSlider("Stacks: ", stacks, 1, 256); 55 | slices = EditorGUILayout.IntSlider("Slices: ", slices, 1, 256); 56 | break; 57 | case PrimitiveType.Plane: 58 | width = EditorGUILayout.Slider("Width: ", width, 0.01f, 1000); 59 | depth = EditorGUILayout.Slider("Depth: ", depth, 0.01f, 1000); 60 | widthDivisions = EditorGUILayout.IntSlider("Width Divisions: ", widthDivisions, 1, 254); 61 | depthDivisions = EditorGUILayout.IntSlider("Depth Divisions: ", depthDivisions, 1, 254); 62 | break; 63 | case PrimitiveType.Sphere: 64 | radius = EditorGUILayout.Slider("Radius: ", radius, 0.01f, 1000); 65 | stacks = EditorGUILayout.IntSlider("Stacks: ", stacks, 1, 256); 66 | slices = EditorGUILayout.IntSlider("Slices: ", slices, 1, 256); 67 | break; 68 | } 69 | 70 | if (GUILayout.Button("Create")) 71 | { 72 | switch (primitiveType) 73 | { 74 | case PrimitiveType.Box: 75 | Primitive.CreateBoxGameObject(width, height, depth); 76 | break; 77 | case PrimitiveType.Cylinder: 78 | Primitive.CreateCylinderGameObject(bottomRadius, topRadius, length, slices, stacks); 79 | break; 80 | case PrimitiveType.Plane: 81 | Primitive.CreatePlaneGameObject(width, depth, widthDivisions, depthDivisions); 82 | break; 83 | case PrimitiveType.Sphere: 84 | Primitive.CreateSphereGameObject(radius, slices, stacks); 85 | break; 86 | } 87 | } 88 | 89 | bool isNull = Camera.main.targetTexture == null; 90 | 91 | if (isNull) 92 | { 93 | RenderTexture rt = new RenderTexture(100, 100, 0); 94 | Camera.main.targetTexture = rt; 95 | } 96 | 97 | RenderTexture currentRT = RenderTexture.active; 98 | RenderTexture.active = Camera.main.targetTexture; 99 | Camera.main.Render(); 100 | 101 | if (Camera.main.targetTexture == null) 102 | { 103 | Debug.Log("Camera is null"); 104 | return; 105 | } 106 | 107 | Texture2D image = new Texture2D(Camera.main.targetTexture.width, Camera.main.targetTexture.height); 108 | image.ReadPixels(new Rect(0, 0, Camera.main.targetTexture.width, Camera.main.targetTexture.height), 0, 0); 109 | image.Apply(); 110 | 111 | RenderTexture.active = currentRT; 112 | EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(100, 100), image); 113 | 114 | if (isNull) 115 | { 116 | Camera.main.targetTexture = null; 117 | } 118 | } 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Scripts/ProceduralPrimitivesMenu.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af72cf736807f2947a6ebb0b16a38a42 3 | labels: 4 | - procedural 5 | - primitive 6 | - C# 7 | - mesh 8 | - collider 9 | - cone 10 | - cylinder 11 | - box 12 | - plane 13 | - sphere 14 | MonoImporter: 15 | serializedVersion: 2 16 | defaultReferences: [] 17 | executionOrder: 0 18 | icon: {instanceID: 0} 19 | userData: 20 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5141c84d7c60d4948b2bea3012acadb8 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Textures/DebugTexture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlitchEnzo/UnityProceduralPrimitives/f78ae73f4da9ad92ebcbf47991d62f877c0b3e8c/Assets/Procedural Primitives/Textures/DebugTexture.jpg -------------------------------------------------------------------------------- /Assets/Procedural Primitives/Textures/DebugTexture.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fb86416915e887d4a81ae3497b50eeb3 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 0 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 5 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Procedural Primitives/readme.txt: -------------------------------------------------------------------------------- 1 | Procedural Primitives 2 | --------------------- 3 | 4 | Create spheres, boxes, planes, cylinders, and cones all in script at the size and quality you desire! You don't need to 5 | learn to use a complicated 3D modelling application. You're no longer confined by the sizes and mesh quality that Unity 6 | provides. You no longer need messy model files cluttering your Assets folder. 7 | 8 | Do you want to create a primitive shape, but you want it to be a higher or lower resolution than the Unity mesh? Do you 9 | want to be able to create cone primitives? Do you want to change the quality of your meshes based upon what platform 10 | you're running on? If so, then Procedural Primitives is what you're looking for! You can call simple methods from script 11 | that generate primitive shapes based upon various quality and sizing parameters. Generate just the meshes, or generate 12 | an entire GameObject with all of the necessary components automatically. Each mesh is automatially texture mapped and 13 | normal mapped for your convenience! 14 | 15 | Now with a custom creation window to allow creation of shapes in the Editor! 16 | 17 | Usage 18 | ----- 19 | 20 | All of the methods are in the Primitive.cs file. They are public static methods that can be called from anywhere. 21 | There are two types of methods: mesh creation methods and object creation methods. The mesh creation methods just create 22 | Mesh objects that can be used wherever a Mesh object is expected inside of Unity. The object creation methods create 23 | GameObject objects that contain a new Mesh of the shape as well as MeshFilter, MeshRenderer, and Collider components that 24 | correspond to the shape. 25 | 26 | The parameters of the shapes are as follows: 27 | 28 | Box: 29 | width = The width of the box, along the X axis. 30 | height = The height of the box, along the Y axis. 31 | depth = The depth of the box, along the Z axis. 32 | 33 | Plane: 34 | width = The width of the plane, along the X axis. 35 | depth = The depth of the plane, along the Z axis. 36 | widthDivisions = The number of divisions along the X axis. 37 | depthDivisions = The number of divisions along the Z axis. 38 | 39 | Sphere: 40 | radius = Radius of the sphere. This value should be greater than or equal to 0.0f. 41 | slices = Number of slices around the Y axis. 42 | stacks = Number of stacks along the Y axis. Should be 2 or greater. (stack of 1 is just a simple cylinder) 43 | 44 | Cylinder: 45 | bottomRadius = Radius at the negative Y end. Value should be greater than or equal to 0.0f. 46 | topRadius = Radius at the positive Y end. Value should be greater than or equal to 0.0f. 47 | length = Length of the cylinder along the Y-axis. 48 | slices = Number of slices about the Y axis. 49 | stacks = Number of stacks along the Y axis. 50 | 51 | Note: In order to make a Cone, you use the Cylinder creation methods and set either the topRadius or bottomRadius to zero (0.0f). 52 | 53 | Please refer to the comments in the code, as well as the example scene for more information. -------------------------------------------------------------------------------- /Assets/Procedural Primitives/readme.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb3b752ff2b3f4248b4995ada362b3b4 3 | labels: 4 | - procedural 5 | - primitive 6 | - C# 7 | - mesh 8 | - collider 9 | - cone 10 | - cylinder 11 | - box 12 | - plane 13 | - sphere 14 | TextScriptImporter: 15 | userData: 16 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Patrick McCarthy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 0 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_DisableAudio: 0 15 | -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | m_Gravity: {x: 0, y: -9.81000042, z: 0} 7 | m_DefaultMaterial: {fileID: 0} 8 | m_BounceThreshold: 2 9 | m_SleepThreshold: .00499999989 10 | m_DefaultContactOffset: .00999999978 11 | m_SolverIterationCount: 6 12 | m_RaycastsHitTriggers: 1 13 | m_EnableAdaptiveForce: 0 14 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 15 | -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: [] 8 | -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_WebSecurityEmulationEnabled: 0 10 | m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d 11 | m_DefaultBehaviorMode: 0 12 | m_SpritePackerMode: 2 13 | -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_LegacyDeferred: 11 | m_Mode: 1 12 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 13 | m_AlwaysIncludedShaders: 14 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 15 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 16 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 17 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 18 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 19 | - {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0} 20 | m_PreloadedShaders: [] 21 | m_LightmapStripping: 0 22 | m_LightmapKeepPlain: 1 23 | m_LightmapKeepDirCombined: 1 24 | m_LightmapKeepDirSeparate: 1 25 | m_LightmapKeepDynamic: 1 26 | m_FogStripping: 0 27 | m_FogKeepLinear: 1 28 | m_FogKeepExp: 1 29 | m_FogKeepExp2: 1 30 | -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!13 &1 4 | InputManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Axes: 8 | - serializedVersion: 3 9 | m_Name: Horizontal 10 | descriptiveName: 11 | descriptiveNegativeName: 12 | negativeButton: left 13 | positiveButton: right 14 | altNegativeButton: a 15 | altPositiveButton: d 16 | gravity: 3 17 | dead: .00100000005 18 | sensitivity: 3 19 | snap: 1 20 | invert: 0 21 | type: 0 22 | axis: 0 23 | joyNum: 0 24 | - serializedVersion: 3 25 | m_Name: Vertical 26 | descriptiveName: 27 | descriptiveNegativeName: 28 | negativeButton: down 29 | positiveButton: up 30 | altNegativeButton: s 31 | altPositiveButton: w 32 | gravity: 3 33 | dead: .00100000005 34 | sensitivity: 3 35 | snap: 1 36 | invert: 0 37 | type: 0 38 | axis: 0 39 | joyNum: 0 40 | - serializedVersion: 3 41 | m_Name: Fire1 42 | descriptiveName: 43 | descriptiveNegativeName: 44 | negativeButton: 45 | positiveButton: left ctrl 46 | altNegativeButton: 47 | altPositiveButton: mouse 0 48 | gravity: 1000 49 | dead: .00100000005 50 | sensitivity: 1000 51 | snap: 0 52 | invert: 0 53 | type: 0 54 | axis: 0 55 | joyNum: 0 56 | - serializedVersion: 3 57 | m_Name: Fire2 58 | descriptiveName: 59 | descriptiveNegativeName: 60 | negativeButton: 61 | positiveButton: left alt 62 | altNegativeButton: 63 | altPositiveButton: mouse 1 64 | gravity: 1000 65 | dead: .00100000005 66 | sensitivity: 1000 67 | snap: 0 68 | invert: 0 69 | type: 0 70 | axis: 0 71 | joyNum: 0 72 | - serializedVersion: 3 73 | m_Name: Fire3 74 | descriptiveName: 75 | descriptiveNegativeName: 76 | negativeButton: 77 | positiveButton: left cmd 78 | altNegativeButton: 79 | altPositiveButton: mouse 2 80 | gravity: 1000 81 | dead: .00100000005 82 | sensitivity: 1000 83 | snap: 0 84 | invert: 0 85 | type: 0 86 | axis: 0 87 | joyNum: 0 88 | - serializedVersion: 3 89 | m_Name: Jump 90 | descriptiveName: 91 | descriptiveNegativeName: 92 | negativeButton: 93 | positiveButton: space 94 | altNegativeButton: 95 | altPositiveButton: 96 | gravity: 1000 97 | dead: .00100000005 98 | sensitivity: 1000 99 | snap: 0 100 | invert: 0 101 | type: 0 102 | axis: 0 103 | joyNum: 0 104 | - serializedVersion: 3 105 | m_Name: Mouse X 106 | descriptiveName: 107 | descriptiveNegativeName: 108 | negativeButton: 109 | positiveButton: 110 | altNegativeButton: 111 | altPositiveButton: 112 | gravity: 0 113 | dead: 0 114 | sensitivity: .100000001 115 | snap: 0 116 | invert: 0 117 | type: 1 118 | axis: 0 119 | joyNum: 0 120 | - serializedVersion: 3 121 | m_Name: Mouse Y 122 | descriptiveName: 123 | descriptiveNegativeName: 124 | negativeButton: 125 | positiveButton: 126 | altNegativeButton: 127 | altPositiveButton: 128 | gravity: 0 129 | dead: 0 130 | sensitivity: .100000001 131 | snap: 0 132 | invert: 0 133 | type: 1 134 | axis: 1 135 | joyNum: 0 136 | - serializedVersion: 3 137 | m_Name: Mouse ScrollWheel 138 | descriptiveName: 139 | descriptiveNegativeName: 140 | negativeButton: 141 | positiveButton: 142 | altNegativeButton: 143 | altPositiveButton: 144 | gravity: 0 145 | dead: 0 146 | sensitivity: .100000001 147 | snap: 0 148 | invert: 0 149 | type: 1 150 | axis: 2 151 | joyNum: 0 152 | - serializedVersion: 3 153 | m_Name: Window Shake X 154 | descriptiveName: 155 | descriptiveNegativeName: 156 | negativeButton: 157 | positiveButton: 158 | altNegativeButton: 159 | altPositiveButton: 160 | gravity: 0 161 | dead: 0 162 | sensitivity: .100000001 163 | snap: 0 164 | invert: 0 165 | type: 3 166 | axis: 0 167 | joyNum: 0 168 | - serializedVersion: 3 169 | m_Name: Window Shake Y 170 | descriptiveName: 171 | descriptiveNegativeName: 172 | negativeButton: 173 | positiveButton: 174 | altNegativeButton: 175 | altPositiveButton: 176 | gravity: 0 177 | dead: 0 178 | sensitivity: .100000001 179 | snap: 0 180 | invert: 0 181 | type: 3 182 | axis: 1 183 | joyNum: 0 184 | - serializedVersion: 3 185 | m_Name: Horizontal 186 | descriptiveName: 187 | descriptiveNegativeName: 188 | negativeButton: 189 | positiveButton: 190 | altNegativeButton: 191 | altPositiveButton: 192 | gravity: 0 193 | dead: .189999998 194 | sensitivity: 1 195 | snap: 0 196 | invert: 0 197 | type: 2 198 | axis: 0 199 | joyNum: 0 200 | - serializedVersion: 3 201 | m_Name: Vertical 202 | descriptiveName: 203 | descriptiveNegativeName: 204 | negativeButton: 205 | positiveButton: 206 | altNegativeButton: 207 | altPositiveButton: 208 | gravity: 0 209 | dead: .189999998 210 | sensitivity: 1 211 | snap: 0 212 | invert: 1 213 | type: 2 214 | axis: 1 215 | joyNum: 0 216 | - serializedVersion: 3 217 | m_Name: Fire1 218 | descriptiveName: 219 | descriptiveNegativeName: 220 | negativeButton: 221 | positiveButton: joystick button 0 222 | altNegativeButton: 223 | altPositiveButton: 224 | gravity: 1000 225 | dead: .00100000005 226 | sensitivity: 1000 227 | snap: 0 228 | invert: 0 229 | type: 0 230 | axis: 0 231 | joyNum: 0 232 | - serializedVersion: 3 233 | m_Name: Fire2 234 | descriptiveName: 235 | descriptiveNegativeName: 236 | negativeButton: 237 | positiveButton: joystick button 1 238 | altNegativeButton: 239 | altPositiveButton: 240 | gravity: 1000 241 | dead: .00100000005 242 | sensitivity: 1000 243 | snap: 0 244 | invert: 0 245 | type: 0 246 | axis: 0 247 | joyNum: 0 248 | - serializedVersion: 3 249 | m_Name: Fire3 250 | descriptiveName: 251 | descriptiveNegativeName: 252 | negativeButton: 253 | positiveButton: joystick button 2 254 | altNegativeButton: 255 | altPositiveButton: 256 | gravity: 1000 257 | dead: .00100000005 258 | sensitivity: 1000 259 | snap: 0 260 | invert: 0 261 | type: 0 262 | axis: 0 263 | joyNum: 0 264 | - serializedVersion: 3 265 | m_Name: Jump 266 | descriptiveName: 267 | descriptiveNegativeName: 268 | negativeButton: 269 | positiveButton: joystick button 3 270 | altNegativeButton: 271 | altPositiveButton: 272 | gravity: 1000 273 | dead: .00100000005 274 | sensitivity: 1000 275 | snap: 0 276 | invert: 0 277 | type: 0 278 | axis: 0 279 | joyNum: 0 280 | - serializedVersion: 3 281 | m_Name: Submit 282 | descriptiveName: 283 | descriptiveNegativeName: 284 | negativeButton: 285 | positiveButton: return 286 | altNegativeButton: 287 | altPositiveButton: joystick button 0 288 | gravity: 1000 289 | dead: .00100000005 290 | sensitivity: 1000 291 | snap: 0 292 | invert: 0 293 | type: 0 294 | axis: 0 295 | joyNum: 0 296 | - serializedVersion: 3 297 | m_Name: Submit 298 | descriptiveName: 299 | descriptiveNegativeName: 300 | negativeButton: 301 | positiveButton: enter 302 | altNegativeButton: 303 | altPositiveButton: space 304 | gravity: 1000 305 | dead: .00100000005 306 | sensitivity: 1000 307 | snap: 0 308 | invert: 0 309 | type: 0 310 | axis: 0 311 | joyNum: 0 312 | - serializedVersion: 3 313 | m_Name: Cancel 314 | descriptiveName: 315 | descriptiveNegativeName: 316 | negativeButton: 317 | positiveButton: escape 318 | altNegativeButton: 319 | altPositiveButton: joystick button 1 320 | gravity: 1000 321 | dead: .00100000005 322 | sensitivity: 1000 323 | snap: 0 324 | invert: 0 325 | type: 0 326 | axis: 0 327 | joyNum: 0 328 | -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshAreas: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlitchEnzo/UnityProceduralPrimitives/f78ae73f4da9ad92ebcbf47991d62f877c0b3e8c/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | m_Gravity: {x: 0, y: -9.81000042} 7 | m_DefaultMaterial: {fileID: 0} 8 | m_VelocityIterations: 8 9 | m_PositionIterations: 3 10 | m_VelocityThreshold: 1 11 | m_MaxLinearCorrection: .200000003 12 | m_MaxAngularCorrection: 8 13 | m_MaxTranslationSpeed: 100 14 | m_MaxRotationSpeed: 360 15 | m_MinPenetrationForPenalty: .00999999978 16 | m_BaumgarteScale: .200000003 17 | m_BaumgarteTimeOfImpactScale: .75 18 | m_TimeToSleep: .5 19 | m_LinearSleepTolerance: .00999999978 20 | m_AngularSleepTolerance: 2 21 | m_RaycastsHitTriggers: 1 22 | m_RaycastsStartInColliders: 1 23 | m_ChangeStopsCallbacks: 0 24 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 25 | -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!129 &1 4 | PlayerSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 6 7 | AndroidProfiler: 0 8 | defaultScreenOrientation: 0 9 | targetDevice: 2 10 | targetGlesGraphics: 1 11 | targetIOSGraphics: -1 12 | targetResolution: 0 13 | accelerometerFrequency: 60 14 | companyName: Patrick 15 | productName: PrimitiveTest 16 | cloudProjectId: 17 | defaultCursor: {fileID: 0} 18 | cursorHotspot: {x: 0, y: 0} 19 | defaultScreenWidth: 1024 20 | defaultScreenHeight: 768 21 | defaultScreenWidthWeb: 600 22 | defaultScreenHeightWeb: 450 23 | m_RenderingPath: 1 24 | m_MobileRenderingPath: 1 25 | m_ActiveColorSpace: 0 26 | m_MTRendering: 1 27 | m_MobileMTRendering: 0 28 | m_UseDX11: 0 29 | m_Stereoscopic3D: 0 30 | iosShowActivityIndicatorOnLoading: -1 31 | androidShowActivityIndicatorOnLoading: -1 32 | iosAppInBackgroundBehavior: 0 33 | displayResolutionDialog: 1 34 | allowedAutorotateToPortrait: 1 35 | allowedAutorotateToPortraitUpsideDown: 1 36 | allowedAutorotateToLandscapeRight: 1 37 | allowedAutorotateToLandscapeLeft: 1 38 | useOSAutorotation: 1 39 | use32BitDisplayBuffer: 0 40 | disableDepthAndStencilBuffers: 0 41 | defaultIsFullScreen: 0 42 | defaultIsNativeResolution: 1 43 | runInBackground: 0 44 | captureSingleScreen: 0 45 | Override IPod Music: 0 46 | Prepare IOS For Recording: 0 47 | submitAnalytics: 1 48 | usePlayerLog: 1 49 | bakeCollisionMeshes: 0 50 | forceSingleInstance: 0 51 | resizableWindow: 0 52 | useMacAppStoreValidation: 0 53 | gpuSkinning: 0 54 | xboxPIXTextureCapture: 0 55 | xboxEnableAvatar: 0 56 | xboxEnableKinect: 0 57 | xboxEnableKinectAutoTracking: 0 58 | xboxEnableFitness: 0 59 | visibleInBackground: 0 60 | macFullscreenMode: 2 61 | d3d9FullscreenMode: 1 62 | d3d11FullscreenMode: 1 63 | xboxSpeechDB: 0 64 | xboxEnableHeadOrientation: 0 65 | xboxEnableGuest: 0 66 | xboxOneResolution: 0 67 | ps3SplashScreen: {fileID: 0} 68 | videoMemoryForVertexBuffers: 0 69 | psp2PowerMode: 0 70 | psp2AcquireBGM: 1 71 | m_SupportedAspectRatios: 72 | 4:3: 1 73 | 5:4: 1 74 | 16:10: 1 75 | 16:9: 1 76 | Others: 1 77 | bundleIdentifier: com.Company.ProductName 78 | bundleVersion: 1.0 79 | preloadedAssets: [] 80 | metroEnableIndependentInputSource: 0 81 | metroEnableLowLatencyPresentationAPI: 0 82 | xboxOneDisableKinectGpuReservation: 0 83 | productGUID: d5a96919df212b94bbfddaafb66958d1 84 | AndroidBundleVersionCode: 1 85 | AndroidMinSdkVersion: 9 86 | AndroidPreferredInstallLocation: 1 87 | aotOptions: 88 | apiCompatibilityLevel: 1 89 | iPhoneStrippingLevel: 0 90 | iPhoneScriptCallOptimization: 0 91 | ForceInternetPermission: 0 92 | ForceSDCardPermission: 0 93 | CreateWallpaper: 0 94 | APKExpansionFiles: 0 95 | preloadShaders: 0 96 | StripUnusedMeshComponents: 0 97 | iPhoneSdkVersion: 988 98 | iPhoneTargetOSVersion: 22 99 | uIPrerenderedIcon: 0 100 | uIRequiresPersistentWiFi: 0 101 | uIStatusBarHidden: 1 102 | uIExitOnSuspend: 0 103 | uIStatusBarStyle: 0 104 | iPhoneSplashScreen: {fileID: 0} 105 | iPhoneHighResSplashScreen: {fileID: 0} 106 | iPhoneTallHighResSplashScreen: {fileID: 0} 107 | iPhone47inSplashScreen: {fileID: 0} 108 | iPhone55inPortraitSplashScreen: {fileID: 0} 109 | iPhone55inLandscapeSplashScreen: {fileID: 0} 110 | iPadPortraitSplashScreen: {fileID: 0} 111 | iPadHighResPortraitSplashScreen: {fileID: 0} 112 | iPadLandscapeSplashScreen: {fileID: 0} 113 | iPadHighResLandscapeSplashScreen: {fileID: 0} 114 | iOSLaunchScreenType: 0 115 | iOSLaunchScreenPortrait: {fileID: 0} 116 | iOSLaunchScreenLandscape: {fileID: 0} 117 | iOSLaunchScreenBackgroundColor: 118 | serializedVersion: 2 119 | rgba: 0 120 | iOSLaunchScreenFillPct: 1 121 | iOSLaunchScreenCustomXibPath: 122 | AndroidTargetDevice: 0 123 | AndroidSplashScreenScale: 0 124 | AndroidKeystoreName: 125 | AndroidKeyaliasName: 126 | AndroidTVCompatibility: 1 127 | AndroidIsGame: 1 128 | androidEnableBanner: 1 129 | m_AndroidBanners: 130 | - width: 320 131 | height: 180 132 | banner: {fileID: 0} 133 | resolutionDialogBanner: {fileID: 0} 134 | m_BuildTargetIcons: 135 | - m_BuildTarget: 136 | m_Icons: 137 | - m_Icon: {fileID: 0} 138 | m_Size: 128 139 | m_BuildTargetBatching: [] 140 | webPlayerTemplate: APPLICATION:Default 141 | m_TemplateCustomTags: {} 142 | actionOnDotNetUnhandledException: 1 143 | enableInternalProfiler: 0 144 | logObjCUncaughtExceptions: 1 145 | enableCrashReportAPI: 0 146 | locationUsageDescription: 147 | XboxTitleId: 148 | XboxImageXexPath: 149 | XboxSpaPath: 150 | XboxGenerateSpa: 0 151 | XboxDeployKinectResources: 0 152 | XboxSplashScreen: {fileID: 0} 153 | xboxEnableSpeech: 0 154 | xboxAdditionalTitleMemorySize: 0 155 | xboxDeployKinectHeadOrientation: 0 156 | xboxDeployKinectHeadPosition: 0 157 | ps3TitleConfigPath: 158 | ps3DLCConfigPath: 159 | ps3ThumbnailPath: 160 | ps3BackgroundPath: 161 | ps3SoundPath: 162 | ps3NPAgeRating: 12 163 | ps3TrophyCommId: 164 | ps3NpCommunicationPassphrase: 165 | ps3TrophyPackagePath: 166 | ps3BootCheckMaxSaveGameSizeKB: 128 167 | ps3TrophyCommSig: 168 | ps3SaveGameSlots: 1 169 | ps3TrialMode: 0 170 | ps3VideoMemoryForAudio: 0 171 | ps3EnableVerboseMemoryStats: 0 172 | ps3UseSPUForUmbra: 0 173 | ps3EnableMoveSupport: 1 174 | ps3DisableDolbyEncoding: 0 175 | ps4NPAgeRating: 12 176 | ps4NPTitleSecret: 177 | ps4NPTrophyPackPath: 178 | ps4ParentalLevel: 1 179 | ps4ContentID: ED1633-NPXX51362_00-0000000000000000 180 | ps4Category: 0 181 | ps4MasterVersion: 01.00 182 | ps4AppVersion: 01.00 183 | ps4AppType: 0 184 | ps4ParamSfxPath: 185 | ps4VideoOutPixelFormat: 0 186 | ps4VideoOutResolution: 4 187 | ps4PronunciationXMLPath: 188 | ps4PronunciationSIGPath: 189 | ps4BackgroundImagePath: 190 | ps4StartupImagePath: 191 | ps4SaveDataImagePath: 192 | ps4BGMPath: 193 | ps4ShareFilePath: 194 | ps4NPtitleDatPath: 195 | ps4RemotePlayKeyAssignment: -1 196 | ps4EnterButtonAssignment: 1 197 | ps4ApplicationParam1: 0 198 | ps4ApplicationParam2: 0 199 | ps4ApplicationParam3: 0 200 | ps4ApplicationParam4: 0 201 | ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ 202 | ps4pnSessions: 1 203 | ps4pnPresence: 1 204 | ps4pnFriends: 1 205 | ps4pnGameCustomData: 1 206 | playerPrefsSupport: 0 207 | monoEnv: 208 | psp2Splashimage: {fileID: 0} 209 | psp2NPTrophyPackPath: 210 | psp2NPSupportGBMorGJP: 0 211 | psp2NPAgeRating: 12 212 | psp2NPCommsID: 213 | psp2NPCommunicationsID: 214 | psp2NPCommsPassphrase: 215 | psp2NPCommsSig: 216 | psp2ParamSfxPath: 217 | psp2ManualPath: 218 | psp2LiveAreaGatePath: 219 | psp2LiveAreaBackroundPath: 220 | psp2LiveAreaPath: 221 | psp2LiveAreaTrialPath: 222 | psp2PatchChangeInfoPath: 223 | psp2PatchOriginalPackage: 224 | psp2PackagePassword: F69AzBlax3CF3EDNhm3soLBPh71Yexui 225 | psp2KeystoneFile: 226 | psp2DRMType: 0 227 | psp2StorageType: 0 228 | psp2MediaCapacity: 0 229 | psp2DLCConfigPath: 230 | psp2ThumbnailPath: 231 | psp2BackgroundPath: 232 | psp2SoundPath: 233 | psp2TrophyCommId: 234 | psp2TrophyPackagePath: 235 | psp2PackagedResourcesPath: 236 | psp2SaveDataQuota: 10240 237 | psp2ParentalLevel: 1 238 | psp2ShortTitle: Not Set 239 | psp2ContentID: IV0000-ABCD12345_00-0123456789ABCDEF 240 | psp2Category: 0 241 | psp2MasterVersion: 01.00 242 | psp2AppVersion: 01.00 243 | psp2TVBootMode: 0 244 | psp2EnterButtonAssignment: 2 245 | psp2TVDisableEmu: 0 246 | psp2AllowTwitterDialog: 1 247 | psp2Upgradable: 0 248 | psp2HealthWarning: 0 249 | psp2UseLibLocation: 0 250 | psp2InfoBarOnStartup: 0 251 | psp2InfoBarColor: 0 252 | psmSplashimage: {fileID: 0} 253 | spritePackerPolicy: 254 | scriptingDefineSymbols: {} 255 | metroPackageName: Procedural Primitives 256 | metroPackageLogo: 257 | metroPackageLogo140: 258 | metroPackageLogo180: 259 | metroPackageLogo240: 260 | metroPackageVersion: 261 | metroCertificatePath: 262 | metroCertificatePassword: 263 | metroCertificateSubject: 264 | metroCertificateIssuer: 265 | metroCertificateNotAfter: 0000000000000000 266 | metroApplicationDescription: Procedural Primitives 267 | metroStoreTileLogo80: 268 | metroStoreTileLogo: 269 | metroStoreTileLogo140: 270 | metroStoreTileLogo180: 271 | metroStoreTileWideLogo80: 272 | metroStoreTileWideLogo: 273 | metroStoreTileWideLogo140: 274 | metroStoreTileWideLogo180: 275 | metroStoreTileSmallLogo80: 276 | metroStoreTileSmallLogo: 277 | metroStoreTileSmallLogo140: 278 | metroStoreTileSmallLogo180: 279 | metroStoreSmallTile80: 280 | metroStoreSmallTile: 281 | metroStoreSmallTile140: 282 | metroStoreSmallTile180: 283 | metroStoreLargeTile80: 284 | metroStoreLargeTile: 285 | metroStoreLargeTile140: 286 | metroStoreLargeTile180: 287 | metroStoreSplashScreenImage: 288 | metroStoreSplashScreenImage140: 289 | metroStoreSplashScreenImage180: 290 | metroPhoneAppIcon: 291 | metroPhoneAppIcon140: 292 | metroPhoneAppIcon240: 293 | metroPhoneSmallTile: 294 | metroPhoneSmallTile140: 295 | metroPhoneSmallTile240: 296 | metroPhoneMediumTile: 297 | metroPhoneMediumTile140: 298 | metroPhoneMediumTile240: 299 | metroPhoneWideTile: 300 | metroPhoneWideTile140: 301 | metroPhoneWideTile240: 302 | metroPhoneSplashScreenImage: 303 | metroPhoneSplashScreenImage140: 304 | metroPhoneSplashScreenImage240: 305 | metroTileShortName: 306 | metroCommandLineArgsFile: 307 | metroTileShowName: 1 308 | metroMediumTileShowName: 0 309 | metroLargeTileShowName: 0 310 | metroWideTileShowName: 0 311 | metroDefaultTileSize: 1 312 | metroTileForegroundText: 1 313 | metroTileBackgroundColor: {r: 0, g: 0, b: 0, a: 1} 314 | metroSplashScreenBackgroundColor: {r: 0, g: 0, b: 0, a: 1} 315 | metroSplashScreenUseBackgroundColor: 0 316 | platformCapabilities: {} 317 | metroFTAName: 318 | metroFTAFileTypes: [] 319 | metroProtocolName: 320 | metroCompilationOverrides: 1 321 | blackberryDeviceAddress: 322 | blackberryDevicePassword: 323 | blackberryTokenPath: 324 | blackberryTokenExires: 325 | blackberryTokenAuthor: 326 | blackberryTokenAuthorId: 327 | blackberryCskPassword: 328 | blackberrySaveLogPath: 329 | blackberrySharedPermissions: 0 330 | blackberryCameraPermissions: 0 331 | blackberryGPSPermissions: 0 332 | blackberryDeviceIDPermissions: 0 333 | blackberryMicrophonePermissions: 0 334 | blackberryGamepadSupport: 0 335 | blackberryBuildId: 0 336 | blackberryLandscapeSplashScreen: {fileID: 0} 337 | blackberryPortraitSplashScreen: {fileID: 0} 338 | blackberrySquareSplashScreen: {fileID: 0} 339 | tizenProductDescription: 340 | tizenProductURL: 341 | tizenCertificatePath: 342 | tizenCertificatePassword: 343 | tizenGPSPermissions: 0 344 | tizenMicrophonePermissions: 0 345 | stvDeviceAddress: 346 | stvProductDescription: 347 | stvProductAuthor: 348 | stvProductAuthorEmail: 349 | stvProductLink: 350 | stvProductCategory: 0 351 | XboxOneProductId: 352 | XboxOneUpdateKey: 353 | XboxOneSandboxId: 354 | XboxOneContentId: 355 | XboxOneTitleId: 356 | XboxOneSCId: 357 | XboxOneGameOsOverridePath: 358 | XboxOnePackagingOverridePath: 359 | XboxOneAppManifestOverridePath: 360 | XboxOnePackageEncryption: 0 361 | XboxOneDescription: 362 | XboxOneIsContentPackage: 0 363 | XboxOneEnableGPUVariability: 0 364 | XboxOneSockets: {} 365 | XboxOneSplashScreen: {fileID: 0} 366 | XboxOneAllowedProductIds: [] 367 | XboxOnePersistentLocalStorageSize: 0 368 | intPropertyNames: 369 | - Metro::ScriptingBackend 370 | - WP8::ScriptingBackend 371 | - WebGL::ScriptingBackend 372 | - WebGL::audioCompressionFormat 373 | - WebGL::exceptionSupport 374 | - WebGL::memorySize 375 | - iOS::Architecture 376 | - iOS::ScriptingBackend 377 | Metro::ScriptingBackend: 2 378 | WP8::ScriptingBackend: 2 379 | WebGL::ScriptingBackend: 1 380 | WebGL::audioCompressionFormat: 4 381 | WebGL::exceptionSupport: 0 382 | WebGL::memorySize: 256 383 | iOS::Architecture: 2 384 | iOS::ScriptingBackend: 0 385 | boolPropertyNames: 386 | - WebGL::dataCaching 387 | WebGL::dataCaching: 0 388 | stringPropertyNames: 389 | - WebGL::emscriptenArgs 390 | - WebGL::template 391 | WebGL::emscriptenArgs: 392 | WebGL::template: APPLICATION:Default 393 | firstStreamedLevelWithResources: 0 394 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 3 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Fastest 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 0 15 | shadowCascades: 1 16 | shadowDistance: 30 17 | shadowCascade2Split: .333333343 18 | shadowCascade4Split: {x: .0666666701, y: .200000003, z: .466666669} 19 | blendWeights: 1 20 | textureQuality: 1 21 | anisotropicTextures: 0 22 | antiAliasing: 0 23 | softParticles: 0 24 | softVegetation: 0 25 | realtimeReflectionProbes: 0 26 | billboardsFaceCameraPosition: 0 27 | vSyncCount: 0 28 | lodBias: .300000012 29 | maximumLODLevel: 0 30 | particleRaycastBudget: 4 31 | excludedTargetPlatforms: [] 32 | - serializedVersion: 2 33 | name: Fast 34 | pixelLightCount: 0 35 | shadows: 0 36 | shadowResolution: 0 37 | shadowProjection: 0 38 | shadowCascades: 1 39 | shadowDistance: 30 40 | shadowCascade2Split: .333333343 41 | shadowCascade4Split: {x: .0666666701, y: .200000003, z: .466666669} 42 | blendWeights: 2 43 | textureQuality: 0 44 | anisotropicTextures: 0 45 | antiAliasing: 0 46 | softParticles: 0 47 | softVegetation: 0 48 | realtimeReflectionProbes: 0 49 | billboardsFaceCameraPosition: 0 50 | vSyncCount: 0 51 | lodBias: .400000006 52 | maximumLODLevel: 0 53 | particleRaycastBudget: 16 54 | excludedTargetPlatforms: [] 55 | - serializedVersion: 2 56 | name: Simple 57 | pixelLightCount: 1 58 | shadows: 1 59 | shadowResolution: 0 60 | shadowProjection: 0 61 | shadowCascades: 1 62 | shadowDistance: 30 63 | shadowCascade2Split: .333333343 64 | shadowCascade4Split: {x: .0666666701, y: .200000003, z: .466666669} 65 | blendWeights: 2 66 | textureQuality: 0 67 | anisotropicTextures: 1 68 | antiAliasing: 0 69 | softParticles: 0 70 | softVegetation: 0 71 | realtimeReflectionProbes: 0 72 | billboardsFaceCameraPosition: 0 73 | vSyncCount: 0 74 | lodBias: .699999988 75 | maximumLODLevel: 0 76 | particleRaycastBudget: 64 77 | excludedTargetPlatforms: [] 78 | - serializedVersion: 2 79 | name: Good 80 | pixelLightCount: 2 81 | shadows: 2 82 | shadowResolution: 1 83 | shadowProjection: 0 84 | shadowCascades: 2 85 | shadowDistance: 100 86 | shadowCascade2Split: .333333343 87 | shadowCascade4Split: {x: .0666666701, y: .200000003, z: .466666669} 88 | blendWeights: 2 89 | textureQuality: 0 90 | anisotropicTextures: 1 91 | antiAliasing: 0 92 | softParticles: 0 93 | softVegetation: 1 94 | realtimeReflectionProbes: 1 95 | billboardsFaceCameraPosition: 1 96 | vSyncCount: 1 97 | lodBias: 1 98 | maximumLODLevel: 0 99 | particleRaycastBudget: 256 100 | excludedTargetPlatforms: [] 101 | - serializedVersion: 2 102 | name: Beautiful 103 | pixelLightCount: 3 104 | shadows: 2 105 | shadowResolution: 2 106 | shadowProjection: 0 107 | shadowCascades: 2 108 | shadowDistance: 150 109 | shadowCascade2Split: .333333343 110 | shadowCascade4Split: {x: .0666666701, y: .200000003, z: .466666669} 111 | blendWeights: 4 112 | textureQuality: 0 113 | anisotropicTextures: 2 114 | antiAliasing: 2 115 | softParticles: 1 116 | softVegetation: 1 117 | realtimeReflectionProbes: 1 118 | billboardsFaceCameraPosition: 1 119 | vSyncCount: 1 120 | lodBias: 1.5 121 | maximumLODLevel: 0 122 | particleRaycastBudget: 1024 123 | excludedTargetPlatforms: [] 124 | - serializedVersion: 2 125 | name: Fantastic 126 | pixelLightCount: 4 127 | shadows: 2 128 | shadowResolution: 2 129 | shadowProjection: 0 130 | shadowCascades: 4 131 | shadowDistance: 300 132 | shadowCascade2Split: .333333343 133 | shadowCascade4Split: {x: .0666666701, y: .200000003, z: .466666669} 134 | blendWeights: 4 135 | textureQuality: 0 136 | anisotropicTextures: 2 137 | antiAliasing: 2 138 | softParticles: 1 139 | softVegetation: 1 140 | realtimeReflectionProbes: 1 141 | billboardsFaceCameraPosition: 1 142 | vSyncCount: 1 143 | lodBias: 2 144 | maximumLODLevel: 0 145 | particleRaycastBudget: 4096 146 | excludedTargetPlatforms: [] 147 | m_PerPlatformDefaultQuality: 148 | Android: 2 149 | BlackBerry: 2 150 | GLES Emulation: 5 151 | PS3: 5 152 | PS4: 5 153 | PSM: 5 154 | PSP2: 5 155 | Samsung TV: 2 156 | Standalone: 5 157 | Tizen: 2 158 | WP8: 5 159 | Web: 5 160 | WebGL: 3 161 | Windows Store Apps: 5 162 | XBOX360: 5 163 | XboxOne: 5 164 | iPhone: 2 165 | -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: .0199999996 7 | Maximum Allowed Timestep: .333333343 8 | m_TimeScale: 1 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityProceduralPrimitives 2 | A set of helper scripts to procedurally generate 3D meshes. 3 | 4 | Procedurally create Unity meshes in the shape of Cylinders, Cones, Boxes, Spheres, Planes, Circles, Rings, Tori, Torus Knots, and Lathes. 5 | --------------------------------------------------------------------------------