Skip to main content

Scene

Struct Scene 

Source
pub struct Scene { /* private fields */ }
Expand description

A scene graph managing nodes with parent-child hierarchy and layers.

Implementations§

Source§

impl Scene

Source

pub fn new() -> Self

Create an empty scene with a default layer.

Source

pub fn version(&self) -> u64

Monotonically increasing generation counter.

Incremented by wrapping_add(1) on every mutation. Compare against a cached value to detect scene changes without hashing instance data.

Source

pub fn add( &mut self, mesh_id: Option<MeshId>, transform: Mat4, material: Material, ) -> NodeId

Add a node with a mesh, transform, and material. Returns the new node’s ID.

Source

pub fn add_named( &mut self, name: &str, mesh_id: Option<MeshId>, transform: Mat4, material: Material, ) -> NodeId

Add a named node. Returns the new node’s ID.

Source

pub fn remove(&mut self, id: NodeId) -> Vec<NodeId>

Remove a node and all its descendants. Returns all removed IDs (caller can use these to release mesh references).

Source

pub fn set_parent(&mut self, child_id: NodeId, new_parent: Option<NodeId>)

Reparent a node. None makes it a root node.

Source

pub fn children(&self, id: NodeId) -> &[NodeId]

Children of a node.

Source

pub fn parent(&self, id: NodeId) -> Option<NodeId>

Parent of a node.

Source

pub fn roots(&self) -> &[NodeId]

Root nodes.

Source

pub fn set_local_transform(&mut self, id: NodeId, transform: Mat4)

Set the local transform of a node, marking it and its descendants dirty.

Source

pub fn set_visible(&mut self, id: NodeId, visible: bool)

Set node visibility.

Source

pub fn set_material(&mut self, id: NodeId, material: Material)

Set node material.

Source

pub fn set_appearance(&mut self, id: NodeId, appearance: ItemSettings)

Set node appearance overrides.

Source

pub fn set_mesh(&mut self, id: NodeId, mesh_id: Option<MeshId>)

Set node mesh.

Source

pub fn set_name(&mut self, id: NodeId, name: &str)

Set node name.

Source

pub fn set_skin_instance(&mut self, id: NodeId, instance: Option<u32>)

Set the GPU skinning instance ID for a node.

Some(instance_id) routes the node through the skinned pipeline using the joint palette uploaded via crate::ViewportGpuResources::set_skin_palette. None treats the node as static even if its mesh has skin data attached.

Source

pub fn set_receives_decals(&mut self, id: NodeId, v: bool)

Set whether projected decals land on this node’s surface.

Source

pub fn set_show_normals(&mut self, id: NodeId, show: bool)

Set whether to show normals.

Source

pub fn set_layer(&mut self, id: NodeId, layer: LayerId)

Set the layer of a node.

Source

pub fn node(&self, id: NodeId) -> Option<&SceneNode>

Get a reference to a node.

Source

pub fn node_count(&self) -> usize

Number of nodes in the scene.

Source

pub fn nodes(&self) -> impl Iterator<Item = &SceneNode>

Iterate over all nodes.

Source

pub fn add_layer(&mut self, name: &str) -> LayerId

Add a new layer, returning its ID.

Source

pub fn remove_layer(&mut self, id: LayerId)

Remove a layer, moving all its nodes to the default layer. Cannot remove the default layer (LayerId(0)).

Source

pub fn set_layer_visible(&mut self, id: LayerId, visible: bool)

Set layer visibility.

Source

pub fn set_layer_locked(&mut self, id: LayerId, locked: bool)

Set layer locked state. Locked layers render but nodes cannot appear selected.

Source

pub fn set_layer_colour(&mut self, id: LayerId, colour: [f32; 4])

Set layer display colour.

Source

pub fn set_layer_order(&mut self, id: LayerId, order: u32)

Set layer sort order.

Source

pub fn is_layer_locked(&self, id: LayerId) -> bool

Whether a layer is currently locked.

Source

pub fn layers(&self) -> Vec<&Layer>

All layers, sorted by their order field (ascending).

Source

pub fn create_group(&mut self, name: &str) -> GroupId

Create a new named group, returning its ID.

Source

pub fn remove_group(&mut self, id: GroupId)

Remove a group by ID. Does not affect its member nodes.

Source

pub fn add_to_group(&mut self, node: NodeId, group: GroupId)

Add a node to a group.

Source

pub fn remove_from_group(&mut self, node: NodeId, group: GroupId)

Remove a node from a group.

Source

pub fn get_group(&self, id: GroupId) -> Option<&Group>

Get a group by ID.

Source

