Browse Source

finish skeletal animation, add a math wrapper module, reduce data sent to the GPU

master
Alison Watson 1 year ago
parent
commit
3b90effb16
  1. 62
      Cargo.lock
  2. 4
      glsl/main.vert
  3. 8
      source/framework/data/bit.rs
  4. 168
      source/framework/data/model.rs
  5. 11
      source/framework/data/read.rs
  6. 2
      source/framework/data/uniforms.rs
  7. 10
      source/framework/data/vertex.rs
  8. 1
      source/framework/lib.rs
  9. 11
      source/framework/math.rs
  10. 18
      source/framework/render/misc.rs
  11. 6
      source/framework/render/model.rs
  12. 36
      source/main_test/entry.rs

62
Cargo.lock generated

@ -49,9 +49,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.66"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
[[package]]
name = "cfg-if"
@ -85,9 +85,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.81"
version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
[[package]]
name = "libloading"
@ -101,9 +101,9 @@ dependencies = [
[[package]]
name = "llvm-sys"
version = "110.0.0"
version = "110.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0062a0c6635fb5d57c6ebba072dcae50e41651030363cf06d220b0d016840f2"
checksum = "21ede189444b8c78907e5d36da5dabcf153170fcff9c1dba48afc4b33c7e19f0"
dependencies = [
"cc",
"lazy_static",
@ -138,30 +138,29 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.7"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.4.2"
version = "1.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"thread_local",
]
[[package]]
name = "regex-syntax"
version = "0.6.21"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
[[package]]
name = "sdl2-sys"
@ -185,27 +184,27 @@ dependencies = [
[[package]]
name = "semver-parser"
version = "0.10.1"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428"
checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7"
dependencies = [
"pest",
]
[[package]]
name = "serde"
version = "1.0.118"
version = "1.0.124"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.118"
version = "1.0.124"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b"
dependencies = [
"proc-macro2",
"quote",
@ -236,9 +235,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "syn"
version = "1.0.54"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f"
dependencies = [
"proc-macro2",
"quote",
@ -256,38 +255,29 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.22"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e"
checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.22"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
dependencies = [
"lazy_static",
]
[[package]]
name = "toml"
version = "0.5.7"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75cf45bb0bef80604d001caaec0d09da99611b3c0fd39d3080468875cdb65645"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
dependencies = [
"serde",
]

4
glsl/main.vert

@ -31,7 +31,7 @@ void main() {
cross(pos_mat[2].xyz, pos_mat[0].xyz),
cross(pos_mat[0].xyz, pos_mat[1].xyz));
vec3 pos = vec3(pos_mat * vec4(in_position, 1.0));
vec4 pos = pos_mat * vec4(in_position, 1.0);
vec3 nrm = adj_mat * in_normal;
vec3 tng = adj_mat * in_tangent;
@ -39,7 +39,7 @@ void main() {
u_matrices.projec *
u_matrices.camera *
u_matrices.object *
vec4(pos, 1.0);
pos;
out_tex_coord = in_tex_coord;
out_color = in_color;

8
source/framework/data/bit.rs

@ -27,7 +27,9 @@ macro_rules! read_bits_impl {
($t:ty) => {
#[allow(clippy::use_self)]
impl ReadBits for $t {
fn read_bits_be(b: &[u8], cr_bit: usize, mut width: usize) -> Option<Self> {
fn read_bits_be(
b: &[u8], cr_bit: usize, mut width: usize,
) -> Option<Self> {
if width == 0 {
return Some(0);
}
@ -62,7 +64,9 @@ macro_rules! read_bits_impl {
Some(res)
}
fn read_bits_le(b: &[u8], cr_bit: usize, mut width: usize) -> Option<Self> {
fn read_bits_le(
b: &[u8], cr_bit: usize, mut width: usize,
) -> Option<Self> {
if width == 0 {
return Some(0);
}

168
source/framework/data/model.rs

@ -1,8 +1,8 @@
use crate::{
data::{read, vertex::Vertex},
ffi,
math::*,
};
use glam::{Mat4, Quat, Vec3, Vec3A, Vec4};
use smol_str::SmolStr;
use std::{
collections::HashMap,
@ -27,6 +27,8 @@ pub enum Err {
Parent,
#[error("Bad frame count")]
FrameCount,
#[error("Inverse of matrix not possible")]
Inverse,
#[error("Unknown vertex array type")]
VaType,
#[error("Unsupported vertex array format")]
@ -35,27 +37,34 @@ pub enum Err {
struct VertexZipper {
// kono jippa......
pos_v: std::vec::IntoIter<Vec3A>,
tex_v: std::vec::IntoIter<Vec3A>,
nrm_v: std::vec::IntoIter<Vec3A>,
pos_v: std::vec::IntoIter<Vec3>,
tex_v: std::vec::IntoIter<Vec3>,
nrm_v: std::vec::IntoIter<Vec3>,
tan_v: std::vec::IntoIter<Vec4>,
idx_v: std::vec::IntoIter<Vec4>,
wgt_v: std::vec::IntoIter<Vec4>,
clr_v: std::vec::IntoIter<Vec4>,
}
pub struct Mesh {
mat: SmolStr,
vtx: Range<usize>,
idx: Range<usize>,
struct Pose {
par: usize,
msk: u32,
ofs: [f32; 10],
scl: [f32; 10],
}
pub struct Joint {
struct Joint {
nam: SmolStr,
mat: Mat4,
inv: Mat4,
}
pub struct Mesh {
mat: SmolStr,
vtx: Range<usize>,
idx: Range<usize>,
}
/// Data to be uploaded to the GPU. Separate from Model so that it may
/// be dropped after upload.
pub struct ModelData {
@ -73,9 +82,9 @@ pub struct Model {
impl Iterator for VertexZipper {
type Item = (
Option<Vec3A>,
Option<Vec3A>,
Option<Vec3A>,
Option<Vec3>,
Option<Vec3>,
Option<Vec3>,
Option<Vec4>,
Option<Vec4>,
Option<Vec4>,
@ -109,49 +118,47 @@ const FMT_F64: u32 = 8;
fn fmt_check(fm: u32) -> Result<(), Err> {
match fm {
FMT_I8 | FMT_U8 |
FMT_I16 | FMT_U16 |
FMT_I32 | FMT_U32 | FMT_F32 |
FMT_F64 => Ok(()),
_ => Err(Err::VaFormat),
| FMT_I8 | FMT_U8 | FMT_I16 | FMT_U16 | FMT_I32 | FMT_U32 | FMT_F32
| FMT_F64 => Ok(()),
| _ => Err(Err::VaFormat),
}
}
fn fmt_size(fm: u32) -> usize {
match fm {
FMT_I8 | FMT_U8 => 1,
FMT_I16 | FMT_U16 => 2,
FMT_I32 | FMT_U32 | FMT_F32 => 4,
FMT_F64 => 8,
_ => unsafe { std::hint::unreachable_unchecked() },
| FMT_I8 | FMT_U8 => 1,
| FMT_I16 | FMT_U16 => 2,
| FMT_I32 | FMT_U32 | FMT_F32 => 4,
| FMT_F64 => 8,
| _ => unsafe { std::hint::unreachable_unchecked() },
}
}
fn fmt_read_abs(fm: u32, vec: &[u8], pos: usize) -> f32 {
match fm {
FMT_I8 => f32::from(vec[pos] as i8),
FMT_U8 => f32::from(vec[pos]),
FMT_I16 => f32::from(read::i16le_16(vec, pos)),
FMT_U16 => f32::from(read::u16le_16(vec, pos)),
FMT_I32 => read::i32le_32(vec, pos) as f32,
FMT_U32 => read::u32le_32(vec, pos) as f32,
FMT_F32 => read::f32le_32(vec, pos),
FMT_F64 => read::f64le_64(vec, pos) as f32,
_ => unsafe { std::hint::unreachable_unchecked() },
| FMT_I8 => f32::from(vec[pos] as i8),
| FMT_U8 => f32::from(vec[pos]),
| FMT_I16 => f32::from(read::i16le_16(vec, pos)),
| FMT_U16 => f32::from(read::u16le_16(vec, pos)),
| FMT_I32 => read::i32le_32(vec, pos) as f32,
| FMT_U32 => read::u32le_32(vec, pos) as f32,
| FMT_F32 => read::f32le_32(vec, pos),
| FMT_F64 => read::f64le_64(vec, pos) as f32,
| _ => unsafe { std::hint::unreachable_unchecked() },
}
}
fn fmt_read_nrm(fm: u32, vec: &[u8], pos: usize) -> f32 {
match fm {
FMT_I8 => f32::abs(f32::from(vec[pos] as i8) / 128.0),
FMT_U8 => f32::from(vec[pos]) / 255.0,
FMT_I16 => f32::abs(f32::from(read::i16le_16(vec, pos)) / 32768.0),
FMT_U16 => f32::from(read::u16le_16(vec, pos)) / 65535.0,
FMT_I32 => (read::i32le_32(vec, pos) as f64 / 2147483648.0) as f32,
FMT_U32 => (read::u32le_32(vec, pos) as f64 / 4294967295.0) as f32,
FMT_F32 => f32::clamp(read::f32le_32(vec, pos), 0.0, 1.0),
FMT_F64 => f32::clamp(read::f64le_64(vec, pos) as f32, 0.0, 1.0),
_ => unsafe { std::hint::unreachable_unchecked() },
| FMT_I8 => f32::abs(f32::from(vec[pos] as i8) / 128.0),
| FMT_U8 => f32::from(vec[pos]) / 255.0,
| FMT_I16 => f32::abs(f32::from(read::i16le_16(vec, pos)) / 32768.0),
| FMT_U16 => f32::from(read::u16le_16(vec, pos)) / 65535.0,
| FMT_I32 => (read::i32le_32(vec, pos) as f64 / 2147483648.0) as f32,
| FMT_U32 => (read::u32le_32(vec, pos) as f64 / 4294967295.0) as f32,
| FMT_F32 => f32::clamp(read::f32le_32(vec, pos), 0.0, 1.0),
| FMT_F64 => f32::clamp(read::f64le_64(vec, pos) as f32, 0.0, 1.0),
| _ => unsafe { std::hint::unreachable_unchecked() },
}
}
@ -254,20 +261,20 @@ impl Model {
let hunk = read::hunk(rd, obj_blks * num_vert)?;
let v2 = |v: &mut Vec<Vec3A>, rd: fn(u32, &[u8], usize) -> f32| {
let v2 = |v: &mut Vec<Vec3>, rd: fn(u32, &[u8], usize) -> f32| {
if obj_amnt != 2 {
Err(Err::VaFormat)
} else {
for vec in hunk.chunks(obj_blks) {
let x = rd(fm, vec, obj_size * 0);
let y = rd(fm, vec, obj_size * 1);
v.push(Vec3A::new(x, y, 0.0));
v.push(Vec3::new(x, y, 0.0));
}
Ok(())
}
};
let v3 = |v: &mut Vec<Vec3A>, rd: fn(u32, &[u8], usize) -> f32| {
let v3 = |v: &mut Vec<Vec3>, rd: fn(u32, &[u8], usize) -> f32| {
if obj_amnt != 3 {
Err(Err::VaFormat)
} else {
@ -275,7 +282,7 @@ impl Model {
let x = rd(fm, vec, obj_size * 0);
let y = rd(fm, vec, obj_size * 1);
let z = rd(fm, vec, obj_size * 2);
v.push(Vec3A::new(x, y, z));
v.push(Vec3::new(x, y, z));
}
Ok(())
}
@ -322,9 +329,9 @@ impl Model {
let mut vert_dat = Vec::with_capacity(num_vert);
for (pos, tex, nrm, tan, idx, wgt, clr) in zipper {
let pos = pos.unwrap_or_else(|| Vec3A::ZERO);
let tex = tex.unwrap_or_else(|| Vec3A::ZERO);
let nrm = nrm.unwrap_or_else(|| Vec3A::ZERO);
let pos = pos.unwrap_or_else(|| Vec3::ZERO);
let tex = tex.unwrap_or_else(|| Vec3::ZERO);
let nrm = nrm.unwrap_or_else(|| Vec3::ZERO);
let tan = tan.unwrap_or_else(|| Vec4::ZERO);
let idx = idx.unwrap_or_else(|| Vec4::ZERO);
let wgt = wgt.unwrap_or_else(|| Vec4::ZERO);
@ -383,11 +390,11 @@ impl Model {
let nam = SmolStr::new(from_stab(&stab, nam)?);
let mut mat = Mat4::from_scale_rotation_translation(
Vec3::new(trs[7], trs[8], trs[9]),
Quat::from_xyzw(trs[3], trs[4], trs[5], trs[6]).normalize(),
Vec3::new(trs[0], trs[1], trs[2]),
);
let xlt = Vec3::new(trs[0], trs[1], trs[2]);
let rot = Quat::from_xyzw(trs[3], trs[4], trs[5], trs[6]).normalize();
let scl = Vec3::new(trs[7], trs[8], trs[9]);
let mut mat = Mat4::from_scale_rotation_translation(scl, rot, xlt);
let mut inv = mat.inverse();
if par & 0x8000_0000 == 0 {
@ -409,59 +416,70 @@ impl Model {
}
// collect pose info
let mut frame = frames.iter();
let mut frames = Vec::with_capacity(num_pose);
let mut poses = Vec::with_capacity(num_pose);
rd.seek(SeekFrom::Start(ofs_pose))?;
for (pose, pose_n) in
read::hunk(rd, num_pose * 4 * 22)?.chunks(4 * 22).zip(0..num_pose)
{
for pose in read::hunk(rd, num_pose * 4 * 22)?.chunks(4 * 22) {
let par = read::u32le_sz(pose, 0);
let msk = read::u32le_32(pose, 4);
let mut ofs = [0.0; 10];
let mut scl = [0.0; 10];
read::array(read::f32le_32, pose, &mut ofs, 4, 8);
read::array(read::f32le_32, pose, &mut scl, 4, 48);
let mut pose_mats = Vec::with_capacity(num_frms);
poses.push(Pose { par, msk, ofs, scl });
}
for _frame_num in 0..num_frms {
let mut ofs = ofs;
// calculate frame matrices
let mut frame = frames.iter();
let mut frames = Vec::with_capacity(num_frms);
for _ in 0..num_frms {
let mut frame_mats = Vec::with_capacity(num_pose);
for (pose, joint) in poses.iter().zip(joints.iter()) {
let mut ofs = pose.ofs;
for i in 0..10 {
if msk & 1 << i != 0 {
ofs[i] +=
f32::from(*frame.next().ok_or(Err::FrameCount)?) * scl[i];
if pose.msk & 1 << i != 0 {
let frm = f32::from(*frame.next().ok_or(Err::FrameCount)?);
ofs[i] += frm * pose.scl[i];
}
}
let mut mat = Mat4::from_scale_rotation_translation(
Vec3::new(ofs[7], ofs[8], ofs[9]),
Quat::from_xyzw(ofs[3], ofs[4], ofs[5], ofs[6]).normalize(),
Vec3::new(ofs[0], ofs[1], ofs[2]),
);
let xlt = Vec3::new(ofs[0], ofs[1], ofs[2]);
let rot =
Quat::from_xyzw(ofs[3], ofs[4], ofs[5], ofs[6]).normalize();
let scl = Vec3::new(ofs[7], ofs[8], ofs[9]);
let joint = &joints[pose_n];
let mut mat = Mat4::from_scale_rotation_translation(scl, rot, xlt);
if par & 0x8000_0000 == 0 {
let parent = joints.get(par).ok_or(Err::Parent)?;
if pose.par & 0x8000_0000 == 0 {
let parent = joints.get(pose.par).ok_or(Err::Parent)?;
mat = parent.mat * mat * joint.inv;
let parent = frame_mats.get(pose.par).ok_or(Err::Parent)?;
mat = *parent * mat;
} else {
mat = mat * joint.inv;
}
pose_mats.push(mat);
frame_mats.push(mat);
}
frames.push(pose_mats);
frames.push(frame_mats);
}
Ok((Self { meshes, frames, num_frms }, ModelData { vtx: vert_dat, idx: indx_dat }))
Ok((
Self { meshes, frames, num_frms },
ModelData { vtx: vert_dat, idx: indx_dat },
))
}
pub fn frame(&self, joint: usize, frame: usize) -> Option<Mat4> {
Some(*self.frames.get(joint)?.get(frame)?)
Some(*self.frames.get(frame)?.get(joint)?)
}
pub const fn num_frames(&self) -> usize {

11
source/framework/data/read.rs

@ -33,7 +33,16 @@ pub fn f32le_32(b: &[u8], p: usize) -> f32 {
}
pub fn f64le_64(b: &[u8], p: usize) -> f64 {
f64::from_le_bytes([b[p], b[p + 1], b[p + 2], b[p + 3], b[p + 4], b[p + 5], b[p + 6], b[p + 7]])
f64::from_le_bytes([
b[p],
b[p + 1],
b[p + 2],
b[p + 3],
b[p + 4],
b[p + 5],
b[p + 6],
b[p + 7],
])
}
pub fn array<'a, 'b, T>(

2
source/framework/data/uniforms.rs

@ -1,4 +1,4 @@
use glam::Mat4;
use crate::math::Mat4;
#[repr(C)]
pub struct Uniforms {

10
source/framework/data/vertex.rs

@ -1,10 +1,10 @@
use glam::{Vec3A, Vec4};
use crate::math::{Vec3, Vec4};
#[repr(C)]
#[repr(C, packed)]
pub struct Vertex {
pub pos: Vec3A,
pub tex: Vec3A,
pub nrm: Vec3A,
pub pos: Vec3,
pub tex: Vec3,
pub nrm: Vec3,
pub tan: Vec4,
pub idx: Vec4,
pub wgt: Vec4,

1
source/framework/lib.rs

@ -24,6 +24,7 @@ pub mod conf;
pub mod data;
pub mod defl;
pub mod hal;
pub mod math;
pub mod meta;
pub mod render;
pub mod vire;

11
source/framework/math.rs

@ -0,0 +1,11 @@
pub type Mat3 = glam::Mat3;
pub type Mat4 = glam::Mat4;
pub type Vec3 = glam::Vec3;
pub type Vec4 = glam::Vec4;
pub type Quat = glam::Quat;
pub const PI: f32 = std::f32::consts::PI;
pub const PI_2: f32 = PI / 2.0;
pub const TAU: f32 = PI * 2.0;
// EOF

18
source/framework/render/misc.rs

@ -1,6 +1,8 @@
use crate::data::{uniforms::Uniforms, vertex::Vertex};
use crate::{
data::{uniforms::Uniforms, vertex::Vertex},
math::Mat4,
};
use ash::vk;
use glam::Mat4;
use std::mem::size_of;
/// Returns the size of `data` as a `vk::DeviceSize`.
@ -57,37 +59,37 @@ pub const VTX_ATTR_DESC: [vk::VertexInputAttributeDescription; 7] = [
location: 1,
binding: 0,
format: vk::Format::R32G32B32_SFLOAT,
offset: 16,
offset: 12,
},
vk::VertexInputAttributeDescription {
location: 2,
binding: 0,
format: vk::Format::R32G32B32_SFLOAT,
offset: 32,
offset: 24,
},
vk::VertexInputAttributeDescription {
location: 3,
binding: 0,
format: vk::Format::R32G32B32A32_SFLOAT,
offset: 48,
offset: 36,
},
vk::VertexInputAttributeDescription {
location: 4,
binding: 0,
format: vk::Format::R32G32B32A32_SFLOAT,
offset: 64,
offset: 52,
},
vk::VertexInputAttributeDescription {
location: 5,
binding: 0,
format: vk::Format::R32G32B32A32_SFLOAT,
offset: 80,
offset: 68,
},
vk::VertexInputAttributeDescription {
location: 6,
binding: 0,
format: vk::Format::R32G32B32A32_SFLOAT,
offset: 96,
offset: 84,
},
];

6
source/framework/render/model.rs

@ -1,9 +1,9 @@
use crate::{
data,
math::Mat4,
render::{Buffer, CommandPool, Device, ErrAllocMem, GetDevice},
};
use ash::{version::DeviceV1_0, vk};
use glam::Mat4;
use std::rc::Rc;
#[derive(Error, Debug)]
@ -85,8 +85,8 @@ impl Model {
matrices
}
pub const fn num_frames(&self) -> usize {
self.model.num_frames()
pub const fn model(&self) -> &data::model::Model {
&self.model
}
}

36
source/main_test/entry.rs

@ -6,7 +6,9 @@ use ash::{version::DeviceV1_0, vk};
use blonkus_fw::{
conf,
data::{self, vfs},
hal, meta,
hal,
math::*,
meta,
render::{
self, misc, Buffer, CommandBuffers, CommandPool, DescriptorPool,
DescriptorSetLayout, Device, ErrAllocMem, Fence, Framebuffer, GetDevice,
@ -16,8 +18,7 @@ use blonkus_fw::{
},
vire,
};
use glam::{Mat4, Quat, Vec3, Vec4};
use std::{f32::consts::PI, io::Cursor, rc::Rc};
use std::{io::Cursor, rc::Rc};
struct SwapchainInfo<'a> {
device: Rc<Device>,
@ -193,12 +194,7 @@ impl<'a> SwapchainData<'a, '_> {
&[],
);
// TODO
for which in &[
"mesh0", "mesh1", "mesh2", "mesh3", "mesh4", "mesh5", "mesh6",
"mesh7", "mesh8", "mesh9", "mesh10", "mesh11", "mesh12",
"mesh13", "mesh14", "mesh15", "mesh16", "mesh17", "mesh18",
] {
for which in sc_info.model.model().keys() {
sc_info.model.draw(buf, which).unwrap();
}
@ -253,22 +249,19 @@ fn draw_frame<'b>(
let time_1 = time_ms as f32 / 1_000.0;
let pos = Vec3::new(0.0, /*f32::sin(time_1 / 2.0) * 0.5*/ 2.0, 0.0);
let pos = Vec3::new(0.0, 2.0, 0.0);
let rot = TAU * time_1 / 10.0;
let object = Mat4::from_scale_rotation_translation(
Vec3::new(0.025, 0.025, 0.025),
Quat::from_rotation_z(PI /*PI * 2.0 * time_1 / 10.0*/),
Vec3::splat(0.025),
Quat::from_rotation_z(rot),
pos,
);
let camera = Mat4::look_at_rh(
Vec3::new(1.0, 1.0, 2.0),
pos,
Vec3::new(0.0, 0.0, 1.0),
);
let camera = Mat4::look_at_rh(Vec3::new(1.0, 1.0, 2.0), pos, Vec3::Z);
let projec = Mat4::perspective_rh_gl(
PI * 2.0 / 4.0,
PI_2,
sc_data.swapchain.extent.width as f32
/ sc_data.swapchain.extent.height as f32,
0.01,
@ -279,9 +272,10 @@ fn draw_frame<'b>(
let (ufm_buf, bon_buf) = &sc_data.descriptor_pool.buffers[image_index];
ufm_buf.write_data(&[uniforms])?;
bon_buf.write_data(
&sc_data.info.model.frame_matrices((time_ms / 100 % sc_data.info.model.num_frames() as u128) as usize),
)?;
bon_buf.write_data(&sc_data.info.model.frame_matrices(
(time_ms / 16 % sc_data.info.model.model().num_frames() as u128)
as usize,
))?;
let wait_semaphores = [**image_avail_s];
let wait_stages = [vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT];

Loading…
Cancel
Save