[Bf-extensions-cvs] [2caaf64a] master: glTF importer: rewrite material import

Julien Duroure noreply at git.blender.org
Wed Jan 29 21:57:40 CET 2020


Commit: 2caaf64ab10be6f03e234fa5b533e341512fbed5
Author: Julien Duroure
Date:   Wed Jan 29 21:57:22 2020 +0100
Branches: master
https://developer.blender.org/rBA2caaf64ab10be6f03e234fa5b533e341512fbed5

glTF importer: rewrite material import

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/com/gltf2_blender_material_helpers.py
M	io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
M	io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_unlit.py
M	io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
D	io_scene_gltf2/blender/imp/gltf2_blender_map_emissive.py
D	io_scene_gltf2/blender/imp/gltf2_blender_map_normal.py
D	io_scene_gltf2/blender/imp/gltf2_blender_map_occlusion.py
M	io_scene_gltf2/blender/imp/gltf2_blender_material.py
M	io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
A	io_scene_gltf2/blender/imp/gltf2_blender_texture.py
M	io_scene_gltf2/io/imp/gltf2_io_gltf.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index fc9f7a79..a2777b0c 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 2, 16),
+    "version": (1, 2, 17),
     'blender': (2, 81, 6),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/com/gltf2_blender_material_helpers.py b/io_scene_gltf2/blender/com/gltf2_blender_material_helpers.py
index ebb357a8..2b26350d 100755
--- a/io_scene_gltf2/blender/com/gltf2_blender_material_helpers.py
+++ b/io_scene_gltf2/blender/com/gltf2_blender_material_helpers.py
@@ -13,50 +13,6 @@
 # limitations under the License.
 
 
-def get_output_node(node_tree):
-    """Retrieve output node."""
-    output = [node for node in node_tree.nodes if node.type == 'OUTPUT_MATERIAL'][0]
-    return output
-
-
-def get_output_surface_input(node_tree):
-    """Retrieve surface input of output node."""
-    output_node = get_output_node(node_tree)
-    return output_node.inputs['Surface']
-
-
-def get_diffuse_texture(node_tree):
-    """Retrieve diffuse texture node."""
-    for node in node_tree.nodes:
-        print(node.name)
-        if node.label == 'BASE COLOR':
-            return node
-
-    return None
-
-
-def get_preoutput_node_output(node_tree):
-    """Retrieve node just before output node."""
-    output_node = get_output_node(node_tree)
-    preoutput_node = output_node.inputs['Surface'].links[0].from_node
-
-    # Pre output node is Principled BSDF or any BSDF => BSDF
-    if 'BSDF' in preoutput_node.type:
-        return preoutput_node.outputs['BSDF']
-    elif 'SHADER' in preoutput_node.type:
-        return preoutput_node.outputs['Shader']
-    else:
-        print(preoutput_node.type)
-
-
-def get_base_color_node(node_tree):
-    """Returns the last node of the diffuse block."""
-    for node in node_tree.nodes:
-        if node.label == 'BASE COLOR':
-            return node
-
-    return None
-
 def get_gltf_node_name():
     return "glTF Settings"
 
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
index 961b6f7a..f684a641 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
@@ -13,255 +13,153 @@
 # limitations under the License.
 
 import bpy
-from .gltf2_blender_material_utils import make_texture_block
 from ...io.com.gltf2_io import TextureInfo
