Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KKBP Exporter and Plugin Updates #138

Merged
merged 127 commits into from Sep 15, 2022

Conversation

MediaMoots
Copy link
Collaborator

@MediaMoots MediaMoots commented Mar 25, 2022

This update has two changes:

  1. Fixes issues like Closed eye import issue #81
    In fact, KK always applies a small correction to the eyes even if all sliders are set to default, this update fixes this issue.
    Basically, the plugin will always clear all blend shapes before exporting.

  2. It now exports the Tears object please see Add support for the cf_O_namida_X (Tears) material #137
    May need to solve this issue first before merging or there might be errors

@MediaMoots MediaMoots marked this pull request as draft March 25, 2022 09:22
@MediaMoots
Copy link
Collaborator Author

V1.21
Fixed eye white Shape keys (so no need for manual fixing)
Fixed Sirome material name.

@MediaMoots
Copy link
Collaborator Author

V1.22
Exports the canine (Small Fangs) mesh
image

it uses the same material as the teeth.
image

@MediaMoots MediaMoots changed the title KKBP Exporter V1.20 KKBP Exporter V1.2 Mar 26, 2022
@FlailingFog
Copy link
Owner

This is a really nice fix. I'm curious what it was though, are they using the armature to make those corrections or was it something else? You mention clearing the blendshapes.
The fangs are exporting even when they're disabled. Is there a way to prevent this?
It'd be nice to have the eyewhite shapekeys fixed in the exporter because the blender script that fixes them can crash the program, but the fix didn't seem to work (only the left eyewhite works). The script I had in shapekeys.py also doesn't fix them anymore and instead just leaves them static for all shapekeys.

@MediaMoots
Copy link
Collaborator Author

MediaMoots commented Mar 28, 2022

I'm curious what it was though, are they using the armature to make those corrections or was it something else?

It was the FaceBlendShape script that was constantly correcting the eyelids to a certain value and also if the character was exported with a face ptn applied it would cause the mesh to be exported with those blendshapes, problem is that the blendshapes were supposed to be applied to the base mesh, so clearing the blendshapes restores the base mesh.

The fangs are exporting even when they're disabled. Is there a way to prevent this?

Sure, ill add a check.

It'd be nice to have the eyewhite shapekeys fixed in the exporter because the blender script that fixes them can crash the program, but the fix didn't seem to work (only the left eyewhite works).

Oh no, I thought it fixed them.
Which shapekeys are broken?
I tested all the eye_siroR.sR00_* and eye_siroL.sL00_*
which were broken before, but after the fix:
image
image

PS: the above is the raw model right after the cats import and hasn't gone through the kkbp scripts yet.

@FlailingFog
Copy link
Owner

Yeah I'm not sure what's up. All of the siroR shapekeys are still affecting the left eye (before running any scripts). I double checked I had the 1.22 exporter version and used chika as the test model.

@MediaMoots MediaMoots changed the title KKBP Exporter V1.2 KKBP Exporter Updates Apr 20, 2022
@MediaMoots
Copy link
Collaborator Author

Yeah I'm not sure what's up. All of the siroR shapekeys are still affecting the left eye (before running any scripts). I double checked I had the 1.22 exporter version and used chika as the test model.

Thats so weird, I just tested it with Chika and the siroR only affects the right side
image
image

Which Koikatsu game was chika exported from? I used the OG Better repack RX11

@MediaMoots
Copy link
Collaborator Author

V1.30

Fixed exporting fangs
Fix for #125
Fix for #151
Fix for #152

Also added support for exporting some SkinnedMeshRenderer data such as which bones/materials each renderer uses, it's a feature to help with porting characters to game engines other than Unity.

I had to shrink all the texture Postfixes to reduce file name length if not blender chops the file name.

As for the shapekeys, I'm not sure what the issue is since Chika works for me.
Would it be possible for you to try this pmx file that I exported and see if the problem persists?
Thanks!
model.zip

@MediaMoots MediaMoots mentioned this pull request Apr 21, 2022
@MediaMoots
Copy link
Collaborator Author

MediaMoots commented Apr 21, 2022

V1.32 0513821
Fix for #150
Fix for #118
Export fix for #147

The main feature of this version is that now all meshes that don't have bones (Accessories, hair, etc...) will be attached automatically to their ca_slotXX bone, gone are the days of manually setting vertex weights, haha.

Funnily enough issues #150 and #118 were the same problem just from a different angle, lol.

@MediaMoots
Copy link
Collaborator Author

MediaMoots commented Apr 21, 2022

V1.33
Fix for #139

The exporter will now export texture offset and scale data to a Json file, then the plugin will take that data and apply it to every imported texture node.
image

Some shaders might need tweaking (eg. hitomi) but I'm scared of merge conflicts, so I didn't change the blend file.

@gitburned
Copy link

For good measure I tried the same with base Chika's first outift (single outfit checked) and didn't get issues importing Outfit 00 (even the custom card I originally exported before discovering the error worked when I exported that Outfit 00), but the categorization error remained.

