tree dissolve + instances

This commit is contained in:
Jonas H
2026-03-05 15:06:29 +01:00
parent 350fddc2af
commit c37a9fd5dd
7 changed files with 124 additions and 83 deletions

View File

@@ -4,7 +4,7 @@ use glam::Vec2;
use nalgebra::vector;
use rapier3d::prelude::{ColliderBuilder, RigidBodyBuilder};
use crate::components::{MeshComponent, PhysicsComponent};
use crate::components::{MeshComponent, PhysicsComponent, TreeInstancesComponent};
use crate::entity::EntityHandle;
use crate::loaders::mesh::{InstanceData, InstanceRaw, Mesh};
use crate::loaders::terrain::load_heightfield_from_exr;
@@ -78,6 +78,7 @@ impl TerrainBundle
enable_snow_light: true,
},
);
world.names.insert(entity, "Terrain".to_string());
if !physics_added
{
@@ -125,7 +126,7 @@ impl TerrainBundle
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Tree Instance Buffer"),
contents: bytemuck::cast_slice(&instance_raw),
usage: wgpu::BufferUsages::VERTEX,
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
})
});
@@ -135,13 +136,18 @@ impl TerrainBundle
MeshComponent {
mesh: Rc::new(mesh),
pipeline: render::Pipeline::Standard,
instance_buffer: Some(instance_buffer),
instance_buffer: Some(instance_buffer.clone()),
num_instances: num_instances as u32,
tile_scale: 4.0,
enable_dissolve: true,
enable_snow_light: false,
},
);
world.tree_instances.insert(
entity,
TreeInstancesComponent::new(instances, Rc::new(instance_buffer)),
);
world.names.insert(entity, "Trees".to_string());
}
}