pub struct Model {
pub size: (u16, u16, u16),
pub position: Option<(i32, i32, i32)>,
pub layer: Option<i32>,
pub name: Option<String>,
/* private fields */
}Expand description
Holds voxel data
Fields§
§size: (u16, u16, u16)§position: Option<(i32, i32, i32)>§layer: Option<i32>§name: Option<String>Implementations§
Source§impl Model
impl Model
Sourcepub fn new(x: u16, y: u16, z: u16) -> Model
pub fn new(x: u16, y: u16, z: u16) -> Model
Creates a new model with the size given
§Example
use create_vox::{VoxFile, Model};
let mut vox = VoxFile::new(5,5,5);
// adds a new model to the voxfile with a size 10 by 10 by 10
vox.models.push(Model::new(10, 10, 10));Sourcepub fn add_voxel(&mut self, new_voxel: Voxel) -> Result<(), &str>
pub fn add_voxel(&mut self, new_voxel: Voxel) -> Result<(), &str>
Adds a voxel to the model. It will return an error if the voxel does not fit inside the model.
§Example
use create_vox::{VoxFile, Voxel};
let mut vox = VoxFile::new(10,10,10);
let voxel = Voxel::new(4, 2, 2, 10);
vox.models[0].add_voxel(voxel);Sourcepub fn clear_voxels(&mut self)
pub fn clear_voxels(&mut self)
Makes the size of the model as small as possible
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(10,10,10);
vox.models[0].add_cube(2, 2, 2, 10, 10, 10, 1);
vox.models[0].clear_voxels();
assert_eq!(0, vox.models[0].num_of_voxels());Sourcepub fn set_size(&mut self, x: u16, y: u16, z: u16)
pub fn set_size(&mut self, x: u16, y: u16, z: u16)
Sets the size of the model. Size must be less than or equal to 256 on all axis.
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(20,20,20);
vox.models[0].set_size(12,6,24);
assert_eq!(vox.models[0].size, (12, 6, 24));Sourcepub fn auto_size(&mut self)
pub fn auto_size(&mut self)
Makes the size of the model as small as possible
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(10,10,10);
vox.models[0].add_cube(2, 2, 2, 6, 7, 6, 1);
vox.models[0].auto_size();Sourcepub fn add_cube(
&mut self,
startx: u8,
starty: u8,
startz: u8,
endx: u8,
endy: u8,
endz: u8,
colorindex: u8,
) -> Result<(), &str>
pub fn add_cube( &mut self, startx: u8, starty: u8, startz: u8, endx: u8, endy: u8, endz: u8, colorindex: u8, ) -> Result<(), &str>
Fills in the area between 2 points with voxels
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(10,10,10);
vox.models[0].add_cube(0, 0, 0, 5, 5, 5, 1);Sourcepub fn is_voxel_at_pos(&self, x: u8, y: u8, z: u8) -> bool
pub fn is_voxel_at_pos(&self, x: u8, y: u8, z: u8) -> bool
Checks if there is a voxel at the position
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(10,10,10);
vox.models[0].add_voxel_at_pos(3,4,3,1);
assert_eq!(true, vox.models[0].is_voxel_at_pos(3, 4, 3));Sourcepub fn add_voxel_at_pos(
&mut self,
x: u8,
y: u8,
z: u8,
voxel_index: u8,
) -> Result<(), &str>
pub fn add_voxel_at_pos( &mut self, x: u8, y: u8, z: u8, voxel_index: u8, ) -> Result<(), &str>
Adds a voxel at certain position
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(50,10,30);
vox.models[0].add_voxel_at_pos(1,1,1,6).unwrap();
vox.models[0].add_voxel_at_pos(1,1,2,5).unwrap();
vox.models[0].add_voxel_at_pos(1,1,3,6).unwrap();
vox.models[0].add_voxel_at_pos(1,1,4,7).unwrap();
vox.models[0].retain_voxels(|voxel| voxel.colorindex == 6);
assert_eq!(2, vox.models[0].num_of_voxels());Sourcepub fn num_of_voxels(&self) -> i32
pub fn num_of_voxels(&self) -> i32
Returns the number of voxels in the model
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(10,10,10);
vox.models[0].add_voxel_at_pos(8,1,1,1).unwrap();
vox.models[0].add_voxel_at_pos(3,3,2,1).unwrap();
vox.models[0].add_voxel_at_pos(6,1,3,2).unwrap();
vox.models[0].add_voxel_at_pos(1,1,4,2).unwrap();
assert_eq!(4, vox.models[0].num_of_voxels());Sourcepub fn retain_voxels<T>(&mut self, closure: T)
pub fn retain_voxels<T>(&mut self, closure: T)
Keeps all of the voxels in the Voxobject that return true with the closure given
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(10,10,10);
vox.models[0].add_voxel_at_pos(1,1,1,6).unwrap();
vox.models[0].add_voxel_at_pos(1,1,2,5).unwrap();
vox.models[0].add_voxel_at_pos(1,1,3,6).unwrap();
vox.models[0].add_voxel_at_pos(1,1,4,7).unwrap();
vox.models[0].retain_voxels(|voxel| voxel.colorindex == 6);
assert_eq!(2, vox.models[0].num_of_voxels());Sourcepub fn change_voxels<T>(&mut self, closure: T)
pub fn change_voxels<T>(&mut self, closure: T)
Changes all the voxels in the Voxobject with the closure
§Example
use create_vox::VoxFile;
let mut vox = VoxFile::new(10, 10, 10);
vox.models[0].add_voxel_at_pos(1,1,1,6).unwrap();
vox.models[0].add_voxel_at_pos(1,1,2,5).unwrap();
vox.models[0].add_voxel_at_pos(1,1,3,6).unwrap();
vox.models[0].add_voxel_at_pos(1,1,4,7).unwrap();
//make all voxels have index 3 on the palette as their color
vox.models[0].change_voxels(|voxel| voxel.colorindex = 3);pub fn get_id(&self) -> i32
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Model
impl RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnwindSafe for Model
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more