FlailingFog / KK-Blender-Porter-Pack

Plugin pack for exporting Koikatsu characters to Blender.
310 stars 29 forks source link

How to fix the issue with the eyes/Separate the eye materials properly #219

Closed TheMaskedMan00 closed 1 year ago

TheMaskedMan00 commented 1 year ago

If you want to actually separate the eye material, you need to actually modify the kk plugin. the way koikatsu does the eyes is this:

Both eyes and both eyewhites actually do use the same material, but they are seperate meshes: cf_Ohitomi_R : Eyewhite Right cf_Ohitomi_L: Eyewhite Left cf_Ohitomi_L02: Left Eye cf_Ohitomi_R02: Right Eye

In unity, you can have 2 different meshes that use the same material, but have different values. The way to get around this is by simply searching for the eye meshes, and getting their respective materials.

Below is a snippet of my mod, and below that is the explanation:

var Meshs = Resources.FindObjectsOfTypeAll<Transform>();
                foreach (Transform M in Meshs)
                {
                    if (M.gameObject.name == "chaF_001" || M.gameObject.name == "chaM_001") //im assuiming that male characters root object is named chaM_001 since the female is chaF_001, but i am not 100% sure xD. I will have to check
                    {

                        foreach (Renderer Rend in M.GetComponentsInChildren<Renderer>(true))
                        {
                            string InputDirMain = $"{Environment.CurrentDirectory}\\Materials\\Input\\";
                            foreach (Material MM in Rend.sharedMaterials)
                            {
if (Rend.name == "cf_Ohitomi_L")
                                {

                                    string InputDir = $"{Environment.CurrentDirectory}\\Materials\\Input\\Templates\\";
                                    Logger.LogMessage($"Creating File {MatName} => Template EyeWhite Assigned Left.mat");
                                    string Text = File.ReadAllText($"{InputDir}EyeW.mat");
                                    Text = Text.Replace($"    - _Color: {{r: 1, g: 1, b: 1, a: 1}}\n    - _CustomAmbient: {{r: 0.6666667, g: 0.6666667, b: 0.6666667, a: 1}}\n    - _EmissionColor: {{r: 0, g: 0, b: 0, a: 1}}\n    - _shadowcolor: {{r: 0.6298235, g: 0.6403289, b: 0.747, a: 1}}", $"    - _Color: {{r: {MM.GetVector("_Color").x}, g: {MM.GetVector("_Color").y}, b: {MM.GetVector("_Color").z}, a: {MM.GetVector("_Color").w}}}\n    - _CustomAmbient: {{r: 0.6666667, g: 0.6666667, b: 0.6666667, a: 1}}\n    - _EmissionColor: {{r: 0, g: 0, b: 0, a: 1}}\n    - _shadowcolor: {{r: {MM.GetVector("_shadowcolor").x}, g: {MM.GetVector("_shadowcolor").y}, b: {MM.GetVector("_shadowcolor").z}, a: {MM.GetVector("_shadowcolor").w}}}");
                                    File.WriteAllText($"{InputDirMain}{CharacterName}\\EyeWhite Assigned Left.mat", Text);
                                    continue;

                                }
                                if (Rend.name == "cf_Ohitomi_R")
                                {

                                    string InputDir = $"{Environment.CurrentDirectory}\\Materials\\Input\\Templates\\";
                                    Logger.LogMessage($"Creating File {MatName} => Template EyeWhite Assigned Right.mat");
                                    string Text = File.ReadAllText($"{InputDir}EyeW.mat");
                                    Text = Text.Replace($"    - _Color: {{r: 1, g: 1, b: 1, a: 1}}\n    - _CustomAmbient: {{r: 0.6666667, g: 0.6666667, b: 0.6666667, a: 1}}\n    - _EmissionColor: {{r: 0, g: 0, b: 0, a: 1}}\n    - _shadowcolor: {{r: 0.6298235, g: 0.6403289, b: 0.747, a: 1}}", $"    - _Color: {{r: {MM.GetVector("_Color").x}, g: {MM.GetVector("_Color").y}, b: {MM.GetVector("_Color").z}, a: {MM.GetVector("_Color").w}}}\n    - _CustomAmbient: {{r: 0.6666667, g: 0.6666667, b: 0.6666667, a: 1}}\n    - _EmissionColor: {{r: 0, g: 0, b: 0, a: 1}}\n    - _shadowcolor: {{r: {MM.GetVector("_shadowcolor").x}, g: {MM.GetVector("_shadowcolor").y}, b: {MM.GetVector("_shadowcolor").z}, a: {MM.GetVector("_shadowcolor").w}}}");
                                    File.WriteAllText($"{InputDirMain}{CharacterName}\\EyeWhite Assigned Right.mat", Text);
                                    continue;

                                }
                                if (Rend.name == "cf_Ohitomi_L02")
                                {

                                    string InputDir = $"{Environment.CurrentDirectory}\\Materials\\Input\\Templates\\";
                                    Logger.LogMessage($"Creating File {MatName} => Template Eye Assigned Left.mat");
                                    string Text = File.ReadAllText($"{InputDir}Eye.mat");
                                    Text = Text.Replace($"    - _MainTex:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _MetallicGlossMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _OcclusionMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _ParallaxMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _expression:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _overtex1:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _overtex2:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}", $"    - _MainTex:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: {MM.GetTextureScale("_MainTex").x}, y: {MM.GetTextureScale("_MainTex").y}}}\n        m_Offset: {{x: {MM.GetTextureOffset("_MainTex").x}, y: {MM.GetTextureOffset("_MainTex").y}}}\n    - _MetallicGlossMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _OcclusionMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _ParallaxMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _expression:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: {MM.GetTextureScale("_expression").x}, y: {MM.GetTextureScale("_expression").y}}}\n        m_Offset: {{x: {MM.GetTextureOffset("_expression").x}, y: {MM.GetTextureOffset("_expression").y}}}\n    - _overtex1:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: {MM.GetTextureScale("_overtex1").x}, y: {MM.GetTextureScale("_overtex1").y}}}\n        m_Offset: {{x: {MM.GetTextureOffset("_overtex1").x}, y: {MM.GetTextureOffset("_overtex1").y}}}\n    - _overtex2:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: {MM.GetTextureScale("_overtex2").x}, y: {MM.GetTextureScale("_overtex2").y}}}\n        m_Offset: {{x: {MM.GetTextureOffset("_overtex2").x}, y: {MM.GetTextureOffset("_overtex2").y}}}");
                                    Text = Text.Replace($"    - _BumpScale: 1\n    - _Cutoff: 0.5\n    - _DetailNormalMapScale: 1\n    - _DstBlend: 0\n    - _EmissionIntensity: 1\n    - _ExpressionDepth: 1\n    - _ExpressionSize: 0.35\n    - _GlossMapScale: 1\n    - _Glossiness: 0.5\n    - _GlossyReflections: 1\n    - _Metallic: 0\n    - _Mode: 0\n    - _OcclusionStrength: 1\n    - _Parallax: 0.02\n    - _SmoothnessTextureChannel: 0\n    - _SpecularHighlights: 1\n    - _SrcBlend: 1\n    - _UVSec: 0\n    - _UseRampForLights: 1\n    - _ZWrite: 1\n    - _exppower: 1\n    - _isHighLight: 0\n    - _rotation: 0", $"    - _BumpScale: 1\n    - _Cutoff: 0.5\n    - _DetailNormalMapScale: 1\n    - _DstBlend: 0\n    - _EmissionIntensity: 1\n    - _ExpressionDepth: {MM.GetFloat("_ExpressionDepth")}\n    - _ExpressionSize: {MM.GetFloat("_ExpressionSize")}\n    - _GlossMapScale: 1\n    - _Glossiness: 0.5\n    - _GlossyReflections: 1\n    - _Metallic: 0\n    - _Mode: 0\n    - _OcclusionStrength: 1\n    - _Parallax: 0.02\n    - _SmoothnessTextureChannel: 0\n    - _SpecularHighlights: 1\n    - _SrcBlend: 1\n    - _UVSec: 0\n    - _UseRampForLights: 1\n    - _ZWrite: 1\n    - _exppower: {MM.GetFloat("_exppower")}\n    - _isHighLight: {MM.GetFloat("_isHighLight")}\n    - _rotation: {MM.GetFloat("_rotation")}");
                                    Text = Text.Replace($"    - _Color: {{r: 1, g: 1, b: 1, a: 1}}\n    - _CustomAmbient: {{r: 0.6666667, g: 0.6666667, b: 0.6666667, a: 1}}\n    - _EmissionColor: {{r: 0, g: 0, b: 0, a: 1}}\n    - _overcolor1: {{r: 1, g: 1, b: 1, a: 1}}\n    - _overcolor2: {{r: 1, g: 1, b: 1, a: 1}}\n    - _shadowcolor: {{r: 0.6298235, g: 0.6403289, b: 0.747, a: 1}}", $"    - _Color: {{r: 1, g: 1, b: 1, a: 1}}\n    - _CustomAmbient: {{r: 0.6666667, g: 0.6666667, b: 0.6666667, a: 1}}\n    - _EmissionColor: {{r: 0, g: 0, b: 0, a: 1}}\n    - _overcolor1: {{r: {MM.GetVector("_overcolor1").x}, g: {MM.GetVector("_overcolor1").y}, b: {MM.GetVector("_overcolor1").z}, a: {MM.GetVector("_overcolor1").w}}}\n    - _overcolor2: {{r: {MM.GetVector("_overcolor2").x}, g: {MM.GetVector("_overcolor2").y}, b: {MM.GetVector("_overcolor2").z}, a: {MM.GetVector("_overcolor2").w}}}\n    - _shadowcolor: {{r: {MM.GetVector("_shadowcolor").x}, g: {MM.GetVector("_shadowcolor").y}, b: {MM.GetVector("_shadowcolor").z}, a: {MM.GetVector("_shadowcolor").w}}}");
                                    File.WriteAllText($"{InputDirMain}{CharacterName}\\Eye Assigned Left.mat", Text);
                                    continue;

                                }
                                if (Rend.name == "cf_Ohitomi_R02")
                                {

                                    string InputDir = $"{Environment.CurrentDirectory}\\Materials\\Input\\Templates\\";
                                    Logger.LogMessage($"Creating File {MatName} => Template Eye Assigned Right.mat");
                                    string Text = File.ReadAllText($"{InputDir}Eye.mat");
                                    Text = Text.Replace($"    - _MainTex:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _MetallicGlossMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _OcclusionMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _ParallaxMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _expression:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _overtex1:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _overtex2:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}", $"    - _MainTex:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: {MM.GetTextureScale("_MainTex").x}, y: {MM.GetTextureScale("_MainTex").y}}}\n        m_Offset: {{x: {MM.GetTextureOffset("_MainTex").x}, y: {MM.GetTextureOffset("_MainTex").y}}}\n    - _MetallicGlossMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _OcclusionMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _ParallaxMap:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: 1, y: 1}}\n        m_Offset: {{x: 0, y: 0}}\n    - _expression:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: {MM.GetTextureScale("_expression").x}, y: {MM.GetTextureScale("_expression").y}}}\n        m_Offset: {{x: {MM.GetTextureOffset("_expression").x}, y: {MM.GetTextureOffset("_expression").y}}}\n    - _overtex1:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: {MM.GetTextureScale("_overtex1").x}, y: {MM.GetTextureScale("_overtex1").y}}}\n        m_Offset: {{x: {MM.GetTextureOffset("_overtex1").x}, y: {MM.GetTextureOffset("_overtex1").y}}}\n    - _overtex2:\n        m_Texture: {{fileID: 0}}\n        m_Scale: {{x: {MM.GetTextureScale("_overtex2").x}, y: {MM.GetTextureScale("_overtex2").y}}}\n        m_Offset: {{x: {MM.GetTextureOffset("_overtex2").x}, y: {MM.GetTextureOffset("_overtex2").y}}}");
                                    Text = Text.Replace($"    - _BumpScale: 1\n    - _Cutoff: 0.5\n    - _DetailNormalMapScale: 1\n    - _DstBlend: 0\n    - _EmissionIntensity: 1\n    - _ExpressionDepth: 1\n    - _ExpressionSize: 0.35\n    - _GlossMapScale: 1\n    - _Glossiness: 0.5\n    - _GlossyReflections: 1\n    - _Metallic: 0\n    - _Mode: 0\n    - _OcclusionStrength: 1\n    - _Parallax: 0.02\n    - _SmoothnessTextureChannel: 0\n    - _SpecularHighlights: 1\n    - _SrcBlend: 1\n    - _UVSec: 0\n    - _UseRampForLights: 1\n    - _ZWrite: 1\n    - _exppower: 1\n    - _isHighLight: 0\n    - _rotation: 0", $"    - _BumpScale: 1\n    - _Cutoff: 0.5\n    - _DetailNormalMapScale: 1\n    - _DstBlend: 0\n    - _EmissionIntensity: 1\n    - _ExpressionDepth: {MM.GetFloat("_ExpressionDepth")}\n    - _ExpressionSize: {MM.GetFloat("_ExpressionSize")}\n    - _GlossMapScale: 1\n    - _Glossiness: 0.5\n    - _GlossyReflections: 1\n    - _Metallic: 0\n    - _Mode: 0\n    - _OcclusionStrength: 1\n    - _Parallax: 0.02\n    - _SmoothnessTextureChannel: 0\n    - _SpecularHighlights: 1\n    - _SrcBlend: 1\n    - _UVSec: 0\n    - _UseRampForLights: 1\n    - _ZWrite: 1\n    - _exppower: {MM.GetFloat("_exppower")}\n    - _isHighLight: {MM.GetFloat("_isHighLight")}\n    - _rotation: {MM.GetFloat("_rotation")}");
                                    Text = Text.Replace($"    - _Color: {{r: 1, g: 1, b: 1, a: 1}}\n    - _CustomAmbient: {{r: 0.6666667, g: 0.6666667, b: 0.6666667, a: 1}}\n    - _EmissionColor: {{r: 0, g: 0, b: 0, a: 1}}\n    - _overcolor1: {{r: 1, g: 1, b: 1, a: 1}}\n    - _overcolor2: {{r: 1, g: 1, b: 1, a: 1}}\n    - _shadowcolor: {{r: 0.6298235, g: 0.6403289, b: 0.747, a: 1}}", $"    - _Color: {{r: 1, g: 1, b: 1, a: 1}}\n    - _CustomAmbient: {{r: 0.6666667, g: 0.6666667, b: 0.6666667, a: 1}}\n    - _EmissionColor: {{r: 0, g: 0, b: 0, a: 1}}\n    - _overcolor1: {{r: {MM.GetVector("_overcolor1").x}, g: {MM.GetVector("_overcolor1").y}, b: {MM.GetVector("_overcolor1").z}, a: {MM.GetVector("_overcolor1").w}}}\n    - _overcolor2: {{r: {MM.GetVector("_overcolor2").x}, g: {MM.GetVector("_overcolor2").y}, b: {MM.GetVector("_overcolor2").z}, a: {MM.GetVector("_overcolor2").w}}}\n    - _shadowcolor: {{r: {MM.GetVector("_shadowcolor").x}, g: {MM.GetVector("_shadowcolor").y}, b: {MM.GetVector("_shadowcolor").z}, a: {MM.GetVector("_shadowcolor").w}}}");
                                    File.WriteAllText($"{InputDirMain}{CharacterName}\\Eye Assigned Right.mat", Text);
                                    continue;

                                }

I know the code is really messy but I will break it down since this is just the code from my material exporter

var Meshs = Resources.FindObjectsOfTypeAll<Transform>(); //Get everything in the scene
                foreach (Transform M in Meshs)
                {
                    if (M.gameObject.name == "chaF_001" || M.gameObject.name == "chaM_001") //Find the character
                    {

                        foreach (Renderer Rend in M.GetComponentsInChildren<Renderer>(true))  //Get the renderer components
                        {

                            foreach (Material MM in Rend.sharedMaterials) // loop through all the materials that each renderer is using
                            { 
                              if (Rend.name == "cf_Ohitomi_L") //Looks for the Left Eyewhite
                                {
                                  //This material (MM) is the one being used by the left eyewhite

                                }

                              if (Rend.name == "cf_Ohitomi_R") //Looks for the Right Eyewhite
                                {
                                  //This material (MM) is the one being used by the right eyewhite

                                }

                              if (Rend.name == "cf_Ohitomi_L02) //Looks for the Left Eye
                                {
                                  //This material(MM) is the one being used by the left eye

                                }
                                if (Rend.name == "cf_Ohitomi_R02) //Looks for the Right Eye
                                {
                                  //This material(MM) is the one being used by the Right eye

                                }
}
}
//We already found the character so we can stop looking
return;

}
}

Sadly, i cannot see where i can put this into your existing plugin as you only include the .dll and not the source. But feel free to use this code. I would love to help you guys with this project as our views on the game and its potential are very similar.

MediaMoots commented 1 year ago

@FlailingFog Has already fixed this issue a while ago though? https://github.com/FlailingFog/KK-Blender-Porter-Pack/pull/138/commits/418b4e88f29f504e277283c74b22e17f99a73e4f

TheMaskedMan00 commented 1 year ago

@FlailingFog Has already fixed this issue a while ago though? 418b4e8

oh, my bad, I did not know

FlailingFog commented 1 year ago

The eye materials are separate in the blender plugin, but I haven't changed importeverything.py to use the data in KK_MaterialData.json yet so the same values are still loaded in for both. I also don't believe the exporter plugin gives you two eye maintex/ot1/etc images if they're different colors or pupil types

MediaMoots commented 1 year ago

I also don't believe the exporter plugin gives you two eye maintex/ot1/etc images if they're different colors or pupil types @FlailingFog

Oh yeah... but are there cards like that? If so, do you have one?

FlailingFog commented 1 year ago

I don't have one in mind, but I remember trying with a heterochromia character and it gave me one image. There's a toggle on the bottom of the Iris category that lets you edit eyes individually: image

MediaMoots commented 1 year ago

I don't have one in mind, but I remember trying with a heterochromia character and it gave me one image. There's a toggle on the bottom of the Iris category that lets you edit eyes individually: image

Cool! I'll make the eye textures export separately, thanks for letting me know!

TheMaskedMan00 commented 1 year ago

I also don't believe the exporter plugin gives you two eye maintex/ot1/etc images if they're different colors or pupil types @FlailingFog

Oh yeah... but are there cards like that? If so, do you have one?

Yes there are cards that can have diff main Tex for the eyes, and not just the main Tex, all the textures can be different for each eye. Eye white is a pretty rare thing to have diff Color’s for each eye white, so we can prob ignore the textures in the eye whites, but the eyes themselves can have all different textures so it is important to export all the textures and values within to their corresponding side. Also while looking through material editor settings and code, I found out that it replaces all materials with a copy to Improve performance, which is why we always get (instance) (instance). It is a setting that can be turned off but in terms of interference it might be the cause of some issues, for example making new materials for things that use the same materials. But that’s just a hunch.

FlailingFog commented 1 year ago

Cool! I'll make the eye textures export separately, thanks for letting me know!

Thanks for adding this in. It appears the materialdata.json wasn't needed