@@ -52,7 +52,11 @@ def import_ngs2_tmc(context, tmc):
52
52
a .collections .new ('WGT' )
53
53
a .collections .new ('WPB' )
54
54
for b in a .bones :
55
- a .collections [b .name [:3 ]].assign (b )
55
+ try :
56
+ a .collections [b .name [:3 ]].assign (b )
57
+ except KeyError :
58
+ # Not categorized bone
59
+ pass
56
60
for c in a .collections .values ():
57
61
if not len (c .bones ):
58
62
a .collections .remove (c )
@@ -81,7 +85,7 @@ def import_ngs2_tmc(context, tmc):
81
85
82
86
for c in tmc .mtrcol .chunks :
83
87
s = f'MtrCol{ c .mtrcol_index :02} '
84
- mesh_obj [s + 'Overlay ' ] = c .overlay
88
+ mesh_obj [s + 'Mix ' ] = c .mix
85
89
mesh_obj [s + 'Diffuse' ] = c .diffuse
86
90
mesh_obj [s + 'Specular' ] = c .specular
87
91
mesh_obj [s + 'Emission Power' ] = c .diffuse_emission_power
@@ -100,7 +104,7 @@ def import_ngs2_tmc(context, tmc):
100
104
new_collection .objects .link (mo )
101
105
for i , c in enumerate (V ):
102
106
s = f'MtrCol{ i :02} '
103
- mo [s + 'Overlay ' ] = c .overlay
107
+ mo [s + 'Mix ' ] = c .mix
104
108
mo [s + 'Diffuse' ] = c .diffuse
105
109
mo [s + 'Specular' ] = c .specular
106
110
mo [s + 'Emission Power' ] = c .diffuse_emission_power
@@ -118,14 +122,13 @@ def import_ngs2_tmc(context, tmc):
118
122
f .write (tmc .ttdm .sub_container .chunks [c .chunk_index ])
119
123
else :
120
124
f .write (tmc .ttdm .chunks [c .chunk_index ])
121
- images .append (x := bpy .data .images .load (t .name ))
125
+ x = bpy .data .images .load (t .name )
126
+ images .append (x )
122
127
x .pack ()
123
- x .name = str ( mesh_obj .data .name )
128
+ x .name = mesh_obj .data .name . translate ( str . maketrans ( '.' , '_' ) )
124
129
x .filepath_raw = ''
125
130
os .remove (t .name )
126
131
127
- #import_colors_from_mtrcol(shader_node_groups, tmc.mtrcol.chunks)
128
-
129
132
# We add material slots for each OBJGEO chunk
130
133
uvnames = [ 'UVMap' , 'UVMap.001' , 'UVMap.002' , 'UVMap.003' ]
131
134
matindex = 1
@@ -216,42 +219,36 @@ def import_ngs2_tmc(context, tmc):
216
219
217
220
218
221
f = m .node_tree .nodes .new ('NodeFrame' )
219
- f .label = 'Overlay '
220
- overlay = m .node_tree .nodes .new ('ShaderNodeMix' )
221
- overlay .parent = f
222
- overlay . name = 'overlay '
223
- overlay . data_type = 'RGBA '
224
- overlay . blend_type = 'OVERLAY'
225
- m .node_tree .links .new (overlay .outputs ['Result' ], pbsdf .inputs ['Base Color' ])
226
- m .node_tree .links .new (overlay .outputs ['Result' ], pbsdf .inputs ['Emission Color' ])
227
-
228
- overlay_input = m .node_tree .nodes .new ('ShaderNodeAttribute' )
229
- overlay_input .parent = f
230
- overlay_input .attribute_type = 'OBJECT'
231
- overlay_input .attribute_name = A ('Overlay ' )
232
- m .node_tree .links .new (overlay_input .outputs ['Color' ], overlay .inputs ['B' ])
222
+ f .label = 'Mix '
223
+ diffuse_mix = m .node_tree .nodes .new ('ShaderNodeMix' )
224
+ diffuse_mix .parent = f
225
+ diffuse_mix . data_type = 'RGBA '
226
+ diffuse_mix . blend_type = 'MIX '
227
+ diffuse_mix . inputs [ 'Factor' ]. default_value = .125
228
+ m .node_tree .links .new (diffuse_mix .outputs ['Result' ], pbsdf .inputs ['Base Color' ])
229
+ m .node_tree .links .new (diffuse_mix .outputs ['Result' ], pbsdf .inputs ['Emission Color' ])
230
+
231
+ diffuse_mix_input = m .node_tree .nodes .new ('ShaderNodeAttribute' )
232
+ diffuse_mix_input .parent = f
233
+ diffuse_mix_input .attribute_type = 'OBJECT'
234
+ diffuse_mix_input .attribute_name = A ('Mix ' )
235
+ m .node_tree .links .new (diffuse_mix_input .outputs ['Color' ], diffuse_mix .inputs ['B' ])
233
236
234
237
f = m .node_tree .nodes .new ('NodeFrame' )
235
238
f .label = 'Diffuse'
236
- mul = m .node_tree .nodes .new ('ShaderNodeVectorMath' )
237
239
diffuse_multiply = m .node_tree .nodes .new ('ShaderNodeMix' )
238
240
diffuse_multiply .parent = f
239
- diffuse_multiply .name = 'multiply'
240
241
diffuse_multiply .data_type = 'RGBA'
241
242
diffuse_multiply .blend_type = 'MULTIPLY'
242
- diffuse_multiply .inputs ['Factor' ].default_value = 1
243
- m .node_tree .links .new (diffuse_multiply .outputs ['Result' ], overlay .inputs ['A' ])
243
+ diffuse_multiply .inputs [0 ].default_value = 1
244
+ m .node_tree .links .new (diffuse_multiply .outputs ['Result' ], diffuse_mix .inputs ['A' ])
244
245
m .node_tree .links .new (diffuse_multiply .outputs ['Result' ], pbsdf .inputs ['Specular Tint' ])
245
246
246
- mul .parent = f
247
- mul .operation = 'SCALE'
248
- mul .inputs ['Scale' ].default_value = 4
249
247
diffuse_multiply_input = m .node_tree .nodes .new ('ShaderNodeAttribute' )
250
248
diffuse_multiply_input .parent = f
251
249
diffuse_multiply_input .attribute_type = 'OBJECT'
252
250
diffuse_multiply_input .attribute_name = A ('Diffuse' )
253
- m .node_tree .links .new (diffuse_multiply_input .outputs ['Color' ], mul .inputs ['Vector' ])
254
- m .node_tree .links .new (mul .outputs [0 ], diffuse_multiply .inputs ['B' ])
251
+ m .node_tree .links .new (diffuse_multiply_input .outputs ['Color' ], diffuse_multiply .inputs ['B' ])
255
252
256
253
257
254
f = m .node_tree .nodes .new ('NodeFrame' )
@@ -288,12 +285,13 @@ def import_ngs2_tmc(context, tmc):
288
285
m .node_tree .links .new (div .outputs [0 ], pbsdf .inputs ['Specular IOR Level' ])
289
286
290
287
291
- mix = m .node_tree .nodes .new ('ShaderNodeMix' )
292
- mix .data_type = 'RGBA'
293
- mix .blend_type = 'ADD'
294
- mix .inputs ['Factor' ].default_value = 0
295
- mix .inputs ['B' ].default_value = 4 * (0 ,)
296
- m .node_tree .links .new (mix .outputs ['Result' ], diffuse_multiply .inputs ['A' ])
288
+ texture_mix = m .node_tree .nodes .new ('ShaderNodeMix' )
289
+ texture_mix .data_type = 'RGBA'
290
+ texture_mix .blend_type = 'ADD'
291
+ texture_mix .inputs ['Factor' ].default_value = 1
292
+ texture_mix .inputs ['A' ].default_value = 4 * (0 ,)
293
+ texture_mix .inputs ['B' ].default_value = 4 * (1 ,)
294
+ m .node_tree .links .new (texture_mix .outputs ['Result' ], diffuse_multiply .inputs ['A' ])
297
295
298
296
uv_idx = 0
299
297
for t in c .texture_info_table :
@@ -322,21 +320,20 @@ def import_ngs2_tmc(context, tmc):
322
320
m .node_tree .links .new (ti .outputs ['Color' ], inv .inputs ['Color' ])
323
321
case 3 :
324
322
ti .label = frame .label = 'Shadow Texture'
325
- mix .parent = frame
323
+ texture_mix .parent = frame
326
324
mul = m .node_tree .nodes .new ('ShaderNodeMath' )
327
325
mul .operation = 'MULTIPLY'
328
- #m.node_tree.links.new(mul.outputs[0], pbsdf.inputs['Alpha'])
329
- m .node_tree .links .new (mix .outputs ['Result' ], pbsdf .inputs ['Alpha' ])
330
- m .node_tree .links .new (mix .outputs ['Result' ], mul .inputs [0 ])
331
- m .node_tree .links .new (ti .outputs ['Color' ], mix .inputs ['A' ])
326
+ m .node_tree .links .new (texture_mix .outputs ['Result' ], mul .inputs [0 ])
332
327
m .node_tree .links .new (ti .outputs ['Alpha' ], mul .inputs [1 ])
328
+ m .node_tree .links .new (mul .outputs [0 ], pbsdf .inputs ['Alpha' ])
333
329
case 5 :
334
330
ti .label = frame .label = 'Diffuse Texture'
335
- mix . parent = frame
331
+ texture_mix . inputs [ 'Factor' ]. default_value = 0
336
332
# It always uses first uv.
337
333
uv .uv_map = uvnames [0 ]
338
- if not mix .inputs ['A' ].is_linked :
339
- m .node_tree .links .new (ti .outputs ['Color' ], mix .inputs ['A' ])
334
+ if not texture_mix .inputs ['A' ].is_linked :
335
+ texture_mix .parent = frame
336
+ m .node_tree .links .new (ti .outputs ['Color' ], texture_mix .inputs ['A' ])
340
337
m .node_tree .links .new (ti .outputs ['Alpha' ], pbsdf .inputs ['Alpha' ])
341
338
case TextureUsage .Normal :
342
339
ti .label = frame .label = 'Normal Texture'
@@ -353,20 +350,20 @@ def import_ngs2_tmc(context, tmc):
353
350
m .node_tree .links .new (ti .outputs ['Color' ], curv .inputs ['Color' ])
354
351
case TextureUsage .Multiply :
355
352
ti .label = frame .label = 'Multiplicative Texture'
356
- mix .blend_type = 'MULTIPLY'
353
+ texture_mix .blend_type = 'MULTIPLY'
357
354
gam = m .node_tree .nodes .new ('ShaderNodeGamma' )
358
355
gam .parent = frame
359
356
gam .inputs ['Gamma' ].default_value = 2.2
360
- m .node_tree .links .new (gam .outputs ['Color' ], mix .inputs ['Factor' ])
357
+ m .node_tree .links .new (gam .outputs ['Color' ], texture_mix .inputs ['Factor' ])
361
358
m .node_tree .links .new (ti .outputs ['Color' ], gam .inputs ['Color' ])
362
- m .node_tree .links .new (ti .outputs ['Color' ], mix .inputs ['B' ])
359
+ m .node_tree .links .new (ti .outputs ['Color' ], texture_mix .inputs ['B' ])
363
360
case TextureUsage .Add :
364
361
ti .label = frame .label = 'Additive Texture'
365
362
# It always uses first uv
366
363
uv .uv_map = uvnames [0 ]
367
- mix .blend_type = 'ADD'
368
- mix . inputs ['Factor' ]. default_value = 1
369
- m .node_tree .links .new (ti .outputs ['Color' ], mix .inputs ['B' ])
364
+ texture_mix .blend_type = 'ADD'
365
+ m . node_tree . links . new ( ti . outputs [ 'Alpha' ], texture_mix . inputs ['Factor' ])
366
+ m .node_tree .links .new (ti .outputs ['Color' ], texture_mix .inputs ['B' ])
370
367
case x :
371
368
raise Exception (f'Not supported texture map usage: { repr (x )} ' )
372
369
0 commit comments