31 lines
916 B
C#
31 lines
916 B
C#
using Godot;
|
|
using IslaApocalypse.Core;
|
|
|
|
namespace IslaApocalypse.Client
|
|
{
|
|
// Notice this inherits from MeshInstance3D, which is Godot's visual 3D node!
|
|
public partial class ChunkRenderer : MeshInstance3D
|
|
{
|
|
public void RenderChunk(ChunkData data)
|
|
{
|
|
// 1. Pass the BlockIDs array to the generator!
|
|
Mesh = MarchingCubes.GenerateMesh(data.Densities, data.BlockIDs, Constants.ISO_LEVEL, Constants.VOXEL_SCALE);
|
|
|
|
|
|
StandardMaterial3D mat = new StandardMaterial3D();
|
|
|
|
// 2. THE FIX: Tell the material to use the colors we paint on the vertices!
|
|
mat.VertexColorUseAsAlbedo = true;
|
|
mat.Roughness = 0.8f;
|
|
mat.CullMode = BaseMaterial3D.CullModeEnum.Disabled;
|
|
|
|
MaterialOverride = mat;
|
|
|
|
Position = new Vector3(
|
|
data.ChunkPosition.X * Constants.CHUNK_SIZE_X * Constants.VOXEL_SCALE,
|
|
0,
|
|
data.ChunkPosition.Y * Constants.CHUNK_SIZE_Z * Constants.VOXEL_SCALE
|
|
);
|
|
}
|
|
}
|
|
}
|