pub trait ModifyVoxelCommandsExt {
// Required method
fn modify_voxel_model<F: Fn(IVec3, &Voxel, &dyn VoxelQueryable) -> Voxel + Send + Sync + 'static>(
&mut self,
model: VoxelModelInstance,
region: VoxelRegionMode,
modify: F
) -> &mut Self;
}
Expand description
Command that programatically modifies the voxels in a model.
This command will run the closure against every voxel within the region of the model.
§Example
// cut a sphere-shaped hole out of the loaded model
let sphere_center = IVec3::new(10, 10, 10);
let radius = 10;
let radius_squared = radius * radius;
let region = VoxelRegion {
origin: sphere_center - IVec3::splat(radius),
size: IVec3::splat(1 + (radius * 2)),
};
commands.modify_voxel_model(
model_instance.clone(),
VoxelRegionMode::Box(region),
move | position, voxel, model | {
// a signed-distance function for a sphere:
if position.distance_squared(sphere_center) <= radius_squared {
// inside of the sphere, return an empty cell
Voxel::EMPTY
} else {
// outside the sphere, return the underlying voxel value from the model
voxel.clone()
}
},
);
Required Methods§
sourcefn modify_voxel_model<F: Fn(IVec3, &Voxel, &dyn VoxelQueryable) -> Voxel + Send + Sync + 'static>(
&mut self,
model: VoxelModelInstance,
region: VoxelRegionMode,
modify: F
) -> &mut Self
fn modify_voxel_model<F: Fn(IVec3, &Voxel, &dyn VoxelQueryable) -> Voxel + Send + Sync + 'static>( &mut self, model: VoxelModelInstance, region: VoxelRegionMode, modify: F ) -> &mut Self
Run the modify
closure against every voxel within the region
of the model
.
§Arguments
model
- the id of theVoxelModel
to be modified (you can obtain this by from the [bevy::asset::Handle::id()
] method).region
- aVoxelRegion
defining the area of the voxel model that the modifier will operate on.modify
- a closure that will run against every voxel within theregion
.
§Arguments passed to the modify
closure
position
- the position of the current voxel, in voxel spacevoxel
- the index of the current voxelmodel
- a reference to the model, allowing, for instance, querying neighbouring voxels via the methods incrate::VoxelQueryable
§Notes
The smaller the region
is, the more performant the operation will be.
Object Safety§
This trait is not object safe.