pub fn groups(&self) -> &[Group]

All groups in the scene.

Source

pub fn node_groups(&self, node: NodeId) -> Vec<GroupId>

Which groups contain the given node.

Source

pub fn update_transforms(&mut self)

Recompute world transforms for all dirty nodes (BFS from roots).

Source

pub fn rebuild_spatial_index( &mut self, mesh_aabb_fn: impl Fn(MeshId) -> Option<Aabb>, )

Rebuild the spatial index from scratch.

Call this after bulk scene construction (level load, import) to avoid accumulating many incremental dirty updates. The index is maintained automatically from this point on.

Source

pub fn scene_stats(&self) -> SceneStats

Diagnostic statistics from the most recent collect_render_items_culled call.

Source

pub fn collect_render_items( &mut self, selection: &Selection, ) -> Vec<SceneRenderItem>

Update transforms and collect render items for all visible nodes.

Skips nodes that are invisible, on an invisible layer, or have no mesh. Marks selected nodes based on the provided Selection.

Source

pub fn collect_render_items_culled( &mut self, selection: &Selection, frustum: &Frustum, mesh_aabb_fn: impl Fn(MeshId) -> Option<Aabb>, ) -> (Vec<SceneRenderItem>, CullStats)

Update transforms and collect render items, culling objects outside the frustum.

Like collect_render_items, but skips objects whose world-space AABB is entirely outside the given frustum. mesh_aabb_fn should return the local-space AABB for a given MeshId (typically read from GpuMesh::aabb).

When the scene has at least 500 nodes, a loose octree spatial index is used to prune subtrees that are entirely outside the frustum. Below that threshold the existing flat walk is used.

Source

pub fn add_light(&mut self, light: LightSource) -> NodeId

Add a light source to the scene graph. Returns the new node’s ID.

The node has no mesh. Set its transform with Scene::set_local_transform to position and orient the light. For directional lights, rotation drives the shading direction; for point and spot lights, translation drives position.

Pass the result of Scene::collect_lights into SceneFrame::lights each frame so the renderer unions these lights with EffectsFrame::lighting.lights.

Source

pub fn collect_lights(&mut self) -> Vec<LightSource>

Collect world-space light sources from all visible nodes on visible layers.

Position and direction values are resolved from each node’s world transform: directional lights rotate their direction, point lights take their position from the world translation, and spot lights take both.

Push the returned vec into SceneFrame::lights each frame. The renderer unions it with EffectsFrame::lighting.lights before building the GPU light uniform.

Source

pub fn set_light(&mut self, id: NodeId, light: Option<LightSource>)

Replace the light source on a node. Pass None to remove the light.

Source

pub fn mesh_ref_count(&self, mesh_id: MeshId) -> usize

Count how many scene nodes reference the given mesh.

O(n) over all nodes. Useful for deciding when to free a GPU mesh.

Source

pub fn walk_depth_first(&self) -> Vec<(NodeId, usize)>

Depth-first traversal of the scene tree. Returns (NodeId, depth) pairs.

Source§

impl Scene

Source

pub fn add_decal(&mut self, item: DecalItem) -> DecalHandle

Add a permanent decal to the scene. Returns a handle for later removal.

Source

pub fn add_decal_with_lifetime( &mut self, item: DecalItem, lifetime: f32, fade_duration: f32, )

Add a decal that fades and is automatically removed after lifetime seconds.

fade_duration controls how many seconds the alpha ramps to zero before expiry. Pass 0.0 to use the default (20% of lifetime).

Source

pub fn add_decal_animated( &mut self, item: DecalItem, animation: DecalAnimation, lifetime: Option<f32>, ) -> DecalHandle

Add a decal with an optional animation and optional lifetime.

Source

pub fn remove_decal(&mut self, handle: DecalHandle)

Remove a decal by handle. No-op if the handle is no longer valid.

Source

pub fn update_decals(&mut self, dt: f32)

Advance all live decals by dt seconds and drop expired ones.

Call once per frame before Scene::collect_decal_items.

Source

pub fn collect_decal_items(&self) -> Vec<DecalItem>

Build the [DecalItem] list for this frame’s fd.scene.decals.

Applies lifetime fading (alpha ramps to 0 in the last 20% of life) and computes UV offset/scale for animated decals.

Trait Implementations§

Source§

impl Default for Scene

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Scene

§

impl RefUnwindSafe for Scene

§

impl Send for Scene

§

impl Sync for Scene

§

impl Unpin for Scene

§

impl UnsafeUnpin for Scene

§

impl UnwindSafe for Scene

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<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

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

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> Upcast<T> for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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