Skip to content

Classes and Methods

jun-mizutani edited this page Oct 12, 2014 · 18 revisions

Classes and Methods

LjES Class Hierarchy and module dependency

Object

A global variable "Object" is basic to LjES object model. Every class in LjES inherit "Object" object. The "Object" object has a method new().

-- Object.lua
Object = {}

function Object.new(self)
  local obj = {}
  setmetatable(obj, obj)
  obj.__index = self
  return obj
end

new()

The method Object:new() can be used as the constructor.

The code below shows the usage of Object. NewClass inherits the method new() from Object.

package.path = "../LjES/?.lua;" .. package.path

require("Object")

NewClass = Object:new()

function NewClass.new(self, name)
  local obj = Object.new(self)
  obj.name = name
  return obj
end

function NewClass.print(self)
  print(self.name)
end

-- test

local instance1 = NewClass:new("One")
local instance2 = NewClass:new("Two")

instance1:print()
instance2:print()
$ luajit class.lua
One
Two

Screen

fbinfo()

Retrieves the framebufer information. It is used from Screen.init method.

new()

Returns an instance of the Screen object.

require("Screen")

aScreen = Screen:new()

checkOverscan()

Checks the screen overscan. If overscan is enabled, aSpace.overscan would be true.

checkSize(width, height, offset_x, offset_y)

This method is used from bcm_init internally. Returns width, height, offset_x, offset_y of the screen.

bcm_init(width, height, offset_x, offset_y)

Initializes the area of ​​the screen that displays the graphics. If width or height equal zero, the width or the height will set the physical screen size. When width or height has negative value, the absolute value means the size of the margin. "(offset_x, offset_y)" specifies the position of top-left corner of the graphics screen. When offset_x has negative value, the screen will be centered horizontally. When offset_y has negative value, the screen will be centered vertically.

deinit()

restoreSize()

move(w, h, x, y)

egl_init()

Initializes EGL interface. It is used from Screen.init method.

setClearColor(r, g, b, alpha)

Specifies the background color with 4 floating point values, ranging from 0.0 to 1.0, each for red, green, blue, and alpha.

cullFace()

Specifies back-face culling. It is used from Screen.init method.

init(w, h, x, y)

Initializes screen. "aScreen.init(0, 0, 0, 0)" should be enough for most cases.

function Screen.init(self, w, h, x, y)
  self:fbinfo()
  self:bcm_init(w, h, x, y)
  self:egl_init()
  self:cullFace()
end

getFrameCount()

Retrieves the count of drawing.

resetFrameCount()

Resets the count of drawing.

getAspect()

Returns an aspect ratio (width / height).

getWidth()

Returns width.

getHeight()

Returns height.

viewport()

clear()

Fills screen with background color.

clearDepthBuffer()

Clears depth buffer.

update()

Updates screen.

swapInterval(interval)

Change maximum framerate. If interval is 0, the framerate can exceed 60 frame/sec. If interval is a range from 1 to 10, the maximum framerate will be 60 / interval.

screenShot(filename)

Takes a screenshot and saves it in the png format.

Space

The Space class contains instances of Node class which holds position and orientation of 3D objects.

new()

Returns an instance of the Space object.

require("Space")

aSpace = Space:new()

addNode(parent_node, name)

Creates and returns an instance of the Node object.

aNode = aSpace:addNode(nil, "Cube")

delNode(name)

Removes the node of the specified name from a Space object.

scanSkeletons()

findNode(name)

Returns the node of the specified name.

listNode()

now()

Returns the current time in seconds (with accuracy of microseconds).

timerStart()

uptime()

Returns the time in seconds since the start of the timer (with accuracy of microseconds).

deltaTime()

count()

setLight(node)

setLightType(light_type)

getLightType()

setEye(node)

draw(eye_node)

Displays the Space visible from the position of eye_node.

drawBones()

Displays bones.

Shape

Shape class contains information of vertices, normals, faces, texture coordinates, skeleton and shader properties.

new()

Returns an instance of the Shape object.

require("Shape")

aShape = Shape:new()

ClassShader(shader)

ClassTexture(texture)

updateBoundingBox(x, y, z)

getBoundingBox()

printBoundingBox()

setAutoCalcNormals(flag)

referShape(shape)

copyShaderParamsFromShape(shape)

setAnimation(anim)

getAnimation()

getVertexCount()

Returns number of vertices.

getTriangleCount()

Returns number of triangles.

shaderParameter(key, value)

