From 5a18364edabfeeab804e84b75a270d8ead857243 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 23 Sep 2020 22:14:31 +0100 Subject: [PATCH] debug stuff --- Marshmallow/Atmosphere/CloudsBuilder.cs | 1 + Marshmallow/General/GravityBuilder.cs | 1 + Marshmallow/General/RFVolumeBuilder.cs | 1 + Marshmallow/Marshmallow.csproj | 2 + Marshmallow/Utility/AddDebugShape.cs | 24 ++++++++++ Marshmallow/Utility/MakeMeshDoubleFaced.cs | 52 ++++++++++++++++++++++ 6 files changed, 81 insertions(+) create mode 100644 Marshmallow/Utility/AddDebugShape.cs create mode 100644 Marshmallow/Utility/MakeMeshDoubleFaced.cs diff --git a/Marshmallow/Atmosphere/CloudsBuilder.cs b/Marshmallow/Atmosphere/CloudsBuilder.cs index 84339b75..dbb735a0 100644 --- a/Marshmallow/Atmosphere/CloudsBuilder.cs +++ b/Marshmallow/Atmosphere/CloudsBuilder.cs @@ -18,6 +18,7 @@ namespace Marshmallow.Atmosphere cloudsTopGO.SetActive(false); cloudsTopGO.transform.parent = cloudsMainGO.transform; cloudsTopGO.transform.localScale = new Vector3(config.TopCloudSize / 2, config.TopCloudSize / 2, config.TopCloudSize / 2); + //AddDebugShape.AddSphere(cloudsTopGO, config.TopCloudSize/2, new Color32(255, 0, 255, 128)); MeshFilter topMF = cloudsTopGO.AddComponent(); topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; diff --git a/Marshmallow/General/GravityBuilder.cs b/Marshmallow/General/GravityBuilder.cs index 8c9ae7fd..9ab7ab1f 100644 --- a/Marshmallow/General/GravityBuilder.cs +++ b/Marshmallow/General/GravityBuilder.cs @@ -19,6 +19,7 @@ namespace Marshmallow.General GV.SetValue("_cutoffAcceleration", 0.1f); GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField("linear").GetValue(GV)); GV.SetValue("_alignmentRadius", 1.5f * upperSurface); + //Utility.AddDebugShape.AddSphere(gravityGO, 1.5f * upperSurface, new Color32(255, 0, 0, 128)); GV.SetValue("_upperSurfaceRadius", upperSurface); GV.SetValue("_lowerSurfaceRadius", lowerSurface); GV.SetValue("_layer", 3); diff --git a/Marshmallow/General/RFVolumeBuilder.cs b/Marshmallow/General/RFVolumeBuilder.cs index 3a4995c1..29f007c9 100644 --- a/Marshmallow/General/RFVolumeBuilder.cs +++ b/Marshmallow/General/RFVolumeBuilder.cs @@ -25,6 +25,7 @@ namespace Marshmallow.General RV.SetValue("_maxTargetDistance", 0); RV.SetValue("_autopilotArrivalDistance", 1000); RV.SetValue("_autoAlignmentDistance", 1000); + //Utility.AddDebugShape.AddSphere(rfGO, 1000, new Color32(0, 255, 0, 128)); RV.SetValue("_hideLandingModePrompt", false); RV.SetValue("_matchAngularVelocity", true); RV.SetValue("_minMatchAngularVelocityDistance", 70); diff --git a/Marshmallow/Marshmallow.csproj b/Marshmallow/Marshmallow.csproj index a069eb6f..2d9e101a 100644 --- a/Marshmallow/Marshmallow.csproj +++ b/Marshmallow/Marshmallow.csproj @@ -96,6 +96,7 @@ + @@ -118,6 +119,7 @@ + diff --git a/Marshmallow/Utility/AddDebugShape.cs b/Marshmallow/Utility/AddDebugShape.cs new file mode 100644 index 00000000..55d9996a --- /dev/null +++ b/Marshmallow/Utility/AddDebugShape.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace Marshmallow.Utility +{ + static class AddDebugShape + { + public static void AddSphere(GameObject obj, float radius, Color color) + { + var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); + sphere.GetComponent().enabled = false; + sphere.transform.parent = obj.transform; + sphere.transform.localScale = new Vector3(radius, radius, radius); + + sphere.GetComponent().material = new Material(Shader.Find("Sprites/Default")); + sphere.GetComponent().material.color = color; + + sphere.AddComponent(); + } + } +} diff --git a/Marshmallow/Utility/MakeMeshDoubleFaced.cs b/Marshmallow/Utility/MakeMeshDoubleFaced.cs new file mode 100644 index 00000000..4834dda5 --- /dev/null +++ b/Marshmallow/Utility/MakeMeshDoubleFaced.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace Marshmallow.Utility +{ + class MakeMeshDoubleFaced : MonoBehaviour + { + private void Start() + { + var mesh = GetComponent().mesh; + var vertices = mesh.vertices; + var uv = mesh.uv; + var normals = mesh.normals; + var szV = vertices.Length; + var newVerts = new Vector3[szV * 2]; + var newUv = new Vector2[szV * 2]; + var newNorms = new Vector3[szV * 2]; + for (var j = 0; j < szV; j++) + { + // duplicate vertices and uvs: + newVerts[j] = newVerts[j + szV] = vertices[j]; + newUv[j] = newUv[j + szV] = uv[j]; + // copy the original normals... + newNorms[j] = normals[j]; + // and revert the new ones + newNorms[j + szV] = -normals[j]; + } + var triangles = mesh.triangles; + var szT = triangles.Length; + var newTris = new int[szT * 2]; // double the triangles + for (var i = 0; i < szT; i += 3) + { + // copy the original triangle + newTris[i] = triangles[i]; + newTris[i + 1] = triangles[i + 1]; + newTris[i + 2] = triangles[i + 2]; + // save the new reversed triangle + var j = i + szT; + newTris[j] = triangles[i] + szV; + newTris[j + 2] = triangles[i + 1] + szV; + newTris[j + 1] = triangles[i + 2] + szV; + } + mesh.vertices = newVerts; + mesh.uv = newUv; + mesh.normals = newNorms; + mesh.triangles = newTris; // assign triangles last! + } + } +}