realize zesterers proposal

This commit is contained in:
Christof Petig 2023-04-05 00:11:26 +02:00
parent f4a87e9f0b
commit e60aace448
6 changed files with 35 additions and 35 deletions

View File

@ -20,14 +20,6 @@ use vek::*;
/// Figures are used to represent things like characters, NPCs, mobs, etc.
pub type Segment = Dyna<Cell, ()>;
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) }
}

View File

@ -167,7 +167,10 @@ fn graceful_load_img(specifier: &str) -> Arc<DynamicImage> {
fn graceful_load_segment_no_skin(specifier: &str, model_index: u32) -> Arc<Segment> {
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,

View File

@ -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<DotVoxAsset> {
let full_specifier: String = ["voxygen.voxel.", mesh_name].concat();
@ -54,13 +57,13 @@ fn graceful_load_vox_fullspec(full_specifier: &str) -> AssetHandle<DotVoxAsset>
}
}
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<K: fmt::Debug + Eq + Hash, V, F: Fn(&V) -> &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,
);

View File

@ -1977,7 +1977,7 @@ fn default_cache(renderer: &mut Renderer) -> HashMap<&'static str, Model<Particl
let max_size = Vec2::from(u16::try_from(max_texture_size).unwrap_or(u16::MAX));
let mut greedy = GreedyMesh::new(max_size, crate::mesh::greedy::general_config());
let segment = Segment::from(&vox.read().0);
let segment = Segment::from_vox_model_index(&vox.read().0, 0);
let segment_size = segment.size();
let mut mesh = generate_mesh_base_vol_particle(segment, &mut greedy).0;
// Center particle vertices around origin

View File

@ -571,7 +571,8 @@ impl SpriteRenderContext {
// Mesh generation exclusively acts using side effects; it
// has no interesting return value, but updates the mesh.
generate_mesh_base_vol_sprite(
Segment::from(&model.read().0).scaled_by(lod_scale),
Segment::from_vox_model_index(&model.read().0, 0)
.scaled_by(lod_scale),
(greedy, sprite_mesh, false),
offset.map(|e: f32| e.floor()) * lod_scale,
);

View File

@ -37,7 +37,7 @@ pub enum VoxelPixArtGraphic {}
fn load_segment(specifier: &str) -> Result<Arc<Segment>, 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))
}