Isotropix Forums

Importing OBJ in PBR still apply StandardMaterial

You think you may have found a bug? Please post it here.

Importing OBJ in PBR still apply StandardMaterial

Unread postby tom_tm » Thu Aug 10, 2017 4:41 pm

Hi,

it's still applies StandardMaterial instead of StandardPhysicalMaterial when importing .obj.
Ok, I could change that with a batch running over the xml project file, but it would be useful
to have this fixed.

Greets Tom
tom_tm
 
Posts: 202
Joined: Mon Nov 18, 2013 9:20 pm
Location: Switzerland

Re: Importing OBJ in PBR still apply StandardMaterial

Unread postby dboude » Thu Aug 10, 2017 6:12 pm

Hi,

Waiting for the fix. Here is a script that replaces legacy materials by PBR materials. It reconnects all the texture map, transfers the values if no map is connected and assigns the PBR materials to the objects/shading group. It doesn't work if you use shading layers.

Uncomment the last line if you want to delete the legacy materials as well.

Code: Select all
materials = ix.api.OfObjectVector()
filter = "*"
type = ["MaterialStandard"]
for i in type:
    ix.application.get_matching_objects(materials, filter, i)

for mat in materials:

    diff = mat.attrs.diffuse
    back = mat.attrs.backlighting
    lumi = mat.attrs.luminosity
    spec = mat.attrs.specularity
    glos = mat.attrs.glossiness
    bump = mat.attrs.bump
    transp = mat.attrs.transparency
    ior = mat.attrs.index_of_refraction

    ix.selection.select(ix.get_item(str(mat)))
    ix.application.select_next_outputs()
    sel = ix.application.get_selection()
    if not sel.get_item(0).is_kindof("MaterialStandard"):
        context = mat.get_context()
        pbr = ix.cmds.CreateObject("pbr_" + str(mat).split("/")[-1], "MaterialPhysicalStandard", "Global", str(context))

        if diff.attr.is_textured() :
            map = diff.attr.get_texture()
            pbr.attrs.diffuse_front_color.attr.set_texture(map)
        else :
            pbr.attrs.diffuse_front_color[0] = diff[0]
            pbr.attrs.diffuse_front_color[1] = diff[1]
            pbr.attrs.diffuse_front_color[2] = diff[2]

        if back.attr.is_textured() :
            map = back.attr.get_texture()
            pbr.attrs.diffuse_back_color.attr.set_texture(map)
        else :
            pbr.attrs.diffuse_back_color[0] = back[0]
            pbr.attrs.diffuse_back_color[1] = back[1]
            pbr.attrs.diffuse_back_color[2] = back[2]

        if lumi.attr.is_textured() :
            map = lumi.attr.get_texture()
            pbr.attrs.emission_strength = 1
            pbr.attrs.emission_color.attr.set_texture(map)

        else :
            pbr.attrs.emission_color[0] = lumi[0]
            pbr.attrs.emission_color[1] = lumi[1]
            pbr.attrs.emission_color[2] = lumi[2]

        if spec.attr.is_textured() :
            map = spec.attr.get_texture()
            pbr.attrs.specular_1_color.attr.set_texture(map)
        else :
            pbr.attrs.specular_1_color[0] = spec[0]
            pbr.attrs.specular_1_color[1] = spec[1]
            pbr.attrs.specular_1_color[2] = spec[2]

        if glos.attr.is_textured() :
            map = glos.attr.get_texture()
            pbr.attrs.specular_1_roughness.attr.set_texture(map)
        else :
            pbr.attrs.specular_1_roughness[0] = 1 - glos[0]
            pbr.attrs.specular_1_roughness[1] = 1 - glos[1]
            pbr.attrs.specular_1_roughness[2] = 1 - glos[2]

        if transp.attr.is_textured() :
            map = transp.attr.get_texture()
            pbr.attrs.transmission_color.attr.set_texture(map)
        else :
            pbr.attrs.transmission_color[0] = transp[0]
            pbr.attrs.transmission_color[1] = transp[1]
            pbr.attrs.transmission_color[2] = transp[2]

        if ior.attr.is_textured() :
            map = ior.attr.get_texture()
            pbr.attrs.specular_1_index_of_refraction.attr.set_texture(map)
        else :
            pbr.attrs.specular_1_index_of_refraction = ior[0]

        if bump.attr.is_textured() :
            map = bump.attr.get_texture()
            bumpnode = ix.cmds.CreateObject("bump_map", "TextureBumpMap", "Global", str(context))
            bumpnode.attrs.input = bump[0]
            ix.cmds.SetTexture([str(bumpnode) + ".input"], str(map))
            pbr.attrs.normal_input.attr.set_texture(bumpnode)

        ix.selection.select(ix.get_item(str(mat)))
        ix.application.select_next_outputs()
        sel = ix.selection
        for i in range(sel.get_count()):
            shadingG = sel[i].get_module().get_geometry().get_shading_group_names()
            count = shadingG.get_count()
            for j in range(count):
                shaders = sel[i].attrs.materials[j]
                if shaders == mat:
                    ix.cmds.SetValues([sel[i].get_full_name() + ".materials" + str([j])], [str(pbr)])
                else:
                    print "No"
