pub struct ViewCamera {
pub eye: [f64; 3],
pub target: [f64; 3],
pub up: [f64; 3],
pub projection: Projection,
pub width: f64,
pub height: f64,
pub near: f64,
pub far: f64,
}Fields§
§eye: [f64; 3]§target: [f64; 3]§up: [f64; 3]§projection: Projection§width: f64Viewport CSS size.
height: f64§near: f64View-space depth window (positive distances along the view direction);
maintained by ViewCamera::fit_depth_range. Ortho near may go
negative (scene behind the eye plane is still projectable).
DEPTH-BUFFER WINDOW ONLY. near/far exist to map the GPU depth buffer
over everything drawn (re-fitted each frame from the render path’s
depth bbox = depth_range_bbox ∪ the full widget overlay’s world bounds
∪ the world origin, so construction geometry — datums / axes / gizmos —
is always bracketed) — they are NEVER a visibility decision. No label, anchor, chip, or hit-region may consult them: the
ONE screen-visibility rule for all of those is
ViewCamera::projectable. Anything gating on near/far (or a bare
depth > 0 in ortho) is a bug — labels would vanish while their
geometry still renders.
far: f64Implementations§
Source§impl ViewCamera
impl ViewCamera
pub fn aspect(&self) -> f64
Sourcepub fn basis(&self) -> ([f64; 3], [f64; 3], [f64; 3])
pub fn basis(&self) -> ([f64; 3], [f64; 3], [f64; 3])
Camera basis: (right, true-up, forward) with forward pointing INTO the scene (eye → target).
pub fn distance(&self) -> f64
Sourcepub fn world_per_pixel(&self) -> f64
pub fn world_per_pixel(&self) -> f64
World units per CSS pixel at the target plane (R21/R25 — the query the pickers, gizmos and sketch glyph sizing key off).
Sourcepub fn view_depth(&self, world: [f64; 3]) -> f64
pub fn view_depth(&self, world: [f64; 3]) -> f64
The view-space depth of a world point: the signed distance along the
forward view axis from the eye (identical to project’s third return).
Positive in front of the eye plane. The screen-space region builder
(brep_gizmos::hit_region) keys the perspective front-clip off this.
Sourcepub fn projectable(&self, world: [f64; 3]) -> bool
pub fn projectable(&self, world: [f64; 3]) -> bool
Whether a world point is PROJECTABLE to a usable screen position — THE screen-visibility policy for every label / anchor / chip / hit-region consumer, in ONE place so no consumer can re-invent a depth cull:
- ORTHOGRAPHIC (the app default): always
true. Behind-eye-plane geometry still renders in ortho, so its labels must too. - PERSPECTIVE:
falseonly for a point at/behind the eye plane, where the projection itself is mathematically undefined — the sameFRONT_EPSrule the region builder (brep_gizmos::hit_region) applies.
The near/far fields NEVER factor in — they are the GPU depth-buffer
window (see their field doc), not visibility. Route ANY new “should this
world-anchored UI draw?” question through here.
Sourcepub fn label_anchor_visible(&self, world: [f64; 3]) -> bool
pub fn label_anchor_visible(&self, world: [f64; 3]) -> bool
Whether a world-anchored TEXT LABEL should draw: Self::projectable
AND the anchor projects INSIDE the viewport rect. The second half is a
screen-BOUNDS test, never a depth test — near/far still cull nothing
(see Self::projectable) — so a chip whose 3D anchor scrolled out of
view disappears instead of piling up clamped at the viewport edge (egui
Areas constrain themselves on-screen). This is the inFront flag every
app label pass keys its skip off (world_to_screen_json); hit-testable
ANCHORS (gizmo handles, hit regions) intentionally stay on the pure
projectable policy — an off-screen handle just can’t be clicked.
Sourcepub fn view_proj_cols(&self) -> [[f64; 4]; 4]
pub fn view_proj_cols(&self) -> [[f64; 4]; 4]
The world→clip view-projection as column-major [col][row] in f64. This
is the exact matrix [resolve] feeds the GPU, kept in f64 so the
CSS-pixel projection the host overlays derive from it matches [project]
to sub-pixel precision. wgpu clip space: x,y in −1..1, z in 0..1.
Sourcepub fn view_proj_flat(&self) -> [f64; 16]
pub fn view_proj_flat(&self) -> [f64; 16]
The view-projection flattened column-major (index = col*4 + row) — the
world→clip matrix for the host overlays’
per-frame world→screen hot path (dimensions + sketch), letting them drop
the compat mirror camera. Pair with the CSS viewport for NDC→pixel.
Sourcepub fn view_proj_inverse_flat(&self) -> [f64; 16]
pub fn view_proj_inverse_flat(&self) -> [f64; 16]
Inverse of [view_proj_flat] (clip→world), column-major, for the host
overlays’ screen→world / screen→ray path. Falls back to the identity if
the matrix is singular (never in practice for a valid camera).
Sourcepub fn project(&self, world: [f64; 3]) -> (f64, f64, f64)
pub fn project(&self, world: [f64; 3]) -> (f64, f64, f64)
Project a world point to CSS-pixel screen coordinates (origin top-left,
y down). Returns (x, y, view_depth); view_depth is the distance
along the view direction (positive in front of the eye plane).
Sourcepub fn pick_ray(&self, x: f64, y: f64) -> Ray
pub fn pick_ray(&self, x: f64, y: f64) -> Ray
A world-space picking ray through CSS-pixel (x, y). Ortho rays start
far behind the eye plane so huge scenes are always in front (the retired
picker pushed its ray origin back the same way).
Sourcepub fn fit_depth_range(&mut self, bbox: &Aabb)
pub fn fit_depth_range(&mut self, bbox: &Aabb)
Fit the depth window to the scene (the _updateDepthRange port): the
whole bbox lands inside [near, far] with generous padding.
Sourcepub fn zoom_to_fit(&mut self, bbox: &Aabb, margin: f64)
pub fn zoom_to_fit(&mut self, bbox: &Aabb, margin: f64)
Zoom-to-fit (R21): recenters the target on the bbox and scales the
frustum/distance so the whole bbox fits with margin, preserving the
view direction (the ArcballControls focus behavior).
Sourcepub fn toggle_projection(&mut self) -> &'static str
pub fn toggle_projection(&mut self) -> &'static str
Toggle ortho ↔ perspective preserving the apparent size at the target
plane (the toggleCameraProjection port). Returns the new kind name.
Sourcepub fn standard_view(&mut self, name: &str) -> bool
pub fn standard_view(&mut self, name: &str) -> bool
Snap to a standard view (future ViewCube seam), preserving distance and frustum scale. Directions are world-axis views with sensible ups.
Sourcepub fn state_json(&self) -> String
pub fn state_json(&self) -> String
Serialize the full camera state (R3: the host holds plain JSON only).
Sourcepub fn apply_state_json(&mut self, json: &str) -> Result<(), String>
pub fn apply_state_json(&mut self, json: &str) -> Result<(), String>
Restore from ViewCamera::state_json output (viewport size is NOT
restored — it belongs to the canvas).
Trait Implementations§
Source§impl Clone for ViewCamera
impl Clone for ViewCamera
Source§fn clone(&self) -> ViewCamera
fn clone(&self) -> ViewCamera
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ViewCamera
impl Debug for ViewCamera
Source§impl Default for ViewCamera
impl Default for ViewCamera
Source§impl RegionCamera for ViewCamera
The render camera projects dimension-gizmo handle points to viewport-local px
for the shared screen-space region builder, so a gizmo’s hit-test + its debug
outline share ONE projection (see brep_gizmos::hit_region).
impl RegionCamera for ViewCamera
The render camera projects dimension-gizmo handle points to viewport-local px
for the shared screen-space region builder, so a gizmo’s hit-test + its debug
outline share ONE projection (see brep_gizmos::hit_region).
Source§fn is_orthographic(&self) -> bool
fn is_orthographic(&self) -> bool
Auto Trait Implementations§
impl Freeze for ViewCamera
impl RefUnwindSafe for ViewCamera
impl Send for ViewCamera
impl Sync for ViewCamera
impl Unpin for ViewCamera
impl UnsafeUnpin for ViewCamera
impl UnwindSafe for ViewCamera
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more