summaryrefslogtreecommitdiff
path: root/world
diff options
context:
space:
mode:
Diffstat (limited to 'world')
-rw-r--r--world/src/main.rs22
-rw-r--r--world/src/mesh.rs39
-rw-r--r--world/src/physics.rs5
3 files changed, 36 insertions, 30 deletions
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()