-- Substitute an obj mesh node with an alembic mesh node -- -- @description substitute an obj mesh node with an alembic mesh node with the same materials pins -- @author Beppe Gullotta aka bepeg4d -- @version 0.1 -- get the current selection local selection = octane.project.getSelection() if #selection ~= 2 or selection.type ~= octane.node.NT_GEO_MESH and selection.type ~= octane.GT_GEOMETRYARCHIVE then error ("please select an obj node and an abc node") end print (unpack(selection)) if selection[1].type ~= octane.node.NT_GEO_MESH then mesh = selection[1] abc = selection[2] else mesh = selection[2] abc = selection[1] end print (mesh) print (abc) local parent = abc:getInputNodes() print(unpack(parent)) -- get the position of the selected node in the graph editor pos = selection[2].position print ("mesh node position =") print (unpack(pos)) -- table with params for the "macro" node graph params = {} params.type = octane.GT_STANDARD params.name = string.format (mesh.name .."-node-materials") params.position = {pos[1], pos[2]-40} -- creates the "macro" node graph, ie. root for all other nodes root = octane.nodegraph.create(params) local nodes = octane.nodegraph.copyItemTree(root, mesh) octane.node.destroy(nodes) local materials = octane.nodegraph.getOwnedItems(root) print (unpack(materials)) -- create the output nodes and connect them with the abc material pins local outMats = {} for i, x in pairs(materials) do outMat = octane.node.create { type = octane.NT_OUT_MATERIAL, name = x.name, graphOwner = root, } outMat:connectTo(octane.P_INPUT, x) print("finded " ..outMat.name) octane.nodegraph.unfold(root, false) for a, abcInLinker in ipairs(abc:getInputNodes()) do if abcInLinker.name == outMat.name and abcInLinker.type == octane.NT_IN_MATERIAL then abcInLinker:connectTo(octane.P_INPUT, outMat) print(abcInLinker.name .." connected with "..outMat.name) elseif abcInLinker.name ~= outMat.name or abcInLinker.type == octane.NT_IN_MATERIAL then print(abcInLinker.name .." not connected with "..outMat.name) end end end