Struct ark_api::world::World

source ·
pub struct World { /* private fields */ }
Expand description

World implements the low-level entity API and the mesh API.

For ease of development, the wrappers (Entity, Environment etc) are recommended for entity management.

Implementations§

source§

impl World

source

pub fn instance_mut() -> impl DerefMut<Target = Self>

Get the World singleton.

source

pub fn instance() -> impl Deref<Target = Self>

Get the World singleton.

source

pub fn create_entity(name: &str, entity_template: EntityTemplate) -> Entity

Creates a world entity, from one of several templates (entity_type).

  • name: only relevant for keeping track of your object during development

  • entity_template: Chooses between one of a few “templates” (sets of precreated components):

    • EntityTemplate::Empty
    • EntityTemplate::Object
    • EntityTemplate::Environment
    • EntityTemplate::MeshStyle
    • EntityTemplate::Camera
source

pub fn add_component(entity: Entity, component_type: ComponentType)

Adds a component to an entity.

source

pub fn remove_component(entity: Entity, component_type: ComponentType)

Removes a component from an entity.

source

pub fn has_component(entity: Entity, component_type: ComponentType) -> bool

Checks whether an entity has a component.

source

pub fn destroy_entity(entity: Entity)

Destroys an entity. Attempting to access the entity after this is an error.

source

pub fn clone_entity(name: &str, entity_src: Entity) -> Entity

Clones an entity with all its components and returns the handle to the new entity.

source

pub fn clone_entities( name: &str, entity_dst: &mut [Entity], entity_src: &[Entity] )

Clones multiple entities with all their components and returns the handles to the new entities.

The name passed will be concatenated to the name of each source entity.

source

pub fn copy_component( entity_dst: Entity, entity_src: Entity, component_type: ComponentType )

Copies a component from an entity to another. Creates the component if it doesn’t exists.

source

pub fn is_valid_entity(entity: Entity) -> bool

Lets you check whether an EntityHandle points to a valid entity.

If it has existed but been destroyed, the return value is false.

source

pub fn set_entity_value( entity: Entity, component_type: ComponentType, param_id: u32, value: &Value )

Sets the value of a property of a component belonging to an entity.

This can panic if an invalid entity handle, component type, parameter id, or value was supplied. Make sure the entity and component actually exist and use the right value for it.

Use try_set_entity_value for a non panicking version of this function.

source

pub fn try_set_entity_value( entity: Entity, component_type: ComponentType, param_id: u32, value: &Value ) -> Result<(), EntityValueError>

Tries to set the value of a property of a component belonging to an entity.

Returns EntityValueError if the set operation failed.

source

pub fn get_entity_value( entity: Entity, component_type: ComponentType, param_id: u32 ) -> Value

Gets the value of a property of a component belonging to an entity.

This can panic if an invalid entity handle, component type, or parameter id was supplied. Make sure the entity and component actually exist.

Use try_set_entity_value for a non panicking version of this function.

source

pub fn try_get_entity_value( entity: Entity, component_type: ComponentType, param_id: u32 ) -> Result<Value, EntityValueError>

Tries to get the value of a property of a component belonging to an entity.

Returns EntityValueError if the get operation failed.

source

pub fn get_entity_values<T: Sized>( entities: &[Entity], value_type: EntityValueType, out_data: &mut Vec<T> ) -> Result<(), Error>

Retrieves values of the entities passed through the slice entities.

Careful attention that the out_data element size and layout matches the corresponding EntityValueType struct, should be taken.

source

pub fn set_entity_values<T: Sized>( entities: &[Entity], value_type: EntityValueType, in_data: &[T] ) -> Result<(), Error>

Sets the values of the entities passed through the slice entities. The length of the out_data slice needs to be the same as entities or a single value in which case it will be applied to all entities.

Careful attention that the in_data element size and layout matches the corresponding EntityValueType struct, should be taken.

source

pub fn set_entity_local_transforms( entities: &[Entity], input: &[EntityTransformConformal3] )

