Merge branch 'dev' into no-more-CR

This commit is contained in:
Nick 2022-05-01 00:57:15 -04:00
commit 6b07ee8bf3
10 changed files with 114 additions and 19 deletions

View File

@ -32,16 +32,14 @@ namespace NewHorizons.Builder.Atmosphere
Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32(); Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32();
GameObject cloudsMainGO = new GameObject(); GameObject cloudsMainGO = new GameObject("Clouds");
cloudsMainGO.SetActive(false); cloudsMainGO.SetActive(false);
cloudsMainGO.transform.parent = body.transform; cloudsMainGO.transform.parent = body.transform;
cloudsMainGO.name = "Clouds";
GameObject cloudsTopGO = new GameObject(); GameObject cloudsTopGO = new GameObject("TopClouds");
cloudsTopGO.SetActive(false); cloudsTopGO.SetActive(false);
cloudsTopGO.transform.parent = cloudsMainGO.transform; cloudsTopGO.transform.parent = cloudsMainGO.transform;
cloudsTopGO.transform.localScale = Vector3.one * atmo.Size; cloudsTopGO.transform.localScale = Vector3.one * atmo.Size;
cloudsTopGO.name = "TopClouds";
MeshFilter topMF = cloudsTopGO.AddComponent<MeshFilter>(); MeshFilter topMF = cloudsTopGO.AddComponent<MeshFilter>();
topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh; topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
@ -54,6 +52,7 @@ namespace NewHorizons.Builder.Atmosphere
{ {
var mat = new Material(GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials[i]); var mat = new Material(GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials[i]);
if (!atmo.ShadowsOnClouds) mat.renderQueue = 2550; if (!atmo.ShadowsOnClouds) mat.renderQueue = 2550;
mat.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud";
tempArray[i] = mat; tempArray[i] = mat;
} }
topMR.sharedMaterials = tempArray; topMR.sharedMaterials = tempArray;
@ -63,6 +62,7 @@ namespace NewHorizons.Builder.Atmosphere
if (_sphereShader == null) _sphereShader = Main.ShaderBundle.LoadAsset<Shader>("Assets/Shaders/SphereTextureWrapper.shader"); if (_sphereShader == null) _sphereShader = Main.ShaderBundle.LoadAsset<Shader>("Assets/Shaders/SphereTextureWrapper.shader");
topMR.material = new Material(_sphereShader); topMR.material = new Material(_sphereShader);
if (!atmo.ShadowsOnClouds) topMR.material.renderQueue = 2550; if (!atmo.ShadowsOnClouds) topMR.material.renderQueue = 2550;
topMR.material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud";
} }
foreach (var material in topMR.sharedMaterials) foreach (var material in topMR.sharedMaterials)
@ -86,11 +86,10 @@ namespace NewHorizons.Builder.Atmosphere
topRT._degreesPerSecond = 10; topRT._degreesPerSecond = 10;
topRT._randomizeRotationRate = false; topRT._randomizeRotationRate = false;
GameObject cloudsBottomGO = new GameObject(); GameObject cloudsBottomGO = new GameObject("BottomClouds");
cloudsBottomGO.SetActive(false); cloudsBottomGO.SetActive(false);
cloudsBottomGO.transform.parent = cloudsMainGO.transform; cloudsBottomGO.transform.parent = cloudsMainGO.transform;
cloudsBottomGO.transform.localScale = Vector3.one * (atmo.Size * 0.9f); cloudsBottomGO.transform.localScale = Vector3.one * (atmo.Size * 0.9f);
cloudsBottomGO.name = "BottomClouds";
TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent<TessellatedSphereRenderer>(); TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent<TessellatedSphereRenderer>();
bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup; bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
@ -114,11 +113,10 @@ namespace NewHorizons.Builder.Atmosphere
TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent<TessSphereSectorToggle>(); TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent<TessSphereSectorToggle>();
bottomTSST._sector = sector; bottomTSST._sector = sector;
GameObject cloudsFluidGO = new GameObject(); GameObject cloudsFluidGO = new GameObject("CloudsFluid");
cloudsFluidGO.SetActive(false); cloudsFluidGO.SetActive(false);
cloudsFluidGO.layer = 17; cloudsFluidGO.layer = 17;
cloudsFluidGO.transform.parent = cloudsMainGO.transform; cloudsFluidGO.transform.parent = cloudsMainGO.transform;
cloudsFluidGO.name = "CloudsFluid";
SphereCollider fluidSC = cloudsFluidGO.AddComponent<SphereCollider>(); SphereCollider fluidSC = cloudsFluidGO.AddComponent<SphereCollider>();
fluidSC.isTrigger = true; fluidSC.isTrigger = true;

View File

