-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.py
39 lines (29 loc) · 880 Bytes
/
utils.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
import json
import bpy
def dict2str(d):
return json.dumps(d)
def str2dict(s):
return json.loads(s)
def loadMatFile(context, force = False):
evertims = context.scene.evertims
# discard if already loaded
if not evertims.mat_list_need_update and not force:
return evertims.mat_list
# get material file name
addon_prefs = context.user_preferences.addons[__package__].preferences
fileName = bpy.path.abspath(addon_prefs.raytracing_client_path_to_matFile)
# load mat file
fileObj = open(fileName, 'r')
mat = dict()
# loop over lines (one per material)
lines = fileObj.readlines()
for line in lines:
l = line.lstrip().split(' ')
absArray = [float(x) for x in l[0:10]]
diff = l[10]
name = l[11].rstrip()
mat[name] = absArray
# update update flag
evertims.mat_list_need_update = False
# return material dictionary as string
return dict2str(mat)