summaryrefslogtreecommitdiff
path: root/world/src
diff options
context:
space:
mode:
Diffstat (limited to 'world/src')
-rw-r--r--world/src/main.rs60
1 files changed, 42 insertions, 18 deletions
diff --git a/world/src/main.rs b/world/src/main.rs
index c1289e2..a56ea74 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -111,6 +111,8 @@ pub struct Args {
debug_armature: bool,
#[arg(long)]
no_particles: bool,
+ #[arg(long)]
+ no_animations: bool,
}
fn main() -> Result<()> {
@@ -134,9 +136,10 @@ fn main() -> Result<()> {
for scenepath in &args.scene {
let path_base = scenepath.parent().unwrap();
- let mut gltf = Gltf::from_reader_without_validation(File::open(scenepath)?)?;
+ let mut gltf =
+ Gltf::from_reader_without_validation(File::open(scenepath)?).context("gltf parsing")?;
let blob = gltf.blob.take();
- let buffers = import_buffers(&gltf, Some(path_base), blob)?;
+ let buffers = import_buffers(&gltf, Some(path_base), blob).context("importing buffers")?;
let root = gltf.default_scene().ok_or(anyhow!("no default scene"))?;
@@ -162,8 +165,8 @@ fn main() -> Result<()> {
let vrm = extract_vrm_data(&gltf)?;
let mut skin_index_to_arm_index = BTreeMap::new();
+ let mut joint_index_to_arm_index = BTreeMap::new();
let armature = {
- let mut joint_index_to_arm_index = BTreeMap::new();
let mut name = Vec::new();
let mut parent_pre_map = Vec::new();
let mut transform = Vec::new();
@@ -374,34 +377,55 @@ fn main() -> Result<()> {
}
let time = store.set(&inputs)?;
let value = store.set(&outputs)?;
- let meshes = node_to_meshes
- .get(&node)
- .ok_or(anyhow!("animation ref to meshless node"))?;
- for &m in meshes {
+
+ if let Some(&m) = joint_index_to_arm_index.get(&node) {
+ let a = 0; // TODO
let mut ch = AnimationChannel::default();
match c.target().property() {
- Property::Translation => ch.t_mesh_translation = Some(m as u32),
- Property::Rotation => ch.t_mesh_rotation = Some(m as u32),
- Property::Scale => ch.t_mesh_scale = Some(m as u32),
- Property::MorphTargetWeights => todo!(),
+ Property::Translation => ch.t_joint_translation = Some((a, m as u32)),
+ Property::Rotation => ch.t_joint_rotation = Some((a, m as u32)),
+ Property::Scale => ch.t_joint_scale = Some((a, m as u32)),
+ Property::MorphTargetWeights => continue,
}
ch.time = Some(time.clone());
ch.value = Some(value.clone());
debug!(
- "animation channel {:?} of mesh {m} with {} time and {} component values",
+ "animation channel {:?} of joint {m} of armature {a} with {} time and {} component values",
c.target().property(),
inputs.len(),
outputs.len()
);
channels.push(ch);
}
+ if let Some(meshes) = node_to_meshes.get(&node) {
+ for &m in meshes {
+ let mut ch = AnimationChannel::default();
+ match c.target().property() {
+ Property::Translation => ch.t_mesh_translation = Some(m as u32),
+ Property::Rotation => ch.t_mesh_rotation = Some(m as u32),
+ Property::Scale => ch.t_mesh_scale = Some(m as u32),
+ Property::MorphTargetWeights => continue,
+ }
+ ch.time = Some(time.clone());
+ ch.value = Some(value.clone());
+ debug!(
+ "animation channel {:?} of mesh {m} with {} time and {} component values",
+ c.target().property(),
+ inputs.len(),
+ outputs.len()
+ );
+ channels.push(ch);
+ }
+ }
+ }
+ if !args.no_animations {
+ info!("adding animation with {} channels", channels.len());
+ prefab.animation.push(store.set(&AnimationPart {
+ name: a.name().map(|n| n.to_string()),
+ channel: channels,
+ duration: Some(max_time),
+ })?);
}
- info!("adding animation with {} channels", channels.len());
- prefab.animation.push(store.set(&AnimationPart {
- name: a.name().map(|n| n.to_string()),
- channel: channels,
- duration: Some(max_time),
- })?);
}
if vrm.camera_mount.is_some()