Chapter 4. 3D Graphics

3D Graphics is implemented through 3D Scenes. To set scene active through Lua-environment scene.activate (id) must be called. There can be several types of objects inside scene.

Here are some examples of 3D Scene objects (not complicated):

Plain Model

This is just a plain model that have model file and parameters of representation: translation, rotation, scale. Model itself is taken as implemented in OGRE. In Lua environment module "plain_model" is used to manipulate 3D modules. Every model has an ID (uint32_t value). plain_model.init (id, "name") is used to load resource "name" with ID id. Of course plain_mode.init () won't tell you at all if model exists and loaded successfully. If something goes wrong, only client can find it out. After model is created with specified ID it can be adjusted through this ID. There are 4 functions:

      plain_model.set_translation (id, v);
      plain_model.set_rotation (id, v);
      plain_model.set_scale (id, v);
      plain_model.set_position (id, v1, v2);
    

where v, v1 and v2 are tables like {x = 0.30, y = 200, z = 13}. Multiple instances of same model are taken care of. To remove specified model use plain_model.remove (id). To remove all models from active scene use plain_model.remove_all (). Models can also be hidden with plain_model.hide (id) and shown back with plain_model.show (id). All these functions are also implemented through chunk system see "idefs.h".

Plain Light

This is a source of light. Control is similar to plain_model except plain_light.init (id) function that doesn't need resource name and adjusting functions:

      plain_light.set_position (id, v1, v2);
      plain_light.set_translation (id, v);
      plain_light.set_direction (id, v);
      plain_light.set_type (id, type);
      plain_light.set_diffuse_color (id, color);
      plain_light.set_specular_color (id, color);
      plain_light.set_attenuation (id, attenuation);
      plain_light.set_spotlight_range (id, spotlight_range);
    

where type is one of: plain_light.lt_point, plain_light.lt_directional, plain_light.lt_spotlight, color is table like {r = 0.4, g = 0.0, b = 1.2}, attenuation is table like {range = 300, constant = 0, linear = 0.03, quadratic = 0.02}, spotlight_range is table like {inner_angle = 0.3, outer_angle = 1.2, falloff = 0}.