[Bf-extensions-cvs] [d9ed9d4d] master: materials_utils: initial update 2.8 series
meta-androcto
noreply at git.blender.org
Sat Jul 27 07:55:13 CEST 2019
Commit: d9ed9d4d064c74c86e2767cd4be32d602a0ee317
Author: meta-androcto
Date: Sat Jul 27 15:54:52 2019 +1000
Branches: master
https://developer.blender.org/rBACd9ed9d4d064c74c86e2767cd4be32d602a0ee317
materials_utils: initial update 2.8 series
===================================================================
M materials_utils/__init__.py
A materials_utils/enum_values.py
A materials_utils/functions.py
D materials_utils/material_converter.py
D materials_utils/materials_cycles_converter.py
A materials_utils/menus.py
A materials_utils/operators.py
D materials_utils/texture_rename.py
D materials_utils/warning_messages_utils.py
===================================================================
diff --git a/materials_utils/__init__.py b/materials_utils/__init__.py
index c0c80dde..40f976d7 100644
--- a/materials_utils/__init__.py
+++ b/materials_utils/__init__.py
@@ -15,2727 +15,165 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
-
+
+# Based on 2010 version by MichaelW
# (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
+# Materials Utils: by MichaleW, meta-androcto, lijenstina,
+# (some code thanks to: CoDEmanX, SynaGl0w, ideasman42)
# Link to base names: Sybren, Texture renamer: Yadoob
+# Ported from 2.6/2.7 to 2.8x by Christopher Hindefjord (chrishinde) 2019
bl_info = {
- "name": "Materials Utils Specials",
- "author": "Community",
+ "name": "Material Utils",
+ "author": "MichaleW, ChrisHinde",
"version": (1, 0, 6),
- "blender": (2, 79, 0),
- "location": "Materials Properties Specials > Shift Q",
- "description": "Materials Utils and Convertors",
+ "blender": (2, 80, 0),
+ "location": "View3D > Shift + Q key",
+ "description": "Menu of material tools (assign, select..) in the 3D View",
"warning": "",
- "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
- "Scripts/3D_interaction/Materials_Utils",
+ "wiki_url": "https://github.com/ChrisHinde/MaterialUtilities",
"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_a:
- warn_mess = ('MAT_TEX_NO_MESH' if mixed_obj is True else 'MAT_TEX_NO_MAT')
- warning_messages(operator, warn_mess, message_a)
-
-
-def assignmats
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list