All Functions Modules Pages
model 3D

Functions

MODEL3D model3d.load (STRING path)
 Loads a 3D model (OBJ and MTL formats are supported). More...
 
MODEL3D model3d.load (STRING path, NUMBER css)
 Loads a 3D model (OBJ and MTL formats are supported). More...
 
NUMBER model3d.countobj (MODEL3D model)
 Calculates the number of objects inside a 3D model. More...
 
NIL model3d.shading (MODEL3D model, NUMBER cs)
 Enables/Disables Cel-Shading on a 3D model. More...
 
NIL model3d.shading (MODEL3D model, NUMBER cs, COLOR linecolor)
 Enables/Disables Cel-Shading on a 3D model. More...
 
NIL model3d.lighting (MODEL3D model, NUMBER object, NUMBER lt)
 Sets if a object inside a 3D model will be affected by the lights. More...
 
NIL model3d.render (MODEL3D model, NUMBER draw_type)
 Renders a 3D model. More...
 
NIL model3d.render (MODEL3D model, NUMBER draw_type, NUMBER object)
 Renders a 3D model or parts of it (if the model contains several sub-objetcs), with three render modes. More...
 
NIL model3d.rotation (MODEL3D model, NUMBER object, TABLE rot)
 Rotates an object inside the 3D model. More...
 
TABLE model3d.getrotation (MODEL3D model, NUMBER object)
 Gets the current rotation values of an object inside the 3D model. More...
 
NIL model3d.position (MODEL3D model, NUMBER object, TABLE pos)
 Changes the position of an object inside the 3D model. More...
 
TABLE model3d.getposition (MODEL3D model, NUMBER object)
 Gets the current position values of an object inside the 3D model. More...
 
NIL model3d.scaling (MODEL3D model, NUMBER object, TABLE scal)
 Scales an object inside the 3D model. More...
 
TABLE model3d.getscaling (MODEL3D model, NUMBER object)
 Gets the current scaling values of an object inside the 3D model. More...
 
NIL model3d.startreflection (MODEL3D model, NUMBER object)
 Initializes the shadow and reflections engine, setting an object inside the 3D model as a floor. More...
 
NIL model3d.mirror (MODEL3D model, NUMBER object, NUMBER eje)
 Renders the reflection of a 3D model on the floor. More...
 
NIL model3d.shadow (MODEL3D model, NUMBER object, NUMBER light)
 Renders the shadow. More...
 
NIL model3d.blitshadow (MODEL3D model, NUMBER object, NUMBER light, NUMBER alpha, NUMBER type)
 Starts drawing volumetric shadows, Draw the model that receives the shadows. More...
 
NIL model3d.finishreflection ()
 Finishes the shadow and reflections engine. More...
 
NIL model3d.initphysics (NUMBER max_objects)
 Inicializes the physics engine. More...
 
NIL model3d.initphysics (TABLE world_size1, TABLE world_size2, NUMBER max_objects)
 Inicializes the physics engine. More...
 
NIL model3d.modelphysics (MODEL3D Model)
 Links a 3D model to simulate it. More...
 
NIL model3d.deletephysics (MODEL3D Model)
 Unlinks a 3D model. More...
 
NIL model3d.updatephysics ()
 Updates the 3D physics. More...
 
NIL model3d.setphysics (MODEL3D Model, NUMBER Object, TABLE Origin, TABLE Position, NUMBER Mass, NUMBER ShapeType)
 Sets the physics components af a 3D model. More...
 
NIL model3d.finishphysics ()
 Finishes the 3D physics engine. More...
 
NIL model3d.setvelocity (MODEL3D Model, NUMBER object, TABLE vel)
 Sets the 3D object linear speed. More...
 
TABLE model3d.getvelocity (MODEL3D Model, NUMBER object)
 Gets the linear speed of an object inside the 3D model. More...
 
BOOLEAN model3d.collision (MODEL3D Model1, NUMBER object1, MODEL3D Model2, NUMBER object2)
 Checks if 2 objects of 2 3D models are colliding. More...
 
NIL model3d.setdamping (MODEL3D Model, NUMBER object, NUMBER lineal, NUMBER angular)
 Sets the damping coefficient of an object inside a 3D model. More...
 
NUMBER model3d.getdamping (MODEL3D Model, NUMBER object)
 Gets the damping coefficient of an object inside a 3D model. More...
 
MODEL3D model3d.newmap (STRING path)
 Makes a heights map using a grayscale image. More...
 

Detailed Description

3D model management.

Function Documentation

MODEL3D model3d.load ( STRING  path)

Loads a 3D model (OBJ and MTL formats are supported).

Parameters
pathPath to the .OBJ file (supports directories).
Returns
A model3d object, ready to use.
MODEL3D model3d.load ( STRING  path,
NUMBER  css 
)