#        ix.cmds.DeleteItems([str(mat)])



Cheers ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 184
Joined: Mon Jul 03, 2017 11:51 am

Re: Importing OBJ in PBR still apply StandardMaterial

Unread postby tom_tm » Thu Aug 10, 2017 9:09 pm

Great, thank you Démian
tom_tm
 
Posts: 202
Joined: Mon Nov 18, 2013 9:20 pm
Location: Switzerland

Re: Importing OBJ in PBR still apply StandardMaterial

Unread postby dboude » Fri Aug 11, 2017 9:32 am

You're welcome !

Let me know if it works as expected.

Cheers ;)

Edit : I forgot to transfer reflections in the previous script. Now reflections are converted to spec 2 and specular to specular 1.

Code: Select all
materials = ix.api.OfObjectVector()
filter = "*"
type = ["MaterialStandard"]
for i in type:
    ix.application.get_matching_objects(materials, filter, i)

for mat in materials:

    diff = mat.attrs.diffuse
    back = mat.attrs.backlighting
    lumi = mat.attrs.luminosity
    spec = mat.attrs.specularity
    glos = mat.attrs.glossiness
    refl = mat.attrs.reflection
    rglos = mat.attrs.reflection_glossiness
    bump = mat.attrs.bump
    transp = mat.attrs.transparency
    ior = mat.attrs.index_of_refraction

    ix.selection.select(ix.get_item(str(mat)))
    ix.application.select_next_outputs()
    sel = ix.application.get_selection()
    if not sel.get_item(0).is_kindof("MaterialStandard"):
        context = mat.get_context()
        pbr = ix.cmds.CreateObject("pbr_" + str(mat).split("/")[-1], "MaterialPhysicalStandard", "Global", str(context))

        if diff.attr.is_textured() :
            map = diff.attr.get_texture()
            pbr.attrs.diffuse_front_color.attr.set_texture(map)
        else :
            pbr.attrs.diffuse_front_color[0] = diff[0]
            pbr.attrs.diffuse_front_color[1] = diff[1]
            pbr.attrs.diffuse_front_color[2] = diff[2]

        if back.attr.is_textured() :
            map = back.attr.get_texture()
            pbr.attrs.diffuse_back_color.attr.set_texture(map)
        else :
            pbr.attrs.diffuse_back_color[0] = back[0]
            pbr.attrs.diffuse_back_color[1] = back[1]
            pbr.attrs.diffuse_back_color[2] = back[2]

        if lumi.attr.is_textured() :
            map = lumi.attr.get_texture()
            pbr.attrs.emission_strength = 1
            pbr.attrs.emission_color.attr.set_texture(map)

        else :
            pbr.attrs.emission_color[0] = lumi[0]
            pbr.attrs.emission_color[1] = lumi[1]
            pbr.attrs.emission_color[2] = lumi[2]

        if spec.attr.is_textured() :
            map = spec.attr.get_texture()
            pbr.attrs.specular_1_color.attr.set_texture(map)
            pbr.attrs.specular_1_strength = 1
            pbr.attrs.specular_1_index_of_refraction = ior[0]
        else :
            pbr.attrs.specular_1_color[0] = spec[0]
            pbr.attrs.specular_1_color[1] = spec[1]
            pbr.attrs.specular_1_color[2] = spec[2]
            if (spec[0] + spec[1] + spec[2]) > 0 :
                pbr.attrs.specular_1_strength = 1
                pbr.attrs.specular_1_index_of_refraction = ior[0]

        if glos.attr.is_textured() :
            map = glos.attr.get_texture()
            pbr.attrs.specular_1_roughness.attr.set_texture(map)
        else :
            pbr.attrs.specular_1_roughness[0] = 1 - glos[0]
            pbr.attrs.specular_1_roughness[1] = 1 - glos[1]
            pbr.attrs.specular_1_roughness[2] = 1 - glos[2]

        if refl.attr.is_textured() :
            map = refl.attr.get_texture()
            pbr.attrs.specular_2_color.attr.set_texture(map)
            pbr.attrs.specular_2_strength[0] = 1
            pbr.attrs.specular_2_index_of_refraction = ior[0]
        else :
            pbr.attrs.specular_2_color[0] = refl[0]
            pbr.attrs.specular_2_color[1] = refl[1]
            pbr.attrs.specular_2_color[2] = refl[2]
            pbr.attrs.specular_2_strength[0] = 1
            pbr.attrs.specular_2_index_of_refraction = ior[0]

        if rglos.attr.is_textured() :
            map = rglos.attr.get_texture()
            pbr.attrs.specular_2_roughness.attr.set_texture(map)
        else :
            pbr.attrs.specular_2_roughness[0] = 1 - rglos[0]
            pbr.attrs.specular_2_roughness[1] = 1 - rglos[1]
            pbr.attrs.specular_2_roughness[2] = 1 - rglos[2]

        if transp.attr.is_textured() :
            map = transp.attr.get_texture()
            pbr.attrs.transmission_color.attr.set_texture(map)
        else :
            pbr.attrs.transmission_color[0] = transp[0]
            pbr.attrs.transmission_color[1] = transp[1]
            pbr.attrs.transmission_color[2] = transp[2]

        if ior.attr.is_textured() :
            map = ior.attr.get_texture()
            pbr.attrs.specular_1_index_of_refraction.attr.set_texture(map)
        else :
            pbr.attrs.specular_1_index_of_refraction = ior[0]

        if bump.attr.is_textured() :
            map = bump.attr.get_texture()
            bumpnode = ix.cmds.CreateObject("bump_map", "TextureBumpMap", "Global", str(context))
            bumpnode.attrs.input = bump[0]
            ix.cmds.SetTexture([str(bumpnode) + ".input"], str(map))
            pbr.attrs.normal_input.attr.set_texture(bumpnode)

        ix.selection.select(ix.get_item(str(mat)))
        ix.application.select_next_outputs()
        sel = ix.selection
        for i in range(sel.get_count()):
            shadingG = sel[i].get_module().get_geometry().get_shading_group_names()
            count = shadingG.get_count()
            for j in range(count):
                shaders = sel[i].attrs.materials[j]
                if shaders == mat:
                    ix.cmds.SetValues([sel[i].get_full_name() + ".materials" + str([j])], [str(pbr)])
                else:
                    print "No"