Sets the local transforms of the entities passed through the slice entities. The length of the input slice needs to be the same as entities or a single value in which case it will be applied to all entities.

source

pub fn get_entity_local_transforms( entities: &[Entity], output: &mut Vec<EntityTransformConformal3> )

Retrieves the local transforms of the entities passed through the slice entities.

source

pub fn set_entity_world_transforms( entities: &[Entity], input: &[EntityTransformConformal3] )

Sets the world transforms of the entities passed through the slice entities. The length of the input slice needs to be the same as entities or a single value in which case it will be applied to all entities.

source

pub fn get_entity_world_transforms( entities: &[Entity], output: &mut Vec<EntityTransformConformal3> )

Retrieves the world transforms of the entities passed through the slice entities.

source

pub fn get_entities_state( entities: &[Entity], output: &mut Vec<EntityStateFlags> )

Retrieves the state of the local transforms of the entities passed through the slice entities.

It is useful to call this method before World::get_entity_local_transforms to figure out which entities actually have the value.

source

pub fn get_entity_local_bounds( entities: &[Entity], output: &mut Vec<EntityBounds> )

Retrieves the local bounds of the entities passed through the slice entities.

source

pub fn get_entity_physics_velocities( entities: &[Entity], output: &mut Vec<EntityVelocity> )

Retrieves the physics velocities of the entities passed through the slice entities.

source

pub fn set_entity_render_tints( entities: &[Entity], input: &[EntityMeshStyleTint] )

Sets the mesh style tints referenced from the entities passed through the slice entities. The length of the input slice needs to be the same as entities or a single value in which case it will be applied to all the entities.

Note: Will set the tint on the mesh style that is used by this entity. This assumes each entity uses its own MeshStyle.

source

pub fn set_entity_render_enables( entities: &[Entity], input: &[EntityRenderEnable] )

Sets if rendering is enabled for the entities passed through the slice entities. The length of the input slice needs to be the same as entities or a single value in which case it will be applied to all the entities.

source

pub fn create_body_immediate(entity: Entity)

Creates a physics body in the middle of the frame

Takes parameters from the Physics component. Automatically used by the World API in enable_dynamic and similar functions.

source

pub fn get_mesh_properties(mesh_handle: DataHandle) -> MeshProperties

Lets you query some properties of a raw mesh, including its bounding volume.

source

pub fn get_mesh_morph_target_names(mesh_handle: DataHandle) -> Vec<String>

Lets you query the names of any morph targets associated with the mesh.

It is recommended to store the return value instead of calling it every frame.

source

pub fn is_valid_mesh(mesh_handle: DataHandle) -> bool

Lets you check whether a DataHandle points to a valid mesh.

If it has existed but been destroyed, the return value is false.

source

pub fn raycast(raycast: &RaycastQuery) -> Option<RaycastHit>

Casts a ray through the world, returning the first hit.

You can also use this to do spherecasts (a.k.a sphere sweeps or “thick” raycasts) by setting RaycastQuery::spherecast_radius.

source

pub fn raycast_multiple_hits(raycast: &RaycastQuery) -> Vec<RaycastHit>

Casts a ray through the world, returning multiple hits with a maximum count of RaycastQuery::max_hits.

You can also use this to do spherecasts (a.k.a sphere sweeps or “thick” raycasts) by setting RaycastQuery::spherecast_radius.

source

pub fn raycast_batched( raycasts: impl Iterator<Item = RaycastQuery> ) -> Vec<Option<RaycastHit>>

Casts multiple rays through the world, returning the first hit for each. This is faster than calling raycast multiple times.

You can also use this to do spherecasts (a.k.a sphere sweeps or “thick” raycasts) by setting RaycastQuery::spherecast_radius.

source

pub fn ray_cast( ray_origin: Vec3, ray_dir: Vec3, min_t: f32, max_t: f32, any_hit: bool, exclude_entity: Entity ) -> Option<(Entity, f32)>

