From 44f1791b9893facc2129a6daa31b4b822e8c2641 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 27 Jun 2022 21:57:29 -0400 Subject: [PATCH] Allow using more than 65535 vertices in CubeSphere and IcoSphere --- NewHorizons/Builder/Body/Geometry/CubeSphere.cs | 13 ++++++------- NewHorizons/Builder/Body/Geometry/Icosphere.cs | 11 ++++++++--- NewHorizons/Builder/Body/HeightMapBuilder.cs | 3 +-- NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- NewHorizons/Handlers/TitleSceneHandler.cs | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/NewHorizons/Builder/Body/Geometry/CubeSphere.cs b/NewHorizons/Builder/Body/Geometry/CubeSphere.cs index f2c97b8d..31ac6752 100644 --- a/NewHorizons/Builder/Body/Geometry/CubeSphere.cs +++ b/NewHorizons/Builder/Body/Geometry/CubeSphere.cs @@ -7,13 +7,6 @@ namespace NewHorizons.Builder.Body.Geometry { public static Mesh Build(int resolution, Texture2D heightMap, float minHeight, float maxHeight, Vector3 stretch) { - // It breaks if resolution is greater than 100 I don't know why - if (resolution > 100) - { - Logger.LogWarning($"Can't make CubeSphere's with resolution higher than 100 for some reason"); - resolution = 100; - } - Mesh mesh = new Mesh(); mesh.name = "CubeSphere"; @@ -109,6 +102,12 @@ namespace NewHorizons.Builder.Body.Geometry } } + // Higher than this and we have to use a different indexFormat + if (vertices.Length > 65535) + { + mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; + } + mesh.vertices = vertices; mesh.normals = normals; mesh.uv = uvs; diff --git a/NewHorizons/Builder/Body/Geometry/Icosphere.cs b/NewHorizons/Builder/Body/Geometry/Icosphere.cs index 67b634b7..0fcbb60c 100644 --- a/NewHorizons/Builder/Body/Geometry/Icosphere.cs +++ b/NewHorizons/Builder/Body/Geometry/Icosphere.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; using Random = UnityEngine.Random; @@ -60,8 +60,7 @@ namespace NewHorizons.Builder.Body.Geometry { Mesh mesh = new Mesh(); - if (vertices.Count <= subdivisions) - RefineFaces(subdivisions); + if (vertices.Count <= subdivisions) RefineFaces(subdivisions); var verticesToCopy = vertices[subdivisions]; @@ -89,6 +88,12 @@ namespace NewHorizons.Builder.Body.Geometry uvs[i] = new Vector2(x, y); } + // Higher than this and we have to use a different indexFormat + if (newVertices.Length > 65535) + { + mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; + } + mesh.vertices = newVertices; mesh.triangles = triangles[subdivisions]; mesh.normals = normals; diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index 955b68e4..2c09240e 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -5,14 +5,13 @@ using OWML.Common; using System; using UnityEngine; using Logger = NewHorizons.Utility.Logger; -using Object = UnityEngine.Object; namespace NewHorizons.Builder.Body { public static class HeightMapBuilder { public static Shader PlanetShader; - public static void Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod, int resolution = 51) + public static void Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod, int resolution) { var deleteHeightmapFlag = false; diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 8ca8f61d..003cbe4e 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -387,7 +387,7 @@ namespace NewHorizons.Handlers if (body.Config.HeightMap != null) { - HeightMapBuilder.Make(go, sector, body.Config.HeightMap, body.Mod); + HeightMapBuilder.Make(go, sector, body.Config.HeightMap, body.Mod, 51); } if (body.Config.ProcGen != null) diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index ebbb4043..52b82def 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -96,7 +96,7 @@ namespace NewHorizons.Handlers heightMap.textureMap = body.Config.Atmosphere.clouds.texturePath; } - HeightMapBuilder.Make(titleScreenGO, null, heightMap, body.Mod); + HeightMapBuilder.Make(titleScreenGO, null, heightMap, body.Mod, 30); GameObject pivot = GameObject.Instantiate(SearchUtilities.Find("Scene/Background/PlanetPivot"), SearchUtilities.Find("Scene/Background").transform); pivot.GetComponent()._degreesPerSecond = 10f;