islaApocalypse/Client/Scripts/ChunkRenderer.cs
beezm f9ea2da3f4 roads: enable Rugged+Trail carving + per-tier character (D-022)
All four road tiers now carve into the 3D world. Rugged and Trail were
generated, exported and parsed all along, but nothing ever consumed them —
which is why county roads visible on the 2D map did not exist in 3D.

Tier identity is now carried into the carve via a RoadSegment struct, so each
tier gets its own width, shoulder and grade-smoothing from one tunable block in
Constants: highways widest and holding a grade, trails narrow and hugging the
land. Rugged and Trail surface as dirt rather than asphalt.

Because tiers now have different reach, nearest-by-distance was no longer a
sound way to pick the governing road — a nearby footpath could shadow a highway
whose shoulder still covered the column. The carve now considers only roads
whose shoulder actually reaches, and takes the closest of those.

The per-chunk cull pad is derived from the widest shoulder plus a margin, so
widening a road cannot silently truncate it at chunk edges.

Untouched: density field, Marching Cubes interpolation/welding, chunk dims,
the .dat contract, the 2D A* generation, and mesher normals.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 03:53:32 -04:00

35 lines
1.1 KiB
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, plus the per-column
// surface/biome/road data it needs to fade colours smoothly.
Mesh = MarchingCubes.GenerateMesh(
data.Densities, data.BlockIDs,
data.SurfaceHeights, data.ColumnBiomes, data.ColumnRoadMaterial,
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
);
}
}
}