SceneObject

Reference

class SceneObject
module:
findByName(name)

Find an object by name and return it

Parameters:

name (str) – name of the object in the scenegraph

Return type:

Object

findById(id)

Find an object by its id and return it

Parameters:

id (str)

Return type:

Object

findByTag(tag)

Find a list of objects by their tag and return it

Parameters:

tag (str)

Return type:

Table

create(objectType, options, parent)

Create a new object in the scenegraph. This is a generic function, for specialized versions, see below.

Parameters:
  • objectType (str) – Type of object. Possible types are “Sphere”, “”.

  • options (table) – The options to use. For information about the possible options, see the specialized functions below.

  • parent (Object) – the parent object to add the new one to or nil to put it at root level

Returns:

a promise resolving to a SceneObject

Return type:

Promise

fromHandle(handle)

Create a scene object by handle number. Used internally

Parameters:

handle (number)

getId()

Return the ID of the scene object

Returns:

ID

Return type:

str

getName()

Return the name of the scene object. The name is the user given name.

Returns:

Name

Return type:

str

getDisplayName()

Return the display name of the scene object. In case the object has no user given name, a name will be generated

in the format “type <id>”

Returns:

Displayname

Return type:

str

getType()

Return the type of the object

Returns:

Type

Return type:

str

setFieldValue(name, value)

Set a field of the scene object to a new value

Parameters:
  • name (str)

  • value (str)

createField(name, fieldType, value)
Parameters:
  • name (any)

  • fieldType (any)

  • value (any)

setFieldColorValue(name, value)

Set a field of the scene object to a new color value

Parameters:
  • name (str)

  • value (Color)

setFieldNumberValue(name, value)

Set a field of the scene object to a new number value

Parameters:
  • name (str)

  • value (number)

setFieldEnumValue(name, value)

Set a field of the scene object to a new enum value

Parameters:
  • name (str)

  • value (number)

setFieldBooleanValue(name, value)

Set a field of the scene object to a new boolean value

Parameters:
  • name (str)

  • value (boolean)

getFieldValue(name)

Get a scene object field’s value

Parameters:

name (str) – name of the field

getFieldColorValue()

Get the value of a scene object’s field as color value

Returns:

value of the field

Return type:

Color

getFieldNumberValue()

Get the value of a scene object’s field as number value

Returns:

value of the field

Return type:

number

getFieldEnumValue()

Get the value of a scene object’s field as string value

Returns:

value of the field

Return type:

str

getFieldEnumOptions()

Get the value of a scene object’s field as string value

Returns:

value of the field

Return type:

str

getFieldBooleanValue()

Get the value of a scene object’s field as boolean value

Returns:

value of the field

Return type:

boolean

getLinkItem(name)

Get a link of the scene object to a new value

Parameters:

name (str) – name of the link field

Returns:

handle of the linked item or nil if not set

Return type:

number

setLinkItem(name, item)

Set a link from the scene object

Parameters:
  • name (str) – name of the link field

  • item (str) – value can be either an item ID or an Item object

translate(x, y, z)

Translate the scene object

Parameters:
  • x (number)

  • y (number)

  • z (number)

rotate(x, y, z)

Rotate the scene object

Parameters:
  • x (number)

  • y (number)

  • z (number)

scale(x, y, z)

Scale the scene object

Parameters:
  • x (number)

  • y (number)

  • z (number)

setField(name, value)

Set a field of the scene bject to a new value

Parameters:
  • name (str)

  • value (str)

getTransform()

Get local transform of a scene object

getWorldTransform()

Get world transform of a scene object

setTransform(transform)

Set local transform of a scene object

Parameters:

transform (Transform) – transform object

getLinearVelocity()

Return the linear velocity of the object. This only works for objects added to the physics engine and

with watchLinearVelocity set to true, otherwise it will return a zero vector

Returns:

the linear velocity

Return type:

Vector3

setLinearVelocity(velocity)

Set the linear velocity of the object. This only works for objects added to the physics engine.

Parameters:

velocity (Vector3) – the new linear velocity

getAngularVelocity()

Return the angular velocity of the object. This only works for objects added to the physics engine and

with watchAngularVelocity set to true, otherwise it will return a zero vector

Returns:

the angular velocity

Return type:

Vector3

setAngularVelocity(velocity)

Set the angular velocity of the object. This only works for objects added to the physics engine

Parameters:

velocity (Vector3) – the new angular velocity

applyImpulse(impulse, relPos)
Parameters:
  • impulse (any)

  • relPos (any)

applyForce(force, relPos)
Parameters:
  • force (any)

  • relPos (any)

applyTorque(torque)
Parameters:

torque (any)

setLinearFactor(factor)
Parameters:

factor (any)

setAngularFactor(factor)
Parameters:

factor (any)

clone(x, y, z, parent)

Clone a scene object to a new position and return it

Parameters:
  • x (number) – optional position transform parameter. Defaults to the cloned position x

  • y (number) – optional position transform parameter. Defaults to the cloned position y

  • z (number) – optional position transform parameter. Defaults to the cloned position z

  • parent (Object) – the parent object to add the new one to or nil to clone it where it currently is

Returns:

a promise resolving to a SceneObject

Return type:

Promise

delete()

Delete scene object

setActive(value)
Parameters:

value (any)

getActive()
getTags()
hasTag(tagName)
Parameters:

tagName (any)

takeSnapshot(recursive)

Take a snapshot of this object and its children if specified. Taking a snapshot will allow to reset it’s complete

state back to this moment at a later point. This will rollback any changes on the objects. This includes recreating deleted child objects or deleting newly created ones.

Parameters:

recursive (boolean)

Returns:

snapshot handle

Return type:

number

rollbackSnapshot(snapshot)

Rollback a snapshot. Any changes made to this object will be rolled back. This includes recreating deleted child objects

or deleting newly created ones.

Parameters:

snapshot (any)

isEnabled()

Check if the object is enabled. Disabled objects are not drawn and their scripts are not executed

enable()

Enable the object

disable()

Disable the object

getMaterial()

Get material

Return type:

Material

getEntities()

Get the list of Entity objects attached to the scene object. One for each script

Returns:

an array of Entity objects, one for each script attached to the scene object

Return type:

table

getEntityByScriptName(name)

Get a reference to an Entity object attached to the scene object based on the script’s name. If multiple scripts of the same name

are attached to the scene object, the first one is returned

Parameters:

name (str) – name of the script item

Returns:

the entity object if found, otherwise nil

Return type:

Entity

getParent()
getChildren()

Find the children of the object and return it as a table

Return type:

Table

Examples