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: WorldDense ECS storage. Direct hierarchy edits are checked by Self::propagate.
Implementations§
Source§impl Scene
impl Scene
Sourcepub fn spawn_2d(
&mut self,
transform: Transform2D,
components: impl Bundle,
) -> Entity
pub fn spawn_2d( &mut self, transform: Transform2D, components: impl Bundle, ) -> Entity
Spawns custom components and the local/global 2D transform pair.
Sourcepub fn spawn_3d(
&mut self,
transform: Transform3D,
components: impl Bundle,
) -> Entity
pub fn spawn_3d( &mut self, transform: Transform3D, components: impl Bundle, ) -> Entity
Spawns custom components and the local/global 3D transform pair.
Sourcepub fn set_parent(
&mut self,
child: Entity,
parent: Option<Entity>,
) -> Result<(), HierarchyError>
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.
Sourcepub fn despawn(&mut self, entity: Entity) -> Result<(), NoSuchEntity>
pub fn despawn(&mut self, entity: Entity) -> Result<(), NoSuchEntity>
Despawns an entity and detaches its direct children, keeping local transforms.
Sourcepub fn propagate(&mut self) -> Result<(), HierarchyError>
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.