katana opscript – localizing texture files

At work we had to localize all the texture maps in a shot for packaging.
Localization was due to happen from a particular folder onward, keeping the folder structure from that point on.

This would need to work at asset level (local material networks) as well as klf assigned network materials.

This opScript takes 2 user attributes from the opscript node: oldPath, new Path, and crawls through the material.nodes finding pxrTexture nodes and replacing the string.

The CEL can run either at /root/materials//* for local materials, as well as on the /root/world/geo//* on scene graph locations where klf’s are assigned

local material = Interface.GetAttr('material.nodes')
if (material ~= nil) then
    old_path= Interface.GetOpArg("user.oldPath")
    new_path = Interface.GetOpArg("user.newPath")
    local len_of_children = material:getNumberOfChildren()
    if (len_of_children > 0) then
        for i=0, len_of_children do
            local shading_node = material:getChildByIndex(i)
            if (shading_node ~= nil) then
                local type = shading_node:getChildByName('type'):getValue()
                if (type == 'PxrTexture') then
                    local image_node_name = 'material.nodes.' .. shading_node:getChildByName('name'):getValue()
                    local image_node_path = Interface.GetAttr(image_node_name .. '.parameters.filename')
                    local image_node_new_path = string.gsub(image_node_path:getValue(),old_path:getValue(),new_path:getValue())
                    Interface.SetAttr(image_node_name .. '.parameters.filename', StringAttribute(image_node_new_path))
                end
            end
        end
    end
end
Previous
Previous

x-special/nautilus-clipboard workaround

Next
Next

RHEL and CentOS 8 nvidia-prime setup