mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'unvariant/center_item_drops' into 'master'
Center item drops See merge request veloren/veloren!3232
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -140,7 +140,7 @@ impl Body {
|
|||||||
),
|
),
|
||||||
Body::Armor(kind) => match kind {
|
Body::Armor(kind) => match kind {
|
||||||
ItemDropArmorKind::Neck | ItemDropArmorKind::Back | ItemDropArmorKind::Tabard => {
|
ItemDropArmorKind::Neck | ItemDropArmorKind::Back | ItemDropArmorKind::Tabard => {
|
||||||
default.pitched_down(PI / -2.0)
|
default.yawed_left(random).pitched_down(PI / 2.0)
|
||||||
},
|
},
|
||||||
_ => default.yawed_left(random),
|
_ => default.yawed_left(random),
|
||||||
},
|
},
|
||||||
|
@ -52,7 +52,7 @@ impl ItemDropSkeleton {
|
|||||||
match body {
|
match body {
|
||||||
Body::Tool(_) => 0.8,
|
Body::Tool(_) => 0.8,
|
||||||
Body::Glider => 0.45,
|
Body::Glider => 0.45,
|
||||||
Body::Coins => 0.5,
|
Body::Coins => 0.3,
|
||||||
Body::Armor(kind) => match kind {
|
Body::Armor(kind) => match kind {
|
||||||
ItemDropArmorKind::Neck | ItemDropArmorKind::Ring => 0.5,
|
ItemDropArmorKind::Neck | ItemDropArmorKind::Ring => 0.5,
|
||||||
ItemDropArmorKind::Back => 0.7,
|
ItemDropArmorKind::Back => 0.7,
|
||||||
|
@ -24,7 +24,7 @@ use common::{
|
|||||||
theropod::{self, BodyType as TBodyType, Species as TSpecies},
|
theropod::{self, BodyType as TBodyType, Species as TSpecies},
|
||||||
},
|
},
|
||||||
figure::{Cell, DynaUnionizer, MatCell, MatSegment, Material, Segment},
|
figure::{Cell, DynaUnionizer, MatCell, MatSegment, Material, Segment},
|
||||||
vol::Vox,
|
vol::{IntoFullPosIterator, ReadVol, Vox},
|
||||||
};
|
};
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@ -4902,7 +4902,7 @@ impl ObjectCentralSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct ItemDropCentralSpec(HashMap<ItemKey, (String, [f32; 3], [f32; 3], f32)>);
|
struct ItemDropCentralSpec(HashMap<ItemKey, String>);
|
||||||
|
|
||||||
make_vox_spec!(
|
make_vox_spec!(
|
||||||
item_drop::Body,
|
item_drop::Body,
|
||||||
@ -4933,33 +4933,39 @@ make_vox_spec!(
|
|||||||
|
|
||||||
impl ItemDropCentralSpec {
|
impl ItemDropCentralSpec {
|
||||||
fn mesh_bone0(&self, item_drop: &item_drop::Body, item_key: &ItemKey) -> BoneMeshes {
|
fn mesh_bone0(&self, item_drop: &item_drop::Body, item_key: &ItemKey) -> BoneMeshes {
|
||||||
let coin_pouch = (
|
let coin_pouch = "voxel.object.pouch".to_string();
|
||||||
"voxel.object.pouch".to_string(),
|
|
||||||
[-5.0, -5.0, 0.0],
|
|
||||||
[-10.0, 15.0, 0.0],
|
|
||||||
0.8,
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(spec) = match item_drop {
|
if let Some(spec) = match item_drop {
|
||||||
item_drop::Body::CoinPouch => Some(&coin_pouch),
|
item_drop::Body::CoinPouch => Some(&coin_pouch),
|
||||||
_ => self.0.get(item_key),
|
_ => self.0.get(item_key),
|
||||||
} {
|
} {
|
||||||
let full_spec: String = ["voxygen.", spec.0.as_str()].concat();
|
let full_spec: String = ["voxygen.", spec.as_str()].concat();
|
||||||
(
|
let segment = match item_drop {
|
||||||
match item_drop {
|
item_drop::Body::Armor(_) => {
|
||||||
item_drop::Body::Armor(_) => {
|
MatSegment::from(&graceful_load_vox_fullspec(&full_spec).read().0)
|
||||||
MatSegment::from(&graceful_load_vox_fullspec(&full_spec).read().0)
|
.map(|mat_cell| match mat_cell {
|
||||||
.map(|mat_cell| match mat_cell {
|
MatCell::None => None,
|
||||||
MatCell::None => None,
|
MatCell::Mat(_) => Some(MatCell::None),
|
||||||
MatCell::Mat(_) => Some(MatCell::None),
|
MatCell::Normal(data) => data.is_hollow().then(|| MatCell::None),
|
||||||
MatCell::Normal(data) => data.is_hollow().then(|| MatCell::None),
|
})
|
||||||
})
|
.to_segment(|_| Default::default())
|
||||||
.to_segment(|_| Default::default())
|
|
||||||
},
|
|
||||||
_ => graceful_load_segment_fullspec(&full_spec),
|
|
||||||
},
|
},
|
||||||
Vec3::from(spec.1),
|
_ => graceful_load_segment_fullspec(&full_spec),
|
||||||
)
|
};
|
||||||
|
let offset = segment_center(&segment).unwrap_or_default();
|
||||||
|
(segment, match item_drop {
|
||||||
|
// TODO: apply non-random rotations to items here
|
||||||
|
item_drop::Body::Tool(_) => Vec3::new(offset.x - 2.0, offset.y, offset.z),
|
||||||
|
item_drop::Body::Armor(kind) => match kind {
|
||||||
|
item_drop::ItemDropArmorKind::Neck
|
||||||
|
| item_drop::ItemDropArmorKind::Back
|
||||||
|
| item_drop::ItemDropArmorKind::Tabard => {
|
||||||
|
Vec3::new(offset.x, offset.y - 2.0, offset.z)
|
||||||
|
},
|
||||||
|
_ => offset * Vec3::new(1.0, 1.0, 0.0),
|
||||||
|
},
|
||||||
|
_ => offset * Vec3::new(1.0, 1.0, 0.0),
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
"No specification exists for {:?}, {:?}",
|
"No specification exists for {:?}, {:?}",
|
||||||
@ -4970,6 +4976,38 @@ impl ItemDropCentralSpec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn segment_center(segment: &Segment) -> Option<Vec3<f32>> {
|
||||||
|
let (mut x_min, mut x_max, mut y_min, mut y_max, mut z_min, mut z_max) =
|
||||||
|
(i32::MAX, 0, i32::MAX, 0, i32::MAX, 0);
|
||||||
|
for pos in segment.full_pos_iter() {
|
||||||
|
if let Ok(Cell::Filled(data)) = segment.get(pos) {
|
||||||
|
if !data.is_hollow() {
|
||||||
|
if pos.x < x_min {
|
||||||
|
x_min = pos.x;
|
||||||
|
} else if pos.x > x_max {
|
||||||
|
x_max = pos.x;
|
||||||
|
}
|
||||||
|
if pos.y < y_min {
|
||||||
|
y_min = pos.y;
|
||||||
|
} else if pos.y > y_max {
|
||||||
|
y_max = pos.y;
|
||||||
|
}
|
||||||
|
if pos.z < z_min {
|
||||||
|
z_min = pos.z;
|
||||||
|
} else if pos.z > z_max {
|
||||||
|
z_max = pos.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x_min, x_max, y_min, y_max, z_min, z_max) == (i32::MAX, 0, i32::MAX, 0, i32::MAX, 0) {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(Vec3::new(x_min + x_max, y_min + y_max, z_min + z_max).map(|n| n as f32 / -2.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn mesh_ship_bone<K: fmt::Debug + Eq + Hash, V, F: Fn(&V) -> &ShipCentralSubSpec>(
|
fn mesh_ship_bone<K: fmt::Debug + Eq + Hash, V, F: Fn(&V) -> &ShipCentralSubSpec>(
|
||||||
map: &HashMap<K, V>,
|
map: &HashMap<K, V>,
|
||||||
obj: &K,
|
obj: &K,
|
||||||
|
Reference in New Issue
Block a user