From 3344eb2d678f9c5973c8e38083760254b54c20fc Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 23 Jan 2025 22:45:35 +0100 Subject: split scene_prepare to many files --- client/src/meshops.rs | 81 --------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 client/src/meshops.rs (limited to 'client/src/meshops.rs') diff --git a/client/src/meshops.rs b/client/src/meshops.rs deleted file mode 100644 index 0a3f963..0000000 --- a/client/src/meshops.rs +++ /dev/null @@ -1,81 +0,0 @@ -/* - wearechat - generic multiplayer game with voip - Copyright (C) 2025 metamuffin - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, version 3 of the License only. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ -use glam::{Vec2, Vec3, vec2}; - -pub fn generate_normals(index: &[[u32; 3]], position: &[Vec3]) -> Vec { - let mut normal_denom = vec![0; position.len()]; - let mut normal = vec![Vec3::ZERO; position.len()]; - - for &[a, b, c] in index { - let pos_a = position[a as usize]; - let pos_b = position[b as usize]; - let pos_c = position[c as usize]; - - // TODO is this right? - let norm = (pos_b - pos_a).cross(pos_c - pos_a).normalize(); - - normal[a as usize] += norm; - normal[b as usize] += norm; - normal[c as usize] += norm; - normal_denom[a as usize] += 1; - normal_denom[b as usize] += 1; - normal_denom[c as usize] += 1; - } - for (denom, norm) in normal_denom.iter().zip(normal.iter_mut()) { - *norm /= *denom as f32; - } - normal -} - -pub fn generate_tangents(index: &[[u32; 3]], position: &[Vec3], texcoord: &[Vec2]) -> Vec { - let mut tangent_denom = vec![0; position.len()]; - let mut tangent = vec![Vec3::ZERO; position.len()]; - - for &[a, b, c] in index { - let (pos_a, uv_a) = (position[a as usize], texcoord[a as usize]); - let (pos_b, uv_b) = (position[b as usize], texcoord[b as usize]); - let (pos_c, uv_c) = (position[c as usize], texcoord[c as usize]); - - let pd_ba = pos_b - pos_a; - let pd_ca = pos_c - pos_a; - let td_ba = uv_b - uv_a; - let td_ca = uv_c - uv_a; - - let face_tangent = - (pd_ba * td_ca.y - pd_ca * td_ba.y) * (td_ba.x * td_ca.y - td_ba.y * td_ca.x); - - tangent[a as usize] += face_tangent; - tangent[b as usize] += face_tangent; - tangent[c as usize] += face_tangent; - tangent_denom[a as usize] += 1; - tangent_denom[b as usize] += 1; - tangent_denom[c as usize] += 1; - } - for (denom, tang) in tangent_denom.iter().zip(tangent.iter_mut()) { - *tang /= *denom as f32; - } - - tangent -} - -pub fn generate_texcoords(index: &[[u32; 3]], position: &[Vec3]) -> Vec { - let _ = (index, position); - // TODO implement equirectangular projection or something - (0..position.len()) - .map(|i| vec2(i as f32 * 0.01, 0.)) - .collect() -} -- cgit v1.2.3-70-g09d2