[Bf-extensions-cvs] [78b3fba] master: Various Fixes - Mostly Cycles Converter

lijenstina noreply at git.blender.org
Sun Aug 14 16:19:45 CEST 2016


Commit: 78b3fba23824c412a81229d88125e357e94ff601
Author: lijenstina
Date:   Sun Aug 14 16:17:59 2016 +0200
Branches: master
https://developer.blender.org/rBA78b3fba23824c412a81229d88125e357e94ff601

Various Fixes - Mostly Cycles Converter

Add missing descriptions for props
Some additional notes in the converters User Guides
Added a workaround for custom screen layouts
The old code accessed the UV editing screen  without checking it's
existence in screen layouts
The workaround temporarly sets the context  to IMAGE EDITOR

Added a texture paint sculpt mode
Adding a blank image for texture paint slot
( still needs proper naming for multiple materials )

Fixed the texture node frame logic
Fixed the loading of texture nodes from images that are not baked

Fix the texture coordinates location
Add frame for them
Add exceptions for creation of links

Added an another prop setting for using uv unwrap
Fixed an issue with possible crash during unwrapping

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

M	materials_utils/__init__.py
M	materials_utils/materials_cycles_converter.py

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

diff --git a/materials_utils/__init__.py b/materials_utils/__init__.py
index fed5949..fb84c4a 100644
--- a/materials_utils/__init__.py
+++ b/materials_utils/__init__.py
@@ -1699,6 +1699,10 @@ class MATERIAL_MT_scenemassive_opt(Menu):
         use_separator(self, context)
         layout.prop(sc.mat_specials, "SET_FAKE_USER", text="Set Fake User on unused images")
         use_separator(self, context)
+        layout.prop(sc.mat_specials, "SCULPT_PAINT", text="Sculpt/Texture paint mode")
+        use_separator(self, context)
+        layout.prop(sc.mat_specials, "UV_UNWRAP", text="Set Auto UV Unwrap (Active Object)")
+        use_separator(self, context)
 
         layout.label("Set the Bake Resolution")
         res = str(sc.mat_specials.img_bake_size)
@@ -1798,14 +1802,20 @@ class MATERIAL_MT_biconv_help(Menu):
 
     def draw(self, context):
         layout = self.layout
+        layout.label(text="If possible, avoid multiple conversions in a row")
         layout.label(text="Save Your Work Often", icon="ERROR")
         use_separator(self, context)
+        layout.label(text="Try to link them manually using Mix Color nodes")
+        layout.label(text="Only the last Image in the stack gets linked to Shader")
+        layout.label(text="Current limitation:", icon="MOD_EXPLODE")
+        use_separator(self, context)
         layout.label(text="Select the texture loaded in the image node")
         layout.label(text="Press Ctrl/T to create the image nodes")
         layout.label(text="In the Node Editor, Select the Diffuse Node")
         layout.label(text="Enable Node Wrangler addon", icon="NODETREE")
         layout.label(text="If Unconnected or No Image Node Error:", icon="MOD_EXPLODE")
         use_separator(self, context)
+        layout.label(text="Extract Alpha: the images have to have alpha channel")
         layout.label(text="The default path is the folder where the current .blend is")
         layout.label(text="During Baking, the script will check writting privileges")
         layout.label(text="Set the save path for extracting images with full access")
@@ -1828,6 +1838,7 @@ class MATERIAL_MT_nodeconv_help(Menu):
 
     def draw(self, context):
         layout = self.layout
+        layout.label(text="If possible, avoid multiple conversions in a row")
         layout.label(text="Save Your Work Often", icon="ERROR")
         use_separator(self, context)
         layout.label(text="Relinking and removing some not needed nodes")
@@ -1839,6 +1850,7 @@ class MATERIAL_MT_nodeconv_help(Menu):
         layout.label(text="Enable Node Wrangler addon", icon="NODETREE")
         layout.label(text="If Unconnected or No Image Node Error:", icon="MOD_EXPLODE")
         use_separator(self, context)
