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

Parameters

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

using namespace Leadwerks;

int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->SetRotation(35, 0, 0);
camera->Move(0, 0, -6);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);

//Create a model
Model* model1 = Model::Box();
model1->SetPosition(-1, 0, 0);
model1->SetColor(0.0, 0.0, 1.0);

//Create a copy
Model* model2 = (Model*)model1->Instance();
model2->SetPosition(1, 0, 0);
model2->SetColor(0.0, 1.0, 0.0);

//Lets modify some vertices to show the instance is not unique
Surface* surface = model2->GetSurface(0);
surface->SetVertexPosition(0, -0.5, -2, -0.5);
surface->UpdateAABB();
model2->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB);

while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Leadwerks::Time::Update();
world->Update();
world->Render();
context->Sync();
}
}