diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index de6bd610..bd1f40e5 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -32,16 +32,14 @@ namespace NewHorizons.Builder.Atmosphere Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32(); - GameObject cloudsMainGO = new GameObject(); + GameObject cloudsMainGO = new GameObject("Clouds"); cloudsMainGO.SetActive(false); cloudsMainGO.transform.parent = body.transform; - cloudsMainGO.name = "Clouds"; - GameObject cloudsTopGO = new GameObject(); + GameObject cloudsTopGO = new GameObject("TopClouds"); cloudsTopGO.SetActive(false); cloudsTopGO.transform.parent = cloudsMainGO.transform; cloudsTopGO.transform.localScale = Vector3.one * atmo.Size; - cloudsTopGO.name = "TopClouds"; MeshFilter topMF = cloudsTopGO.AddComponent(); topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; @@ -54,6 +52,7 @@ namespace NewHorizons.Builder.Atmosphere { var mat = new Material(GameObject.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials[i]); if (!atmo.ShadowsOnClouds) mat.renderQueue = 2550; + mat.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud"; tempArray[i] = mat; } topMR.sharedMaterials = tempArray; @@ -63,6 +62,7 @@ namespace NewHorizons.Builder.Atmosphere if (_sphereShader == null) _sphereShader = Main.ShaderBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); topMR.material = new Material(_sphereShader); if (!atmo.ShadowsOnClouds) topMR.material.renderQueue = 2550; + topMR.material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud"; } foreach (var material in topMR.sharedMaterials) @@ -86,11 +86,10 @@ namespace NewHorizons.Builder.Atmosphere topRT._degreesPerSecond = 10; topRT._randomizeRotationRate = false; - GameObject cloudsBottomGO = new GameObject(); + GameObject cloudsBottomGO = new GameObject("BottomClouds"); cloudsBottomGO.SetActive(false); cloudsBottomGO.transform.parent = cloudsMainGO.transform; cloudsBottomGO.transform.localScale = Vector3.one * (atmo.Size * 0.9f); - cloudsBottomGO.name = "BottomClouds"; TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent().tessellationMeshGroup; @@ -114,11 +113,10 @@ namespace NewHorizons.Builder.Atmosphere TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); bottomTSST._sector = sector; - GameObject cloudsFluidGO = new GameObject(); + GameObject cloudsFluidGO = new GameObject("CloudsFluid"); cloudsFluidGO.SetActive(false); cloudsFluidGO.layer = 17; cloudsFluidGO.transform.parent = cloudsMainGO.transform; - cloudsFluidGO.name = "CloudsFluid"; SphereCollider fluidSC = cloudsFluidGO.AddComponent(); fluidSC.isTrigger = true; diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index 038debfa..9aa3e404 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -14,7 +14,7 @@ namespace NewHorizons.Builder.Atmosphere volumesGO.SetActive(false); volumesGO.transform.parent = body.transform; - GameObject rulesetGO = new GameObject(); + GameObject rulesetGO = new GameObject("Ruleset"); rulesetGO.SetActive(false); rulesetGO.transform.parent = volumesGO.transform; diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 1ab97506..25a14665 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -20,9 +20,10 @@ namespace NewHorizons.Builder.Body { var belt = parentConfig.AsteroidBelt; - var minSize = 20; - var maxSize = 50; + float minSize = belt.MinSize; + float maxSize = belt.MaxSize; int count = (int)(2f * Mathf.PI * belt.InnerRadius / (10f * maxSize)); + if (belt.Amount >= 0) count = belt.Amount; if (count > 200) count = 200; Random.InitState(belt.RandomSeed); diff --git a/NewHorizons/Builder/Body/Geometry/CubeSphere.cs b/NewHorizons/Builder/Body/Geometry/CubeSphere.cs index 489a8e3a..113dfbbd 100644 --- a/NewHorizons/Builder/Body/Geometry/CubeSphere.cs +++ b/NewHorizons/Builder/Body/Geometry/CubeSphere.cs @@ -11,7 +11,7 @@ namespace NewHorizons.Builder.Body.Geometry { static class CubeSphere { - public static Mesh Build(int resolution, Texture2D heightMap, float minHeight, float maxHeight) + 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) @@ -23,15 +23,51 @@ namespace NewHorizons.Builder.Body.Geometry Mesh mesh = new Mesh(); mesh.name = "CubeSphere"; + float max = 1; + if (stretch.x > stretch.y && stretch.x > stretch.z) + max = stretch.x; + else if (stretch.y > stretch.x && stretch.y > stretch.z) + max = stretch.y; + else if (stretch.z > stretch.x && stretch.z > stretch.y) + max = stretch.z; + else if (stretch.y == stretch.z && stretch.x > stretch.y) + max = stretch.x; + else if (stretch.x == stretch.z && stretch.y > stretch.x) + max = stretch.y; + else if (stretch.x == stretch.y && stretch.z > stretch.x) + max = stretch.z; + minHeight /= max; + maxHeight /= max; + CreateVertices(mesh, resolution, heightMap, minHeight, maxHeight); + StretchVertices(mesh, stretch); CreateTriangles(mesh, resolution); mesh.RecalculateNormals(); + mesh.RecalculateBounds(); mesh.RecalculateTangents(); return mesh; } + private static void StretchVertices(Mesh mesh, Vector3 scale) + { + var baseVertices = mesh.vertices; + + var vertices = new Vector3[baseVertices.Length]; + + for (var i = 0; i < vertices.Length; i++) + { + var vertex = baseVertices[i]; + vertex.x = vertex.x * scale.x; + vertex.y = vertex.y * scale.y; + vertex.z = vertex.z * scale.z; + vertices[i] = vertex; + } + + mesh.vertices = vertices; + } + // Thank you Catlikecoding private static void CreateVertices(Mesh mesh, int resolution, Texture2D heightMap, float minHeight, float maxHeight) { diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index 0744c84e..7c28e4b1 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -38,7 +38,7 @@ namespace NewHorizons.Builder.Body cubeSphere.transform.parent = go.transform; cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0); - Mesh mesh = CubeSphere.Build(51, heightMap, module.MinHeight, module.MaxHeight); + Mesh mesh = CubeSphere.Build(51, heightMap, module.MinHeight, module.MaxHeight, module.Stretch); cubeSphere.AddComponent(); cubeSphere.GetComponent().mesh = mesh; @@ -49,6 +49,7 @@ namespace NewHorizons.Builder.Body var cubeSphereMR = cubeSphere.AddComponent(); cubeSphereMR.material = new Material(PlanetShader); + cubeSphereMR.material.name = textureMap.name; cubeSphereMR.material.mainTexture = textureMap; var cubeSphereMC = cubeSphere.AddComponent(); diff --git a/NewHorizons/External/AsteroidBeltModule.cs b/NewHorizons/External/AsteroidBeltModule.cs index c275b376..42cf1a64 100644 --- a/NewHorizons/External/AsteroidBeltModule.cs +++ b/NewHorizons/External/AsteroidBeltModule.cs @@ -10,6 +10,9 @@ namespace NewHorizons.External { public float InnerRadius { get; set; } public float OuterRadius { get; set; } + public float MinSize { get; set; } = 20; + public float MaxSize { get; set; } = 50; + public int Amount { get; set; } = -1; public float Inclination { get; set; } public float LongitudeOfAscendingNode { get; set; } public int RandomSeed { get; set; } diff --git a/NewHorizons/External/HeightMapModule.cs b/NewHorizons/External/HeightMapModule.cs index 3e67e704..ea81c16e 100644 --- a/NewHorizons/External/HeightMapModule.cs +++ b/NewHorizons/External/HeightMapModule.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using NewHorizons.Utility; +using UnityEngine; namespace NewHorizons.External { @@ -12,5 +9,6 @@ namespace NewHorizons.External public string TextureMap { get; set; } public float MinHeight { get; set; } public float MaxHeight { get; set; } + public MVector3 Stretch { get; set; } = (MVector3)Vector3.one; } } diff --git a/NewHorizons/Utility/ImageUtilities.cs b/NewHorizons/Utility/ImageUtilities.cs index 005dfa2b..4d1aa679 100644 --- a/NewHorizons/Utility/ImageUtilities.cs +++ b/NewHorizons/Utility/ImageUtilities.cs @@ -1,5 +1,6 @@ using OWML.Common; -using System; +using System; +using System.Collections.Generic; using System.IO; using UnityEngine; @@ -10,6 +11,7 @@ namespace NewHorizons.Utility public static Texture2D MakeOutline(Texture2D texture, Color color, int thickness) { var outline = new Texture2D(texture.width, texture.height, TextureFormat.ARGB32, false); + outline.name = texture.name + "Outline"; var outlinePixels = new Color[texture.width * texture.height]; var pixels = texture.GetPixels(); @@ -62,6 +64,7 @@ namespace NewHorizons.Utility } var newImage = new Texture2D(image.width, image.height); + newImage.name = image.name + "Tinted"; newImage.SetPixels(pixels); newImage.Apply(); return newImage; @@ -78,6 +81,7 @@ namespace NewHorizons.Utility } var newImage = new Texture2D(image.width, image.height); + newImage.name = image.name + "LerpedGrayscale"; newImage.SetPixels(pixels); newImage.Apply(); return newImage; @@ -86,6 +90,7 @@ namespace NewHorizons.Utility public static Texture2D LoadImage(string filepath) { Texture2D tex = new Texture2D(2, 2); + tex.name = Path.GetFileNameWithoutExtension(filepath); tex.LoadRawTextureData(File.ReadAllBytes(filepath)); return tex; } @@ -93,6 +98,7 @@ namespace NewHorizons.Utility public static Texture2D ClearTexture(int width, int height) { var tex = (new Texture2D(1, 1, TextureFormat.ARGB32, false)); + tex.name = "Clear"; Color fillColor = Color.clear; Color[] fillPixels = new Color[tex.width * tex.height]; for(int i = 0; i < fillPixels.Length; i++) @@ -107,6 +113,7 @@ namespace NewHorizons.Utility public static Texture2D CanvasScaled(Texture2D src, int width, int height) { var tex = (new Texture2D(width, height, TextureFormat.ARGB32, false)); + tex.name = src.name + "CanvasScaled"; Color[] fillPixels = new Color[tex.width * tex.height]; for (int i = 0; i < tex.width; i++) { @@ -120,13 +127,24 @@ namespace NewHorizons.Utility return tex; } + private static Dictionary _loadedTextures = new Dictionary(); + public static Texture2D GetTexture(IModBehaviour mod, string filename) { // Copied from OWML but without the print statement lol var path = mod.ModHelper.Manifest.ModFolderPath + filename; + if (_loadedTextures.ContainsKey(path)) + { + Logger.Log($"Already loaded image at path: {path}"); + return _loadedTextures[path]; + } + Logger.Log($"Loading image at path: {path}"); var data = File.ReadAllBytes(path); var texture = new Texture2D(2, 2); + texture.name = Path.GetFileNameWithoutExtension(path); texture.LoadImage(data); + UnityEngine.Object.DontDestroyOnLoad(texture); + _loadedTextures.Add(path, texture); return texture; } diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index 3ce0323b..5fbd70f2 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -439,6 +439,10 @@ "type": "number", "minimum": 0, "description": "The highest points on your planet will be at this height." + }, + "stretch": { + "$ref": "#/$defs/vector3", + "description": "The scale of the terrain." } } }, @@ -459,6 +463,24 @@ "default": 0, "minimum": 0 }, + "minSize": { + "type": "number", + "default": 20, + "minimum": 0, + "description": "Minimum size of the asteroids." + }, + "maxSize": { + "type": "number", + "default": 50, + "minimum": 0, + "description": "Maximum size of the asteroids." + }, + "amount": { + "type": "integer", + "minimum": 0, + "maximum": 200, + "description": "Amount of asteroids to create." + }, "inclination": { "$ref": "#/$defs/angle", "description": "Angle between the rings and the equatorial plane of the planet." @@ -581,6 +603,14 @@ "type": "string", "description": "Relative filepath to an asset-bundle" }, + "objFilePath": { + "type": "string", + "description": "Relative filepath to the obj file" + }, + "mtlFilePath": { + "type": "string", + "description": "Relative filepath to the mtl file of the obj file" + }, "position": { "$ref": "#/$defs/vector3" },