@gitburned
Copy link

UPDATE: Trying to export all outfits from base chika and it imports into Blender but I get this error idk what it means cause all outfits are in at least:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 306, in move_accessory_bones
    outfit_id_array = bone['KKBP outfit ID'].to_list()
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 334, in execute
    move_accessory_bones(context)
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 310, in move_accessory_bones
    bone['KKBP outfit ID'] = [outfit_or_hair['KKBP outfit ID']]
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

Error: Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 306, in move_accessory_bones
    outfit_id_array = bone['KKBP outfit ID'].to_list()
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 334, in execute
    move_accessory_bones(context)
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 310, in move_accessory_bones
    bone['KKBP outfit ID'] = [outfit_or_hair['KKBP outfit ID']]
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\importbuttons.py", line 100, in execute
    bpy.ops.kkb.cleanarmature('INVOKE_DEFAULT'),
  File "C:\Program Files (x86)\Steam\steamapps\common\Blender\3.2\scripts\modules\bpy\ops.py", line 113, in __call__
    ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 306, in move_accessory_bones
    outfit_id_array = bone['KKBP outfit ID'].to_list()
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 334, in execute
    move_accessory_bones(context)
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 310, in move_accessory_bones
    bone['KKBP outfit ID'] = [outfit_or_hair['KKBP outfit ID']]
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'


@LegionInstaller
Copy link

UPDATE: Trying to export all outfits from base chika and it imports into Blender but I get this error idk what it means cause all outfits are in at least:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 306, in move_accessory_bones
    outfit_id_array = bone['KKBP outfit ID'].to_list()
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 334, in execute
    move_accessory_bones(context)
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 310, in move_accessory_bones
    bone['KKBP outfit ID'] = [outfit_or_hair['KKBP outfit ID']]
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

Error: Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 306, in move_accessory_bones
    outfit_id_array = bone['KKBP outfit ID'].to_list()
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 334, in execute
    move_accessory_bones(context)
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 310, in move_accessory_bones
    bone['KKBP outfit ID'] = [outfit_or_hair['KKBP outfit ID']]
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\importbuttons.py", line 100, in execute
    bpy.ops.kkb.cleanarmature('INVOKE_DEFAULT'),
  File "C:\Program Files (x86)\Steam\steamapps\common\Blender\3.2\scripts\modules\bpy\ops.py", line 113, in __call__
    ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 306, in move_accessory_bones
    outfit_id_array = bone['KKBP outfit ID'].to_list()
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 334, in execute
    move_accessory_bones(context)
  File "C:\Users\*****\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons\KK-Blender-Shader-Pack-pluginupdate\importing\cleanarmature.py", line 310, in move_accessory_bones
    bone['KKBP outfit ID'] = [outfit_or_hair['KKBP outfit ID']]
KeyError: 'bpy_struct[key]: key "KKBP outfit ID" not found'

Are you having problems with Baking the Textures ? , using the newest KKBP Version ?

merge permalight and dark into one file
move body alpha files out to textures group
@MediaMoots MediaMoots mentioned this pull request Sep 5, 2022
Fixes an error on some cards where the gag eyes don't have materials.
cats context fix when cats not installed
use AM over AM_00 if available
@gitburned
Copy link

On a more suggestion side, I think besides all or single outfits, there should be options to pick and choose which outfits to export, what do you think?

@LegionInstaller
Copy link

On a more suggestion side, I think besides all or single outfits, there should be options to pick and choose which outfits to export, what do you think?

Sounds Nice

@MediaMoots
Copy link
Collaborator Author

On a more suggestion side, I think besides all or single outfits, there should be options to pick and choose which outfits to export, what do you think?

Good idea!

@FlailingFog
Copy link
Owner

Ok so, just checked the code, the order is arbitrary, the way KK shows and hides clothes is quite complicated, it starts with the ReferenceInfo

Thanks, that helped a lot!

@FlailingFog
Copy link
Owner

@MediaMoots I think everything is working at the moment, so I'm going to merge this into the master branch. Is there anything else you want to change before I do that?

@MediaMoots
Copy link
Collaborator Author

MediaMoots commented Sep 15, 2022

@FlailingFog

Yup, everything seems to work great!

I'll work on the selective outfit export feature, but that will take some time, so feel free to merge this PR, I will make a new PR later.

Thanks! We added so much, eh? haha
Virgin V5 vs Chad V6 XD jk

@MediaMoots
Copy link
Collaborator Author

MediaMoots commented Sep 15, 2022

Oh yeah, it seems that Blender 3.3 works without issues too, so I'll be developing with 3.3 from now on, if that's alright with you.

Bug fix
@MediaMoots
Copy link
Collaborator Author

@FlailingFog

Card:
81622243_p12

Actually, I found an issue, try importing a character (HachikujiMayoi) with multiple outfits with these settings:
image

