islaApocalypse/Client/Scripts/ChunkRenderer.cs
beezm 7f0f43b5fb baseline: working salvaged prototype on Godot 4.7.1 (pre-F1)
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 01:45:41 -04:00

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
);
}
}
}