#        ix.cmds.DeleteItems([str(mat)])
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 184
Joined: Mon Jul 03, 2017 11:51 am

Re: Importing OBJ in PBR still apply StandardMaterial

Unread postby tom_tm » Fri Aug 11, 2017 4:04 pm

Hi Démian,
the first script works perfectly, in the latest one I got following error:



00:07:46 Traceback (most recent call last):
00:07:46 File "<string>", line 57, in <module>
00:07:46 File "C:/Program Files/Isotropix/Clarisse iFX 3.5/Clarisse/python\framework.py", line 3393, in __setattr__
00:07:46 print "error setting value " + str(value) + " of attr " + name
00:07:46 AttributeError: the specified attribute doesn't exist
00:07:46
tom_tm
 
Posts: 202
Joined: Mon Nov 18, 2013 9:20 pm
Location: Switzerland

Re: Importing OBJ in PBR still apply StandardMaterial

Unread postby dboude » Fri Aug 11, 2017 5:48 pm

I updated my last post. There was an extra character.

Cheers ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 184
Joined: Mon Jul 03, 2017 11:51 am

Re: Importing OBJ in PBR still apply StandardMaterial

Unread postby tom_tm » Sat Aug 12, 2017 6:31 pm

now, working like a charm :-) Thank you!
I will also positing it in the scripting forum.
tom_tm
 
Posts: 202
Joined: Mon Nov 18, 2013 9:20 pm
Location: Switzerland

Re: Importing OBJ in PBR still apply StandardMaterial

Unread postby dboude » Wed Aug 16, 2017 10:14 am

;) Thank you !
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 184
Joined: Mon Jul 03, 2017 11:51 am


Return to Bugs Archive