|
|
|
@ -0,0 +1,155 @@
|
|
|
|
|
use std::{
|
|
|
|
|
fs::File,
|
|
|
|
|
io::Write,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fn main () {
|
|
|
|
|
let mut f = File::create ("cube.iqm").unwrap ();
|
|
|
|
|
|
|
|
|
|
f.write_all (b"INTERQUAKEMODEL\0").unwrap ();
|
|
|
|
|
|
|
|
|
|
f.write_all (&(2u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// filesize
|
|
|
|
|
f.write_all (&(0x198u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// flags
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_text, ofs_text
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_meshes, ofs_meshes
|
|
|
|
|
f.write_all (&(1u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0x7Cu32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_vertexarrays, num_vertexes, ofs_vertexarrays
|
|
|
|
|
f.write_all (&(1u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(8u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0x94u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_triangles, ofs_triangles, ofs_adjacency
|
|
|
|
|
f.write_all (&(1u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0x108u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_joints, ofs_joints
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_poses, ofs_poses
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_anims, ofs_anims
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0u32.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 (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_comment, ofs_comment
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// num_extensions, ofs_extensions
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// Meshes
|
|
|
|
|
|
|
|
|
|
// name
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// material
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// first_vertex, num_vertexes
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(8u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// first_triangle, num_triangles
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
f.write_all (&(12u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// Vertex arrays
|
|
|
|
|
|
|
|
|
|
// type
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// flags
|
|
|
|
|
f.write_all (&(0u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// format
|
|
|
|
|
f.write_all (&(7u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// size
|
|
|
|
|
f.write_all (&(3u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// offset
|
|
|
|
|
f.write_all (&(0xA8u32.to_le_bytes ())).unwrap ();
|
|
|
|
|
|
|
|
|
|
// Vertexes
|
|
|
|
|
|
|
|
|
|
for t in [
|
|
|
|
|
[-1.0, -1.0, -1.0],
|
|
|
|
|
[ 1.0, -1.0, -1.0],
|
|
|
|
|
[ 1.0, 1.0, -1.0],
|
|
|
|
|
[-1.0, 1.0, -1.0],
|
|
|
|
|
|
|
|
|
|
[-1.0, -1.0, 1.0],
|
|
|
|
|
[ 1.0, -1.0, 1.0],
|
|
|
|
|
[ 1.0, 1.0, 1.0],
|
|
|
|
|
[-1.0, 1.0, 1.0],
|
|
|
|
|
] {
|
|
|
|
|
for x in t {
|
|
|
|
|
f.write_all (&(f32::to_le_bytes (x))).unwrap ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Triangles
|
|
|
|
|
|
|
|
|
|
for t in [
|
|
|
|
|
[0, 2, 1],
|
|
|
|
|
[0, 3, 2],
|
|
|
|
|
|
|
|
|
|
[0, 5, 1],
|
|
|
|
|
[1, 6, 2],
|
|
|
|
|
[2, 7, 3],
|
|
|
|
|
[3, 4, 0],
|
|
|
|
|
|
|
|
|
|
[0, 4, 5],
|
|
|
|
|
[1, 5, 6],
|
|
|
|
|
[2, 6, 7],
|
|
|
|
|
[3, 7, 4],
|
|
|
|
|
|
|
|
|
|
[4, 6, 5],
|
|
|
|
|
[4, 7, 6],
|
|
|
|
|
] {
|
|
|
|
|
for x in t {
|
|
|
|
|
f.write_all (&(u32::to_le_bytes (x))).unwrap ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod iqm {
|
|
|
|
|
struct VertexArray {
|
|
|
|
|
r#type: u32,
|
|
|
|
|
flags: u32,
|
|
|
|
|
format: u32,
|
|
|
|
|
size: u32,
|
|
|
|
|
offset: u32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Triangle {
|
|
|
|
|
vertex: [u32; 3],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Vertex {
|
|
|
|
|
position: [f32; 3],
|
|
|
|
|
}
|
|
|
|
|
}
|