Model:getNodeDraw

Returns the draw mode, material, and vertex range of a mesh in the model.


mode, material, start, count, base = Model:getNodeDraw(node, index)

Arguments

NameTypeDescription
nodenumber The index of the node.
indexnumber The index of the draw.

Returns

NameTypeDescription
modeMeshMode Whether the vertices are points, lines, or triangles.
materialMaterial The Material used by the draw.
startnumber The offset of the first vertex in the draw.
countnumber The number of vertices in the draw.
basenumber The base vertex of the draw (added to each instance value), or nil if the draw does not use an index buffer.

mode, material, start, count, base = Model:getNodeDraw(name, index)

Arguments

NameTypeDescription
namestring The name of the node.
indexnumber The index of the draw.

Returns

NameTypeDescription
modeMeshMode Whether the vertices are points, lines, or triangles.
materialMaterial The Material used by the draw.
startnumber The offset of the first vertex in the draw.
countnumber The number of vertices in the draw.
basenumber The base vertex of the draw (added to each instance value), or nil if the draw does not use an index buffer.

Example

function lovr.load()
  local m = lovr.graphics.newModel('enraged-gorilla.gltf')

  model = {
    object = m,
    data = m:getData(),
    vertices = m:getVertexBuffer(),
    indices = m:getIndexBuffer()
  }
end

local function drawNode(model, pass, i)
  for j = 1, model.object:getNodeDrawCount(i) do
    local mode, material, start, count, base = model.object:getNodeDraw(i, j)
    local transform = mat4(model.object:getNodeTransform(i))

    pass:setMeshMode(mode)
    pass:setMaterial(material)

    if base then
      pass:mesh(model.vertices, model.indices, transform, start, count, 1, base)
    else
      pass:mesh(model.vertices, transform, start, count)
    end
  end

  for _, index in ipairs(model.data:getNodeChildren(i)) do
    drawNode(model, pass, index)
  end
end

function lovr.draw(pass)
  drawNode(model, pass, model.data:getRootNode())
end

See also