[Bf-extensions-cvs] [199586c9] master: materials_utils: moved to contrib: T63750

meta-androcto noreply at git.blender.org
Fri May 24 08:00:37 CEST 2019


Commit: 199586c9884ea3ea89ed2c93cc2eadbe975f8a5c
Author: meta-androcto
Date:   Fri May 24 16:00:12 2019 +1000
Branches: master
https://developer.blender.org/rBAC199586c9884ea3ea89ed2c93cc2eadbe975f8a5c

materials_utils: moved to contrib: T63750

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

A	materials_utils/__init__.py
A	materials_utils/material_converter.py
A	materials_utils/materials_cycles_converter.py
A	materials_utils/texture_rename.py
A	materials_utils/warning_messages_utils.py

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

diff --git a/materials_utils/__init__.py b/materials_utils/__init__.py
new file mode 100644
index 00000000..70ff4fc9
--- /dev/null
+++ b/materials_utils/__init__.py
@@ -0,0 +1,2741 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+#  (c) 2016 meta-androcto, parts based on work by Saidenka, lijenstina
+#  Materials Utils: by MichaleW, lijenstina,
+#       (some code thanks to: CoDEmanX, SynaGl0w, ideasman42)
+#  Materials Conversion: Silvio Falcinelli, johnzero7#,
+#        fixes by angavrilov and others
+#  Link to base names: Sybren, Texture renamer: Yadoob
+
+bl_info = {
+    "name": "Materials Utils Specials",
+    "author": "Community",
+    "version": (1, 0, 6),
+    "blender": (2, 79, 0),
+    "location": "Materials Properties Specials > Shift Q",
+    "description": "Materials Utils and Convertors",
+    "warning": "",
+    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
+                "Scripts/3D_interaction/Materials_Utils",
+    "category": "Material"
+}
+
+if "bpy" in locals():
+    import importlib
+    importlib.reload(texture_rename)
+    importlib.reload(warning_messages_utils)
+else:
+    from . import texture_rename
+    from . import warning_messages_utils
+
+import bpy
+import os
+from os import (
+    path as os_path,
+    access as os_access,
+    remove as os_remove,
+)
+from bpy.props import (
+    BoolProperty,
+    CollectionProperty,
+    EnumProperty,
+    IntProperty,
+    StringProperty,
+    PointerProperty,
+)
+from bpy.types import (
+    AddonPreferences,
+    Menu,
+    Operator,
+    Panel,
+    PropertyGroup,
+    UIList,
+)
+from .warning_messages_utils import (
+    warning_messages,
+    c_data_has_materials,
+    c_obj_data_has_materials,
+)
+
+# Globals
+UNDO_MESSAGE = "*Only Undo is available*"
+COLUMN_SPLIT = 20
+
+
+# Functions
+
+def fake_user_set(fake_user='ON', materials='UNUSED', operator=None):
+    warn_mesg, w_mesg = '', ""
+    if materials == 'ALL':
+        mats = (mat for mat in bpy.data.materials if mat.library is None)
+        w_mesg = "(All Materials in this .blend file)"
+    elif materials == 'UNUSED':
+        mats = (mat for mat in bpy.data.materials if mat.library is None and mat.users == 0)
+        w_mesg = "(Unused Materials - Active/Selected Objects)"
+    else:
+        mats = []
+        if materials == 'ACTIVE':
+            objs = [bpy.context.active_object]
+            w_mesg = "(All Materials on Active Object)"
+        elif materials == 'SELECTED':
+            objs = bpy.context.selected_objects
+            w_mesg = "(All Materials on Selected Objects)"
+        elif materials == 'SCENE':
+            objs = bpy.context.scene.objects
+            w_mesg = "(All Scene Objects)"
+        else:
+            # used materials
+            objs = bpy.data.objects
+            w_mesg = "(All Used Materials)"
+
+        mats = (mat for ob in objs if hasattr(ob.data, "materials") for
+                mat in ob.data.materials if mat.library is None)
+
+    # collect mat names for warning_messages
+    matnames = []
+
+    warn_mesg = ('FAKE_SET_ON' if fake_user == 'ON' else 'FAKE_SET_OFF')
+
+    for mat in mats:
+        mat.use_fake_user = (fake_user == 'ON')
+        matnames.append(getattr(mat, "name", "NO NAME"))
+
+    if operator:
+        if matnames:
+            warning_messages(operator, warn_mesg, matnames, 'MAT', w_mesg)
+        else:
+            warning_messages(operator, 'FAKE_NO_MAT')
+
+    for area in bpy.context.screen.areas:
+        if area.type in ('PROPERTIES', 'NODE_EDITOR', 'OUTLINER'):
+            area.tag_redraw()
+
+
+def replace_material(m1, m2, all_objects=False, update_selection=False, operator=None):
+    # replace material named m1 with material named m2
+    # m1 is the name of original material
+    # m2 is the name of the material to replace it with
+    # 'all' will replace throughout the blend file
+
+    matorg = bpy.data.materials.get(m1)
+    matrep = bpy.data.materials.get(m2)
+
+    if matorg != matrep and None not in (matorg, matrep):
+        # store active object
+        if all_objects:
+            objs = bpy.data.objects
+        else:
+            objs = bpy.context.selected_editable_objects
+
+        for ob in objs:
+            if ob.type == 'MESH':
+                match = False
+                for m in ob.material_slots:
+                    if m.material == matorg:
+                        m.material = matrep
+                        # don't break the loop as the material can be
+                        # referenced more than once
+
+                        # Indicate which objects were affected
+                        if update_selection:
+                            ob.select_set(True)
+                            match = True
+
+                if update_selection and not match:
+                    ob.select_set(False)
+    else:
+        if operator:
+            warning_messages(operator, "REP_MAT_NONE")
+
+
+def select_material_by_name(find_mat_name):
+    # in object mode selects all objects with material find_mat_name
+    # in edit mode selects all polygons with material find_mat_name
+
+    find_mat = bpy.data.materials.get(find_mat_name)
+
+    if find_mat is None:
+        return
+
+    # check for edit mode
+    editmode = False
+
+    scn = bpy.context.scene
+
+    # set selection mode to polygons
+    scn.tool_settings.mesh_select_mode = False, False, True
+
+    actob = bpy.context.active_object
+    if actob.mode == 'EDIT':
+        editmode = True
+        bpy.ops.object.mode_set()
+
+    if not editmode:
+        objs = bpy.data.objects
+        for ob in objs:
+            if included_object_types(ob.type):
+                ms = ob.material_slots
+                for m in ms:
+                    if m.material == find_mat:
+                        ob.select_set(True)
+                        # the active object may not have the mat!
+                        # set it to one that does!
+                        scn.objects.active = ob
+                        break
+                    else:
+                        ob.select_set(False)
+            # deselect non-meshes
+            else:
+                ob.select_set(False)
+    else:
+        # it's edit mode, so select the polygons
+        ob = actob
+        ms = ob.material_slots
+
+        # same material can be on multiple slots
+        slot_indeces = []
+        i = 0
+
+        for m in ms:
+            if m.material == find_mat:
+                slot_indeces.append(i)
+            i += 1
+        me = ob.data
+
+        for f in me.polygons:
+            if f.material_index in slot_indeces:
+                f.select = True
+            else:
+                f.select = False
+        me.update()
+
+    if editmode:
+        bpy.ops.object.mode_set(mode='EDIT')
+
+
+def mat_to_texface(operator=None):
+    # assigns the first image in each material to the polygons in the active
+    # uv layer for all selected objects
+
+    # check for editmode
+    editmode = False
+
+    actob = bpy.context.active_object
+    if actob.mode == 'EDIT':
+        editmode = True
+        bpy.ops.object.mode_set()
+
+    # collect object names for warning messages
+    message_a = []
+    # Flag if there are non MESH objects selected
+    mixed_obj = False
+
+    for ob in bpy.context.selected_editable_objects:
+        if ob.type == 'MESH':
+            # get the materials from slots
+            ms = ob.material_slots
+
+            # build a list of images, one per material
+            images = []
+            # get the textures from the mats
+            for m in ms:
+                if m.material is None:
+                    continue
+                gotimage = False
+                textures = zip(m.material.texture_slots, m.material.use_textures)
+                for t, enabled in textures:
+                    if enabled and t is not None:
+                        tex = t.texture
+                        if tex.type == 'IMAGE':
+                            img = tex.image
+                            images.append(img)
+                            gotimage = True
+                            break
+
+                if not gotimage:
+                    images.append(None)
+
+            # check materials for warning messages
+            mats = ob.material_slots.keys()
+            if operator and not mats and mixed_obj is False:
+                message_a.append(ob.name)
+
+            # now we have the images, apply them to the uvlayer
+            me = ob.data
+
+            # got uvs?
+            if not me.uv_textures:
+                scn = bpy.context.scene
+                scn.objects.active = ob
+                bpy.ops.mesh.uv_texture_add()
+                scn.objects.active = actob
+
+            # get active uv layer
+            for t in me.uv_textures:
+                if t.active:
+                    uvtex = t.data
+                    for f in me.polygons:
+                        # check that material had an image!
+                        if images and images[f.material_index] is not None:
+                            uvtex[f.index].image = images[f.material_index]
+                        else:
+                            uvtex[f.index].image = None
+            me.update()
+        else:
+            message_a.append(ob.name)
+            mixed_obj = True
+
+    if editmode:
+        bpy.ops.object.mode_set(mode='EDIT')
+
+    if operator and message

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list