From 5dceedeaf1fcd6f1dd5b350f5d89c08cdb5743e2 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 3 Aug 2024 17:16:28 +0100 Subject: [PATCH] Extract mesh and occluder generation to methods --- project/code/Mission.cs | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/project/code/Mission.cs b/project/code/Mission.cs index 6be5ee5..edb132c 100644 --- a/project/code/Mission.cs +++ b/project/code/Mission.cs @@ -191,15 +191,36 @@ public partial class Mission : Node3D } } - - var cellNode = new Node3D(); - var material = new StandardMaterial3D { AlbedoTexture = ImageTexture.CreateFromImage(image), TextureFilter = BaseMaterial3D.TextureFilterEnum.Nearest, }; + MeshInstance3D mesh = GenerateMesh(vertices, normals, indices, lightmapUvs, material); + OccluderInstance3D occluderInstance = GenerateOccluder(vertices, indices); + + var cellNode = new Node3D(); + cellNode.AddChild(mesh); + cellNode.AddChild(occluderInstance); + + AddChild(cellNode); + } + + private static OccluderInstance3D GenerateOccluder(List vertices, List indices) + { + var occluder = new ArrayOccluder3D(); + occluder.SetArrays(vertices.ToArray(), indices.ToArray()); + var occluderInstance = new OccluderInstance3D + { + Occluder = occluder, + BakeSimplificationDistance = 0.0f + }; + return occluderInstance; + } + + private static MeshInstance3D GenerateMesh(List vertices, List normals, List indices, List lightmapUvs, StandardMaterial3D material) + { var arrMesh = new ArrayMesh(); var arrays = new Godot.Collections.Array(); arrays.Resize((int)Mesh.ArrayType.Max); @@ -216,18 +237,7 @@ public partial class Mission : Node3D Mesh = arrMesh, CastShadow = GeometryInstance3D.ShadowCastingSetting.On }; - cellNode.AddChild(meshInstance); - - var occluder = new ArrayOccluder3D(); - occluder.SetArrays(vertices.ToArray(), indices.ToArray()); - var occluderInstance = new OccluderInstance3D - { - Occluder = occluder, - BakeSimplificationDistance = 0.0f - }; - cellNode.AddChild(occluderInstance); - - AddChild(cellNode); + return meshInstance; } private static int[] CalcBaseUV(