🚧 wip: write bogus normals

main
_ 2022-02-22 00:17:55 +00:00
parent 7d70c8af21
commit e23bf0af59
1 changed files with 45 additions and 24 deletions

View File

@ -58,6 +58,11 @@ fn main () {
let pos_offset = pos.offset () + pos_view.offset (); let pos_offset = pos.offset () + pos_view.offset ();
let pos_slice = &buffer [pos_offset..(pos_offset + pos.count () * 4 * 3)]; let pos_slice = &buffer [pos_offset..(pos_offset + pos.count () * 4 * 3)];
let norm = prim.get (&gltf::Semantic::Normals).unwrap ();
let pos_view = pos.view ().unwrap ();
let pos_offset = pos.offset () + pos_view.offset ();
let pos_slice = &buffer [pos_offset..(pos_offset + pos.count () * 4 * 3)];
let first_vertex = vertexes.len (); let first_vertex = vertexes.len ();
let mesh = iqm::Mesh { let mesh = iqm::Mesh {
@ -131,12 +136,14 @@ fn main () {
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 = 1u32; let num_vertexarrays = 2u32;
let header_len = 124u32; let header_len = 124u32;
let ofs_meshes = header_len; let ofs_meshes = header_len;
let ofs_vertexarrays = ofs_meshes + num_meshes * 6 * 4; let ofs_vertexarrays = ofs_meshes + num_meshes * 6 * 4;
let ofs_triangles = ofs_vertexarrays + num_vertexarrays * 5 * 4 + num_vertexes * 3 * 4; // Not part of IQM spec, but I need it for self-care
let ofs_vertexes = ofs_vertexarrays + num_vertexarrays * 5 * 4;
let ofs_triangles = ofs_vertexes + num_vertexes * 3 * 4 + num_vertexes * 3 * 4;
let ofs_text = ofs_triangles + num_triangles * 3 * 4; let ofs_text = ofs_triangles + num_triangles * 3 * 4;
let filesize = ofs_text + num_text; let filesize = ofs_text + num_text;
@ -210,25 +217,39 @@ fn main () {
// Vertex arrays // Vertex arrays
// type for va in [
f.write_all (&(0u32.to_le_bytes ())).unwrap (); iqm::VertexArray {
r#type: 0,
flags: 0,
format: 7,
size: 3,
offset: ofs_vertexes + 0,
},
iqm::VertexArray {
r#type: 2,
flags: 0,
format: 7,
size: 3,
offset: ofs_vertexes + num_vertexes * 3 * 4,
},
] {
f.write_all (&(va.r#type.to_le_bytes ())).unwrap ();
f.write_all (&(va.flags.to_le_bytes ())).unwrap ();
f.write_all (&(va.format.to_le_bytes ())).unwrap ();
f.write_all (&(va.size.to_le_bytes ())).unwrap ();
f.write_all (&(va.offset.to_le_bytes ())).unwrap ();
}
// flags // Vertex position
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
// format for t in &vertexes {
f.write_all (&(7u32.to_le_bytes ())).unwrap ();
// size
f.write_all (&(3u32.to_le_bytes ())).unwrap ();
// offset
f.write_all (&((ofs_vertexarrays + 5 * 4 * 1).to_le_bytes ())).unwrap ();
// Vertexes
for t in vertexes {
for x in t { for x in t {
f.write_all (&(f32::to_le_bytes (*x))).unwrap ();
}
}
for t in &vertexes {
for x in [0.0, 0.0, 1.0] {
f.write_all (&(f32::to_le_bytes (x))).unwrap (); f.write_all (&(f32::to_le_bytes (x))).unwrap ();
} }
} }
@ -261,12 +282,12 @@ mod iqm {
pub num_triangles: u32, pub num_triangles: u32,
} }
struct VertexArray { pub struct VertexArray {
r#type: u32, pub r#type: u32,
flags: u32, pub flags: u32,
format: u32, pub format: u32,
size: u32, pub size: u32,
offset: u32, pub offset: u32,
} }
struct Triangle { struct Triangle {