diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-12 12:08:56 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-12 12:08:56 +0100 |
commit | 7121bb7c49fcf5b24795c77100cb1ff46097ecb6 (patch) | |
tree | 8a8ea6cbbca75a8aa8e0394d07cfe4a3a0817e94 | |
parent | c626006c767f21d1ba0d452b64e244c7d69fa09b (diff) | |
download | weareserver-7121bb7c49fcf5b24795c77100cb1ff46097ecb6.tar weareserver-7121bb7c49fcf5b24795c77100cb1ff46097ecb6.tar.bz2 weareserver-7121bb7c49fcf5b24795c77100cb1ff46097ecb6.tar.zst |
add scale and z_up arguments
-rw-r--r-- | client/src/camera.rs | 2 | ||||
-rw-r--r-- | client/src/download.rs | 6 | ||||
-rw-r--r-- | world/src/main.rs | 22 | ||||
-rw-r--r-- | world/src/mesh.rs | 39 | ||||
-rw-r--r-- | world/src/physics.rs | 5 |
5 files changed, 42 insertions, 32 deletions
diff --git a/client/src/camera.rs b/client/src/camera.rs index 4006c74..d2d4bda 100644 --- a/client/src/camera.rs +++ b/client/src/camera.rs @@ -47,7 +47,7 @@ impl Camera { Mat3::from_euler(EulerRot::YXZ, self.rot.x, self.rot.y, self.rot.z) } pub fn to_matrix(&self) -> Mat4 { - Mat4::perspective_rh(self.fov, self.aspect, 0.1, 100.) + Mat4::perspective_rh(self.fov, self.aspect, 0.1, 300.) * Mat4::from_mat3(self.rotation_mat().inverse()) * Mat4::from_translation(-self.pos) } diff --git a/client/src/download.rs b/client/src/download.rs index 85cce32..2d61a53 100644 --- a/client/src/download.rs +++ b/client/src/download.rs @@ -84,7 +84,11 @@ impl Downloader { pub fn update(&self, network: &Network) -> Result<()> { let mut state = self.inner.write().unwrap(); let mut new_pending = Vec::new(); - for n in state.need.difference(&state.pending) { + for n in state + .need + .difference(&state.pending) + .take(32 - state.pending.len()) + { network .packet_send .send(Packet::RequestResource(*n)) diff --git a/world/src/main.rs b/world/src/main.rs index 72e7df2..0decba6 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -44,7 +44,7 @@ use weareshared::{ }; #[derive(Parser)] -struct Args { +pub struct Args { address: SocketAddr, /// Path to a glTF file, binary or json format scene: PathBuf, @@ -64,11 +64,15 @@ struct Args { #[arg(short, long)] webp: bool, /// Add skybox - #[arg(short, long)] + #[arg(long)] skybox: Option<PathBuf>, /// Override prefab name #[arg(short, long)] name: Option<String>, + #[arg(short, long)] + scale: Option<f32>, + #[arg(short, long)] + z_up: bool, } fn main() -> Result<()> { @@ -87,7 +91,7 @@ fn main() -> Result<()> { let mut prefab = Prefab::default(); - prefab.name = args.name.or(gltf + prefab.name = args.name.clone().or(gltf .default_scene() .map(|n| n.name()) .flatten() @@ -96,15 +100,7 @@ fn main() -> Result<()> { for node in gltf.nodes() { if let Some(mesh) = node.mesh() { info!("--- MESH ---"); - import_mesh( - mesh, - &buffers, - &store, - path_base, - &node, - &mut prefab, - args.webp, - )?; + import_mesh(mesh, &buffers, &store, path_base, &node, &mut prefab, &args)?; } let (position, _, _) = node.transform().decomposed(); if let Some(light) = node.light() { @@ -121,7 +117,7 @@ fn main() -> Result<()> { })?, )); } - import_physics(&gltf, &node, &mut prefab, &store, &buffers)?; + import_physics(&gltf, &node, &mut prefab, &store, &buffers, &args)?; } if let Some(skybox) = args.skybox { diff --git a/world/src/mesh.rs b/world/src/mesh.rs index 77bb05d..f66be82 100644 --- a/world/src/mesh.rs +++ b/world/src/mesh.rs @@ -14,13 +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::load_texture; +use crate::{Args, load_texture}; use anyhow::Result; use gltf::{Mesh, Node, buffer::Data}; use log::{debug, info}; -use std::path::Path; +use std::{f32::consts::PI, path::Path}; use weareshared::{ - Affine3A, Vec3A, + Affine3A, Mat3A, Vec3A, resources::{MeshPart, Prefab}, store::ResourceStore, vec2, vec3a, @@ -33,7 +33,7 @@ pub fn import_mesh( path_base: &Path, node: &Node, prefab: &mut Prefab, - webp: bool, + args: &Args, ) -> Result<()> { Ok(for p in mesh.primitives() { let reader = p.reader(|buf| Some(&buffers[buf.index()])); @@ -114,7 +114,7 @@ pub fn import_mesh( path_base, &buffers, &tex.texture().source().source(), - webp, + args.webp, )?; tex_albedo = Some(r.clone()); tex_alpha = Some(r.clone()); @@ -127,7 +127,7 @@ pub fn import_mesh( path_base, &buffers, &tex.texture().source().source(), - webp, + args.webp, )?); } let mut tex_emission = None; @@ -138,7 +138,7 @@ pub fn import_mesh( path_base, &buffers, &tex.texture().source().source(), - webp, + args.webp, )?); } let mut tex_transmission = None; @@ -154,7 +154,7 @@ pub fn import_mesh( path_base, &buffers, &tex.texture().source().source(), - webp, + args.webp, )?); } let mut tex_thickness = None; @@ -170,7 +170,7 @@ pub fn import_mesh( path_base, &buffers, &tex.texture().source().source(), - webp, + args.webp, )?); } let mut tex_occlusion = None; @@ -181,7 +181,7 @@ pub fn import_mesh( path_base, &buffers, &tex.texture().source().source(), - webp, + args.webp, )?); } let mut tex_roughness = None; @@ -197,7 +197,7 @@ pub fn import_mesh( path_base, &buffers, &tex.texture().source().source(), - webp, + args.webp, )?; tex_roughness = Some(r.clone()); tex_metallic = Some(r.clone()); @@ -333,16 +333,25 @@ pub fn import_mesh( va_roughness: None, })?; - prefab.mesh.push((node_transform_to_affine(node), mesh)) + prefab + .mesh + .push((node_transform_to_affine(node, args), mesh)) }) } -pub fn node_transform_to_affine(node: &Node) -> Affine3A { +pub fn node_transform_to_affine(node: &Node, args: &Args) -> Affine3A { let mat = node.transform().matrix(); - Affine3A::from_cols_array_2d(&[ + let mut aff = Affine3A::from_cols_array_2d(&[ [mat[0][0], mat[0][1], mat[0][2]], [mat[1][0], mat[1][1], mat[1][2]], [mat[2][0], mat[2][1], mat[2][2]], [mat[3][0], mat[3][1], mat[3][2]], - ]) + ]); + aff.matrix3 *= args.scale.unwrap_or(1.); + if args.z_up { + let r = Mat3A::from_rotation_x(PI / 2.); + aff.matrix3 *= r; + aff.translation = r * aff.translation; + } + aff } diff --git a/world/src/physics.rs b/world/src/physics.rs index 3b98378..4afeab7 100644 --- a/world/src/physics.rs +++ b/world/src/physics.rs @@ -14,7 +14,7 @@ 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::mesh::node_transform_to_affine; +use crate::{Args, mesh::node_transform_to_affine}; use anyhow::{Result, anyhow}; use gltf::{Gltf, Node, buffer::Data, json::Value}; use log::info; @@ -30,6 +30,7 @@ pub fn import_physics( prefab: &mut Prefab, store: &ResourceStore, buffers: &[Data], + args: &Args, ) -> Result<()> { if let Some(physics) = node .extensions() @@ -72,7 +73,7 @@ pub fn import_physics( ); prefab.collision.push(( - node_transform_to_affine(&node), + node_transform_to_affine(&node, args), store.set(&CollisionPart { sh_mesh: Some((store.set(&index)?, store.set(&position)?)), ..Default::default() |