Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Havok shapes for 80809121 (Push Surfaces) #9

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ pub struct SMeshInstanceOcclusionBounds {
#[derive(BinRead, Debug, Clone)]
pub struct Unk80809178 {
// Points to havok pre-tag
pub unk0: RelPointer<Unk80809121>,
pub unk0: RelPointer<SSlipSurfaceVolume>,

pub unk8: u32,
pub unkc: u32,
Expand All @@ -539,15 +539,15 @@ pub struct Unk80809178 {
#[derive(BinRead, Debug, Clone)]
pub struct Unk8080917b {
// Points to havok pre-tag
pub unk0: RelPointer<Unk80809121>,
pub unk0: RelPointer<SSlipSurfaceVolume>,
pub unk8: u32,
pub unkc: u32,
pub kind: u8,
pub unk11: u8,
}

#[derive(BinRead, Debug, Clone)]
pub struct Unk80809121 {
pub struct SSlipSurfaceVolume {
pub unk0: [u32; 4],
pub havok_file: TagHash,
pub unk14: u32,
Expand Down
18 changes: 15 additions & 3 deletions src/map_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum MapResource {
Decoration(AABB, TagHash),
InstantKillBarrier(TagHash, u32, Option<CustomDebugShape>),
TurnbackKillBarrier(TagHash, u32, Option<CustomDebugShape>),
Unk80809121(TagHash),
SlipSurfaceVolume(TagHash, Option<CustomDebugShape>),
Unk808068d4(TagHash),
PlayAreaBounds(TagHash, Option<CustomDebugShape>),
Unk80808246(TagHash, u32, Option<CustomDebugShape>),
Expand Down Expand Up @@ -107,7 +107,16 @@ impl MapResource {
)
}
}
MapResource::Unk80809121(h) => format!("Unk80809121 (havok {h})"),
MapResource::SlipSurfaceVolume(t, s) => {
if s.is_some() {
format!("Slippey Surface Volume (havok {t})")
} else {
format!(
"Slippey Surface Volume (havok {t})\n{} Havok shape visualization failed to load",
ICON_ALERT
)
}
}
MapResource::AmbientSound(s) => {
if let Some(s) = s {
format!(
Expand Down Expand Up @@ -211,6 +220,9 @@ impl MapResource {
1.0,
self.debug_color(),
),
MapResource::SlipSurfaceVolume(_, Some(shape)) => {
debug_shapes.custom_shape(*transform, shape.clone(), self.debug_color(), true);
}
MapResource::InstantKillBarrier(_, _, Some(shape)) => {
debug_shapes.custom_shape(*transform, shape.clone(), self.debug_color(), true);
}
Expand Down Expand Up @@ -349,7 +361,7 @@ mapresource_info!(
9, Unk808085c0, [255, 96, 96], ICON_HELP
10, Unk80806a40, [255, 44, 44], ICON_HELP
11, Decoration, [80, 210, 80], ICON_PINE_TREE
12, Unk80809121, [96, 96, 255], ICON_HELP
12, SlipSurfaceVolume, [96, 96, 255], ICON_HELP
13, Unk808068d4, [22, 230, 190], ICON_WAVES
14, CubemapVolume, [50, 255, 50], ICON_SPHERE
15, NamedArea, [0, 127, 0], ICON_TAG
Expand Down
40 changes: 36 additions & 4 deletions src/mapload_temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
map::SMapDataTable,
map::{
SMeshInstanceOcclusionBounds, SShadowingLight, SimpleLight, Unk808068d4, Unk80806ac2,
Unk80806c98, Unk80806d19, Unk80808246, Unk808085c2, Unk80808604, Unk80808cb7, Unk80809121,
Unk80806c98, Unk80806d19, Unk80808246, Unk808085c2, Unk80808604, Unk80808cb7, SSlipSurfaceVolume,
Unk80809178, Unk8080917b, Unk80809802,
},
render::{cbuffer::ConstantBufferCached, debug::CustomDebugShape, renderer::RendererShared},
Expand Down Expand Up @@ -1592,12 +1592,44 @@ fn load_datatable_into_scene<R: Read + Seek>(
.seek(SeekFrom::Start(data.data_resource.offset))
.unwrap();

let d: Unk80809121 = table_data.read_le()?;
let d: SSlipSurfaceVolume = table_data.read_le()?;

let (havok_debugshape, new_transform) =
if let Ok(havok_data) = package_manager().read_tag(d.havok_file) {
let mut cur = Cursor::new(&havok_data);
match destiny_havok::shape_collection::read_shape_collection(&mut cur) {
Ok(o) => {
if (d.shape_index as usize) < o.len() {
let mut shape = o[d.shape_index as usize].clone();

let center = shape.center();
shape.apply_transform(Mat4::from_translation(-center));

let new_transform = Transform::from_mat4(
transform.to_mat4() * Mat4::from_translation(center),
);

(
CustomDebugShape::from_havok_shape(&dcs, &shape).ok(),
Some(new_transform),
)
} else {
(None, None)
}
}
Err(e) => {
error!("Failed to read shapes: {e}");
(None, None)
}
}
} else {
(None, None)
};

ents.push(scene.spawn((
transform,
new_transform.unwrap_or(transform),
ResourcePoint {
resource: MapResource::Unk80809121(d.havok_file),
resource: MapResource::SlipSurfaceVolume(d.havok_file, havok_debugshape),
has_havok_data: true,
..base_rp
},
Expand Down