summaryrefslogtreecommitdiff
path: root/world/src/main.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-02-25 21:48:49 +0100
committermetamuffin <metamuffin@disroot.org>2025-02-25 21:48:49 +0100
commit6df8b23ffc7ff248dc9fe5d3d8c4ee60abbab022 (patch)
treef3cf01eeb6276361be4b3524a3eab563a15e1dfe /world/src/main.rs
parente642e804f6309796117a4f823a42eb8f49d12809 (diff)
downloadweareserver-6df8b23ffc7ff248dc9fe5d3d8c4ee60abbab022.tar
weareserver-6df8b23ffc7ff248dc9fe5d3d8c4ee60abbab022.tar.bz2
weareserver-6df8b23ffc7ff248dc9fe5d3d8c4ee60abbab022.tar.zst
more options to attempt animation transfer
Diffstat (limited to 'world/src/main.rs')
-rw-r--r--world/src/main.rs39
1 files changed, 30 insertions, 9 deletions
diff --git a/world/src/main.rs b/world/src/main.rs
index 14a4477..695b4aa 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -24,6 +24,7 @@ pub mod vrm;
use animation::import_animation;
use anyhow::{Context, Result, anyhow};
use clap::Parser;
+use glam::Vec3;
use gltf::{Gltf, Node, image::Source, import_buffers, scene::Transform};
use humansize::BINARY;
use image::{ImageReader, codecs::webp::WebPEncoder};
@@ -99,6 +100,12 @@ pub struct Args {
animation: Option<PathBuf>,
#[arg(long)]
animation_bone_map: Option<PathBuf>,
+ #[arg(long)]
+ animation_rotation_y: Option<f32>,
+ #[arg(long)]
+ animation_scale: Option<f32>,
+ #[arg(long)]
+ animation_apply_ibm: bool,
/// Spins the object
#[arg(long)]
@@ -392,7 +399,7 @@ fn main() -> Result<()> {
let anim_name_map = if let Some(ref map_path) = args.animation_bone_map {
let mut map = BTreeMap::new();
for l in read_to_string(map_path)?.lines() {
- if !l.trim().is_empty() {
+ if !l.trim().is_empty() && !l.starts_with(";") {
let (a, b) = l.split_once("=").unwrap();
map.insert(a.to_string(), b.to_string());
}
@@ -423,21 +430,34 @@ fn main() -> Result<()> {
}
}
}
- for s in gltf.skins() {
- let reader = s.reader(|buf| Some(&buffers[buf.index()]));
- if let Some(ibms) = reader.read_inverse_bind_matrices() {
- for (jn, ibm) in s.joints().zip(ibms) {
- joint_index_to_ibm.insert(
- jn.index(),
- transform_to_affine(Transform::Matrix { matrix: ibm }),
- );
+ if args.animation_apply_ibm {
+ for s in gltf.skins() {
+ let reader = s.reader(|buf| Some(&buffers[buf.index()]));
+ if let Some(ibms) = reader.read_inverse_bind_matrices() {
+ for (jn, ibm) in s.joints().zip(ibms) {
+ joint_index_to_ibm.insert(
+ jn.index(),
+ transform_to_affine(Transform::Matrix { matrix: ibm }),
+ );
+ }
}
}
+ debug!("{} joint IBMs found", joint_index_to_ibm.len());
}
+ let transform = args
+ .animation_rotation_y
+ .map(Affine3A::from_rotation_y)
+ .unwrap_or_default()
+ * args
+ .animation_scale
+ .map(Vec3::splat)
+ .map(Affine3A::from_scale)
+ .unwrap_or_default();
for a in gltf.animations() {
prefab.animation.push(import_animation(
a,
&store,
+ transform,
&joint_index_to_ibm,
&anim_joint_index_to_arm_index,
&BTreeMap::new(),
@@ -451,6 +471,7 @@ fn main() -> Result<()> {
prefab.animation.push(import_animation(
a,
&store,
+ Affine3A::IDENTITY,
&BTreeMap::new(),
&joint_index_to_arm_index,
&node_to_meshes,