Skip to main content

ViewCamera

Struct ViewCamera 

Source
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: f64

Viewport CSS size.

§height: f64§near: f64

View-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: f64

Implementations§

Source§

impl ViewCamera

Source

pub fn aspect(&self) -> f64

Source

pub fn basis(&self) -> ([f64; 3], [f64; 3], [f64; 3])

Camera basis: (right, true-up, forward) with forward pointing INTO the scene (eye → target).

Source

pub fn distance(&self) -> f64

Source

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).

Source

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.

Source

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: false only for a point at/behind the eye plane, where the projection itself is mathematically undefined — the same FRONT_EPS rule 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.

Source

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.

Source

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.

Source

pub fn resolve(&self) -> Camera

Resolve to the GPU camera (column-major view-proj, f32).

Source

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.

Source

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).

Source

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).

Source

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).

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn state_json(&self) -> String

Serialize the full camera state (R3: the host holds plain JSON only).

Source

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

Source§

fn clone(&self) -> ViewCamera

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ViewCamera

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ViewCamera

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
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).

Source§

fn is_orthographic(&self) -> bool

True for an orthographic projection: behind-eye-plane geometry still projects + renders, so it is never clipped or omitted.
Source§

fn depth(&self, p: [f64; 3]) -> f64

Signed view-space depth of a world point (positive in front of the eye plane). Used only to decide front/behind for the perspective clip.
Source§

fn project_px(&self, p: [f64; 3]) -> Option<[f32; 2]>

Project a world point to viewport-local screen px, or None if it is not projectable (perspective, at/behind the eye). Ortho always projects.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,