Skip to content

Commit f8f4d86

Browse files
authored
Merge pull request #93 from soupday/dev
Dev
2 parents 9e60f48 + fb7fd92 commit f8f4d86

File tree

6 files changed

+133
-94
lines changed

6 files changed

+133
-94
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
### 1.6.2
5+
- URP Amplify shader fix for when there is no main light.
6+
- Work around to intermittent CC4 specular export issue when exporting with 'Bake diffuse maps from skin color' option (which is enabled by default now).
7+
48
### 1.6.1
59
- Magica Cloth 2 support for hair physics.
610
- Magica Cloth and collider navigation tools added.

Editor/Importer.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ private void ConnectDefaultHairMaterial(GameObject obj, string sourceName, Mater
14641464
if (matJson.PathExists("Textures/Normal/Strength"))
14651465
mat.SetFloat("_NormalScale", matJson.GetFloatValue("Textures/Normal/Strength") / 100f);
14661466
}
1467-
}
1467+
}
14681468

14691469
private void ConnectHQSkinMaterial(GameObject obj, string sourceName, Material sharedMat, Material mat,
14701470
MaterialType materialType, QuickJSON matJson)
@@ -1594,14 +1594,42 @@ private void ConnectHQSkinMaterial(GameObject obj, string sourceName, Material s
15941594

15951595
if (matJson != null)
15961596
{
1597+
float specular = matJson.GetFloatValue("Custom Shader/Variable/_Specular");
1598+
bool specularBakeZero = false;
1599+
1600+
// work around CC4 Head specular export bug, when exporting with bake skin option
1601+
if (specular == 0.0f && materialType == MaterialType.Head)
1602+
{
1603+
float skinSpecular = 0.0f;
1604+
QuickJSON materialsJson = jsonData.FindParentOf(matJson);
1605+
if (materialsJson != null)
1606+
{
1607+
QuickJSON skinJson = null;
1608+
if (materialsJson.PathExists("Std_Skin_Body"))
1609+
skinJson = materialsJson.GetObjectAtPath("Std_Skin_Body");
1610+
else if (materialsJson.PathExists("Std_Skin_Arm"))
1611+
skinJson = materialsJson.GetObjectAtPath("Std_Skin_Arm");
1612+
else if (materialsJson.PathExists("Std_Skin_Leg"))
1613+
skinJson = materialsJson.GetObjectAtPath("Std_Skin_Leg");
1614+
if (skinJson != null)
1615+
skinSpecular = skinJson.GetFloatValue("Custom Shader/Variable/_Specular");
1616+
}
1617+
1618+
if (skinSpecular != 0.0f)
1619+
{
1620+
Util.LogWarn("Specular export bug in skin material, setting head specular to: " + skinSpecular);
1621+
specular = skinSpecular;
1622+
specularBakeZero = true;
1623+
}
1624+
}
1625+
15971626
mat.SetFloatIf("_AOStrength", Mathf.Clamp01(matJson.GetFloatValue("Textures/AO/Strength") / 100f));
15981627
if (matJson.PathExists("Textures/Glow/Texture Path"))
15991628
mat.SetColorIf("_EmissiveColor", Color.white * (matJson.GetFloatValue("Textures/Glow/Strength") / 100f));
16001629
if (matJson.PathExists("Textures/Normal/Strength"))
16011630
mat.SetFloatIf("_NormalStrength", matJson.GetFloatValue("Textures/Normal/Strength") / 100f);
16021631
mat.SetFloatIf("_MicroNormalTiling", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Tiling"));
1603-
mat.SetFloatIf("_MicroNormalStrength", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Strength"));
1604-
float specular = matJson.GetFloatValue("Custom Shader/Variable/_Specular");
1632+
mat.SetFloatIf("_MicroNormalStrength", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Strength"));
16051633
float smoothnessMax = Util.CombineSpecularToSmoothness(specular, ValueByPipeline(1f, 0.9f, 1f));
16061634
mat.SetFloatIf("_SmoothnessMax", smoothnessMax);
16071635
//float secondarySmoothness = 0.85f * smoothnessMax;
@@ -1617,7 +1645,10 @@ private void ConnectHQSkinMaterial(GameObject obj, string sourceName, Material s
16171645

16181646
if (materialType == MaterialType.Head)
16191647
{
1620-
mat.SetFloatIf("_ColorBlendStrength", matJson.GetFloatValue("Custom Shader/Variable/BaseColor Blend2 Strength"));
1648+
// specular bake bug bakes color blend into diffuse
1649+
float colorBlenderStrength = matJson.GetFloatValue("Custom Shader/Variable/BaseColor Blend2 Strength");
1650+
if (specularBakeZero) colorBlenderStrength = 0.0f;
1651+
mat.SetFloatIf("_ColorBlendStrength", colorBlenderStrength);
16211652
mat.SetFloatIf("_NormalBlendStrength", matJson.GetFloatValue("Custom Shader/Variable/NormalMap Blend Strength"));
16221653
mat.SetFloatIf("_MouthCavityAO", matJson.GetFloatValue("Custom Shader/Variable/Inner Mouth Ao"));
16231654
mat.SetFloatIf("_NostrilCavityAO", matJson.GetFloatValue("Custom Shader/Variable/Nostril Ao"));

Editor/Physics.cs

Lines changed: 85 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -953,87 +953,89 @@ private void AddUnityClothInstance()
953953
}
954954

955955

956-
private void DoCloth(GameObject clothTarget, string meshName)
957-
{
958-
SkinnedMeshRenderer renderer = clothTarget.GetComponent<SkinnedMeshRenderer>();
959-
if (!renderer) return;
960-
Mesh mesh = renderer.sharedMesh;
961-
if (!mesh) return;
962-
963-
List<WeightMapper.PhysicsSettings> settingsList = new List<WeightMapper.PhysicsSettings>();
964-
965-
bool hasPhysics = false;
966-
967-
for (int i = 0; i < mesh.subMeshCount; i++)//
968-
{
969-
Material mat = renderer.sharedMaterials[i];
970-
971-
if (!mat) continue;
972-
string sourceName = mat.name;
973-
if (sourceName.iContains("_2nd_Pass")) continue;
974-
if (sourceName.iContains("_1st_Pass"))
975-
{
976-
sourceName = sourceName.Remove(sourceName.IndexOf("_1st_Pass"));
977-
}
978-
979-
foreach (SoftPhysicsData data in softPhysics)
980-
{
981-
if (data.materialName == sourceName &&
982-
data.meshName == meshName &&
983-
CanAddPhysics(data))
984-
{
985-
WeightMapper.PhysicsSettings settings = new WeightMapper.PhysicsSettings();
986-
987-
settings.name = sourceName;
988-
settings.activate = data.activate;
989-
settings.gravity = data.gravity;
990-
settings.selfCollision = Importer.USE_SELF_COLLISION ? data.selfCollision : false;
991-
settings.softRigidCollision = data.softRigidCollision;
992-
settings.softRigidMargin = data.softRigidMargin;
993-
994-
if (data.isHair)
995-
{
996-
// hair meshes degenerate quickly if less than full stiffness
997-
// (too dense, too many verts?)
998-
settings.bending = 0f;
999-
settings.stretch = 0f;
1000-
}
1001-
else
1002-
{
1003-
settings.bending = data.bending;
1004-
settings.stretch = data.stretch;
1005-
}
1006-
1007-
settings.solverFrequency = data.solverFrequency;
1008-
settings.stiffnessFrequency = data.stiffnessFrequency;
1009-
settings.mass = data.mass;
1010-
settings.friction = data.friction;
1011-
settings.damping = data.damping;
1012-
settings.selfMargin = data.selfMargin;
1013-
settings.maxDistance = 20f;
1014-
settings.maxPenetration = 10f;
1015-
settings.colliderThreshold = PHYSICS_WEIGHT_MAP_DETECT_COLLIDER_THRESHOLD;
1016-
1017-
Texture2D weightMap = GetTextureFrom(data.weightMapPath, data.materialName, "WeightMap", out string texName, true);
1018-
if (!weightMap) weightMap = Texture2D.blackTexture;
1019-
settings.weightMap = weightMap;
1020-
1021-
settingsList.Add(settings);
1022-
hasPhysics = true;
1023-
}
1024-
}
1025-
}
1026-
1027-
if (hasPhysics)
1028-
{
1029-
WeightMapper mapper = clothTarget.GetComponent<WeightMapper>();
1030-
if (!mapper) mapper = clothTarget.AddComponent<WeightMapper>();
1031-
1032-
mapper.settings = settingsList.ToArray();
1033-
mapper.characterGUID = characterGUID;
1034-
mapper.ApplyWeightMap();
1035-
}
1036-
}
956+
private void DoCloth(GameObject clothTarget, string meshName)
957+
{
958+
SkinnedMeshRenderer renderer = clothTarget.GetComponent<SkinnedMeshRenderer>();
959+
if (!renderer) return;
960+
Mesh mesh = renderer.sharedMesh;
961+
if (!mesh) return;
962+
963+
List<WeightMapper.PhysicsSettings> settingsList = new List<WeightMapper.PhysicsSettings>();
964+
965+
bool hasPhysics = false;
966+
967+
for (int i = 0; i < mesh.subMeshCount; i++)
968+
{
969+
if (i >= renderer.sharedMaterials.Length) break;
970+
971+
Material mat = renderer.sharedMaterials[i];
972+
973+
if (!mat) continue;
974+
string sourceName = mat.name;
975+
if (sourceName.iContains("_2nd_Pass")) continue;
976+
if (sourceName.iContains("_1st_Pass"))
977+
{
978+
sourceName = sourceName.Remove(sourceName.IndexOf("_1st_Pass"));
979+
}
980+
981+
foreach (SoftPhysicsData data in softPhysics)
982+
{
983+
if (data.materialName == sourceName &&
984+
data.meshName == meshName &&
985+
CanAddPhysics(data))
986+
{
987+
WeightMapper.PhysicsSettings settings = new WeightMapper.PhysicsSettings();
988+
989+
settings.name = sourceName;
990+
settings.activate = data.activate;
991+
settings.gravity = data.gravity;
992+
settings.selfCollision = Importer.USE_SELF_COLLISION ? data.selfCollision : false;
993+
settings.softRigidCollision = data.softRigidCollision;
994+
settings.softRigidMargin = data.softRigidMargin;
995+
996+
if (data.isHair)
997+
{
998+
// hair meshes degenerate quickly if less than full stiffness
999+
// (too dense, too many verts?)
1000+
settings.bending = 0f;
1001+
settings.stretch = 0f;
1002+
}
1003+
else
1004+
{
1005+
settings.bending = data.bending;
1006+
settings.stretch = data.stretch;
1007+
}
1008+
1009+
settings.solverFrequency = data.solverFrequency;
1010+
settings.stiffnessFrequency = data.stiffnessFrequency;
1011+
settings.mass = data.mass;
1012+
settings.friction = data.friction;
1013+
settings.damping = data.damping;
1014+
settings.selfMargin = data.selfMargin;
1015+
settings.maxDistance = 20f;
1016+
settings.maxPenetration = 10f;
1017+
settings.colliderThreshold = PHYSICS_WEIGHT_MAP_DETECT_COLLIDER_THRESHOLD;
1018+
1019+
Texture2D weightMap = GetTextureFrom(data.weightMapPath, data.materialName, "WeightMap", out string texName, true);
1020+
if (!weightMap) weightMap = Texture2D.blackTexture;
1021+
settings.weightMap = weightMap;
1022+
1023+
settingsList.Add(settings);
1024+
hasPhysics = true;
1025+
}
1026+
}
1027+
}
1028+
1029+
if (hasPhysics)
1030+
{
1031+
WeightMapper mapper = clothTarget.GetComponent<WeightMapper>();
1032+
if (!mapper) mapper = clothTarget.AddComponent<WeightMapper>();
1033+
1034+
mapper.settings = settingsList.ToArray();
1035+
mapper.characterGUID = characterGUID;
1036+
mapper.ApplyWeightMap();
1037+
}
1038+
}
10371039

10381040
private void AddMagicaMeshCloth()
10391041
{
@@ -1111,6 +1113,8 @@ private bool CanAddMagicaCloth(GameObject clothTarget, string meshName) // adds
11111113

11121114
for (int i = 0; i < mesh.subMeshCount; i++)
11131115
{
1116+
if (i >= renderer.sharedMaterials.Length) break;
1117+
11141118
Material mat = renderer.sharedMaterials[i];
11151119

11161120
if (!mat) continue;

Editor/Pipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public enum MaterialQuality { None, Default, High, Baked }
4040

4141
public static class Pipeline
4242
{
43-
public const string VERSION = "1.6.1";
43+
public const string VERSION = "1.6.2";
4444

4545
#if HDRP_10_5_0_OR_NEWER
4646
// version

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ Links
1717
[HDRP Version](https://github.com/soupday/cc_unity_tools_HDRP)
1818

1919
Note: There are two verions of the HDRP package
20-
- [**CC Unity Tools HDRP10**](https://github.com/soupday/cc_unity_tools_HDRP/releases/tag/1.6.1.HDRP10) for Unity 2020.3+
21-
- [**CC Unity Tools HDRP12**](https://github.com/soupday/cc_unity_tools_HDRP/releases/tag/1.6.1.HDRP12) for Unity 2021.2+
20+
- [**CC Unity Tools HDRP10**](https://github.com/soupday/cc_unity_tools_HDRP/releases/tag/1.6.2.HDRP10) for Unity 2020.3+
21+
- [**CC Unity Tools HDRP12**](https://github.com/soupday/cc_unity_tools_HDRP/releases/tag/1.6.2.HDRP12) for Unity 2021.2+
2222

2323
The main repository contains the HDRP10 version. See the releases page for the HDRP12 version.
2424

2525
[URP Version](https://github.com/soupday/cc_unity_tools_URP)
2626

2727
Note: There are four verions of the URP package
28-
- [**CC Unity Tools URP10**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.1.URP10) for Unity 2020.3+
29-
- [**CC Unity Tools URP12**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.1.URP12) for Unity 2021.2+
30-
- [**CC Unity Tools URP14**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.1.URP14) for Unity 2022.3+
31-
- [**CC Unity Tools URP15**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.1.URP15) for Unity 2023.1+
28+
- [**CC Unity Tools URP10**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.2.URP10) for Unity 2020.3+
29+
- [**CC Unity Tools URP12**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.2.URP12) for Unity 2021.2+
30+
- [**CC Unity Tools URP14**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.2.URP14) for Unity 2022.3+
31+
- [**CC Unity Tools URP15**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.2.URP15) for Unity 2023.1+
3232

3333
The main repository contains the URP10 version. See the releases page for the URP12/14/15 version.
3434

3535
[3D/Built-in Version](https://github.com/soupday/cc_unity_tools_3D)
3636

3737
The built-in pipeline version is for Unity 2019.4 and upwards.
38-
- [**CC Unity Tools 3D**](https://github.com/soupday/cc_unity_tools_3D/releases/tag/1.6.1) for Unity 2019.4+
38+
- [**CC Unity Tools 3D**](https://github.com/soupday/cc_unity_tools_3D/releases/tag/1.6.2) for Unity 2019.4+
3939

4040
How it works
4141
============

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.soupday.cc3_unity_tools",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"displayName": "CC/iC Unity Tools HDRP",
55
"description": "Unity importer for Character Creator 3 & 4 and iClone 7 and 8.",
66
"unity": "2020.3",

0 commit comments

Comments
 (0)