Hi Davve,
Thanks for your script! I modified it a bit to make it work for us Linux users. The only catch is that you'll need to install the lua file system library (
http://keplerproject.github.io/luafilesystem/manual.html) because we need a portable way to list the content of a directory (We'll probably include this in one of the next versions of Octane because it's really useful). I described LuaRocks in a different post:
http://render.otoy.com/forum/viewtopic.php?f=73&t=37632.
Just some remarks, the field
groupOwner
doesn't exist in
PROPS_NODE_ITEM
so it's ignored by Octane. When you don't want to position your nodes manually, you can call
unfold()
on your graph which will layout it nicely for you. Thanks again! here's the code:
- Code: Select all
-- Generates a group node from the obj files loaded from a directory
--
-- @description Loads OBJ files from a folder and hooks them up with a group node
-- @version 0.2
-- @author Davve
-- use the lua file system module
require("lfs")
-- let the user choose a directory
local result = octane.gui.showDialog
{
type = octane.gui.dialogType.FILE_DIALOG,
title = "Choose OBJ file directory",
browseDirectory = true,
save = false,
}
local path = result.result
assert(path ~= "", "invalid OBJ directory")
-- fetch all the obj files in the directory
local objFiles = {}
for child in lfs.dir(path) do
if (string.lower(string.sub(child, -4)) == ".obj") then
table.insert(objFiles, child)
end
end
local root = octane.nodegraph.getRootGraph()
-- create the group node
group = octane.node.create{ type=octane.NT_GEO_GROUP, name="Group" }
group:setAttribute(octane.A_PIN_COUNT, #objFiles, true)
-- create a node for each obj file and connect it to the group
for i, name in ipairs(objFiles) do
local mesh = octane.node.create{type=octane.NT_GEO_MESH , name=name }
mesh:setAttribute(octane.A_FILENAME, string.format("%s//%s", path, name), true)
group:connectToIx(i, mesh)
end
-- call unfold on the root graph to arrange everything neatly
root:unfold()
You should see something like this in the end:
- group created from all the OBJ files in a folder
cheers,
Thomas