diff --git a/common/src/figure/mod.rs b/common/src/figure/mod.rs index e2e7296d76..f23035e615 100644 --- a/common/src/figure/mod.rs +++ b/common/src/figure/mod.rs @@ -20,14 +20,6 @@ use vek::*; /// Figures are used to represent things like characters, NPCs, mobs, etc. pub type Segment = Dyna; -impl From<&DotVoxData> for Segment { - fn from(dot_vox_data: &DotVoxData) -> Self { Segment::from_vox(dot_vox_data, false, 0) } -} - -impl From<(&DotVoxData, usize)> for Segment { - fn from(spec: (&DotVoxData, usize)) -> Self { Segment::from_vox(spec.0, false, spec.1) } -} - impl Segment { /// Take a list of voxel data, offsets, and x-mirror flags, and assembled /// them into a combined segment @@ -39,6 +31,10 @@ impl Segment { union.unify() } + pub fn from_vox_model_index(dot_vox_data: &DotVoxData, model_index: usize) -> Self { + Self::from_vox(dot_vox_data, false, model_index) + } + pub fn from_vox(dot_vox_data: &DotVoxData, flipped: bool, model_index: usize) -> Self { if let Some(model) = dot_vox_data.models.get(model_index) { let palette = dot_vox_data @@ -206,6 +202,10 @@ impl MatSegment { }) } + pub fn from_vox_model_index(dot_vox_data: &DotVoxData, model_index: usize) -> Self { + Self::from_vox(dot_vox_data, false, model_index) + } + pub fn from_vox(dot_vox_data: &DotVoxData, flipped: bool, model_index: usize) -> Self { if let Some(model) = dot_vox_data.models.get(model_index) { let palette = dot_vox_data @@ -266,11 +266,3 @@ impl MatSegment { } } } - -impl From<&DotVoxData> for MatSegment { - fn from(dot_vox_data: &DotVoxData) -> Self { Self::from_vox(dot_vox_data, false, 0) } -} - -impl From<(&DotVoxData, usize)> for MatSegment { - fn from(spec: (&DotVoxData, usize)) -> Self { Self::from_vox(spec.0, false, spec.1) } -} diff --git a/voxygen/src/hud/item_imgs.rs b/voxygen/src/hud/item_imgs.rs index cd8c9fcf36..ef5ab60de5 100644 --- a/voxygen/src/hud/item_imgs.rs +++ b/voxygen/src/hud/item_imgs.rs @@ -167,7 +167,10 @@ fn graceful_load_img(specifier: &str) -> Arc { fn graceful_load_segment_no_skin(specifier: &str, model_index: u32) -> Arc { use common::figure::{mat_cell::MatCell, MatSegment}; - let mat_seg = MatSegment::from((&graceful_load_vox(specifier).read().0, model_index as usize)); + let mat_seg = MatSegment::from_vox_model_index( + &graceful_load_vox(specifier).read().0, + model_index as usize, + ); let seg = mat_seg .map(|mat_cell| match mat_cell { MatCell::None => None, diff --git a/voxygen/src/scene/figure/load.rs b/voxygen/src/scene/figure/load.rs index c8ebebdca1..ecd1d71b6d 100644 --- a/voxygen/src/scene/figure/load.rs +++ b/voxygen/src/scene/figure/load.rs @@ -38,7 +38,10 @@ const DEFAULT_INDEX: u32 = 0; fn load_segment(mesh_name: &str) -> Segment { let full_specifier: String = ["voxygen.voxel.", mesh_name].concat(); - Segment::from(&DotVoxAsset::load_expect(&full_specifier).read().0) + Segment::from_vox_model_index( + &DotVoxAsset::load_expect(&full_specifier).read().0, + DEFAULT_INDEX as usize, + ) } fn graceful_load_vox(mesh_name: &str) -> AssetHandle { let full_specifier: String = ["voxygen.voxel.", mesh_name].concat(); @@ -54,13 +57,13 @@ fn graceful_load_vox_fullspec(full_specifier: &str) -> AssetHandle } } fn graceful_load_segment(mesh_name: &str, model_index: u32) -> Segment { - Segment::from((&graceful_load_vox(mesh_name).read().0, model_index as usize)) + Segment::from_vox_model_index(&graceful_load_vox(mesh_name).read().0, model_index as usize) } fn graceful_load_segment_fullspec(full_specifier: &str, model_index: u32) -> Segment { - Segment::from(( + Segment::from_vox_model_index( &graceful_load_vox_fullspec(full_specifier).read().0, model_index as usize, - )) + ) } fn graceful_load_segment_flipped(mesh_name: &str, flipped: bool, model_index: u32) -> Segment { Segment::from_vox( @@ -70,7 +73,7 @@ fn graceful_load_segment_flipped(mesh_name: &str, flipped: bool, model_index: u3 ) } fn graceful_load_mat_segment(mesh_name: &str, model_index: u32) -> MatSegment { - MatSegment::from((&graceful_load_vox(mesh_name).read().0, model_index as usize)) + MatSegment::from_vox_model_index(&graceful_load_vox(mesh_name).read().0, model_index as usize) } fn graceful_load_mat_segment_flipped(mesh_name: &str, model_index: u32) -> MatSegment { MatSegment::from_vox( @@ -5153,15 +5156,16 @@ impl ItemDropCentralSpec { } { let full_spec: String = ["voxygen.", spec.as_str()].concat(); let segment = match item_drop { - item_drop::Body::Armor(_) => { - MatSegment::from(&graceful_load_vox_fullspec(&full_spec).read().0) - .map(|mat_cell| match mat_cell { - MatCell::None => None, - MatCell::Mat(_) => Some(MatCell::None), - MatCell::Normal(data) => data.is_hollow().then_some(MatCell::None), - }) - .to_segment(|_| Default::default()) - }, + item_drop::Body::Armor(_) => MatSegment::from_vox_model_index( + &graceful_load_vox_fullspec(&full_spec).read().0, + 0, + ) + .map(|mat_cell| match mat_cell { + MatCell::None => None, + MatCell::Mat(_) => Some(MatCell::None), + MatCell::Normal(data) => data.is_hollow().then_some(MatCell::None), + }) + .to_segment(|_| Default::default()), _ => graceful_load_segment_fullspec(&full_spec, DEFAULT_INDEX), }; let offset = segment_center(&segment).unwrap_or_default(); @@ -5234,7 +5238,7 @@ fn mesh_ship_bone &ShipCentralSubSpec }; let bone = f(spec); let central = graceful_load_segment_fullspec( - &["common.voxel.", &bone.central.0].concat(), + &format!("common.voxel.{}", &bone.central.0), bone.model_index, ); diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index 7f7494f74d..8b7c9b0219 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -1977,7 +1977,7 @@ fn default_cache(renderer: &mut Renderer) -> HashMap<&'static str, Model Result, Error> { let dot_vox = DotVoxAsset::load(specifier)?; - let seg = Segment::from(&dot_vox.read().0); + let seg = Segment::from_vox_model_index(&dot_vox.read().0, 0); Ok(Arc::new(seg)) }