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_appearance(&mut self, id: NodeId, appearance: ItemSettings)
pub fn set_appearance(&mut self, id: NodeId, appearance: ItemSettings)
Set node appearance overrides.
Sourcepub fn set_deform_instance(&mut self, id: NodeId, instance: Option<u32>)
pub fn set_deform_instance(&mut self, id: NodeId, instance: Option<u32>)
Set the per-instance deformer ID for a node.
Addresses per-(mesh, instance) deformer data such as a GPU skinning
joint palette. None treats the node as having no per-instance
deformer data and uses the per-mesh slot only.
Sourcepub fn set_receives_decals(&mut self, id: NodeId, v: bool)
pub fn set_receives_decals(&mut self, id: NodeId, v: bool)
Set whether projected decals land on this node’s surface.
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_colour(&mut self, id: LayerId, colour: [f32; 4])
pub fn set_layer_colour(&mut self, id: LayerId, colour: [f32; 4])
Set layer display colour.
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 rebuild_spatial_index(
&mut self,
mesh_aabb_fn: impl Fn(MeshId) -> Option<Aabb>,
)
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.
Sourcepub fn scene_stats(&self) -> SceneStats
pub fn scene_stats(&self) -> SceneStats
Diagnostic statistics from the most recent collect_render_items_culled call.
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).
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.
Sourcepub fn add_light(&mut self, light: LightSource) -> NodeId
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.
Sourcepub fn collect_lights(&mut self) -> Vec<LightSource>
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.
Sourcepub fn set_light(&mut self, id: NodeId, light: Option<LightSource>)
pub fn set_light(&mut self, id: NodeId, light: Option<LightSource>)
Replace the light source on a node. Pass None to remove the light.
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.
Source§impl Scene
impl Scene
Sourcepub fn add_decal(&mut self, item: DecalItem) -> DecalHandle
pub fn add_decal(&mut self, item: DecalItem) -> DecalHandle
Add a permanent decal to the scene. Returns a handle for later removal.
Sourcepub fn add_decal_with_lifetime(
&mut self,
item: DecalItem,
lifetime: f32,
fade_duration: f32,
)
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).
Sourcepub fn add_decal_animated(
&mut self,
item: DecalItem,
animation: DecalAnimation,
lifetime: Option<f32>,
) -> DecalHandle
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.
Sourcepub fn remove_decal(&mut self, handle: DecalHandle)
pub fn remove_decal(&mut self, handle: DecalHandle)
Remove a decal by handle. No-op if the handle is no longer valid.
Sourcepub fn update_decals(&mut self, dt: f32)
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.
Sourcepub fn collect_decal_items(&self) -> Vec<DecalItem>
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§
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
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> 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<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.