Loving Cube Engine API documentation

Introduction and table of contents - The init file - The Main object - Importing new textures - Importing 3D meshes - New data types - List of instantiable objects - List of static objects


Import 3D meshes

1) Export the mesh

In 3DsMax, export your mesh as an OBJ file (with a material .mtl file), in a subfolder somewhere in the application folder, for example a file "my_object.obj" in a new directory "data/obj_my_object/".

(img1) (img2)

Important note: each line in the material .mtl file must be aligned to the left, e.g. this is valid:

newmtl Material__42
Ns 0.0000
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000 
illum 2
Ka 0.5880 0.5880 0.5880
Kd 0.5880 0.5880 0.5880
Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000
map_Ka pole1a.png
map_Kd pole1a.png

On the contrary, this is NOT valid (TODO dev):

newmtl Material__42
	Ns 0.0000
	Ni 1.5000
	d 1.0000
	Tr 0.0000
	Tf 1.0000 1.0000 1.0000 
	illum 2
	Ka 0.5880 0.5880 0.5880
	Kd 0.5880 0.5880 0.5880
	Ks 0.0000 0.0000 0.0000
	Ke 0.0000 0.0000 0.0000
	map_Ka pole1a.png
	map_Kd pole1a.png

2) Create the lua table for a new "active object"

The "active object" are objects which will appear in the game and which behavior will be coded in lua.

In a lua file, define a new table, for example "MyObject", with the following methods:

MethodDescription
load()Called when an object of this type is created.TODO: is going in view range
init()Called when the current object is created.
manage()Called when the current object has to be managed.
draw()Called when the current object has to be drawed.
uninit()Called when the current object is destroyed.
unload()Called when the objects of this type is destroyed.TODO: is going out of view range

An "active object" does not necessarily have a 3D mesh, but in this example, we make it load and display one:

MyObject = {

	model3D = 0,
	
	--load the model into memory
	load = function()
		model3D = Model3D.new('data/obj_my_object/my_object.obj')
	end,

	--do object-related things
	manage = function()
	end,

	--draw the model

	draw = function()
		model3D:draw()
	end,
	
	--free the model from memory
	unload = function()
		model3D:drop()
	end
}

3) Make it load this new "active object" at startup

Create a new PNG file "my_object.png" (which will represent your new active object in the 3D editor), put it for example in "data/images_engine/active_objects/".

Add in the Main->init function:

ActiveObjects.get():add("MyObject", "data/images_engine/active_objects/my_object.png")
[...]
-- must be called once when all new cube types and active objects are loaded:
-- (check that this function is not already called, because no need to call it twice)
CubesAndActiveObjects.finalizeCubeTypesAndActiveObjectTypes()

4) Create an instance of the object, using the 3D editor

Start the application, add the object into the game editor, by selecting it in the selection menu (top-right button within the 3D editor).