pub struct ViewportRuntime { /* private fields */ }Expand description
Per-frame scene orchestration layer.
Owns plugins, an optional fixed timestep accumulator, and a transform snapshot table. Does not own the scene, selection, GPU resources, or window.
§Priority execution order
Each call to step executes plugins in ascending priority order:
[i32::MIN, SELECT)– Prepare (100), Pick (200): once, at wall dt[SELECT, MANIPULATE)– Select (300): once (built-in SelectionSystem runs first)[MANIPULATE, SIMULATE)– Manipulate (400), Animate (500): once[SIMULATE, POST_SIM)– Simulate (600): once per fixed step or once at wall dt[POST_SIM, i32::MAX]– PostSim (700), Writeback (800): once at wall dt
Implementations§
Source§impl ViewportRuntime
impl ViewportRuntime
Sourcepub fn with_selection_system(self) -> Self
pub fn with_selection_system(self) -> Self
Enable the built-in click-to-select system.
The SelectionSystem runs before the Select phase each frame. It reads
RuntimeFrameContext::clicked, pick_hit, and shift_held to produce
SelectionOp entries in RuntimeOutput.
Sourcepub fn with_manipulation_system(self) -> Self
pub fn with_manipulation_system(self) -> Self
Enable the built-in manipulation system.
The ManipulationSystem runs before the Manipulate phase each frame. It
drives G/R/S sessions and gizmo drag from RuntimeFrameContext inputs, writing
transform changes via TransformWriteback.
Sourcepub fn is_manipulating(&self) -> bool
pub fn is_manipulating(&self) -> bool
True while the built-in manipulation system has an active G/R/S session or gizmo drag.
Use this to suppress orbit camera movement while manipulating objects.
Sourcepub fn manipulation_system(&self) -> Option<&ManipulationSystem>
pub fn manipulation_system(&self) -> Option<&ManipulationSystem>
Access the built-in manipulation system, if enabled.
Sourcepub fn with_mode(self, mode: SceneRuntimeMode) -> Self
pub fn with_mode(self, mode: SceneRuntimeMode) -> Self
Set the runtime mode.
Sourcepub fn with_plugin(self, plugin: impl RuntimePlugin) -> Self
pub fn with_plugin(self, plugin: impl RuntimePlugin) -> Self
Register a plugin. Plugins run in ascending priority order each frame. Plugins with equal priority run in registration order (stable sort).
Sourcepub fn add_plugin(&mut self, plugin: impl RuntimePlugin)
pub fn add_plugin(&mut self, plugin: impl RuntimePlugin)
Register a plugin on an existing runtime.
Same semantics as with_plugin but takes
&mut self, for hosts that need to add plugins after the runtime
has been constructed and possibly already run frames.
Sourcepub fn with_gpu_plugin(self, plugin: impl GpuPlugin) -> Self
pub fn with_gpu_plugin(self, plugin: impl GpuPlugin) -> Self
Register a GPU plugin. GPU plugins encode wgpu command buffers from
ViewportRuntime::pre_prepare, which the host calls each frame after
step and before renderer.prepare(). Plugins run in ascending
priority order; equal priorities preserve registration order.
Registering a plugin after the runtime has already run a frame re-runs
every GPU plugin’s init_gpu on the next pre_prepare. Implementations
should be idempotent or guard their own one-time setup.
Sourcepub fn add_gpu_plugin(&mut self, plugin: impl GpuPlugin)
pub fn add_gpu_plugin(&mut self, plugin: impl GpuPlugin)
Register a GPU plugin on an existing runtime.
Same semantics as with_gpu_plugin but
takes &mut self.
Sourcepub fn with_gpu_plugin_for_viewport(
self,
viewport: ViewportId,
plugin: impl GpuPlugin,
) -> Self
pub fn with_gpu_plugin_for_viewport( self, viewport: ViewportId, plugin: impl GpuPlugin, ) -> Self
Register a GPU plugin scoped to a single viewport.
The plugin’s pre_prepare and post_paint only execute when the
host’s GpuFrameContext::viewport_id equals viewport. init_gpu
and on_device_recreated still run unconditionally.
Use this in multi-viewport hosts (CAD quad-view, split-screen) that
call pre_prepare / post_paint once per viewport with a populated
viewport_id. Single-viewport hosts that never set viewport_id
effectively disable scoped plugins; use with_gpu_plugin
instead.
Sourcepub fn notify_device_recreated(&mut self, device: &Device, queue: &Queue)
pub fn notify_device_recreated(&mut self, device: &Device, queue: &Queue)
Notify every registered GPU plugin that the wgpu device has been recreated (device loss, surface re-init, host-driven reset).
Calls GpuPlugin::on_device_recreated on each plugin, then clears
the init flag so init_gpu runs again with the new device on the
next pre_prepare. The runtime does not detect
device loss on its own; the host is responsible for invoking this
when it recreates the device.
Sourcepub fn pre_prepare(
&mut self,
device: &Device,
queue: &Queue,
ctx: &GpuFrameContext<'_>,
) -> Vec<CommandBuffer>
pub fn pre_prepare( &mut self, device: &Device, queue: &Queue, ctx: &GpuFrameContext<'_>, ) -> Vec<CommandBuffer>
Run every registered GPU plugin’s pre_prepare in ascending priority
order and return the concatenated command buffers.
Call after step and before renderer.prepare(). The
returned buffers should be submitted ahead of the renderer’s own:
let plugin_bufs = runtime.pre_prepare(device, queue, &gpu_ctx);
let prepare_bufs = renderer.pass().prepare(device, queue, &frame);
queue.submit(plugin_bufs.into_iter().chain(prepare_bufs));wgpu submit ordering guarantees plugin work completes before
prepare()’s, so any storage buffer written by a plugin is observable
by the standard render passes in the same frame.
On the first call (or after a new plugin is registered), every plugin’s
init_gpu is invoked once before any pre_prepare.
Sourcepub fn post_paint(
&mut self,
device: &Device,
queue: &Queue,
targets: &PostPaintTargets<'_>,
ctx: &GpuFrameContext<'_>,
) -> Vec<CommandBuffer>
pub fn post_paint( &mut self, device: &Device, queue: &Queue, targets: &PostPaintTargets<'_>, ctx: &GpuFrameContext<'_>, ) -> Vec<CommandBuffer>
Run every registered GPU plugin’s post_paint in ascending priority
order and return the concatenated command buffers.
Call after renderer.paint_to() has run for the frame. The host
supplies views of the just-rendered color and depth targets (and
optionally a pick-id view), and is responsible for compositing any
plugin overlay output into the final image: the lib does not loop
plugin output back into the rendered color.
Plugins registered after the first frame still go through init_gpu
on the next pre_prepare; this method does not trigger init on its
own to keep the post-paint path deterministic.
Sourcepub fn with_fixed_timestep(self, ts: FixedTimestep) -> Self
pub fn with_fixed_timestep(self, ts: FixedTimestep) -> Self
Enable fixed-timestep accumulation for physics plugins.
When set, plugins in the [SIMULATE, POST_SIM) range run once per
accumulated fixed step rather than once per frame at wall dt. All other
priority ranges always run once per frame.
Sourcepub fn set_fixed_timestep(&mut self, ts: FixedTimestep)
pub fn set_fixed_timestep(&mut self, ts: FixedTimestep)
Replace the fixed timestep at runtime. Resets the accumulator.
Use this to change the simulation rate after construction without rebuilding the runtime or its plugins.
Sourcepub fn clear_fixed_timestep(&mut self)
pub fn clear_fixed_timestep(&mut self)
Remove the fixed timestep, reverting to one simulate call per frame at wall dt.
Sourcepub fn mode(&self) -> SceneRuntimeMode
pub fn mode(&self) -> SceneRuntimeMode
The current runtime mode.
Sourcepub fn snapshots(&self) -> &TransformSnapshotTable
pub fn snapshots(&self) -> &TransformSnapshotTable
The transform snapshot table for interpolated rendering.
Updated each frame during writeback. Pass alpha as the
blend factor to TransformSnapshotTable::interpolated.
Sourcepub fn resources(&self) -> &RuntimeResources
pub fn resources(&self) -> &RuntimeResources
Read access to the shared resource registry.
Use this after step to inspect resources without running the frame loop.
During the frame loop, access resources through RuntimeStepContext::resources.
Sourcepub fn resources_mut(&mut self) -> &mut RuntimeResources
pub fn resources_mut(&mut self) -> &mut RuntimeResources
Write access to the shared resource registry.
Use this to pre-populate resources before the first step, or to inject
resources from outside the plugin system (e.g. from the application).
Sourcepub fn alpha(&self) -> f32
pub fn alpha(&self) -> f32
Blend factor for rendering interpolation between fixed steps.
Returns 1.0 if no fixed timestep is configured (render directly from
current scene transforms without interpolation).
Sourcepub fn step_index(&self) -> u64
pub fn step_index(&self) -> u64
Monotonically increasing simulation step counter.
Incremented once per simulate execution. With a fixed timestep this means it may increment multiple times per rendered frame. Wraps on overflow.
Sourcepub fn with_camera_follow(self, follow: CameraFollow) -> Self
pub fn with_camera_follow(self, follow: CameraFollow) -> Self
Set a camera follow binding (builder style).
Each call to step will compute a suggested camera center
from the followed node and emit it as a CameraFollowTarget event on
RuntimeOutput::events.
Sourcepub fn set_camera_follow(&mut self, follow: CameraFollow)
pub fn set_camera_follow(&mut self, follow: CameraFollow)
Update the camera follow binding at runtime.
Sourcepub fn clear_camera_follow(&mut self)
pub fn clear_camera_follow(&mut self)
Remove the camera follow binding. No CameraFollowTarget event
will be emitted after this call.
Sourcepub fn camera_follow(&self) -> Option<&CameraFollow>
pub fn camera_follow(&self) -> Option<&CameraFollow>
The current camera follow binding.
Sourcepub fn step(
&mut self,
scene: &mut Scene,
selection: &mut Selection,
frame: &RuntimeFrameContext,
) -> RuntimeOutput
pub fn step( &mut self, scene: &mut Scene, selection: &mut Selection, frame: &RuntimeFrameContext, ) -> RuntimeOutput
Run one frame of the runtime.
Plugins run in ascending priority order. The simulate range
[SIMULATE, POST_SIM) runs once per accumulated fixed step (or once at
frame.dt when no fixed timestep is configured). All other ranges run
once per frame. Transform ops are flushed to scene and the snapshot
table is updated after the writeback range.
Selection ops produced by plugins are applied to selection before returning.
Contact events and the applied transform ops are returned in RuntimeOutput.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ViewportRuntime
impl !Sync for ViewportRuntime
impl !UnwindSafe for ViewportRuntime
impl Freeze for ViewportRuntime
impl Send for ViewportRuntime
impl Unpin for ViewportRuntime
impl UnsafeUnpin for ViewportRuntime
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.