Skip to main content

Scene

Struct Scene 

Source
pub struct Scene {
    pub world: World,
    /* private fields */
}
Expand description

Scene container. Game-defined components remain ordinary Rust structs.

Scratch storage is reused between propagations. Parenting is optional and global transforms are updated explicitly once after local transforms change.

use rayengine_core::prelude::*;
struct Health(u32);
let mut scene = Scene::new();
let root = scene.spawn_2d(Transform2D::at(Vec2::new(10.0, 0.0)), ());
let child = scene.spawn_2d(Transform2D::at(Vec2::new(5.0, 0.0)), (Health(100),));
scene.set_parent(child, Some(root)).unwrap();
scene.propagate().unwrap();
let global = scene.world.get::<&GlobalTransform2D>(child).unwrap();
assert_eq!(global.0.transform_point2(Vec2::ZERO), Vec2::new(15.0, 0.0));

Fields§

§world: World

Dense ECS storage. Direct hierarchy edits are checked by Self::propagate.

Implementations§

Source§

impl Scene

Source

pub fn new() -> Self

Creates an empty scene.

Source

pub fn spawn_2d( &mut self, transform: Transform2D, components: impl Bundle, ) -> Entity

Spawns custom components and the local/global 2D transform pair.

Source

pub fn spawn_3d( &mut self, transform: Transform3D, components: impl Bundle, ) -> Entity

Spawns custom components and the local/global 3D transform pair.

Source

pub fn set_parent( &mut self, child: Entity, parent: Option<Entity>, ) -> Result<(), HierarchyError>

Changes a parent after checking entity lifetime, dimension and cycles. A failed edit leaves the previous parent unchanged.

Source

pub fn despawn(&mut self, entity: Entity) -> Result<(), NoSuchEntity>

Despawns an entity and detaches its direct children, keeping local transforms.

Source

pub fn propagate(&mut self) -> Result<(), HierarchyError>

Computes global transforms in O(entities + parent links), without recursion. Entities spawned directly into world need their own global component. Invalid parent chains return an error before any globals are changed.

Trait Implementations§

Source§

impl Default for Scene

Source§

fn default() -> Self

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

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> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.