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
impl VoxFile
Sourcepub fn set_palette_color(&mut self, index: u8, r: u8, g: u8, b: u8, a: u8)
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);
Sourcepub fn add_gradient(
&mut self,
index1: u8,
index2: u8,
color1: Color,
color2: Color,
)
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);
Sourcepub fn reset_palette(&mut self)
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);
Sourcepub fn get_palette_color(&self, index: u8) -> Color
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));
Sourcepub fn set_all_palette_color(&mut self, r: u8, g: u8, b: u8, a: u8)
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
impl VoxFile
Sourcepub fn new(size_x: u16, size_y: u16, size_z: u16) -> VoxFile
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));
pub fn save(&mut self, file_path: &str)
Sourcepub fn add_model_copy(&mut self, model_id: i32, x: i32, y: i32, z: i32)
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);
Sourcepub fn add_layer(&mut self, name: String, hidden: bool) -> i32
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));
Sourcepub fn change_model_id(&mut self, index: i32, new_id: i32)
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);
Sourcepub fn add_model(&mut self, model: Model)
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§
impl Freeze for VoxFile
impl RefUnwindSafe for VoxFile
impl Send for VoxFile
impl Sync for VoxFile
impl Unpin for VoxFile
impl UnwindSafe for VoxFile
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