👎Deprecated: Use raycast instead

Casts a ray through the world (SLOW!).

Reports the first hit or optionally any hit, which can be somewhat faster to compute, but which hit you get is not guaranteed in any way).

One entity can be excluded to avoid self-hits.

source

pub fn send_messages(entity: Entity, messages: &[Message])

Sends multiple messages to an entity. TODO (nummelin): Should probably batch this like retrieve_messages

source

pub fn retrieve_messages(entities: &[Entity]) -> (Vec<u32>, Vec<Message>)

Returns a list of message counts for each entity and all messages concatenated in the same order.

source

pub fn get_components(entity: Entity, components: &mut [ComponentType]) -> u32

Gets all components an entity has, returns the number of components.

source

pub fn get_components_vec(entity: Entity) -> Vec<ComponentType>

Gets all components an entity has

source

pub fn create_data(create_data_type: CreateDataType, data: &[u8]) -> DataHandle

Creates a new data object from a CreateDataType and slice of bytes.

source

pub fn retrieve_data( data_handle: DataHandle, retrieve_data_type: RetrieveDataType, out_data: &mut [u8] ) -> u32

Gets data from the data referenced by the handle. Always returns the number of bytes even if the output is empty (so you can allocate the right amount)

source

pub fn retrieve_data_vec( data_handle: DataHandle, retrieve_data_type: RetrieveDataType ) -> Vec<u8>

Retrieves data by this DataHandle and RetrieveDataType as a Vec of bytes.

source

pub fn destroy_data(data: DataHandle)

Decreases the ref count of a data object. When ref count reaches zero it is destroyed. Attempting to access the data after this is an error.

source

pub fn retain_data(data: DataHandle)

Increases the ref count of a data object.

source

pub fn is_valid_data(data_handle: DataHandle) -> bool

Lets you check whether a DataHandle points to a valid data object. If it has existed but been destroyed, the return value is false.

source

pub fn set_data_debug_name(data_handle: DataHandle, name: &str)

Sets a debug name of this data object. Useful for debugging memory usage and leaks.

source

pub fn get_data_debug_name(data_handle: DataHandle) -> String

Gets a debug name of this data object.

source

pub fn set_entity_debug_options( entities: &[Entity], options: EntityDebugOptions )

Sets debug options of this entity such as whether to enable physics shape debug rendering or not. An empty slice will mean to apply the options to all entities in the world.

source

pub fn update<F: FnOnce()>(f: F)

Pass your world update function to this. Will make sure messages are received, sent and transient entities are destroyed in the right order.

source

pub fn measure_formatted_text( formatted_text: &FormattedText ) -> MeasuredTextSize

Measures the layout size of a chunk of formatted text. Formatting is embedded directly into the string using a simple markup language, documented elsewhere.

source

pub fn get_collided_entity_pairs(out: &mut Vec<EntityPair>)

Get pairs of entities that have collided this frame.

source

pub fn get_collision_info(entities: &[EntityPair], out: &mut Vec<CollisionInfo>)

Get collision info for a pairs of entities that have collided this frame.

source

pub fn get_all_collision_info(out: &mut Vec<CollisionInfo>)

Get collisions that have happened this frame. This is slightly faster than get_collided_entity_pairs and get_collision_info combined.

source

pub fn get_ended_collision_entity_pairs(out_pairs: &mut Vec<EntityPair>)

Get all entity pairs that have stopped colliding this frame.

source

pub fn get_started_trigger_entity_pairs(out: &mut Vec<EntityPair>)

Get entity pairs that have started triggering this frame.

source

pub fn get_ended_trigger_entity_pairs(out: &mut Vec<EntityPair>)

Get all entity pairs that have ended triggering this frame.

Auto Trait Implementations§

§

impl RefUnwindSafe for World

§

impl Send for World

§

impl Sync for World

§

impl Unpin for World

§

impl UnwindSafe for World

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.