Model

Edit

Models 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.newModelCreate a new Model.
lovr.headset.newModelLoad a model for an active device.
Model:cloneReturn a lightweight copy of the Model with its own animation state.

Nodes

Model:getRootNodeGet the index of the root node.
Model:getNodeCountGet the number of nodes in the Model.
Model:getNodeNameGet the name of a node in the Model.
Model:getNodeChildGet the first child of a node.
Model:getNodeChildrenGet the children of a node.
Model:getNodeSiblingGet the next sibling of a node.
Model:getNodeParentGet the parent of a node.
Model:getNodeMeshGet the index of the mesh attached to a node.
Model:isNodeVisibleCheck if a node is visible.
Model:setNodeVisibleSet the visibility of a node.
Model:getNodePositionGet the position of a node.
Model:setNodePositionSet or blend the position of a node.
Model:getNodeOrientationGet the orientation of a node.
Model:setNodeOrientationSet or blend the orientation of a node.
Model:getNodeScaleGet the scale of a node.
Model:setNodeScaleSet or blend the scale of a node.
Model:getNodePoseGet the pose of a node.
Model:setNodePoseSet or blend the pose of a node.
Model:getNodeTransformGet the transform of a node.
Model:setNodeTransformSet or blend the transform of a node.
Model:resetNodeTransformsReset node transforms.

Animation

Model:getAnimationCountGet the number of animations in the Model.
Model:getAnimationNameGet the name of an animation.
Model:getAnimationDurationGet the duration of an animation, in seconds.
Model:hasJointsCheck if the Model uses joints for skeletal animation.
Model:animateAnimate the Model.

Blend Shapes

Model:resetBlendShapesReset blend shape weights.
Model:getBlendShapeWeightGet the weight of a blend shape.
Model:setBlendShapeWeightSet the weight of a blend shape.
Model:getBlendShapeCountGet the total number of blend shapes in the Model.
Model:getBlendShapeNameGet the name of a blend shape.
Model:getMeshBlendShapeCountGet the number of blend shapes in one of the Model's meshes.
Model:getMeshBlendShapeNameGet the name of a blend shape.

Bounds

Model:getWidthGet the width of the Model.
Model:getHeightGet the height of the Model.
Model:getDepthGet the depth of the Model.
Model:getDimensionsGet the dimensions of the Model.
Model:getCenterGet the center of the Model's bounding box.
Model:getBoundingBoxGet the bounding box of the Model.

Meshes

Model:meshesIterate over the nodes with meshes in the Model.
Model:getMeshCountGet the number of meshes in the Model.
Model:getMeshVertexCountGet the number of vertices in a mesh.
Model:getMeshIndexCountGet the number of vertex indices in a mesh.
Model:getMeshPartCountGet the number of parts in a mesh.
Model:getMeshDrawModeGet the draw mode of a mesh part.
Model:getMeshDrawRangeGet the vertex range of a mesh part.
Model:getMeshMaterialGet the index of the material used by a mesh part.

Textures

Model:getTextureCountGet the number of textures in the Model.
Model:getTextureGet one of the textures in the Model.
Model:getMaterialCountGet the number of materials in the Model.
Model:getMaterialNameGet the name of a material in the Model.
Model:getMaterialGet a Material from the Model.

Miscellaneous

Model:cloneReturn a lightweight copy of the Model with its own animation state.
Model:buildRaytracerRebuild raytracing data for the Model.
Model:getMetadataGet extra information from the model file.
Model:getVertexBufferGet a Buffer containing the vertices in the Model.
Model:getIndexBufferGet a Buffer containing the triangle indices in the Model.
Model:getMeshGet a Mesh from the Model.

See also