Model

Struct Model 

Source
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

Source

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));
Source

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);
Source

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());
Source

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));
Source

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();
Source

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);
Source

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));
Source

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());
Source

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());
Source

pub fn retain_voxels<T>(&mut self, closure: T)
where T: FnMut(&Voxel) -> bool,

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());
Source

pub fn change_voxels<T>(&mut self, closure: T)
where T: FnMut(&mut Voxel),

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);
Source

pub fn get_id(&self) -> i32

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.