The Object3d class
An 'Object3d' instance is an object in a scene which can be
manipulated via its position, rotation or scale. The 'Object3d' class
is mostly used as the base class for other permutations like
'OEntity' or 'OLight' which extend the usability for their specific use-case.
Finds the object with the given name in the current scene
and constructs a new Object3d instance for it.
Example:
function onSceneUpdate()
-- Get the object with name "Entity0"
object = Object3d.getObject("Entity0")
end
function Object3d.getObject(name)
Static methods to fetch the object with the given name.
Parameter
name
return
function Object3d:getPosition()
Returns the position of the object.
Return: s A vec3 containing the position.
function Object3d:getRotation()
Returns the rotation of the object.
Return: s A vec3 containing the rotation.
function Object3d:getScale()
Returns the scale of the object.
Return: s A vec3 containing the scale.
function Object3d:setPosition(pos)
Sets the position of the object
Parameter
pos
function Object3d:setRotation(rot)
Sets the rotation of the object
Parameter
pos
function Object3d:setScale(scale)
Sets the scale of the object
Parameter
pos
function Object3d:translate(vec, mode)
Translates the object by the given vec3
The mode parameter is optional and should contain "local" when a local translation
should be executed. If this parameter is not given the translation will be done in
world space.
Example:
function onSceneUpdate()
-- Translate 50 units towards the global Z-Axis
object:translate({0,0,50})
-- Translate 50 units towards the local Y-Axis
object:translate({0,50,0}, "local")
end
Parameter
vec
mode
function Object3d:rotate(axis, amount, mode)
Rotates the object by the given amount around the given axis.
The mode parameter is optional and should contain "local" when a local rotation
should be executed. If this parameter is not given the rotation will be done in
world space.
Example:
function onSceneUpdate()
-- Rotate 10° globally around the Z-Axis
object:rotate({0,0,1}, 10)
-- Rotate 10° locally around the X-Axis
object:rotate({1,0,0}, 10, "local")
end
Parameter
axis
amount
mode
function Object3d:getParent()
Returns the parent of the object or 'nil' if there isn't any.
Return: The parent object as Object3d.
function Object3d:setParent(object)
Sets the parent of the object.
You can remove the parent by setting the parent to 'nil'
Example:
function onSceneUpdate()
local newParent = Object3d.getObject("Parent")
-- Set the new parent
object:setParent(newParent)
-- Remove parent
object:setParent(nil)
end
Parameter
object
function Object3d:getName()
Returns the name of the object.
Return: The name as a string
function Object3d:activate()
Activates an inactive Object3d
function Object3d:deactivate()
Deactivates an inactive Object3d.
This function does _not_ delete the object from the scene!
The object will be invisible and physically inactive but 'not deleted'!
function Object3d:setActive(status)
Sets the activity status.
Calls either Object3d:activate or Object3d:deactivate to set the status.
Example:
function onSceneUpdate()
-- Activate the object
object:setActive(true)
-- Deactivate the object
object:setActive(false)
end
Parameter
status
function Object3d:isActive()
Returns the current activation status of the object.
Return: A boolean.
function Object3d:getClone()
Creates a clone of the object and returns it as an Object3d.
This will only clone the object and not the children.
Children need to be cloned manually!
Return: : The clone as Object3d
function Object3d:getChildren()
Returns a table with all of the objects children.
The children are of the type Object3d.
Return: A list of Object3d