+        layout.label(text="For Specular Nodes, Image color influence has to be enabled")
         layout.label(text="Generated images (i.e. Noise and others) are not converted")
         layout.label(text="The Converter report can point out to some failures")
         layout.label(text="Not all Files will produce good results", icon="ERROR")
@@ -1894,20 +1906,36 @@ class material_specials_scene_props(PropertyGroup):
     EXTRACT_ALPHA = BoolProperty(
             attr="EXTRACT_ALPHA",
             default=False,
+            description=("Extract Alpha channel from non-procedural images \n"
+                         "Don't use this option if the image doesn't have Alpha"),
             )
     SET_FAKE_USER = BoolProperty(
             attr="SET_FAKE_USER",
             default=False,
+            description="Set fake user on unused images, so they can be kept in the .blend",
             )
     EXTRACT_PTEX = BoolProperty(
             attr="EXTRACT_PTEX",
             default=False,
+            description="Extract procedural images and bake them to jpeg",
             )
     EXTRACT_OW = BoolProperty(
             attr="Overwrite",
             default=False,
             description="Extract textures again instead of re-using priorly extracted textures",
             )
+    SCULPT_PAINT = BoolProperty(
+            attr="SCULPT_PAINT",
+            default=False,
+            description=("Conversion geared towards sculpting and painting.\n"
+                         "Creates a diffuse, glossy mixed with layer weight. \n"
+                         "Image nodes are not connected"),
+            )
+    UV_UNWRAP = BoolProperty(
+            attr="UV_UNWRAP",
+            default=False,
+            description=("Use automatical Angle based UV Unwrap of the active Object"),
+            )
     img_bake_size = EnumProperty(
             name="Bake Image Size",
             description="Set the resolution size of baked images \n",
@@ -1970,7 +1998,7 @@ class VIEW3D_MT_material_utils_pref(AddonPreferences):
     show_converters = BoolProperty(
             name="Enable Converters",
             default=True,
-            description=" \n  ",
+            description="Enable Material Converters",
             )
 
     set_preview_size = EnumProperty(
diff --git a/materials_utils/materials_cycles_converter.py b/materials_utils/materials_cycles_converter.py
index 838c555..1b46c0f 100644
--- a/materials_utils/materials_cycles_converter.py
+++ b/materials_utils/materials_cycles_converter.py
@@ -3,7 +3,6 @@
 # -*- coding: utf-8 -*-
 
 import bpy
-import os
 from os import path as os_path
 from bpy.types import Operator
 from bpy.props import (
@@ -23,8 +22,14 @@ from .warning_messages_utils import (
 # switch for operator's function called after AutoNodeInitiate
 CHECK_AUTONODE = False
 
-# set the node color for baked textures (default greenish)
+# set the node color for baked images (default greenish)
 NODE_COLOR = (0.32, 0.75, 0.32)
+# set the node color for the paint base images (default reddish)
+NODE_COLOR_PAINT = (0.6, 0.0, 0.0)
+
+# color for sculpt/texture painting setting (default clay the last entry is Roughness)
+PAINT_SC_COLOR = (0.80, 0.75, 0.54, 0.9)
+CLAY_GLOSSY = (0.38, 0.032, 0.023, 1)
 
 # -----------------------------------------------------------------------------
 # Functions #
@@ -61,6 +66,7 @@ def SetFakeUserTex():
 def BakingText(tex, mode, tex_type=None):
     collect_report("INFO: start bake texture named: " + tex.name)
     saved_img_path = None
+
     bpy.ops.object.mode_set(mode='OBJECT')
     sc = bpy.context.scene
     tmat = ''
@@ -113,43 +119,59 @@ def BakingText(tex, mode, tex_type=None):
 
     bpy.ops.image.new(name="TMP_BAKING", width=sizeX, height=sizeY,
                       color=(0.0, 0.0, 0.0, 1.0), alpha=True, float=False)
-    bpy.data.screens['UV Editing'].areas[1].spaces[0].image = bpy.data.images["TMP_BAKING"]
+
     sc.render.engine = 'BLENDER_RENDER'
     img = bpy.data.images["TMP_BAKING"]
     img = bpy.data.images.get("TMP_BAKING")
     img.file_format = ("JPEG" if not mode == "ALPHA" else "PNG")
 
-    paths = bpy.path.abspath(sc.mat_specials.conv_path)
-    tex_name = getattr(getattr(tex.texture, "image", None), "name", None)
-    texture_name = (tex_name.rpartition(".")[0] if tex_name else tex.texture.name)
-    new_tex_name = "baked"
-    name_append = ("_BAKING" if mode == "ALPHA" and
-                   tex.texture.type == 'IMAGE' else "_PTEXT")
-    new_appendix = (".jpg" if not mode == "ALPHA" else ".png")
-
-    if name_append in texture_name:
-        new_tex_name = texture_name
-    elif tex_type:
-        new_tex_name = tex_type + name_append
-    else:
-        new_tex_name = texture_name + name_append
-
-    img.filepath_raw = paths + new_tex_name + new_appendix
-    saved_img_path = img.filepath_raw
-
-    sc.render.bake_type = 'ALPHA'
-    sc.render.use_bake_selected_to_active = True
-    sc.render.use_bake_clear = True
-
-    # try to bake if it fails give report
+    # switch temporarly to 'IMAGE EDITOR'
+    # other approaches are not reliable
+    check_area = False
+    store_area = bpy.context.area.type
+    collect_report("INFO: Temporarly switching context to Image Editor")
     try:
-        bpy.ops.object.bake_image()
-        img.save()
+        bpy.context.area.type = 'IMAGE_EDITOR'
+        bpy.context.area.spaces[0].image = bpy.data.images["TMP_BAKING"]
+        check_area = True
     except:
-        # no return value so the image loading is skipped
-        saved_img_path = None
-        collect_report("ERROR: Baking could not be completed. "
-                       "Check System Console for info")
+        collect_report("ERROR: Setting to Image Editor failed, Baking aborted")
+        check_area = False
+
+    if check_area:
+        paths = bpy.path.abspath(sc.mat_specials.conv_path)
+        tex_name = getattr(getattr(tex.texture, "image", None), "name", None)
+        texture_name = (tex_name.rpartition(".")[0] if tex_name else tex.texture.name)
+        new_tex_name = "baked"
+        name_append = ("_BAKING" if mode == "ALPHA" and
+                       tex.texture.type == 'IMAGE' else "_PTEXT")
+        new_appendix = (".jpg" if not mode == "ALPHA" else ".png")
+
+        if name_append in texture_name:
+            new_tex_name = texture_name
+        elif tex_type:
+            new_tex_name = tex_type + name_append
+        else:
+            new_tex_name = texture_name + name_append
+
+        img.filepath_raw = paths + new_tex_name + new_appendix
+        saved_img_path = img.filepath_raw
+
+        sc.render.bake_type = 'ALPHA'
+        sc.render.use_bake_selected_to_active = True
+        sc.render.use_bake_clear = True
+
+        # try to bake if it fails give report
+        try:
+            bpy.ops.object.bake_image()
+            img.save()
+        except:
+            # no return value, so the image loading is skipped
+            saved_img_path = None
+            collect_report("ERROR: Baking could not be completed. "
+                           "Check System Console for info")
+    if store_area:
+        bpy.context.area.type = store_area
 
     bpy.ops.object.mode_set(mode='OBJECT')
     bpy.ops.object.delete()
@@ -162,7 +184,7 @@ def BakingText(tex, mode, tex_type=None):
         bpy.data.materials.remove(tmat)
 
     if saved_img_path:
-        collect_report("________________________________________")
+        collect_report("------- Baking fini

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list