summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-21 17:59:19 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-21 17:59:19 +0100
commit8ec1b82052cfe6d73be988a7e22a10fdc8f6e1f3 (patch)
tree4b57875d5a568b849cdb260540e7410303f9d776 /client
parent51f5c31108ffa00381b6cd7c9d32d6a332356267 (diff)
downloadweareserver-8ec1b82052cfe6d73be988a7e22a10fdc8f6e1f3.tar
weareserver-8ec1b82052cfe6d73be988a7e22a10fdc8f6e1f3.tar.bz2
weareserver-8ec1b82052cfe6d73be988a7e22a10fdc8f6e1f3.tar.zst
fix tangent generation for missing uvs
Diffstat (limited to 'client')
-rw-r--r--client/src/meshops.rs8
-rw-r--r--client/src/scene_prepare.rs14
2 files changed, 15 insertions, 7 deletions
diff --git a/client/src/meshops.rs b/client/src/meshops.rs
index 38c6c7b..afa50ce 100644
--- a/client/src/meshops.rs
+++ b/client/src/meshops.rs
@@ -1,4 +1,4 @@
-use glam::{Vec2, Vec3};
+use glam::{Vec2, Vec3, vec2};
pub fn generate_normals(index: &[[u32; 3]], position: &[Vec3]) -> Vec<Vec3> {
let mut normal_denom = vec![0; position.len()];
@@ -58,6 +58,8 @@ pub fn generate_tangents(index: &[[u32; 3]], position: &[Vec3], texcoord: &[Vec2
pub fn generate_texcoords(index: &[[u32; 3]], position: &[Vec3]) -> Vec<Vec2> {
let _ = (index, position);
- // TODO implement equirectangular projection
- todo!()
+ // TODO implement equirectangular projection or something
+ (0..position.len())
+ .map(|i| vec2(i as f32 * 0.01, 0.))
+ .collect()
}
diff --git a/client/src/scene_prepare.rs b/client/src/scene_prepare.rs
index 0e65e72..3a93485 100644
--- a/client/src/scene_prepare.rs
+++ b/client/src/scene_prepare.rs
@@ -120,7 +120,7 @@ pub struct RMeshPart {
struct TangentBufferSpec {
index: Resource<Vec<[u32; 3]>>,
position: Resource<Vec<Vec3>>,
- texcoord: Resource<Vec<Vec2>>,
+ texcoord: Option<Resource<Vec<Vec2>>>,
}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -280,11 +280,17 @@ impl ScenePreparer {
num_done += 1;
}
for spec in self.generated_tangent_buffers.needed() {
- if let (Some(index), Some(position), Some(texcoord)) = (
+ if let (Some(index), Some(position), texcoord) = (
dls.try_get(spec.index.clone())?,
dls.try_get(spec.position.clone())?,
- dls.try_get(spec.texcoord.clone())?,
+ spec.texcoord.clone().map(|r| dls.try_get(r)).transpose()?,
) {
+ let texcoord = match texcoord {
+ Some(Some(x)) => Some(x),
+ Some(None) => continue, // tangents provided but still loading
+ None => None,
+ };
+ let texcoord = texcoord.unwrap_or_else(|| generate_texcoords(&index, &position));
let tangents = generate_tangents(&index, &position, &texcoord);
let buffer = self.device.create_buffer_init(&BufferInitDescriptor {
label: Some("generated tangent"),
@@ -382,7 +388,7 @@ impl ScenePreparer {
self.generated_tangent_buffers.try_get(TangentBufferSpec {
index: indexres,
position: Resource(positionres.0, PhantomData),
- texcoord: part.va_texcoord.expect("TODO"),
+ texcoord: part.va_texcoord,
})
};