Entity
API for creating and manipulating entities as well as components.
Constants
Entity.Components.Name
The name component.
Entity.Components.Name: component
Entity.Components.Position
The position component.
Entity.Components.Position: component
Entity.Components.Rotation
The rotation component.
Entity.Components.Rotation: component
Entity.Components.Scale
The scale component.
Entity.Components.Scale: component
Functions
Entity.create
Creates a new entity.
Entity.create(): entity
Returns
Name | Type | Description |
---|---|---|
entity | entity | The newly created entity. |
Entity.fromAsset3d
Creates a new entity from an Asset3d.
Entity.fromAsset3d(assetPath: string, position: vector, rotation: Quaternion): entity
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
assetPath | string | Required | The path of the Asset3d to create the entity from. |
position | vector | Required | The position of the entity. |
rotation | Quaternion | Required | The rotation of the entity. |
Returns
Name | Type | Description |
---|---|---|
entity | entity | The newly created entity. |
Entity.destroy
Destroys an entity.
Entity.destroy(entity: entity)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to destroy. |
Entity.createComponent
Creates a new component.
Performance for Component Types
Primitive component types are the fastest to create and access. Primitive component types include:
boolean
integer
unsigned
number
string
vector
quaternion
Reference component types are slower to create and access. Reference component types include:
table
buffer
function
userdata
thread
Entity.createComponent(type: 'boolean' | 'integer' | 'unsigned' | 'number' | 'string' | 'vector' | 'quaternion' | 'table' | 'buffer' | 'function' | 'userdata' | 'thread'): component
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
type | 'boolean' | 'integer' | 'unsigned' | 'number' | 'string' | 'vector' | 'quaternion' | 'table' | 'buffer' | 'function' | 'userdata' | 'thread' | Required | The type of component to create. |
Returns
Name | Type | Description |
---|---|---|
component | component | The newly created component. |
Entity.isValid
Checks if an entity is valid.
Entity.isValid(entity: entity): boolean
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to check. |
Returns
Name | Type | Description |
---|---|---|
valid | boolean | Whether the entity is valid. |
Entity.getId
Gets the ID of an entity.
Entity.getId(entity: entity): number
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the ID of. |
Returns
Name | Type | Description |
---|---|---|
id | number | The ID of the entity. |
Entity.findByComponents
Finds entities which contain the given components.
Entity.findByComponents(components: component[]): entity[]
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
components | component[] | Required | The components to search for. |
Returns
Name | Type | Description |
---|---|---|
entities | entity[] | The entities which contain the given components. |
Entity.getComponent
Gets a component from an entity.
Entity.getComponent(entity: entity, component: component): any
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the component from. |
component | component | Required | The component to get. |
Returns
Name | Type | Description |
---|---|---|
data | any | The component data from the entity. |
Entity.setComponent
Sets component data on an entity.
Entity.setComponent(entity: entity, component: component, data: any)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to set the component on. |
component | component | Required | The component to set. |
data | any | Required | The data to set. |
Entity.removeComponent
Removes a component from an entity.
Entity.removeComponent(entity: entity, component: component)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to remove the component from. |
component | component | Required | The component to remove. |
Entity.hasComponent
Checks if an entity has a component.
Entity.hasComponent(entity: entity, component: component): boolean
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to check. |
component | component | Required | The component to check for. |
Returns
Name | Type | Description |
---|---|---|
hasComponent | boolean | Whether the entity has the component. |
Entity.getParent
Gets the parent of an entity.
Entity.getParent(entity: entity): entity?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the parent of. |
Returns
Name | Type | Description |
---|---|---|
parent | entity? | The parent of the entity. |
Entity.getChildren
Gets the children of an entity.
Entity.getChildren(entity: entity): entity[]
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the children of. |
Returns
Name | Type | Description |
---|---|---|
children | entity[] | The children of the entity. |
Entity.getGlobalPosition
Gets the global position of an entity.
Entity.getGlobalPosition(entity: entity): vector?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the global position of. |
Returns
Name | Type | Description |
---|---|---|
position | vector? | The global position of the entity. |
Entity.getGlobalRotation
Gets the global rotation of an entity.
Entity.getGlobalRotation(entity: entity): Quaternion?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the global rotation of. |
Returns
Name | Type | Description |
---|---|---|
rotation | Quaternion? | The global rotation of the entity. |
Entity.getGlobalScale
Gets the global scale of an entity.
Entity.getGlobalScale(entity: entity): vector?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the global scale of. |
Returns
Name | Type | Description |
---|---|---|
scale | vector? | The global scale of the entity. |
Entity.getName
Gets the name of an entity.
Entity.getName(entity: entity): string?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the name of. |
Returns
Name | Type | Description |
---|---|---|
name | string? | The name of the entity. |
Entity.setName
Sets the name of an entity.
Entity.setName(entity: entity, name: string)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to set the name of. |
name | string | Required | The name to set. |
Entity.getLocalPosition
Gets the local position of an entity.
Entity.getLocalPosition(entity: entity): vector?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the local position of. |
Returns
Name | Type | Description |
---|---|---|
position | vector? | The local position of the entity. |
Entity.getLocalRotation
Gets the local rotation of an entity.
Entity.getLocalRotation(entity: entity): Quaternion?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the local rotation of. |
Returns
Name | Type | Description |
---|---|---|
rotation | Quaternion? | The local rotation of the entity. |
Entity.getLocalScale
Gets the local scale of an entity.
Entity.getLocalScale(entity: entity): vector?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to get the local scale of. |
Returns
Name | Type | Description |
---|---|---|
scale | vector? | The local scale of the entity. |
Entity.setLocalPosition
Sets the local position of an entity.
Entity.setLocalPosition(entity: entity, position: vector)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to set the local position of. |
position | vector | Required | The local position to set. |
Entity.setLocalRotation
Sets the local rotation of an entity.
Entity.setLocalRotation(entity: entity, rotation: Quaternion)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to set the local rotation of. |
rotation | Quaternion | Required | The local rotation to set. |
Entity.setLocalScale
Sets the local scale of an entity.
Entity.setLocalScale(entity: entity, scale: vector)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
entity | entity | Required | The entity to set the local scale of. |
scale | vector | Required | The local scale to set. |