setShader(shader)

setTexture(texture)

setTextureMappingMode(mode)

setTextureMappingAxis(axis)

setTextureScale(scale_u, scale_v)

endShape()

releaseObjects()

setSkeleton(skeleton)

getSkeleton()

hide(true_or_false)

draw(modelview, normal)

setVertex(x, y, z)

addVertex(x, y, z)

addVertexUV(x, y, z, u, v)

addVertexPosUV(pos, uv)

setVertNormal(vn, x, y, z)

getVertNormal(vn)

getVertPosition(vn)

addVertexWeight(vn, ind, wt)

checkAltVertex(p)

addTriangle(p0, p1, p2)

addPlane(indices)

calcUV(x, y, z)

revolution(latitude, longitude, verts, spherical)

sphere(radius, latitude, longitude)

donut(radius, radiusTube, latitude, longitude)

cone(height, radius, n)

truncated_cone(height, radiusTop, radiusBottom, n)

double_cone(height, radius, n)

prism(height, radius, n)

arrow(length, head, width, n)

cuboid(size_x, size_y, size_z)

mapCuboid(size_x, size_y, size_z)

cube(size)

mapCube(size)

simpleBone(a)

listVertex(vn)

listVertexAll()

printVertex()

Action

new(anim)

Returns an instance of the Action object.

require("Action")

anAction = Action:new(node.shapes[1].anim)

addKeyPattern(name, time, from, to)

addAction(name, pattern_list)

setVerbose(true_or_false)

startAction(action_name)

getPattern()

playAction()

startTimeFromTo(pat)

Animation

Animation class contains keyframes of animation.

new(name)

Returns an instance of the Animation object.

require("Animation")

anAnimation = Animation:new("human")

setTimes(times)

setBonePoses(bone_poses)

addBoneName(bone_name)

getBoneName(i)

getType()

getName()

countPoses()

getNoOfBones()

close()

setData(skeleton, bind_shape_matrix)

appendData(time, key_frame_no)

getPeriodFromTo(from, to)

setPose(key)

transitionTo(time, keyFrom, keyTo)

start()

play()

playFps(frame_per_sec)

startFromTo(keyFrom, keyTo)

startTimeFromTo(time, keyFrom, keyTo)

list(print_matrix)

Schedule

Schedule class contains Task objects and execute Task's commands.

new()

Returns an instance of the Schedule object.

require("Schedule")

aSchedule = Schedule:new()

addTask(name)

 local aTask = aSchedule:addTask("task1")

delTask(task)

getEmptyTask()

getNoOfTasks()

getTask(n)

getTaskByName(name)

pause()

start()

startFrom(start_ip)

startFromTo(start_ip, stop_ip)

doCommandFps(frame_per_sec)

doCommand()

doOneCommand(ip, rate)

directExecution(time, command, args, start_ip, stop_ip)

setSpeed(time_scale)

Task

new(name, no)

Returns an instance of the Task object. Schedule:addTask(name) calls internally.

require("Task")

local aTask = Task:new("task1", no)

setTargetObject(target)

addCommand(time, func, arg)

setTime(ip, time)

getTime(ip)

getTime()

getNoOfCommands()

setCommand(command_table)

partial_arg(arg, total_time, dtime)

controlCommand(command, arg)

execCommand(doarg)

getNextCommand()

start()

startFrom(start_ip)

startFromTo(start_ip, stop_ip)

execute(delta_msec)

executeOneCommand(ip, arg_rate)

directExecution(command, doarg)

insertCurrentCommand(time, command, arg, start_ip, stop_ip)

CoordinateSystem

CoordinateSystem class is inherited from "Node" and "Frame". CoordinateSystem object contains position and rotation information.

new(parent_node, name)

print(str, q, pos)

printMoveRange()

setType(type)

getType()

addChild(child)

getNoOfChildren()

getChild(n)

setParent(parent)

Specifies the parent node

getParent()

Retrieves the parent node.

setName(name)

Specifies the name of the node.

getName()

Retrieves the name of the node.

setAttitude(head, pitch, bank)

Sets the rotation angle (degree) of the node.

getWorldAttitude()

Retrieves the rotation angle (degree) of the node in the world coordinate system. it returns the multiple values.

head, pitch, bank = aNode:getWorldAttitude()

getLocalAttitude()

Retrieves the rotation angle (degree) :of the node in the local coordinate system.

head, pitch, bank = aNode:getLocalAttitude()

getWorldPosition()

getPosition()

