Skip to content

Commit

Permalink
Support for character compatibility mode
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveModding committed Nov 16, 2024
1 parent b6612d8 commit 5ff10e5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 49 deletions.
10 changes: 5 additions & 5 deletions MeddleTools/blend_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ def import_shaders():
section = "\\NodeTree\\"

for n in node_groups.nodegroups:
if n in bpy.data.node_groups:
print(n + " already in file")
if n.name in bpy.data.node_groups:
print(n.name + " already in file")
continue

print("Appending " + n)
print("Appending " + n.name)
bpy.ops.wm.append(
filepath = blendfile + section + n,
filename = n,
filepath = blendfile + section + n.name,
filename = n.name,
directory = blendfile + section,
do_reuse_local_id = True
)
Expand Down
87 changes: 44 additions & 43 deletions MeddleTools/node_groups.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import bpy
from os import path

meddleSkinName = 'meddle skin.shpk'
meddleFaceSkinName = 'meddle face skin.shpk'
meddleHairName = 'meddle hair.shpk'
meddleFaceHairName = 'meddle face hair.shpk'
meddleIrisName = 'meddle iris.shpk'
meddleCharacterTattooName = 'meddle charactertattoo.shpk'
meddleCharacterOcclusionName = 'meddle characterocclusion.shpk'
meddleCharacterName = 'meddle character.shpk'
meddleBgName = 'meddle bg.shpk'
meddleBgColorChangeName = 'meddle bgcolorchange.shpk'

pngMappings = 'PngMappings'
floatRgbMappings = 'FloatRgbMappings'
boolToFloatMappings = 'BoolToFloatMappings'

nodegroups: list[str] = [
meddleSkinName,
meddleFaceSkinName,
meddleHairName,
meddleFaceHairName,
meddleIrisName,
meddleCharacterTattooName,
meddleCharacterOcclusionName,
meddleBgName,
meddleBgColorChangeName,
meddleCharacterName
]

class NodeGroup:
def __init__(self, name: str, mapping_definitions: list):
Expand Down Expand Up @@ -139,8 +112,7 @@ def apply(self, groupNode, properties):
if len(value_arr) == 3:
value_arr.append(1.0)

groupNode.inputs[self.color_dest].default_value = value_arr

groupNode.inputs[self.color_dest].default_value = value_arr

class ColorSetMapping:
def __init__(self, property_name: str, id_texture_name: str, ramp_name_a: str, ramp_name_b: str, ramp_a_dest: str, ramp_b_dest:str, index_g_dest: str):
Expand Down Expand Up @@ -286,7 +258,7 @@ def apply(self, groupNode, properties):
groupNode.inputs[self.float_dest].default_value = 0.0

