Skip to content

Commit

Permalink
Merge pull request #1573 from erenoku/navigation_cube
Browse files Browse the repository at this point in the history
Add navigation cube
  • Loading branch information
hannobraun authored Feb 13, 2023
2 parents 5ee0e59 + 533f6c2 commit 5879a0c
Show file tree
Hide file tree
Showing 20 changed files with 825 additions and 2 deletions.
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added assets/navigation_cube/bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/navigation_cube/cube.blend
Binary file not shown.
62 changes: 62 additions & 0 deletions assets/navigation_cube/cube.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Blender 3.4.1 MTL File: 'cube.blend'
# www.blender.org

newmtl bottom
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd bottom.png

newmtl front
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd front.png

newmtl left
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd left.png

newmtl rear
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd rear.png

newmtl right
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd right.png

newmtl top
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd top.png
51 changes: 51 additions & 0 deletions assets/navigation_cube/cube.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Blender 3.4.1
# www.blender.org
mtllib cube.mtl
o Cube
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
vn -0.0000 1.0000 -0.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vn -0.0000 -1.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn 1.0000 -0.0000 -0.0000
vt 0.999900 0.000100
vt 0.999900 0.999900
vt 0.000100 0.999900
vt 0.999900 0.999900
vt 0.999900 0.000100
vt 0.000100 0.000100
vt 0.000100 0.000100
vt 0.999900 0.999900
vt 0.000100 0.999900
vt 0.999900 0.000100
vt 0.000100 0.999900
vt 0.000100 0.000100
vt 0.000100 0.999900
vt 0.999900 0.999900
vt 0.000100 0.000100
vt 0.999900 0.000100
vt 0.000100 0.999900
vt 0.999900 0.999900
vt 0.999900 0.000100
vt 0.000100 0.000100
s 0
usemtl top
f 1/1/1 5/14/1 7/17/1 3/7/1
usemtl left
f 4/10/2 3/8/2 7/17/2 8/20/2
usemtl front
f 2/5/5 1/2/5 3/9/5 4/12/5
usemtl right
f 6/16/6 5/14/6 1/3/6 2/6/6
usemtl rear
f 8/19/3 7/18/3 5/13/3 6/15/3
usemtl bottom
f 6/16/4 2/4/4 4/11/4 8/20/4
Binary file added assets/navigation_cube/front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/navigation_cube/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/navigation_cube/rear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/navigation_cube/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/navigation_cube/top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions crates/fj-math/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ impl Transform {
))
}

/// Construct a scaling
pub fn scale(scaling_factor: f64) -> Self {
Self(nalgebra::Transform::from_matrix_unchecked(
nalgebra::OMatrix::new_scaling(scaling_factor),
))
}

/// Transform the given point
pub fn transform_point(&self, point: &Point<3>) -> Point<3> {
Point::from(self.0.transform_point(&point.to_na()))
Expand Down Expand Up @@ -119,6 +126,11 @@ impl Transform {
array.map(Scalar::from)
}

/// Return a copy of the inner nalgebra transform
pub fn get_inner(&self) -> nalgebra::Transform<f64, nalgebra::TAffine, 3> {
self.0
}

/// Transform the given axis-aligned bounding box
pub fn transform_aabb(&self, aabb: &Aabb<3>) -> Aabb<3> {
Aabb {
Expand Down
7 changes: 7 additions & 0 deletions crates/fj-viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ egui = "0.20.1"
egui-wgpu = "0.20.0"
fj-interop.workspace = true
fj-math.workspace = true
nalgebra = "0.32.1"
tobj = "3.2.4"
raw-window-handle = "0.5.0"
thiserror = "1.0.35"
tracing = "0.1.37"
wgpu_glyph = "0.18.0"

[dependencies.image]
version = "0.24"
default-features = false
features = ["png", "jpeg"]

[dependencies.rfd]
version = "0.11.1"
default_features = false
Expand Down
59 changes: 59 additions & 0 deletions crates/fj-viewer/src/assets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
pub struct Assets<'a> {
pub cube_obj: &'a [u8],
pub cube_mtl: &'a [u8],
pub front_texture: &'a [u8],
pub right_texture: &'a [u8],
pub rear_texture: &'a [u8],
pub left_texture: &'a [u8],
pub top_texture: &'a [u8],
pub bottom_texture: &'a [u8],
}

impl<'a> Assets<'a> {
pub fn get_instance() -> Self {
let cube_obj: &[u8] =
include_bytes!("../../../assets/navigation_cube/cube.obj");
let cube_mtl: &[u8] =
include_bytes!("../../../assets/navigation_cube/cube.mtl");
let front_texture: &[u8] =
include_bytes!("../../../assets/navigation_cube/front.png");
let right_texture: &[u8] =
include_bytes!("../../../assets/navigation_cube/right.png");
let rear_texture: &[u8] =
include_bytes!("../../../assets/navigation_cube/rear.png");
let left_texture: &[u8] =
include_bytes!("../../../assets/navigation_cube/left.png");
let top_texture: &[u8] =
include_bytes!("../../../assets/navigation_cube/top.png");
let bottom_texture: &[u8] =
include_bytes!("../../../assets/navigation_cube/bottom.png");

Self {
cube_obj,
cube_mtl,
front_texture,
right_texture,
rear_texture,
left_texture,
top_texture,
bottom_texture,
}
}

pub fn get_asset(&self, file_name: &str) -> &[u8] {
match file_name {
"cube.obj" => self.cube_obj,
"cube.mtl" => self.cube_mtl,
"front.png" => self.front_texture,
"right.png" => self.right_texture,
"rear.png" => self.rear_texture,
"left.png" => self.left_texture,
"top.png" => self.top_texture,
"bottom.png" => self.bottom_texture,
_ => unreachable!(
"An unknown asset: {} is trying to be loaded",
file_name
),
}
}
}
3 changes: 3 additions & 0 deletions crates/fj-viewer/src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
mod draw_config;
mod drawables;
mod geometries;
mod model;
mod navigation_cube;
mod pipelines;
mod renderer;
mod shaders;
mod texture;
mod transform;
mod uniforms;
mod vertices;
Expand Down
Loading

0 comments on commit 5879a0c

Please sign in to comment.