Presets for an OBJ scene ?

Forum for OctaneRender Lua scripting examples, discussion and support.
Post Reply
Zay
Licensed Customer
Posts: 1123
Joined: Sun Jan 17, 2010 2:53 am

Is it possible to edit the materials from a loaded OBJ file using Lua? Making your own presets to correct most problems when loading a raw OBJ? I would really like to see an example I can work with if this is possible :)

Examine the OBJ file and change all Diffuse materials to Glossy.
Set the Specular/GreyScale Color to a fixed value.
Set the Roughness/GreyScale Color to a fixed value.
Set the Bump/GreyScale Color Power (if a node is found) to a fixed value.
Set the Index/Float Value to a fixed value.

Would this be possible?
Win 11 Pro | i5 12600K | 32GB ram | 2x GTX 1080Ti + 3080Ti - studio driver 560.94| Modo/Blender/ZBrush/Daz/Poser
Tugpsx
Licensed Customer
Posts: 1150
Joined: Thu Feb 04, 2010 8:04 pm
Location: Chicago, IL
Contact:

What program are you generating the OBJ files from. There are several Plugins and exporters that already do this, that's why i'm curious. For instance some exporters modifies the mtl file to add options that work in Octane, while the new version of Octane now supports custom ocs file.
Win 11 64GB | NVIDIA RTX3060 12GB
Zay
Licensed Customer
Posts: 1123
Joined: Sun Jan 17, 2010 2:53 am

Yep, that is exactly why I ask for this in Octane standalone and not in a plugin :)
Win 11 Pro | i5 12600K | 32GB ram | 2x GTX 1080Ti + 3080Ti - studio driver 560.94| Modo/Blender/ZBrush/Daz/Poser
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Hi Zay,

Here's a basic skeleton script, all it does is collect all the materials in the mesh node in a list. What you do with them is up to you... .

Code: Select all

-- Script to do "something" with the materials of a loaded OBJ mesh.

-- Get the selected mesh.
local mesh = octane.project.getSelection()[1]
assert(mesh:getProperties().type == octane.NT_GEO_MESH, "mesh expected")

-- Get all the materials of the selected mesh.
local mats = {}
for pinIx = 1, mesh:getPinCount() do
    local matNode = mesh:getConnectedNodeIx(pinIx)

    if matNode then
        print(string.format("pin %d -> material %s", pinIx, matNode:getProperties().name))

        -- collect the connected nodes
        table.insert(mats, matNode)
    end
end

-- We have the materials in a list, do something with them ...
For example, you could write a script that ask the user which OBJ file to load and display a window with some presets that can be configured. When the mesh is loaded, those presets will be used (e.g. create glossy materials for materials slots that weren't loaded, set the roughness to 1, ...).

I hope this snippet helps...

cheers,
Thomas
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

BTW, you could make it even more funky by asking the user which OBJ to load and then do the magic automatically.

Here we describe how you would load an OBJ file from Lua http://render.otoy.com/forum/viewtopic.php?f=73&t=37294

cheers,
Thomas
Zay
Licensed Customer
Posts: 1123
Joined: Sun Jan 17, 2010 2:53 am

Thanks stratified! I'll see what I can do with it :)
Win 11 Pro | i5 12600K | 32GB ram | 2x GTX 1080Ti + 3080Ti - studio driver 560.94| Modo/Blender/ZBrush/Daz/Poser
Post Reply

Return to “Lua Scripting”