@ -14,7 +14,7 @@ namespace NewHorizons.Builder.Atmosphere
volumesGO.SetActive(false); volumesGO.SetActive(false);
volumesGO.transform.parent = body.transform; volumesGO.transform.parent = body.transform;
GameObject rulesetGO = new GameObject(); GameObject rulesetGO = new GameObject("Ruleset");
rulesetGO.SetActive(false); rulesetGO.SetActive(false);
rulesetGO.transform.parent = volumesGO.transform; rulesetGO.transform.parent = volumesGO.transform;

View File

@ -20,9 +20,10 @@ namespace NewHorizons.Builder.Body
{ {
var belt = parentConfig.AsteroidBelt; var belt = parentConfig.AsteroidBelt;
var minSize = 20; float minSize = belt.MinSize;
var maxSize = 50; float maxSize = belt.MaxSize;
int count = (int)(2f * Mathf.PI * belt.InnerRadius / (10f * maxSize)); int count = (int)(2f * Mathf.PI * belt.InnerRadius / (10f * maxSize));
if (belt.Amount >= 0) count = belt.Amount;
if (count > 200) count = 200; if (count > 200) count = 200;
Random.InitState(belt.RandomSeed); Random.InitState(belt.RandomSeed);

View File

@ -11,7 +11,7 @@ namespace NewHorizons.Builder.Body.Geometry
{ {
static class CubeSphere 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 // It breaks if resolution is greater than 100 I don't know why
if(resolution > 100) if(resolution > 100)
@ -23,15 +23,51 @@ namespace NewHorizons.Builder.Body.Geometry
Mesh mesh = new Mesh(); Mesh mesh = new Mesh();
mesh.name = "CubeSphere"; 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); CreateVertices(mesh, resolution, heightMap, minHeight, maxHeight);
StretchVertices(mesh, stretch);
CreateTriangles(mesh, resolution); CreateTriangles(mesh, resolution);
mesh.RecalculateNormals(); mesh.RecalculateNormals();
mesh.RecalculateBounds();
mesh.RecalculateTangents(); mesh.RecalculateTangents();
return mesh; 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 // Thank you Catlikecoding
private static void CreateVertices(Mesh mesh, int resolution, Texture2D heightMap, float minHeight, float maxHeight) private static void CreateVertices(Mesh mesh, int resolution, Texture2D heightMap, float minHeight, float maxHeight)
{ {

View File

@ -38,7 +38,7 @@ namespace NewHorizons.Builder.Body
cubeSphere.transform.parent = go.transform; cubeSphere.transform.parent = go.transform;
cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0); 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<MeshFilter>(); cubeSphere.AddComponent<MeshFilter>();
cubeSphere.GetComponent<MeshFilter>().mesh = mesh; cubeSphere.GetComponent<MeshFilter>().mesh = mesh;
@ -49,6 +49,7 @@ namespace NewHorizons.Builder.Body
var cubeSphereMR = cubeSphere.AddComponent<MeshRenderer>(); var cubeSphereMR = cubeSphere.AddComponent<MeshRenderer>();
cubeSphereMR.material = new Material(PlanetShader); cubeSphereMR.material = new Material(PlanetShader);
cubeSphereMR.material.name = textureMap.name;
cubeSphereMR.material.mainTexture = textureMap; cubeSphereMR.material.mainTexture = textureMap;
var cubeSphereMC = cubeSphere.AddComponent<MeshCollider>(); var cubeSphereMC = cubeSphere.AddComponent<MeshCollider>();

View File

@ -10,6 +10,9 @@ namespace NewHorizons.External
{ {
public float InnerRadius { get; set; } public float InnerRadius { get; set; }
public float OuterRadius { 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 Inclination { get; set; }
public float LongitudeOfAscendingNode { get; set; } public float LongitudeOfAscendingNode { get; set; }
public int RandomSeed { get; set; } public int RandomSeed { get; set; }

View File

@ -1,8 +1,5 @@
using System; using NewHorizons.Utility;
using System.Collections.Generic; using UnityEngine;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.External namespace NewHorizons.External
{ {
@ -12,5 +9,6 @@ namespace NewHorizons.External
public string TextureMap { get; set; } public string TextureMap { get; set; }
public float MinHeight { get; set; } public float MinHeight { get; set; }
public float MaxHeight { get; set; } public float MaxHeight { get; set; }
public MVector3 Stretch { get; set; } = (MVector3)Vector3.one;
} }
} }

View File

@ -132,6 +132,7 @@ namespace NewHorizons
Logger.Log($"Scene Loaded: {scene.name} {mode}"); Logger.Log($"Scene Loaded: {scene.name} {mode}");
SearchUtilities.ClearCache(); SearchUtilities.ClearCache();
ImageUtilities.ClearCache();
_isChangingStarSystem = false; _isChangingStarSystem = false;

View File

@ -1,5 +1,6 @@
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
@ -10,6 +11,7 @@ namespace NewHorizons.Utility
public static Texture2D MakeOutline(Texture2D texture, Color color, int thickness) public static Texture2D MakeOutline(Texture2D texture, Color color, int thickness)
{ {
var outline = new Texture2D(texture.width, texture.height, TextureFormat.ARGB32, false); 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 outlinePixels = new Color[texture.width * texture.height];
var pixels = texture.GetPixels(); var pixels = texture.GetPixels();
@ -62,6 +64,7 @@ namespace NewHorizons.Utility
} }
var newImage = new Texture2D(image.width, image.height); var newImage = new Texture2D(image.width, image.height);
newImage.name = image.name + "Tinted";
newImage.SetPixels(pixels); newImage.SetPixels(pixels);
newImage.Apply(); newImage.Apply();
return newImage; return newImage;
@ -78,6 +81,7 @@ namespace NewHorizons.Utility
} }
var newImage = new Texture2D(image.width, image.height); var newImage = new Texture2D(image.width, image.height);
newImage.name = image.name + "LerpedGrayscale";
newImage.SetPixels(pixels); newImage.SetPixels(pixels);
newImage.Apply(); newImage.Apply();
return newImage; return newImage;
@ -86,6 +90,7 @@ namespace NewHorizons.Utility
public static Texture2D LoadImage(string filepath) public static Texture2D LoadImage(string filepath)
{ {
Texture2D tex = new Texture2D(2, 2); Texture2D tex = new Texture2D(2, 2);
tex.name = Path.GetFileNameWithoutExtension(filepath);
tex.LoadRawTextureData(File.ReadAllBytes(filepath)); tex.LoadRawTextureData(File.ReadAllBytes(filepath));
return tex; return tex;
} }
@ -93,6 +98,7 @@ namespace NewHorizons.Utility
public static Texture2D ClearTexture(int width, int height) public static Texture2D ClearTexture(int width, int height)
{ {
var tex = (new Texture2D(1, 1, TextureFormat.ARGB32, false)); var tex = (new Texture2D(1, 1, TextureFormat.ARGB32, false));
tex.name = "Clear";
Color fillColor = Color.clear; Color fillColor = Color.clear;
Color[] fillPixels = new Color[tex.width * tex.height]; Color[] fillPixels = new Color[tex.width * tex.height];
for(int i = 0; i < fillPixels.Length; i++) 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) public static Texture2D CanvasScaled(Texture2D src, int width, int height)
{ {
var tex = (new Texture2D(width, height, TextureFormat.ARGB32, false)); var tex = (new Texture2D(width, height, TextureFormat.ARGB32, false));
tex.name = src.name + "CanvasScaled";
Color[] fillPixels = new Color[tex.width * tex.height]; Color[] fillPixels = new Color[tex.width * tex.height];
for (int i = 0; i < tex.width; i++) for (int i = 0; i < tex.width; i++)
{ {
@ -120,16 +127,36 @@ namespace NewHorizons.Utility
return tex; return tex;
} }
private static Dictionary<string, Texture2D> _loadedTextures = new Dictionary<string, Texture2D>();
public static Texture2D GetTexture(IModBehaviour mod, string filename) public static Texture2D GetTexture(IModBehaviour mod, string filename)
{ {
// Copied from OWML but without the print statement lol // Copied from OWML but without the print statement lol
var path = mod.ModHelper.Manifest.ModFolderPath + filename; 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 data = File.ReadAllBytes(path);
var texture = new Texture2D(2, 2); var texture = new Texture2D(2, 2);
texture.name = Path.GetFileNameWithoutExtension(path);
texture.LoadImage(data); texture.LoadImage(data);
_loadedTextures.Add(path, texture);
return texture; return texture;
} }
public static void ClearCache()
{
foreach(var texture in _loadedTextures.Values)
{
if (texture == null) continue;
UnityEngine.Object.Destroy(texture);
}
_loadedTextures.Clear();
}
public static Color GetAverageColor(Texture2D src) public static Color GetAverageColor(Texture2D src)
{ {
var pixels = src.GetPixels32(); var pixels = src.GetPixels32();

View File

@ -439,6 +439,10 @@
"type": "number", "type": "number",
"minimum": 0, "minimum": 0,
"description": "The highest points on your planet will be at this height." "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, "default": 0,
"minimum": 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": { "inclination": {
"$ref": "#/$defs/angle", "$ref": "#/$defs/angle",
"description": "Angle between the rings and the equatorial plane of the planet." "description": "Angle between the rings and the equatorial plane of the planet."
@ -581,6 +603,14 @@
"type": "string", "type": "string",
"description": "Relative filepath to an asset-bundle" "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": { "position": {
"$ref": "#/$defs/vector3" "$ref": "#/$defs/vector3"
}, },