mirror of
https://codeberg.org/icewind/vbspview.git
synced 2026-06-03 10:14:10 +02:00
bumb maps
This commit is contained in:
parent
21b4b19e0c
commit
e4b884f680
4 changed files with 19 additions and 12 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
|
@ -2399,7 +2399,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steamy-vdf"
|
name = "steamy-vdf"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/icewind1991/steamy?branch=nom7#56b737b329ec27c198669d1f4fef9d827be80470"
|
source = "git+https://github.com/icewind1991/steamy?branch=nom7#7f9b91c42f857f13bd45a16c7bab1972dafe26d1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nom",
|
"nom",
|
||||||
]
|
]
|
||||||
|
|
@ -2895,7 +2895,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vmdl"
|
name = "vmdl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/icewind1991/vmdl#9e2ca40d297db90c65d832ee6f31099b74dc224b"
|
source = "git+https://github.com/icewind1991/vmdl#922699a0898fcfc324f3ddb0db7af06bccf52124"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.4",
|
"arrayvec 0.7.4",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
|
|
@ -3323,9 +3323,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winnow"
|
name = "winnow"
|
||||||
version = "0.5.27"
|
version = "0.5.28"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cb877ca3232bec99a6472ed63f7241de2a250165260908b2d24c09d867907a85"
|
checksum = "6c830786f7720c2fd27a1a0e27a709dbd3c4d009b56d098fc742d4f4eab91fe2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ fn face_to_mesh(face: &Handle<Face>) -> CpuMesh {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
mesh.compute_normals();
|
mesh.compute_normals();
|
||||||
|
mesh.compute_tangents();
|
||||||
mesh
|
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(
|
pub fn load_material(
|
||||||
name: &str,
|
name: &str,
|
||||||
search_dirs: &[String],
|
search_dirs: &[String],
|
||||||
|
|
@ -73,13 +77,7 @@ pub fn load_material(
|
||||||
.next()
|
.next()
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(Error::Other("empty vmt"))?;
|
.ok_or(Error::Other("empty vmt"))?;
|
||||||
let base_texture = table
|
let base_texture = get_path(&table, "$basetexture").ok_or(Error::Other("no $basetexture"))?;
|
||||||
.lookup("$basetexture")
|
|
||||||
.ok_or(Error::Other("no $basetexture"))?
|
|
||||||
.as_str()
|
|
||||||
.ok_or(Error::Other("$basetexture not a string"))?
|
|
||||||
.replace('\\', "/")
|
|
||||||
.replace('\t', "/t");
|
|
||||||
|
|
||||||
let translucent = table
|
let translucent = table
|
||||||
.lookup("$translucent")
|
.lookup("$translucent")
|
||||||
|
|
@ -105,11 +103,16 @@ pub fn load_material(
|
||||||
.and_then(|val| f32::from_str(val).ok())
|
.and_then(|val| f32::from_str(val).ok())
|
||||||
.unwrap_or(1.0);
|
.unwrap_or(1.0);
|
||||||
|
|
||||||
|
let bump_map = get_path(&table, "$bumpmap")
|
||||||
|
.map(|path| load_texture(&path, loader, true).ok())
|
||||||
|
.flatten();
|
||||||
|
|
||||||
Ok(CpuMaterial {
|
Ok(CpuMaterial {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
albedo: Color::WHITE,
|
albedo: Color::WHITE,
|
||||||
albedo_texture: Some(texture),
|
albedo_texture: Some(texture),
|
||||||
alpha_cutout: alpha_test.then_some(alpha_cutout),
|
alpha_cutout: alpha_test.then_some(alpha_cutout),
|
||||||
|
normal_texture: bump_map,
|
||||||
..CpuMaterial::default()
|
..CpuMaterial::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use crate::material::load_material_fallback;
|
||||||
use crate::{Error, Loader};
|
use crate::{Error, Loader};
|
||||||
use cgmath::{Matrix, SquareMatrix};
|
use cgmath::{Matrix, SquareMatrix};
|
||||||
use std::collections::HashMap;
|
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 tracing::warn;
|
||||||
use vbsp::{Handle, StaticPropLump};
|
use vbsp::{Handle, StaticPropLump};
|
||||||
use vmdl::mdl::{Mdl, TextureInfo};
|
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())
|
.map(|vertex| vertex.texture_coordinates.into())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let tangents: Vec<Vec4> = mesh.tangents().map(|tangent| tangent.into()).collect();
|
||||||
|
|
||||||
CpuMesh {
|
CpuMesh {
|
||||||
positions: Positions::F32(positions),
|
positions: Positions::F32(positions),
|
||||||
normals: Some(normals),
|
normals: Some(normals),
|
||||||
uvs: Some(uvs),
|
uvs: Some(uvs),
|
||||||
material_name: Some(texture.into()),
|
material_name: Some(texture.into()),
|
||||||
|
tangents: Some(tangents),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue