pub struct Scene { /* private fields */ }Expand description
A scene graph managing nodes with parent-child hierarchy and layers.
Implementations§
Source§impl Scene
impl Scene
Sourcepub fn version(&self) -> u64
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.
Sourcepub fn add(
&mut self,
mesh_id: Option<MeshId>,
transform: Mat4,
material: Material,
) -> NodeId
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.
Sourcepub fn add_named(
&mut self,
name: &str,
mesh_id: Option<MeshId>,
transform: Mat4,
material: Material,
) -> NodeId
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.
Sourcepub fn remove(&mut self, id: NodeId) -> Vec<NodeId> ⓘ
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).
Sourcepub fn set_parent(&mut self, child_id: NodeId, new_parent: Option<NodeId>)
pub fn set_parent(&mut self, child_id: NodeId, new_parent: Option<NodeId>)
Reparent a node. None makes it a root node.
Sourcepub fn set_local_transform(&mut self, id: NodeId, transform: Mat4)
pub fn set_local_transform(&mut self, id: NodeId, transform: Mat4)
Set the local transform of a node, marking it and its descendants dirty.
Sourcepub fn set_visible(&mut self, id: NodeId, visible: bool)
pub fn set_visible(&mut self, id: NodeId, visible: bool)
Set node visibility.
Sourcepub fn set_material(&mut self, id: NodeId, material: Material)
pub fn set_material(&mut self, id: NodeId, material: Material)
Set node material.
Sourcepub fn set_show_normals(&mut self, id: NodeId, show: bool)
pub fn set_show_normals(&mut self, id: NodeId, show: bool)
Set whether to show normals.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the scene.
Sourcepub fn remove_layer(&mut self, id: LayerId)
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)).
Sourcepub fn set_layer_visible(&mut self, id: LayerId, visible: bool)
pub fn set_layer_visible(&mut self, id: LayerId, visible: bool)
Set layer visibility.
Sourcepub fn set_layer_locked(&mut self, id: LayerId, locked: bool)
pub fn set_layer_locked(&mut self, id: LayerId, locked: bool)
Set layer locked state. Locked layers render but nodes cannot appear selected.
Sourcepub fn set_layer_color(&mut self, id: LayerId, color: [f32; 4])
pub fn set_layer_color(&mut self, id: LayerId, color: [f32; 4])
Set layer display color.
Sourcepub fn set_layer_order(&mut self, id: LayerId, order: u32)
pub fn set_layer_order(&mut self, id: LayerId, order: u32)
Set layer sort order.
Sourcepub fn is_layer_locked(&self, id: LayerId) -> bool
pub fn is_layer_locked(&self, id: LayerId) -> bool
Whether a layer is currently locked.
Sourcepub fn create_group(&mut self, name: &str) -> GroupId
pub fn create_group(&mut self, name: &str) -> GroupId
Create a new named group, returning its ID.
Sourcepub fn remove_group(&mut self, id: GroupId)
pub fn remove_group(&mut self, id: GroupId)
Remove a group by ID. Does not affect its member nodes.
Sourcepub fn add_to_group(&mut self, node: NodeId, group: GroupId)
pub fn add_to_group(&mut self, node: NodeId, group: GroupId)
Add a node to a group.
Sourcepub fn remove_from_group(&mut self, node: NodeId, group: GroupId)
pub fn remove_from_group(&mut self, node: NodeId, group: GroupId)
Remove a node from a group.
Sourcepub fn node_groups(&self, node: NodeId) -> Vec<GroupId>
pub fn node_groups(&self, node: NodeId) -> Vec<GroupId>
Which groups contain the given node.
Sourcepub fn update_transforms(&mut self)
pub fn update_transforms(&mut self)
Recompute world transforms for all dirty nodes (BFS from roots).
Sourcepub fn collect_render_items(
&mut self,
selection: &Selection,
) -> Vec<SceneRenderItem>
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.
Sourcepub fn collect_render_items_culled(
&mut self,
selection: &Selection,
frustum: &Frustum,
mesh_aabb_fn: impl Fn(MeshId) -> Option<Aabb>,
) -> (Vec<SceneRenderItem>, CullStats)
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).
Sourcepub fn mesh_ref_count(&self, mesh_id: MeshId) -> usize
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.
Sourcepub fn walk_depth_first(&self) -> Vec<(NodeId, usize)>
pub fn walk_depth_first(&self) -> Vec<(NodeId, usize)>
Depth-first traversal of the scene tree. Returns (NodeId, depth) pairs.
Trait Implementations§
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> 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
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> DowncastSync for T
impl<T> DowncastSync 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<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.