store prop transforms as matrix instead of TRS

This commit is contained in:
Robin Appelman 2023-12-21 17:06:09 +01:00
commit 08650afed8
2 changed files with 11 additions and 29 deletions

View file

@ -1,6 +1,5 @@
use crate::materials::{load_material_fallback, MaterialData, TextureData};
use crate::pad_byte_vector;
use bytemuck::{Pod, Zeroable};
use gltf_json::buffer::View;
use gltf_json::image::MimeType;
use gltf_json::material::{AlphaCutoff, AlphaMode, PbrBaseColorFactor, PbrMetallicRoughness};
@ -11,24 +10,6 @@ use image::png::PngEncoder;
use image::{ColorType, DynamicImage, GenericImageView};
use tf_asset_loader::Loader;
#[derive(Copy, Clone, Debug, Default, Zeroable, Pod)]
#[repr(C)]
pub struct Vertex {
position: [f32; 3],
normal: [f32; 3],
uv: [f32; 2],
}
impl From<&vmdl::vvd::Vertex> for Vertex {
fn from(vertex: &vmdl::vvd::Vertex) -> Self {
Vertex {
position: vertex.position.into(),
uv: vertex.texture_coordinates,
normal: vertex.normal.into(),
}
}
}
pub fn push_or_get_material(
buffer: &mut Vec<u8>,
gltf: &mut Root,

View file

@ -7,10 +7,10 @@ mod prop;
use crate::bsp::{bsp_models, push_bsp_model};
use crate::prop::push_or_get_model;
use cgmath::Matrix4;
use clap::Parser;
pub use error::Error;
use gltf::Glb;
use gltf_json::scene::UnitQuaternion;
use gltf_json::{Buffer, Index, Node, Root, Scene};
use miette::Context;
use std::borrow::Cow;
@ -81,24 +81,25 @@ fn export(bsp: Bsp, loader: &Loader) -> Result<Glb<'static>, Error> {
for prop in bsp.static_props() {
let mesh = push_or_get_model(&mut buffer, &mut root, loader, prop.model(), prop.skin);
let rotation = prop.rotation();
let matrix = Matrix4::from_translation(map_coords(prop.origin).into())
* Matrix4::from(prop.rotation());
let node = Node {
camera: None,
children: None,
extensions: Default::default(),
extras: Default::default(),
matrix: None,
matrix: Some([
matrix.x.x, matrix.x.y, matrix.x.z, matrix.x.w, matrix.y.x, matrix.y.y, matrix.y.z,
matrix.y.w, matrix.z.x, matrix.z.y, matrix.z.z, matrix.z.w, matrix.w.x, matrix.w.y,
matrix.w.z, matrix.w.w,
]),
mesh: Some(mesh),
name: None,
rotation: Some(UnitQuaternion([
rotation.v.x,
rotation.v.y,
rotation.v.z,
rotation.s,
])),
rotation: None,
scale: None,
translation: Some(map_coords(prop.origin)),
translation: None,
skin: None,
weights: None,
};