mirror of
https://codeberg.org/icewind/vmdl.git
synced 2026-06-04 00:54:14 +02:00
fixes
This commit is contained in:
parent
4722ce296e
commit
74d0a389e6
4 changed files with 9 additions and 15 deletions
|
|
@ -6,7 +6,7 @@ description = "Rust parser for valve model files."
|
||||||
repository = "https://github.com/icewind1991/vmdl"
|
repository = "https://github.com/icewind1991/vmdl"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
exclude = ["data"]
|
exclude = ["data"]
|
||||||
rust-version = "1.76.0"
|
rust-version = "1.80.1"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = "0.7.6"
|
arrayvec = "0.7.6"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
use cgmath::Matrix4;
|
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::hint::black_box;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use vmdl::mdl::Mdl;
|
use vmdl::mdl::Mdl;
|
||||||
use vmdl::vtx::Vtx;
|
use vmdl::vtx::Vtx;
|
||||||
|
|
@ -32,7 +30,7 @@ fn main() -> Result<(), vmdl::ModelError> {
|
||||||
"{}: {} frames at {}fps",
|
"{}: {} frames at {}fps",
|
||||||
animation_desc.name, animation_desc.frame_count, animation_desc.fps,
|
animation_desc.name, animation_desc.frame_count, animation_desc.fps,
|
||||||
);
|
);
|
||||||
for animation in &animation_desc.animations.first() {
|
for animation in &animation_desc.animations {
|
||||||
dbg!(animation.flags);
|
dbg!(animation.flags);
|
||||||
println!(
|
println!(
|
||||||
"\tbone {:.2} frame 0:\n\t\ttrans: {:?}\n\t\tpos: {:?}",
|
"\tbone {:.2} frame 0:\n\t\ttrans: {:?}\n\t\tpos: {:?}",
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ mod material;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::material::{load_material_fallback, MaterialData};
|
use crate::material::{load_material_fallback, MaterialData};
|
||||||
use cgmath::{vec3, Matrix4, SquareMatrix, Vector3};
|
use cgmath::{vec3, Matrix4, SquareMatrix};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env::args_os;
|
use std::env::args_os;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
@ -53,7 +53,7 @@ fn main() -> Result<(), Error> {
|
||||||
let context = window.gl();
|
let context = window.gl();
|
||||||
|
|
||||||
let (bb_min, bb_max) = source_model.bounding_box();
|
let (bb_min, bb_max) = source_model.bounding_box();
|
||||||
let bb_center = Vector3::from(map_coords((bb_min + bb_max) * 0.5));
|
let bb_center = map_coords((bb_min + bb_max) * 0.5);
|
||||||
|
|
||||||
let mut camera = Camera::new_perspective(
|
let mut camera = Camera::new_perspective(
|
||||||
window.viewport(),
|
window.viewport(),
|
||||||
|
|
@ -301,7 +301,7 @@ fn model_to_model(
|
||||||
let positions: Vec<Vec3> = mesh
|
let positions: Vec<Vec3> = mesh
|
||||||
.vertices()
|
.vertices()
|
||||||
.map(|vertex| model.apply_animation(animation, vertex, frame))
|
.map(|vertex| model.apply_animation(animation, vertex, frame))
|
||||||
.map(|position| map_coords(position))
|
.map(map_coords)
|
||||||
.map(|vertex: Vec3| (transforms * vertex.extend(1.0)).truncate())
|
.map(|vertex: Vec3| (transforms * vertex.extend(1.0)).truncate())
|
||||||
.collect();
|
.collect();
|
||||||
let normals: Vec<Vec3> = mesh.vertices().map(|vertex| vertex.normal.into()).collect();
|
let normals: Vec<Vec3> = mesh.vertices().map(|vertex| vertex.normal.into()).collect();
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,6 @@ impl ReadableRelative for ValueHeader {}
|
||||||
fn read_animation_values(
|
fn read_animation_values(
|
||||||
frame: usize,
|
frame: usize,
|
||||||
animation_value_pointers: AnimationValuePointers,
|
animation_value_pointers: AnimationValuePointers,
|
||||||
debug: bool,
|
|
||||||
) -> Result<[f32; 3], ModelError> {
|
) -> Result<[f32; 3], ModelError> {
|
||||||
let [x, y, z] = animation_value_pointers
|
let [x, y, z] = animation_value_pointers
|
||||||
.offsets
|
.offsets
|
||||||
|
|
@ -196,10 +195,7 @@ fn read_animation_values(
|
||||||
Ok(0)
|
Ok(0)
|
||||||
} else {
|
} else {
|
||||||
let values: FrameValues = read_single(animation_value_pointers.data, offset)?;
|
let values: FrameValues = read_single(animation_value_pointers.data, offset)?;
|
||||||
if debug {
|
Ok(values.get(frame as u8)?)
|
||||||
println!("frame {frame}");
|
|
||||||
}
|
|
||||||
Ok(values.get(frame as u8, debug)?)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let [x, y, z] = [x?, y?, z?];
|
let [x, y, z] = [x?, y?, z?];
|
||||||
|
|
@ -228,7 +224,7 @@ impl<'a> ReadRelative<'a> for FrameValues<'a> {
|
||||||
fn read(data: &'a [u8], header: Self::Header) -> Result<Self, ModelError> {
|
fn read(data: &'a [u8], header: Self::Header) -> Result<Self, ModelError> {
|
||||||
Ok(FrameValues {
|
Ok(FrameValues {
|
||||||
header,
|
header,
|
||||||
data: &data
|
data: data
|
||||||
.get(size_of::<ValueHeader>()..)
|
.get(size_of::<ValueHeader>()..)
|
||||||
.ok_or(ModelError::OutOfBounds {
|
.ok_or(ModelError::OutOfBounds {
|
||||||
data: "animation frame data",
|
data: "animation frame data",
|
||||||
|
|
@ -425,7 +421,7 @@ fn read_animation(
|
||||||
let pointers: AnimationValuePointers = read_single(data, offset)?;
|
let pointers: AnimationValuePointers = read_single(data, offset)?;
|
||||||
println!("bone: {}", header.bone);
|
println!("bone: {}", header.bone);
|
||||||
let values: Vec<RadianEuler> = (0..frames)
|
let values: Vec<RadianEuler> = (0..frames)
|
||||||
.map(|frame| read_animation_values(frame, pointers, header.bone == 0))
|
.map(|frame| read_animation_values(frame, pointers))
|
||||||
.map_ok(|[pitch, yaw, roll]| RadianEuler { pitch, yaw, roll })
|
.map_ok(|[pitch, yaw, roll]| RadianEuler { pitch, yaw, roll })
|
||||||
.collect::<Result<_, ModelError>>()?;
|
.collect::<Result<_, ModelError>>()?;
|
||||||
RotationData::from(values)
|
RotationData::from(values)
|
||||||
|
|
@ -439,7 +435,7 @@ fn read_animation(
|
||||||
} else if header.flags.contains(AnimationFlags::STUDIO_ANIM_ANIMPOS) {
|
} else if header.flags.contains(AnimationFlags::STUDIO_ANIM_ANIMPOS) {
|
||||||
let pointers: AnimationValuePointers = read_single(data, position_offset)?;
|
let pointers: AnimationValuePointers = read_single(data, position_offset)?;
|
||||||
let values = (0..frames)
|
let values = (0..frames)
|
||||||
.map(|frame| read_animation_values(frame, pointers, false))
|
.map(|frame| read_animation_values(frame, pointers))
|
||||||
.map_ok(Vector::from)
|
.map_ok(Vector::from)
|
||||||
.collect::<Result<_, ModelError>>()?;
|
.collect::<Result<_, ModelError>>()?;
|
||||||
PositionData::PositionValues(values)
|
PositionData::PositionValues(values)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue