mirror of
https://codeberg.org/icewind/vbspview.git
synced 2026-06-03 18:24:09 +02:00
bumb maps
This commit is contained in:
parent
21b4b19e0c
commit
e4b884f680
4 changed files with 19 additions and 12 deletions
|
|
@ -47,6 +47,7 @@ fn face_to_mesh(face: &Handle<Face>) -> CpuMesh {
|
|||
..Default::default()
|
||||
};
|
||||
mesh.compute_normals();
|
||||
mesh.compute_tangents();
|
||||
mesh
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ pub fn load_material_fallback(name: &str, search_dirs: &[String], loader: &Loade
|
|||
}
|
||||
}
|
||||
|
||||
fn get_path(vmt: &Entry, name: &str) -> Option<String> {
|
||||
Some(vmt.lookup(name)?.as_str()?.replace('\\', "/"))
|
||||
}
|
||||
|
||||
pub fn load_material(
|
||||
name: &str,
|
||||
search_dirs: &[String],
|
||||
|
|
@ -73,13 +77,7 @@ pub fn load_material(
|
|||
.next()
|
||||
.cloned()
|
||||
.ok_or(Error::Other("empty vmt"))?;
|
||||
let base_texture = table
|
||||
.lookup("$basetexture")
|
||||
.ok_or(Error::Other("no $basetexture"))?
|
||||
.as_str()
|
||||
.ok_or(Error::Other("$basetexture not a string"))?
|
||||
.replace('\\', "/")
|
||||
.replace('\t', "/t");
|
||||
let base_texture = get_path(&table, "$basetexture").ok_or(Error::Other("no $basetexture"))?;
|
||||
|
||||
let translucent = table
|
||||
.lookup("$translucent")
|
||||
|
|
@ -105,11 +103,16 @@ pub fn load_material(
|
|||
.and_then(|val| f32::from_str(val).ok())
|
||||
.unwrap_or(1.0);
|
||||
|
||||
let bump_map = get_path(&table, "$bumpmap")
|
||||
.map(|path| load_texture(&path, loader, true).ok())
|
||||
.flatten();
|
||||
|
||||
Ok(CpuMaterial {
|
||||
name: name.into(),
|
||||
albedo: Color::WHITE,
|
||||
albedo_texture: Some(texture),
|
||||
alpha_cutout: alpha_test.then_some(alpha_cutout),
|
||||
normal_texture: bump_map,
|
||||
..CpuMaterial::default()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::material::load_material_fallback;
|
|||
use crate::{Error, Loader};
|
||||
use cgmath::{Matrix, SquareMatrix};
|
||||
use std::collections::HashMap;
|
||||
use three_d::{CpuMaterial, CpuMesh, CpuModel, Mat4, Positions, Vec2, Vec3};
|
||||
use three_d::{CpuMaterial, CpuMesh, CpuModel, Mat4, Positions, Vec2, Vec3, Vec4};
|
||||
use tracing::warn;
|
||||
use vbsp::{Handle, StaticPropLump};
|
||||
use vmdl::mdl::{Mdl, TextureInfo};
|
||||
|
|
@ -91,11 +91,14 @@ fn prop_to_meshes(prop: &PropData) -> impl Iterator<Item = CpuMesh> + '_ {
|
|||
.map(|vertex| vertex.texture_coordinates.into())
|
||||
.collect();
|
||||
|
||||
let tangents: Vec<Vec4> = mesh.tangents().map(|tangent| tangent.into()).collect();
|
||||
|
||||
CpuMesh {
|
||||
positions: Positions::F32(positions),
|
||||
normals: Some(normals),
|
||||
uvs: Some(uvs),
|
||||
material_name: Some(texture.into()),
|
||||
tangents: Some(tangents),
|
||||
..Default::default()
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue