mirror of
https://github.com/eliasstepanik/voxel-simulation.git
synced 2026-01-10 21:38:29 +00:00
Merge pull request #13 from eliasstepanik/codex/verify-chunk-mesh-visibility-logic
Fix empty chunk meshes
This commit is contained in:
commit
208da2dffa
@ -304,7 +304,7 @@ pub(crate) fn mesh_chunk(
|
||||
origin: Vec3,
|
||||
step: f32,
|
||||
tree: &SparseVoxelOctree,
|
||||
) -> Mesh {
|
||||
) -> Option<Mesh> {
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
// Helpers
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
@ -462,6 +462,10 @@ pub(crate) fn mesh_chunk(
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
// Final mesh assembly
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
if indices.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::default());
|
||||
mesh.insert_attribute(
|
||||
Mesh::ATTRIBUTE_POSITION,
|
||||
@ -476,5 +480,5 @@ pub(crate) fn mesh_chunk(
|
||||
VertexAttributeValues::Float32x2(uvs),
|
||||
);
|
||||
mesh.insert_indices(Indices::U32(indices));
|
||||
mesh
|
||||
Some(mesh)
|
||||
}
|
||||
|
||||
@ -85,13 +85,22 @@ pub fn rebuild_dirty_chunks(
|
||||
for (key, buf, origin, step, lod) in bufs {
|
||||
if let Some((ent, mesh_h, _mat_h, _)) = existing.get(&key).cloned() {
|
||||
// update mesh in-place; keeps old asset id
|
||||
if let Some(mesh) = meshes.get_mut(&mesh_h) {
|
||||
*mesh = mesh_chunk(&buf, origin, step, &tree);
|
||||
match mesh_chunk(&buf, origin, step, &tree) {
|
||||
Some(new_mesh) => {
|
||||
if let Some(mesh) = meshes.get_mut(&mesh_h) {
|
||||
*mesh = new_mesh;
|
||||
}
|
||||
spawned.0.insert(key, ent);
|
||||
}
|
||||
None => {
|
||||
meshes.remove(&mesh_h);
|
||||
commands.entity(ent).despawn_recursive();
|
||||
spawned.0.remove(&key);
|
||||
}
|
||||
}
|
||||
spawned.0.insert(key, ent);
|
||||
} else {
|
||||
// spawn brand-new chunk
|
||||
let mesh_h = meshes.add(mesh_chunk(&buf, origin, step, &tree));
|
||||
} else if let Some(mesh) = mesh_chunk(&buf, origin, step, &tree) {
|
||||
// spawn brand-new chunk only if mesh has faces
|
||||
let mesh_h = meshes.add(mesh);
|
||||
let mat_h = materials.add(StandardMaterial::default());
|
||||
|
||||
commands.entity(root.0).with_children(|p| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user