pub struct Scene {Show 17 fields
pub names: SecondaryMap<NodeHandle, Cow<'static, str>>,
pub meshes: SparseSecondaryMap<NodeHandle, Mesh>,
pub cameras: SparseSecondaryMap<NodeHandle, Camera>,
pub lights: SparseSecondaryMap<NodeHandle, Light>,
pub skins: SparseSecondaryMap<NodeHandle, SkinBinding>,
pub morph_weights: SparseSecondaryMap<NodeHandle, Vec<f32>>,
pub animation_mixers: SparseSecondaryMap<NodeHandle, AnimationMixer>,
pub rest_transforms: SparseSecondaryMap<NodeHandle, Transform>,
pub split_primitive_tags: SparseSecondaryMap<NodeHandle, SplitPrimitiveTag>,
pub skeleton_pool: SlotMap<SkeletonKey, Skeleton>,
pub environment: Environment,
pub tone_mapping: ToneMappingSettings,
pub bloom: BloomSettings,
pub ssao: SsaoSettings,
pub screen_space: ScreenSpaceSettings,
pub background: BackgroundSettings,
pub active_camera: Option<NodeHandle>,
/* private fields */
}Expand description
The scene graph container.
Scene is the pure data layer that stores scene graph hierarchy and component data.
Uses SlotMap + SecondaryMap for high-performance component-based storage.
§Storage Layout
nodes: Core node data (hierarchy and transforms) usingSlotMap- Dense components (names, meshes): Use
SecondaryMap - Sparse components (cameras, lights, skins): Use
SparseSecondaryMap
§Example
let mut scene = Scene::new();
// Create nodes
let root = scene.create_node_with_name("Root");
let child = scene.create_node_with_name("Child");
scene.attach(child, root);
// Add mesh component
scene.set_mesh(child, Mesh::new(geometry, material));Fields§
§names: SecondaryMap<NodeHandle, Cow<'static, str>>Node names - almost all nodes have a name
meshes: SparseSecondaryMap<NodeHandle, Mesh>Mesh components stored directly on nodes
cameras: SparseSecondaryMap<NodeHandle, Camera>Camera components stored directly on nodes
lights: SparseSecondaryMap<NodeHandle, Light>Light components stored directly on nodes
skins: SparseSecondaryMap<NodeHandle, SkinBinding>Skeletal skin bindings
morph_weights: SparseSecondaryMap<NodeHandle, Vec<f32>>Morph target weights
animation_mixers: SparseSecondaryMap<NodeHandle, AnimationMixer>Animation mixer components (sparse, only character roots have animations)
rest_transforms: SparseSecondaryMap<NodeHandle, Transform>Rest pose transforms recorded before animation takes over. Used to restore nodes when animations stop or blend with weight < 1.0.
Split primitive tags
skeleton_pool: SlotMap<SkeletonKey, Skeleton>Skeleton is a shared resource - multiple characters may reference the same skeleton definition
environment: EnvironmentScene environment settings (skybox, IBL)
tone_mapping: ToneMappingSettingsTone mapping settings (exposure, mode)
bloom: BloomSettingsBloom post-processing settings
ssao: SsaoSettingsSSAO (Screen Space Ambient Occlusion) settings
screen_space: ScreenSpaceSettingsScreen space effects settings (SSS, SSR)
background: BackgroundSettingsBackground rendering settings (mode + skybox uniform buffer)
active_camera: Option<NodeHandle>Currently active camera for rendering
Implementations§
Source§impl Scene
impl Scene
pub fn new() -> Scene
Sourcepub fn root_nodes(&self) -> &[NodeHandle]
pub fn root_nodes(&self) -> &[NodeHandle]
Returns a read-only slice of root-level node handles.
Sourcepub fn push_root_node(&mut self, handle: NodeHandle)
pub fn push_root_node(&mut self, handle: NodeHandle)
Registers a node as a root-level node (no parent).
Sourcepub fn nodes(&self) -> &SlotMap<NodeHandle, Node>
pub fn nodes(&self) -> &SlotMap<NodeHandle, Node>
Returns a read-only reference to the node storage.
Sourcepub fn create_node(&mut self) -> NodeHandle
pub fn create_node(&mut self) -> NodeHandle
Creates a new node and returns its handle.
Sourcepub fn create_node_with_name(&mut self, name: &str) -> NodeHandle
pub fn create_node_with_name(&mut self, name: &str) -> NodeHandle
Creates a new node with a name.
Sourcepub fn add_node(&mut self, node: Node) -> NodeHandle
pub fn add_node(&mut self, node: Node) -> NodeHandle
Adds a node to the scene (defaults to root level).
Sourcepub fn add_to_parent(
&mut self,
child: Node,
parent_handle: NodeHandle,
) -> NodeHandle
pub fn add_to_parent( &mut self, child: Node, parent_handle: NodeHandle, ) -> NodeHandle
Adds a node as a child of the specified parent.
Sourcepub fn remove_node(&mut self, handle: NodeHandle)
pub fn remove_node(&mut self, handle: NodeHandle)
Removes a node and all its descendants recursively.
Sourcepub fn attach(&mut self, child_handle: NodeHandle, parent_handle: NodeHandle)
pub fn attach(&mut self, child_handle: NodeHandle, parent_handle: NodeHandle)
Attaches a node as a child of another (establishes parent-child relationship).
Sourcepub fn get_node(&self, handle: NodeHandle) -> Option<&Node>
pub fn get_node(&self, handle: NodeHandle) -> Option<&Node>
Returns a read-only reference to a node.
Sourcepub fn get_node_mut(&mut self, handle: NodeHandle) -> Option<&mut Node>
pub fn get_node_mut(&mut self, handle: NodeHandle) -> Option<&mut Node>
Returns a mutable reference to a node.
Sourcepub fn set_name(&mut self, handle: NodeHandle, name: &str)
pub fn set_name(&mut self, handle: NodeHandle, name: &str)
Sets the name for a node.
Sourcepub fn get_name(&self, handle: NodeHandle) -> Option<&str>
pub fn get_name(&self, handle: NodeHandle) -> Option<&str>
Returns the name of a node.
Sourcepub fn set_mesh(&mut self, handle: NodeHandle, mesh: Mesh)
pub fn set_mesh(&mut self, handle: NodeHandle, mesh: Mesh)
Sets the mesh component for a node.
Sourcepub fn get_mesh(&self, handle: NodeHandle) -> Option<&Mesh>
pub fn get_mesh(&self, handle: NodeHandle) -> Option<&Mesh>
Gets a reference to the node’s Mesh component
Sourcepub fn get_mesh_mut(&mut self, handle: NodeHandle) -> Option<&mut Mesh>
pub fn get_mesh_mut(&mut self, handle: NodeHandle) -> Option<&mut Mesh>
Gets a mutable reference to the node’s Mesh component
Sourcepub fn set_camera(&mut self, handle: NodeHandle, camera: Camera)
pub fn set_camera(&mut self, handle: NodeHandle, camera: Camera)
Sets the Camera component for a node
Sourcepub fn get_camera(&self, handle: NodeHandle) -> Option<&Camera>
pub fn get_camera(&self, handle: NodeHandle) -> Option<&Camera>
Gets a reference to the node’s Camera component
Sourcepub fn get_camera_mut(&mut self, handle: NodeHandle) -> Option<&mut Camera>
pub fn get_camera_mut(&mut self, handle: NodeHandle) -> Option<&mut Camera>
Gets a mutable reference to the node’s Camera component
Sourcepub fn set_light(&mut self, handle: NodeHandle, light: Light)
pub fn set_light(&mut self, handle: NodeHandle, light: Light)
Sets the Light component for a node
Sourcepub fn get_light(&self, handle: NodeHandle) -> Option<&Light>
pub fn get_light(&self, handle: NodeHandle) -> Option<&Light>
Gets a reference to the node’s Light component
Sourcepub fn get_light_mut(&mut self, handle: NodeHandle) -> Option<&mut Light>
pub fn get_light_mut(&mut self, handle: NodeHandle) -> Option<&mut Light>
Gets a mutable reference to the node’s Light component
Sourcepub fn get_light_bundle(
&mut self,
handle: NodeHandle,
) -> Option<(&mut Light, &mut Node)>
pub fn get_light_bundle( &mut self, handle: NodeHandle, ) -> Option<(&mut Light, &mut Node)>
Gets both the Light component and Transform for a node (for light processing)
Sourcepub fn bind_skeleton(
&mut self,
handle: NodeHandle,
skeleton_key: SkeletonKey,
bind_mode: BindMode,
)
pub fn bind_skeleton( &mut self, handle: NodeHandle, skeleton_key: SkeletonKey, bind_mode: BindMode, )
Binds a skeleton to a node
Sourcepub fn get_skin(&self, handle: NodeHandle) -> Option<&SkinBinding>
pub fn get_skin(&self, handle: NodeHandle) -> Option<&SkinBinding>
Gets the node’s skin binding
Sourcepub fn set_morph_weights(&mut self, handle: NodeHandle, weights: Vec<f32>)
pub fn set_morph_weights(&mut self, handle: NodeHandle, weights: Vec<f32>)
Sets morph weights
Sourcepub fn get_morph_weights(&self, handle: NodeHandle) -> Option<&Vec<f32>>
pub fn get_morph_weights(&self, handle: NodeHandle) -> Option<&Vec<f32>>
Gets morph weights
Sourcepub fn get_morph_weights_mut(
&mut self,
handle: NodeHandle,
) -> Option<&mut Vec<f32>>
pub fn get_morph_weights_mut( &mut self, handle: NodeHandle, ) -> Option<&mut Vec<f32>>
Gets a mutable reference to morph weights
Sourcepub fn set_morph_weights_from_pod(
&mut self,
handle: NodeHandle,
data: &MorphWeightData,
)
pub fn set_morph_weights_from_pod( &mut self, handle: NodeHandle, data: &MorphWeightData, )
Sets morph weights for a node (from POD data)
pub fn iter_active_lights(&self) -> impl Iterator<Item = (&Light, &Affine3A)>
Sourcepub fn query_main_camera_bundle(
&mut self,
) -> Option<(&mut Transform, &mut Camera)>
pub fn query_main_camera_bundle( &mut self, ) -> Option<(&mut Transform, &mut Camera)>
Gets the (Transform, Camera) bundle for the main camera
pub fn query_camera_bundle( &mut self, node_handle: NodeHandle, ) -> Option<(&mut Transform, &mut Camera)>
Sourcepub fn query_light_bundle(
&mut self,
node_handle: NodeHandle,
) -> Option<(&mut Transform, &Light)>
pub fn query_light_bundle( &mut self, node_handle: NodeHandle, ) -> Option<(&mut Transform, &Light)>
Queries the Transform and Light for a specified node
Sourcepub fn query_mesh_bundle(
&mut self,
node_handle: NodeHandle,
) -> Option<(&mut Transform, &Mesh)>
pub fn query_mesh_bundle( &mut self, node_handle: NodeHandle, ) -> Option<(&mut Transform, &Mesh)>
Queries the Transform and Mesh for a specified node
Sourcepub fn update_matrix_world(&mut self)
pub fn update_matrix_world(&mut self)
Updates world matrices for the entire scene
Sourcepub fn update_subtree(&mut self, root_handle: NodeHandle)
pub fn update_subtree(&mut self, root_handle: NodeHandle)
Updates world matrices for a specified subtree
pub fn add_mesh(&mut self, mesh: Mesh) -> NodeHandle
pub fn add_mesh_to_parent( &mut self, mesh: Mesh, parent: NodeHandle, ) -> NodeHandle
pub fn add_skeleton(&mut self, skeleton: Skeleton) -> SkeletonKey
pub fn add_camera(&mut self, camera: Camera) -> NodeHandle
pub fn add_camera_to_parent( &mut self, camera: Camera, parent: NodeHandle, ) -> NodeHandle
pub fn add_light(&mut self, light: Light) -> NodeHandle
pub fn add_light_to_parent( &mut self, light: Light, parent: NodeHandle, ) -> NodeHandle
pub fn mark_as_split_primitive(&mut self, handle: NodeHandle)
Sourcepub fn shader_defines(&self) -> &ShaderDefines
pub fn shader_defines(&self) -> &ShaderDefines
Computes the scene’s shader macro definitions
Uses internal caching mechanism, only recalculates when Environment version changes.
pub fn add_logic<L>(&mut self, logic: L)where
L: SceneLogic,
Sourcepub fn on_update<F>(&mut self, f: F)
pub fn on_update<F>(&mut self, f: F)
Shortcut method: Add closure logic (for quick prototyping)
Sourcepub fn sync_gpu_buffers(&mut self)
pub fn sync_gpu_buffers(&mut self)
Syncs GPU Buffer data
pub fn light_storage(&self) -> &CpuBuffer<Vec<GpuLightStorage>>
pub fn environment_uniforms(&self) -> &CpuBuffer<EnvironmentUniforms>
pub fn update_skeletons(&mut self)
pub fn sync_morph_weights(&mut self)
pub fn main_camera_node_mut(&mut self) -> Option<&mut Node>
pub fn main_camera_node(&self) -> Option<&Node>
Sourcepub fn set_background_color(&mut self, r: f32, g: f32, b: f32)
pub fn set_background_color(&mut self, r: f32, g: f32, b: f32)
Sets the background to a solid color.
Sourcepub fn node(&mut self, handle: &NodeHandle) -> SceneNode<'_>
pub fn node(&mut self, handle: &NodeHandle) -> SceneNode<'_>
Sourcepub fn build_node(&mut self, name: &str) -> NodeBuilder<'_>
pub fn build_node(&mut self, name: &str) -> NodeBuilder<'_>
Starts building a node
Sourcepub fn find_node_by_name(&self, name: &str) -> Option<NodeHandle>
pub fn find_node_by_name(&self, name: &str) -> Option<NodeHandle>
Finds a node by name
Sourcepub fn get_global_transform(&self, handle: NodeHandle) -> Affine3A
pub fn get_global_transform(&self, handle: NodeHandle) -> Affine3A
Gets the global transform matrix of a node
Sourcepub fn play_animation(&mut self, node_handle: NodeHandle, clip_name: &str)
pub fn play_animation(&mut self, node_handle: NodeHandle, clip_name: &str)
Plays a specific animation clip on the node (if an AnimationMixer is present)
Sourcepub fn play_if_any_animation(&mut self, node_handle: NodeHandle)
pub fn play_if_any_animation(&mut self, node_handle: NodeHandle)
Plays any animation on the node (used for simple cases where clip name is not important)
Sourcepub fn get_bbox_of_node(
&self,
node_handle: NodeHandle,
query: &impl GeometryQuery,
) -> Option<BoundingBox>
pub fn get_bbox_of_node( &self, node_handle: NodeHandle, query: &impl GeometryQuery, ) -> Option<BoundingBox>
Recursively computes the world-space bounding box enclosing a node and all its descendants.
query implements crate::GeometryQuery to map geometry handles to local-space bounding boxes.
Trait Implementations§
Source§impl AnimationTarget for Scene
impl AnimationTarget for Scene
Source§fn node_children(&self, handle: NodeHandle) -> Option<Vec<NodeHandle>>
fn node_children(&self, handle: NodeHandle) -> Option<Vec<NodeHandle>>
Source§fn node_transform(&self, handle: NodeHandle) -> Option<Transform>
fn node_transform(&self, handle: NodeHandle) -> Option<Transform>
Source§fn set_node_position(&mut self, handle: NodeHandle, position: Vec3)
fn set_node_position(&mut self, handle: NodeHandle, position: Vec3)
Source§fn set_node_rotation(&mut self, handle: NodeHandle, rotation: Quat)
fn set_node_rotation(&mut self, handle: NodeHandle, rotation: Quat)
Source§fn set_node_scale(&mut self, handle: NodeHandle, scale: Vec3)
fn set_node_scale(&mut self, handle: NodeHandle, scale: Vec3)
Source§fn mark_node_dirty(&mut self, handle: NodeHandle)
fn mark_node_dirty(&mut self, handle: NodeHandle)
Source§fn has_rest_transform(&self, handle: NodeHandle) -> bool
fn has_rest_transform(&self, handle: NodeHandle) -> bool
Source§fn rest_transform(&self, handle: NodeHandle) -> Option<Transform>
fn rest_transform(&self, handle: NodeHandle) -> Option<Transform>
Source§fn store_rest_transform(&mut self, handle: NodeHandle, transform: Transform)
fn store_rest_transform(&mut self, handle: NodeHandle, transform: Transform)
Source§fn morph_weights_mut(&mut self, handle: NodeHandle) -> &mut Vec<f32>
fn morph_weights_mut(&mut self, handle: NodeHandle) -> &mut Vec<f32>
Source§impl Bindings for Scene
impl Bindings for Scene
fn define_bindings<'a>(&'a self, _builder: &mut ResourceBuilder<'a>)
Source§impl SceneExt for Scene
impl SceneExt for Scene
Source§fn instantiate(&mut self, prefab: &Prefab) -> NodeHandle
fn instantiate(&mut self, prefab: &Prefab) -> NodeHandle
Prefab into the scene, returning the root node handle.Source§fn spawn(
&mut self,
geometry: impl ResolveGeometry,
material: impl ResolveMaterial,
assets: &AssetServer,
) -> NodeHandle
fn spawn( &mut self, geometry: impl ResolveGeometry, material: impl ResolveMaterial, assets: &AssetServer, ) -> NodeHandle
Source§fn spawn_box(
&mut self,
w: f32,
h: f32,
d: f32,
material: impl ResolveMaterial,
assets: &AssetServer,
) -> NodeHandle
fn spawn_box( &mut self, w: f32, h: f32, d: f32, material: impl ResolveMaterial, assets: &AssetServer, ) -> NodeHandle
Source§fn spawn_sphere(
&mut self,
radius: f32,
material: impl ResolveMaterial,
assets: &AssetServer,
) -> NodeHandle
fn spawn_sphere( &mut self, radius: f32, material: impl ResolveMaterial, assets: &AssetServer, ) -> NodeHandle
Source§fn spawn_plane(
&mut self,
width: f32,
height: f32,
material: impl ResolveMaterial,
assets: &AssetServer,
) -> NodeHandle
fn spawn_plane( &mut self, width: f32, height: f32, material: impl ResolveMaterial, assets: &AssetServer, ) -> NodeHandle
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>. Box<dyn Any> can
then be further downcast into Box<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>. Rc<Any> 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> 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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().