Make remove skin in armor item images

This commit is contained in:
Imbris 2020-04-05 22:50:27 -04:00 committed by Pfauenauge90
parent 77948d27ca
commit 6c336c015e
3 changed files with 39 additions and 12 deletions

View File

@ -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<DynamicImage> {
},
}
}
fn graceful_load_segment_no_skin(specifier: &str) -> Arc<Segment> {
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)
}

View File

@ -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<DynamicImage>),
Voxel(Arc<DotVoxData>, Transform, SampleStrat),
// Note: none of the users keep this Arc currently
Voxel(Arc<Segment>, Transform, SampleStrat),
Blank,
}
@ -292,8 +293,8 @@ fn draw_graphic(graphic_map: &GraphicMap, graphic_id: Id, dims: Vec2<u16>) -> 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,

View File

@ -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<Arc<Segment>, Error> {
let dot_vox = load::<DotVoxData>(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<Graphic, Error> {
Ok(Graphic::Voxel(
load::<DotVoxData>(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<Graphic, Error> {
Ok(Graphic::Voxel(
load::<DotVoxData>(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<Graphic, Error> {
Ok(Graphic::Voxel(
load::<DotVoxData>(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<Graphic, Error> {
Ok(Graphic::Voxel(
load::<DotVoxData>(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<Graphic, Error> {
Ok(Graphic::Voxel(
load::<DotVoxData>(specifier)?,
load_segment(specifier)?,
Transform {
ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0),
..Default::default()