meddle_skin = NodeGroup(
meddleSkinName,
'meddle skin.shpk',
[
PngMapping('g_SamplerDiffuse_PngCachePath', 'g_SamplerDiffuse', 'g_SamplerDiffuse_alpha', 'sRGB'),
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', None, 'Non-Color'),
Expand All @@ -296,7 +268,7 @@ def apply(self, groupNode, properties):
)

meddle_face_skin = NodeGroup(
meddleFaceSkinName,
'meddle face skin.shpk',
[
PngMapping('g_SamplerDiffuse_PngCachePath', 'g_SamplerDiffuse', 'g_SamplerDiffuse_alpha', 'sRGB'),
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', 'g_SamplerNormal_alpha', 'Non-Color'),
Expand All @@ -308,7 +280,7 @@ def apply(self, groupNode, properties):
)

meddle_iris = NodeGroup(
meddleIrisName,
'meddle iris.shpk',
[
PngMapping('g_SamplerDiffuse_PngCachePath', 'g_SamplerDiffuse', None, 'sRGB'),
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', None, 'Non-Color'),
Expand All @@ -319,7 +291,7 @@ def apply(self, groupNode, properties):
)

meddle_hair = NodeGroup(
meddleHairName,
'meddle hair.shpk',
[
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', 'g_SamplerNormal_alpha', 'Non-Color'),
PngMapping('g_SamplerMask_PngCachePath', 'g_SamplerMask', 'g_SamplerMask_alpha', 'Non-Color'),
Expand All @@ -329,7 +301,7 @@ def apply(self, groupNode, properties):
)

meddle_face_hair = NodeGroup(
meddleFaceHairName,
'meddle face hair.shpk',
[
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', 'g_SamplerNormal_alpha', 'Non-Color'),
PngMapping('g_SamplerMask_PngCachePath', 'g_SamplerMask', 'g_SamplerMask_alpha', 'Non-Color'),
Expand All @@ -338,29 +310,40 @@ def apply(self, groupNode, properties):
)

meddle_character_occlusion = NodeGroup(
meddleCharacterOcclusionName,
'meddle characterocclusion.shpk',
[
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', 'g_SamplerNormal_alpha', 'Non-Color'),
]
)

meddle_character_tattoo = NodeGroup(
meddleCharacterTattooName,
'meddle charactertattoo.shpk',
[
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', 'g_SamplerNormal_alpha', 'Non-Color'),
]
)

meddle_character = NodeGroup(
meddleCharacterName,
'meddle character.shpk',
[
ColorSetMapping('ColorTable', 'g_SamplerIndex_PngCachePath', 'TableA', 'TableB', 'color_a', 'color_b', 'id_mix'),
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', None, 'Non-Color'),
PngMapping('g_SamplerMask_PngCachePath', 'g_SamplerMask', None, 'Non-Color'),
]
)

meddle_character_compatibility = NodeGroup(
'meddle character_compatibility.shpk',
[
PngMapping('g_SamplerDiffuse_PngCachePath', 'g_SamplerDiffuse', 'g_SamplerDiffuse_Alpha', 'sRGB'),
PngMapping('g_SamplerNormal_PngCachePath', 'g_SamplerNormal', None, 'Non-Color'),
PngMapping('g_SamplerMask_PngCachePath', 'g_SamplerMask', None, 'Non-Color'),
]
)


meddle_bg = NodeGroup(
meddleBgName,
'meddle bg.shpk',
[
PngMapping('g_SamplerColorMap0', 'g_SamplerColorMap0', 'g_SamplerColorMap0_alpha', 'sRGB'),
PngMapping('g_SamplerColorMap1', 'g_SamplerColorMap1', 'g_SamplerColorMap1_alpha', 'sRGB'),
Expand All @@ -373,14 +356,28 @@ def apply(self, groupNode, properties):
)

meddle_bg_colorchange = NodeGroup(
meddleBgColorChangeName,
'meddle bgcolorchange.shpk',
[
PngMapping('g_SamplerColorMap0', 'g_SamplerColorMap0', 'g_SamplerColorMap0_alpha', 'sRGB'),
PngMapping('g_SamplerNormalMap0', 'g_SamplerNormalMap0', None, 'Non-Color'),
PngMapping('g_SamplerSpecularMap0', 'g_SamplerSpecularMap0', None, 'Non-Color'),
FloatRgbMapping('StainColor', 'StainColor'),
]
)

nodegroups: list[NodeGroup] = [
meddle_skin,
meddle_face_skin,
meddle_iris,
meddle_hair,
meddle_face_hair,
meddle_character_occlusion,
meddle_character_tattoo,
meddle_character,
meddle_bg,
meddle_bg_colorchange,
meddle_character_compatibility
]

def matchShader(mat):
if mat is None:
Expand All @@ -389,6 +386,8 @@ def matchShader(mat):
properties = mat
shaderPackage = properties["ShaderPackage"]

print(f"Matching shader {shaderPackage} on material {mat.name}")

if shaderPackage is None:
return None

Expand Down Expand Up @@ -421,10 +420,12 @@ def matchShader(mat):
if shaderPackage == 'characterocclusion.shpk':
return meddle_character_occlusion

if shaderPackage == 'character.shpk':
return meddle_character

if shaderPackage == 'characterlegacy.shpk':
if shaderPackage == 'character.shpk' or shaderPackage == 'characterlegacy.shpk':
# check if GetValuesTextureType is 'Compatibility'
if 'GetValuesTextureType' in properties:
if properties['GetValuesTextureType'] == 'Compatibility':
return meddle_character_compatibility

return meddle_character

if shaderPackage == 'bg.shpk':
Expand Down
3 changes: 2 additions & 1 deletion MeddleTools/shader_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def execute(self, context):
continue

for slot in obj.material_slots:
shpkMtrlFixer(obj, slot.material, self.directory)
if slot.material is not None:
shpkMtrlFixer(obj, slot.material, self.directory)

return {'FINISHED'}

Expand Down
Binary file modified MeddleTools/shaders.blend
Binary file not shown.

0 comments on commit 5ff10e5

Please sign in to comment.