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§

source

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 the VoxelModel to be modified (you can obtain this by from the [bevy::asset::Handle::id()] method).
  • region - a VoxelRegion defining the area of the voxel model that the modifier will operate on.
  • modify - a closure that will run against every voxel within the region.
§Arguments passed to the modify closure
  • position - the position of the current voxel, in voxel space
  • voxel - the index of the current voxel
  • model - a reference to the model, allowing, for instance, querying neighbouring voxels via the methods in crate::VoxelQueryable
§Notes

The smaller the region is, the more performant the operation will be.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl ModifyVoxelCommandsExt for Commands<'_, '_>

source§

fn modify_voxel_model<F: Fn(IVec3, &Voxel, &dyn VoxelQueryable) -> Voxel + Send + Sync + 'static>( &mut self, model: VoxelModelInstance, region: VoxelRegionMode, modify: F ) -> &mut Self

Implementors§