Export to OBJ format

Visionary Render does not include exporters out of the box, however using LUA scripts a Visionary Render Platform developer can write their own exporter.

This example code translates a Visionary Render mesh node to an OBJ file. For more information about the OBJ format, see https://en.wikipedia.org/wiki/Wavefront_.obj_file.


function ExportOBJ(meshNode, filename)
  function WriteVertexData(f, attribNode, tag)
    local step = attribNode.Size
    local content = attribNode.Content
    for i=1,#content,step do
      f:write(tag)
      for j=1,step do
        f:write(" ", content[i+j-1])
      end
      f:write("\n")
    end
  end
 
  function WriteIndexData(f, primNode, tag)
    local step = 3 -- Assuming trilist for now.
    local content = primNode.Content
    for i=1,#content,step do
      f:write(tag)
      for j=1,step do
        f:write(" ", content[i+j-1]+1)
      end
      f:write("\n")
    end
  end
   
  local f = assert(io.open(filename, "w")) 
   
  local n = meshNode:child()
  while n do
    local name = n:getName()
    if name == "pos" then
      WriteVertexData(f, n, "v")
    elseif name == "nrm" then
      WriteVertexData(f, n, "vn")
    elseif name == "tan" then
      WriteVertexData(f, n, "vp")
    elseif name == "tex0" then
      WriteVertexData(f, n, "vt")
    elseif name == "trilist" then
      WriteIndexData(f, n, "f")
    end
    n = n:next()
  end
   
  f:close()
end
 
local Mesh = vrTreeRoot():find("root/Libraries/Geometry/rotor_moving/GeoGroup_1/Mesh")
ExportOBJ(Mesh, "C:\\temp\\Test.obj")


E
Ericka is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.