setPosition(x, y, z)

Sets the position (x, y, z) of the node in the parent coordinate system, or in the world coordinate system when the node's parent is nil.

setPositionX(x)

Sets the x-value of the node position.

setPositionY(y)

Sets the y-value of the node position.

setPositionZ(z)

Sets the z-value of the node position.

rotateX(degree)

Sets the rotation angle around the x-axis.

rotateY(degree)

Sets the rotation angle around the y-axis.

rotateZ(degree)

Sets the rotation angle around the z-axis.

rotate(head, pitch, bank)

Sets the rotation angle of head (around the y-axis), pitch (around the x-axis), bank (around the z-axis).

move(x, y, z)

Moves the position of the node.

setMatrix()

Sets the local matrix of the node.

setWorldMatrix()

Sets the world matrix of the node.

setWorldMatrixAll(wmat)

Sets the world matrix of all nodes.

getWorldMatrix()

Retrieves the world matrix of the node.

setByMatrix(matrix)

Sets the position and the attitude of the node by the specified Matrix object.

setQuat(quat)

Sets the attitude of the node by the specified Quaternion object.

getQuat()

Retrieves the Quaternion object of the node.

getQuatFromMatrix()

Retrieves the Quaternion object from the local Matrix object of the node.

getPositionFromMatrix()

Retrieves the position from the local Matrix object of the node.

detach()

attach(parent_node)

inverse(new_parent)

distance(node)

putRotation(head, pitch, bank)

putRotationByQuat(quat)

putAttitudeByQuat(quat)

putAttitude(head, pitch, bank)

putDistance(x, y, z)

putRotTrans(quat, pos)

putRotTransByMatrix(matrix)

execRotation(t)

execTranslation(t)

doRotation(t)

doTranslation(t)

doRotTrans(t)

Node

Node class inherits from a class named CoordinateSystem. A Node object contains position and rotation information. A Node object can contain Shape objects. Node objects are also used as bones of skeleton.

new(parent_bone, name)

setParent(parent)

hide(true_or_false)

setAttachable(true_or_false)

detach()

attach(parent_node)

setWeights()

setRestPosition(x, y, z)

setRestByMatrix(matrix)

rotateRest(head, pitch, bank)

moveRest(x, y, z)

setRestMatrix()

setModelMatrixAll(mmat)

setGlobalMatrixAll(wmat)

getRestMatrix()

getModelMatrix()

getBofMatrix()

getGlobalMatrix()

addShape(shape)

delShape()

setShape(shape)

getShape(n)

getShapeCount()

draw(view_matrix, light_vec)

drawBones()

Skeleton

Skeleton object contains bones.

new()

clone()

addBone(parent_bone, name)

setBoneShape(shape)

setAttachable(true_or_false)

isAttachable()

isShown()

showBone(true_or_false)

setBoneOrder(names)

getBoneOrder()

getBoneNo(name)

getBoneCount()

getBone(name)

getBoneFromJointNo(num)

printJointNames()

printBone()

getJointFromBone(bone)

getBoneNoFromBone(bone)

bindRestPose()

updateMatrixPalette()

listBones()

printMatrixPalette()

drawBones(view_matrix)

Matrix

Matrix class represents a 4x4 transformation matrix. Matrix objects is used to perform various graphical transformations on a 3D objects.

new()

makeUnit()

makeZero()

set(row, column, val)

check()

setBulk(numtable)

setBulkWithOffset(numtable, offset)

get(row, column)

clone()

copyFrom(mat)

convFloat()

setByQuat(quat)

setByEulerXYZ(rx, ry, rz)

matToEulerXYZ()

setByEuler(head, pitch, bank)

matToEuler()

position(position)

getPosition()

add(mb)

mul_(mb)

mul(mb)

lmul(mb)

makeProjectionMatrix(near, far, vfov, ratio)

makeProjectionMatrixWH(near, far, width, height)

makeProjectionMatrixOrtho(near, far, width, height)

inverse()

transpose()

makeView(w)

tmul3x3Vector(v)

mul3x3Vector(v)

mulVector(v)

print(f)

Quat

Quaternion class represents 3D rotations and orientations.

new()

mulQuat(qb)

lmulQuat(qb)

condugate()

normalize()

setRotateX(degree)

setRotateY(degree)

setRotateZ(degree)

eulerToQuat(head, pitch, bank)

dotProduct(qr)

negate()

slerp(a, b, t)

matrixToQuat(m)

print()

clone()

copyFrom(quat)

check()

quatToEuler()

FrameBufferObject

create(texture_class)

setClearColor(r, g, b, alpha)

clear()

endDraw()

destroy()

writeToFile()

Texture

new()

setupTexture()

setClamp()

readImageFromFile(textureFile)

setImage(image, width, height, ncol)

writeImageToFile()

createTexture(width, height, ncol)

fillTexture(r, g, b, a)

point(x, y, color)

assignTexture()

name()

active()

Font

Font object is a shader to draw characters.

new()

initShaderParameter()

setTextureUnit(tex_unit)

setChar(x, y, ch)

setPos(x, y)

setColor(r, g, b)

Sets the color of font.

setScale(scale)

Sets the font scale. The initial value is 1.0 (80x25).

getScale()

Returns the font scale.

Text

Text object is used to draw characters on the graphics screen. The Text object uses the screen as an 80x25 text screen.

new()

goTo(x, y)

Sets the start position at (x, y). The range of x is 0 to 79. The range of y is 0 to 24.

saveCursor()

Saves the cursor position.

restoreCursor()

Restores the cursor position.

scrollUp()

incCursorPosition()

write(str)

Writes a block of characters from cursor position.

writef(fmt, ...)

Writes a block of characters from cursor position.

writeAt(x, y, str)

Writes a block of characters from (x, y).

writefAt(x, y, fmt, ...)

Writes a block of characters from (x, y).

clearLine(lineNo)

Clears the line at lineNo.

clearScreen()

Clears screen.

fontTest()

setScale(scale)

makeShape()

init(texture_file)

Initialises the Font object with font image file.

initFont()

getDefaultFontImage()

drawScreen()

Message

new()

init(font_texture_file)

setMessage(n, x, y, text)

writeMessage(x, y, text)

delMessage(n)

clearMessages()

listMessages()

setColor(r, g, b)

drawScreen()

Shader

Shader class is a base class to use vertex shader and fragment shader. Shader object is inherited from Font, Phong, BonePhong and Background class.

new()

loadShader(type, shaderSource)

initShaders()

setDefaultParam(key, value)

updateParam(param, key, updateFunc)

initShaderParameter()

doParameter(param)

useProgram()

init()

Background

Background object is a shader.

new()

require("Background")

local background = Background:new()

initShaderParameter()

setTextureUnit(tex_unit)

setColor(r, g, b)

setAspect(aspect)

setWindow(left, top, width, height)

setOrder(order)

init()

setBackground(texture)

makeShape (scale)

drawScreen()

BonePhong

BonePhong object is a phong shader supported vertex blending.

new()

require("BonePhong")

local phong = BonePhong:new()
phong:setDefaultParam("light", {0, 100, 1000, 1})
phong:init()

initShaderParameter()

init()

Initializes the shader.

setDefaultParam(key, value)

Sets the default shader parameter. The "key" parameter is one of "color", "tex_unit", "use_texture", "light", "emissive", "ambient", "specular", "power" or "has_bone".

setLightPosition(positionAndType)

positionAndType parameter is a table which contains {x, y, z, type}. If type is 1, the light is parallel light. If type is 0, the light is point light. The initial value is {0.0, 0.0, 100.0, 1}.

useTexture(flag)

Specifies whether to use (flag=1) or not (flag=0).

setTextureUnit(tex_unit)

setEmissive(flag)

Specifies the emissivity. if a surface is emissive, flag is 1. The initial value is 0.

setAmbientLight(intensity)

Sets the ambient light intencity. The initial value is 0.3.

setSpecular(intensity)

Sets the specular intencity. The initial value is 0.6.

setSpecularPower(power)

Sets the specular reflection power. The initial value is 40.

setColor(color)

Sets the object color. The initial value is {0.8, 0.8, 1.0, 1.0} (red, green, blue, alpha).

setProjectionMatrix(m)

Sets the projection matrix.

setModelViewMatrix(m)

Sets the model matrix.

setNormalMatrix(m)

Sets the normal matrix.

updateTexture(param)

setHasBone(flag)

Specifies whether to have bones (flag=1). The initial value is 0.

setMatrixPalette(matrixPalette)

Sets the matrix palette.

doParameter(param)

Phong

Phong object is a phong shader.

new()

require("Phong")

local phong = Phong:new()
phong:setDefaultParam("light", {0, 100, 1000, 1})
phong:init()

initShaderParameter()

init()

Initializes the shader.

setDefaultParam(key, value)

Sets the default shader parameter. The "key" parameter is one of "color", "tex_unit", "use_texture", "light", "emissive", "ambient", "specular" or "power".

setLightPosition(positionAndType)

positionAndType parameter is a table which contains {x, y, z, type}. If type is 1, the light is parallel light. If type is 0, the light is point light. The initial value is {0.0, 0.0, 100.0, 1}.

useTexture(flag)

Specifies whether to use (flag=1) or not (flag=0).

setTextureUnit(tex_unit)

setEmissive(flag)

Specifies the emissivity. if a surface is emissive, flag is 1. The initial value is 0.

setAmbientLight(intensity)

Sets the ambient light intencity. The initial value is 0.3.

setSpecular(intensity)

Sets the specular intencity. The initial value is 0.6.

setSpecularPower(power)

Sets the specular reflection power. The initial value is 40.

setColor(color)

Sets the object color. The initial value is {0.8, 0.8, 1.0, 1.0} (red, green, blue, alpha).

setProjectionMatrix(m)

Sets the projection matrix.

setModelViewMatrix(m)

Sets the model matrix.

setNormalMatrix(m)

Sets the normal matrix.

updateTexture(param)

doParameter(param)

Collada

Collada class is inherited from ColladaShape class. Collada class is mostly for internal use.

new()

For internal use only.

printf(fmt, ...)

For internal use only.

getMeshes()

For internal use only.

getMeshCount()

For internal use only.

releaseMeshes()

For internal use only.

parseText(string_to_parse)

For internal use only.

parseArgs(string_to_parse)

For internal use only.

getNextTag()

For internal use only.

skip(tag)

This method is used internally to skip the collada source block with "tag".

skipToClosingTag(element)

This method is used internally to skip the collada source block up to closing tag.

asset(tag)

For internal use only.

library_cameras(tag)

For internal use only.

library_lights(tag)

For internal use only.

library_images(tag)

For internal use only.

library_effects(tag)

For internal use only.

library_materials(tag)

For internal use only.

getNumList(tag_id)

For internal use only.

getList(tag_id)

For internal use only.

source()

For internal use only.

getPolygonData(p, pointer, data_count)

For internal use only.

geo_mesh(id)

For internal use only.

extra(tag)

For internal use only.

library_geometries(tag)

For internal use only.

controller_skin(source_name)

For internal use only.

library_controllers(tag)

For internal use only.

node(tag, parent_frame)

For internal use only.

library_visual_scenes(tag)

For internal use only.

checkAnimationType(id)

For internal use only.

animation(tag, parent)

For internal use only.

library_animations(tag)

For internal use only.

scene(tag)

For internal use only.

getAnimation()

For internal use only.

parse(text, verbose)

Parses the collada format text.

ColladaShape

ColladaShape class inherits Collada class. ColladaShape object returns a Shape object form a collada format file.

new()

require("ColladaShape")

-- load collada
local collada = ColladaShape:new()
local collada_text = util.readFile(collada_file)
collada:parse(collada_text ,true)
local shapes = collada:makeShapes(true, true)

setBones(mesh, shape, verts, newindex)

For internal use only.

setShape(nmesh, bone_enable, texture_select)

For internal use only.

makeShapes(bone_enable, verbose, tex_select)

Returns Shape objects from collada format. if bone_enable is true, Shape object may contain a Skeleton object.

Frame

"Frame" is used in "Collada".

new(parent, name)

setByMatrix(matrix)

setWeights()

setType(type_name)

getType()

getName()

findFrame(name)

getNoOfBones(names)

findChildFrames(names)

getFramesFromNames(joint_names)

copyToBone(joint_names, bind_shape_matrix,

list(level)

listAll(level)

Mesh

Mesh class is used to contain vertex data in Collada object.

new(frame)

setName(name)

getName()

setVertices(verts)

getVertices()

setPolygons(polygons)

getPolygons()

setTextureCoord(texure_coord)

getTextureCoord()

setSkinWeights(skin_weights)

getSkinWeights()

setNormals(normals)

getNormals()

setJointNames(joint_names)

getJointNames()

setBindPoseMatrices(bindPoseMatrices)

getBindPoseMatrices()

setBindShapeMatrix(bind_shape_matrix)

getBindShapeMatrix()

updateBoundingBox(x, y, z)

printInfo()

Stack

Stack class is used in "Collada".

new()

push(contents)

pop()

top()

count()

Clone this wiki locally
You can’t perform that action at this time.