-
-
-class BlenderKHR_materials_pbrSpecularGlossiness():
-    """Blender KHR_materials_pbrSpecularGlossiness extension."""
-    def __new__(cls, *args, **kwargs):
-        raise RuntimeError("%s should not be instantiated" % cls)
-
-    @staticmethod
-    def create(gltf, pbrSG, mat_name, vertex_color):
-        """KHR_materials_pbrSpecularGlossiness creation."""
-        engine = bpy.context.scene.render.engine
-        if engine in ['CYCLES', 'BLENDER_EEVEE']:
-            BlenderKHR_materials_pbrSpecularGlossiness.create_nodetree(gltf, pbrSG, mat_name, vertex_color)
-
-    @staticmethod
-    def create_nodetree(gltf, pbrSG, mat_name, vertex_color):
-        """Node tree creation."""
-        material = bpy.data.materials[mat_name]
-        material.use_nodes = True
-        node_tree = material.node_tree
-
-        # delete all nodes except output
-        for node in list(node_tree.nodes):
-            if not node.type == 'OUTPUT_MATERIAL':
-                node_tree.nodes.remove(node)
-
-        output_node = node_tree.nodes[0]
-        output_node.location = 1000, 0
-
-        # create PBR node
-        diffuse = node_tree.nodes.new('ShaderNodeBsdfDiffuse')
-        diffuse.location = 0, 0
-        glossy = node_tree.nodes.new('ShaderNodeBsdfGlossy')
-        glossy.location = 0, 100
-        mix = node_tree.nodes.new('ShaderNodeMixShader')
-        mix.location = 500, 0
-
-        glossy.inputs[1].default_value = 1 - pbrSG['glossinessFactor']
-
-        if pbrSG['diffuse_type'] == gltf.SIMPLE:
-            if not vertex_color:
-                # change input values
-                diffuse.inputs[0].default_value = pbrSG['diffuseFactor']
-
-            else:
-                # Create vertexcolor node to get COLOR_0 data
-                vertexcolor_node = node_tree.nodes.new('ShaderNodeVertexColor')
-                vertexcolor_node.layer_name = 'Col'
-                vertexcolor_node.location = -500, 0
-
-                # links
-                node_tree.links.new(diffuse.inputs[0], vertexcolor_node.outputs[0])
-
-        elif pbrSG['diffuse_type'] == gltf.TEXTURE_FACTOR:
-
-            # TODO alpha ?
-            if vertex_color:
-                # TODO tree locations
-                # Create vertexcolor / separate / math nodes
-                vertexcolor_node = node_tree.nodes.new('ShaderNodeVertexColor')
-                vertexcolor_node.layer_name = 'Col'
-
-                separate_vertex_color = node_tree.nodes.new('ShaderNodeSeparateRGB')
-                math_vc_R = node_tree.nodes.new('ShaderNodeMath')
-                math_vc_R.operation = 'MULTIPLY'
-
-                math_vc_G = node_tree.nodes.new('ShaderNodeMath')
-                math_vc_G.operation = 'MULTIPLY'
-
-                math_vc_B = node_tree.nodes.new('ShaderNodeMath')
-                math_vc_B.operation = 'MULTIPLY'
-
-            # create UV Map / Mapping / Texture nodes / separate & math and combine
-            text_node = make_texture_block(
-                gltf,
-                node_tree,
-                TextureInfo.from_dict(pbrSG['diffuseTexture']),
-                location=(-1000, 500),
-                label='DIFFUSE',
-                name='diffuseTexture',
-            )
-
-            combine = node_tree.nodes.new('ShaderNodeCombineRGB')
-            combine.location = -250, 500
-
-            math_R = node_tree.nodes.new('ShaderNodeMath')
-            math_R.location = -500, 750
-            math_R.operation = 'MULTIPLY'
-            math_R.inputs[1].default_value = pbrSG['diffuseFactor'][0]
-
-            math_G = node_tree.nodes.new('ShaderNodeMath')
-            math_G.location = -500, 500
-            math_G.operation = 'MULTIPLY'
-            math_G.inputs[1].default_value = pbrSG['diffuseFactor'][1]
-
-            math_B = node_tree.nodes.new('ShaderNodeMath')
-            math_B.location = -500, 250
-            math_B.operation = 'MULTIPLY'
-            math_B.inputs[1].default_value = pbrSG['diffuseFactor'][2]
-
-            separate = node_tree.nodes.new('ShaderNodeSeparateRGB')
-            separate.location = -750, 500
-
-            # Create links
-            if vertex_color:
-                node_tree.links.new(separate_vertex_color.inputs[0], vertexcolor_node.outputs[0])
-                node_tree.links.new(math_vc_R.inputs[1], separate_vertex_color.outputs[0])
-                node_tree.links.new(math_vc_G.inputs[1], separate_vertex_color.outputs[1])
-                node_tree.links.new(math_vc_B.inputs[1], separate_vertex_color.outputs[2])
-                node_tree.links.new(math_vc_R.inputs[0], math_R.outputs[0])
-                node_tree.links.new(math_vc_G.inputs[0], math_G.outputs[0])
-                node_tree.links.new(math_vc_B.inputs[0], math_B.outputs[0])
-                node_tree.links.new(combine.inputs[0], math_vc_R.outputs[0])
-                node_tree.links.new(combine.inputs[1], math_vc_G.outputs[0])
-                node_tree.links.new(combine.inputs[2], math_vc_B.outputs[0])
-
-            else:
-                node_tree.links.new(combine.inputs[0], math_R.outputs[0])
-                node_tree.links.new(combine.inputs[1], math_G.outputs[0])
-                node_tree.links.new(combine.inputs[2], math_B.outputs[0])
-
-            # Common for both mode (non vertex color / vertex color)
-            node_tree.links.new(math_R.inputs[0], separate.outputs[0])
-            node_tree.links.new(math_G.inputs[0], separate.outputs[1])
-            node_tree.links.new(math_B.inputs[0], separate.outputs[2])
-
-            node_tree.links.new(separate.inputs[0], text_node.outputs[0])
-
-            node_tree.links.new(diffuse.inputs[0], combine.outputs[0])
-
-        elif pbrSG['diffuse_type'] == gltf.TEXTURE:
-
-            # TODO alpha ?
-            if vertex_color:
-                # Create vertexcolor / separate / math nodes
-                vertexcolor_node = node_tree.nodes.new('ShaderNodeVertexColor')
-                vertexcolor_node.layer_name = 'Col'
-                vertexcolor_node.location = -2000, 250
-
-                separate_vertex_color = node_tree.nodes.new('ShaderNodeSeparateRGB')
-                separate_vertex_color.location = -1500, 250
-
-                math_vc_R = node_tree.nodes.new('ShaderNodeMath')
-                math_vc_R.operation = 'MULTIPLY'
-                math_vc_R.location = -1000, 750
-
-                math_vc_G = node_tree.nodes.new('ShaderNodeMath')
-                math_vc_G.operation = 'MULTIPLY'
-                math_vc_G.location = -1000, 500
-
-                math_vc_B = node_tree.nodes.new('ShaderNodeMath')
-                math_vc_B.operation = 'MULTIPLY'
-                math_vc_B.location = -1000, 250
-
-                combine = node_tree.nodes.new('ShaderNodeCombineRGB')
-                combine.location = -500, 500
-
-                separate = node_tree.nodes.new('ShaderNodeSeparateRGB')
-                separate.location = -1500, 500
-
-            # create UV Map / Mapping / Texture nodes / separate & math and combine
-            if vertex_color:
-                location = (-2000, 500)
-            else:
-                location = (-500, 500)
-            text_node = text_node = make_texture_block(
-                gltf,
-                node_tree,
-                TextureInfo.from_dict(pbrSG['diffuseTexture']),
-                location=location,
-                label='DIFF

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list