Skip to content

Commit

Permalink
Revamp camera and viewport handling (#181)
Browse files Browse the repository at this point in the history
- Adds `View2` and `View3` types to the Fidget crate itself, which
  define world-to-model transform matrices. Remove the existing `Camera`
  type.
- Adds a `RegionSize<N>` (typedefed to `ImageSize` and `VoxelSize`) for
  a pixel size, which gives the screen-to-world transform matrix
- Uses these types in `RenderConfig` (2D / 3D images) and `Settings`
  (for meshing)
  • Loading branch information
mkeeter authored Nov 15, 2024
1 parent eb0e7b7 commit f0cf358
Show file tree
Hide file tree
Showing 27 changed files with 1,044 additions and 989 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
- Add a new `TileSizes(Vec<usize>)` object representing tile sizes used during
rendering. Unlike the previous `Vec<usize>`, this data type checks our tile
size invariants at construction. It is used in the `struct RenderConfig`.
- Rethink rendering and viewport configuration:
- Add a new `RegionSize<const N: usize>` type (with `ImageSize` and
`VoxelSize` aliases), representing a render region. This type is
responsible for the screen-to-world transform
- Add `View2` and `View3` types, which stores the world-to-model
transform (scaling, panning, etc)
- Image rendering uses both `RegionSize` and `ViewX`; this means that we
can now render non-square images!
- Meshing uses just a `View3`, to position the model within the ±1 bounds
- The previous `fidget::shape::Bounds` type is removed
- Remove `fidget::render::render2d/3d` from the public API, as they're
equivalent to the functions on `ImageRenderConfig` / `VoxelRenderConfig`

# 0.3.3
- `Function` and evaluator types now produce multiple outputs
Expand Down
9 changes: 0 additions & 9 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ members = [
"demos/constraints",
"demos/cli",
"demos/viewer",
"demos/camera",
"workspace-hack",
]
exclude = ["demos/web-editor/crate"]
Expand Down
8 changes: 0 additions & 8 deletions demos/camera/Cargo.toml

This file was deleted.

212 changes: 0 additions & 212 deletions demos/camera/src/lib.rs

This file was deleted.

28 changes: 12 additions & 16 deletions demos/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,18 @@ fn run3d<F: fidget::eval::Function + fidget::shape::RenderHints>(
if !isometric {
*mat.matrix_mut().get_mut((3, 2)).unwrap() = 0.3;
}
let cfg = fidget::render::RenderConfig {
image_size: settings.size as usize,
let cfg = fidget::render::VoxelRenderConfig {
image_size: fidget::render::VoxelSize::from(settings.size),
tile_sizes: F::tile_sizes_3d(),
threads: settings.threads,
threads: settings.threads.into(),
..Default::default()
};
let shape = shape.apply_transform(mat.into());

let mut depth = vec![];
let mut color = vec![];
for _ in 0..settings.n {
(depth, color) = fidget::render::render3d(shape.clone(), &cfg);
(depth, color) = cfg.run(shape.clone());
}

let out = if mode_color {
Expand Down Expand Up @@ -197,19 +197,17 @@ fn run2d<F: fidget::eval::Function + fidget::shape::RenderHints>(
.flat_map(|i| i.into_iter())
.collect()
} else {
let cfg = fidget::render::RenderConfig {
image_size: settings.size as usize,
let cfg = fidget::render::ImageRenderConfig {
image_size: fidget::render::ImageSize::from(settings.size),
tile_sizes: F::tile_sizes_2d(),
threads: settings.threads,
threads: settings.threads.into(),
..Default::default()
};
if sdf {
let mut image = vec![];
for _ in 0..settings.n {
image = fidget::render::render2d::<
_,
fidget::render::SdfRenderMode,
>(shape.clone(), &cfg);
image =
cfg.run::<_, fidget::render::SdfRenderMode>(shape.clone());
}
image
.into_iter()
Expand All @@ -218,10 +216,8 @@ fn run2d<F: fidget::eval::Function + fidget::shape::RenderHints>(
} else {
let mut image = vec![];
for _ in 0..settings.n {
image = fidget::render::render2d::<
_,
fidget::render::DebugRenderMode,
>(shape.clone(), &cfg);
image = cfg
.run::<_, fidget::render::DebugRenderMode>(shape.clone());
}
image
.into_iter()
Expand All @@ -241,7 +237,7 @@ fn run_mesh<F: fidget::eval::Function + fidget::shape::RenderHints>(

for _ in 0..settings.n {
let settings = fidget::mesh::Settings {
threads: settings.threads,
threads: settings.threads.into(),
depth: settings.depth,
..Default::default()
};
Expand Down
1 change: 0 additions & 1 deletion demos/viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ notify.workspace = true
rhai.workspace = true

fidget = { path = "../../fidget", default-features = false, features = ["render", "rhai"] }
camera = { path = "../camera" }
workspace-hack = { version = "0.1", path = "../../workspace-hack" }

[features]
Expand Down
Loading

0 comments on commit f0cf358

Please sign in to comment.