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_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_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_color(&mut self, id: LayerId, color: [f32; 4])

Set layer display color.

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

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.

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 + Sync + Send>

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 + Sync + Send>

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<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<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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