Skip to content

Commit d2061f4

Browse files
author
Nozomi Miyamori
committed
release version 2.1.0
* Fix an error when importing a map model. * Improve NGS2 material emulation.
1 parent 3b18c1f commit d2061f4

File tree

3 files changed

+50
-53
lines changed

3 files changed

+50
-53
lines changed

src/ninja_gaiden_tmc/blender_manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version = "1.0.0"
22

33
id = "ninja_gaiden_tmc"
4-
version = "2.0.2"
4+
version = "2.1.0"
55
name = "Ninja Gaiden Sigma 2 TMC Format"
66
tagline = "Import Ninja Gaiden Sigma 2 TMC"
77
maintainer = "Nozomi Miyamori"

src/ninja_gaiden_tmc/importer.py

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ def import_ngs2_tmc(context, tmc):
5252
a.collections.new('WGT')
5353
a.collections.new('WPB')
5454
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
5660
for c in a.collections.values():
5761
if not len(c.bones):
5862
a.collections.remove(c)
@@ -81,7 +85,7 @@ def import_ngs2_tmc(context, tmc):
8185

8286
for c in tmc.mtrcol.chunks:
8387
s = f'MtrCol{c.mtrcol_index:02} '
84-
mesh_obj[s + 'Overlay'] = c.overlay
88+
mesh_obj[s + 'Mix'] = c.mix
8589
mesh_obj[s + 'Diffuse'] = c.diffuse
8690
mesh_obj[s + 'Specular'] = c.specular
8791
mesh_obj[s + 'Emission Power'] = c.diffuse_emission_power
@@ -100,7 +104,7 @@ def import_ngs2_tmc(context, tmc):
100104
new_collection.objects.link(mo)
101105
for i, c in enumerate(V):
102106
s = f'MtrCol{i:02} '
103-
mo[s + 'Overlay'] = c.overlay
107+
mo[s + 'Mix'] = c.mix
104108
mo[s + 'Diffuse'] = c.diffuse
105109
mo[s + 'Specular'] = c.specular
106110
mo[s + 'Emission Power'] = c.diffuse_emission_power
@@ -118,14 +122,13 @@ def import_ngs2_tmc(context, tmc):
118122
f.write(tmc.ttdm.sub_container.chunks[c.chunk_index])
119123
else:
120124
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)
122127
x.pack()
123-
x.name = str(mesh_obj.data.name)
128+
x.name = mesh_obj.data.name.translate(str.maketrans('.', '_'))
124129
x.filepath_raw = ''
125130
os.remove(t.name)
126131

127-
#import_colors_from_mtrcol(shader_node_groups, tmc.mtrcol.chunks)
128-
129132
# We add material slots for each OBJGEO chunk
130133
uvnames = [ 'UVMap', 'UVMap.001', 'UVMap.002', 'UVMap.003' ]
131134
matindex = 1
@@ -216,42 +219,36 @@ def import_ngs2_tmc(context, tmc):
216219

217220

218221
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'])
233236

234237
f = m.node_tree.nodes.new('NodeFrame')
235238
f.label = 'Diffuse'
236-
mul = m.node_tree.nodes.new('ShaderNodeVectorMath')
237239
diffuse_multiply = m.node_tree.nodes.new('ShaderNodeMix')
238240
diffuse_multiply.parent = f
239-
diffuse_multiply.name = 'multiply'
240241
diffuse_multiply.data_type = 'RGBA'
241242
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'])
244245
m.node_tree.links.new(diffuse_multiply.outputs['Result'], pbsdf.inputs['Specular Tint'])
245246

246-
mul.parent = f
247-
mul.operation = 'SCALE'
248-
mul.inputs['Scale'].default_value = 4
249247
diffuse_multiply_input = m.node_tree.nodes.new('ShaderNodeAttribute')
250248
diffuse_multiply_input.parent = f
251249
diffuse_multiply_input.attribute_type = 'OBJECT'
252250
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'])
255252

256253

257254
f = m.node_tree.nodes.new('NodeFrame')
@@ -288,12 +285,13 @@ def import_ngs2_tmc(context, tmc):
288285
m.node_tree.links.new(div.outputs[0], pbsdf.inputs['Specular IOR Level'])
289286

290287

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'])
297295

298296
uv_idx = 0
299297
for t in c.texture_info_table:
@@ -322,21 +320,20 @@ def import_ngs2_tmc(context, tmc):
322320
m.node_tree.links.new(ti.outputs['Color'], inv.inputs['Color'])
323321
case 3:
324322
ti.label = frame.label = 'Shadow Texture'
325-
mix.parent = frame
323+
texture_mix.parent = frame
326324
mul = m.node_tree.nodes.new('ShaderNodeMath')
327325
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])
332327
m.node_tree.links.new(ti.outputs['Alpha'], mul.inputs[1])
328+
m.node_tree.links.new(mul.outputs[0], pbsdf.inputs['Alpha'])
333329
case 5:
334330
ti.label = frame.label = 'Diffuse Texture'
335-
mix.parent = frame
331+
texture_mix.inputs['Factor'].default_value = 0
336332
# It always uses first uv.
337333
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'])
340337
m.node_tree.links.new(ti.outputs['Alpha'], pbsdf.inputs['Alpha'])
341338
case TextureUsage.Normal:
342339
ti.label = frame.label = 'Normal Texture'
@@ -353,20 +350,20 @@ def import_ngs2_tmc(context, tmc):
353350
m.node_tree.links.new(ti.outputs['Color'], curv.inputs['Color'])
354351
case TextureUsage.Multiply:
355352
ti.label = frame.label = 'Multiplicative Texture'
356-
mix.blend_type = 'MULTIPLY'
353+
texture_mix.blend_type = 'MULTIPLY'
357354
gam = m.node_tree.nodes.new('ShaderNodeGamma')
358355
gam.parent = frame
359356
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'])
361358
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'])
363360
case TextureUsage.Add:
364361
ti.label = frame.label = 'Additive Texture'
365362
# It always uses first uv
366363
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'])
370367
case x:
371368
raise Exception(f'Not supported texture map usage: {repr(x)}')
372369

src/ninja_gaiden_tmc/tcmlib/ngs2/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def _gen_chunks(chunks):
386386
mtrcol_index, xrefs)
387387

388388
class MtrColChunk(NamedTuple):
389-
overlay: tuple[float]
389+
mix: tuple[float]
390390
diffuse: tuple[float]
391391
specular: tuple[float]
392392
# unknown0x30: tuple[float]
@@ -572,7 +572,7 @@ class MTRLCHNGMetaData(NamedTuple):
572572

573573
# Same as MtrColChunk but w/o mtrcol_index and xrefs
574574
class MTRLCHNGElement(NamedTuple):
575-
overlay: tuple[float]
575+
mix: tuple[float]
576576
diffuse: tuple[float]
577577
specular: tuple[float]
578578
# unknown0x30: tuple[float]

0 commit comments

Comments
 (0)