Instance
This function creates and returns a new instance of the specified entity. Because the function will not duplicate model surfaces, it is generally fast enough for real-time use.
Syntax
- Entity Instance(recursive=true)
Parameters
- bool: recursive: if set to true, copies of the entity's children will be made and parented to the new entity.
Returns
Returns a new instance of the entity.
Remarks
This function creates a fast instance of an entity, and should be used for real-time use instead of the slower Entity::Copy() command.
Example
--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-8)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)
--Create a model
local model1 = Model:Box()
model1:SetPosition(-1,0,0)
model1:SetColor(0,0,1)
--Create a copy
local model2 = tolua.cast(model1:Instance(),"Model")
model2:SetPosition(1,0,0)
model2:SetColor(0,1,0)
--Lets modify some vertices to show the instance is not unique
local surface = model2:GetSurface(0)
surface:SetVertexPosition(0,-0.5,-2,-0.5)
surface:UpdateAABB()
model2:UpdateAABB(Entity.LocalAABB)
model2:UpdateAABB(Entity.GlobalAABB)
while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
world:Update()
world:Render()
context:Sync()
end