-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperties.py
191 lines (158 loc) · 5.57 KB
/
properties.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import bpy
import os
import json
from bpy.props import BoolProperty, EnumProperty, FloatProperty, IntProperty, PointerProperty, StringProperty
from bpy.types import Panel, PropertyGroup, Operator
import functools
from .utils import myutils
global dm_lang_data
dm_lang_data = {}
language = 'en'
def my_dm_img_files_callback(self, context):
items = []
my_dmimgs_path = self.dmimgsdir
if not os.path.isdir(my_dmimgs_path):
return [("0", "None", "")]
myunsortedfiles = os.listdir(my_dmimgs_path)
mydmimgfiles = sorted(myunsortedfiles, key=lambda x: os.path.getmtime(os.path.join(my_dmimgs_path, x)), reverse=False)
i = 0
for file in mydmimgfiles:
myfilename = os.path.join(my_dmimgs_path, file)
if os.path.isfile(myfilename) and myfilename.lower()[-4:] in ['.bmp', '.png', '.jpg']:
if i > 30:
break
#filename = file.split('.bmp')[0]
filename = file[:-4]
cnfilename = bytes(filename, encoding='UTF-8')
items.append((str(i), str(i), ""))
i += 1
if len(items) == 0:
return [("0", "None", "")]
return items
def update_dm_img_files(self, context):
items = []
my_dmimgs_path = self.dmimgsdir
myunsortedfiles = os.listdir(my_dmimgs_path)
mydmimgfiles = sorted(myunsortedfiles, key=lambda x: os.path.getmtime(os.path.join(my_dmimgs_path, x)), reverse=False)
i = 0
for file in mydmimgfiles:
myfilename = os.path.join(my_dmimgs_path, file)
if os.path.isfile(myfilename) and myfilename.lower()[-4:] in ['.bmp', '.png', '.jpg']:
if i > 30:
break
#filename = file.split('.bmp')[0]
filename = file[:-4]
items.append(filename)
i += 1
imgname = os.path.join(my_dmimgs_path, items[int(self.dmimgenumfiles)])
handle = bpy.types.SpaceView3D.draw_handler_add(myutils.draw_callback_px, (self, context, imgname, 20), 'WINDOW', 'POST_PIXEL')
bpy.app.timers.register(functools.partial(myutils.remove_text, handle), first_interval=1)
def my_dm_img_dirs_callback(self, context):
#this only applies to enum property
addon_name = __name__.split('.')[0]
mygrayscaledir = context.preferences.addons[addon_name].preferences.grayscale_dir
items = []
mydmimgdirs = os.listdir(mygrayscaledir)
i = 0
for mydir in mydmimgdirs:
mydirname = os.path.join(mygrayscaledir, mydir)
if os.path.isdir(mydirname):
cndirname = mydir.encode('utf-8').decode('utf-8')
items.append((str(i), cndirname, ""))
i += 1
return items
def my_dm_img_dirs_str_callback(context):
#this only applies to enum property
addon_name = __name__.split('.')[0]
mygrayscaledir = context.preferences.addons[addon_name].preferences.grayscale_dir
items = []
mydmimgdirs = os.listdir(mygrayscaledir)
i = 1
for mydir in mydmimgdirs:
mydirname = os.path.join(mygrayscaledir, mydir)
if os.path.isdir(mydirname):
cndirname = mydir.encode('utf-8').decode('utf-8')
mycndirname = os.path.join(mygrayscaledir, cndirname)
items.append(mycndirname)
i += 1
return items
def update_dm_img_dirs(self, context):
pass
def get_dm_imgs_dir(self):
addon_name = __name__.split('.')[0]
mygrayscaledir = bpy.context.preferences.addons[addon_name].preferences.grayscale_dir
return self.get('dm_imgs_dir', mygrayscaledir)
def set_dm_imgs_dir(self, value):
self['dm_imgs_dir'] = value
return None
myaddondirectory = os.path.dirname(os.path.abspath(__file__))
if language == 'en':
myjsonfile = os.path.join(myaddondirectory, "lang", "en.json")
elif language == 'cn':
myjsonfile = os.path.join(myaddondirectory, "lang", "cn.json")
with open(myjsonfile, 'r') as f:
dm_lang_data = json.load(f)
class DMMISCSettings(PropertyGroup):
# FOR MISC SETTINGS
collectionName : StringProperty(
name = dm_lang_data["collectionName"],
default = ""
)
boolName : BoolProperty(
name = "Boolean",
default = True
)
locx : FloatProperty(
name = "X:",
description = "translate x",
min = -10000,
max = 10000,
default = 0.0,
)
locy : FloatProperty(
name = "Y:",
description = "translate y",
min = -10000,
max = 10000,
default = 0.0,
)
locz : FloatProperty(
name = "Z:",
description = "translate z",
min = -10000,
max = 10000,
default = 0.0,
)
dmthickness : FloatProperty(
name = dm_lang_data["dmthickness"],
description = "Thickness",
min = 0,
max = 1000,
default = 0.03,
)
isbyrandomdir : BoolProperty(
name = dm_lang_data["isbyrandomfile"],
default = True
)
isbyrandomfile : BoolProperty(
name = dm_lang_data["isbyrandomfile"],
default = True
)
isclockwise : BoolProperty(
name = dm_lang_data["isclockwise"],
default = False
)
dmimgsdir: bpy.props.StringProperty(
name = dm_lang_data["dmimgsdir"],
subtype = 'DIR_PATH',
description = "Displacement mapping images Directory",
default = '',
get = get_dm_imgs_dir,
set = set_dm_imgs_dir
)
dmimgenumfiles: EnumProperty(
items=my_dm_img_files_callback,
name=dm_lang_data["dmimgenumfiles"],
description="Displacement mapping images",
update=update_dm_img_files,
)