Skip to main content

Scene

Struct Scene 

Source
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) using SlotMap
  • 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: SparseSecondaryMap<NodeHandle, SplitPrimitiveTag>

Split primitive tags

§skeleton_pool: SlotMap<SkeletonKey, Skeleton>

Skeleton is a shared resource - multiple characters may reference the same skeleton definition

§environment: Environment

Scene environment settings (skybox, IBL)

§tone_mapping: ToneMappingSettings

Tone mapping settings (exposure, mode)

§bloom: BloomSettings

Bloom post-processing settings

§ssao: SsaoSettings

SSAO (Screen Space Ambient Occlusion) settings

§screen_space: ScreenSpaceSettings

Screen space effects settings (SSS, SSR)

§background: BackgroundSettings

Background rendering settings (mode + skybox uniform buffer)

§active_camera: Option<NodeHandle>

Currently active camera for rendering

Implementations§

Source§

impl Scene

Source

pub fn new() -> Scene

Source

pub fn id(&self) -> u32

Returns the unique scene identifier.

Source

pub fn root_nodes(&self) -> &[NodeHandle]

Returns a read-only slice of root-level node handles.

Source

pub fn push_root_node(&mut self, handle: NodeHandle)

Registers a node as a root-level node (no parent).

Source

pub fn nodes(&self) -> &SlotMap<NodeHandle, Node>

Returns a read-only reference to the node storage.

Source

pub fn create_node(&mut self) -> NodeHandle

Creates a new node and returns its handle.

Source

pub fn create_node_with_name(&mut self, name: &str) -> NodeHandle

Creates a new node with a name.

Source

pub fn add_node(&mut self, node: Node) -> NodeHandle

Adds a node to the scene (defaults to root level).

Source

pub fn add_to_parent( &mut self, child: Node, parent_handle: NodeHandle, ) -> NodeHandle

Adds a node as a child of the specified parent.

Source

pub fn remove_node(&mut self, handle: NodeHandle)

Removes a node and all its descendants recursively.

Source

pub fn attach(&mut self, child_handle: NodeHandle, parent_handle: NodeHandle)

Attaches a node as a child of another (establishes parent-child relationship).

Source

pub fn get_node(&self, handle: NodeHandle) -> Option<&Node>

Returns a read-only reference to a node.

Source

pub fn get_node_mut(&mut self, handle: NodeHandle) -> Option<&mut Node>

Returns a mutable reference to a node.

Source

pub fn set_name(&mut self, handle: NodeHandle, name: &str)

Sets the name for a node.

Source

pub fn get_name(&self, handle: NodeHandle) -> Option<&str>

Returns the name of a node.

Source

pub fn set_mesh(&mut self, handle: NodeHandle, mesh: Mesh)

Sets the mesh component for a node.

Source

pub fn get_mesh(&self, handle: NodeHandle) -> Option<&Mesh>

Gets a reference to the node’s Mesh component

Source

pub fn get_mesh_mut(&mut self, handle: NodeHandle) -> Option<&mut Mesh>

Gets a mutable reference to the node’s Mesh component

Source

pub fn set_camera(&mut self, handle: NodeHandle, camera: Camera)

Sets the Camera component for a node

Source

pub fn get_camera(&self, handle: NodeHandle) -> Option<&Camera>

Gets a reference to the node’s Camera component

Source

pub fn get_camera_mut(&mut self, handle: NodeHandle) -> Option<&mut Camera>

Gets a mutable reference to the node’s Camera component

Source

pub fn set_light(&mut self, handle: NodeHandle, light: Light)

Sets the Light component for a node

Source

pub fn get_light(&self, handle: NodeHandle) -> Option<&Light>

Gets a reference to the node’s Light component

Source

pub fn get_light_mut(&mut self, handle: NodeHandle) -> Option<&mut Light>

Gets a mutable reference to the node’s Light component

Source

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)

Source

pub fn bind_skeleton( &mut self, handle: NodeHandle, skeleton_key: SkeletonKey, bind_mode: BindMode, )

Binds a skeleton to a node

Source

pub fn get_skin(&self, handle: NodeHandle) -> Option<&SkinBinding>

Gets the node’s skin binding

Source

pub fn set_morph_weights(&mut self, handle: NodeHandle, weights: Vec<f32>)

Sets morph weights

Source

pub fn get_morph_weights(&self, handle: NodeHandle) -> Option<&Vec<f32>>

Gets morph weights

Source

pub fn get_morph_weights_mut( &mut self, handle: NodeHandle, ) -> Option<&mut Vec<f32>>

Gets a mutable reference to morph weights

Source

pub fn set_morph_weights_from_pod( &mut self, handle: NodeHandle, data: &MorphWeightData, )

Sets morph weights for a node (from POD data)

Source

pub fn iter_active_lights(&self) -> impl Iterator<Item = (&Light, &Affine3A)>

Source

pub fn query_main_camera_bundle( &mut self, ) -> Option<(&mut Transform, &mut Camera)>

Gets the (Transform, Camera) bundle for the main camera

Source

pub fn query_camera_bundle( &mut self, node_handle: NodeHandle, ) -> Option<(&mut Transform, &mut Camera)>

Source

pub fn query_light_bundle( &mut self, node_handle: NodeHandle, ) -> Option<(&mut Transform, &Light)>

Queries the Transform and Light for a specified node

Source

pub fn query_mesh_bundle( &mut self, node_handle: NodeHandle, ) -> Option<(&mut Transform, &Mesh)>

Queries the Transform and Mesh for a specified node

Source

pub fn update_matrix_world(&mut self)

