summaryrefslogtreecommitdiff
path: root/world/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'world/src/main.rs')
-rw-r--r--world/src/main.rs36
1 files changed, 33 insertions, 3 deletions
diff --git a/world/src/main.rs b/world/src/main.rs
index 081aa09..c3fb959 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -18,6 +18,7 @@
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
pub mod mesh;
pub mod physics;
+pub mod vrm;
use anyhow::{Result, anyhow};
use clap::Parser;
@@ -41,6 +42,7 @@ use std::{
thread::{self, sleep},
time::Duration,
};
+use vrm::{Vrm, Vrmc};
use weareshared::{
Affine3A, Vec3A,
helper::ReadWrite,
@@ -110,6 +112,8 @@ fn main() -> Result<()> {
root_affine.matrix3 *= args.scale.unwrap_or(1.);
root_affine.translation *= args.scale.unwrap_or(1.);
+ let mut debug_bone = (0, Affine3A::IDENTITY);
+
for scenepath in &args.scene {
let path_base = scenepath.parent().unwrap();
let mut gltf = Gltf::from_reader_without_validation(File::open(scenepath)?)?;
@@ -169,6 +173,27 @@ fn main() -> Result<()> {
})
.collect::<Vec<_>>();
+ if let Some(vrm) = gltf.extension_value("VRM") {
+ let vrm: Vrm = serde_json::from_value(vrm.clone())?;
+ for bone in vrm.humanoid.human_bones {
+ let ind = joint_index_to_arm_index[&bone.node];
+ name[ind] = bone.bone;
+ }
+ }
+ if let Some(vrm) = gltf.extension_value("VRMC_vrm") {
+ let vrm: Vrmc = serde_json::from_value(vrm.clone())?;
+ for (bname, bone) in vrm.humanoid.human_bones {
+ let ind = joint_index_to_arm_index[&bone.node];
+ name[ind] = bname;
+ }
+ }
+
+ for (i, (name, tr)) in name.iter().zip(transform.iter()).enumerate() {
+ if name == "head" {
+ debug_bone = (i, *tr);
+ }
+ }
+
if !parent.is_empty() {
Some(store.set(&ArmaturePart {
name: Some(name),
@@ -317,10 +342,15 @@ fn main() -> Result<()> {
thread::spawn(move || {
let mut x = 0f32;
loop {
- let a = Affine3A::from_rotation_y(x.sin());
- Packet::Pose(ob, vec![(6, a)]).write(&mut sock2).unwrap();
+ let a = Affine3A::IDENTITY
+ * Affine3A::from_rotation_x(x.cos() * 0.3)
+ * Affine3A::from_rotation_y(x.sin() * 0.5)
+ * debug_bone.1;
+ Packet::Pose(ob, vec![(debug_bone.0 as u16, a)])
+ .write(&mut sock2)
+ .unwrap();
sock2.flush().unwrap();
- x += 0.1;
+ x += 0.2;
sleep(Duration::from_millis(50));
}
});