diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-19 16:51:37 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-19 16:51:37 +0100 |
commit | 2dd953715cd61ef66b0a9315ec8df68a37fe8885 (patch) | |
tree | a6bb56637f7e88bbf6121a10b1f65f7d1e021b57 /client/src/scene_prepare.rs | |
parent | 2d6f319dfccf6339ed1a3bbfb003b8b2dde82383 (diff) | |
download | weareserver-2dd953715cd61ef66b0a9315ec8df68a37fe8885.tar weareserver-2dd953715cd61ef66b0a9315ec8df68a37fe8885.tar.bz2 weareserver-2dd953715cd61ef66b0a9315ec8df68a37fe8885.tar.zst |
client: generate normals
Diffstat (limited to 'client/src/scene_prepare.rs')
-rw-r--r-- | client/src/scene_prepare.rs | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/client/src/scene_prepare.rs b/client/src/scene_prepare.rs index 8941fa7..4cf6c87 100644 --- a/client/src/scene_prepare.rs +++ b/client/src/scene_prepare.rs @@ -14,10 +14,13 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use crate::{download::Downloader, meshops::generate_tangents}; +use crate::{ + download::Downloader, + meshops::{generate_normals, generate_tangents, generate_texcoords}, +}; use anyhow::Result; use egui::{Grid, Widget}; -use glam::{Vec2, Vec3, Vec3A}; +use glam::{Vec2, Vec3}; use humansize::DECIMAL; use image::ImageReader; use log::{debug, trace}; @@ -119,12 +122,12 @@ struct TangentBufferSpec { #[derive(Debug, Clone, Hash, PartialEq, Eq)] struct NormalBufferSpec { index: Resource<Vec<[u32; 3]>>, - position: Resource<Vec<Vec3A>>, + position: Resource<Vec<Vec3>>, } #[derive(Debug, Clone, Hash, PartialEq, Eq)] struct TexcoordBufferSpec { index: Resource<Vec<[u32; 3]>>, - position: Resource<Vec<Vec3A>>, + position: Resource<Vec<Vec3>>, } #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] @@ -260,6 +263,42 @@ impl ScenePreparer { ); } } + for spec in self.generated_normal_buffers.needed() { + if let (Some(index), Some(position)) = ( + dls.try_get(spec.index.clone())?, + dls.try_get(spec.position.clone())?, + ) { + let normals = generate_normals(&index, &position); + let buffer = self.device.create_buffer_init(&BufferInitDescriptor { + label: None, + usage: BufferUsages::COPY_DST | BufferUsages::VERTEX, + contents: bytemuck::cast_slice(normals.as_slice()), + }); + self.generated_normal_buffers.insert( + spec, + Arc::new(buffer), + size_of::<f32>() * normals.len() * 3, + ); + } + } + for spec in self.generated_texcoord_buffers.needed() { + if let (Some(index), Some(position)) = ( + dls.try_get(spec.index.clone())?, + dls.try_get(spec.position.clone())?, + ) { + let texcoords = generate_texcoords(&index, &position); + let buffer = self.device.create_buffer_init(&BufferInitDescriptor { + label: None, + usage: BufferUsages::COPY_DST | BufferUsages::VERTEX, + contents: bytemuck::cast_slice(texcoords.as_slice()), + }); + self.generated_texcoord_buffers.insert( + spec, + Arc::new(buffer), + size_of::<f32>() * texcoords.len() * 3, + ); + } + } for pres in self.mesh_parts.needed() { let start = Instant::now(); if let Some(part) = dls.try_get(pres.clone())? { @@ -272,13 +311,19 @@ impl ScenePreparer { let normal = if let Some(res) = part.va_normal.clone() { self.vertex_buffers.try_get(Resource(res.0, PhantomData)) } else { - todo!() + self.generated_normal_buffers.try_get(NormalBufferSpec { + index: indexres.clone(), + position: Resource(positionres.0, PhantomData), + }) }; let texcoord = if let Some(res) = part.va_texcoord.clone() { self.vertex_buffers.try_get(Resource(res.0, PhantomData)) } else { - todo!() + self.generated_texcoord_buffers.try_get(TexcoordBufferSpec { + index: indexres.clone(), + position: Resource(positionres.0, PhantomData), + }) }; let tangent = if let Some(res) = part.va_tangent.clone() { self.vertex_buffers.try_get(Resource(res.0, PhantomData)) |