Updates world matrices for the entire scene

Source

pub fn update_subtree(&mut self, root_handle: NodeHandle)

Updates world matrices for a specified subtree

Source

pub fn add_mesh(&mut self, mesh: Mesh) -> NodeHandle

Source

pub fn add_mesh_to_parent( &mut self, mesh: Mesh, parent: NodeHandle, ) -> NodeHandle

Source

pub fn add_skeleton(&mut self, skeleton: Skeleton) -> SkeletonKey

Source

pub fn add_camera(&mut self, camera: Camera) -> NodeHandle

Source

pub fn add_camera_to_parent( &mut self, camera: Camera, parent: NodeHandle, ) -> NodeHandle

Source

pub fn add_light(&mut self, light: Light) -> NodeHandle

Source

pub fn add_light_to_parent( &mut self, light: Light, parent: NodeHandle, ) -> NodeHandle

Source

pub fn mark_as_split_primitive(&mut self, handle: NodeHandle)

Source

pub fn shader_defines(&self) -> &ShaderDefines

Computes the scene’s shader macro definitions

Uses internal caching mechanism, only recalculates when Environment version changes.

Source

pub fn add_logic<L>(&mut self, logic: L)
where L: SceneLogic,

Source

pub fn on_update<F>(&mut self, f: F)
where F: FnMut(&mut Scene, &Input, f32) + Send + Sync + 'static,

Shortcut method: Add closure logic (for quick prototyping)

Source

pub fn update(&mut self, input: &Input, dt: f32)

Updates scene state (called every frame)

Source

pub fn sync_gpu_buffers(&mut self)

Syncs GPU Buffer data

Source

pub fn light_storage(&self) -> &CpuBuffer<Vec<GpuLightStorage>>

Source

pub fn environment_uniforms(&self) -> &CpuBuffer<EnvironmentUniforms>

Source

pub fn update_skeletons(&mut self)

Source

pub fn sync_morph_weights(&mut self)

Source

pub fn main_camera_node_mut(&mut self) -> Option<&mut Node>

Source

pub fn main_camera_node(&self) -> Option<&Node>

Source

pub fn set_background_color(&mut self, r: f32, g: f32, b: f32)

Sets the background to a solid color.

Source

pub fn node(&mut self, handle: &NodeHandle) -> SceneNode<'_>

Returns a chainable wrapper for the given node.

Silently no-ops if the handle is stale, avoiding unwrap().

§Example
scene.node(&handle)
    .set_position(0.0, 3.0, 0.0)
    .set_scale(2.0)
    .look_at(Vec3::ZERO);
Source

pub fn build_node(&mut self, name: &str) -> NodeBuilder<'_>

Starts building a node

Source

pub fn find_node_by_name(&self, name: &str) -> Option<NodeHandle>

Finds a node by name

Source

pub fn get_global_transform(&self, handle: NodeHandle) -> Affine3A

Gets the global transform matrix of a node

Source

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)

Source

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)

Source

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

Source§

fn node_children(&self, handle: NodeHandle) -> Option<Vec<NodeHandle>>

Get the children of a node.
Source§

fn node_name(&self, handle: NodeHandle) -> Option<String>

Get a node’s name.
Source§

fn node_transform(&self, handle: NodeHandle) -> Option<Transform>

Get a node’s transform.
Source§

fn set_node_position(&mut self, handle: NodeHandle, position: Vec3)

Get a mutable reference and apply a transform mutation.
Source§

fn set_node_rotation(&mut self, handle: NodeHandle, rotation: Quat)

Set a node’s rotation.
Source§

fn set_node_scale(&mut self, handle: NodeHandle, scale: Vec3)

Set a node’s scale.
Source§

fn mark_node_dirty(&mut self, handle: NodeHandle)

Mark a node’s transform as dirty (needs hierarchy update).
Source§

fn has_rest_transform(&self, handle: NodeHandle) -> bool

Check if a rest transform exists for a node.
Source§

fn rest_transform(&self, handle: NodeHandle) -> Option<Transform>

Get the rest transform for a node.
Source§

fn store_rest_transform(&mut self, handle: NodeHandle, transform: Transform)

Store a rest transform for a node.
Source§

fn morph_weights_mut(&mut self, handle: NodeHandle) -> &mut Vec<f32>

Get or create a mutable morph weights vector for a node.
Source§

impl Bindings for Scene

Source§

fn define_bindings<'a>(&'a self, _builder: &mut ResourceBuilder<'a>)

Source§

impl Default for Scene

Source§

fn default() -> Scene

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

impl SceneExt for Scene

Source§

fn instantiate(&mut self, prefab: &Prefab) -> NodeHandle

Instantiates a Prefab into the scene, returning the root node handle.
Source§

fn spawn( &mut self, geometry: impl ResolveGeometry, material: impl ResolveMaterial, assets: &AssetServer, ) -> NodeHandle

Spawns a mesh node from any geometry/material combination. Read more
Source§

fn spawn_box( &mut self, w: f32, h: f32, d: f32, material: impl ResolveMaterial, assets: &AssetServer, ) -> NodeHandle

Spawns a box mesh node.
Source§

fn spawn_sphere( &mut self, radius: f32, material: impl ResolveMaterial, assets: &AssetServer, ) -> NodeHandle

Spawns a sphere mesh node.
Source§

fn spawn_plane( &mut self, width: f32, height: f32, material: impl ResolveMaterial, assets: &AssetServer, ) -> NodeHandle

Spawns a plane mesh node.

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>

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

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

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

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

Source§

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

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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,