World

World extends Object, adding functions and properties to it.
World is not creatable, there's only one instance of it. It can only be accessed through its globally exposed variable.

World is the Object at the root of the 3D scene.

Functions

Inherited from Object

Hide

nil Load ( string itemName, function callback, table config optional )

Loads the given item asynchronously and calls the callback once done. The parameter itemName follows the usual naming convention user.item.

This is a function of the global World, to be called as Object:Load(itemName, callback, config).

The config table options are as follows,
- mutable allows to create the item shapes as MutableShape instead of Shape. Default false.
- bakedLight allows to generate baked lighting for the item shapes. Default false.

nil AddChild ( Object child, boolean keepWorld optional )

Adds given Object as a child. Object extensions like Shape or MutableShape are naturally accepted too.

The keepWorld optional parameter, false by default, dictates whether to maintain the child's world or local position and rotation. Keeping world will ensure the object doesn't move in the scene, adjusting its local position/rotation accordingly; keeping local will have the object move in the scene in order to maintain an equivalent local position/rotation relative to its new parent.

local o = Object()
local myShape = Shape(Items.someuser.someitem)
o:AddChild(myShape)
nil RemoveChild ( Object child, boolean keepWorld optional )

Unsets parent/child relationship with child parameter. The child ends up being deleted if it has no other references.

The keepWorld optional parameter, false by default, dictates whether to maintain the child's world or local position and rotation. Keeping world will ensure the object doesn't move in the scene, adjusting its local position/rotation accordingly; keeping local will have the object move in the scene in order to maintain an equivalent local position/rotation relative to its new parent.

o:RemoveChild(someChildObject)
nil RemoveChildren ( boolean keepWorld optional )

Unsets parent/child relationship with all children. Individual children end up being deleted if they have no other references.

The keepWorld optional parameter, false by default, dictates whether to maintain the child's world or local position and rotation. Keeping world will ensure the object doesn't move in the scene, adjusting its local position/rotation accordingly; keeping local will have the object move in the scene in order to maintain an equivalent local position/rotation relative to its new parent.

o:RemoveChildren()
nil Recurse ( function callback, table config optional )

Iterates over all descendants of World and calls the callback function for each.

The callback function is called with the descendant as the only argument.

The config table accepts two boolean options:
- deepFirst: if true, traverses depth-first instead of root-first. Default false.
- includeRoot: if true, includes World in the recursion. Default false.

o:Recurse(function(descendant)
  print(descendant)
end, { includeRoot = true })
Object FindFirst ( function searchFunction, table config optional )

Returns the first descendant Object for which the search function returns true.
If no descendant is found, returns nil.

The search function is called with the descendant as the only argument.

The config table accepts two boolean options:
- deepFirst: if true, traverses depth-first instead of root-first. Default false.
- includeRoot: if true, includes World in the recursion. Default false.

local leaf = oakTree:FindFirst(function(o) return o.Name == "leaf" end)
if leaf then
  print("found a leaf:", leaf)
end
table Find ( function searchFunction, table config optional )

Returns all descendants Objects for which the search function returns true.
If no descendant is found, returns an empty table.

The search function is called with the descendant as the only argument.

The config table accepts two boolean options:
- deepFirst: if true, traverses depth-first instead of root-first. Default false.
- includeRoot: if true, includes World in the recursion. Default false.

local leaves = oakTree:Find(function(o) return o.Name == "leaf" end)
for i, leaf in leaves do
  print("leaf #" .. i .. ":", leaf)
end

The most efficient way to dispose of an Object for good.

Calling Destroy removes the Object and all its descendants from the World.
Metadata associated with all of these Objects also gets removed.

Once destroyed, the Objects can't be used anymore.

o:Destroy()

Get child Object at index.

if o.ChildrenCount > 0 then
  print(o:GetChild(1)) -- prints first child
end

Get World's parent.

print(myObject:GetParent())

Resets to World's original collision box. For example, Player and Shape objects will revert to fitting their model bounding box.

nil Recurse ( function callback, table config optional )

Iterates over all descendants of World and calls the callback function for each.

The callback function is called with the descendant as the only argument.

The config table options are as follows,
- includeRoot whether to include World in the iteration. Default true.
- depth the maximum depth of the iteration. Default -1 (unlimited).
- deepFirst whether to iterate in depth-first order. Default false.

If you were to remove an object from its parent while recursing through it, the object removal will be delayed until the full recursion is completed.

o:Recurse(function(descendant)
  print(descendant.Name)
end, { includeRoot = true })
nil Copy ( table config optional )

Creates a copy of the object, including all its properties and current state.

To copy a composite object, you may call o:Copy({ recurse = true }). This will copy and replicate the full object hierarchy.

Properties

Inherited from Object

Hide

nil by default. Can be set to a function that will be triggered when this object begins a collision with another object.

The function is called with 3 parameters:
- the object the callback was set for,
- the other actor in the collision,
- the world normal of the hit surface.

Note: it's not necessary to use all 3 parameters.

object.OnCollisionBegin = function(self, other, normal)
  print("collision began between", self, " and ", other, " with world normal ", normal)
end

nil by default. Can be set to a function that will be triggered when the World ends colliding with another Object.

The function is called with 2 parameters: the object the callback was set for and the other actor in the collision.

object.OnCollisionEnd = function(self, other)
  print("collision ended between", self, "and", other)
end

Can be set to true for the World to be hidden individually.

Nothing else changes, the World remains in the scene and it keeps being affected by the simulation (collisions, etc.).

Size in world units of the shadow cookie projected under the World, default is 0.0 (disabled).
The shadow cookie, also called blob shadow, is a square texture acting as a cheap alternative to projected shadows.

If this value is strictly positive, shadow cookies will be displayed when:
- the scene has no light source,
- the scene has light sources, but they are disabled because the client is using lower quality settings

Shadow cookies can be used as a fallback to your scene shadows for players with low quality settings, of course, you can also use them instead of shadows as a design choice.

Tick is a function executed ~30 times per second when set (nil by default). Provides the World and elapsed time in seconds as parameters.

-- executed ~30 times per second on each user device
myObject.Tick = function(object, dt)
  print("elapsed:", dt, "seconds")
end

Returns number of child Objects.