Files
KKBP_Importer/extras/imageconvert.py
小煜 5d9e09e9c3 feat: Add KoikatsuBlenderPipeline addon with import/export functionality
- Add core addon files (__init__.py, KKPanel.py, preferences.py, common.py)
- Add import pipeline with armature, mesh, and material modification modules
- Add export pipeline with material baking and FBX preparation utilities
- Add material combiner tool for texture atlas generation and optimization
- Add extras utilities for animation, rigging, and asset management
- Add bone orientation data from better_fbx for accurate skeletal structure
- Add comprehensive documentation and wiki with multi-language support (EN, JP, ZH)
- Add animation library retargeting lists for ARP and Rokoko motion capture
- Add Rigify integration scripts for advanced rigging workflows
- Add shader file (KK Shader V8.0.blend) for material rendering
- Add manifest and license files for addon distribution
- Add changelog documenting version history and improvements
- Initialize complete Blender addon project for Koikatsu character import/export
2025-12-06 15:26:19 +08:00

63 lines
2.9 KiB
Python

from pathlib import Path
import bpy
from .. import common as c
from ..importing.modifymaterial import modify_material
class image_convert(bpy.types.Operator):
bl_idname = "kkbp.imageconvert"
bl_label = "Convert light image"
bl_description = "Click this to saturate the currently loaded image using the selected Koikatsu LUT"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
c.kklog("Converting image: ".format(context.space_data.image))
scene = context.scene.kkbp
lut_selection = scene.image_dropdown
if lut_selection == 'A':
lut_choice = 'Lut_TimeDay.png'
elif lut_selection == 'B':
lut_choice = 'Lut_TimeNight.png'
else:
lut_choice = 'Lut_TimeSunset.png'
image = context.space_data.image
image.reload()
image.colorspace_settings.name = 'sRGB'
# Use code from importcolors to convert the current image
modify_material.load_luts(lut_choice, lut_choice)
# Need to run image_to_KK twice for the first image due to a weird bug
modify_material.image_to_KK(image, lut_choice)
new_pixels, width, height = modify_material.image_to_KK(image, lut_choice)
image.pixels = new_pixels
#image.save()
return {'FINISHED'}
class image_dark_convert(bpy.types.Operator):
bl_idname = "kkbp.imagedarkconvert"
bl_label = "Convert dark image"
bl_description = "Click this to create a dark version of the currently loaded maintex image. The new image will end in 'MT_DT.png' The new image will be automatically loaded to the dark color node group"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
body = bpy.data.objects['Body']
c.kklog("Converting image: ".format(context.space_data.image))
image = context.space_data.image
material_name = image.name[:-10]
try:
shadow_color = [body['KKBP shadow colors'][material_name]['r'], body['KKBP shadow colors'][material_name]['g'], body['KKBP shadow colors'][material_name]['b']]
darktex = modify_material.create_darktex(bpy.data.images[image.name], shadow_color)
material_name = 'KK ' + image.name[:-10]
bpy.data.materials[material_name].node_tree.nodes['Gentex'].node_tree.nodes['Darktex'].image = darktex
bpy.data.materials[material_name].node_tree.nodes['Shader'].node_tree.nodes['colorsDark'].inputs['Use dark maintex?'].default_value = 1
bpy.data.materials[material_name].node_tree.nodes['Shader'].node_tree.nodes['colorsDark'].inputs['Ignore colormask?'].default_value = 1
except:
c.kklog('Tried to create a dark version of {} but there was no shadow color available. \nDark color conversion is only available for Koikatsu images that end in \'_MT_CT.png\''.format(image.name), type='error')
return {'FINISHED'}