diff --git a/voxygen/src/hud/item_imgs.rs b/voxygen/src/hud/item_imgs.rs index e8a7ca851e..647c91d3ac 100644 --- a/voxygen/src/hud/item_imgs.rs +++ b/voxygen/src/hud/item_imgs.rs @@ -6,6 +6,7 @@ use common::{ tool::{Tool, ToolKind}, Consumable, Ingredient, Item, ItemKind, Utility, }, + figure::Segment, }; use conrod_core::image::Id; use dot_vox::DotVoxData; @@ -49,7 +50,7 @@ impl ImageSpec { match self { ImageSpec::Png(specifier) => Graphic::Image(graceful_load_img(&specifier)), ImageSpec::Vox(specifier) => Graphic::Voxel( - graceful_load_vox(&specifier), + graceful_load_segment_no_skin(&specifier), Transform { stretch: false, ..Default::default() @@ -57,7 +58,7 @@ impl ImageSpec { SampleStrat::None, ), ImageSpec::VoxTrans(specifier, offset, [rot_x, rot_y, rot_z], zoom) => Graphic::Voxel( - graceful_load_vox(&specifier), + graceful_load_segment_no_skin(&specifier), Transform { ori: Quaternion::rotation_x(rot_x * std::f32::consts::PI / 180.0) .rotated_y(rot_y * std::f32::consts::PI / 180.0) @@ -179,3 +180,16 @@ fn graceful_load_img(specifier: &str) -> Arc { }, } } + +fn graceful_load_segment_no_skin(specifier: &str) -> Arc { + use common::figure::{mat_cell::MatCell, MatSegment}; + let mat_seg = MatSegment::from(&*graceful_load_vox(specifier)); + let seg = mat_seg + .map(|mat_cell| match mat_cell { + MatCell::None => None, + MatCell::Mat(_) => Some(MatCell::None), + MatCell::Normal(_) => None, + }) + .to_segment(|_| Rgb::broadcast(255)); + Arc::new(seg) +} diff --git a/voxygen/src/ui/graphic/mod.rs b/voxygen/src/ui/graphic/mod.rs index f1431aff08..acb3aa5be3 100644 --- a/voxygen/src/ui/graphic/mod.rs +++ b/voxygen/src/ui/graphic/mod.rs @@ -4,7 +4,7 @@ mod renderer; pub use renderer::{SampleStrat, Transform}; use crate::render::{Renderer, Texture}; -use dot_vox::DotVoxData; +use common::figure::Segment; use guillotiere::{size2, SimpleAtlasAllocator}; use hashbrown::{hash_map::Entry, HashMap}; use image::{DynamicImage, RgbaImage}; @@ -16,7 +16,8 @@ use vek::*; #[derive(Clone)] pub enum Graphic { Image(Arc), - Voxel(Arc, Transform, SampleStrat), + // Note: none of the users keep this Arc currently + Voxel(Arc, Transform, SampleStrat), Blank, } @@ -292,8 +293,8 @@ fn draw_graphic(graphic_map: &GraphicMap, graphic_id: Id, dims: Vec2) -> Op u32::from(dims.x), u32::from(dims.y), )), - Some(Graphic::Voxel(ref vox, trans, sample_strat)) => Some(renderer::draw_vox( - &vox.as_ref().into(), + Some(Graphic::Voxel(ref segment, trans, sample_strat)) => Some(renderer::draw_vox( + &segment, dims, trans.clone(), *sample_strat, diff --git a/voxygen/src/ui/img_ids.rs b/voxygen/src/ui/img_ids.rs index ea5a8ac294..2e64e904f7 100644 --- a/voxygen/src/ui/img_ids.rs +++ b/voxygen/src/ui/img_ids.rs @@ -1,7 +1,11 @@ use super::{Graphic, SampleStrat, Transform}; -use common::assets::{load, Error}; +use common::{ + assets::{load, Error}, + figure::Segment, +}; use dot_vox::DotVoxData; use image::DynamicImage; +use std::sync::Arc; use vek::*; pub enum BlankGraphic {} @@ -25,17 +29,25 @@ impl<'a> GraphicCreator<'a> for ImageGraphic { } pub enum VoxelGraphic {} +// TODO: Are these uneeded now that we have PixArtGraphic? pub enum VoxelSsGraphic {} pub enum VoxelSs4Graphic {} pub enum VoxelSs9Graphic {} + pub enum VoxelPixArtGraphic {} +fn load_segment(specifier: &str) -> Result, Error> { + let dot_vox = load::(specifier)?; + let seg = dot_vox.as_ref().into(); + Ok(Arc::new(seg)) +} + impl<'a> GraphicCreator<'a> for VoxelGraphic { type Specifier = &'a str; fn new_graphic(specifier: Self::Specifier) -> Result { Ok(Graphic::Voxel( - load::(specifier)?, + load_segment(specifier)?, Transform { ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0), ..Default::default() @@ -49,7 +61,7 @@ impl<'a> GraphicCreator<'a> for VoxelSsGraphic { fn new_graphic(specifier: Self::Specifier) -> Result { Ok(Graphic::Voxel( - load::(specifier.0)?, + load_segment(specifier.0)?, Transform { ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0), ..Default::default() @@ -63,7 +75,7 @@ impl<'a> GraphicCreator<'a> for VoxelSs4Graphic { fn new_graphic(specifier: Self::Specifier) -> Result { Ok(Graphic::Voxel( - load::(specifier)?, + load_segment(specifier)?, Transform { ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0), ..Default::default() @@ -77,7 +89,7 @@ impl<'a> GraphicCreator<'a> for VoxelSs9Graphic { fn new_graphic(specifier: Self::Specifier) -> Result { Ok(Graphic::Voxel( - load::(specifier)?, + load_segment(specifier)?, Transform { ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0), ..Default::default() @@ -91,7 +103,7 @@ impl<'a> GraphicCreator<'a> for VoxelPixArtGraphic { fn new_graphic(specifier: Self::Specifier) -> Result { Ok(Graphic::Voxel( - load::(specifier)?, + load_segment(specifier)?, Transform { ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0), ..Default::default()