Compare commits

...

4 Commits

Author SHA1 Message Date
_ 514f0d4ac9 got a one-channel animation working 2022-02-23 01:30:11 +00:00
_ 10bd7278d7 🐛 the demo can load a do-nothing anim now 2022-02-23 01:26:35 +00:00
_ 5515362d7b 🚧 wip: write bogus frames, fix alignment 2022-02-23 01:08:54 +00:00
_ 003cbe4547 🚧 wip: write bogus anim 2022-02-23 00:57:13 +00:00
2 changed files with 80 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
/target
/videos
*.blend
*.glb

View File

@ -164,6 +164,12 @@ fn main () {
format: iqm::FLOAT,
size: 3,
},
iqm::VertexArrayUnplaced {
r#type: iqm::TANGENT,
flags: 0,
format: iqm::FLOAT,
size: 4,
},
iqm::VertexArrayUnplaced {
r#type: iqm::BLENDINDEXES,
flags: 0,
@ -183,7 +189,7 @@ fn main () {
name: u32::try_from (texts.len ()).unwrap (),
parent: -1,
translate: [0.0, 0.0, 0.0],
rotate: [1.0, 0.0, 0.0, 0.0],
rotate: [0.0, 0.0, 0.0, 1.0],
scale: [1.0, 1.0, 1.0],
},
];
@ -193,11 +199,33 @@ fn main () {
iqm::Pose {
parent: -1,
channelmask: 1, // Should be X translation
channeloffset: [0.0; 10],
channeloffset: [
0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0,
1.0, 1.0, 1.0,
],
channelscale: [16.0 / 32768.0; 10],
},
];
let anims = [
iqm::Anim {
name: u32::try_from (texts.len ()).unwrap (),
first_frame: 0,
num_frames: 2,
framerate: 0.5,
flags: 0,
},
];
texts.push_str ("bogus_anim\0");
let num_framechannels = 1;
let frames = [
0,
32768,
];
let vertexes = vertexes;
let triangles = triangles;
let meshes = meshes;
@ -208,6 +236,8 @@ fn main () {
let num_joints = u32::try_from (joints.len ()).unwrap ();
let num_poses = u32::try_from (poses.len ()).unwrap ();
let num_anims = u32::try_from (anims.len ()).unwrap ();
let num_frames = u32::try_from (frames.len ()).unwrap () / num_framechannels;
let num_text = texts.len ();
let num_text = u32::try_from (num_text).unwrap ();
@ -245,13 +275,22 @@ fn main () {
let ofs_triangles = offset;
offset += num_triangles * 3 * 4;
let ofs_text = offset;
offset += num_text;
let ofs_joints = offset;
offset += num_joints * 48;
let ofs_poses = offset;
offset += num_poses * 88;
let ofs_anims = offset;
offset += num_anims * 5 * 4;
let ofs_frames = offset;
offset += num_frames * num_framechannels * 2;
let ofs_text = offset;
offset += num_text;
let filesize = offset;
let _ = offset;
@ -294,13 +333,13 @@ fn main () {
f.write_all (&(ofs_poses.to_le_bytes ())).unwrap ();
// num_anims, ofs_anims
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
f.write_all (&(num_anims.to_le_bytes ())).unwrap ();
f.write_all (&(ofs_anims.to_le_bytes ())).unwrap ();
// num_frames, num_framechannels, ofs_frames, ofs_bounds
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
f.write_all (&(num_frames.to_le_bytes ())).unwrap ();
f.write_all (&(num_framechannels.to_le_bytes ())).unwrap ();
f.write_all (&(ofs_frames.to_le_bytes ())).unwrap ();
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
// num_comment, ofs_comment
@ -346,6 +385,12 @@ fn main () {
}
}
for v in &vertexes {
for x in [0.0, 0.0, 0.0, 1.0] {
f.write_all (&(f32::to_le_bytes (x))).unwrap ();
}
}
for v in &vertexes {
f.write_all (&[0, 0, 0, 0]).unwrap ();
}
@ -362,10 +407,6 @@ fn main () {
}
}
// Text
f.write_all (texts.as_bytes ()).unwrap ();
// Joints
for j in joints {
@ -394,6 +435,22 @@ fn main () {
f.write_all (&(f32::to_le_bytes (x))).unwrap ();
}
}
for a in anims {
f.write_all (&(u32::to_le_bytes (a.name))).unwrap ();
f.write_all (&(u32::to_le_bytes (a.first_frame))).unwrap ();
f.write_all (&(u32::to_le_bytes (a.num_frames))).unwrap ();
f.write_all (&(f32::to_le_bytes (a.framerate))).unwrap ();
f.write_all (&(u32::to_le_bytes (a.flags))).unwrap ();
}
for x in frames {
f.write_all (&(u16::to_le_bytes (x))).unwrap ();
}
// Text
f.write_all (texts.as_bytes ()).unwrap ();
}
fn gltf_node_get_mat4 (node: &gltf::Node) -> Mat4 {
@ -414,6 +471,7 @@ mod iqm {
pub const POSITION: u32 = 0;
pub const NORMAL: u32 = 2;
pub const TANGENT: u32 = 3;
pub const BLENDINDEXES: u32 = 4;
pub const BLENDWEIGHTS: u32 = 5;
@ -466,6 +524,14 @@ mod iqm {
pub channelscale: [f32; 10],
}
pub struct Anim {
pub name: u32,
pub first_frame: u32,
pub num_frames: u32,
pub framerate: f32,
pub flags: u32,
}
pub struct Vertex {
pub position: [f32; 3],
pub normal: [f32; 3],