summaryrefslogtreecommitdiff
path: root/world/src/mesh.rs
diff options
context:
space:
mode:
Diffstat (limited to 'world/src/mesh.rs')
-rw-r--r--world/src/mesh.rs39
1 files changed, 24 insertions, 15 deletions
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
}