pub struct Scene { /* private fields */ }Expand description
A hierarchical scene graph for storing and organizing nodes.
the scene manages the Scene Tree which stores Nodes in a Tree structure meaning Nodes can have children. Nodes are stored internally using a RWLock to allow mutibility because of this borrow checking is runtime managed and calling .write on the same node twice at once will panic.
§Example
let scene = Scene::new();
let camera = scene.add("main_camera", Camera3D::default());
let player = Scene.add("player", Player::default());
player.add_child("tool", Tool::new());Implementations§
Source§impl<'a> Scene
impl<'a> Scene
pub fn new() -> Scene
Sourcepub fn spawn<T>(&'a self, name: impl Into<String>, node: T) -> NodeHandle<'a, T>where
T: Node,
pub fn spawn<T>(&'a self, name: impl Into<String>, node: T) -> NodeHandle<'a, T>where
T: Node,
Adds a node to the root of the scene with no parents.
Sourcepub fn spawn_as_child<T>(
&'a self,
name: impl Into<String>,
node: T,
parent: NodeId,
) -> NodeHandle<'a, T>where
T: Node,
pub fn spawn_as_child<T>(
&'a self,
name: impl Into<String>,
node: T,
parent: NodeId,
) -> NodeHandle<'a, T>where
T: Node,
Adds a node to the scene with a parent
Sourcepub fn on<E, N>(
&self,
node: NodeId,
handler: impl FnMut(EventCtx<'_, E, N>) + SendSync + 'static,
)where
E: EventLabel,
N: Node,
pub fn on<E, N>(
&self,
node: NodeId,
handler: impl FnMut(EventCtx<'_, E, N>) + SendSync + 'static,
)where
E: EventLabel,
N: Node,
add an event to a node
Sourcepub fn merge(&self, other: impl Into<Scene>) -> Vec<NodeId>
pub fn merge(&self, other: impl Into<Scene>) -> Vec<NodeId>
merge a different scene into this one preserving the hierarchy.
Sourcepub fn merge_as_child(
&self,
other: impl Into<Scene>,
parent: NodeId,
) -> Vec<NodeId>
pub fn merge_as_child( &self, other: impl Into<Scene>, parent: NodeId, ) -> Vec<NodeId>
merge a different scene as a child of a specified node
Sourcepub fn merge_asset<T>(&self, handle: AssetHandle<T>)where
T: Asset + SceneAsset,
pub fn merge_asset<T>(&self, handle: AssetHandle<T>)where
T: Asset + SceneAsset,
merge a scene without blocking the load
Sourcepub fn merge_asset_as_child<T>(&self, handle: AssetHandle<T>, parent: NodeId)where
T: Asset + SceneAsset,
pub fn merge_asset_as_child<T>(&self, handle: AssetHandle<T>, parent: NodeId)where
T: Asset + SceneAsset,
merge a scene assent as a child of a node
Sourcepub fn get<T>(&'a self, id: NodeId) -> Option<NodeHandle<'a, T>>where
T: Node,
pub fn get<T>(&'a self, id: NodeId) -> Option<NodeHandle<'a, T>>where
T: Node,
get handle to a node via an id
Sourcepub fn get_by_name<T>(&'a self, name: &str) -> Option<NodeHandle<'a, T>>where
T: Node,
pub fn get_by_name<T>(&'a self, name: &str) -> Option<NodeHandle<'a, T>>where
T: Node,
get a node by name
Sourcepub fn collect<T>(&'a self) -> Vec<NodeHandle<'a, T>>where
T: Node,
pub fn collect<T>(&'a self) -> Vec<NodeHandle<'a, T>>where
T: Node,
collects all nodes of a specific type
Sourcepub fn emit<E>(&self, event: &E, ctx: &GameContext)where
E: EventLabel,
pub fn emit<E>(&self, event: &E, ctx: &GameContext)where
E: EventLabel,
emit an event to the scene (this will also update world space transforms)
Sourcepub fn sync_world_transform(&self)
pub fn sync_world_transform(&self)
goes through every node and updates the world position recursively
this is done once per frame after update
Sourcepub fn emit_to<E>(&self, id: NodeId, event: &E, ctx: &GameContext)where
E: EventLabel,
pub fn emit_to<E>(&self, id: NodeId, event: &E, ctx: &GameContext)where
E: EventLabel,
emit an event to a single node
Sourcepub fn for_each<T>(&self, f: &mut impl FnMut(&mut T))where
T: Node,
pub fn for_each<T>(&self, f: &mut impl FnMut(&mut T))where
T: Node,
run a callback on each node of a specific type
Sourcepub fn for_each_ref<T>(&self, f: &mut impl FnMut(&T))where
T: Node,
pub fn for_each_ref<T>(&self, f: &mut impl FnMut(&T))where
T: Node,
run a callback for each node of a specific type
Sourcepub fn for_each_with_id<T>(&self, f: &mut impl FnMut(NodeId, &mut T))where
T: Node,
pub fn for_each_with_id<T>(&self, f: &mut impl FnMut(NodeId, &mut T))where
T: Node,
run a callback on each node of a specific type and get the NodeId
Sourcepub fn poll_async(&mut self, assets: &AssetLibrary)
pub fn poll_async(&mut self, assets: &AssetLibrary)
polls pending assets and adds them if ready
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 !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> 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> 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
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().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.