forked from z64tools/io_export_objex_2.5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.py
186 lines (159 loc) · 8.92 KB
/
template.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
import bpy
COMBINER_TEMPLATES = {
'DEFAULT': {
'input_flags_C_A_0': ( 'OBJEX_ColorCycle0', 'A', 'G_CCMUX_TEXEL0' ),
'input_flags_C_B_0': ( 'OBJEX_ColorCycle0', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_0': ( 'OBJEX_ColorCycle0', 'C', 'G_CCMUX_PRIMITIVE' ),
'input_flags_C_D_0': ( 'OBJEX_ColorCycle0', 'D', 'G_CCMUX_0' ),
'input_flags_C_A_1': ( 'OBJEX_ColorCycle1', 'A', 'G_CCMUX_COMBINED' ),
'input_flags_C_B_1': ( 'OBJEX_ColorCycle1', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_1': ( 'OBJEX_ColorCycle1', 'C', 'G_CCMUX_SHADE' ),
'input_flags_C_D_1': ( 'OBJEX_ColorCycle1', 'D', 'G_CCMUX_0' ),
'input_flags_A_A_0': ( 'OBJEX_AlphaCycle0', 'A', 'G_ACMUX_TEXEL0' ),
'input_flags_A_B_0': ( 'OBJEX_AlphaCycle0', 'B', 'G_ACMUX_0' ),
'input_flags_A_C_0': ( 'OBJEX_AlphaCycle0', 'C', 'G_ACMUX_PRIMITIVE' ),
'input_flags_A_D_0': ( 'OBJEX_AlphaCycle0', 'D', 'G_ACMUX_0' ),
},
'DEFAULT_ENV': {
'input_flags_C_A_0': ( 'OBJEX_ColorCycle0', 'A', 'G_CCMUX_TEXEL0' ),
'input_flags_C_B_0': ( 'OBJEX_ColorCycle0', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_0': ( 'OBJEX_ColorCycle0', 'C', 'G_CCMUX_ENVIRONMENT' ),
'input_flags_C_D_0': ( 'OBJEX_ColorCycle0', 'D', 'G_CCMUX_0' ),
'input_flags_C_A_1': ( 'OBJEX_ColorCycle1', 'A', 'G_CCMUX_COMBINED' ),
'input_flags_C_B_1': ( 'OBJEX_ColorCycle1', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_1': ( 'OBJEX_ColorCycle1', 'C', 'G_CCMUX_SHADE' ),
'input_flags_C_D_1': ( 'OBJEX_ColorCycle1', 'D', 'G_CCMUX_0' ),
'input_flags_A_A_0': ( 'OBJEX_AlphaCycle0', 'A', 'G_ACMUX_TEXEL0' ),
'input_flags_A_B_0': ( 'OBJEX_AlphaCycle0', 'B', 'G_ACMUX_0' ),
'input_flags_A_C_0': ( 'OBJEX_AlphaCycle0', 'C', 'G_ACMUX_ENVIRONMENT' ),
'input_flags_A_D_0': ( 'OBJEX_AlphaCycle0', 'D', 'G_ACMUX_0' ),
},
'MIX': {
'input_flags_C_A_0': ( 'OBJEX_ColorCycle0', 'A', 'G_CCMUX_TEXEL0' ),
'input_flags_C_B_0': ( 'OBJEX_ColorCycle0', 'B', 'G_CCMUX_TEXEL1' ),
'input_flags_C_C_0': ( 'OBJEX_ColorCycle0', 'C', 'G_CCMUX_PRIMITIVE_ALPHA' ),
'input_flags_C_D_0': ( 'OBJEX_ColorCycle0', 'D', 'G_CCMUX_TEXEL1' ),
'input_flags_C_A_1': ( 'OBJEX_ColorCycle1', 'A', 'G_CCMUX_COMBINED' ),
'input_flags_C_B_1': ( 'OBJEX_ColorCycle1', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_1': ( 'OBJEX_ColorCycle1', 'C', 'G_CCMUX_SHADE' ),
'input_flags_C_D_1': ( 'OBJEX_ColorCycle1', 'D', 'G_CCMUX_0' ),
'input_flags_A_A_0': ( 'OBJEX_AlphaCycle0', 'A', 'G_ACMUX_TEXEL0' ),
'input_flags_A_B_0': ( 'OBJEX_AlphaCycle0', 'B', 'G_ACMUX_TEXEL1' ),
'input_flags_A_C_0': ( 'OBJEX_AlphaCycle0', 'C', 'G_ACMUX_PRIMITIVE' ),
'input_flags_A_D_0': ( 'OBJEX_AlphaCycle0', 'D', 'G_ACMUX_TEXEL1' ),
},
'MIX_ENV': {
'input_flags_C_A_0': ( 'OBJEX_ColorCycle0', 'A', 'G_CCMUX_TEXEL0' ),
'input_flags_C_B_0': ( 'OBJEX_ColorCycle0', 'B', 'G_CCMUX_TEXEL1' ),
'input_flags_C_C_0': ( 'OBJEX_ColorCycle0', 'C', 'G_CCMUX_ENV_ALPHA' ),
'input_flags_C_D_0': ( 'OBJEX_ColorCycle0', 'D', 'G_CCMUX_TEXEL1' ),
'input_flags_C_A_1': ( 'OBJEX_ColorCycle1', 'A', 'G_CCMUX_COMBINED' ),
'input_flags_C_B_1': ( 'OBJEX_ColorCycle1', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_1': ( 'OBJEX_ColorCycle1', 'C', 'G_CCMUX_SHADE' ),
'input_flags_C_D_1': ( 'OBJEX_ColorCycle1', 'D', 'G_CCMUX_0' ),
'input_flags_A_A_0': ( 'OBJEX_AlphaCycle0', 'A', 'G_ACMUX_TEXEL0' ),
'input_flags_A_B_0': ( 'OBJEX_AlphaCycle0', 'B', 'G_ACMUX_TEXEL1' ),
'input_flags_A_C_0': ( 'OBJEX_AlphaCycle0', 'C', 'G_ACMUX_ENVIRONMENT' ),
'input_flags_A_D_0': ( 'OBJEX_AlphaCycle0', 'D', 'G_ACMUX_TEXEL1' ),
},
'MULT': {
'input_flags_C_A_0': ( 'OBJEX_ColorCycle0', 'A', 'G_CCMUX_TEXEL0' ),
'input_flags_C_B_0': ( 'OBJEX_ColorCycle0', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_0': ( 'OBJEX_ColorCycle0', 'C', 'G_CCMUX_TEXEL1' ),
'input_flags_C_D_0': ( 'OBJEX_ColorCycle0', 'D', 'G_CCMUX_0' ),
'input_flags_C_A_1': ( 'OBJEX_ColorCycle1', 'A', 'G_CCMUX_COMBINED' ),
'input_flags_C_B_1': ( 'OBJEX_ColorCycle1', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_1': ( 'OBJEX_ColorCycle1', 'C', 'G_CCMUX_SHADE' ),
'input_flags_C_D_1': ( 'OBJEX_ColorCycle1', 'D', 'G_CCMUX_0' ),
'input_flags_A_A_0': ( 'OBJEX_AlphaCycle0', 'A', 'G_ACMUX_TEXEL0' ),
'input_flags_A_B_0': ( 'OBJEX_AlphaCycle0', 'B', 'G_ACMUX_0' ),
'input_flags_A_C_0': ( 'OBJEX_AlphaCycle0', 'C', 'G_ACMUX_TEXEL1' ),
'input_flags_A_D_0': ( 'OBJEX_AlphaCycle0', 'D', 'G_ACMUX_0' ),
},
'LIGHTED': {
'input_flags_C_A_0': ( 'OBJEX_ColorCycle0', 'A', 'G_CCMUX_TEXEL0' ),
'input_flags_C_B_0': ( 'OBJEX_ColorCycle0', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_0': ( 'OBJEX_ColorCycle0', 'C', 'G_CCMUX_PRIMITIVE' ),
'input_flags_C_D_0': ( 'OBJEX_ColorCycle0', 'D', 'G_CCMUX_0' ),
'input_flags_C_A_1': ( 'OBJEX_ColorCycle1', 'A', 'G_CCMUX_COMBINED' ),
'input_flags_C_B_1': ( 'OBJEX_ColorCycle1', 'B', 'G_CCMUX_0' ),
'input_flags_C_C_1': ( 'OBJEX_ColorCycle1', 'C', 'G_CCMUX_SHADE' ),
'input_flags_C_D_1': ( 'OBJEX_ColorCycle1', 'D', 'G_CCMUX_0' ),
'input_flags_A_A_0': ( 'OBJEX_AlphaCycle0', 'A', 'G_ACMUX_TEXEL0' ),
'input_flags_A_B_0': ( 'OBJEX_AlphaCycle0', 'B', 'G_ACMUX_0' ),
'input_flags_A_C_0': ( 'OBJEX_AlphaCycle0', 'C', 'G_ACMUX_PRIMITIVE' ),
'input_flags_A_D_0': ( 'OBJEX_AlphaCycle0', 'D', 'G_ACMUX_0' ),
},
'FLAME_TEXEL': {
'input_flags_C_A_0': ( 'OBJEX_ColorCycle0', 'A', 'G_CCMUX_TEXEL1' ),
'input_flags_C_B_0': ( 'OBJEX_ColorCycle0', 'B', 'G_CCMUX_PRIMITIVE' ),
'input_flags_C_C_0': ( 'OBJEX_ColorCycle0', 'C', 'G_CCMUX_PRIM_LOD_FRAC' ),
'input_flags_C_D_0': ( 'OBJEX_ColorCycle0', 'D', 'G_CCMUX_TEXEL1' ),
'input_flags_C_A_1': ( 'OBJEX_ColorCycle1', 'A', 'G_CCMUX_PRIMITIVE' ),
'input_flags_C_B_1': ( 'OBJEX_ColorCycle1', 'B', 'G_CCMUX_ENVIRONMENT' ),
'input_flags_C_C_1': ( 'OBJEX_ColorCycle1', 'C', 'G_CCMUX_COMBINED' ),
'input_flags_C_D_1': ( 'OBJEX_ColorCycle1', 'D', 'G_CCMUX_ENVIRONMENT' ),
'input_flags_A_A_0': ( 'OBJEX_AlphaCycle0', 'A', 'G_ACMUX_TEXEL1' ),
'input_flags_A_B_0': ( 'OBJEX_AlphaCycle0', 'B', 'G_ACMUX_1' ),
'input_flags_A_C_0': ( 'OBJEX_AlphaCycle0', 'C', 'G_ACMUX_PRIM_LOD_FRAC' ),
'input_flags_A_D_0': ( 'OBJEX_AlphaCycle0', 'D', 'G_ACMUX_TEXEL0' ),
},
}
MATERIAL_TEMPLATES = {
'OPAQUE': {
'geometrymode_G_FOG': True,
'rendermode_forceblending': False,
'rendermode_blender_flag_CVG_X_ALPHA': False,
'rendermode_blender_flag_CLR_ON_CVG': False,
'rendermode_blender_flag_ALPHA_CVG_SEL': True,
'rendermode_blender_flag_CVG_DST_': 'CVG_DST_CLAMP',
'rendermode_zmode': 'OPA',
'rendermode_blending_cycle0': 'FOG_SHADE',
'rendermode_blending_cycle1': 'OPA',
},
'CLIP': {
'geometrymode_G_FOG': True,
'rendermode_forceblending': False,
'rendermode_blender_flag_CVG_X_ALPHA': True,
'rendermode_blender_flag_CLR_ON_CVG': False,
'rendermode_blender_flag_ALPHA_CVG_SEL': True,
'rendermode_blender_flag_CVG_DST_': 'CVG_DST_CLAMP',
'rendermode_zmode': 'OPA',
'rendermode_blending_cycle0': 'FOG_SHADE',
'rendermode_blending_cycle1': 'OPA',
},
'BLEND': {
'geometrymode_G_FOG': False,
'rendermode_forceblending': True,
'rendermode_blender_flag_CVG_X_ALPHA': False,
'rendermode_blender_flag_CLR_ON_CVG': True,
'rendermode_blender_flag_ALPHA_CVG_SEL': False,
'rendermode_blender_flag_CVG_DST_': 'CVG_DST_WRAP',
'rendermode_zmode': 'XLU',
'rendermode_blending_cycle0': 'XLU',
'rendermode_blending_cycle1': 'XLU',
},
'OPAQUE_XLU': {
'geometrymode_G_FOG': True,
'rendermode_forceblending': True,
'rendermode_blender_flag_CVG_X_ALPHA': False,
'rendermode_blender_flag_CLR_ON_CVG': True,
'rendermode_blender_flag_ALPHA_CVG_SEL': False,
'rendermode_blender_flag_CVG_DST_': 'CVG_DST_CLAMP',
'rendermode_zmode': 'OPA',
'rendermode_blending_cycle0': 'FOG_SHADE',
'rendermode_blending_cycle1': 'XLU',
},
}
def material_apply_template(template:str, material:bpy.types.Material):
objex = material.objex_bonus
for key, value in MATERIAL_TEMPLATES[template].items():
setattr(objex, key, value)
if key == "rendermode_blending_cycle0":
if objex.shading == "VERTEX_ALL":
setattr(objex, key, "VC_SHADE")
def combiner_apply_template(template:str, material:bpy.types.Material):
node_tree = material.node_tree
for input_flag, (node_target, alpha, value) in COMBINER_TEMPLATES[template].items():
node = node_tree.nodes[node_target]
setattr(node.inputs[alpha], input_flag, value)