Model
EditModels are 3D model assets loaded from files. Currently, OBJ, glTF, and binary STL files are supported.
A model can be drawn using Pass:draw. A specific mesh or part of a mesh can be drawn using Pass:drawPart.
The raw CPU data for a model is held in a ModelData object.
Models have a hierarchy of nodes which can have their transforms modified. Meshes are attached to these nodes. The same mesh can be attached to multiple nodes, allowing it to be drawn multiple times while only storing a single copy of its data.
Models can have animations. Animations have keyframes which affect the transforms of nodes. Right now each model can only be drawn with a single animated pose per frame.
Models can have materials, which are collections of properties and textures that define how its surface is affected by lighting. Meshes are split up into multiple parts, and each part can have its own material.
Constructors
| lovr.graphics.newModel | Create a new Model. |
| lovr.headset.newModel | Load a model for an active device. |
| Model:clone | Return a lightweight copy of the Model with its own animation state. |
Nodes
| Model:getRootNode | Get the index of the root node. |
| Model:getNodeCount | Get the number of nodes in the Model. |
| Model:getNodeName | Get the name of a node in the Model. |
| Model:getNodeChild | Get the first child of a node. |
| Model:getNodeChildren | Get the children of a node. |
| Model:getNodeSibling | Get the next sibling of a node. |
| Model:getNodeParent | Get the parent of a node. |
| Model:getNodeMesh | Get the index of the mesh attached to a node. |
| Model:isNodeVisible | Check if a node is visible. |
| Model:setNodeVisible | Set the visibility of a node. |
| Model:getNodePosition | Get the position of a node. |
| Model:setNodePosition | Set or blend the position of a node. |
| Model:getNodeOrientation | Get the orientation of a node. |
| Model:setNodeOrientation | Set or blend the orientation of a node. |
| Model:getNodeScale | Get the scale of a node. |
| Model:setNodeScale | Set or blend the scale of a node. |
| Model:getNodePose | Get the pose of a node. |
| Model:setNodePose | Set or blend the pose of a node. |
| Model:getNodeTransform | Get the transform of a node. |
| Model:setNodeTransform | Set or blend the transform of a node. |
| Model:resetNodeTransforms | Reset node transforms. |
Animation
| Model:getAnimationCount | Get the number of animations in the Model. |
| Model:getAnimationName | Get the name of an animation. |
| Model:getAnimationDuration | Get the duration of an animation, in seconds. |
| Model:hasJoints | Check if the Model uses joints for skeletal animation. |
| Model:animate | Animate the Model. |
Blend Shapes
| Model:resetBlendShapes | Reset blend shape weights. |
| Model:getBlendShapeWeight | Get the weight of a blend shape. |
| Model:setBlendShapeWeight | Set the weight of a blend shape. |
| Model:getBlendShapeCount | Get the total number of blend shapes in the Model. |
| Model:getBlendShapeName | Get the name of a blend shape. |
| Model:getMeshBlendShapeCount | Get the number of blend shapes in one of the Model's meshes. |
| Model:getMeshBlendShapeName | Get the name of a blend shape. |
Bounds
| Model:getWidth | Get the width of the Model. |
| Model:getHeight | Get the height of the Model. |
| Model:getDepth | Get the depth of the Model. |
| Model:getDimensions | Get the dimensions of the Model. |
| Model:getCenter | Get the center of the Model's bounding box. |
| Model:getBoundingBox | Get the bounding box of the Model. |
Meshes
| Model:meshes | Iterate over the nodes with meshes in the Model. |
| Model:getMeshCount | Get the number of meshes in the Model. |
| Model:getMeshVertexCount | Get the number of vertices in a mesh. |
| Model:getMeshIndexCount | Get the number of vertex indices in a mesh. |
| Model:getMeshPartCount | Get the number of parts in a mesh. |
| Model:getMeshDrawMode | Get the draw mode of a mesh part. |
| Model:getMeshDrawRange | Get the vertex range of a mesh part. |
| Model:getMeshMaterial | Get the index of the material used by a mesh part. |
Textures
| Model:getTextureCount | Get the number of textures in the Model. |
| Model:getTexture | Get one of the textures in the Model. |
| Model:getMaterialCount | Get the number of materials in the Model. |
| Model:getMaterialName | Get the name of a material in the Model. |
| Model:getMaterial | Get a Material from the Model. |
Miscellaneous
| Model:clone | Return a lightweight copy of the Model with its own animation state. |
| Model:buildRaytracer | Rebuild raytracing data for the Model. |
| Model:getMetadata | Get extra information from the model file. |
| Model:getVertexBuffer | Get a Buffer containing the vertices in the Model. |
| Model:getIndexBuffer | Get a Buffer containing the triangle indices in the Model. |
| Model:getMesh | Get a Mesh from the Model. |