This commit is contained in:
Robin Appelman 2024-08-29 13:30:17 +02:00
commit 51e767a306
6 changed files with 15 additions and 66 deletions

View file

@ -20,6 +20,7 @@ pub fn load_material_fallback(name: &str, search_dirs: &[String], loader: &Loade
}
#[derive(Default, Debug)]
#[allow(dead_code)]
pub struct MaterialData {
pub name: String,
pub path: String,

View file

@ -9,7 +9,7 @@ use gltf_json::texture::Info;
use gltf_json::validation::Checked::Valid;
use gltf_json::{Accessor, Extras, Image, Index, Material, Mesh, Texture, Value};
use image::codecs::png::PngEncoder;
use image::GenericImageView;
use image::ImageEncoder;
use std::mem::size_of;
use vmdl::Model;
@ -287,7 +287,7 @@ fn push_texture(
let mut png_buffer = Vec::new();
let encoder = PngEncoder::new(&mut png_buffer);
encoder
.encode(
.write_image(
image.as_bytes(),
image.width(),
image.height(),

View file

@ -1,11 +1,10 @@
use cgmath::{Euler, Matrix4};
use std::env::args;
use std::fs;
use std::path::PathBuf;
use vmdl::mdl::Mdl;
use vmdl::vtx::Vtx;
use vmdl::vvd::Vvd;
use vmdl::{Model, Quaternion};
use vmdl::Model;
fn main() -> Result<(), vmdl::ModelError> {
let mut args = args();
@ -19,40 +18,16 @@ fn main() -> Result<(), vmdl::ModelError> {
let data = fs::read(path.with_extension("vvd"))?;
let vvd = Vvd::read(&data)?;
// dbg!(&mdl.header);
for bone in &mdl.bones {
println!(
"{}: from {} at\n\t{:?}\n\t{:?}\n\t{:?}\n\t{:?}",
bone.name, bone.parent, bone.rot, bone.rot_scale, bone.quaternion, bone.pose_to_bone
);
}
// for bone in &mdl.bones {
// println!(
// "{}: from {} at\n\t{:?}\n\t{:?}\n\t{:?}\n\t{:?}",
// bone.name, bone.parent, bone.rot, bone.rot_scale, bone.quaternion, bone.pose_to_bone
// );
// }
// dbg!(&mdl.bones[0]);
dbg!(&mdl.local_animations[0].animations[0]);
let transform = mdl
.local_animations
.get(0)
.map(|a| a.animations[0].rotation(0))
.unwrap();
dbg!(transform);
dbg!(Euler::from(cgmath::Quaternion::from(transform)));
// dbg!(&mdl.body_table_by_name);
// dbg!(&mdl.attachments);
let model = Model::from_parts(mdl, vtx, vvd);
dbg!(model.animations().nth(1).unwrap().get_bone_transform(1, 0));
// dbg!(model.root_transform());
// dbg!(model.idle_transform());
// dbg!(Euler::from(cgmath::Quaternion::from(
// model.idle_transform()
// )));
// dbg!(Euler::from(Quaternion::from(model.root_transform())));
// for strip in model.vertex_strips() {
// for vertex in strip {
// println!("{:?}", vertex);
// }
// println!("")
// }
dbg!(model.root_transform());
dbg!(model.idle_transform());
Ok(())
}

View file

@ -5,13 +5,11 @@ mod material;
use crate::error::Error;
use crate::material::{load_material_fallback, MaterialData};
use image::GenericImageView;
use std::env::args_os;
use std::path::PathBuf;
use tf_asset_loader::Loader;
use thiserror::Error;
use three_d::*;
use vmdl::{Model, Vector};
use vmdl::Model;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[allow(missing_docs)]
@ -241,13 +239,6 @@ pub fn map_coords<C: Into<Vec3>>(vec: C) -> Vec3 {
}
fn model_to_model(model: &Model, loader: &Loader, skin: usize) -> CpuModel {
let bounds = model.bounding_box();
let offset = Vector {
x: -(bounds.1.x + bounds.0.x) / 2.0,
y: -(bounds.1.y + bounds.0.y) / 2.0,
z: -(bounds.1.z + bounds.0.z) / 2.0,
};
let skin = model.skin_tables().nth(skin).unwrap();
let transforms = Matrix4::identity();