Loads a 3D model (OBJ and MTL formats are supported).

Parameters
pathPath to the .OBJ file (supports directories).
cssSize of the Cel-Shading.
Returns
A model3d object, ready to use.
NUMBER model3d.countobj ( MODEL3D  model)

Calculates the number of objects inside a 3D model.

Parameters
modelA 3D model.
Returns
The number of objects inside a 3D model.
NIL model3d.shading ( MODEL3D  model,
NUMBER  cs 
)

Enables/Disables Cel-Shading on a 3D model.

Parameters
modelA 3D model.
csPass 1 to enable, 0 to disable.
Note
You should enable the lights before use this function.
Returns
Nothing.
NIL model3d.shading ( MODEL3D  model,
NUMBER  cs,
COLOR  linecolor 
)

Enables/Disables Cel-Shading on a 3D model.

Parameters
modelA 3D model.
csPass 1 to enable, 0 to disable.
linecolorColor for the Cel-Shading.
Note
You should enable the lights before use this function.
Returns
Nothing.
NIL model3d.lighting ( MODEL3D  model,
NUMBER  object,
NUMBER  lt 
)

Sets if a object inside a 3D model will be affected by the lights.

Parameters
modelA 3D model.
objectThe object inside the 3D model to edit.
ltPass 1 to enable and 0 to disable the object lightning.
Returns
Nothing.
NIL model3d.render ( MODEL3D  model,
NUMBER  draw_type 
)

Renders a 3D model.

Parameters
modelA 3D model.
draw_typeRender mode, one of the following values:
  • 0 (FRONT) Only render front faces, the fastest.
  • 1 (TRANS) Render the back faces first and then render the front faces on top, for transparent objects, it can be slower.
  • 2 (ALL) Render all faces at once.
Note
If an object is translucent or it has textures which use the alpha channel, only the objects rendered before it will be shown. The rendering order would be from far to near.
Returns
Nothing.
NIL model3d.render ( MODEL3D  model,
NUMBER  draw_type,
NUMBER  object 
)

Renders a 3D model or parts of it (if the model contains several sub-objetcs), with three render modes.

Parameters
modelThe 3D model.
draw_typeRender mode, one of the following values:
  • 0 (FRONT) Only render front faces, the fastest.
  • 1 (TRANS) Render the back faces first and then render the front faces on top, for transparent objects, it can be slower.
  • 2 (ALL) Render all faces at once.
objectSelects a sub-object from the model.
  • If the value is positive, only the selected sub-object will be drawn.
  • If the value is negative, the selected sub-object will not be drawn.
Returns
Nothing.
NIL model3d.rotation ( MODEL3D  model,
NUMBER  object,
TABLE  rot 
)

Rotates an object inside the 3D model.

Parameters
modelA 3D model.
objectThe object inside the 3D model to edit.
rotA table with the object rotation values for the 3 axes (x,y,z).
Returns
Nothing.
TABLE model3d.getrotation ( MODEL3D  model,
NUMBER  object 
)

Gets the current rotation values of an object inside the 3D model.

Parameters
modelA 3D model.
objectThe object inside the 3D model.
Returns
A table with the object rotation values for the 3 axes (x,y,z).
NIL model3d.position ( MODEL3D  model,
NUMBER  object,
TABLE  pos 
)

Changes the position of an object inside the 3D model.

Parameters
modelA 3D model.
objectThe object inside the 3D model to edit.
posA table with the object position values for the 3 axes (x,y,z).
Returns
Nothing.
TABLE model3d.getposition ( MODEL3D  model,
NUMBER  object 
)

Gets the current position values of an object inside the 3D model.

Parameters
modelA 3D model.
objectThe object inside the 3D model.
Returns
A table with the object rotation values for the 3 axes (x,y,z).
NIL model3d.scaling ( MODEL3D  model,
NUMBER  object,
TABLE  scal 
)

Scales an object inside the 3D model.

Parameters
modelA 3D model.
objectThe object inside the 3D model to edit.
scalA table with the object scaling values for the 3 axes (x,y,z).
Returns
Nothing.
TABLE model3d.getscaling ( MODEL3D  model,
NUMBER  object 
)

Gets the current scaling values of an object inside the 3D model.

Parameters
modelA 3D model.
objectThe object inside the 3D model.
Returns
A table with the object scaling values for the 3 axes (x,y,z).
NIL model3d.startreflection ( MODEL3D  model,
NUMBER  object 
)

Initializes the shadow and reflections engine, setting an object inside the 3D model as a floor.

Parameters
modelA 3D model.
objectThe object to use as floor.
Returns
Nothing.
NIL model3d.mirror ( MODEL3D  model,
NUMBER  object,
NUMBER  eje 
)

Renders the reflection of a 3D model on the floor.

