mirror of
https://codeberg.org/icewind/vmdl.git
synced 2026-06-03 16:44:11 +02:00
cleanup
This commit is contained in:
parent
2dffd8d7cd
commit
51e767a306
6 changed files with 15 additions and 66 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
20
src/lib.rs
20
src/lib.rs
|
|
@ -145,12 +145,7 @@ impl Model {
|
|||
|
||||
self.bones()
|
||||
.next()
|
||||
.map(|bone| {
|
||||
// let inv = Matrix4::from(bone.pose_to_bone)
|
||||
// .inverse_transform()
|
||||
// .unwrap();
|
||||
Matrix4::from(bone.rot)
|
||||
})
|
||||
.map(|bone| Matrix4::from(bone.rot))
|
||||
.unwrap_or_else(Matrix4::identity)
|
||||
}
|
||||
|
||||
|
|
@ -183,19 +178,6 @@ impl Model {
|
|||
.transform_vector(Vector3::from(vertex.position))
|
||||
.into()
|
||||
}
|
||||
|
||||
fn bone_transform(
|
||||
&self,
|
||||
bone_id: u8,
|
||||
bone: &Bone,
|
||||
animation: &AnimationDescription,
|
||||
weight: f32,
|
||||
frame: usize,
|
||||
) -> Matrix4<f32> {
|
||||
let animation_transform = weight * animation.get_bone_transform(bone_id, frame);
|
||||
let bone_origin = Matrix4::from(bone.pose_to_bone);
|
||||
bone_origin.inverse_transform().unwrap() * animation_transform * bone_origin
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SkinTable<'a> {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl Vector {
|
|||
|
||||
pub fn transformed<T: Into<Matrix4<f32>>>(&self, transform: T) -> Vector {
|
||||
let transform = transform.into();
|
||||
transform.transform_vector(self.clone().into()).into()
|
||||
transform.transform_vector((*self).into()).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue