♻️ refactor: file offsets

main
_ 2022-02-23 00:02:00 +00:00
parent 1e9c671c68
commit 4bd6d7d25d
1 changed files with 41 additions and 12 deletions

View File

@ -50,7 +50,7 @@ fn main () {
let m = gltf_node_get_mat4 (&node); let m = gltf_node_get_mat4 (&node);
for prim in mesh.primitives () { for (i, prim) in mesh.primitives ().enumerate () {
assert_eq! (prim.mode (), gltf::mesh::Mode::Triangles); assert_eq! (prim.mode (), gltf::mesh::Mode::Triangles);
let indices = prim.indices ().unwrap (); let indices = prim.indices ().unwrap ();
@ -80,7 +80,7 @@ fn main () {
num_triangles: u32::try_from (indices_slice.len () / 6).unwrap (), num_triangles: u32::try_from (indices_slice.len () / 6).unwrap (),
//num_triangles: u32::try_from (1).unwrap (), //num_triangles: u32::try_from (1).unwrap (),
}; };
texts.push_str ("\0"); texts.push_str (&format! ("{}/{}\0", node.name ().unwrap (), i));
meshes.push (mesh); meshes.push (mesh);
@ -178,6 +178,17 @@ fn main () {
}, },
]; ];
let joints = [
iqm::Joint {
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],
scale: [1.0, 1.0, 1.0],
}
];
texts.push_str ("bogus_joint\0");
let vertexes = vertexes; let vertexes = vertexes;
let triangles = triangles; let triangles = triangles;
let meshes = meshes; let meshes = meshes;
@ -186,20 +197,25 @@ fn main () {
let num_vertexes = u32::try_from (vertexes.len ()).unwrap (); let num_vertexes = u32::try_from (vertexes.len ()).unwrap ();
let num_triangles = u32::try_from (triangles.len ()).unwrap (); let num_triangles = u32::try_from (triangles.len ()).unwrap ();
let num_joints = u32::try_from (joints.len ()).unwrap ();
let num_text = texts.len (); let num_text = texts.len ();
let num_text = u32::try_from (num_text).unwrap (); let num_text = u32::try_from (num_text).unwrap ();
let num_meshes = u32::try_from (meshes.len ()).unwrap (); let num_meshes = u32::try_from (meshes.len ()).unwrap ();
let num_vertexarrays = u32::try_from (vertexarrays_unplaced.len ()).unwrap (); let num_vertexarrays = u32::try_from (vertexarrays_unplaced.len ()).unwrap ();
let mut offset = 0;
let header_len = 124u32; let header_len = 124u32;
let ofs_meshes = header_len;
let ofs_vertexarrays = ofs_meshes + num_meshes * 6 * 4; offset += header_len;
// Not part of IQM spec, but I need it for self-care let ofs_meshes = offset;
let ofs_vertexes = ofs_vertexarrays + num_vertexarrays * 5 * 4; offset += num_meshes * 6 * 4;
let ofs_vertexarrays = offset;
offset += num_vertexarrays * 5 * 4;
let mut vertexarrays = Vec::default (); let mut vertexarrays = Vec::default ();
let mut ofs_va = ofs_vertexes;
for va_in in vertexarrays_unplaced { for va_in in vertexarrays_unplaced {
let stride = va_in.stride (); let stride = va_in.stride ();
@ -209,18 +225,23 @@ fn main () {
flags: va_in.flags, flags: va_in.flags,
format: va_in.format, format: va_in.format,
size: va_in.size, size: va_in.size,
offset: ofs_va, offset,
}); });
ofs_va += num_vertexes * stride; offset += num_vertexes * stride;
} }
let vertexarrays = vertexarrays; let vertexarrays = vertexarrays;
let ofs_triangles = ofs_va; let ofs_triangles = offset;
let ofs_text = ofs_triangles + num_triangles * 3 * 4; offset += num_triangles * 3 * 4;
let ofs_text = offset;
offset += num_text;
let ofs_joints = offset;
// offset += num_joints * 48;
let filesize = ofs_text + num_text; let filesize = offset;
let _ = offset;
let mut f = File::create (output_path).unwrap (); let mut f = File::create (output_path).unwrap ();
@ -386,6 +407,14 @@ mod iqm {
vertex: [u32; 3], vertex: [u32; 3],
} }
pub struct Joint {
pub name: u32,
pub parent: i32,
pub translate: [f32; 3],
pub rotate: [f32; 4],
pub scale: [f32; 3],
}
pub struct Vertex { pub struct Vertex {
pub position: [f32; 3], pub position: [f32; 3],
pub normal: [f32; 3], pub normal: [f32; 3],