CM3D2 Converter.misc_MATERIAL_PT_context_material

   1# 「プロパティ」エリア → 「マテリアル」タブ
   2import os
   3import re
   4import sys
   5import time
   6import bpy
   7import bmesh
   8import mathutils
   9from . import common
  10from . import compat
  11from . import cm3d2_data
  12from .translations.pgettext_functions import *
  13
  14
  15# メニュー等に項目追加 (for 2.7x or less)
  16def menu_func(self, context):
  17    if compat.IS_LEGACY is False:
  18        return
  19
  20    # ModelVersionでCOM3D2のmodelか判断
  21    model_ver = bpy.context.active_object.get("ModelVersion")
  22    is_com_mode = model_ver and model_ver >= 2000
  23
  24    mate = context.material
  25    if not mate:
  26        col = self.layout.column(align=True)
  27        if is_com_mode:
  28            col.operator('material.new_com3d2', icon_value=common.kiss_icon())
  29        else:
  30            col.operator('material.new_cm3d2', icon_value=common.kiss_icon())
  31            col.operator('material.new_com3d2', icon='ERROR')
  32        row = col.row(align=True)
  33        row.operator('material.import_cm3d2_mate', icon='FILE_FOLDER', text="mateから")
  34        opr = row.operator('material.paste_material', icon='PASTEDOWN', text="クリップボードから")
  35        opr.is_decorate, opr.is_create = True, True
  36    else:
  37        if 'shader1' in mate and 'shader2' in mate:
  38            box = self.layout.box()
  39            # row = box.split(percentage=0.3)
  40            row = compat.layout_split(box, factor=0.5)
  41            row.label(text="CM3D2用", icon_value=common.kiss_icon())
  42            sub_row = row.row(align=True)
  43            sub_row.operator('material.export_cm3d2_mate', icon='FILE_FOLDER', text="mateへ")
  44            sub_row.operator('material.copy_material', icon='COPYDOWN', text="コピー")
  45            sub_row.operator('material.paste_material', icon='PASTEDOWN', text="貼付け")
  46
  47            icon = 'ERROR'
  48            shader1 = mate['shader1']
  49            shader_prop = cm3d2_data.MaterialHandler.get_shader_prop_dynamic(mate) #cm3d2_data.Handler.get_shader_prop(shader1)
  50            type_name = shader_prop.get('type_name')
  51            icon = shader_prop.get('icon')
  52
  53            row = compat.layout_split(box, factor=0.333333333333333333333)
  54            row.label(text="種類:")
  55            row.label(text=type_name, icon=icon)
  56            box.prop(mate, 'name', icon='SORTALPHA', text="マテリアル名")
  57            box.prop(mate, '["shader1"]', icon='MATERIAL', text="シェーダー1")
  58            box.prop(mate, '["shader2"]', icon=compat.icon('SHADING_RENDERED'), text="シェーダー2")
  59
  60            box.operator('material.decorate_material', icon=compat.icon('SHADING_TEXTURE'))
  61
  62            if 'CM3D2 Texture Expand' not in mate:
  63                mate['CM3D2 Texture Expand'] = True
  64            box = self.layout.box()
  65            if mate.get('CM3D2 Texture Expand', False):
  66                row = box.row()
  67                row.alignment = 'LEFT'
  68                op = row.operator('wm.context_set_int', icon='DOWNARROW_HLT', text="", emboss=False)
  69                op.data_path, op.value, op.relative = 'material["CM3D2 Texture Expand"]', 0, False
  70                row.label(text="簡易テクスチャ情報", icon_value=common.kiss_icon())
  71
  72                if compat.IS_LEGACY:
  73                    for slot in mate.texture_slots:
  74                        if not slot or not slot.texture:
  75                            continue
  76                        tex = slot.texture
  77                        name = common.remove_serial_number(tex.name).replace("_", "") + " "
  78
  79                        if slot.use:
  80                            node_type = 'tex'
  81                        else:
  82                            node_type = 'col' if slot.use_rgb_to_intensity else 'f'
  83
  84                        if node_type == 'tex':
  85                            row = box.row(align=True)
  86                            sub_row = compat.layout_split(row, factor=0.333333333333333333333, align=True)
  87                            sub_row.label(text=name, icon_value=sub_row.icon(tex))
  88                            img = getattr(text, 'image')
  89                            if img:
  90                                sub_row.template_ID(tex, 'image')
  91                            row.operator('material.quick_texture_show', text="", icon='RIGHTARROW').texture_name = tex.name
  92                        elif node_type == 'col':
  93                            row = box.row(align=True)
  94                            sub_row = compat.layout_split(row, factor=0.333333333333333333333, align=True)
  95                            sub_row.label(text=name, icon_value=sub_row.icon(tex))
  96                            sub_row.prop(slot, 'color', text="")
  97                            sub_row.prop(slot, 'diffuse_color_factor', icon='IMAGE_RGB_ALPHA', text="透明度", slider=True)
  98                            row.operator('material.quick_texture_show', text="", icon='RIGHTARROW').texture_name = tex.name
  99                        elif node_type == 'f':
 100                            row = box.row(align=True)
 101                            sub_row = compat.layout_split(row, factor=0.333333333333333333333, align=True)
 102                            sub_row.label(text=name, icon_value=sub_row.icon(tex))
 103                            sub_row.prop(slot, 'diffuse_color_factor', icon='ARROW_LEFTRIGHT', text="値")
 104                            row.operator('material.quick_texture_show', text="", icon='RIGHTARROW').texture_name = tex.name
 105
 106                    box.operator('texture.sync_tex_color_ramps', icon='LINKED')
 107
 108            else:
 109                row = box.row()
 110                row.alignment = 'LEFT'
 111                op = row.operator('wm.context_set_int', icon='RIGHTARROW', text="", emboss=False)
 112                op.data_path, op.value, op.relative = 'material["CM3D2 Texture Expand"]', 1, False
 113                row.label(text="簡易テクスチャ情報", icon_value=common.kiss_icon())
 114
 115        else:
 116            if is_com_mode:
 117                self.layout.operator('material.new_com3d2', text="COM3D2用に変更", icon_value=common.kiss_icon())
 118            else:
 119                self.layout.operator('material.new_com3d2', text="COM3D2用に変更", icon_value=common.kiss_icon())
 120                self.layout.operator('material.new_cm3d2', text="CM3D2用に変更", icon_value=common.kiss_icon())
 121
 122
 123@compat.BlRegister(only_latest=True)
 124class MATERIAL_PT_cm3d2_properties(bpy.types.Panel):
 125    bl_space_type = 'PROPERTIES'
 126    bl_region_type = 'WINDOW'
 127    bl_context = 'material'
 128    bl_label = 'CM3D2'
 129    bl_idname = 'MATERIAL_PT_cm3d2_properties'
 130
 131    @classmethod
 132    def poll(cls, context):
 133        return True
 134
 135    def draw(self, context):
 136        ob = context.active_object
 137        # ModelVersionでCOM3D2のmodelか判断
 138        model_ver = ob.get('ModelVersion')
 139        is_com_mode = model_ver and model_ver >= 2000
 140
 141        mate = context.material
 142        if not mate:
 143            col = self.layout.column(align=True)
 144            if is_com_mode:
 145                col.operator('material.new_com3d2', icon_value=common.kiss_icon())
 146            else:
 147                col.operator('material.new_cm3d2', icon_value=common.kiss_icon())
 148                col.operator('material.new_com3d2', icon='ERROR')
 149            row = col.row(align=True)
 150            row.operator('material.import_cm3d2_mate', icon='FILE_FOLDER', text="mateから")
 151            opr = row.operator('material.paste_material', icon='PASTEDOWN', text="クリップボードから")
 152            opr.is_decorate, opr.is_create, opr.use_dialog = True, True, False
 153
 154        else:
 155            if 'shader1' in mate and 'shader2' in mate:
 156                box = self.layout#.box()
 157                # row = box.split(percentage=0.3)
 158                #row = compat.layout_split(box, factor=0.5)
 159                row = self.layout.column()
 160                row.label(text="CM3D2用", icon_value=common.kiss_icon())
 161                sub_row = row.row(align=True)
 162                sub_row.operator('material.export_cm3d2_mate', icon='FILE_FOLDER', text="mateへ")
 163                sub_row.operator('material.copy_material', icon='COPYDOWN', text="コピー")
 164                opr = sub_row.operator('material.paste_material', icon='PASTEDOWN', text="貼付け")
 165                opr.use_dialog = True
 166                opr.is_create = False
 167
 168                shader1 = mate['shader1']
 169                shader_prop = cm3d2_data.MaterialHandler.get_shader_prop_dynamic(mate) #cm3d2_data.Handler.get_shader_prop(shader1)
 170                type_name = shader_prop.get('type_name', '不明')
 171                icon = shader_prop.get('icon', 'ERROR')
 172
 173                row = compat.layout_split(box, factor=1 / 3)
 174                row.label(text="種類:")
 175                row.label(text=type_name, icon=icon)
 176                box.prop(mate, 'name', icon='SORTALPHA', text="マテリアル名")
 177                box.prop(mate, '["shader1"]', icon='MATERIAL', text="シェーダー1")
 178                box.prop(mate, '["shader2"]', icon=compat.icon('SHADING_RENDERED'), text="シェーダー2")
 179
 180                # For LEGACY
 181                # box.operator('material.decorate_material', icon=compat.icon('SHADING_TEXTURE'))
 182                if 'CM3D2 Texture Expand' not in mate:
 183                    box.operator('material.setup_mate_expand', text="フラグセットアップ")
 184                    return
 185
 186                box = self.layout.box()
 187                if mate['CM3D2 Texture Expand']:
 188                    if mate.use_nodes is False:
 189                        box.operator('material.setup_mate_expand', text="フラグセットアップ")
 190                        return
 191
 192                    row = box.row()
 193                    row.alignment = 'LEFT'
 194                    op = row.operator('wm.context_set_int', icon='DOWNARROW_HLT', text="", emboss=False)
 195                    op.data_path, op.value, op.relative = 'material["CM3D2 Texture Expand"]', 0, False
 196                    row.label(text="マテリアルプロパティ", icon_value=common.kiss_icon())
 197
 198                    # ノード名はシリアル番号がついていない想定とする
 199                    tex_list, col_list, f_list = [], [], []
 200                    nodes = mate.node_tree.nodes
 201                    for node_name in shader_prop['tex_list']:
 202                        node = nodes.get(node_name)
 203                        if node and node.type == 'TEX_IMAGE':
 204                            tex_list.append(node)
 205
 206                    for node_name in shader_prop['col_list']:
 207                        node = nodes.get(node_name)
 208                        if node and node.type == 'RGB':
 209                            col_list.append(node)
 210
 211                    for node_name in shader_prop['f_list']:
 212                        node = nodes.get(node_name)
 213                        if node and node.type == 'VALUE':
 214                            f_list.append(node)
 215
 216                    for node in tex_list:
 217                        tex = node.image
 218                        if tex:
 219                            name = common.remove_serial_number(tex.name).replace("_", "") + " "
 220
 221                            row = box.row(align=True)
 222                            sub_row = compat.layout_split(row, factor=1 / 3, align=True)
 223                            sub_row.label(text=node.label, icon_value=sub_row.icon(tex))
 224                            if tex:
 225                                sub_row.template_ID(node, 'image', open='image.open')
 226
 227                            expand = node.get('CM3D2 Prop Expand', False)
 228                            if expand:
 229                                row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
 230                                menu_mateprop_tex(context, box, node)
 231                            else:
 232                                row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
 233
 234                    for node in col_list:
 235                        row = box.row(align=True)
 236                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
 237                        sub_row.label(text=node.label, icon='COLOR')
 238                        col = node.outputs[0]
 239                        sub_row.prop(col, 'default_value', text="")
 240
 241                        expand = node.get('CM3D2 Prop Expand', False)
 242                        if expand:
 243                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
 244                            menu_mateprop_col(context, box, node)
 245                        else:
 246                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
 247
 248                    for node in f_list:
 249                        row = box.row(align=True)
 250
 251                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
 252                        sub_row.label(text=node.label, icon='ARROW_LEFTRIGHT')
 253
 254                        f = node.outputs[0]
 255                        sub_row.prop(f, 'default_value', icon='ARROW_LEFTRIGHT', text="値")
 256
 257                        expand = node.get('CM3D2 Prop Expand', False)
 258                        if expand:
 259                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
 260                            menu_mateprop_f(context, box, node)
 261                        else:
 262                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
 263
 264                    if '_ALPHAPREMULTIPLY_ON' in mate.keys():
 265                        row = box.row(align=True)
 266                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
 267                        sub_row.label(text="_ALPHAPREMULTIPLY_ON", icon='CHECKBOX_HLT')
 268                        sub_row.prop(mate, '["_ALPHAPREMULTIPLY_ON"]', icon=compat.icon('SHADING_RENDERED'), text="Value", toggle=1)
 269                        row.label(text="", icon='BLANK1')
 270
 271                    # if compat.IS_LEGACY:
 272                    # 	box.operator('texture.sync_tex_color_ramps', icon='LINKED')
 273                else:
 274                    row = box.row()
 275                    row.alignment = 'LEFT'
 276                    op = row.operator('wm.context_set_int', icon='RIGHTARROW', text="", emboss=False)
 277                    op.data_path, op.value, op.relative = 'material["CM3D2 Texture Expand"]', 1, False
 278                    row.label(text="マテリアルプロパティ", icon_value=common.kiss_icon())
 279                    # op = row.operator('wm.context_set_int', icon='RIGHTARROW', text="", emboss=False)
 280
 281            else:
 282                if is_com_mode:
 283                    self.layout.operator('material.new_com3d2', text="COM3D2用に変更", icon_value=common.kiss_icon())
 284                else:
 285                    self.layout.operator('material.new_cm3d2', text="CM3D2用に変更", icon_value=common.kiss_icon())
 286                    self.layout.operator('material.new_com3d2', text="COM3D2用に変更", icon_value=common.kiss_icon())
 287
 288
 289class new_mate_opr():
 290    is_decorate = bpy.props.BoolProperty(name="種類に合わせてマテリアルを装飾", default=True)
 291    # is_replace_cm3d2_tex = bpy.props.BoolProperty(name="テクスチャを探す", default=False, description="CM3D2本体のインストールフォルダからtexファイルを探して開きます")
 292
 293    @classmethod
 294    def poll(cls, context):
 295        return True
 296
 297    def invoke(self, context, event):
 298        return context.window_manager.invoke_props_dialog(self)
 299
 300    def draw(self, context):
 301        self.layout.separator()
 302        self.layout.prop(self, 'shader_type', icon='MATERIAL')
 303        if compat.IS_LEGACY:
 304            self.layout.prop(self, 'is_decorate', icon=compat.icon('SHADING_TEXTURE'))
 305        prefs = common.preferences()
 306
 307        self.layout.prop(prefs, 'is_replace_cm3d2_tex', icon='BORDERMOVE')
 308
 309    def execute(self, context):
 310        ob = context.active_object
 311        me = ob.data
 312        ob_names = common.remove_serial_number(ob.name).split('.')
 313        ob_name = ob_names[0]
 314
 315        if context.material:
 316            mate = context.material
 317            if compat.IS_LEGACY:
 318                for index, slot in enumerate(mate.texture_slots):
 319                    mate.texture_slots.clear(index)
 320            else:
 321                if mate.use_nodes:
 322                    cm3d2_data.clear_nodes(mate.node_tree.nodes)
 323
 324        else:
 325            if not context.material_slot:
 326                bpy.ops.object.material_slot_add()
 327            mate = context.blend_data.materials.new(ob_name)
 328        common.setup_material(mate)
 329
 330        context.material_slot.material = mate
 331        tex_list, col_list, f_list = [], [], []
 332
 333        base_path = common.BASE_PATH_TEX
 334        prefs = common.preferences()
 335
 336        _MainTex = ("_MainTex", ob_name, base_path + ob_name + ".png")
 337        _ToonRamp = ("_ToonRamp", prefs.new_mate_toonramp_name, prefs.new_mate_toonramp_path)
 338        _ShadowTex = ("_ShadowTex", ob_name + "_shadow", base_path + ob_name + "_shadow.png")
 339        _ShadowRateToon = ("_ShadowRateToon", prefs.new_mate_shadowratetoon_name, prefs.new_mate_shadowratetoon_path)
 340        _HiTex = ("_HiTex", ob_name + "_s", base_path + ob_name + "_s.png")
 341        _OutlineTex = ("_OutlineTex", ob_name + "_line", base_path + ob_name + "_line.png")
 342        _OutlineToonRamp = ("_OutlineToonRamp", prefs.new_mate_linetoonramp_name, prefs.new_mate_linetoonramp_path)
 343
 344        _Color = ("_Color", prefs.new_mate_color)
 345        _ShadowColor = ("_ShadowColor", prefs.new_mate_shadowcolor)
 346        _RimColor = ("_RimColor", prefs.new_mate_rimcolor)
 347        _OutlineColor = ("_OutlineColor", prefs.new_mate_outlinecolor)
 348
 349        _Shininess = ("_Shininess", prefs.new_mate_shininess)
 350        _OutlineWidth = ("_OutlineWidth", prefs.new_mate_outlinewidth)
 351        _RimPower = ("_RimPower", prefs.new_mate_rimpower)
 352        _RimShift = ("_RimShift", prefs.new_mate_rimshift)
 353        _HiRate = ("_HiRate", prefs.new_mate_hirate)
 354        _HiPow = ("_HiPow", prefs.new_mate_hipow)
 355        _Cutoff = ("_Cutoff", prefs.new_mate_cutoff)
 356        _ZTest = ("_ZTest", prefs.new_mate_ztest)
 357        _ZTest2 = ("_ZTest2", prefs.new_mate_ztest2)
 358        _ZTest2Alpha = ("_ZTest2Alpha", prefs.new_mate_ztest2alpha)
 359
 360        if False:
 361            pass
 362        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline':
 363            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline'
 364            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline'
 365            tex_list.append(_MainTex)
 366            tex_list.append(_ToonRamp)
 367            tex_list.append(_ShadowTex)
 368            tex_list.append(_ShadowRateToon)
 369            col_list.append(_Color)
 370            col_list.append(_ShadowColor)
 371            col_list.append(_RimColor)
 372            col_list.append(_OutlineColor)
 373            f_list.append(_Shininess)
 374            f_list.append(_OutlineWidth)
 375            f_list.append(_RimPower)
 376            f_list.append(_RimShift)
 377        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans':
 378            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans'
 379            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans'
 380            tex_list.append(_MainTex)
 381            tex_list.append(_ToonRamp)
 382            tex_list.append(_ShadowTex)
 383            tex_list.append(_ShadowRateToon)
 384            col_list.append(_Color)
 385            col_list.append(_ShadowColor)
 386            col_list.append(_RimColor)
 387            f_list.append(_Shininess)
 388            f_list.append(_Cutoff)
 389            f_list.append(_RimPower)
 390            f_list.append(_RimShift)
 391        elif self.shader_type == 'CM3D2/Toony_Lighted_Hair_Outline':
 392            mate['shader1'] = 'CM3D2/Toony_Lighted_Hair_Outline'
 393            mate['shader2'] = 'CM3D2__Toony_Lighted_Hair_Outline'
 394            tex_list.append(_MainTex)
 395            tex_list.append(_ToonRamp)
 396            tex_list.append(_ShadowTex)
 397            tex_list.append(_ShadowRateToon)
 398            tex_list.append(_HiTex)
 399            col_list.append(_Color)
 400            col_list.append(_ShadowColor)
 401            col_list.append(_RimColor)
 402            col_list.append(_OutlineColor)
 403            f_list.append(_Shininess)
 404            f_list.append(_OutlineWidth)
 405            f_list.append(_RimPower)
 406            f_list.append(_RimShift)
 407            f_list.append(_HiRate)
 408            f_list.append(_HiPow)
 409        elif self.shader_type == 'CM3D2/Mosaic':
 410            mate['shader1'] = 'CM3D2/Mosaic'
 411            mate['shader2'] = 'CM3D2__Mosaic'
 412            tex_list.append(("_RenderTex", ""))
 413            f_list.append(("_FloatValue1", 30))
 414        elif self.shader_type == 'Unlit/Texture':
 415            mate['shader1'] = 'Unlit/Texture'
 416            mate['shader2'] = 'Unlit__Texture'
 417            tex_list.append(_MainTex)
 418            # col_list.append(_Color)
 419        elif self.shader_type == 'Unlit/Transparent':
 420            mate['shader1'] = 'Unlit/Transparent'
 421            mate['shader2'] = 'Unlit__Transparent'
 422            tex_list.append(_MainTex)
 423            # col_list.append(_Color)
 424            # col_list.append(_ShadowColor)
 425            # col_list.append(_RimColor)
 426            # f_list.append(_Shininess)
 427            # f_list.append(_RimPower)
 428            # f_list.append(_RimShift)
 429        elif self.shader_type == 'CM3D2/Man':
 430            mate['shader1'] = 'CM3D2/Man'
 431            mate['shader2'] = 'CM3D2__Man'
 432            col_list.append(_Color)
 433            f_list.append(("_FloatValue2", 0.5))
 434            f_list.append(("_FloatValue3", 1))
 435        elif self.shader_type == 'Diffuse':
 436            mate['shader1'] = 'Legacy Shaders/Diffuse'
 437            mate['shader2'] = 'Legacy Shaders__Diffuse'
 438            tex_list.append(_MainTex)
 439            col_list.append(_Color)
 440        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans_NoZ':
 441            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans_NoZ'
 442            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans_NoZ'
 443            tex_list.append(_MainTex)
 444            tex_list.append(_ToonRamp)
 445            tex_list.append(_ShadowTex)
 446            tex_list.append(_ShadowRateToon)
 447            col_list.append(_Color)
 448            col_list.append(_ShadowColor)
 449            col_list.append(_RimColor)
 450            f_list.append(_Shininess)
 451            f_list.append(_RimPower)
 452            f_list.append(_RimShift)
 453        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans_NoZTest':
 454            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans_NoZTest'
 455            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans_NoZTest'
 456            tex_list.append(_MainTex)
 457            tex_list.append(_ToonRamp)
 458            tex_list.append(_ShadowTex)
 459            tex_list.append(_ShadowRateToon)
 460            col_list.append(_Color)
 461            col_list.append(_ShadowColor)
 462            col_list.append(_RimColor)
 463            f_list.append(_Shininess)
 464            f_list.append(_RimPower)
 465            f_list.append(_RimShift)
 466            f_list.append(_ZTest)
 467            f_list.append(_ZTest2)
 468            f_list.append(_ZTest2Alpha)
 469        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline_Trans':
 470            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline_Trans'
 471            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline_Trans'
 472            tex_list.append(_MainTex)
 473            tex_list.append(_ToonRamp)
 474            tex_list.append(_ShadowTex)
 475            tex_list.append(_ShadowRateToon)
 476            col_list.append(_Color)
 477            col_list.append(_ShadowColor)
 478            col_list.append(_RimColor)
 479            col_list.append(_OutlineColor)
 480            f_list.append(_Shininess)
 481            f_list.append(_OutlineWidth)
 482            f_list.append(_RimPower)
 483            f_list.append(_RimShift)
 484        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline_Tex':
 485            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline_Tex'
 486            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline_Tex'
 487            tex_list.append(_MainTex)
 488            tex_list.append(_ToonRamp)
 489            tex_list.append(_ShadowTex)
 490            tex_list.append(_ShadowRateToon)
 491            tex_list.append(_OutlineTex)
 492            tex_list.append(_OutlineToonRamp)
 493            col_list.append(_Color)
 494            col_list.append(_ShadowColor)
 495            col_list.append(_RimColor)
 496            col_list.append(_OutlineColor)
 497            f_list.append(_Shininess)
 498            f_list.append(_OutlineWidth)
 499            f_list.append(_RimPower)
 500            f_list.append(_RimShift)
 501        elif self.shader_type == 'CM3D2/Lighted':
 502            mate['shader1'] = 'CM3D2/Lighted'
 503            mate['shader2'] = 'CM3D2__Lighted'
 504            tex_list.append(_MainTex)
 505            col_list.append(_Color)
 506            col_list.append(_ShadowColor)
 507            f_list.append(_Shininess)
 508        elif self.shader_type == 'CM3D2/Lighted_Cutout_AtC':
 509            mate['shader1'] = 'CM3D2/Lighted_Cutout_AtC'
 510            mate['shader2'] = 'CM3D2__Lighted_Cutout_AtC'
 511            tex_list.append(_MainTex)
 512            col_list.append(_Color)
 513            col_list.append(_ShadowColor)
 514            f_list.append(_Shininess)
 515            f_list.append(_Cutoff)
 516        elif self.shader_type == 'CM3D2/Lighted_Trans':
 517            mate['shader1'] = 'CM3D2/Lighted_Trans'
 518            mate['shader2'] = 'CM3D2__Lighted_Trans'
 519            tex_list.append(_MainTex)
 520            col_list.append(_Color)
 521            col_list.append(_ShadowColor)
 522            f_list.append(_Shininess)
 523        elif self.shader_type == 'CM3D2/Toony_Lighted':
 524            mate['shader1'] = 'CM3D2/Toony_Lighted'
 525            mate['shader2'] = 'CM3D2__Toony_Lighted'
 526            tex_list.append(_MainTex)
 527            tex_list.append(_ToonRamp)
 528            tex_list.append(_ShadowTex)
 529            tex_list.append(_ShadowRateToon)
 530            col_list.append(_Color)
 531            col_list.append(_ShadowColor)
 532            col_list.append(_RimColor)
 533            f_list.append(_Shininess)
 534            f_list.append(_RimPower)
 535            f_list.append(_RimShift)
 536        elif self.shader_type == 'CM3D2/Toony_Lighted_Cutout_AtC':
 537            mate['shader1'] = 'CM3D2/Toony_Lighted_Cutout_AtC'
 538            mate['shader2'] = 'CM3D2__Toony_Lighted_Cutout_AtC'
 539            tex_list.append(_MainTex)
 540            tex_list.append(_ToonRamp)
 541            tex_list.append(_ShadowTex)
 542            tex_list.append(_ShadowRateToon)
 543            col_list.append(_Color)
 544            col_list.append(_ShadowColor)
 545            col_list.append(_RimColor)
 546            f_list.append(_Shininess)
 547            f_list.append(_RimPower)
 548            f_list.append(_RimShift)
 549            f_list.append(_Cutoff)
 550        elif self.shader_type == 'CM3D2/Toony_Lighted_Hair':
 551            mate['shader1'] = 'CM3D2/Toony_Lighted_Hair'
 552            mate['shader2'] = 'CM3D2__Toony_Lighted_Hair'
 553            tex_list.append(_MainTex)
 554            tex_list.append(_ToonRamp)
 555            tex_list.append(_ShadowTex)
 556            tex_list.append(_ShadowRateToon)
 557            tex_list.append(_HiTex)
 558            col_list.append(_Color)
 559            col_list.append(_ShadowColor)
 560            col_list.append(_RimColor)
 561            f_list.append(_Shininess)
 562            f_list.append(_RimPower)
 563            f_list.append(_RimShift)
 564            f_list.append(_HiRate)
 565            f_list.append(_HiPow)
 566        elif self.shader_type == 'Transparent/Diffuse':
 567            mate['shader1'] = 'Legacy Shaders/Transparent/Diffuse'
 568            mate['shader2'] = 'Legacy Shaders__Transparent__Diffuse'
 569            tex_list.append(_MainTex)
 570            col_list.append(_Color)
 571            # col_list.append(_ShadowColor)
 572            # col_list.append(_RimColor)
 573            # col_list.append(_OutlineColor)
 574            # f_list.append(_Shininess)
 575            # f_list.append(_OutlineWidth)
 576            # f_list.append(_RimPower)
 577            # f_list.append(_RimShift)
 578        elif self.shader_type == 'CM3D2_Debug/Debug_CM3D2_Normal2Color':
 579            mate['shader1'] = 'CM3D2_Debug/Debug_CM3D2_Normal2Color'
 580            mate['shader2'] = 'CM3D2_Debug__Debug_CM3D2_Normal2Color'
 581            col_list.append(_Color)
 582            col_list.append(_RimColor)
 583            col_list.append(_OutlineColor)
 584            col_list.append(("_SpecColor", (1, 1, 1, 1)))
 585            f_list.append(_Shininess)
 586            f_list.append(_OutlineWidth)
 587            f_list.append(_RimPower)
 588            f_list.append(_RimShift)
 589        
 590        texpath_dict = common.get_texpath_dict()
 591        slot_index = 0
 592        
 593        for data in tex_list:
 594            key = data[0]
 595            tex_name = data[1]
 596            cm3d2path = data[2]
 597            # prefsから初期値を取得
 598            tex_map = prefs.new_mate_tex_offset[:2] + prefs.new_mate_tex_scale[:2]
 599            tex = common.create_tex(context, mate, key, tex_name, cm3d2path, cm3d2path, tex_map, False, slot_index)
 600
 601            # tex探し
 602            if prefs.is_replace_cm3d2_tex:
 603                replaced = common.replace_cm3d2_tex(tex.image, texpath_dict=texpath_dict, reload_path=False)
 604                if compat.IS_LEGACY and replaced and key == '_MainTex':
 605                    for face in me.polygons:
 606                        if face.material_index == ob.active_material_index:
 607                            me.uv_textures.active.data[face.index].image = tex.image
 608            if compat.IS_LEGACY:
 609                slot_index += 1
 610
 611        for data in col_list:
 612            node = common.create_col(context, mate, data[0], data[1][:4], slot_index)
 613            if compat.IS_LEGACY:
 614                slot_index += 1
 615
 616        for data in f_list:
 617            node = common.create_float(context, mate, data[0], data[1], slot_index)
 618            if compat.IS_LEGACY:
 619                slot_index += 1
 620
 621        if compat.IS_LEGACY:
 622            common.decorate_material(mate, self.is_decorate, me, ob.active_material_index)
 623        else:
 624            cm3d2_data.align_nodes(mate)
 625            common.decorate_material(mate, self.is_decorate, me, ob.active_material_index)
 626
 627        return {'FINISHED'}
 628
 629
 630@compat.BlRegister()
 631class CNV_OT_new_cm3d2(bpy.types.Operator, new_mate_opr):
 632    bl_idname = 'material.new_cm3d2'
 633    bl_label = "CM3D2用マテリアルを新規作成"
 634    bl_description = "Blender-CM3D2-Converterで使用できるマテリアルを新規で作成します"
 635    bl_options = {'REGISTER', 'UNDO'}
 636
 637    shader_type = bpy.props.EnumProperty(items=cm3d2_data.Handler.create_shader_items(), name="種類", default='CM3D2/Toony_Lighted_Outline')
 638
 639
 640@compat.BlRegister()
 641class CNV_OT_new_com3d2(bpy.types.Operator, new_mate_opr):
 642    bl_idname = 'material.new_com3d2'
 643    bl_label = "COM3D2用マテリアルを新規作成"
 644    bl_description = "Blender-CM3D2-Converterで使用できるマテリアルを新規で作成します"
 645    bl_options = {'REGISTER', 'UNDO'}
 646
 647    shader_type = bpy.props.EnumProperty(items=cm3d2_data.Handler.create_comshader_items(), name="種類", default='CM3D2/Toony_Lighted_Outline')
 648
 649
 650@compat.BlRegister()
 651class CNV_OT_paste_material(bpy.types.Operator):
 652    bl_idname = 'material.paste_material'
 653    bl_label = "クリップボードからマテリアルを貼付け"
 654    bl_description = "クリップボード内のテキストからマテリアル情報を上書きします"
 655    bl_options = {'REGISTER', 'UNDO'}
 656
 657    is_decorate = bpy.props.BoolProperty(name="種類に合わせてマテリアルを装飾", default=False)
 658    is_replace_cm3d2_tex = bpy.props.BoolProperty(name="テクスチャを探す", default=False, description="CM3D2本体のインストールフォルダからtexファイルを探して開きます")
 659    is_create = bpy.props.BoolProperty(name="マテリアルの新規作成", default=False)
 660    override_name = bpy.props.BoolProperty(name="マテリアル名を上書きする", default=False)
 661    use_dialog = bpy.props.BoolProperty(name="上書き設定", default=True)
 662
 663    @classmethod
 664    def poll(cls, context):
 665        data = context.window_manager.clipboard
 666        if len(data) < 32:
 667            return False
 668
 669        # if not data.startswith('1000'):
 670        # 	return False
 671        if '\ntex\n\t' in data or '\ncol\n\t' in data or '\nf\n\t' in data:
 672            return True
 673
 674        # if not data.startswith('1000'):
 675        # 	return False
 676        # if '\n\t_MainTex\n' in data or '\n\t_Color\n' in data:
 677        # 	return True
 678        return False
 679
 680    def invoke(self, context, event):
 681        if self.use_dialog:
 682            return context.window_manager.invoke_props_dialog(self)
 683        return self.execute(context)
 684
 685    def draw(self, context):
 686        self.layout.prop(self, 'override_name')
 687        if compat.IS_LEGACY:
 688            self.layout.prop(self, 'is_decorate')
 689        prefs = common.preferences()
 690        self.layout.prop(prefs, 'is_replace_cm3d2_tex', icon='BORDERMOVE')
 691
 692    def execute(self, context):
 693        text = context.window_manager.clipboard
 694
 695        try:
 696            mat_data = cm3d2_data.MaterialHandler.parse_text(text)
 697        except Exception as e:
 698            # tb = sys.exc_info()[2]
 699            # e.with_traceback(tb)
 700            self.report(type={'ERROR'}, message='マテリアル情報の貼付けを中止します。' + str(e))
 701            return {'CANCELLED'}
 702
 703        mate_name = mat_data.name
 704        if self.is_create:
 705            if not context.material_slot:
 706                bpy.ops.object.material_slot_add()
 707            mate = context.blend_data.materials.new(mate_name)
 708            context.material_slot.material = mate
 709            common.setup_material(mate)
 710        else:
 711            mate = context.material
 712            if self.override_name:
 713                # シリアル番号が異なる場合は変更しない
 714                if common.remove_serial_number(mate_name) != common.remove_serial_number(mate.name):
 715                    mate.name = mate_name
 716
 717        prefs = common.preferences()
 718        if compat.IS_LEGACY:
 719            cm3d2_data.MaterialHandler.apply_to_old(context, mate, mat_data, prefs.is_replace_cm3d2_tex, self.is_decorate)
 720        else:
 721            cm3d2_data.MaterialHandler.apply_to(context, mate, mat_data, prefs.is_replace_cm3d2_tex)
 722
 723        self.report(type={'INFO'}, message="クリップボードからマテリアルを貼付けました")
 724        return {'FINISHED'}
 725
 726
 727@compat.BlRegister()
 728class CNV_OT_copy_material(bpy.types.Operator):
 729    bl_idname = 'material.copy_material'
 730    bl_label = "マテリアルをクリップボードにコピー"
 731    bl_description = "表示しているマテリアルをテキスト形式でクリップボードにコピーします"
 732    bl_options = {'REGISTER', 'UNDO'}
 733
 734    @classmethod
 735    def poll(cls, context):
 736        mate = getattr(context, 'material')
 737        if mate:
 738            return 'shader1' in mate and 'shader2' in mate
 739        return False
 740
 741    def execute(self, context):
 742        mate = context.material
 743        try:
 744            if compat.IS_LEGACY:
 745                mat_data = cm3d2_data.MaterialHandler.parse_mate_old(mate)
 746            else:
 747                mat_data = cm3d2_data.MaterialHandler.parse_mate(mate)
 748        except Exception as e:
 749            self.report(type={'ERROR'}, message="クリップボードへのコピーを中止します。:" + str(e))
 750            return {'CANCELLED'}
 751
 752        context.window_manager.clipboard = mat_data.to_text()
 753        self.report(type={'INFO'}, message="マテリアルテキストをクリップボードにコピーしました")
 754        return {'FINISHED'}
 755
 756
 757@compat.BlRegister()
 758class CNV_OT_decorate_material(bpy.types.Operator):
 759    bl_idname = 'material.decorate_material'
 760    bl_label = "マテリアルを装飾"
 761    bl_description = "スロット内のマテリアルを全て設定に合わせて装飾します"
 762    bl_options = {'REGISTER', 'UNDO'}
 763
 764    @classmethod
 765    def poll(cls, context):
 766        ob = context.active_object
 767        if not ob or ob.type != 'MESH':
 768            return False
 769        for slot in ob.material_slots:
 770            mate = slot.material
 771            if mate and 'shader1' in mate and 'shader2' in mate:
 772                return True
 773        return False
 774
 775    def execute(self, context):
 776        ob = context.active_object
 777        me = ob.data
 778
 779        for slot_index, slot in enumerate(ob.material_slots):
 780            mate = slot.material
 781            if mate and 'shader1' in mate and 'shader2' in mate:
 782                common.decorate_material(mate, True, me, slot_index)
 783
 784        return {'FINISHED'}
 785
 786
 787@compat.BlRegister()
 788class CNV_OT_quick_texture_show(bpy.types.Operator):
 789    bl_idname = 'material.quick_texture_show'
 790    bl_label = "このテクスチャを見る"
 791    bl_description = "このテクスチャを見る"
 792    bl_options = {'REGISTER'}
 793
 794    texture_name = bpy.props.StringProperty(name="テクスチャ名")
 795
 796    @classmethod
 797    def poll(cls, context):
 798        mate = context.material
 799        if mate:
 800            if 'shader1' in mate and 'shader2' in mate:
 801                return True
 802        return False
 803
 804    def execute(self, context):
 805        mate = context.material
 806        if hasattr(mate, 'texture_slots'):
 807            for index, slot in enumerate(mate.texture_slots):
 808                if not slot or not slot.texture:
 809                    continue
 810                if slot.texture.name == self.texture_name:
 811                    mate.active_texture_index = index
 812                    context.space_data.context = 'TEXTURE'
 813                    break
 814        else:
 815            # TODO テクスチャの表示検討
 816            pass
 817
 818        return {'FINISHED'}
 819
 820
 821@compat.BlRegister()
 822class CNV_OT_setup_material_expand(bpy.types.Operator):
 823    bl_idname = 'material.setup_mate_expand'
 824    bl_label = "マテリアルのセットアップ"
 825    bl_description = "マテリアルの各種フラグを初期化する"
 826    bl_options = {'REGISTER', 'UNDO'}
 827
 828    @classmethod
 829    def poll(cls, context):
 830        mate = context.material
 831        if mate:
 832            if 'shader1' in mate and 'shader2' in mate:
 833                return True
 834        return False
 835
 836    def execute(self, context):
 837        mate = context.material
 838        common.setup_material(mate)
 839
 840        return {'FINISHED'}
 841
 842
 843@compat.BlRegister()
 844class CNV_OT_material_prop_expand(bpy.types.Operator, common.NodeHandler):
 845    bl_idname = 'material.mateprop_expand'
 846    bl_label = "マテリアルプロパティの詳細情報"
 847    bl_description = "マテリアルプロパティの詳細情報の表示状態を切り替える"
 848    bl_options = {'REGISTER', 'UNDO'}
 849
 850    @classmethod
 851    def poll(cls, context):
 852        mate = context.material
 853        return mate and 'shader1' in mate and 'shader2' in mate
 854
 855    def execute(self, context):
 856        node = self.get_node(context)
 857        if node is None:
 858            return {'CANCELLED'}
 859        prev = node.get('CM3D2 Prop Expand', False)
 860        node['CM3D2 Prop Expand'] = not prev
 861
 862        return {'FINISHED'}
 863
 864
 865LAYOUT_FACTOR = 0.3
 866
 867
 868def menu_mateprop_tex(context, layout, node):
 869    base_name = common.remove_serial_number(node.name)
 870    prop_info = cm3d2_data.PROPS.get(base_name)
 871
 872    row = layout.row(align=True)
 873    row.label(text="", icon='BLANK1')
 874    box = row.box()
 875
 876    split = compat.layout_split(box, factor=LAYOUT_FACTOR)
 877    split.label(text="プロパティ タイプ:")
 878    row = split.row()
 879    row.label(text="テクスチャ", icon='TEXTURE')
 880
 881    # check_row = row.row(align=True)
 882    # sub_row = check_row.row()
 883    # split = compat.layout_split(box, factor=LAYOUT_FACTOR)
 884    # split.label(text="設定値名:")
 885    # split.prop(node, 'name', icon='SORTALPHA', text="")
 886
 887    img = node.image
 888    if img and img.source == 'FILE':
 889        row.operator('texture.reload_textures', text="", icon='FILE_REFRESH').tex_name = img.name
 890
 891        sub_box = box.box()
 892
 893        if '.png' in img.name[-8:].lower():
 894            sub_box.operator('texture.setup_image_name', text="拡張子を省略", icon='FILE')
 895
 896        # row = compat.layout_split(sub_box, factor=LAYOUT_FACTOR, align=True)
 897        # row.label(text="テクスチャ名:")
 898        # row.template_ID(node, 'image', open='image.open')
 899
 900        if 'cm3d2_path' in img:
 901            row = compat.layout_split(sub_box, factor=LAYOUT_FACTOR, align=True)
 902            row.label(text="テクスチャパス:")
 903            row.prop(img, '["cm3d2_path"]', text="")
 904        else:
 905            sub_box.operator('texture.set_cm3d2path', text="テクスチャパスを生成", icon='FILE').node_name = node.name
 906
 907        row = compat.layout_split(sub_box, factor=LAYOUT_FACTOR, align=True)
 908        row.label(text="実ファイルパス:")
 909        # TODO ファイル選択用オペレータを自作(.pngフィルタ)
 910        row.prop(img, 'filepath', text="")
 911
 912        # TODO node_nameの渡し方調査。
 913        if base_name in ['_ToonRamp', '_ShadowRateToon', '_OutlineToonRamp']:
 914            sub_box.menu('TEXTURE_MT_texture' + base_name, icon='NLA')
 915
 916        tex_map = node.texture_mapping
 917        split = compat.layout_split(sub_box, factor=LAYOUT_FACTOR, align=True)
 918        split.label(text="オフセット:")
 919        row = split.row(align=True)
 920        row.prop(tex_map, 'translation', index=0, text="x")
 921        row.prop(tex_map, 'translation', index=1, text="y")
 922        row.operator('texture.reset_offset', text="", icon='CANCEL').node_name = node.name
 923
 924        split = compat.layout_split(sub_box, factor=LAYOUT_FACTOR, align=True)
 925        split.label(text="スケール:")
 926        row = split.row(align=True)
 927        row.prop(tex_map, 'scale', index=0, text="x")
 928        row.prop(tex_map, 'scale', index=1, text="y")
 929        row.operator('texture.reset_scale', text="", icon='CANCEL').node_name = node.name
 930
 931        row = sub_box.row()
 932        col = row.column()
 933        if os.path.exists(img.filepath) is False:
 934            col.enabled = False
 935        col.operator('image.show_image', text="画像を表示", icon='ZOOM_IN').image_name = img.name
 936
 937        # else:
 938        # 	row.label(text="画像を表示", icon='ZOOM_IN')
 939
 940        if len(img.pixels):
 941            row.operator('image.quick_export_cm3d2_tex', text="texで保存", icon=compat.icon('FILE_FOLDER')).node_name = node.name
 942        else:
 943            row.operator('image.replace_cm3d2_tex', icon='BORDERMOVE').node_name = node.name
 944
 945    # TODO expand
 946    desc = prop_info.get('desc')
 947    if desc:
 948        sub_box = box.box()
 949        col = sub_box.column(align=True)
 950        col.label(text="解説", icon='TEXT')
 951        for line in desc:
 952            col.label(text=line)
 953
 954
 955def menu_mateprop_col(context, layout, node):
 956    base_name = common.remove_serial_number(node.name)
 957    prop_info = cm3d2_data.PROPS.get(base_name)
 958
 959    row = layout.row(align=True)
 960    row.label(text="", icon='BLANK1')
 961    box = row.box()
 962
 963    split = compat.layout_split(box, factor=LAYOUT_FACTOR)
 964    split.label(text="プロパティ タイプ:")
 965    row = split.row()
 966    row.label(text="色", icon='COLOR')
 967
 968    # check_row = row.row(align=True)
 969    # sub_row = check_row.row()
 970    # split = compat.layout_split(box, factor=LAYOUT_FACTOR)
 971    # split.label(text="設定値名:")
 972    # split.prop(node, 'name', icon='SORTALPHA', text="")
 973
 974    # sub_box = box.box()
 975    row = box.row(align=True)
 976    col = node.outputs[0]
 977    col_val = col.default_value
 978    if node.name in ['_ShadowColor', '_RimColor', '_OutlineColor']:
 979        row.operator('texture.auto_set_color_value', icon='AUTO', text="自動設定").node_name = node.name
 980    opr = row.operator('texture.set_color_value', text="", icon=compat.icon('MESH_CIRCLE'))
 981    opr.node_name, opr.color = node.name, [0, 0, 0, col_val[3]]
 982    opr = row.operator('texture.set_color_value', text="", icon=compat.icon('SHADING_SOLID'))
 983    opr.node_name, opr.color = node.name, [1, 1, 1, col_val[3]]
 984
 985    # 透過は_Colorのみ (TODO さらにTransシェーダの場合に限定)
 986    if node.name in ['_Color']:
 987        row = box.row(align=True)
 988        opr = row.operator('texture.set_color_value', text="", icon='TRIA_LEFT')
 989        opr.node_name, opr.color = node.name, col_val[:3] + (0,)
 990
 991        row.prop(col, 'default_value', index=3, icon='IMAGE_RGB_ALPHA', text="色の透明度", slider=True)
 992
 993        opr = row.operator('texture.set_color_value', text="", icon='TRIA_RIGHT')
 994        opr.node_name, opr.color = node.name, col_val[:3] + (1,)
 995
 996    # TODO expand
 997    desc = prop_info.get('desc')
 998    if desc:
 999        sub_box = box.box()
1000        col = sub_box.column(align=True)
1001        col.label(text="解説", icon='TEXT')
1002        for line in desc:
1003            col.label(text=line)
1004
1005
1006def menu_mateprop_f(context, layout, node):
1007    base_name = common.remove_serial_number(node.name)
1008    prop_info = cm3d2_data.PROPS.get(base_name)
1009
1010    # row = compat.layout_split(layout, factor=0.05)
1011    row = layout.row(align=True)
1012    row.label(text="", icon='BLANK1')
1013    box = row.box()
1014
1015    split = compat.layout_split(box, factor=LAYOUT_FACTOR)
1016    split.label(text="プロパティ タイプ:")
1017    row = split.row()
1018    row.label(text="値", icon='ARROW_LEFTRIGHT')
1019
1020    # check_row = row.row(align=True)
1021    # sub_row = check_row.row()
1022    # split = compat.layout_split(box, factor=LAYOUT_FACTOR)
1023    # split.label(text="設定値名:")
1024    # split.prop(node, 'name', icon='SORTALPHA', text="")
1025
1026    # sub_box = layout.box()
1027    # row = sub_box.row(align=True)
1028    # disable_slider = prop_info.get('disableSlider')
1029    # output = node.outputs[0]
1030    # if disable_slider:
1031    # 	row.label(output, 'default_value', icon='ARROW_LEFTRIGHT', text="値")
1032    # else:
1033    # 	row.prop(output, 'default_value', icon='ARROW_LEFTRIGHT', text="値")
1034
1035    # コンボメニュー
1036    # row.menu('TEXTURE_MT_context_texture_values_normal', icon='DOWNARROW_HLT', text="")
1037
1038    presets = prop_info.get('presets')
1039    if presets:
1040        # TODO 複数行
1041        row = box.row(align=True)
1042        for preset in presets:
1043            text = str(preset)
1044            opr = row.operator('texture.set_value', text=text)
1045            opr.value, opr.node_name = preset, node.name
1046
1047    preset_enums = prop_info.get('preset_enums')
1048    if preset_enums:
1049        for idx, preset in enumerate(preset_enums):
1050            if idx % 5 == 0:
1051                row = box.row(align=True)
1052            val = preset[0]
1053            opr = row.operator('texture.set_value', text=preset[1])
1054            opr.value, opr.node_name = val, node.name
1055
1056    if prop_info.get('dispExact'):
1057        split = compat.layout_split(box, factor=LAYOUT_FACTOR)
1058        split.label(text="正確な値: ")
1059        split.label(text="{0:f}".format(node.outputs[0].default_value))
1060
1061    # TODO expand
1062    desc = prop_info.get('desc')
1063    if desc:
1064        sub_box = box.box()
1065        col = sub_box.column(align=True)
1066        col.label(text="解説", icon='TEXT')
1067        for line in desc:
1068            col.label(text=line)
@compat.BlRegister(only_latest=True)
class MATERIAL_PT_cm3d2_properties(bpy_types.Panel):
124@compat.BlRegister(only_latest=True)
125class MATERIAL_PT_cm3d2_properties(bpy.types.Panel):
126    bl_space_type = 'PROPERTIES'
127    bl_region_type = 'WINDOW'
128    bl_context = 'material'
129    bl_label = 'CM3D2'
130    bl_idname = 'MATERIAL_PT_cm3d2_properties'
131
132    @classmethod
133    def poll(cls, context):
134        return True
135
136    def draw(self, context):
137        ob = context.active_object
138        # ModelVersionでCOM3D2のmodelか判断
139        model_ver = ob.get('ModelVersion')
140        is_com_mode = model_ver and model_ver >= 2000
141
142        mate = context.material
143        if not mate:
144            col = self.layout.column(align=True)
145            if is_com_mode:
146                col.operator('material.new_com3d2', icon_value=common.kiss_icon())
147            else:
148                col.operator('material.new_cm3d2', icon_value=common.kiss_icon())
149                col.operator('material.new_com3d2', icon='ERROR')
150            row = col.row(align=True)
151            row.operator('material.import_cm3d2_mate', icon='FILE_FOLDER', text="mateから")
152            opr = row.operator('material.paste_material', icon='PASTEDOWN', text="クリップボードから")
153            opr.is_decorate, opr.is_create, opr.use_dialog = True, True, False
154
155        else:
156            if 'shader1' in mate and 'shader2' in mate:
157                box = self.layout#.box()
158                # row = box.split(percentage=0.3)
159                #row = compat.layout_split(box, factor=0.5)
160                row = self.layout.column()
161                row.label(text="CM3D2用", icon_value=common.kiss_icon())
162                sub_row = row.row(align=True)
163                sub_row.operator('material.export_cm3d2_mate', icon='FILE_FOLDER', text="mateへ")
164                sub_row.operator('material.copy_material', icon='COPYDOWN', text="コピー")
165                opr = sub_row.operator('material.paste_material', icon='PASTEDOWN', text="貼付け")
166                opr.use_dialog = True
167                opr.is_create = False
168
169                shader1 = mate['shader1']
170                shader_prop = cm3d2_data.MaterialHandler.get_shader_prop_dynamic(mate) #cm3d2_data.Handler.get_shader_prop(shader1)
171                type_name = shader_prop.get('type_name', '不明')
172                icon = shader_prop.get('icon', 'ERROR')
173
174                row = compat.layout_split(box, factor=1 / 3)
175                row.label(text="種類:")
176                row.label(text=type_name, icon=icon)
177                box.prop(mate, 'name', icon='SORTALPHA', text="マテリアル名")
178                box.prop(mate, '["shader1"]', icon='MATERIAL', text="シェーダー1")
179                box.prop(mate, '["shader2"]', icon=compat.icon('SHADING_RENDERED'), text="シェーダー2")
180
181                # For LEGACY
182                # box.operator('material.decorate_material', icon=compat.icon('SHADING_TEXTURE'))
183                if 'CM3D2 Texture Expand' not in mate:
184                    box.operator('material.setup_mate_expand', text="フラグセットアップ")
185                    return
186
187                box = self.layout.box()
188                if mate['CM3D2 Texture Expand']:
189                    if mate.use_nodes is False:
190                        box.operator('material.setup_mate_expand', text="フラグセットアップ")
191                        return
192
193                    row = box.row()
194                    row.alignment = 'LEFT'
195                    op = row.operator('wm.context_set_int', icon='DOWNARROW_HLT', text="", emboss=False)
196                    op.data_path, op.value, op.relative = 'material["CM3D2 Texture Expand"]', 0, False
197                    row.label(text="マテリアルプロパティ", icon_value=common.kiss_icon())
198
199                    # ノード名はシリアル番号がついていない想定とする
200                    tex_list, col_list, f_list = [], [], []
201                    nodes = mate.node_tree.nodes
202                    for node_name in shader_prop['tex_list']:
203                        node = nodes.get(node_name)
204                        if node and node.type == 'TEX_IMAGE':
205                            tex_list.append(node)
206
207                    for node_name in shader_prop['col_list']:
208                        node = nodes.get(node_name)
209                        if node and node.type == 'RGB':
210                            col_list.append(node)
211
212                    for node_name in shader_prop['f_list']:
213                        node = nodes.get(node_name)
214                        if node and node.type == 'VALUE':
215                            f_list.append(node)
216
217                    for node in tex_list:
218                        tex = node.image
219                        if tex:
220                            name = common.remove_serial_number(tex.name).replace("_", "") + " "
221
222                            row = box.row(align=True)
223                            sub_row = compat.layout_split(row, factor=1 / 3, align=True)
224                            sub_row.label(text=node.label, icon_value=sub_row.icon(tex))
225                            if tex:
226                                sub_row.template_ID(node, 'image', open='image.open')
227
228                            expand = node.get('CM3D2 Prop Expand', False)
229                            if expand:
230                                row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
231                                menu_mateprop_tex(context, box, node)
232                            else:
233                                row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
234
235                    for node in col_list:
236                        row = box.row(align=True)
237                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
238                        sub_row.label(text=node.label, icon='COLOR')
239                        col = node.outputs[0]
240                        sub_row.prop(col, 'default_value', text="")
241
242                        expand = node.get('CM3D2 Prop Expand', False)
243                        if expand:
244                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
245                            menu_mateprop_col(context, box, node)
246                        else:
247                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
248
249                    for node in f_list:
250                        row = box.row(align=True)
251
252                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
253                        sub_row.label(text=node.label, icon='ARROW_LEFTRIGHT')
254
255                        f = node.outputs[0]
256                        sub_row.prop(f, 'default_value', icon='ARROW_LEFTRIGHT', text="値")
257
258                        expand = node.get('CM3D2 Prop Expand', False)
259                        if expand:
260                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
261                            menu_mateprop_f(context, box, node)
262                        else:
263                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
264
265                    if '_ALPHAPREMULTIPLY_ON' in mate.keys():
266                        row = box.row(align=True)
267                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
268                        sub_row.label(text="_ALPHAPREMULTIPLY_ON", icon='CHECKBOX_HLT')
269                        sub_row.prop(mate, '["_ALPHAPREMULTIPLY_ON"]', icon=compat.icon('SHADING_RENDERED'), text="Value", toggle=1)
270                        row.label(text="", icon='BLANK1')
271
272                    # if compat.IS_LEGACY:
273                    # 	box.operator('texture.sync_tex_color_ramps', icon='LINKED')
274                else:
275                    row = box.row()
276                    row.alignment = 'LEFT'
277                    op = row.operator('wm.context_set_int', icon='RIGHTARROW', text="", emboss=False)
278                    op.data_path, op.value, op.relative = 'material["CM3D2 Texture Expand"]', 1, False
279                    row.label(text="マテリアルプロパティ", icon_value=common.kiss_icon())
280                    # op = row.operator('wm.context_set_int', icon='RIGHTARROW', text="", emboss=False)
281
282            else:
283                if is_com_mode:
284                    self.layout.operator('material.new_com3d2', text="COM3D2用に変更", icon_value=common.kiss_icon())
285                else:
286                    self.layout.operator('material.new_cm3d2', text="CM3D2用に変更", icon_value=common.kiss_icon())
287                    self.layout.operator('material.new_com3d2', text="COM3D2用に変更", icon_value=common.kiss_icon())
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'material'
bl_label = 'CM3D2'
bl_idname = 'MATERIAL_PT_cm3d2_properties'
@classmethod
def poll(cls, context):
132    @classmethod
133    def poll(cls, context):
134        return True
def draw(self, context):
136    def draw(self, context):
137        ob = context.active_object
138        # ModelVersionでCOM3D2のmodelか判断
139        model_ver = ob.get('ModelVersion')
140        is_com_mode = model_ver and model_ver >= 2000
141
142        mate = context.material
143        if not mate:
144            col = self.layout.column(align=True)
145            if is_com_mode:
146                col.operator('material.new_com3d2', icon_value=common.kiss_icon())
147            else:
148                col.operator('material.new_cm3d2', icon_value=common.kiss_icon())
149                col.operator('material.new_com3d2', icon='ERROR')
150            row = col.row(align=True)
151            row.operator('material.import_cm3d2_mate', icon='FILE_FOLDER', text="mateから")
152            opr = row.operator('material.paste_material', icon='PASTEDOWN', text="クリップボードから")
153            opr.is_decorate, opr.is_create, opr.use_dialog = True, True, False
154
155        else:
156            if 'shader1' in mate and 'shader2' in mate:
157                box = self.layout#.box()
158                # row = box.split(percentage=0.3)
159                #row = compat.layout_split(box, factor=0.5)
160                row = self.layout.column()
161                row.label(text="CM3D2用", icon_value=common.kiss_icon())
162                sub_row = row.row(align=True)
163                sub_row.operator('material.export_cm3d2_mate', icon='FILE_FOLDER', text="mateへ")
164                sub_row.operator('material.copy_material', icon='COPYDOWN', text="コピー")
165                opr = sub_row.operator('material.paste_material', icon='PASTEDOWN', text="貼付け")
166                opr.use_dialog = True
167                opr.is_create = False
168
169                shader1 = mate['shader1']
170                shader_prop = cm3d2_data.MaterialHandler.get_shader_prop_dynamic(mate) #cm3d2_data.Handler.get_shader_prop(shader1)
171                type_name = shader_prop.get('type_name', '不明')
172                icon = shader_prop.get('icon', 'ERROR')
173
174                row = compat.layout_split(box, factor=1 / 3)
175                row.label(text="種類:")
176                row.label(text=type_name, icon=icon)
177                box.prop(mate, 'name', icon='SORTALPHA', text="マテリアル名")
178                box.prop(mate, '["shader1"]', icon='MATERIAL', text="シェーダー1")
179                box.prop(mate, '["shader2"]', icon=compat.icon('SHADING_RENDERED'), text="シェーダー2")
180
181                # For LEGACY
182                # box.operator('material.decorate_material', icon=compat.icon('SHADING_TEXTURE'))
183                if 'CM3D2 Texture Expand' not in mate:
184                    box.operator('material.setup_mate_expand', text="フラグセットアップ")
185                    return
186
187                box = self.layout.box()
188                if mate['CM3D2 Texture Expand']:
189                    if mate.use_nodes is False:
190                        box.operator('material.setup_mate_expand', text="フラグセットアップ")
191                        return
192
193                    row = box.row()
194                    row.alignment = 'LEFT'
195                    op = row.operator('wm.context_set_int', icon='DOWNARROW_HLT', text="", emboss=False)
196                    op.data_path, op.value, op.relative = 'material["CM3D2 Texture Expand"]', 0, False
197                    row.label(text="マテリアルプロパティ", icon_value=common.kiss_icon())
198
199                    # ノード名はシリアル番号がついていない想定とする
200                    tex_list, col_list, f_list = [], [], []
201                    nodes = mate.node_tree.nodes
202                    for node_name in shader_prop['tex_list']:
203                        node = nodes.get(node_name)
204                        if node and node.type == 'TEX_IMAGE':
205                            tex_list.append(node)
206
207                    for node_name in shader_prop['col_list']:
208                        node = nodes.get(node_name)
209                        if node and node.type == 'RGB':
210                            col_list.append(node)
211
212                    for node_name in shader_prop['f_list']:
213                        node = nodes.get(node_name)
214                        if node and node.type == 'VALUE':
215                            f_list.append(node)
216
217                    for node in tex_list:
218                        tex = node.image
219                        if tex:
220                            name = common.remove_serial_number(tex.name).replace("_", "") + " "
221
222                            row = box.row(align=True)
223                            sub_row = compat.layout_split(row, factor=1 / 3, align=True)
224                            sub_row.label(text=node.label, icon_value=sub_row.icon(tex))
225                            if tex:
226                                sub_row.template_ID(node, 'image', open='image.open')
227
228                            expand = node.get('CM3D2 Prop Expand', False)
229                            if expand:
230                                row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
231                                menu_mateprop_tex(context, box, node)
232                            else:
233                                row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
234
235                    for node in col_list:
236                        row = box.row(align=True)
237                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
238                        sub_row.label(text=node.label, icon='COLOR')
239                        col = node.outputs[0]
240                        sub_row.prop(col, 'default_value', text="")
241
242                        expand = node.get('CM3D2 Prop Expand', False)
243                        if expand:
244                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
245                            menu_mateprop_col(context, box, node)
246                        else:
247                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
248
249                    for node in f_list:
250                        row = box.row(align=True)
251
252                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
253                        sub_row.label(text=node.label, icon='ARROW_LEFTRIGHT')
254
255                        f = node.outputs[0]
256                        sub_row.prop(f, 'default_value', icon='ARROW_LEFTRIGHT', text="値")
257
258                        expand = node.get('CM3D2 Prop Expand', False)
259                        if expand:
260                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_DOWN', text="", emboss=False).node_name = node.name
261                            menu_mateprop_f(context, box, node)
262                        else:
263                            row.operator(CNV_OT_material_prop_expand.bl_idname, icon='TRIA_LEFT', text="", emboss=False).node_name = node.name
264
265                    if '_ALPHAPREMULTIPLY_ON' in mate.keys():
266                        row = box.row(align=True)
267                        sub_row = compat.layout_split(row, factor=1 / 3, align=True)
268                        sub_row.label(text="_ALPHAPREMULTIPLY_ON", icon='CHECKBOX_HLT')
269                        sub_row.prop(mate, '["_ALPHAPREMULTIPLY_ON"]', icon=compat.icon('SHADING_RENDERED'), text="Value", toggle=1)
270                        row.label(text="", icon='BLANK1')
271
272                    # if compat.IS_LEGACY:
273                    # 	box.operator('texture.sync_tex_color_ramps', icon='LINKED')
274                else:
275                    row = box.row()
276                    row.alignment = 'LEFT'
277                    op = row.operator('wm.context_set_int', icon='RIGHTARROW', text="", emboss=False)
278                    op.data_path, op.value, op.relative = 'material["CM3D2 Texture Expand"]', 1, False
279                    row.label(text="マテリアルプロパティ", icon_value=common.kiss_icon())
280                    # op = row.operator('wm.context_set_int', icon='RIGHTARROW', text="", emboss=False)
281
282            else:
283                if is_com_mode:
284                    self.layout.operator('material.new_com3d2', text="COM3D2用に変更", icon_value=common.kiss_icon())
285                else:
286                    self.layout.operator('material.new_cm3d2', text="CM3D2用に変更", icon_value=common.kiss_icon())
287                    self.layout.operator('material.new_com3d2', text="COM3D2用に変更", icon_value=common.kiss_icon())
bl_rna = <bpy_struct, Struct("MATERIAL_PT_cm3d2_properties")>
Inherited Members
bpy_types._GenericUI
is_extended
append
prepend
remove
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
class new_mate_opr:
290class new_mate_opr():
291    is_decorate = bpy.props.BoolProperty(name="種類に合わせてマテリアルを装飾", default=True)
292    # is_replace_cm3d2_tex = bpy.props.BoolProperty(name="テクスチャを探す", default=False, description="CM3D2本体のインストールフォルダからtexファイルを探して開きます")
293
294    @classmethod
295    def poll(cls, context):
296        return True
297
298    def invoke(self, context, event):
299        return context.window_manager.invoke_props_dialog(self)
300
301    def draw(self, context):
302        self.layout.separator()
303        self.layout.prop(self, 'shader_type', icon='MATERIAL')
304        if compat.IS_LEGACY:
305            self.layout.prop(self, 'is_decorate', icon=compat.icon('SHADING_TEXTURE'))
306        prefs = common.preferences()
307
308        self.layout.prop(prefs, 'is_replace_cm3d2_tex', icon='BORDERMOVE')
309
310    def execute(self, context):
311        ob = context.active_object
312        me = ob.data
313        ob_names = common.remove_serial_number(ob.name).split('.')
314        ob_name = ob_names[0]
315
316        if context.material:
317            mate = context.material
318            if compat.IS_LEGACY:
319                for index, slot in enumerate(mate.texture_slots):
320                    mate.texture_slots.clear(index)
321            else:
322                if mate.use_nodes:
323                    cm3d2_data.clear_nodes(mate.node_tree.nodes)
324
325        else:
326            if not context.material_slot:
327                bpy.ops.object.material_slot_add()
328            mate = context.blend_data.materials.new(ob_name)
329        common.setup_material(mate)
330
331        context.material_slot.material = mate
332        tex_list, col_list, f_list = [], [], []
333
334        base_path = common.BASE_PATH_TEX
335        prefs = common.preferences()
336
337        _MainTex = ("_MainTex", ob_name, base_path + ob_name + ".png")
338        _ToonRamp = ("_ToonRamp", prefs.new_mate_toonramp_name, prefs.new_mate_toonramp_path)
339        _ShadowTex = ("_ShadowTex", ob_name + "_shadow", base_path + ob_name + "_shadow.png")
340        _ShadowRateToon = ("_ShadowRateToon", prefs.new_mate_shadowratetoon_name, prefs.new_mate_shadowratetoon_path)
341        _HiTex = ("_HiTex", ob_name + "_s", base_path + ob_name + "_s.png")
342        _OutlineTex = ("_OutlineTex", ob_name + "_line", base_path + ob_name + "_line.png")
343        _OutlineToonRamp = ("_OutlineToonRamp", prefs.new_mate_linetoonramp_name, prefs.new_mate_linetoonramp_path)
344
345        _Color = ("_Color", prefs.new_mate_color)
346        _ShadowColor = ("_ShadowColor", prefs.new_mate_shadowcolor)
347        _RimColor = ("_RimColor", prefs.new_mate_rimcolor)
348        _OutlineColor = ("_OutlineColor", prefs.new_mate_outlinecolor)
349
350        _Shininess = ("_Shininess", prefs.new_mate_shininess)
351        _OutlineWidth = ("_OutlineWidth", prefs.new_mate_outlinewidth)
352        _RimPower = ("_RimPower", prefs.new_mate_rimpower)
353        _RimShift = ("_RimShift", prefs.new_mate_rimshift)
354        _HiRate = ("_HiRate", prefs.new_mate_hirate)
355        _HiPow = ("_HiPow", prefs.new_mate_hipow)
356        _Cutoff = ("_Cutoff", prefs.new_mate_cutoff)
357        _ZTest = ("_ZTest", prefs.new_mate_ztest)
358        _ZTest2 = ("_ZTest2", prefs.new_mate_ztest2)
359        _ZTest2Alpha = ("_ZTest2Alpha", prefs.new_mate_ztest2alpha)
360
361        if False:
362            pass
363        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline':
364            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline'
365            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline'
366            tex_list.append(_MainTex)
367            tex_list.append(_ToonRamp)
368            tex_list.append(_ShadowTex)
369            tex_list.append(_ShadowRateToon)
370            col_list.append(_Color)
371            col_list.append(_ShadowColor)
372            col_list.append(_RimColor)
373            col_list.append(_OutlineColor)
374            f_list.append(_Shininess)
375            f_list.append(_OutlineWidth)
376            f_list.append(_RimPower)
377            f_list.append(_RimShift)
378        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans':
379            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans'
380            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans'
381            tex_list.append(_MainTex)
382            tex_list.append(_ToonRamp)
383            tex_list.append(_ShadowTex)
384            tex_list.append(_ShadowRateToon)
385            col_list.append(_Color)
386            col_list.append(_ShadowColor)
387            col_list.append(_RimColor)
388            f_list.append(_Shininess)
389            f_list.append(_Cutoff)
390            f_list.append(_RimPower)
391            f_list.append(_RimShift)
392        elif self.shader_type == 'CM3D2/Toony_Lighted_Hair_Outline':
393            mate['shader1'] = 'CM3D2/Toony_Lighted_Hair_Outline'
394            mate['shader2'] = 'CM3D2__Toony_Lighted_Hair_Outline'
395            tex_list.append(_MainTex)
396            tex_list.append(_ToonRamp)
397            tex_list.append(_ShadowTex)
398            tex_list.append(_ShadowRateToon)
399            tex_list.append(_HiTex)
400            col_list.append(_Color)
401            col_list.append(_ShadowColor)
402            col_list.append(_RimColor)
403            col_list.append(_OutlineColor)
404            f_list.append(_Shininess)
405            f_list.append(_OutlineWidth)
406            f_list.append(_RimPower)
407            f_list.append(_RimShift)
408            f_list.append(_HiRate)
409            f_list.append(_HiPow)
410        elif self.shader_type == 'CM3D2/Mosaic':
411            mate['shader1'] = 'CM3D2/Mosaic'
412            mate['shader2'] = 'CM3D2__Mosaic'
413            tex_list.append(("_RenderTex", ""))
414            f_list.append(("_FloatValue1", 30))
415        elif self.shader_type == 'Unlit/Texture':
416            mate['shader1'] = 'Unlit/Texture'
417            mate['shader2'] = 'Unlit__Texture'
418            tex_list.append(_MainTex)
419            # col_list.append(_Color)
420        elif self.shader_type == 'Unlit/Transparent':
421            mate['shader1'] = 'Unlit/Transparent'
422            mate['shader2'] = 'Unlit__Transparent'
423            tex_list.append(_MainTex)
424            # col_list.append(_Color)
425            # col_list.append(_ShadowColor)
426            # col_list.append(_RimColor)
427            # f_list.append(_Shininess)
428            # f_list.append(_RimPower)
429            # f_list.append(_RimShift)
430        elif self.shader_type == 'CM3D2/Man':
431            mate['shader1'] = 'CM3D2/Man'
432            mate['shader2'] = 'CM3D2__Man'
433            col_list.append(_Color)
434            f_list.append(("_FloatValue2", 0.5))
435            f_list.append(("_FloatValue3", 1))
436        elif self.shader_type == 'Diffuse':
437            mate['shader1'] = 'Legacy Shaders/Diffuse'
438            mate['shader2'] = 'Legacy Shaders__Diffuse'
439            tex_list.append(_MainTex)
440            col_list.append(_Color)
441        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans_NoZ':
442            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans_NoZ'
443            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans_NoZ'
444            tex_list.append(_MainTex)
445            tex_list.append(_ToonRamp)
446            tex_list.append(_ShadowTex)
447            tex_list.append(_ShadowRateToon)
448            col_list.append(_Color)
449            col_list.append(_ShadowColor)
450            col_list.append(_RimColor)
451            f_list.append(_Shininess)
452            f_list.append(_RimPower)
453            f_list.append(_RimShift)
454        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans_NoZTest':
455            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans_NoZTest'
456            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans_NoZTest'
457            tex_list.append(_MainTex)
458            tex_list.append(_ToonRamp)
459            tex_list.append(_ShadowTex)
460            tex_list.append(_ShadowRateToon)
461            col_list.append(_Color)
462            col_list.append(_ShadowColor)
463            col_list.append(_RimColor)
464            f_list.append(_Shininess)
465            f_list.append(_RimPower)
466            f_list.append(_RimShift)
467            f_list.append(_ZTest)
468            f_list.append(_ZTest2)
469            f_list.append(_ZTest2Alpha)
470        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline_Trans':
471            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline_Trans'
472            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline_Trans'
473            tex_list.append(_MainTex)
474            tex_list.append(_ToonRamp)
475            tex_list.append(_ShadowTex)
476            tex_list.append(_ShadowRateToon)
477            col_list.append(_Color)
478            col_list.append(_ShadowColor)
479            col_list.append(_RimColor)
480            col_list.append(_OutlineColor)
481            f_list.append(_Shininess)
482            f_list.append(_OutlineWidth)
483            f_list.append(_RimPower)
484            f_list.append(_RimShift)
485        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline_Tex':
486            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline_Tex'
487            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline_Tex'
488            tex_list.append(_MainTex)
489            tex_list.append(_ToonRamp)
490            tex_list.append(_ShadowTex)
491            tex_list.append(_ShadowRateToon)
492            tex_list.append(_OutlineTex)
493            tex_list.append(_OutlineToonRamp)
494            col_list.append(_Color)
495            col_list.append(_ShadowColor)
496            col_list.append(_RimColor)
497            col_list.append(_OutlineColor)
498            f_list.append(_Shininess)
499            f_list.append(_OutlineWidth)
500            f_list.append(_RimPower)
501            f_list.append(_RimShift)
502        elif self.shader_type == 'CM3D2/Lighted':
503            mate['shader1'] = 'CM3D2/Lighted'
504            mate['shader2'] = 'CM3D2__Lighted'
505            tex_list.append(_MainTex)
506            col_list.append(_Color)
507            col_list.append(_ShadowColor)
508            f_list.append(_Shininess)
509        elif self.shader_type == 'CM3D2/Lighted_Cutout_AtC':
510            mate['shader1'] = 'CM3D2/Lighted_Cutout_AtC'
511            mate['shader2'] = 'CM3D2__Lighted_Cutout_AtC'
512            tex_list.append(_MainTex)
513            col_list.append(_Color)
514            col_list.append(_ShadowColor)
515            f_list.append(_Shininess)
516            f_list.append(_Cutoff)
517        elif self.shader_type == 'CM3D2/Lighted_Trans':
518            mate['shader1'] = 'CM3D2/Lighted_Trans'
519            mate['shader2'] = 'CM3D2__Lighted_Trans'
520            tex_list.append(_MainTex)
521            col_list.append(_Color)
522            col_list.append(_ShadowColor)
523            f_list.append(_Shininess)
524        elif self.shader_type == 'CM3D2/Toony_Lighted':
525            mate['shader1'] = 'CM3D2/Toony_Lighted'
526            mate['shader2'] = 'CM3D2__Toony_Lighted'
527            tex_list.append(_MainTex)
528            tex_list.append(_ToonRamp)
529            tex_list.append(_ShadowTex)
530            tex_list.append(_ShadowRateToon)
531            col_list.append(_Color)
532            col_list.append(_ShadowColor)
533            col_list.append(_RimColor)
534            f_list.append(_Shininess)
535            f_list.append(_RimPower)
536            f_list.append(_RimShift)
537        elif self.shader_type == 'CM3D2/Toony_Lighted_Cutout_AtC':
538            mate['shader1'] = 'CM3D2/Toony_Lighted_Cutout_AtC'
539            mate['shader2'] = 'CM3D2__Toony_Lighted_Cutout_AtC'
540            tex_list.append(_MainTex)
541            tex_list.append(_ToonRamp)
542            tex_list.append(_ShadowTex)
543            tex_list.append(_ShadowRateToon)
544            col_list.append(_Color)
545            col_list.append(_ShadowColor)
546            col_list.append(_RimColor)
547            f_list.append(_Shininess)
548            f_list.append(_RimPower)
549            f_list.append(_RimShift)
550            f_list.append(_Cutoff)
551        elif self.shader_type == 'CM3D2/Toony_Lighted_Hair':
552            mate['shader1'] = 'CM3D2/Toony_Lighted_Hair'
553            mate['shader2'] = 'CM3D2__Toony_Lighted_Hair'
554            tex_list.append(_MainTex)
555            tex_list.append(_ToonRamp)
556            tex_list.append(_ShadowTex)
557            tex_list.append(_ShadowRateToon)
558            tex_list.append(_HiTex)
559            col_list.append(_Color)
560            col_list.append(_ShadowColor)
561            col_list.append(_RimColor)
562            f_list.append(_Shininess)
563            f_list.append(_RimPower)
564            f_list.append(_RimShift)
565            f_list.append(_HiRate)
566            f_list.append(_HiPow)
567        elif self.shader_type == 'Transparent/Diffuse':
568            mate['shader1'] = 'Legacy Shaders/Transparent/Diffuse'
569            mate['shader2'] = 'Legacy Shaders__Transparent__Diffuse'
570            tex_list.append(_MainTex)
571            col_list.append(_Color)
572            # col_list.append(_ShadowColor)
573            # col_list.append(_RimColor)
574            # col_list.append(_OutlineColor)
575            # f_list.append(_Shininess)
576            # f_list.append(_OutlineWidth)
577            # f_list.append(_RimPower)
578            # f_list.append(_RimShift)
579        elif self.shader_type == 'CM3D2_Debug/Debug_CM3D2_Normal2Color':
580            mate['shader1'] = 'CM3D2_Debug/Debug_CM3D2_Normal2Color'
581            mate['shader2'] = 'CM3D2_Debug__Debug_CM3D2_Normal2Color'
582            col_list.append(_Color)
583            col_list.append(_RimColor)
584            col_list.append(_OutlineColor)
585            col_list.append(("_SpecColor", (1, 1, 1, 1)))
586            f_list.append(_Shininess)
587            f_list.append(_OutlineWidth)
588            f_list.append(_RimPower)
589            f_list.append(_RimShift)
590        
591        texpath_dict = common.get_texpath_dict()
592        slot_index = 0
593        
594        for data in tex_list:
595            key = data[0]
596            tex_name = data[1]
597            cm3d2path = data[2]
598            # prefsから初期値を取得
599            tex_map = prefs.new_mate_tex_offset[:2] + prefs.new_mate_tex_scale[:2]
600            tex = common.create_tex(context, mate, key, tex_name, cm3d2path, cm3d2path, tex_map, False, slot_index)
601
602            # tex探し
603            if prefs.is_replace_cm3d2_tex:
604                replaced = common.replace_cm3d2_tex(tex.image, texpath_dict=texpath_dict, reload_path=False)
605                if compat.IS_LEGACY and replaced and key == '_MainTex':
606                    for face in me.polygons:
607                        if face.material_index == ob.active_material_index:
608                            me.uv_textures.active.data[face.index].image = tex.image
609            if compat.IS_LEGACY:
610                slot_index += 1
611
612        for data in col_list:
613            node = common.create_col(context, mate, data[0], data[1][:4], slot_index)
614            if compat.IS_LEGACY:
615                slot_index += 1
616
617        for data in f_list:
618            node = common.create_float(context, mate, data[0], data[1], slot_index)
619            if compat.IS_LEGACY:
620                slot_index += 1
621
622        if compat.IS_LEGACY:
623            common.decorate_material(mate, self.is_decorate, me, ob.active_material_index)
624        else:
625            cm3d2_data.align_nodes(mate)
626            common.decorate_material(mate, self.is_decorate, me, ob.active_material_index)
627
628        return {'FINISHED'}
is_decorate = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '種類に合わせてマテリアルを装飾', 'default': True, 'attr': 'is_decorate'}>
@classmethod
def poll(cls, context):
294    @classmethod
295    def poll(cls, context):
296        return True
def invoke(self, context, event):
298    def invoke(self, context, event):
299        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
301    def draw(self, context):
302        self.layout.separator()
303        self.layout.prop(self, 'shader_type', icon='MATERIAL')
304        if compat.IS_LEGACY:
305            self.layout.prop(self, 'is_decorate', icon=compat.icon('SHADING_TEXTURE'))
306        prefs = common.preferences()
307
308        self.layout.prop(prefs, 'is_replace_cm3d2_tex', icon='BORDERMOVE')
def execute(self, context):
310    def execute(self, context):
311        ob = context.active_object
312        me = ob.data
313        ob_names = common.remove_serial_number(ob.name).split('.')
314        ob_name = ob_names[0]
315
316        if context.material:
317            mate = context.material
318            if compat.IS_LEGACY:
319                for index, slot in enumerate(mate.texture_slots):
320                    mate.texture_slots.clear(index)
321            else:
322                if mate.use_nodes:
323                    cm3d2_data.clear_nodes(mate.node_tree.nodes)
324
325        else:
326            if not context.material_slot:
327                bpy.ops.object.material_slot_add()
328            mate = context.blend_data.materials.new(ob_name)
329        common.setup_material(mate)
330
331        context.material_slot.material = mate
332        tex_list, col_list, f_list = [], [], []
333
334        base_path = common.BASE_PATH_TEX
335        prefs = common.preferences()
336
337        _MainTex = ("_MainTex", ob_name, base_path + ob_name + ".png")
338        _ToonRamp = ("_ToonRamp", prefs.new_mate_toonramp_name, prefs.new_mate_toonramp_path)
339        _ShadowTex = ("_ShadowTex", ob_name + "_shadow", base_path + ob_name + "_shadow.png")
340        _ShadowRateToon = ("_ShadowRateToon", prefs.new_mate_shadowratetoon_name, prefs.new_mate_shadowratetoon_path)
341        _HiTex = ("_HiTex", ob_name + "_s", base_path + ob_name + "_s.png")
342        _OutlineTex = ("_OutlineTex", ob_name + "_line", base_path + ob_name + "_line.png")
343        _OutlineToonRamp = ("_OutlineToonRamp", prefs.new_mate_linetoonramp_name, prefs.new_mate_linetoonramp_path)
344
345        _Color = ("_Color", prefs.new_mate_color)
346        _ShadowColor = ("_ShadowColor", prefs.new_mate_shadowcolor)
347        _RimColor = ("_RimColor", prefs.new_mate_rimcolor)
348        _OutlineColor = ("_OutlineColor", prefs.new_mate_outlinecolor)
349
350        _Shininess = ("_Shininess", prefs.new_mate_shininess)
351        _OutlineWidth = ("_OutlineWidth", prefs.new_mate_outlinewidth)
352        _RimPower = ("_RimPower", prefs.new_mate_rimpower)
353        _RimShift = ("_RimShift", prefs.new_mate_rimshift)
354        _HiRate = ("_HiRate", prefs.new_mate_hirate)
355        _HiPow = ("_HiPow", prefs.new_mate_hipow)
356        _Cutoff = ("_Cutoff", prefs.new_mate_cutoff)
357        _ZTest = ("_ZTest", prefs.new_mate_ztest)
358        _ZTest2 = ("_ZTest2", prefs.new_mate_ztest2)
359        _ZTest2Alpha = ("_ZTest2Alpha", prefs.new_mate_ztest2alpha)
360
361        if False:
362            pass
363        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline':
364            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline'
365            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline'
366            tex_list.append(_MainTex)
367            tex_list.append(_ToonRamp)
368            tex_list.append(_ShadowTex)
369            tex_list.append(_ShadowRateToon)
370            col_list.append(_Color)
371            col_list.append(_ShadowColor)
372            col_list.append(_RimColor)
373            col_list.append(_OutlineColor)
374            f_list.append(_Shininess)
375            f_list.append(_OutlineWidth)
376            f_list.append(_RimPower)
377            f_list.append(_RimShift)
378        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans':
379            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans'
380            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans'
381            tex_list.append(_MainTex)
382            tex_list.append(_ToonRamp)
383            tex_list.append(_ShadowTex)
384            tex_list.append(_ShadowRateToon)
385            col_list.append(_Color)
386            col_list.append(_ShadowColor)
387            col_list.append(_RimColor)
388            f_list.append(_Shininess)
389            f_list.append(_Cutoff)
390            f_list.append(_RimPower)
391            f_list.append(_RimShift)
392        elif self.shader_type == 'CM3D2/Toony_Lighted_Hair_Outline':
393            mate['shader1'] = 'CM3D2/Toony_Lighted_Hair_Outline'
394            mate['shader2'] = 'CM3D2__Toony_Lighted_Hair_Outline'
395            tex_list.append(_MainTex)
396            tex_list.append(_ToonRamp)
397            tex_list.append(_ShadowTex)
398            tex_list.append(_ShadowRateToon)
399            tex_list.append(_HiTex)
400            col_list.append(_Color)
401            col_list.append(_ShadowColor)
402            col_list.append(_RimColor)
403            col_list.append(_OutlineColor)
404            f_list.append(_Shininess)
405            f_list.append(_OutlineWidth)
406            f_list.append(_RimPower)
407            f_list.append(_RimShift)
408            f_list.append(_HiRate)
409            f_list.append(_HiPow)
410        elif self.shader_type == 'CM3D2/Mosaic':
411            mate['shader1'] = 'CM3D2/Mosaic'
412            mate['shader2'] = 'CM3D2__Mosaic'
413            tex_list.append(("_RenderTex", ""))
414            f_list.append(("_FloatValue1", 30))
415        elif self.shader_type == 'Unlit/Texture':
416            mate['shader1'] = 'Unlit/Texture'
417            mate['shader2'] = 'Unlit__Texture'
418            tex_list.append(_MainTex)
419            # col_list.append(_Color)
420        elif self.shader_type == 'Unlit/Transparent':
421            mate['shader1'] = 'Unlit/Transparent'
422            mate['shader2'] = 'Unlit__Transparent'
423            tex_list.append(_MainTex)
424            # col_list.append(_Color)
425            # col_list.append(_ShadowColor)
426            # col_list.append(_RimColor)
427            # f_list.append(_Shininess)
428            # f_list.append(_RimPower)
429            # f_list.append(_RimShift)
430        elif self.shader_type == 'CM3D2/Man':
431            mate['shader1'] = 'CM3D2/Man'
432            mate['shader2'] = 'CM3D2__Man'
433            col_list.append(_Color)
434            f_list.append(("_FloatValue2", 0.5))
435            f_list.append(("_FloatValue3", 1))
436        elif self.shader_type == 'Diffuse':
437            mate['shader1'] = 'Legacy Shaders/Diffuse'
438            mate['shader2'] = 'Legacy Shaders__Diffuse'
439            tex_list.append(_MainTex)
440            col_list.append(_Color)
441        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans_NoZ':
442            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans_NoZ'
443            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans_NoZ'
444            tex_list.append(_MainTex)
445            tex_list.append(_ToonRamp)
446            tex_list.append(_ShadowTex)
447            tex_list.append(_ShadowRateToon)
448            col_list.append(_Color)
449            col_list.append(_ShadowColor)
450            col_list.append(_RimColor)
451            f_list.append(_Shininess)
452            f_list.append(_RimPower)
453            f_list.append(_RimShift)
454        elif self.shader_type == 'CM3D2/Toony_Lighted_Trans_NoZTest':
455            mate['shader1'] = 'CM3D2/Toony_Lighted_Trans_NoZTest'
456            mate['shader2'] = 'CM3D2__Toony_Lighted_Trans_NoZTest'
457            tex_list.append(_MainTex)
458            tex_list.append(_ToonRamp)
459            tex_list.append(_ShadowTex)
460            tex_list.append(_ShadowRateToon)
461            col_list.append(_Color)
462            col_list.append(_ShadowColor)
463            col_list.append(_RimColor)
464            f_list.append(_Shininess)
465            f_list.append(_RimPower)
466            f_list.append(_RimShift)
467            f_list.append(_ZTest)
468            f_list.append(_ZTest2)
469            f_list.append(_ZTest2Alpha)
470        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline_Trans':
471            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline_Trans'
472            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline_Trans'
473            tex_list.append(_MainTex)
474            tex_list.append(_ToonRamp)
475            tex_list.append(_ShadowTex)
476            tex_list.append(_ShadowRateToon)
477            col_list.append(_Color)
478            col_list.append(_ShadowColor)
479            col_list.append(_RimColor)
480            col_list.append(_OutlineColor)
481            f_list.append(_Shininess)
482            f_list.append(_OutlineWidth)
483            f_list.append(_RimPower)
484            f_list.append(_RimShift)
485        elif self.shader_type == 'CM3D2/Toony_Lighted_Outline_Tex':
486            mate['shader1'] = 'CM3D2/Toony_Lighted_Outline_Tex'
487            mate['shader2'] = 'CM3D2__Toony_Lighted_Outline_Tex'
488            tex_list.append(_MainTex)
489            tex_list.append(_ToonRamp)
490            tex_list.append(_ShadowTex)
491            tex_list.append(_ShadowRateToon)
492            tex_list.append(_OutlineTex)
493            tex_list.append(_OutlineToonRamp)
494            col_list.append(_Color)
495            col_list.append(_ShadowColor)
496            col_list.append(_RimColor)
497            col_list.append(_OutlineColor)
498            f_list.append(_Shininess)
499            f_list.append(_OutlineWidth)
500            f_list.append(_RimPower)
501            f_list.append(_RimShift)
502        elif self.shader_type == 'CM3D2/Lighted':
503            mate['shader1'] = 'CM3D2/Lighted'
504            mate['shader2'] = 'CM3D2__Lighted'
505            tex_list.append(_MainTex)
506            col_list.append(_Color)
507            col_list.append(_ShadowColor)
508            f_list.append(_Shininess)
509        elif self.shader_type == 'CM3D2/Lighted_Cutout_AtC':
510            mate['shader1'] = 'CM3D2/Lighted_Cutout_AtC'
511            mate['shader2'] = 'CM3D2__Lighted_Cutout_AtC'
512            tex_list.append(_MainTex)
513            col_list.append(_Color)
514            col_list.append(_ShadowColor)
515            f_list.append(_Shininess)
516            f_list.append(_Cutoff)
517        elif self.shader_type == 'CM3D2/Lighted_Trans':
518            mate['shader1'] = 'CM3D2/Lighted_Trans'
519            mate['shader2'] = 'CM3D2__Lighted_Trans'
520            tex_list.append(_MainTex)
521            col_list.append(_Color)
522            col_list.append(_ShadowColor)
523            f_list.append(_Shininess)
524        elif self.shader_type == 'CM3D2/Toony_Lighted':
525            mate['shader1'] = 'CM3D2/Toony_Lighted'
526            mate['shader2'] = 'CM3D2__Toony_Lighted'
527            tex_list.append(_MainTex)
528            tex_list.append(_ToonRamp)
529            tex_list.append(_ShadowTex)
530            tex_list.append(_ShadowRateToon)
531            col_list.append(_Color)
532            col_list.append(_ShadowColor)
533            col_list.append(_RimColor)
534            f_list.append(_Shininess)
535            f_list.append(_RimPower)
536            f_list.append(_RimShift)
537        elif self.shader_type == 'CM3D2/Toony_Lighted_Cutout_AtC':
538            mate['shader1'] = 'CM3D2/Toony_Lighted_Cutout_AtC'
539            mate['shader2'] = 'CM3D2__Toony_Lighted_Cutout_AtC'
540            tex_list.append(_MainTex)
541            tex_list.append(_ToonRamp)
542            tex_list.append(_ShadowTex)
543            tex_list.append(_ShadowRateToon)
544            col_list.append(_Color)
545            col_list.append(_ShadowColor)
546            col_list.append(_RimColor)
547            f_list.append(_Shininess)
548            f_list.append(_RimPower)
549            f_list.append(_RimShift)
550            f_list.append(_Cutoff)
551        elif self.shader_type == 'CM3D2/Toony_Lighted_Hair':
552            mate['shader1'] = 'CM3D2/Toony_Lighted_Hair'
553            mate['shader2'] = 'CM3D2__Toony_Lighted_Hair'
554            tex_list.append(_MainTex)
555            tex_list.append(_ToonRamp)
556            tex_list.append(_ShadowTex)
557            tex_list.append(_ShadowRateToon)
558            tex_list.append(_HiTex)
559            col_list.append(_Color)
560            col_list.append(_ShadowColor)
561            col_list.append(_RimColor)
562            f_list.append(_Shininess)
563            f_list.append(_RimPower)
564            f_list.append(_RimShift)
565            f_list.append(_HiRate)
566            f_list.append(_HiPow)
567        elif self.shader_type == 'Transparent/Diffuse':
568            mate['shader1'] = 'Legacy Shaders/Transparent/Diffuse'
569            mate['shader2'] = 'Legacy Shaders__Transparent__Diffuse'
570            tex_list.append(_MainTex)
571            col_list.append(_Color)
572            # col_list.append(_ShadowColor)
573            # col_list.append(_RimColor)
574            # col_list.append(_OutlineColor)
575            # f_list.append(_Shininess)
576            # f_list.append(_OutlineWidth)
577            # f_list.append(_RimPower)
578            # f_list.append(_RimShift)
579        elif self.shader_type == 'CM3D2_Debug/Debug_CM3D2_Normal2Color':
580            mate['shader1'] = 'CM3D2_Debug/Debug_CM3D2_Normal2Color'
581            mate['shader2'] = 'CM3D2_Debug__Debug_CM3D2_Normal2Color'
582            col_list.append(_Color)
583            col_list.append(_RimColor)
584            col_list.append(_OutlineColor)
585            col_list.append(("_SpecColor", (1, 1, 1, 1)))
586            f_list.append(_Shininess)
587            f_list.append(_OutlineWidth)
588            f_list.append(_RimPower)
589            f_list.append(_RimShift)
590        
591        texpath_dict = common.get_texpath_dict()
592        slot_index = 0
593        
594        for data in tex_list:
595            key = data[0]
596            tex_name = data[1]
597            cm3d2path = data[2]
598            # prefsから初期値を取得
599            tex_map = prefs.new_mate_tex_offset[:2] + prefs.new_mate_tex_scale[:2]
600            tex = common.create_tex(context, mate, key, tex_name, cm3d2path, cm3d2path, tex_map, False, slot_index)
601
602            # tex探し
603            if prefs.is_replace_cm3d2_tex:
604                replaced = common.replace_cm3d2_tex(tex.image, texpath_dict=texpath_dict, reload_path=False)
605                if compat.IS_LEGACY and replaced and key == '_MainTex':
606                    for face in me.polygons:
607                        if face.material_index == ob.active_material_index:
608                            me.uv_textures.active.data[face.index].image = tex.image
609            if compat.IS_LEGACY:
610                slot_index += 1
611
612        for data in col_list:
613            node = common.create_col(context, mate, data[0], data[1][:4], slot_index)
614            if compat.IS_LEGACY:
615                slot_index += 1
616
617        for data in f_list:
618            node = common.create_float(context, mate, data[0], data[1], slot_index)
619            if compat.IS_LEGACY:
620                slot_index += 1
621
622        if compat.IS_LEGACY:
623            common.decorate_material(mate, self.is_decorate, me, ob.active_material_index)
624        else:
625            cm3d2_data.align_nodes(mate)
626            common.decorate_material(mate, self.is_decorate, me, ob.active_material_index)
627
628        return {'FINISHED'}
@compat.BlRegister()
class CNV_OT_new_cm3d2(bpy_types.Operator, new_mate_opr):
631@compat.BlRegister()
632class CNV_OT_new_cm3d2(bpy.types.Operator, new_mate_opr):
633    bl_idname = 'material.new_cm3d2'
634    bl_label = "CM3D2用マテリアルを新規作成"
635    bl_description = "Blender-CM3D2-Converterで使用できるマテリアルを新規で作成します"
636    bl_options = {'REGISTER', 'UNDO'}
637
638    shader_type = bpy.props.EnumProperty(items=cm3d2_data.Handler.create_shader_items(), name="種類", default='CM3D2/Toony_Lighted_Outline')
bl_idname = 'material.new_cm3d2'
bl_label = 'CM3D2用マテリアルを新規作成'
bl_description = 'Blender-CM3D2-Converterで使用できるマテリアルを新規で作成します'
bl_options = {'REGISTER', 'UNDO'}
shader_type: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('CM3D2/Toony_Lighted', 'トゥーン', '', 'SHADING_SOLID', 0), ('CM3D2/Toony_Lighted_Hair', 'トゥーン 髪', '', 'PARTICLEMODE', 1), ('CM3D2/Toony_Lighted_Trans', 'トゥーン 透過', '', 'SHADING_WIRE', 2), ('CM3D2/Toony_Lighted_Trans_NoZ', 'トゥーン 透過 NoZ', '', 'DRIVER', 3), ('CM3D2/Toony_Lighted_Outline', 'トゥーン 輪郭線', '', 'ANTIALIASED', 4), ('CM3D2/Toony_Lighted_Outline_Trans', 'トゥーン 輪郭線 透過', '', 'PROP_OFF', 5), ('CM3D2/Toony_Lighted_Hair_Outline', 'トゥーン 輪郭線 髪', '', 'PARTICLEMODE', 6), ('CM3D2/Lighted_Trans', 'トゥーン無し 透過', '', 'VIS_SEL_01', 7), ('CM3D2/Lighted', 'トゥーン無し', '', 'VIS_SEL_11', 8), ('Unlit/Texture', '発光', '', 'PARTICLES', 9), ('Unlit/Transparent', '発光 透過', '', 'MOD_PARTICLES', 10), ('CM3D2/Mosaic', 'モザイク', '', 'ALIASED', 11), ('CM3D2/Man', 'ご主人様', '', 'ARMATURE_DATA', 12), ('Diffuse', 'リアル', '', 'BRUSH_CLAY_STRIPS', 13), ('Transparent/Diffuse', 'リアル 透過', '', 'BRUSH_TEXFILL', 14), ('CM3D2_Debug/Debug_CM3D2_Normal2Color', '法線', '', 'NORMALS_VERTEX', 15)], 'name': '種類', 'default': 'CM3D2/Toony_Lighted_Outline', 'attr': 'shader_type'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('CM3D2/Toony_Lighted', 'トゥーン', '', 'SHADING_SOLID', 0), ('CM3D2/Toony_Lighted_Hair', 'トゥーン 髪', '', 'PARTICLEMODE', 1), ('CM3D2/Toony_Lighted_Trans', 'トゥーン 透過', '', 'SHADING_WIRE', 2), ('CM3D2/Toony_Lighted_Trans_NoZ', 'トゥーン 透過 NoZ', '', 'DRIVER', 3), ('CM3D2/Toony_Lighted_Outline', 'トゥーン 輪郭線', '', 'ANTIALIASED', 4), ('CM3D2/Toony_Lighted_Outline_Trans', 'トゥーン 輪郭線 透過', '', 'PROP_OFF', 5), ('CM3D2/Toony_Lighted_Hair_Outline', 'トゥーン 輪郭線 髪', '', 'PARTICLEMODE', 6), ('CM3D2/Lighted_Trans', 'トゥーン無し 透過', '', 'VIS_SEL_01', 7), ('CM3D2/Lighted', 'トゥーン無し', '', 'VIS_SEL_11', 8), ('Unlit/Texture', '発光', '', 'PARTICLES', 9), ('Unlit/Transparent', '発光 透過', '', 'MOD_PARTICLES', 10), ('CM3D2/Mosaic', 'モザイク', '', 'ALIASED', 11), ('CM3D2/Man', 'ご主人様', '', 'ARMATURE_DATA', 12), ('Diffuse', 'リアル', '', 'BRUSH_CLAY_STRIPS', 13), ('Transparent/Diffuse', 'リアル 透過', '', 'BRUSH_TEXFILL', 14), ('CM3D2_Debug/Debug_CM3D2_Normal2Color', '法線', '', 'NORMALS_VERTEX', 15)], 'name': '種類', 'default': 'CM3D2/Toony_Lighted_Outline', 'attr': 'shader_type'}>
bl_rna = <bpy_struct, Struct("MATERIAL_OT_new_cm3d2")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
new_mate_opr
is_decorate
poll
invoke
draw
execute
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_new_com3d2(bpy_types.Operator, new_mate_opr):
641@compat.BlRegister()
642class CNV_OT_new_com3d2(bpy.types.Operator, new_mate_opr):
643    bl_idname = 'material.new_com3d2'
644    bl_label = "COM3D2用マテリアルを新規作成"
645    bl_description = "Blender-CM3D2-Converterで使用できるマテリアルを新規で作成します"
646    bl_options = {'REGISTER', 'UNDO'}
647
648    shader_type = bpy.props.EnumProperty(items=cm3d2_data.Handler.create_comshader_items(), name="種類", default='CM3D2/Toony_Lighted_Outline')
bl_idname = 'material.new_com3d2'
bl_label = 'COM3D2用マテリアルを新規作成'
bl_description = 'Blender-CM3D2-Converterで使用できるマテリアルを新規で作成します'
bl_options = {'REGISTER', 'UNDO'}
shader_type: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('CM3D2/Toony_Lighted', 'トゥーン', '', 'SHADING_SOLID', 0), ('CM3D2/Toony_Lighted_Hair', 'トゥーン 髪', '', 'PARTICLEMODE', 1), ('CM3D2/Toony_Lighted_Trans', 'トゥーン 透過', '', 'SHADING_WIRE', 2), ('CM3D2/Toony_Lighted_Trans_NoZ', 'トゥーン 透過 NoZ', '', 'DRIVER', 3), ('CM3D2/Toony_Lighted_Trans_NoZTest', 'トゥーン 透過 NoZTest', '', 'ANIM_DATA', 4), ('CM3D2/Toony_Lighted_Outline', 'トゥーン 輪郭線', '', 'ANTIALIASED', 5), ('CM3D2/Toony_Lighted_Outline_Tex', 'トゥーン 輪郭線 Tex', '', 'MATSPHERE', 6), ('CM3D2/Toony_Lighted_Hair_Outline', 'トゥーン 輪郭線 髪', '', 'PARTICLEMODE', 7), ('CM3D2/Toony_Lighted_Outline_Trans', 'トゥーン 輪郭線 透過', '', 'PROP_OFF', 8), ('CM3D2/Toony_Lighted_Cutout_AtC', 'トゥーン Cutout', '', 'IPO_BACK', 9), ('CM3D2/Lighted_Cutout_AtC', 'トゥーン無し Cutout', '', 'IPO_BACK', 10), ('CM3D2/Lighted_Trans', 'トゥーン無し 透過', '', 'VIS_SEL_01', 11), ('CM3D2/Lighted', 'トゥーン無し', '', 'VIS_SEL_11', 12), ('Unlit/Texture', '発光', '', 'PARTICLES', 13), ('Unlit/Transparent', '発光 透過', '', 'MOD_PARTICLES', 14), ('CM3D2/Mosaic', 'モザイク', '', 'ALIASED', 15), ('CM3D2/Man', 'ご主人様', '', 'ARMATURE_DATA', 16), ('Diffuse', 'リアル', '', 'BRUSH_CLAY_STRIPS', 17), ('Transparent/Diffuse', 'リアル 透過', '', 'BRUSH_TEXFILL', 18), ('CM3D2_Debug/Debug_CM3D2_Normal2Color', '法線', '', 'NORMALS_VERTEX', 19)], 'name': '種類', 'default': 'CM3D2/Toony_Lighted_Outline', 'attr': 'shader_type'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('CM3D2/Toony_Lighted', 'トゥーン', '', 'SHADING_SOLID', 0), ('CM3D2/Toony_Lighted_Hair', 'トゥーン 髪', '', 'PARTICLEMODE', 1), ('CM3D2/Toony_Lighted_Trans', 'トゥーン 透過', '', 'SHADING_WIRE', 2), ('CM3D2/Toony_Lighted_Trans_NoZ', 'トゥーン 透過 NoZ', '', 'DRIVER', 3), ('CM3D2/Toony_Lighted_Trans_NoZTest', 'トゥーン 透過 NoZTest', '', 'ANIM_DATA', 4), ('CM3D2/Toony_Lighted_Outline', 'トゥーン 輪郭線', '', 'ANTIALIASED', 5), ('CM3D2/Toony_Lighted_Outline_Tex', 'トゥーン 輪郭線 Tex', '', 'MATSPHERE', 6), ('CM3D2/Toony_Lighted_Hair_Outline', 'トゥーン 輪郭線 髪', '', 'PARTICLEMODE', 7), ('CM3D2/Toony_Lighted_Outline_Trans', 'トゥーン 輪郭線 透過', '', 'PROP_OFF', 8), ('CM3D2/Toony_Lighted_Cutout_AtC', 'トゥーン Cutout', '', 'IPO_BACK', 9), ('CM3D2/Lighted_Cutout_AtC', 'トゥーン無し Cutout', '', 'IPO_BACK', 10), ('CM3D2/Lighted_Trans', 'トゥーン無し 透過', '', 'VIS_SEL_01', 11), ('CM3D2/Lighted', 'トゥーン無し', '', 'VIS_SEL_11', 12), ('Unlit/Texture', '発光', '', 'PARTICLES', 13), ('Unlit/Transparent', '発光 透過', '', 'MOD_PARTICLES', 14), ('CM3D2/Mosaic', 'モザイク', '', 'ALIASED', 15), ('CM3D2/Man', 'ご主人様', '', 'ARMATURE_DATA', 16), ('Diffuse', 'リアル', '', 'BRUSH_CLAY_STRIPS', 17), ('Transparent/Diffuse', 'リアル 透過', '', 'BRUSH_TEXFILL', 18), ('CM3D2_Debug/Debug_CM3D2_Normal2Color', '法線', '', 'NORMALS_VERTEX', 19)], 'name': '種類', 'default': 'CM3D2/Toony_Lighted_Outline', 'attr': 'shader_type'}>
bl_rna = <bpy_struct, Struct("MATERIAL_OT_new_com3d2")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
new_mate_opr
is_decorate
poll
invoke
draw
execute
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_paste_material(bpy_types.Operator):
651@compat.BlRegister()
652class CNV_OT_paste_material(bpy.types.Operator):
653    bl_idname = 'material.paste_material'
654    bl_label = "クリップボードからマテリアルを貼付け"
655    bl_description = "クリップボード内のテキストからマテリアル情報を上書きします"
656    bl_options = {'REGISTER', 'UNDO'}
657
658    is_decorate = bpy.props.BoolProperty(name="種類に合わせてマテリアルを装飾", default=False)
659    is_replace_cm3d2_tex = bpy.props.BoolProperty(name="テクスチャを探す", default=False, description="CM3D2本体のインストールフォルダからtexファイルを探して開きます")
660    is_create = bpy.props.BoolProperty(name="マテリアルの新規作成", default=False)
661    override_name = bpy.props.BoolProperty(name="マテリアル名を上書きする", default=False)
662    use_dialog = bpy.props.BoolProperty(name="上書き設定", default=True)
663
664    @classmethod
665    def poll(cls, context):
666        data = context.window_manager.clipboard
667        if len(data) < 32:
668            return False
669
670        # if not data.startswith('1000'):
671        # 	return False
672        if '\ntex\n\t' in data or '\ncol\n\t' in data or '\nf\n\t' in data:
673            return True
674
675        # if not data.startswith('1000'):
676        # 	return False
677        # if '\n\t_MainTex\n' in data or '\n\t_Color\n' in data:
678        # 	return True
679        return False
680
681    def invoke(self, context, event):
682        if self.use_dialog:
683            return context.window_manager.invoke_props_dialog(self)
684        return self.execute(context)
685
686    def draw(self, context):
687        self.layout.prop(self, 'override_name')
688        if compat.IS_LEGACY:
689            self.layout.prop(self, 'is_decorate')
690        prefs = common.preferences()
691        self.layout.prop(prefs, 'is_replace_cm3d2_tex', icon='BORDERMOVE')
692
693    def execute(self, context):
694        text = context.window_manager.clipboard
695
696        try:
697            mat_data = cm3d2_data.MaterialHandler.parse_text(text)
698        except Exception as e:
699            # tb = sys.exc_info()[2]
700            # e.with_traceback(tb)
701            self.report(type={'ERROR'}, message='マテリアル情報の貼付けを中止します。' + str(e))
702            return {'CANCELLED'}
703
704        mate_name = mat_data.name
705        if self.is_create:
706            if not context.material_slot:
707                bpy.ops.object.material_slot_add()
708            mate = context.blend_data.materials.new(mate_name)
709            context.material_slot.material = mate
710            common.setup_material(mate)
711        else:
712            mate = context.material
713            if self.override_name:
714                # シリアル番号が異なる場合は変更しない
715                if common.remove_serial_number(mate_name) != common.remove_serial_number(mate.name):
716                    mate.name = mate_name
717
718        prefs = common.preferences()
719        if compat.IS_LEGACY:
720            cm3d2_data.MaterialHandler.apply_to_old(context, mate, mat_data, prefs.is_replace_cm3d2_tex, self.is_decorate)
721        else:
722            cm3d2_data.MaterialHandler.apply_to(context, mate, mat_data, prefs.is_replace_cm3d2_tex)
723
724        self.report(type={'INFO'}, message="クリップボードからマテリアルを貼付けました")
725        return {'FINISHED'}
bl_idname = 'material.paste_material'
bl_label = 'クリップボードからマテリアルを貼付け'
bl_description = 'クリップボード内のテキストからマテリアル情報を上書きします'
bl_options = {'REGISTER', 'UNDO'}
is_decorate: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '種類に合わせてマテリアルを装飾', 'default': False, 'attr': 'is_decorate'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '種類に合わせてマテリアルを装飾', 'default': False, 'attr': 'is_decorate'}>
is_replace_cm3d2_tex: <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'テクスチャを探す', 'default': False, 'description': 'CM3D2本体のインストールフォルダからtexファイルを探して開きます', 'attr': 'is_replace_cm3d2_tex'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'テクスチャを探す', 'default': False, 'description': 'CM3D2本体のインストールフォルダからtexファイルを探して開きます', 'attr': 'is_replace_cm3d2_tex'}>
is_create: <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'マテリアルの新規作成', 'default': False, 'attr': 'is_create'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'マテリアルの新規作成', 'default': False, 'attr': 'is_create'}>
override_name: <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'マテリアル名を上書きする', 'default': False, 'attr': 'override_name'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'マテリアル名を上書きする', 'default': False, 'attr': 'override_name'}>
use_dialog: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '上書き設定', 'default': True, 'attr': 'use_dialog'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '上書き設定', 'default': True, 'attr': 'use_dialog'}>
@classmethod
def poll(cls, context):
664    @classmethod
665    def poll(cls, context):
666        data = context.window_manager.clipboard
667        if len(data) < 32:
668            return False
669
670        # if not data.startswith('1000'):
671        # 	return False
672        if '\ntex\n\t' in data or '\ncol\n\t' in data or '\nf\n\t' in data:
673            return True
674
675        # if not data.startswith('1000'):
676        # 	return False
677        # if '\n\t_MainTex\n' in data or '\n\t_Color\n' in data:
678        # 	return True
679        return False
def invoke(self, context, event):
681    def invoke(self, context, event):
682        if self.use_dialog:
683            return context.window_manager.invoke_props_dialog(self)
684        return self.execute(context)
def draw(self, context):
686    def draw(self, context):
687        self.layout.prop(self, 'override_name')
688        if compat.IS_LEGACY:
689            self.layout.prop(self, 'is_decorate')
690        prefs = common.preferences()
691        self.layout.prop(prefs, 'is_replace_cm3d2_tex', icon='BORDERMOVE')
def execute(self, context):
693    def execute(self, context):
694        text = context.window_manager.clipboard
695
696        try:
697            mat_data = cm3d2_data.MaterialHandler.parse_text(text)
698        except Exception as e:
699            # tb = sys.exc_info()[2]
700            # e.with_traceback(tb)
701            self.report(type={'ERROR'}, message='マテリアル情報の貼付けを中止します。' + str(e))
702            return {'CANCELLED'}
703
704        mate_name = mat_data.name
705        if self.is_create:
706            if not context.material_slot:
707                bpy.ops.object.material_slot_add()
708            mate = context.blend_data.materials.new(mate_name)
709            context.material_slot.material = mate
710            common.setup_material(mate)
711        else:
712            mate = context.material
713            if self.override_name:
714                # シリアル番号が異なる場合は変更しない
715                if common.remove_serial_number(mate_name) != common.remove_serial_number(mate.name):
716                    mate.name = mate_name
717
718        prefs = common.preferences()
719        if compat.IS_LEGACY:
720            cm3d2_data.MaterialHandler.apply_to_old(context, mate, mat_data, prefs.is_replace_cm3d2_tex, self.is_decorate)
721        else:
722            cm3d2_data.MaterialHandler.apply_to(context, mate, mat_data, prefs.is_replace_cm3d2_tex)
723
724        self.report(type={'INFO'}, message="クリップボードからマテリアルを貼付けました")
725        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("MATERIAL_OT_paste_material")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_copy_material(bpy_types.Operator):
728@compat.BlRegister()
729class CNV_OT_copy_material(bpy.types.Operator):
730    bl_idname = 'material.copy_material'
731    bl_label = "マテリアルをクリップボードにコピー"
732    bl_description = "表示しているマテリアルをテキスト形式でクリップボードにコピーします"
733    bl_options = {'REGISTER', 'UNDO'}
734
735    @classmethod
736    def poll(cls, context):
737        mate = getattr(context, 'material')
738        if mate:
739            return 'shader1' in mate and 'shader2' in mate
740        return False
741
742    def execute(self, context):
743        mate = context.material
744        try:
745            if compat.IS_LEGACY:
746                mat_data = cm3d2_data.MaterialHandler.parse_mate_old(mate)
747            else:
748                mat_data = cm3d2_data.MaterialHandler.parse_mate(mate)
749        except Exception as e:
750            self.report(type={'ERROR'}, message="クリップボードへのコピーを中止します。:" + str(e))
751            return {'CANCELLED'}
752
753        context.window_manager.clipboard = mat_data.to_text()
754        self.report(type={'INFO'}, message="マテリアルテキストをクリップボードにコピーしました")
755        return {'FINISHED'}
bl_idname = 'material.copy_material'
bl_label = 'マテリアルをクリップボードにコピー'
bl_description = '表示しているマテリアルをテキスト形式でクリップボードにコピーします'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
735    @classmethod
736    def poll(cls, context):
737        mate = getattr(context, 'material')
738        if mate:
739            return 'shader1' in mate and 'shader2' in mate
740        return False
def execute(self, context):
742    def execute(self, context):
743        mate = context.material
744        try:
745            if compat.IS_LEGACY:
746                mat_data = cm3d2_data.MaterialHandler.parse_mate_old(mate)
747            else:
748                mat_data = cm3d2_data.MaterialHandler.parse_mate(mate)
749        except Exception as e:
750            self.report(type={'ERROR'}, message="クリップボードへのコピーを中止します。:" + str(e))
751            return {'CANCELLED'}
752
753        context.window_manager.clipboard = mat_data.to_text()
754        self.report(type={'INFO'}, message="マテリアルテキストをクリップボードにコピーしました")
755        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("MATERIAL_OT_copy_material")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_decorate_material(bpy_types.Operator):
758@compat.BlRegister()
759class CNV_OT_decorate_material(bpy.types.Operator):
760    bl_idname = 'material.decorate_material'
761    bl_label = "マテリアルを装飾"
762    bl_description = "スロット内のマテリアルを全て設定に合わせて装飾します"
763    bl_options = {'REGISTER', 'UNDO'}
764
765    @classmethod
766    def poll(cls, context):
767        ob = context.active_object
768        if not ob or ob.type != 'MESH':
769            return False
770        for slot in ob.material_slots:
771            mate = slot.material
772            if mate and 'shader1' in mate and 'shader2' in mate:
773                return True
774        return False
775
776    def execute(self, context):
777        ob = context.active_object
778        me = ob.data
779
780        for slot_index, slot in enumerate(ob.material_slots):
781            mate = slot.material
782            if mate and 'shader1' in mate and 'shader2' in mate:
783                common.decorate_material(mate, True, me, slot_index)
784
785        return {'FINISHED'}
bl_idname = 'material.decorate_material'
bl_label = 'マテリアルを装飾'
bl_description = 'スロット内のマテリアルを全て設定に合わせて装飾します'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
765    @classmethod
766    def poll(cls, context):
767        ob = context.active_object
768        if not ob or ob.type != 'MESH':
769            return False
770        for slot in ob.material_slots:
771            mate = slot.material
772            if mate and 'shader1' in mate and 'shader2' in mate:
773                return True
774        return False
def execute(self, context):
776    def execute(self, context):
777        ob = context.active_object
778        me = ob.data
779
780        for slot_index, slot in enumerate(ob.material_slots):
781            mate = slot.material
782            if mate and 'shader1' in mate and 'shader2' in mate:
783                common.decorate_material(mate, True, me, slot_index)
784
785        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("MATERIAL_OT_decorate_material")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_texture_show(bpy_types.Operator):
788@compat.BlRegister()
789class CNV_OT_quick_texture_show(bpy.types.Operator):
790    bl_idname = 'material.quick_texture_show'
791    bl_label = "このテクスチャを見る"
792    bl_description = "このテクスチャを見る"
793    bl_options = {'REGISTER'}
794
795    texture_name = bpy.props.StringProperty(name="テクスチャ名")
796
797    @classmethod
798    def poll(cls, context):
799        mate = context.material
800        if mate:
801            if 'shader1' in mate and 'shader2' in mate:
802                return True
803        return False
804
805    def execute(self, context):
806        mate = context.material
807        if hasattr(mate, 'texture_slots'):
808            for index, slot in enumerate(mate.texture_slots):
809                if not slot or not slot.texture:
810                    continue
811                if slot.texture.name == self.texture_name:
812                    mate.active_texture_index = index
813                    context.space_data.context = 'TEXTURE'
814                    break
815        else:
816            # TODO テクスチャの表示検討
817            pass
818
819        return {'FINISHED'}
bl_idname = 'material.quick_texture_show'
bl_label = 'このテクスチャを見る'
bl_description = 'このテクスチャを見る'
bl_options = {'REGISTER'}
texture_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': 'テクスチャ名', 'attr': 'texture_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': 'テクスチャ名', 'attr': 'texture_name'}>
@classmethod
def poll(cls, context):
797    @classmethod
798    def poll(cls, context):
799        mate = context.material
800        if mate:
801            if 'shader1' in mate and 'shader2' in mate:
802                return True
803        return False
def execute(self, context):
805    def execute(self, context):
806        mate = context.material
807        if hasattr(mate, 'texture_slots'):
808            for index, slot in enumerate(mate.texture_slots):
809                if not slot or not slot.texture:
810                    continue
811                if slot.texture.name == self.texture_name:
812                    mate.active_texture_index = index
813                    context.space_data.context = 'TEXTURE'
814                    break
815        else:
816            # TODO テクスチャの表示検討
817            pass
818
819        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("MATERIAL_OT_quick_texture_show")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_setup_material_expand(bpy_types.Operator):
822@compat.BlRegister()
823class CNV_OT_setup_material_expand(bpy.types.Operator):
824    bl_idname = 'material.setup_mate_expand'
825    bl_label = "マテリアルのセットアップ"
826    bl_description = "マテリアルの各種フラグを初期化する"
827    bl_options = {'REGISTER', 'UNDO'}
828
829    @classmethod
830    def poll(cls, context):
831        mate = context.material
832        if mate:
833            if 'shader1' in mate and 'shader2' in mate:
834                return True
835        return False
836
837    def execute(self, context):
838        mate = context.material
839        common.setup_material(mate)
840
841        return {'FINISHED'}
bl_idname = 'material.setup_mate_expand'
bl_label = 'マテリアルのセットアップ'
bl_description = 'マテリアルの各種フラグを初期化する'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
829    @classmethod
830    def poll(cls, context):
831        mate = context.material
832        if mate:
833            if 'shader1' in mate and 'shader2' in mate:
834                return True
835        return False
def execute(self, context):
837    def execute(self, context):
838        mate = context.material
839        common.setup_material(mate)
840
841        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("MATERIAL_OT_setup_mate_expand")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_material_prop_expand(bpy_types.Operator, CM3D2 Converter.common.NodeHandler):
844@compat.BlRegister()
845class CNV_OT_material_prop_expand(bpy.types.Operator, common.NodeHandler):
846    bl_idname = 'material.mateprop_expand'
847    bl_label = "マテリアルプロパティの詳細情報"
848    bl_description = "マテリアルプロパティの詳細情報の表示状態を切り替える"
849    bl_options = {'REGISTER', 'UNDO'}
850
851    @classmethod
852    def poll(cls, context):
853        mate = context.material
854        return mate and 'shader1' in mate and 'shader2' in mate
855
856    def execute(self, context):
857        node = self.get_node(context)
858        if node is None:
859            return {'CANCELLED'}
860        prev = node.get('CM3D2 Prop Expand', False)
861        node['CM3D2 Prop Expand'] = not prev
862
863        return {'FINISHED'}
bl_idname = 'material.mateprop_expand'
bl_label = 'マテリアルプロパティの詳細情報'
bl_description = 'マテリアルプロパティの詳細情報の表示状態を切り替える'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
851    @classmethod
852    def poll(cls, context):
853        mate = context.material
854        return mate and 'shader1' in mate and 'shader2' in mate
def execute(self, context):
856    def execute(self, context):
857        node = self.get_node(context)
858        if node is None:
859            return {'CANCELLED'}
860        prev = node.get('CM3D2 Prop Expand', False)
861        node['CM3D2 Prop Expand'] = not prev
862
863        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("MATERIAL_OT_mateprop_expand")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
CM3D2 Converter.common.NodeHandler
node_name
get_node
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
LAYOUT_FACTOR = 0.3