Skip to content

Commit

Permalink
auto apply .chara colors to colorsetter shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
wikid24 committed Nov 23, 2023
1 parent 4f9d30d commit a89ec5c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
14 changes: 7 additions & 7 deletions ffxiv_mmd_tools_helper/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,22 +718,22 @@ def draw(self, context):
grid.prop(colorsetter_face_lip_color_mix,"default_value",text='Lip Color Mix',slider=True)
grid.prop(colorsetter_face_lip_lightdark,"default_value",text='Lip Light/Dark',slider=True)
grid.prop(colorsetter_face_lip_brightness,"default_value",text='Lip Brightness/Opacity',slider=True)
grid.prop(colorsetter_face_facepaint_mix,"default_value",text='Facepaint Mix',slider=True)
grid.prop(colorsetter_face_facepaint_color,"default_value",text='Facepaint Color')
grid.prop(colorsetter_face_facepaint_lightdark,"default_value",text='Facepaint Light/Dark')
grid.prop(colorsetter_face_facepaint_brightness,"default_value",text='Facepaint Brightness/Opacity')
#grid.prop(colorsetter_face_facepaint_mix,"default_value",text='Facepaint Mix',slider=True)
#grid.prop(colorsetter_face_facepaint_color,"default_value",text='Facepaint Color')
#grid.prop(colorsetter_face_facepaint_lightdark,"default_value",text='Facepaint Light/Dark')
#grid.prop(colorsetter_face_facepaint_brightness,"default_value",text='Facepaint Brightness/Opacity')


grid = box.grid_flow(columns=2,align=True)
grid.prop(colorsetter_face_diffuse_node,"image",text='Diffuse')
grid.prop(colorsetter_face_multi_node,"image",text='Multi')
grid.prop(colorsetter_face_normal_node,"image",text='Normal')
grid.prop(colorsetter_face_facepaint_node,"image",text='Facepaint')
#grid.prop(colorsetter_face_facepaint_node,"image",text='Facepaint')
grid.operator("ffxiv_mmd.update_colorsetter_image_node",text='',icon='FILEBROWSER').image_node_name = colorsetter_face_diffuse_node.name
grid.operator("ffxiv_mmd.update_colorsetter_image_node",text='',icon='FILEBROWSER').image_node_name = colorsetter_face_multi_node.name
grid.operator("ffxiv_mmd.update_colorsetter_image_node",text='',icon='FILEBROWSER').image_node_name = colorsetter_face_normal_node.name
grid.operator("ffxiv_mmd.update_colorsetter_image_node",text='',icon='FILEBROWSER').image_node_name = colorsetter_face_facepaint_node.name
#grid.prop(colorsetter_eye_node.node_tree.nodes['Normal Map'].inputs['Strength'],"default_value",text='Normal Strength',slider=True)
#grid.operator("ffxiv_mmd.update_colorsetter_image_node",text='',icon='FILEBROWSER').image_node_name = colorsetter_face_facepaint_node.name


#Colorsetter Face Accent panel
if colorsetter_faceacc_node:
Expand Down
42 changes: 37 additions & 5 deletions ffxiv_mmd_tools_helper/shaders_colorsetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,16 @@ def update_image_node_file(image_node,file_path):
if image is None:
image = bpy.data.images.load(file_path) # Load the image from the selected file path
image_node.image = image
image_node.image.colorspace_settings.name = 'Non-Color'

if file_path.endswith(("_d.png", "_d.bmp", "_d.dds")):
return
else:
image_node.image.colorspace_settings.name = 'Non-Color'
return


from . import import_ffxiv_charafile

def add_colorsetter_shader(context,shader_type):

shader_type_list = ['eye','face','hair','faceacc','tail','skin']
Expand All @@ -494,6 +500,7 @@ def add_colorsetter_shader(context,shader_type):

active_material = context.active_object.active_material
active_object = context.active_object
active_armature = model.findArmature(active_object)

#check if material is a colorsetter node material
if active_material.name.startswith(f"colorsetter_{shader_type}_"):
Expand Down Expand Up @@ -528,12 +535,37 @@ def add_colorsetter_shader(context,shader_type):
#name the instance of the node group within the material to colorsetter_{shader_type}_node_instance
if colorsetter_material.node_tree.nodes['Group'].node_tree.name.startswith(f"colorsetter_{shader_type}_node_group"):
colorsetter_material.node_tree.nodes['Group'].name = f"colorsetter_{shader_type}_node_instance"
node_group_instance = colorsetter_material.node_tree.nodes.get(f"colorsetter_{shader_type}_node_instance")

#set the default color values to the ones from the .chara file that were stored as custom properties on the armature
if active_armature:
if shader_type == 'skin':
node_group_instance.inputs['Skin Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_skin'])

if shader_type == 'eye':
set_colorsetter_eye_textures(active_object)
node_group_instance.inputs['Eye Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_eyes'])
node_group_instance.inputs['Odd Eye Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_odd_eye'])

if shader_type == 'face':
node_group_instance.inputs['Skin Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_skin'])
node_group_instance.inputs['Lip Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_lips'])
node_group_instance.inputs['Face Paint Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_facepaint'])


if shader_type == 'eye':
set_colorsetter_eye_textures(active_object)
if shader_type == 'hair':
node_group_instance.inputs['Hair Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_hair'])
node_group_instance.inputs['Highlights Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_hair_highlights'])

if shader_type == 'hair':
print ("hair time wheeeee")

if shader_type == 'faceacc':
node_group_instance.inputs['Hair Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_hair'])
node_group_instance.inputs['Tattoo Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_tattoo_limbal'])
node_group_instance.inputs['Limbal Ring Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_tattoo_limbal'])

if shader_type == 'tail':
node_group_instance.inputs['Hair Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_hair'])
node_group_instance.inputs['Highlight Color'].default_value = import_ffxiv_charafile.hex_to_rgba(active_armature.data['color_hex_hair_highlights'])

else:
print(f"Material '{shader_type_mat_dict[shader_type]}' not found in the source file.")
Expand Down

0 comments on commit a89ec5c

Please sign in to comment.