Struct VoxFile

Source
pub struct VoxFile {
    pub models: Vec<Model>,
    pub palette: [Color; 256],
    /* private fields */
}
Expand description

Struct which holds all data for a .vox file such as models and palette

Fields§

§models: Vec<Model>§palette: [Color; 256]

Implementations§

Source§

impl VoxFile

Source

pub fn set_palette_color(&mut self, index: u8, r: u8, g: u8, b: u8, a: u8)

sets the color of a index on the palette. The index used can not be 0.

§Example
use create_vox::VoxFile;

let mut vox = VoxFile::new(10, 10, 10);

//sets index 1 to be red
vox.set_palette_color(1, 255, 0, 0, 255);
//sets index 5 to be white
vox.set_palette_color(5, 255, 255, 255, 255);
Source

pub fn add_gradient( &mut self, index1: u8, index2: u8, color1: Color, color2: Color, )

makes a gradient between 2 indexes on the palette

§Example
use create_vox::{VoxFile, Color};

let mut vox = VoxFile::new(10, 10, 10);
let red = Color::new(255, 0, 0 , 255);
let blue = Color::new(0, 0, 255, 255);

vox.add_gradient(1, 50, red, blue);
Source

pub fn reset_palette(&mut self)

resets all colors in palette to grey

§Example
use create_vox::{VoxFile, Color};

let mut vox = VoxFile::new(10, 10, 10);
let red = Color::new(255, 0, 0 , 255);
let blue = Color::new(0, 0, 255, 255);

vox.add_gradient(1, 50, red, blue);
Source

pub fn get_palette_color(&self, index: u8) -> Color

Gets a color from the palette

§Example
use create_vox::{VoxFile, Color};

let mut vox = VoxFile::new(10, 10, 10);
vox.set_palette_color(11, 255, 100, 0, 255);
assert_eq!(Color::new(255, 100, 0, 255), vox.get_palette_color(11));
Source

pub fn set_all_palette_color(&mut self, r: u8, g: u8, b: u8, a: u8)

Like set_palette_color() but sets the color of all indexes on palette

§Example
use create_vox::VoxFile;

let mut vox = VoxFile::new(10, 10, 10);
//sets all indexes on the palette to be red.
vox.set_all_palette_color(255, 0, 0, 255);
Source§

impl VoxFile

Source

pub fn load(path: &str) -> VoxFile

Source§

impl VoxFile

Source

pub fn new(size_x: u16, size_y: u16, size_z: u16) -> VoxFile

creates a new voxfile with one model with the size given.

§Example
use create_vox::VoxFile;

let vox = VoxFile::new(30, 10, 10);
assert_eq!(vox.models[0].size, (30, 10, 10));
Source

pub fn save(&mut self, file_path: &str)

Source

pub fn add_model_copy(&mut self, model_id: i32, x: i32, y: i32, z: i32)

Add a copy of a model at a certain position. The model id is which model in the array of models to use.

§Example
use create_vox::VoxFile;

let mut vox = VoxFile::new(10, 10, 10);
vox.add_model_copy(0, 5, 10, 5);
Source

pub fn add_layer(&mut self, name: String, hidden: bool) -> i32

Creates a new layer and returns the id that it has.

§Example
use create_vox::VoxFile;

let mut vox = VoxFile::new(10, 10, 10);
vox.models[0].layer = Some(vox.add_layer(String::from("my layer"), false));
Source

pub fn change_model_id(&mut self, index: i32, new_id: i32)

Changes the id of a model in the voxfile. If another model already has that id it will panic.

§Example
use create_vox::VoxFile;

let mut vox = VoxFile::new(10, 10, 10);
vox.change_model_id(0, 12);
vox.add_model_copy(12, 20, 20, 20);
Source

pub fn add_model(&mut self, model: Model)

Adds a model and gives it a new id so it does not conflict with other models

§Example
use create_vox::{VoxFile, Model};

let mut vox = VoxFile::new(10, 10, 10);
vox.add_model(Model::new(20, 20, 20));
vox.add_model(Model::new(25,15,10));
assert_eq!(vox.models.len(), 3);

Auto Trait Implementations§

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> 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, 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.