From b3a9a275337e7b6d5f02891c152585d38e1f8907 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 21 Jun 2026 10:41:34 +0100 Subject: [PATCH] Remove celestial body Unity physics bake --- .../Scripts/CelestialBodyGenerator.cs | 40 +--------------- .../Celestial Body/Scripts/MeshBaker.cs | 48 ------------------- .../Celestial Body/Scripts/MeshBaker.cs.meta | 11 ----- 3 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 Assets/Plugins/Celestial Body/Scripts/MeshBaker.cs delete mode 100644 Assets/Plugins/Celestial Body/Scripts/MeshBaker.cs.meta diff --git a/Assets/Plugins/Celestial Body/Scripts/CelestialBodyGenerator.cs b/Assets/Plugins/Celestial Body/Scripts/CelestialBodyGenerator.cs index d4a0f66b9..bd2b7dd33 100644 --- a/Assets/Plugins/Celestial Body/Scripts/CelestialBodyGenerator.cs +++ b/Assets/Plugins/Celestial Body/Scripts/CelestialBodyGenerator.cs @@ -5,7 +5,7 @@ using UnityEngine; [ExecuteInEditMode] public class CelestialBodyGenerator : MonoBehaviour { - public enum PreviewMode { LOD0, LOD1, LOD2, CollisionRes } + public enum PreviewMode { LOD0, LOD1, LOD2 } public ResolutionSettings resolutionSettings; public PreviewMode previewMode; @@ -18,7 +18,6 @@ public class CelestialBodyGenerator : MonoBehaviour { // Private variables Mesh previewMesh; - Mesh collisionMesh; Mesh[] lodMeshes; ComputeBuffer vertexBuffer; @@ -68,9 +67,6 @@ public class CelestialBodyGenerator : MonoBehaviour { } } - // Generate collision mesh - GenerateCollisionMesh (resolutionSettings.collider); - // Create terrain renderer and set shading properties on the instanced material terrainMatInstance = new Material (body.shading.terrainMaterial); body.shading.Initialize (body.shape); @@ -78,17 +74,6 @@ public class CelestialBodyGenerator : MonoBehaviour { GameObject terrainHolder = GetOrCreateMeshObject ("Terrain Mesh", null, terrainMatInstance); terrainMeshFilter = terrainHolder.GetComponent (); - // Add collider - MeshCollider collider; - if (!terrainHolder.TryGetComponent (out collider)) { - collider = terrainHolder.AddComponent (); - } - - var collisionBakeTimer = System.Diagnostics.Stopwatch.StartNew (); - MeshBaker.BakeMeshImmediate (collisionMesh); - collider.sharedMesh = collisionMesh; - LogTimer (collisionBakeTimer, "Mesh collider"); - } else { Debug.Log ("Could not generate mesh"); } @@ -254,23 +239,6 @@ public class CelestialBodyGenerator : MonoBehaviour { return new Vector2 (minHeight, maxHeight); } - void GenerateCollisionMesh (int resolution) { - var (vertices, triangles) = CreateSphereVertsAndTris (resolution); - ComputeHelper.CreateStructuredBuffer (ref vertexBuffer, vertices); - - // Set heights - float[] heights = body.shape.CalculateHeights (vertexBuffer); - for (int i = 0; i < vertices.Length; i++) { - float height = heights[i]; - vertices[i] *= height; - } - - // Create mesh - CreateMesh (ref collisionMesh, vertices.Length); - collisionMesh.vertices = vertices; - collisionMesh.triangles = triangles; - } - void CreateMesh (ref Mesh mesh, int numVertices) { const int vertexLimit16Bit = 1 << 16 - 1; // 65535 if (mesh == null) { @@ -324,8 +292,6 @@ public class CelestialBodyGenerator : MonoBehaviour { return resolutionSettings.lod1; case PreviewMode.LOD2: return resolutionSettings.lod2; - case PreviewMode.CollisionRes: - return resolutionSettings.collider; } } @@ -425,7 +391,6 @@ public class CelestialBodyGenerator : MonoBehaviour { public int lod0 = 300; public int lod1 = 100; public int lod2 = 50; - public int collider = 100; public int GetLODResolution (int lodLevel) { switch (lodLevel) { @@ -443,8 +408,7 @@ public class CelestialBodyGenerator : MonoBehaviour { lod0 = Mathf.Min (maxAllowedResolution, lod0); lod1 = Mathf.Min (maxAllowedResolution, lod1); lod2 = Mathf.Min (maxAllowedResolution, lod2); - collider = Mathf.Min (maxAllowedResolution, collider); } } -} \ No newline at end of file +} diff --git a/Assets/Plugins/Celestial Body/Scripts/MeshBaker.cs b/Assets/Plugins/Celestial Body/Scripts/MeshBaker.cs deleted file mode 100644 index 76dde46c4..000000000 --- a/Assets/Plugins/Celestial Body/Scripts/MeshBaker.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using Unity.Collections; -using Unity.Jobs; -using UnityEngine; - -public static class MeshBaker { - - static Dictionary jobsByMesh; - - static MeshBaker () { - jobsByMesh = new Dictionary (); - } - - public static void BakeMeshImmediate (Mesh mesh) { - var job = new BakeJob (mesh.GetInstanceID ()); - JobHandle currentJob = job.Schedule (); - currentJob.Complete (); - } - - public static void StartBakingMesh (Mesh mesh) { - var job = new BakeJob (mesh.GetInstanceID ()); - JobHandle currentJob = job.Schedule (); - jobsByMesh.Add (mesh, currentJob); - } - - public static void EnsureBakingComplete (Mesh mesh) { - if (jobsByMesh.ContainsKey (mesh)) { - jobsByMesh[mesh].Complete (); - jobsByMesh.Remove (mesh); - } else { - BakeMeshImmediate (mesh); - } - } - -} - -public struct BakeJob : IJob { - - int meshID; - public BakeJob (int meshID) { - this.meshID = meshID; - } - - public void Execute () { - Physics.BakeMesh (meshID, false); - } -} \ No newline at end of file diff --git a/Assets/Plugins/Celestial Body/Scripts/MeshBaker.cs.meta b/Assets/Plugins/Celestial Body/Scripts/MeshBaker.cs.meta deleted file mode 100644 index f35e03933..000000000 --- a/Assets/Plugins/Celestial Body/Scripts/MeshBaker.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e6efe2e9f564c464e8b47696ab6a5752 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: