-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9536f8e
commit 38c76fe
Showing
6 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::io::{BinaryStream, SeekFrom, Stream}; | ||
use crate::scene::*; | ||
use crate::SystemInfo; | ||
use grim_traits::scene::*; | ||
use std::collections::HashSet; | ||
use std::error::Error; | ||
use thiserror::Error as ThisError; | ||
|
||
#[derive(Debug, ThisError)] | ||
pub enum CharBoneLoadError { | ||
#[error("CharBone version {version} is not supported")] | ||
CharBoneVersionNotSupported { | ||
version: u32 | ||
}, | ||
} | ||
|
||
fn is_version_supported(version: u32) -> bool { | ||
match version { | ||
2 => true, // GH2 | ||
3 => true, // GH2 360 | ||
8 => true, // TBRB | ||
_ => false | ||
} | ||
} | ||
|
||
impl ObjectReadWrite for CharBone { | ||
fn load(&mut self, stream: &mut dyn Stream, info: &SystemInfo) -> Result<(), Box<dyn Error>> { | ||
let mut reader = Box::new(BinaryStream::from_stream_with_endian(stream, info.endian)); | ||
|
||
let version = reader.read_uint32()?; | ||
if !is_version_supported(version) { | ||
return Err(Box::new(CharBoneLoadError::CharBoneVersionNotSupported { | ||
version | ||
})); | ||
} | ||
|
||
load_object(self, &mut reader, info)?; | ||
load_trans(self, &mut reader, info, false)?; | ||
|
||
//Ok(()) | ||
todo!() | ||
} | ||
|
||
fn save(&self, stream: &mut dyn Stream, info: &SystemInfo) -> Result<(), Box<dyn Error>> { | ||
let mut stream = Box::new(BinaryStream::from_stream_with_endian(stream, info.endian)); | ||
|
||
// TODO: Get version from system info | ||
let version = 3; | ||
|
||
stream.write_uint32(version)?; | ||
|
||
save_object(self, &mut stream, info)?; | ||
save_trans(self, &mut stream, info, false)?; | ||
|
||
stream.write_boolean(self.position)?; | ||
stream.write_boolean(self.scale)?; | ||
|
||
stream.write_uint32(self.rotation as u32)?; | ||
if version < 5 { | ||
stream.write_uint32(RotationConstraint::kRotNone as u32)?; | ||
} | ||
|
||
if version >= 3 { | ||
stream.write_float32(self.unknown)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
mod io; | ||
|
||
use grim_macros::*; | ||
use grim_traits::scene::*; | ||
pub use io::*; | ||
|
||
#[milo(Trans)] | ||
pub struct CharBone { | ||
pub position: bool, | ||
pub scale: bool, | ||
pub rotation: RotationConstraint, | ||
pub unknown: f32, | ||
} | ||
|
||
impl Default for CharBone { | ||
fn default() -> CharBone { | ||
CharBone { | ||
// Base object | ||
name: String::default(), | ||
type2: String::default(), | ||
note: String::default(), | ||
|
||
// Trans object | ||
local_xfm: Matrix::default(), | ||
world_xfm: Matrix::default(), | ||
|
||
trans_objects: Vec::new(), | ||
|
||
constraint: TransConstraint::default(), | ||
target: String::default(), | ||
|
||
preserve_scale: false, | ||
parent: String::default(), | ||
|
||
// CharBone object | ||
position: true, | ||
scale: true, | ||
rotation: RotationConstraint::kRotFull, | ||
unknown: 1.0, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#[allow(non_camel_case_types)] | ||
#[derive(Clone, Copy)] | ||
#[repr(u32)] | ||
pub enum RotationConstraint { | ||
kRotNone = 9, | ||
kRotFull = 2, | ||
kRotX = 3, | ||
kRotY = 4, | ||
kRotZ = 5 | ||
} | ||
|
||
impl From<u32> for RotationConstraint { | ||
fn from(num: u32) -> RotationConstraint { | ||
match num { | ||
9 => RotationConstraint::kRotNone, | ||
2 => RotationConstraint::kRotFull, | ||
3 => RotationConstraint::kRotX, | ||
4 => RotationConstraint::kRotY, | ||
5 => RotationConstraint::kRotZ, | ||
// Default | ||
_ => RotationConstraint::kRotNone, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters