Skip to content

Commit

Permalink
lots of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anarelion committed Dec 30, 2023
1 parent 54310c3 commit fdb1ad7
Show file tree
Hide file tree
Showing 20 changed files with 465 additions and 248 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
bitbybit = "1.2"
bytes = "1.0"
compress = "0.2"
glam = "0.24"
lazy_static = "1.4"
thiserror = "1.0"
tracing = "0.1"
40 changes: 20 additions & 20 deletions src/wld/fragments/mod.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
mod t16_skeleton;
mod t17_skeleton_ref;
mod t18_track_def;
mod t19_track;
mod t16_skeleton_track_set;
mod t17_skeleton_track_set_ref;
mod t18_skeleton_piece_track_def;
mod t19_skeleton_piece_track;
mod t20_model;
mod t3_texture_name;
mod t45_dm_sprite_ref;
mod t48_material;
mod t49_material_list;
mod t4_texture;
mod t3_texture_bitmap_name;
mod t45_mesh_ref;
mod t48_texture;
mod t49_texture_list;
mod t4_texture_bitmap_info;
mod t54_mesh;
mod t5_texture_list_wrapper;
mod t5_texture_bitmap_info_ref;

use std::sync::Arc;

pub use t16_skeleton::WldSkeleton;
pub use t17_skeleton_ref::WldSkeletonRef;
pub use t18_track_def::WldTrackDef;
pub use t19_track::WldTrack;
pub use t16_skeleton_track_set::WldSkeletonTrackSet;
pub use t17_skeleton_track_set_ref::WldSkeletonTrackSetRef;
pub use t18_skeleton_piece_track_def::WldSkeletonPieceTrackDef;
pub use t19_skeleton_piece_track::WldSkeletonPieceTrack;
pub use t20_model::WldModel;
pub use t3_texture_name::WldTextureFilename;
pub use t45_dm_sprite_ref::WldDmSpriteRef;
pub use t48_material::WldMaterial;
pub use t49_material_list::WldMaterialList;
pub use t4_texture::WldTextureList;
pub use t3_texture_bitmap_name::WldTextureBitmapName;
pub use t45_mesh_ref::WldMeshRef;
pub use t48_texture::WldTexture;
pub use t49_texture_list::WldMaterialList;
pub use t4_texture_bitmap_info::WldTextureBitmapInfo;
pub use t54_mesh::WldMesh;
pub use t5_texture_list_wrapper::WldTextureRef;
pub use t5_texture_bitmap_info_ref::WldTextureBitmapInfoRef;

use crate::Decoder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ use bytes::{Buf, Bytes};
use std::fmt::{Debug, Formatter};
use std::sync::Arc;

use crate::Decoder;
use crate::{utils::count, Settings};
use crate::{Decoder, WldFragment};

