Extract mesh and occluder generation to methods

This commit is contained in:
Jarrod Doyle 2024-08-03 17:16:28 +01:00
parent 91bddd5c12
commit 5dceedeaf1
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 25 additions and 15 deletions

View File

@ -191,15 +191,36 @@ public partial class Mission : Node3D
} }
} }
var cellNode = new Node3D();
var material = new StandardMaterial3D var material = new StandardMaterial3D
{ {
AlbedoTexture = ImageTexture.CreateFromImage(image), AlbedoTexture = ImageTexture.CreateFromImage(image),
TextureFilter = BaseMaterial3D.TextureFilterEnum.Nearest, 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<Vector3> vertices, List<int> 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<Vector3> vertices, List<Vector3> normals, List<int> indices, List<Vector2> lightmapUvs, StandardMaterial3D material)
{
var arrMesh = new ArrayMesh(); var arrMesh = new ArrayMesh();
var arrays = new Godot.Collections.Array(); var arrays = new Godot.Collections.Array();
arrays.Resize((int)Mesh.ArrayType.Max); arrays.Resize((int)Mesh.ArrayType.Max);
@ -216,18 +237,7 @@ public partial class Mission : Node3D
Mesh = arrMesh, Mesh = arrMesh,
CastShadow = GeometryInstance3D.ShadowCastingSetting.On CastShadow = GeometryInstance3D.ShadowCastingSetting.On
}; };
cellNode.AddChild(meshInstance); return 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);
} }
private static int[] CalcBaseUV( private static int[] CalcBaseUV(