mirror of
https://codeberg.org/icewind/vbsp-to-gltf.git
synced 2026-06-03 18:24:07 +02:00
store prop transforms as matrix instead of TRS
This commit is contained in:
parent
81672af828
commit
08650afed8
2 changed files with 11 additions and 29 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::materials::{load_material_fallback, MaterialData, TextureData};
|
use crate::materials::{load_material_fallback, MaterialData, TextureData};
|
||||||
use crate::pad_byte_vector;
|
use crate::pad_byte_vector;
|
||||||
use bytemuck::{Pod, Zeroable};
|
|
||||||
use gltf_json::buffer::View;
|
use gltf_json::buffer::View;
|
||||||
use gltf_json::image::MimeType;
|
use gltf_json::image::MimeType;
|
||||||
use gltf_json::material::{AlphaCutoff, AlphaMode, PbrBaseColorFactor, PbrMetallicRoughness};
|
use gltf_json::material::{AlphaCutoff, AlphaMode, PbrBaseColorFactor, PbrMetallicRoughness};
|
||||||
|
|
@ -11,24 +10,6 @@ use image::png::PngEncoder;
|
||||||
use image::{ColorType, DynamicImage, GenericImageView};
|
use image::{ColorType, DynamicImage, GenericImageView};
|
||||||
use tf_asset_loader::Loader;
|
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(
|
pub fn push_or_get_material(
|
||||||
buffer: &mut Vec<u8>,
|
buffer: &mut Vec<u8>,
|
||||||
gltf: &mut Root,
|
gltf: &mut Root,
|
||||||
|
|
|
||||||
21
src/main.rs
21
src/main.rs
|
|
@ -7,10 +7,10 @@ mod prop;
|
||||||
|
|
||||||
use crate::bsp::{bsp_models, push_bsp_model};
|
use crate::bsp::{bsp_models, push_bsp_model};
|
||||||
use crate::prop::push_or_get_model;
|
use crate::prop::push_or_get_model;
|
||||||
|
use cgmath::Matrix4;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
use gltf::Glb;
|
use gltf::Glb;
|
||||||
use gltf_json::scene::UnitQuaternion;
|
|
||||||
use gltf_json::{Buffer, Index, Node, Root, Scene};
|
use gltf_json::{Buffer, Index, Node, Root, Scene};
|
||||||
use miette::Context;
|
use miette::Context;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
@ -81,24 +81,25 @@ fn export(bsp: Bsp, loader: &Loader) -> Result<Glb<'static>, Error> {
|
||||||
|
|
||||||
for prop in bsp.static_props() {
|
for prop in bsp.static_props() {
|
||||||
let mesh = push_or_get_model(&mut buffer, &mut root, loader, prop.model(), prop.skin);
|
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 {
|
let node = Node {
|
||||||
camera: None,
|
camera: None,
|
||||||
children: None,
|
children: None,
|
||||||
extensions: Default::default(),
|
extensions: Default::default(),
|
||||||
extras: 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),
|
mesh: Some(mesh),
|
||||||
name: None,
|
name: None,
|
||||||
rotation: Some(UnitQuaternion([
|
rotation: None,
|
||||||
rotation.v.x,
|
|
||||||
rotation.v.y,
|
|
||||||
rotation.v.z,
|
|
||||||
rotation.s,
|
|
||||||
])),
|
|
||||||
scale: None,
|
scale: None,
|
||||||
translation: Some(map_coords(prop.origin)),
|
translation: None,
|
||||||
skin: None,
|
skin: None,
|
||||||
weights: None,
|
weights: None,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue