mirror of
https://codeberg.org/icewind/vmdl.git
synced 2026-06-03 16:44:11 +02:00
fix indexes
This commit is contained in:
parent
3649ffd9b2
commit
4876ccf0f4
4 changed files with 36 additions and 6 deletions
|
|
@ -6,7 +6,7 @@ use three_d::*;
|
||||||
use vmdl::mdl::Mdl;
|
use vmdl::mdl::Mdl;
|
||||||
use vmdl::vtx::Vtx;
|
use vmdl::vtx::Vtx;
|
||||||
use vmdl::vvd::Vvd;
|
use vmdl::vvd::Vvd;
|
||||||
use vmdl::Model;
|
use vmdl::{Model, Vector};
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
enum Error {
|
enum Error {
|
||||||
|
|
@ -62,7 +62,7 @@ fn main() -> Result<(), Error> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut model = three_d::Model::new_with_material(&context, &cpu_mesh, material)?;
|
let mut model = three_d::Model::new_with_material(&context, &cpu_mesh, material)?;
|
||||||
model.set_transformation(Mat4::from_angle_x(degrees(90.0)));
|
model.set_transformation(Mat4::from_angle_x(degrees(-90.0)));
|
||||||
|
|
||||||
let mut lights = Lights {
|
let mut lights = Lights {
|
||||||
ambient: Some(AmbientLight {
|
ambient: Some(AmbientLight {
|
||||||
|
|
@ -71,8 +71,8 @@ fn main() -> Result<(), Error> {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
directional: vec![
|
directional: vec![
|
||||||
DirectionalLight::new(&context, 1.0, Color::WHITE, &vec3(0.0, -1.0, 0.0))?,
|
DirectionalLight::new(&context, 1.0, Color::WHITE, &vec3(1.0, -1.0, 0.0))?,
|
||||||
DirectionalLight::new(&context, 1.0, Color::WHITE, &vec3(0.0, 1.0, 0.0))?,
|
DirectionalLight::new(&context, 1.0, Color::WHITE, &vec3(1.0, 1.0, 0.0))?,
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
@ -224,10 +224,26 @@ fn load(path: &Path) -> Result<Model, vmdl::ModelError> {
|
||||||
const UNIT_SCALE: f32 = 1.0 / (1.905 * 100.0);
|
const UNIT_SCALE: f32 = 1.0 / (1.905 * 100.0);
|
||||||
|
|
||||||
fn model_to_mesh(model: &Model) -> CPUMesh {
|
fn model_to_mesh(model: &Model) -> CPUMesh {
|
||||||
|
let offset = model
|
||||||
|
.vertices()
|
||||||
|
.iter()
|
||||||
|
.map(|vert| vert.position.z)
|
||||||
|
.max_by(|a, b| a.partial_cmp(b).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
let offset = Vector {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
z: -offset / 2.0,
|
||||||
|
};
|
||||||
|
|
||||||
let positions: Vec<f32> = model
|
let positions: Vec<f32> = model
|
||||||
.vertices()
|
.vertices()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|vertex| vertex.position.iter().map(|pos| pos * UNIT_SCALE * 10.0))
|
.flat_map(|vertex| {
|
||||||
|
(vertex.position + offset)
|
||||||
|
.iter()
|
||||||
|
.map(|pos| pos * UNIT_SCALE * 10.0)
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let normals: Vec<f32> = model
|
let normals: Vec<f32> = model
|
||||||
.vertices()
|
.vertices()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use arrayvec::ArrayString;
|
||||||
use binrw::{BinResult, ReadOptions};
|
use binrw::{BinResult, ReadOptions};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
use std::ops::Add;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, BinRead)]
|
#[derive(Debug, Clone, Copy, BinRead)]
|
||||||
pub struct Vector {
|
pub struct Vector {
|
||||||
|
|
@ -39,6 +40,18 @@ impl From<&Vector> for [f32; 3] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Add<Vector> for Vector {
|
||||||
|
type Output = Vector;
|
||||||
|
|
||||||
|
fn add(self, rhs: Vector) -> Self::Output {
|
||||||
|
Vector {
|
||||||
|
x: self.x + rhs.x,
|
||||||
|
y: self.y + rhs.y,
|
||||||
|
z: self.z + rhs.z,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, BinRead)]
|
#[derive(Debug, Clone, BinRead)]
|
||||||
pub struct Quaternion {
|
pub struct Quaternion {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
|
|
|
||||||
|
|
@ -214,6 +214,7 @@ impl Strip {
|
||||||
|
|
||||||
pub fn indices(&self) -> impl Iterator<Item = [usize; 3]> + 'static {
|
pub fn indices(&self) -> impl Iterator<Item = [usize; 3]> + 'static {
|
||||||
if self.flags.contains(StripFlags::IS_TRI_STRIP) {
|
if self.flags.contains(StripFlags::IS_TRI_STRIP) {
|
||||||
|
dbg!("strip");
|
||||||
let offset = self.indices.start;
|
let offset = self.indices.start;
|
||||||
Either::Left((0..self.indices.len()).map(move |i| {
|
Either::Left((0..self.indices.len()).map(move |i| {
|
||||||
let cw = i & 1;
|
let cw = i & 1;
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ impl StripGroupHeader {
|
||||||
index_range(
|
index_range(
|
||||||
self.vertex_offset,
|
self.vertex_offset,
|
||||||
self.vertex_count,
|
self.vertex_count,
|
||||||
size_of::<u16>(), // Vertex index from .VVD's vertex array
|
size_of::<Vertex>(), // Vertex index from .VVD's vertex array
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue