-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathresources.py
85 lines (75 loc) · 2.78 KB
/
resources.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import bpy
import os
MATERIAL_PREFIX = {'MESH': 'NijiGP_Mesh: ',
'NORMAL': 'NijiGP_Normal: '}
def get_cache_folder():
preferences = bpy.context.preferences.addons[__package__].preferences
if len(preferences.cache_folder)>0:
return preferences.cache_folder
else:
return bpy.app.tempdir
def get_workspace_tool_icon(file_name):
"""
Get a pre-defined .dat file as the icon of a workspace tool
"""
script_file = os.path.realpath(__file__)
return os.path.join(os.path.dirname(script_file), 'res/icons', file_name)
def get_library_blend_file():
file_name = 'res/library.blend'
script_file = os.path.realpath(__file__)
directory = os.path.dirname(script_file)
file_path = os.path.join(directory, file_name)
return file_path
def get_material_list(mesh_type, engine):
if mesh_type == 'MESH' and engine!='CYCLES':
return ['Principled BSDF',
'Simple Toon',
'Simple Comic',
'MatCap Liquid',
'MatCap Metal',
'Isoline Map']
elif mesh_type == 'MESH' and engine=='CYCLES':
return ['Principled BSDF',
'Cycles Toon',
'MatCap Liquid',
'MatCap Metal',
'Isoline Map']
elif mesh_type == 'NORMAL' and engine!='CYCLES':
return ['Principled BSDF',
'Simple Toon',
'Simple Comic',
'MatCap Liquid',
'MatCap Metal',
'Normal Map']
elif mesh_type == 'NORMAL' and engine=='CYCLES':
return ['Principled BSDF',
'Cycles Toon',
'MatCap Liquid',
'MatCap Metal',
'Normal Map']
def append_material(context, mesh_type, material_name, reuse = True, operator = None):
"""
Import a pre-defined material from the library blend file
"""
true_name = MATERIAL_PREFIX[mesh_type] + material_name
if reuse and true_name in bpy.data.materials:
return bpy.data.materials[true_name]
# Record the status before appending to check what is appended later
material_set = set(bpy.data.materials[:])
mode = context.mode
bpy.ops.object.mode_set(mode='OBJECT')
file_path = get_library_blend_file()
inner_path = 'Material'
bpy.ops.wm.append(
filepath=os.path.join(file_path, inner_path, true_name),
directory=os.path.join(file_path, inner_path),
filename=true_name
)
bpy.ops.object.mode_set(mode=mode)
new_materials = set(bpy.data.materials[:])-material_set
if len(new_materials)>0:
return list(new_materials)[0]
else:
if operator:
operator.report({"WARNING"}, "Material not found. Please select the material again.")
return