Flip models for hands, shoulders, and feet of humanoids

This commit is contained in:
Imbris 2020-03-21 18:48:03 -04:00
parent b96d71a8c7
commit f399085974
4 changed files with 83 additions and 102 deletions

View File

@ -1,7 +1,7 @@
({
Bare: (
left: (
vox_spec: ("armor.hand.hand_left_none", (-1.5, -1.5, -7.0)),
vox_spec: ("armor.hand.hand_right_none", (-1.5, -1.5, -7.0)),
color: None
),
right: (
@ -11,7 +11,7 @@
),
Assassin: (
left: (
vox_spec: ("armor.hand.assa_left", (-1.5, -1.5, -7.0)),
vox_spec: ("armor.hand.assa_right", (-1.5, -1.5, -7.0)),
color: None
),
right: (
@ -21,7 +21,7 @@
),
Cloth: (
left: (
vox_spec: ("armor.hand.cloth_basic_left", (-1.5, -1.5, -7.0)),
vox_spec: ("armor.hand.cloth_basic_right", (-1.5, -1.5, -7.0)),
color: None
),
right: (
@ -31,7 +31,7 @@
),
Plate0: (
left: (
vox_spec: ("armor.hand.plate_left-0", (-1.5, -1.5, -7.0)),
vox_spec: ("armor.hand.plate_right-0", (-1.5, -1.5, -7.0)),
color: None
),
right: (
@ -41,7 +41,7 @@
),
Leather0: (
left: (
vox_spec: ("armor.hand.leather_left-0", (-1.5, -1.5, -7.0)),
vox_spec: ("armor.hand.leather_right-0", (-1.5, -1.5, -7.0)),
color: None
),
right: (

View File

@ -12,7 +12,7 @@
),
Brown1: (
left: (
vox_spec: ("armor.shoulder.brown_left", (-3.0, -3.5, 1.0)),
vox_spec: ("armor.shoulder.brown_right", (-3.0, -3.5, 1.0)),
color: None
),
right: (
@ -22,7 +22,7 @@
),
Assassin: (
left: (
vox_spec: ("armor.shoulder.assa_left", (-4.0, -3.5, 1.0)),
vox_spec: ("armor.shoulder.assa_right", (-4.0, -3.5, 1.0)),
color: None
),
right: (
@ -32,7 +32,7 @@
),
Assassin: (
left: (
vox_spec: ("armor.shoulder.assa_left", (-4.0, -3.5, 1.0)),
vox_spec: ("armor.shoulder.assa_right", (-4.0, -3.5, 1.0)),
color: None
),
right: (
@ -42,7 +42,7 @@
),
Chain: (
left: (
vox_spec: ("armor.shoulder.chain_left-1", (-4.0, -3.5, 1.0)),
vox_spec: ("armor.shoulder.chain_right-1", (-4.0, -3.5, 1.0)),
color: None
),
right: (
@ -52,7 +52,7 @@
),
Plate0: (
left: (
vox_spec: ("armor.shoulder.plate_left-0", (-3.6, -3.5, 1.0)),
vox_spec: ("armor.shoulder.plate_right-0", (-3.6, -3.5, 1.0)),
color: None
),
right: (
@ -62,7 +62,7 @@
),
Leather0: (
left: (
vox_spec: ("armor.shoulder.leather_left-0", (-3.2, -3.5, 1.0)),
vox_spec: ("armor.shoulder.leather_right-0", (-3.2, -3.5, 1.0)),
color: None
),
right: (
@ -72,7 +72,7 @@
),
Leather1: (
left: (
vox_spec: ("armor.shoulder.leather_left-1", (-3.6, -4.5, 1.0)),
vox_spec: ("armor.shoulder.leather_right-1", (-3.6, -4.5, 1.0)),
color: None
),
right: (

View File

@ -149,10 +149,8 @@ impl MatSegment {
_ => None,
})
}
}
impl From<&DotVoxData> for MatSegment {
fn from(dot_vox_data: &DotVoxData) -> Self {
pub fn from_vox(dot_vox_data: &DotVoxData, flipped: bool) -> Self {
if let Some(model) = dot_vox_data.models.get(0) {
let palette = dot_vox_data
.palette
@ -186,7 +184,16 @@ impl From<&DotVoxData> for MatSegment {
};
vol.set(
Vec3::new(voxel.x, voxel.y, voxel.z).map(|e| i32::from(e)),
Vec3::new(
if flipped {
model.size.x as u8 - 1 - voxel.x
} else {
voxel.x
},
voxel.y,
voxel.z,
)
.map(|e| i32::from(e)),
block,
)
.unwrap();
@ -198,3 +205,7 @@ impl From<&DotVoxData> for MatSegment {
}
}
}
impl From<&DotVoxData> for MatSegment {
fn from(dot_vox_data: &DotVoxData) -> Self { Self::from_vox(dot_vox_data, false) }
}

View File

@ -21,6 +21,7 @@ use common::{
ItemKind, Loadout,
},
figure::{DynaUnionizer, MatSegment, Material, Segment},
vol::SizedVol,
};
use dot_vox::DotVoxData;
use hashbrown::HashMap;
@ -49,6 +50,9 @@ fn graceful_load_segment(mesh_name: &str) -> Segment {
fn graceful_load_mat_segment(mesh_name: &str) -> MatSegment {
MatSegment::from(graceful_load_vox(mesh_name).as_ref())
}
fn graceful_load_mat_segment_flipped(mesh_name: &str) -> MatSegment {
MatSegment::from_vox(graceful_load_vox(mesh_name).as_ref(), true)
}
fn generate_mesh(segment: &Segment, offset: Vec3<f32>) -> Mesh<FigurePipeline> {
Meshable::<FigurePipeline, FigurePipeline>::generate_mesh(segment, offset).0
@ -302,7 +306,7 @@ impl HumArmorShoulderSpec {
.unwrap()
}
pub fn mesh_left_shoulder(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
fn mesh_shoulder(&self, body: &Body, loadout: &Loadout, flipped: bool) -> Mesh<FigurePipeline> {
let shoulder = if let Some(ItemKind::Armor {
kind: Armor::Shoulder(shoulder),
..
@ -322,42 +326,36 @@ impl HumArmorShoulderSpec {
};
let shoulder_segment = color_segment(
graceful_load_mat_segment(&spec.left.vox_spec.0),
if flipped {
graceful_load_mat_segment_flipped(&spec.left.vox_spec.0)
} else {
graceful_load_mat_segment(&spec.right.vox_spec.0)
},
body.race.skin_color(body.skin),
body.race.hair_color(body.hair_color),
body.race.eye_color(body.eye_color),
);
generate_mesh(&shoulder_segment, Vec3::from(spec.left.vox_spec.1))
// TODO: use this if we can
/*let mut offset = spec.vox_spec.1;
if flipped {
offset[0] = -(shoulder_segment.size().x as f32) - offset[0];
}*/
let offset = if flipped {
spec.left.vox_spec.1
} else {
spec.right.vox_spec.1
};
generate_mesh(&shoulder_segment, Vec3::from(offset))
}
pub fn mesh_left_shoulder(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
self.mesh_shoulder(body, loadout, true)
}
pub fn mesh_right_shoulder(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
let shoulder = if let Some(ItemKind::Armor {
kind: Armor::Shoulder(shoulder),
..
}) = loadout.shoulder.as_ref().map(|i| &i.kind)
{
shoulder
} else {
&Shoulder::None
};
let spec = match self.0.get(&shoulder) {
Some(spec) => spec,
None => {
error!("No shoulder specification exists for {:?}", shoulder);
return load_mesh("not_found", Vec3::new(-2.0, -3.5, 0.1));
},
};
let shoulder_segment = color_segment(
graceful_load_mat_segment(&spec.right.vox_spec.0),
body.race.skin_color(body.skin),
body.race.hair_color(body.hair_color),
body.race.eye_color(body.eye_color),
);
generate_mesh(&shoulder_segment, Vec3::from(spec.right.vox_spec.1))
self.mesh_shoulder(body, loadout, false)
}
}
@ -420,7 +418,7 @@ impl HumArmorHandSpec {
.unwrap()
}
pub fn mesh_left_hand(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
fn mesh_hand(&self, body: &Body, loadout: &Loadout, flipped: bool) -> Mesh<FigurePipeline> {
let hand = if let Some(ItemKind::Armor {
kind: Armor::Hand(hand),
..
@ -440,42 +438,31 @@ impl HumArmorHandSpec {
};
let hand_segment = color_segment(
graceful_load_mat_segment(&spec.left.vox_spec.0),
if flipped {
graceful_load_mat_segment_flipped(&spec.left.vox_spec.0)
} else {
graceful_load_mat_segment(&spec.right.vox_spec.0)
},
body.race.skin_color(body.skin),
body.race.hair_color(body.hair_color),
body.race.eye_color(body.eye_color),
);
generate_mesh(&hand_segment, Vec3::from(spec.left.vox_spec.1))
let offset = if flipped {
spec.left.vox_spec.1
} else {
spec.right.vox_spec.1
};
generate_mesh(&hand_segment, Vec3::from(offset))
}
pub fn mesh_left_hand(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
self.mesh_hand(body, loadout, true)
}
pub fn mesh_right_hand(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
let hand = if let Some(ItemKind::Armor {
kind: Armor::Hand(hand),
..
}) = loadout.hand.as_ref().map(|i| &i.kind)
{
hand
} else {
&Hand::Bare
};
let spec = match self.0.get(&hand) {
Some(spec) => spec,
None => {
error!("No hand specification exists for {:?}", hand);
return load_mesh("not_found", Vec3::new(-1.5, -1.5, -7.0));
},
};
let hand_segment = color_segment(
graceful_load_mat_segment(&spec.right.vox_spec.0),
body.race.skin_color(body.skin),
body.race.hair_color(body.hair_color),
body.race.eye_color(body.eye_color),
);
generate_mesh(&hand_segment, Vec3::from(spec.right.vox_spec.1))
self.mesh_hand(body, loadout, false)
}
}
@ -574,7 +561,7 @@ impl HumArmorFootSpec {
.unwrap()
}
pub fn mesh_left_foot(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
fn mesh_foot(&self, body: &Body, loadout: &Loadout, flipped: bool) -> Mesh<FigurePipeline> {
let foot = if let Some(ItemKind::Armor {
kind: Armor::Foot(foot),
..
@ -594,7 +581,11 @@ impl HumArmorFootSpec {
};
let foot_segment = color_segment(
graceful_load_mat_segment(&spec.vox_spec.0),
if flipped {
graceful_load_mat_segment_flipped(&spec.vox_spec.0)
} else {
graceful_load_mat_segment(&spec.vox_spec.0)
},
body.race.skin_color(body.skin),
body.race.hair_color(body.hair_color),
body.race.eye_color(body.eye_color),
@ -603,33 +594,12 @@ impl HumArmorFootSpec {
generate_mesh(&foot_segment, Vec3::from(spec.vox_spec.1))
}
pub fn mesh_left_foot(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
self.mesh_foot(body, loadout, true)
}
pub fn mesh_right_foot(&self, body: &Body, loadout: &Loadout) -> Mesh<FigurePipeline> {
let foot = if let Some(ItemKind::Armor {
kind: Armor::Foot(foot),
..
}) = loadout.foot.as_ref().map(|i| &i.kind)
{
foot
} else {
&Foot::Bare
};
let spec = match self.0.get(&foot) {
Some(spec) => spec,
None => {
error!("No foot specification exists for {:?}", foot);
return load_mesh("not_found", Vec3::new(-2.5, -3.5, -9.0));
},
};
let foot_segment = color_segment(
graceful_load_mat_segment(&spec.vox_spec.0),
body.race.skin_color(body.skin),
body.race.hair_color(body.hair_color),
body.race.eye_color(body.eye_color),
);
generate_mesh(&foot_segment, Vec3::from(spec.vox_spec.1))
self.mesh_foot(body, loadout, false)
}
}