Gltf-blender-io: Import occlusion map

Created on 22 Feb 2019  路  7Comments  路  Source: KhronosGroup/glTF-Blender-IO

@julienduroure I'm curious if you would be willing to modify the importer to preserve an occlusion map using an empty custom node. For example, when occlusion is combined with metal/rough, perhaps the importer could produce something similar to this:

image

I think I've worked out the code for creating and using a node group like this. This is what I have so far:

    # Put this definition somewhere common, it will likely change to "glTF Settings" or similar.
    gltf_node_group_name = 'glTF Metallic Roughness'

    # The following code runs per-material for materials with occlusion.

    # Check if the custom node group already exists
    if gltf_node_group_name in bpy.data.node_groups:
        gltf_node_group = bpy.data.node_groups[gltf_node_group_name]
    else:
        # Create a new node grouping
        gltf_node_group = bpy.data.node_groups.new(gltf_node_group_name, 'ShaderNodeTree')
        gltf_node_group.inputs.new("NodeSocketFloat", "Occlusion")
        gltf_node_group.nodes.new('NodeGroupOutput')
        gltf_group_input = gltf_node_group.nodes.new('NodeGroupInput')
        gltf_group_input.location = -200, 0

    # Place a new node grouping in the current material
    gltf_settings_node = bpy.data.materials[material_idx].node_tree.nodes.new('ShaderNodeGroup')

    # Set the newly placed node grouping to be the glTF grouping
    gltf_settings_node.node_tree = gltf_node_group
    gltf_settings_node.width = 220

From there you would connect the R channel of the occlusion image texture to the one socket on the new custom node.

enhancement importer

Most helpful comment

+1 for renaming this node to glTF Settings or glTF Export.

All 7 comments

Of course this has no effect in Blender preview, since it calculates its own AO. This would just be for round-trip purposes.

+1 for renaming this node to glTF Settings or glTF Export.

@emackey @donmccurdy I made a first draft on branch import_ao_node

Testing it now, thanks @julienduroure!

First thing I noticed, Double Sided doesn't need to be in the custom node group anymore, that got fixed in #304. I think Occlusion is the only remaining member of that node group.

@emackey Ok, DoubleSided is now removed

@emackey Any other review before I merge it?

Further review discussion in #437.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

UX3D-nopper picture UX3D-nopper  路  3Comments

spiraloid picture spiraloid  路  3Comments

Quinten123 picture Quinten123  路  4Comments

capnm picture capnm  路  5Comments

donmccurdy picture donmccurdy  路  3Comments