Parameters
modelA 3D model.
objectThe "reflection" object.
ejeAxis to render the reflection (X, Y or Z).
  • 0 Axis X.
  • 1 Axis Y.
  • 2 Axis Z.
Returns
Nothing.
NIL model3d.shadow ( MODEL3D  model,
NUMBER  object,
NUMBER  light 
)

Renders the shadow.

Parameters
modelA 3D model.
objectThe "shadow" object.
lightThe light that casts the shadow (any value between 1 to 4).
Returns
Nothing.
NIL model3d.blitshadow ( MODEL3D  model,
NUMBER  object,
NUMBER  light,
NUMBER  alpha,
NUMBER  type 
)

Starts drawing volumetric shadows, Draw the model that receives the shadows.

Parameters
modelThe model that casts the shadow.
objectSelect an object inside the model.
lightLight used to cast the shadow.
alphaShadow transparency.
typeShadow parameter, static or dynamic: 1 to rotate the shadow and 0 static.
Note
This function will cast shadow only over objects drawn before itself
Returns
Nothing.
NIL model3d.finishreflection ( )

Finishes the shadow and reflections engine.

Returns
Nothing.
NIL model3d.initphysics ( NUMBER  max_objects)

Inicializes the physics engine.

Parameters
max_objectsThe maximum number of 3D objects.
Note
The world size is considered infinite by this call.
Returns
Nothing.
NIL model3d.initphysics ( TABLE  world_size1,
TABLE  world_size2,
NUMBER  max_objects 
)

Inicializes the physics engine.

Parameters
world_size13D world size (minimum coordinates).
world_size23D world size (maximum coordinates).
max_objectsThe maximum number of 3D objects.
Returns
Nothing.
NIL model3d.modelphysics ( MODEL3D  Model)

Links a 3D model to simulate it.

Parameters
ModelA 3D model.
Returns
Nothing.
NIL model3d.deletephysics ( MODEL3D  Model)

Unlinks a 3D model.

Parameters
ModelA 3D model.
Returns
Nothing.
NIL model3d.updatephysics ( )

Updates the 3D physics.

Returns
Nothing.
NIL model3d.setphysics ( MODEL3D  Model,
NUMBER  Object,
TABLE  Origin,
TABLE  Position,
NUMBER  Mass,
NUMBER  ShapeType 
)

Sets the physics components af a 3D model.

Parameters
ModelA 3D model.
ObjectThe object inside the 3D model to edit.
OriginA table with the coordinates of the 3D model origin (normally its center).
PositionA table with the coordinates of the 3D model initial position.
MassThe object mass (pass 0 to use it as floor).
ShapeTypeThe object shape, one of these constants:
  • __BOX
  • __SPHERE
  • __CONE
  • __CYLINDER
  • __CONVEX (This works for any shape).
Returns
Nothing.
NIL model3d.finishphysics ( )

Finishes the 3D physics engine.

Returns
Nothing.
NIL model3d.setvelocity ( MODEL3D  Model,
NUMBER  object,
TABLE  vel 
)

Sets the 3D object linear speed.

Parameters
ModelA 3D model.
objectThe object inside the 3D model to edit.
velA table with the speed values for the 3 axes (x,y,z).
Returns
Nothing.
TABLE model3d.getvelocity ( MODEL3D  Model,
NUMBER  object 
)

Gets the linear speed of an object inside the 3D model.

Parameters
ModelA 3D model.
objectThe object inside the 3D model.
Returns
A table with the speed values for the 3 axes (x,y,z).
BOOLEAN model3d.collision ( MODEL3D  Model1,
NUMBER  object1,
MODEL3D  Model2,
NUMBER  object2 
)

Checks if 2 objects of 2 3D models are colliding.

Parameters
Model1The first model.
object1The first object.
Model2The second model.
object2the second object.
Returns
true if the objects are colliding, false otherwise.
NIL model3d.setdamping ( MODEL3D  Model,
NUMBER  object,
NUMBER  lineal,
NUMBER  angular 
)

Sets the damping coefficient of an object inside a 3D model.

Parameters
ModelA 3D model.
objectThe object inside the 3D model to edit.
linealThe damping coefficient for linear movements (a higher value produces less rebound).
angularThe damping coefficient for rotational movements (a higher value produces less rotation).
Returns
Nothing.
NUMBER model3d.getdamping ( MODEL3D  Model,
NUMBER  object 
)

Gets the damping coefficient of an object inside a 3D model.

Parameters
ModelA 3D model.
objectThe object inside the 3D model.
Returns
Two numbers:
  • lineal The damping coefficient for linear movements.
  • angular The damping coefficient for rotational movements.
MODEL3D model3d.newmap ( STRING  path)

Makes a heights map using a grayscale image.

Parameters
pathPath to the image (recommended 64x64pix or less).
Returns
A model3D object with the heights map.