forked from kidintwo3/clarisse_alshader_io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalshader_import.py
78 lines (55 loc) · 2.99 KB
/
alshader_import.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
import ix
import os
import json
import ntpath
def read_mat_data(file_path=None, default_path="project://scene"):
"""
Reads the material data from the json file
Example: read_mat_data(file_path='c:/test_mat.json')
:param file_path: str, full path to the json file
:param default_path: str, context path where the materials and texture nodes will be created
:return:
"""
if not file_path:
return
if not os.path.exists(file_path):
return
# Open the json file and read the data
with open(file_path, 'r') as fp:
dataA = json.load(fp)
if not dataA:
return
for shader in dataA:
if shader:
shader_name = shader['name']
# Create Physical Material
if shader_name:
standard_mat = ix.cmds.CreateObject(str(shader_name) + '_mat', "MaterialPhysicalStandard", "Global",
default_path)
# Get the attributes
if standard_mat:
attributes_data = shader.get('data')
if attributes_data:
for i in attributes_data:
if i:
if isinstance(i, dict):
for clar_id, val in i.iteritems():
if isinstance(val, list) and len(val) == 3:
ix.cmds.SetValues([standard_mat.get_full_name() + "." + str(clar_id)],
[str(val[0]), str(val[1]), str(val[2])])
# Everything that is a string is considered as a file path
elif isinstance(val, basestring):
texture_node = ix.cmds.CreateObject(str(ntpath.basename(val)) + "_tx",
"TextureStreamedMapFile", "Global",
default_path)
if texture_node:
ix.cmds.SetValues([texture_node.get_full_name() + ".filename[0]"],
[str(val)])
# TODO Bump still needs to be implemented as an override
ix.cmds.SetTexture([standard_mat.get_full_name() + "." + str(clar_id)],
texture_node.get_full_name())
else:
# Set the attribute
ix.cmds.SetValues([standard_mat.get_full_name() + "." + str(clar_id)],
[str(val)])
read_mat_data(file_path='C:/Users/etudiant/Documents/clarisse_alshader_io/test_mat.json', default_path="project://scene")