1
0
Fork 0
mirror of https://codeberg.org/icewind/vbsp.git synced 2026-06-03 18:54:05 +02:00

fix texture transforms

This commit is contained in:
Robin Appelman 2023-12-15 20:45:56 +01:00
commit 160370b5f8
3 changed files with 16 additions and 10 deletions

View file

@ -172,8 +172,8 @@ impl<const LEN: usize> BinRead for FixedString<LEN> {
#[derive(Debug, Clone, BinRead)] #[derive(Debug, Clone, BinRead)]
pub struct TextureInfo { pub struct TextureInfo {
pub texture_scale: [f32; 4], pub texture_transforms_u: [f32; 4],
pub texture_transform: [f32; 4], pub texture_transform_v: [f32; 4],
pub light_map_scale: [f32; 4], pub light_map_scale: [f32; 4],
pub light_map_transform: [f32; 4], pub light_map_transform: [f32; 4],
pub flags: TextureFlags, pub flags: TextureFlags,

View file

@ -1,8 +1,8 @@
use super::Handle; use super::Handle;
use crate::data::*; use crate::data::*;
impl Handle<'_, StaticPropLump> { impl<'a> Handle<'a, StaticPropLump> {
pub fn model(&self) -> &str { pub fn model(&self) -> &'a str {
self.bsp.static_props.dict.name[self.prop_type as usize].as_str() self.bsp.static_props.dict.name[self.prop_type as usize].as_str()
} }
} }

View file

@ -64,6 +64,10 @@ impl<'a> Handle<'a, Model> {
.iter() .iter()
.map(move |face| Handle::new(bsp, face)) .map(move |face| Handle::new(bsp, face))
} }
pub fn textures(&self) -> impl Iterator<Item = Handle<'_, TextureInfo>> {
self.bsp.textures()
}
} }
impl Handle<'_, Node> { impl Handle<'_, Node> {
@ -128,16 +132,18 @@ impl<'a> Handle<'a, TextureInfo> {
} }
pub fn u(&self, pos: Vector) -> f32 { pub fn u(&self, pos: Vector) -> f32 {
(self.texture_scale[0] * pos.x (self.texture_transforms_u[0] * pos.x
+ self.texture_scale[1] * pos.y + self.texture_transforms_u[1] * pos.y
+ self.texture_scale[2] * pos.z) + self.texture_transforms_u[2] * pos.z
+ self.texture_transforms_u[3])
/ self.texture_data().width as f32 / self.texture_data().width as f32
} }
pub fn v(&self, pos: Vector) -> f32 { pub fn v(&self, pos: Vector) -> f32 {
(self.texture_transform[0] * pos.x (self.texture_transform_v[0] * pos.x
+ self.texture_transform[1] * pos.y + self.texture_transform_v[1] * pos.y
+ self.texture_transform[2] * pos.z) + self.texture_transform_v[2] * pos.z
+ self.texture_transform_v[3])
/ self.texture_data().height as f32 / self.texture_data().height as f32
} }