From 36a926d568ee997f27d81dbd623fa0a548e43433 Mon Sep 17 00:00:00 2001 From: PikminGuts92 Date: Tue, 6 Feb 2024 23:10:34 -0500 Subject: [PATCH 1/6] Support devkit wii milos --- core/grim/src/system.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/grim/src/system.rs b/core/grim/src/system.rs index 49eb3ef..cf34b5b 100644 --- a/core/grim/src/system.rs +++ b/core/grim/src/system.rs @@ -53,7 +53,8 @@ impl SystemInfo { let mut endian = IOEndian::Big; let mut version = 25; - if platform == Platform::X360 { + // Devkit wii is little endian for some reason + if platform == Platform::X360 || platform == Platform::Wii { if let Some((end, ver)) = milo.guess_endian_version() { endian = end; version = ver; From d7f2bbd555edf65fb0c25deb76f5c2159b33ca56 Mon Sep 17 00:00:00 2001 From: PikminGuts92 Date: Tue, 6 Feb 2024 23:32:11 -0500 Subject: [PATCH 2/6] Log warning if milo not fully parsed --- apps/cli/scene_tool/Cargo.toml | 1 + apps/cli/scene_tool/src/apps/dir2milo.rs | 4 ++-- apps/cli/scene_tool/src/apps/milo2dir.rs | 2 +- apps/cli/scene_tool/src/main.rs | 19 +++++++++++++++++++ core/grim/src/io/archive.rs | 8 +++++++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/apps/cli/scene_tool/Cargo.toml b/apps/cli/scene_tool/Cargo.toml index 3fb9f44..34b546d 100644 --- a/apps/cli/scene_tool/Cargo.toml +++ b/apps/cli/scene_tool/Cargo.toml @@ -7,6 +7,7 @@ edition.workspace = true [dependencies] clap = { workspace = true } grim = { workspace = true, features = [ "midi" ] } +simplelog = { workspace = true } thiserror = { workspace = true } [lints] diff --git a/apps/cli/scene_tool/src/apps/dir2milo.rs b/apps/cli/scene_tool/src/apps/dir2milo.rs index b08c604..5d37e5f 100644 --- a/apps/cli/scene_tool/src/apps/dir2milo.rs +++ b/apps/cli/scene_tool/src/apps/dir2milo.rs @@ -1,9 +1,9 @@ -use crate::apps::{SubApp}; +use crate::apps::SubApp; use clap::Parser; use std::error::Error; -use std::path::{Path}; +use std::path::Path; use grim::{Platform, SystemInfo}; diff --git a/apps/cli/scene_tool/src/apps/milo2dir.rs b/apps/cli/scene_tool/src/apps/milo2dir.rs index ba49530..9af21ae 100644 --- a/apps/cli/scene_tool/src/apps/milo2dir.rs +++ b/apps/cli/scene_tool/src/apps/milo2dir.rs @@ -9,7 +9,7 @@ use thiserror::Error; use grim::{Platform, SystemInfo}; use grim::io::*; use grim::scene::{Object, ObjectDir, PackedObject, Tex}; -use grim::texture::{write_rgba_to_file}; +use grim::texture::write_rgba_to_file; // TODO: Use this error somewhere or refactor #[derive(Debug, Error)] diff --git a/apps/cli/scene_tool/src/main.rs b/apps/cli/scene_tool/src/main.rs index e54efca..820c2fe 100644 --- a/apps/cli/scene_tool/src/main.rs +++ b/apps/cli/scene_tool/src/main.rs @@ -1,7 +1,26 @@ mod apps; use apps::SceneTool; +use simplelog::*; + +#[cfg(debug_assertions)] +const LOG_LEVEL: LevelFilter = LevelFilter::Debug; + +#[cfg(not(debug_assertions))] +const LOG_LEVEL: LevelFilter = LevelFilter::Info; fn main() -> Result<(), Box> { + let log_config = ConfigBuilder::new() + .add_filter_allow_str("grim") + .add_filter_allow_str("scene_tool") + .build(); + + // Setup logging + CombinedLogger::init( + vec![ + TermLogger::new(LOG_LEVEL, log_config, TerminalMode::Mixed, ColorChoice::Auto), + ] + )?; + let mut scene = SceneTool::new(); scene.run() } \ No newline at end of file diff --git a/core/grim/src/io/archive.rs b/core/grim/src/io/archive.rs index 1ac2259..7319df8 100644 --- a/core/grim/src/io/archive.rs +++ b/core/grim/src/io/archive.rs @@ -1,4 +1,4 @@ -use crate::{SystemInfo}; +use crate::SystemInfo; use crate::io::compression::*; use crate::io::stream::{BinaryStream, IOEndian, MemoryStream, SeekFrom, Stream}; use crate::scene::{Object, ObjectDir, ObjectDirBase, PackedObject}; @@ -156,6 +156,8 @@ impl MiloArchive { pub fn unpack_directory(&self, info: &SystemInfo) -> Result> { let mut stream = self.get_stream(); + let stream_size = stream.len().unwrap() as u64; + let stream = stream.as_mut(); let mut reader = BinaryStream::from_stream_with_endian(stream, info.endian); @@ -258,6 +260,10 @@ impl MiloArchive { } } + if stream.pos() < stream_size { + log::warn!("Read less data than length of milo file. Likely not parsed correctly."); + } + Ok(ObjectDir::ObjectDir(ObjectDirBase { entries: packed_entries .into_iter() From fdeec8ea0df416f3db3e90a5aeb4228e58306cf4 Mon Sep 17 00:00:00 2001 From: PikminGuts92 Date: Tue, 6 Feb 2024 23:39:53 -0500 Subject: [PATCH 3/6] Support 0x4802 wii textures --- core/grim/src/texture/io.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/grim/src/texture/io.rs b/core/grim/src/texture/io.rs index cb3e8ad..e9d21ea 100644 --- a/core/grim/src/texture/io.rs +++ b/core/grim/src/texture/io.rs @@ -174,6 +174,7 @@ impl Bitmap { let tpl_enc = match self.encoding { 72 => TPLEncoding::CMP, 328 => TPLEncoding::CMP_ALPHA, + 584 => TPLEncoding::CMP, // I think it's the same as 72? _ => { return Err(Box::new(BitmapError::UnsupportedEncoding { version: self.encoding, From c3520903f72282dc96e86e7aa6abc8d8173a3d9f Mon Sep 17 00:00:00 2001 From: PikminGuts92 Date: Sun, 18 Feb 2024 19:32:59 -0500 Subject: [PATCH 4/6] Update crates --- Cargo.toml | 13 +++++++------ core/grim/Cargo.toml | 6 +++--- core/grim_macros/Cargo.toml | 6 +++--- utils/anim_preview/Cargo.toml | 4 ++-- utils/lipsync_preview/Cargo.toml | 6 +++--- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bf87795..f706263 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,17 +18,18 @@ authors = ["PikminGuts92"] edition = "2021" [workspace.dependencies] -clap = { version = "4.4.18", features = ["derive"] } +clap = { version = "4.5.1", features = ["derive"] } gltf = { version = "=1.3.0", default-features = false, features = [ "import", "names", "utils" ] } gltf-json = { version = "=1.3.0", features = [ "names" ] } grim = { path = "core/grim" } -itertools = "0.12.0" +itertools = "0.12.1" lazy_static = "1.4.0" log = "0.4.20" -serde = { version = "1.0.195", features = ["derive"] } -serde_json = "1.0.111" -simplelog = "0.12.1" -thiserror = "1.0.56" +serde = { version = "1.0.196", features = ["derive"] } +serde_json = "1.0.113" +# simplelog = "0.12.1" +simplelog = { git = "https://github.com/Drakulix/simplelog.rs", rev = "4ef071d" } +thiserror = "1.0.57" [workspace.lints.rust] dead_code = "allow" diff --git a/core/grim/Cargo.toml b/core/grim/Cargo.toml index 427cf27..459f4b4 100644 --- a/core/grim/Cargo.toml +++ b/core/grim/Cargo.toml @@ -24,8 +24,8 @@ nalgebra = { version = "0.32.3", optional = true } nom = "7.1.3" # pyo3 = { version = "0.17.3", optional = true, features = [ "extension-module" ] } pyo3 = { git = "https://github.com/PyO3/pyo3", branch = "cfg-feature-pyo3", optional = true, features = [ "experimental-inspect", "extension-module" ] } -rayon = "1.8.0" -regex = { version = "1.10.2", default-features = false, features = [ "std" ] } +rayon = "1.8.1" +regex = { version = "1.10.3", default-features = false, features = [ "std" ] } serde = { optional = true, workspace = true } thiserror = { workspace = true } wav = { version = "1.0.0", optional = true } @@ -50,4 +50,4 @@ bench = false crate-type = [ "lib", "cdylib" ] [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/core/grim_macros/Cargo.toml b/core/grim_macros/Cargo.toml index e500b4d..43d90a6 100644 --- a/core/grim_macros/Cargo.toml +++ b/core/grim_macros/Cargo.toml @@ -10,9 +10,9 @@ proc-macro = true [dependencies] grim_traits = { path = "../grim_traits" } lazy_static = { workspace = true } -proc-macro2 = "1.0.76" +proc-macro2 = "1.0.78" quote = "1.0.35" -syn = { version = "2.0.48", default-features = false, features = [ "clone-impls", "derive", "parsing", "printing", "proc-macro" ] } +syn = { version = "2.0.49", default-features = false, features = [ "clone-impls", "derive", "parsing", "printing", "proc-macro" ] } [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/utils/anim_preview/Cargo.toml b/utils/anim_preview/Cargo.toml index 00386a0..ecea464 100644 --- a/utils/anim_preview/Cargo.toml +++ b/utils/anim_preview/Cargo.toml @@ -8,8 +8,8 @@ edition.workspace = true grim = { workspace = true } keyframe = "1.1.1" nalgebra = "0.32.3" -rerun = { version = "0.12.0", features = [ "native_viewer" ] } +rerun = { version = "0.13.0", features = [ "native_viewer" ] } shared = { path = "../shared" } [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/utils/lipsync_preview/Cargo.toml b/utils/lipsync_preview/Cargo.toml index 04b89ba..d28c402 100644 --- a/utils/lipsync_preview/Cargo.toml +++ b/utils/lipsync_preview/Cargo.toml @@ -6,12 +6,12 @@ edition.workspace = true [dependencies] grim = { workspace = true, features = [ "audio" ] } -eframe = "0.25.0" -egui_plot = "0.25.0" +eframe = "0.26.2" +egui_plot = "0.26.2" keyframe = "1.1.1" nalgebra = "0.32.3" #rerun = "0.2.0" shared = { path = "../shared" } [lints] -workspace = true \ No newline at end of file +workspace = true From 40dd809e46390a3c2952affdcc19b5c48857fb03 Mon Sep 17 00:00:00 2001 From: PikminGuts92 Date: Sun, 18 Feb 2024 19:42:08 -0500 Subject: [PATCH 5/6] Update stupid gltf crates --- Cargo.toml | 4 ++-- core/grim/src/model/export.rs | 24 ++++++++++++------------ core/grim_gltf/src/lib.rs | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f706263..8b47468 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ edition = "2021" [workspace.dependencies] clap = { version = "4.5.1", features = ["derive"] } -gltf = { version = "=1.3.0", default-features = false, features = [ "import", "names", "utils" ] } -gltf-json = { version = "=1.3.0", features = [ "names" ] } +gltf = { version = "=1.4.0", default-features = false, features = [ "import", "names", "utils" ] } +gltf-json = { version = "=1.4.0", features = [ "names" ] } grim = { path = "core/grim" } itertools = "0.12.1" lazy_static = "1.4.0" diff --git a/core/grim/src/model/export.rs b/core/grim/src/model/export.rs index 30167bc..8593df5 100644 --- a/core/grim/src/model/export.rs +++ b/core/grim/src/model/export.rs @@ -1065,7 +1065,7 @@ impl GltfExporter { json::Buffer { name: None, - byte_length: total_size as u32, + byte_length: total_size.into(), uri: Some(str_data), extensions: None, extras: Default::default() @@ -1075,9 +1075,9 @@ impl GltfExporter { gltf.buffer_views = vec![ json::buffer::View { name: Some(String::from("verts_norms")), - byte_length: bv_verts_norms as u32, - byte_offset: Some(0), - byte_stride: Some(12), + byte_length: bv_verts_norms.into(), + byte_offset: Some(0u64.into()), + byte_stride: Some(json::buffer::Stride(12)), buffer: json::Index::new(0), target: None, extensions: None, @@ -1085,9 +1085,9 @@ impl GltfExporter { }, json::buffer::View { name: Some(String::from("uvs")), - byte_length: bv_uvs as u32, - byte_offset: Some(bv_verts_norms as u32), - byte_stride: Some(8), + byte_length: bv_uvs.into(), + byte_offset: Some(bv_verts_norms.into()), + byte_stride: Some(json::buffer::Stride(8)), buffer: json::Index::new(0), target: None, extensions: None, @@ -1095,9 +1095,9 @@ impl GltfExporter { }, json::buffer::View { name: Some(String::from("weights_tans")), - byte_length: bv_weights_tans as u32, - byte_offset: Some((bv_verts_norms + bv_uvs) as u32), - byte_stride: Some(16), + byte_length: bv_weights_tans.into(), + byte_offset: Some((bv_verts_norms + bv_uvs).into()), + byte_stride: Some(json::buffer::Stride(16)), buffer: json::Index::new(0), target: None, extensions: None, @@ -1105,8 +1105,8 @@ impl GltfExporter { }, json::buffer::View { name: Some(String::from("faces")), - byte_length: bv_faces as u32, - byte_offset: Some((bv_verts_norms + bv_uvs + bv_weights_tans) as u32), + byte_length: bv_faces.into(), + byte_offset: Some((bv_verts_norms + bv_uvs + bv_weights_tans).into()), byte_stride: None, buffer: json::Index::new(0), target: None, diff --git a/core/grim_gltf/src/lib.rs b/core/grim_gltf/src/lib.rs index 6fc3b42..2ba4971 100644 --- a/core/grim_gltf/src/lib.rs +++ b/core/grim_gltf/src/lib.rs @@ -1,7 +1,7 @@ use gltf_json as json; use itertools::*; use serde::ser::Serialize; -use std::collections::{HashMap}; +use std::collections::HashMap; pub struct AccessorBuilder { // Key = stride, Value = (idx, data) @@ -93,8 +93,8 @@ impl AccessorBuilder { // Create accessor let accessor = json::Accessor { buffer_view: Some(json::Index::new(buff_idx as u32)), - byte_offset: Some(buff_off as u32), - count: count as u32, + byte_offset: Some(buff_off.into()), + count: count.into(), component_type: json::validation::Checked::Valid(json::accessor::GenericComponentType(comp_type)), extensions: None, extras: Default::default(), @@ -139,11 +139,11 @@ impl AccessorBuilder { views.push(json::buffer::View { name: None, - byte_length: data_size as u32, - byte_offset: Some(data_offset as u32), + byte_length: data_size.into(), + byte_offset: Some(data_offset.into()), byte_stride: match stride { 64 => None, // Hacky way to disable writing stride for inverse bind transforms - s if s % 4 == 0 => Some(stride as u32), + s if s % 4 == 0 => Some(json::buffer::Stride(stride)), _ => None // Don't encode if not multiple }, buffer: json::Index::new(0), @@ -163,7 +163,7 @@ impl AccessorBuilder { // Create buffer json let buffer = json::Buffer { name: None, - byte_length: buffer_data.len() as u32, + byte_length: buffer_data.len().into(), uri: match name.into() { s if !s.is_empty() => Some(s), _ => None From 2263335adb9c85fb4590c7ce47d4f1a772b44475 Mon Sep 17 00:00:00 2001 From: PikminGuts92 Date: Sat, 2 Mar 2024 09:57:58 -0500 Subject: [PATCH 6/6] Set platform in system info from arg in p9 tool --- .../p9_scene_tool/src/apps/project2milo.rs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/cli/p9_scene_tool/src/apps/project2milo.rs b/apps/cli/p9_scene_tool/src/apps/project2milo.rs index 3d67b5c..ba80c1e 100644 --- a/apps/cli/p9_scene_tool/src/apps/project2milo.rs +++ b/apps/cli/p9_scene_tool/src/apps/project2milo.rs @@ -66,13 +66,6 @@ impl SubApp for Project2MiloApp { // Create milos files... - // Write everything? - let sys_info = SystemInfo { - version: 25, - platform: Platform::PS3, - endian: IOEndian::Big, - }; - let output_dir = PathBuf::from(&self.output_path); if !output_dir.exists() { // Create outout path if it doesn't exist @@ -80,10 +73,16 @@ impl SubApp for Project2MiloApp { } // Get platform ext - let platform_ext = match self.platform.to_ascii_lowercase().as_str() { - "ps3" => "ps3", - "wii" => "wii", - _ => "xbox" + let (platform, platform_ext) = match self.platform.to_ascii_lowercase().as_str() { + "ps3" => (Platform::PS3, "ps3"), + "wii" => (Platform::Wii, "wii"), + _ => (Platform::X360, "xbox") + }; + + let sys_info = SystemInfo { + version: 25, + platform: platform, + endian: IOEndian::Big, }; // Name, object dir init