Got the stem
parent
a1911141e1
commit
aa36fddb09
43
src/main.rs
43
src/main.rs
|
@ -208,6 +208,8 @@ impl <'a> IqmModel <'a> {
|
||||||
meshes
|
meshes
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//println! ("{:?}", meshes);
|
||||||
|
|
||||||
let vertexarrays = {
|
let vertexarrays = {
|
||||||
let num: usize = header.fields [iqm_consts::NUM_VERTEXARRAYS].try_into ().unwrap ();
|
let num: usize = header.fields [iqm_consts::NUM_VERTEXARRAYS].try_into ().unwrap ();
|
||||||
let mut vertexarrays = Vec::with_capacity (num);
|
let mut vertexarrays = Vec::with_capacity (num);
|
||||||
|
@ -239,16 +241,16 @@ impl <'a> IqmModel <'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_vertex_slice (&self,
|
pub fn get_vertex_slice (&self,
|
||||||
mesh_index: usize, vertexarray_index: usize
|
vertexarray_index: usize
|
||||||
) -> &[u8]
|
) -> &[u8]
|
||||||
{
|
{
|
||||||
let vertexarray = &self.vertexarrays [vertexarray_index];
|
let vertexarray = &self.vertexarrays [vertexarray_index];
|
||||||
let bytes_per_float = 4;
|
let bytes_per_float = 4;
|
||||||
let stride = bytes_per_float * vertexarray.va_size;
|
let stride = bytes_per_float * vertexarray.va_size;
|
||||||
|
assert_eq! (stride, 12);
|
||||||
|
|
||||||
let mesh = &self.meshes [mesh_index];
|
let offset: usize = (vertexarray.va_offset).try_into ().unwrap ();
|
||||||
let offset: usize = (vertexarray.va_offset + stride * mesh.first_vertex).try_into ().unwrap ();
|
let num_bytes: usize = (stride * self.header.fields [iqm_consts::NUM_VERTEXES]).try_into ().unwrap ();
|
||||||
let num_bytes: usize = (stride * mesh.num_vertexes).try_into ().unwrap ();
|
|
||||||
|
|
||||||
&self.data [offset..offset + num_bytes]
|
&self.data [offset..offset + num_bytes]
|
||||||
}
|
}
|
||||||
|
@ -548,9 +550,6 @@ fn main () {
|
||||||
})
|
})
|
||||||
.collect ();
|
.collect ();
|
||||||
|
|
||||||
//println! ("uni_model: {}", unis ["model"]);
|
|
||||||
//println! ("uni_viewproj: {}", unis ["viewproj"]);
|
|
||||||
|
|
||||||
let attrs: HashMap <_, Option <u32>> = vec! [
|
let attrs: HashMap <_, Option <u32>> = vec! [
|
||||||
"pos",
|
"pos",
|
||||||
"uv",
|
"uv",
|
||||||
|
@ -574,19 +573,8 @@ fn main () {
|
||||||
})
|
})
|
||||||
.collect ();
|
.collect ();
|
||||||
|
|
||||||
//println! ("attr_pos: {}", attrs ["pos"]);
|
|
||||||
|
|
||||||
let tri_mesh: Vec <f32> = vec! [
|
|
||||||
0.0, 0.0,
|
|
||||||
1.0, 0.0,
|
|
||||||
1.0, 1.0,
|
|
||||||
];
|
|
||||||
|
|
||||||
let model_data = load_small_file ("pumpking.iqm");
|
let model_data = load_small_file ("pumpking.iqm");
|
||||||
let model = IqmModel::from_slice (&model_data [..]);
|
let model = IqmModel::from_slice (&model_data [..]);
|
||||||
let vertex_slice = model.get_vertex_slice (0, 0);
|
|
||||||
let normal_slice = model.get_vertex_slice (0, 2);
|
|
||||||
let index_slice = model.get_index_slice (0);
|
|
||||||
|
|
||||||
let id_mat = Mat4::identity ();
|
let id_mat = Mat4::identity ();
|
||||||
let view_mat: Vec <f32> = vec! [
|
let view_mat: Vec <f32> = vec! [
|
||||||
|
@ -595,7 +583,6 @@ fn main () {
|
||||||
0.0, 0.0, 0.3125, 0.0,
|
0.0, 0.0, 0.3125, 0.0,
|
||||||
0.0, 0.0, 0.0, 1.0,
|
0.0, 0.0, 0.0, 1.0,
|
||||||
];
|
];
|
||||||
let indexes: Vec <u16> = vec! [0, 1, 2];
|
|
||||||
|
|
||||||
const FALSE_U8: u8 = 0;
|
const FALSE_U8: u8 = 0;
|
||||||
|
|
||||||
|
@ -653,11 +640,11 @@ fn main () {
|
||||||
window.gl_make_current (&gl_ctx).unwrap ();
|
window.gl_make_current (&gl_ctx).unwrap ();
|
||||||
|
|
||||||
let longitude = (frame as f32).to_radians ();
|
let longitude = (frame as f32).to_radians ();
|
||||||
let latitude = (frame as f32 / 5.0).to_radians ().sin () * 45.0f32.to_radians () - 120.0f32.to_radians ();
|
let latitude = (frame as f32 / 5.0).to_radians ().sin () * 30.0f32.to_radians () - 120.0f32.to_radians ();
|
||||||
let model_mat =
|
let model_mat =
|
||||||
Mat4::from_rotation_x (latitude) *
|
Mat4::from_rotation_x (latitude) *
|
||||||
Mat4::from_rotation_z (longitude) *
|
Mat4::from_rotation_z (longitude) *
|
||||||
Mat4::from_translation (Vec3::from ((0.0, 0.0, -1.0)))
|
Mat4::from_translation (Vec3::from ((0.0, 0.0, -2.7 * 0.5)))
|
||||||
;
|
;
|
||||||
|
|
||||||
let light = Vec4::from ((0.0, 0.0, 0.0, 1.0));
|
let light = Vec4::from ((0.0, 0.0, 0.0, 1.0));
|
||||||
|
@ -679,18 +666,18 @@ fn main () {
|
||||||
|
|
||||||
gl::Uniform3fv (unis ["albedo"], 1, &orange as *const Vec3 as *const f32);
|
gl::Uniform3fv (unis ["albedo"], 1, &orange as *const Vec3 as *const f32);
|
||||||
|
|
||||||
vertex_attrib_pointer (attrs ["pos"], 3, model.get_vertex_slice (0, 0));
|
vertex_attrib_pointer (attrs ["pos"], 3, model.get_vertex_slice (0));
|
||||||
vertex_attrib_pointer (attrs ["normal"], 3, model.get_vertex_slice (0, 2));
|
vertex_attrib_pointer (attrs ["normal"], 3, model.get_vertex_slice (2));
|
||||||
|
|
||||||
gl::DrawElements (gl::TRIANGLES, (model.meshes [0].num_triangles * 3) as i32, gl::UNSIGNED_INT, &index_slice [0] as *const u8 as *const c_void);
|
gl::DrawElements (gl::TRIANGLES, (model.meshes [0].num_triangles * 3) as i32, gl::UNSIGNED_INT, &model.get_index_slice (0) [0] as *const u8 as *const c_void);
|
||||||
|
|
||||||
if false {
|
if true {
|
||||||
gl::Uniform3fv (unis ["albedo"], 1, &green as *const Vec3 as *const f32);
|
gl::Uniform3fv (unis ["albedo"], 1, &green as *const Vec3 as *const f32);
|
||||||
|
|
||||||
vertex_attrib_pointer (attrs ["pos"], 3, model.get_vertex_slice (1, 0));
|
vertex_attrib_pointer (attrs ["pos"], 3, model.get_vertex_slice (0));
|
||||||
vertex_attrib_pointer (attrs ["normal"], 3, model.get_vertex_slice (1, 2));
|
vertex_attrib_pointer (attrs ["normal"], 3, model.get_vertex_slice (2));
|
||||||
|
|
||||||
gl::DrawElements (gl::TRIANGLES, (model.meshes [1].num_triangles * 3) as i32, gl::UNSIGNED_INT, &index_slice [1] as *const u8 as *const c_void);
|
gl::DrawElements (gl::TRIANGLES, (model.meshes [1].num_triangles * 3) as i32, gl::UNSIGNED_INT, &model.get_index_slice (1) [0] as *const u8 as *const c_void);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue