# Class: model

A model contains triangle meshes and bonesystems, it can also have skin information for weighted vertex deformation based on bones. Models can be animateable or static, they can also have normals for lighting computation or simple vertex data. The information is needed for optimized storage and rendering of the model.
Every model can be loaded only once, so if one instance needs lighting use neednormals.

## Hierarchy

    o-+ resource
      o-+ model

## Methods:

### Method overview:

- bbox
- bonecount
- boneid
- create
- createfinish
- defaultpath
- forceload
- getboneparents
- getrestype
- load
- loaderprescale
- meshcount
- meshid
- removefromanim
- setanimcache
- setmeshtype
- skincount
- skinid
- updatebbox

bbox (model,[matrix4x4/float minx,miny,minz, maxx,maxy,maxz])
  returns: ([float minx,miny,minz, maxx,maxy,maxz])
  returns or sets bounding box. Returning can be done with matrix transformation applied (computes new AABB based)
bonecount (model)
  returns: (int)
  returns number of bones within model.
boneid (model,[string bonename/int index])
  returns: (boneid)
  returns boneid within model. If a string is applied, a bone with that name is seeked and if it doesn't exist, nothing is returned. If a number is passed, the bone with this index is returned, or an error is thrown to a index out of bounds exception. The index must be >=0 and <bonecount.
create (string name, vertextype, int meshcount, int bonecount,[int skincount])
  returns: (model)
  returns an empty model, using boneid,meshid,skinid.init as well as vertex-/indexarrays you can fill it with content. To make it useable you must run the createfinish command after you set all data. There will be bonecount+meshcount bones at start, and the first bones are linked with the meshes.
createfinish (model,boolean animatable,[boolean nodisplaylist],[boolean novbo],[boolean lmcoords])
  returns: (model)
  returns itself after successful compiling and errorchecking. To make the model useable you must call this function after all data was set. It will load all needed textures and materials as well as creating proper bone hierarchy. If it's not animateable we will precompute all vertices and remove bonelinks from meshids, as well as compute the internal bounding box. For last two parameters see load command (set both false if you know that you will often change vertex/index data). If skins are set and model is animateable, those will be initialized as well.
defaultpath ([string])
  returns: ([string])
  returns or sets the default resource path. Luxinia will search in those when resources are not found.
forceload
  (model):(string filename,[boolean animateable],[boolean neednormals],[boolean bigvertex],[boolean nodisplaylist],[boolean novbo] - same as load but enforces to load a copy if resource was loaded before.)
getboneparents (model)
  returns: ([table int])
  returns an array of the parent index for every bone. We start at 0 not 1. -1 means it has no parent. With model.boneid(index) command you can get more info about the bone.
getrestype ()
  returns: (int restype)
  returns the resource type as int value, useful for resdata or reschunk functions
load (string filename,[boolean animateable],[boolean neednormals],[boolean bigvertex],[boolean nodisplaylist],[boolean novbo],[boolean lmcoords])
  returns: (model)
  loads a model. Bigvertex means that multiple texcoords, hardware skinning, normal mapping.. can be used. If you pass the novbo and nodisplaylist with true, then the model will not get special GL memory processing for faster rendering, it is supposedly used for compiled l3dmodels. Normally the engine will favor vbo if avaliable over displaylists. However as displaylists allow only few changes (need to use same shader, cant disable vertexcolors) depending on your needs it is useful to disable them. VBOs dont have those disadvantages, but can be costly for older cards if the model has just very few vertices.
  When you should need lightmap texcoords use lmcoords with true.
  (defaults: neednormals:true, rest:false)<
loaderprescale ([float x,y,z])
  returns: ([float x,y,z])
  prescales vertices and bone positions with a given vector. The factor remains active for all follwing 'model.load' calls. Animations based on original size may cause problems. Prescale will be reapplied if the model is reloaded from disk again.
meshcount (model)
  returns: (int)
  returns number of meshes within model.
meshid (model,[string meshname/int index])
  returns: (meshid)
  returns meshid within model. If a string is applied, a mesh with that name is seeked and if it doesn't exist, nothing is returned. If a number is passed, the mesh with this index is returned, or an error is thrown to a index out of bounds exception. The index must be >=0 and <meshcount.
removefromanim (model,animation)
  returns: ()
  when animations are applied to models, they create an assignlist for each model to speed up track/bone matching. If you know this model will not use the given animation again, you can remove it from that list for speed's sake.
setanimcache (model,animation, int time,[matrix4x4 rootmatrix])
  returns: ()
  updates the animcache of a model with the given data. There is no visual effect of this operation, but only to be able to compute animation results without visual representation and query results via the boneid functions.
setmeshtype (model,int type,[boolean lmcoords],[boolean vertexcolors])
  returns: ()
  updates all meshes with given type: 0 auto 1 display list, 2 vertex array, 3 vertexbufferobject. defaults: lmcoords = false, vertexcolors = true
skincount (model)
  returns: (int)
  returns number of skins within model.
skinid (model,[int index])
  returns: (boneid)
  returns skinid within model. The skin with this index is returned, or an error is thrown to a index out of bounds exception. The index must be >=0 and < skincount.
updatebbox (model)
  returns: ()
  updates bounding box based on current vertices and reference bones.

## Inherited Methods:

### From resource

condition, getresname, getresshortname, resuserstring