#[derive(Clone, Debug)]
pub struct WldSkeleton {
pub struct WldSkeletonTrackSet {
pub name: Option<String>,
pub flags: WldSkeletonFlags,
pub num_dags: u32,
pub collision_volume_reference: u32,
pub polygon_animation_reference: u32,
pub centre_offset: Option<(u32, u32, u32)>,
pub bounding_radius: Option<f32>,
pub dags: Vec<WldSkeletonDag>,
pub num_attached_skins: Option<u32>,
pub mesh_reference_count: Option<u32>,
pub dm_sprites: Vec<u32>,
pub link_skin_updates_to_dag_index: Vec<u32>,
}
Expand All @@ -27,7 +27,7 @@ pub struct WldSkeletonFlags {
#[bit(1, r)]
pub has_bounding_radius: bool, // 0x02
#[bit(9, r)]
pub unknown: bool, // 0x200
pub has_mesh_references: bool, // 0x200
}

#[derive(Clone, Debug)]
Expand All @@ -38,57 +38,64 @@ pub struct WldSkeletonDag {
pub mesh_or_sprite_ref: u32,
pub num_sub_dags: u32,
pub sub_dags: Vec<u32>,
pub parent: Option<u32>,
}

impl Decoder<Settings> for WldSkeleton {
impl WldFragment for WldSkeletonTrackSet {
const TYPE: u32 = 16;
}

impl Decoder<Settings> for WldSkeletonTrackSet {
fn new(input: &mut Bytes, settings: Arc<Settings>) -> Result<Self, crate::EQFilesError>
where
Self: Sized,
{
let name = settings.get_name().clone();
let flags = WldSkeletonFlags::new_with_raw_value(input.get_u32_le());
let num_dags = input.get_u32_le();
let collision_volume_reference = input.get_u32_le();
let centre_offset = if flags.has_center_offset() {
Some((input.get_u32_le(), input.get_u32_le(), input.get_u32_le()))
} else {
None
};
let bounding_radius = if flags.has_bounding_radius() {
Some(input.get_f32_le())
} else {
None
};
let polygon_animation_reference = input.get_u32_le();
let centre_offset = flags
.has_center_offset()
.then(|| (input.get_u32_le(), input.get_u32_le(), input.get_u32_le()));
let bounding_radius = flags.has_bounding_radius().then(|| input.get_f32_le());

let dags = count(input, num_dags as usize, settings, WldSkeletonDag::new)?;
let mut dags = count(input, num_dags as usize, settings, WldSkeletonDag::new)?;

let num_attached_skins = if flags.unknown() {
Some(input.get_u32_le())
} else {
None
};
let mesh_reference_count = flags.has_mesh_references().then(|| input.get_u32_le());

let mut dm_sprites = Vec::new();
let mut link_skin_updates_to_dag_index = Vec::new();
if num_attached_skins.is_some() {
for _ in 0..num_attached_skins.unwrap() {
if mesh_reference_count.is_some() {
for _ in 0..mesh_reference_count.unwrap() {
dm_sprites.push(input.get_u32_le());
}

for _ in 0..num_attached_skins.unwrap() {
for _ in 0..mesh_reference_count.unwrap() {
link_skin_updates_to_dag_index.push(input.get_u32_le());
}
}

for index in 0..dags.len() {
let subs = {
let dag = dags.get(index).unwrap();
dag.sub_dags.clone()
};

for sub in &subs {
let sb = dags.get_mut(*sub as usize).unwrap();
sb.parent = Some(index as u32);
}
};

Ok(Self {
name,
flags,
num_dags,
collision_volume_reference,
polygon_animation_reference,
centre_offset,
bounding_radius,
dags,
num_attached_skins,
mesh_reference_count,
dm_sprites,
link_skin_updates_to_dag_index,
})
Expand Down Expand Up @@ -119,6 +126,7 @@ impl Decoder<Settings> for WldSkeletonDag {
mesh_or_sprite_ref,
num_sub_dags,
sub_dags,
parent: None,
})
}
}
Expand All @@ -128,7 +136,7 @@ impl Debug for WldSkeletonFlags {
f.debug_struct("WldSkeletonFlags")
.field("has_center_offset", &self.has_center_offset())
.field("has_bounding_radius", &self.has_bounding_radius())
.field("unknown", &self.unknown())
.field("has_mesh_references", &self.has_mesh_references())
.finish()
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
use std::sync::Arc;

use bytes::{Buf, Bytes};
use tracing::info;

use crate::Decoder;
use crate::{Decoder, WldFragment};
use crate::Settings;

#[derive(Clone, Debug)]
pub struct WldSkeletonRef {
pub struct WldSkeletonTrackSetRef {
pub name_ref: i32,
pub name: Option<String>,
pub reference: u32,
pub params1: u32,
}

impl Decoder<Settings> for WldSkeletonRef {
impl WldFragment for WldSkeletonTrackSetRef {
const TYPE: u32 = 17;
}

impl Decoder<Settings> for WldSkeletonTrackSetRef {
fn new(input: &mut Bytes, settings: Arc<Settings>) -> Result<Self, crate::EQFilesError>
where
Self: Sized,
{
let reference = input.get_u32_le();
let params1 = input.get_u32_le();

info!("Remaining t17: {:?}", input);

Ok(Self {
name_ref: settings.get_name_ref(),
name: settings.get_name(),
Expand Down
75 changes: 75 additions & 0 deletions src/wld/fragments/t18_skeleton_piece_track_def.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::sync::Arc;

use bytes::{Buf, Bytes};

use crate::{Decoder, Settings, WldFragment};

#[derive(Clone, Debug)]
pub struct WldSkeletonPieceTrackDef {
pub name_ref: i32,
pub name: Option<String>,
pub flags: u32,
pub frames: Vec<WldSkeletonPieceTrackFrameTransform>,
pub remainder: Bytes,
}

impl WldFragment for WldSkeletonPieceTrackDef {
const TYPE: u32 = 18;
}

impl Decoder<Settings> for WldSkeletonPieceTrackDef {
fn new(input: &mut Bytes, settings: Arc<Settings>) -> Result<Self, crate::EQFilesError>
where
Self: Sized,
{
let name_ref = settings.get_name_ref();
let name = settings.get_name();
let flags = input.get_u32_le(); // bit 3 means more values
let frame_count = input.get_u32_le();
let mut frames = Vec::new();
for _ in 0..frame_count {
let rotation_denominator = input.get_i16_le();
let rotation_x = input.get_i16_le();
let rotation_y = input.get_i16_le();
let rotation_z = input.get_i16_le();
let shift_x = input.get_i16_le();
let shift_y = input.get_i16_le();
let shift_z = input.get_i16_le();
let shift_denominator = input.get_i16_le();
let mut frame_transform = if shift_denominator != 0 {
WldSkeletonPieceTrackFrameTransform {
translation: glam::vec3(
shift_x as f32 / 256f32,
shift_y as f32 / 256f32,
shift_z as f32 / 256f32,
),
scale: shift_denominator as f32 / 256f32,
..Default::default()
}
} else {
WldSkeletonPieceTrackFrameTransform {
translation: glam::vec3(0.0, 0.0, 0.0),
..Default::default()
}
};
frame_transform.rotation = glam::quat(rotation_x as f32, rotation_y as f32, rotation_z as f32, rotation_denominator as f32).normalize();
frames.push(frame_transform);
}

Ok(Self {
name_ref,
name,
flags,
frames,
remainder: input.clone(),
})
}
}

#[derive(Clone, Debug, Default)]
pub struct WldSkeletonPieceTrackFrameTransform {
pub translation: glam::Vec3,
pub rotation: glam::Quat,
pub scale: f32,
pub model_matrix: glam::Mat4,
}
25 changes: 0 additions & 25 deletions src/wld/fragments/t18_track_def.rs

This file was deleted.

Loading

0 comments on commit fdb1ad7

Please sign in to comment.