1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! Neighbor-aware greedy meshing with cross-chunk border culling.
//!
//! The standalone mesher in [`super::greedy`] always emits border faces as
//! visible, which produces single-voxel cracks between adjacent loaded chunks.
//! This module plugs a custom `face_visible` callback into [`super::greedy::build_mesh`]
//! that consults [`super::ChunkNeighbors`] for voxels that cross chunk boundaries.
//!
//! # Culling strategy
//!
//! For each candidate face the callback checks whether the neighbor cell falls
//! inside or outside the current chunk:
//!
//! - **Interior** — the neighbor is within bounds; the standard solid-check
//! (`!super_voxel.is_solid()`) is used, identical to the standalone mesher.
//! - **Border** — the neighbor is outside bounds; the corresponding slot in
//! [`super::ChunkNeighbors::faces`] is consulted. If the slot is `None`
//! (neighbor not loaded), the face is treated as visible. If the slot is
//! `Some`, the voxel at the matching `(u, v)` position in the border slice
//! is checked; the face is culled when that voxel is solid.
//!
//! This approach requires no changes to the greedy merge loop itself — only
//! the face-visibility predicate changes, making it zero-cost for interior faces.
use Mesh;
use crate;
use crateVoxelType;
use ChunkNeighbors;
use ;
/// Generates a seam-free [`Mesh`] for a chunk by culling border faces against
/// adjacent chunk data supplied in `neighbors`.
///
/// This is the preferred meshing entry point for in-world rendering. It
/// produces the same greedy-merged geometry as [`super::generate_chunk_mesh`]
/// but eliminates single-voxel gaps at chunk boundaries by consulting
/// [`ChunkNeighbors`] before emitting any border face.
///
/// # Parameters
///
/// - `chunk` — The [`Chunk<V>`] to mesh.
/// - `neighbors` — Border voxel data for the six adjacent chunks. Slots set
/// to `None` are treated as open air; the corresponding border faces are
/// always emitted. Build this from [`Chunk::border_slice`] on each loaded
/// neighbor or use [`ChunkNeighbors::default`] to treat all borders as air.
/// - `step` — LOD step size. `1` = full detail; `2` = half detail. Use
/// [`super::lod::lod_to_step`] to derive this from a LOD level.
///
/// # Returns
///
/// See [`super::generate_chunk_mesh`] for the full attribute list. The mesh
/// is otherwise identical; only face culling at chunk borders differs.
///
/// # Examples
///
/// ```rust,no_run
/// use voxel_framework::{
/// chunk::Chunk,
/// mesh::{ChunkNeighbors, generate_chunk_mesh_with_neighbors},
/// voxel::DefaultVoxel,
/// };
///
/// let chunk = Chunk::<DefaultVoxel>::new();
/// // All neighbors absent — borders treated as open air.
/// let neighbors = ChunkNeighbors::<DefaultVoxel>::default();
/// let mesh = generate_chunk_mesh_with_neighbors(&chunk, &neighbors, 1);
/// ```
/// Determines whether a face is visible, checking neighbor data at borders.
///
/// For interior voxels, this is equivalent to `!neighbor_voxel.is_solid()`.
/// For border voxels, the neighbor border slice is consulted.
/// Maps a `FaceDir` to its conventional face index (0..6).
/// Computes the index into a `border_slice` array for a given face and
/// local (u, v) coordinates.
///
/// The packing matches `Chunk::border_slice`:
/// - Face 0 (+Y): `x * CHUNK_SIZE + z`
/// - Face 1 (-Y): `x * CHUNK_SIZE + z`
/// - Face 2 (+X): `y * CHUNK_SIZE + z`
/// - Face 3 (-X): `y * CHUNK_SIZE + z`
/// - Face 4 (+Z): `x * CHUNK_SIZE + y`
/// - Face 5 (-Z): `x * CHUNK_SIZE + y`
///
/// The `u_coord` and `v_coord` here are in the FaceDir's tangent-axis space.