Error:
Blender Foundation\Blender\3.3\scripts\addons\KK Blender Porter Pack\importing\separatebody.py", line 126, in separate_materials

I suspect the issue is due to the incorrect material sometimes being separated:
image

@ghost
Copy link

ghost commented Sep 15, 2022

Settings I used and errors I get, maybe this is a linux issue, maybe it isn't. I really don't know.

Screenshot_20220915_195942

use single outline disabled error
Error:          Unknown python error occurred
Traceback (most recent call last):
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importeverything.py", line 1254, in execute
    add_outlines(single_outline_mode)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importeverything.py", line 979, in add_outlines
    mod.thickness = 0.0005
AttributeError: 'UVWarpModifier' object has no attribute 'thickness'

Error: Traceback (most recent call last):
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importeverything.py", line 1254, in execute
    add_outlines(single_outline_mode)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importeverything.py", line 979, in add_outlines
    mod.thickness = 0.0005
AttributeError: 'UVWarpModifier' object has no attribute 'thickness'

Traceback (most recent call last):
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importbuttons.py", line 112, in execute
    bpy.ops.kkb.importeverything('INVOKE_DEFAULT'),
  File "/home/metabox/Documents/blender/3.3/scripts/modules/bpy/ops.py", line 111, in __call__
    ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Traceback (most recent call last):
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importeverything.py", line 1254, in execute
    add_outlines(single_outline_mode)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importeverything.py", line 979, in add_outlines
    mod.thickness = 0.0005
AttributeError: 'UVWarpModifier' object has no attribute 'thickness'

I really hope this can be fixed eventually.

shader compilation error linux
Converting Colors...
ERROR (gpu.shader): pyGPUShader FragShader: 
      | 
   98 |         vec3 lutcol_bot = texture2D( lut, coord_bot ).rgb;
      |                     ^
      | Error: no function with name 'texture2D'
      | Error: type mismatch
      | 
   99 |         vec3 lutcol_top = texture2D( lut, coord_top ).rgb;
      |                     ^
      | Error: no function with name 'texture2D'
      | Error: type mismatch
      | 
  101 |         vec3 lutColor = mix(lutcol_bot, lutcol_top, coord_frac.z);
      |                       ^
      | `lutcol_bot' used uninitialized
      | 
      |         vec3 lutColor = mix(lutcol_bot, lutcol_top, coord_frac.z);
      |                                   ^
      | `lutcol_top' used uninitialized
      | 
  107 |         vec4 texRGBA = texture2D(tex0, gl_FragCoord.xy / u_resolution);
      |                  ^
      | Error: no function with name 'texture2D'
      | 
  109 |         vec3 texColor = to_srgb(texRGBA.rgb);
      |                           ^
      | `texRGBA' used uninitialized
      | 
  115 |         out_Color = vec4(newColor.rgb, texRGBA.a);
      |                                  ^
      | `texRGBA' used uninitialized


Error:          Unknown python error occurred
Traceback (most recent call last):
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 770, in execute
    convert_main_textures(lut_light)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 501, in convert_main_textures
    image_to_KK(image, lut_light)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 105, in image_to_KK
    shader = gpu.types.GPUShader(vertex_default, current_code)
Exception: Shader Compile Error, see console for more details

Error: Traceback (most recent call last):
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 770, in execute
    convert_main_textures(lut_light)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 501, in convert_main_textures
    image_to_KK(image, lut_light)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 105, in image_to_KK
    shader = gpu.types.GPUShader(vertex_default, current_code)
Exception: Shader Compile Error, see console for more details

Traceback (most recent call last):
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importbuttons.py", line 113, in execute
    bpy.ops.kkb.importcolors('EXEC_DEFAULT'),
  File "/home/metabox/Documents/blender/3.3/scripts/modules/bpy/ops.py", line 111, in __call__
    ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Traceback (most recent call last):
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 770, in execute
    convert_main_textures(lut_light)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 501, in convert_main_textures
    image_to_KK(image, lut_light)
  File "/home/metabox/.config/blender/3.3/scripts/addons/KK-Blender-Shader-Pack-pluginupdate/importing/importcolors.py", line 105, in image_to_KK
    shader = gpu.types.GPUShader(vertex_default, current_code)
Exception: Shader Compile Error, see console for more details

modifier fix
count maximum enum value before separating alternate clothes
@FlailingFog
Copy link
Owner

I suspect the issue is due to the incorrect material sometimes being separated:

It looks like the length of KK_referenceinfodata varies per character, so I added a check for the length. I also downloaded 3.3 myself

Virgin V5 vs Chad V6 XD jk

Seriously! Thanks for all these upgrades. This is like half a year's worth of work

use single outline disabled error

I'm not getting that error so I can't know for sure, but it should be fixed

@FlailingFog FlailingFog merged commit d96e69e into FlailingFog:master Sep 15, 2022
@MediaMoots
Copy link
Collaborator Author

🎉 🎉 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment