mirror of
https://codeberg.org/icewind/vmdl.git
synced 2026-06-03 08:34:23 +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"
|
||||
license = "MIT"
|
||||
exclude = ["data"]
|
||||
rust-version = "1.76.0"
|
||||
rust-version = "1.80.1"
|
||||
|
||||
[dependencies]
|
||||
arrayvec = "0.7.6"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
use cgmath::Matrix4;
|
||||
use std::env::args;
|
||||
use std::fs;
|
||||
use std::hint::black_box;
|
||||
use std::path::PathBuf;
|
||||
use vmdl::mdl::Mdl;
|
||||
use vmdl::vtx::Vtx;
|
||||
|
|
@ -32,7 +30,7 @@ fn main() -> Result<(), vmdl::ModelError> {
|
|||
"{}: {} frames at {}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);
|
||||
println!(
|
||||
"\tbone {:.2} frame 0:\n\t\ttrans: {:?}\n\t\tpos: {:?}",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ mod material;
|
|||
|
||||
use crate::error::Error;
|
||||
use crate::material::{load_material_fallback, MaterialData};
|
||||
use cgmath::{vec3, Matrix4, SquareMatrix, Vector3};
|
||||
use cgmath::{vec3, Matrix4, SquareMatrix};
|
||||
use std::collections::HashMap;
|
||||
use std::env::args_os;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -53,7 +53,7 @@ fn main() -> Result<(), Error> {
|
|||
let context = window.gl();
|
||||
|
||||
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(
|
||||
window.viewport(),
|
||||
|
|
@ -301,7 +301,7 @@ fn model_to_model(
|
|||
let positions: Vec<Vec3> = mesh
|
||||
.vertices()
|
||||
.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())
|
||||
.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(
|
||||
frame: usize,
|
||||
animation_value_pointers: AnimationValuePointers,
|
||||
debug: bool,
|
||||
) -> Result<[f32; 3], ModelError> {
|
||||
let [x, y, z] = animation_value_pointers
|
||||
.offsets
|
||||
|
|
@ -196,10 +195,7 @@ fn read_animation_values(
|
|||
Ok(0)
|
||||
} else {
|
||||
let values: FrameValues = read_single(animation_value_pointers.data, offset)?;
|
||||
if debug {
|
||||
println!("frame {frame}");
|
||||
}
|
||||
Ok(values.get(frame as u8, debug)?)
|
||||
Ok(values.get(frame as u8)?)
|
||||
}
|
||||
});
|
||||
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> {
|
||||
Ok(FrameValues {
|
||||
header,
|
||||
data: &data
|
||||
data: data
|
||||
.get(size_of::<ValueHeader>()..)
|
||||
.ok_or(ModelError::OutOfBounds {
|
||||
data: "animation frame data",
|
||||
|
|
@ -425,7 +421,7 @@ fn read_animation(
|
|||
let pointers: AnimationValuePointers = read_single(data, offset)?;
|
||||
println!("bone: {}", header.bone);
|
||||
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 })
|
||||
.collect::<Result<_, ModelError>>()?;
|
||||
RotationData::from(values)
|
||||
|
|
@ -439,7 +435,7 @@ fn read_animation(
|
|||
} else if header.flags.contains(AnimationFlags::STUDIO_ANIM_ANIMPOS) {
|
||||
let pointers: AnimationValuePointers = read_single(data, position_offset)?;
|
||||
let values = (0..frames)
|
||||
.map(|frame| read_animation_values(frame, pointers, false))
|
||||
.map(|frame| read_animation_values(frame, pointers))
|
||||
.map_ok(Vector::from)
|
||||
.collect::<Result<_, ModelError>>()?;
|
||||
PositionData::PositionValues(values)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue