Skip to content

Commit

Permalink
Merge pull request #93 from soupday/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
soupday committed Mar 12, 2024
2 parents 9e60f48 + fb7fd92 commit f8f4d86
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 94 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

### 1.6.2
- URP Amplify shader fix for when there is no main light.
- Work around to intermittent CC4 specular export issue when exporting with 'Bake diffuse maps from skin color' option (which is enabled by default now).

### 1.6.1
- Magica Cloth 2 support for hair physics.
- Magica Cloth and collider navigation tools added.
Expand Down
39 changes: 35 additions & 4 deletions Editor/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ private void PrepBlenderTextures(string sourceName, QuickJSON matJson)
if (matJson.PathExists("Textures/Normal/Strength"))
mat.SetFloat("_NormalScale", matJson.GetFloatValue("Textures/Normal/Strength") / 100f);
}
}
}

private void ConnectHQSkinMaterial(GameObject obj, string sourceName, Material sharedMat, Material mat,
MaterialType materialType, QuickJSON matJson)
Expand Down Expand Up @@ -1594,14 +1594,42 @@ private void PrepBlenderTextures(string sourceName, QuickJSON matJson)

if (matJson != null)
{
float specular = matJson.GetFloatValue("Custom Shader/Variable/_Specular");
bool specularBakeZero = false;

// work around CC4 Head specular export bug, when exporting with bake skin option
if (specular == 0.0f && materialType == MaterialType.Head)
{
float skinSpecular = 0.0f;
QuickJSON materialsJson = jsonData.FindParentOf(matJson);
if (materialsJson != null)
{
QuickJSON skinJson = null;
if (materialsJson.PathExists("Std_Skin_Body"))
skinJson = materialsJson.GetObjectAtPath("Std_Skin_Body");
else if (materialsJson.PathExists("Std_Skin_Arm"))
skinJson = materialsJson.GetObjectAtPath("Std_Skin_Arm");
else if (materialsJson.PathExists("Std_Skin_Leg"))
skinJson = materialsJson.GetObjectAtPath("Std_Skin_Leg");
if (skinJson != null)
skinSpecular = skinJson.GetFloatValue("Custom Shader/Variable/_Specular");
}

if (skinSpecular != 0.0f)
{
Util.LogWarn("Specular export bug in skin material, setting head specular to: " + skinSpecular);
specular = skinSpecular;
specularBakeZero = true;
}
}

mat.SetFloatIf("_AOStrength", Mathf.Clamp01(matJson.GetFloatValue("Textures/AO/Strength") / 100f));
if (matJson.PathExists("Textures/Glow/Texture Path"))
mat.SetColorIf("_EmissiveColor", Color.white * (matJson.GetFloatValue("Textures/Glow/Strength") / 100f));
if (matJson.PathExists("Textures/Normal/Strength"))
mat.SetFloatIf("_NormalStrength", matJson.GetFloatValue("Textures/Normal/Strength") / 100f);
mat.SetFloatIf("_MicroNormalTiling", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Tiling"));
mat.SetFloatIf("_MicroNormalStrength", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Strength"));
float specular = matJson.GetFloatValue("Custom Shader/Variable/_Specular");
mat.SetFloatIf("_MicroNormalStrength", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Strength"));
float smoothnessMax = Util.CombineSpecularToSmoothness(specular, ValueByPipeline(1f, 0.9f, 1f));
mat.SetFloatIf("_SmoothnessMax", smoothnessMax);
//float secondarySmoothness = 0.85f * smoothnessMax;
Expand All @@ -1617,7 +1645,10 @@ private void PrepBlenderTextures(string sourceName, QuickJSON matJson)

if (materialType == MaterialType.Head)
{
mat.SetFloatIf("_ColorBlendStrength", matJson.GetFloatValue("Custom Shader/Variable/BaseColor Blend2 Strength"));
// specular bake bug bakes color blend into diffuse
float colorBlenderStrength = matJson.GetFloatValue("Custom Shader/Variable/BaseColor Blend2 Strength");
if (specularBakeZero) colorBlenderStrength = 0.0f;
mat.SetFloatIf("_ColorBlendStrength", colorBlenderStrength);
mat.SetFloatIf("_NormalBlendStrength", matJson.GetFloatValue("Custom Shader/Variable/NormalMap Blend Strength"));
mat.SetFloatIf("_MouthCavityAO", matJson.GetFloatValue("Custom Shader/Variable/Inner Mouth Ao"));
mat.SetFloatIf("_NostrilCavityAO", matJson.GetFloatValue("Custom Shader/Variable/Nostril Ao"));
Expand Down
166 changes: 85 additions & 81 deletions Editor/Physics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -953,87 +953,89 @@ private void AddUnityClothInstance()
}


private void DoCloth(GameObject clothTarget, string meshName)
{
SkinnedMeshRenderer renderer = clothTarget.GetComponent<SkinnedMeshRenderer>();
if (!renderer) return;
Mesh mesh = renderer.sharedMesh;
if (!mesh) return;

List<WeightMapper.PhysicsSettings> settingsList = new List<WeightMapper.PhysicsSettings>();

bool hasPhysics = false;

for (int i = 0; i < mesh.subMeshCount; i++)//
{
Material mat = renderer.sharedMaterials[i];

if (!mat) continue;
string sourceName = mat.name;
if (sourceName.iContains("_2nd_Pass")) continue;
if (sourceName.iContains("_1st_Pass"))
{
sourceName = sourceName.Remove(sourceName.IndexOf("_1st_Pass"));
}

foreach (SoftPhysicsData data in softPhysics)
{
if (data.materialName == sourceName &&
data.meshName == meshName &&
CanAddPhysics(data))
{
WeightMapper.PhysicsSettings settings = new WeightMapper.PhysicsSettings();

settings.name = sourceName;
settings.activate = data.activate;
settings.gravity = data.gravity;
settings.selfCollision = Importer.USE_SELF_COLLISION ? data.selfCollision : false;
settings.softRigidCollision = data.softRigidCollision;
settings.softRigidMargin = data.softRigidMargin;

if (data.isHair)
{
// hair meshes degenerate quickly if less than full stiffness
// (too dense, too many verts?)
settings.bending = 0f;
settings.stretch = 0f;
}
else
{
settings.bending = data.bending;
settings.stretch = data.stretch;
}

settings.solverFrequency = data.solverFrequency;
settings.stiffnessFrequency = data.stiffnessFrequency;
settings.mass = data.mass;
settings.friction = data.friction;
settings.damping = data.damping;
settings.selfMargin = data.selfMargin;
settings.maxDistance = 20f;
settings.maxPenetration = 10f;
settings.colliderThreshold = PHYSICS_WEIGHT_MAP_DETECT_COLLIDER_THRESHOLD;

Texture2D weightMap = GetTextureFrom(data.weightMapPath, data.materialName, "WeightMap", out string texName, true);
if (!weightMap) weightMap = Texture2D.blackTexture;
settings.weightMap = weightMap;

settingsList.Add(settings);
hasPhysics = true;
}
}
}

if (hasPhysics)
{
WeightMapper mapper = clothTarget.GetComponent<WeightMapper>();
if (!mapper) mapper = clothTarget.AddComponent<WeightMapper>();

mapper.settings = settingsList.ToArray();
mapper.characterGUID = characterGUID;
mapper.ApplyWeightMap();
}
}
private void DoCloth(GameObject clothTarget, string meshName)
{
SkinnedMeshRenderer renderer = clothTarget.GetComponent<SkinnedMeshRenderer>();
if (!renderer) return;
Mesh mesh = renderer.sharedMesh;
if (!mesh) return;

List<WeightMapper.PhysicsSettings> settingsList = new List<WeightMapper.PhysicsSettings>();

bool hasPhysics = false;

for (int i = 0; i < mesh.subMeshCount; i++)
{
if (i >= renderer.sharedMaterials.Length) break;

Material mat = renderer.sharedMaterials[i];

if (!mat) continue;
string sourceName = mat.name;
if (sourceName.iContains("_2nd_Pass")) continue;
if (sourceName.iContains("_1st_Pass"))
{
sourceName = sourceName.Remove(sourceName.IndexOf("_1st_Pass"));
}

foreach (SoftPhysicsData data in softPhysics)
{
if (data.materialName == sourceName &&
data.meshName == meshName &&
CanAddPhysics(data))
{
WeightMapper.PhysicsSettings settings = new WeightMapper.PhysicsSettings();

settings.name = sourceName;
settings.activate = data.activate;
settings.gravity = data.gravity;
settings.selfCollision = Importer.USE_SELF_COLLISION ? data.selfCollision : false;
settings.softRigidCollision = data.softRigidCollision;
settings.softRigidMargin = data.softRigidMargin;

if (data.isHair)
{
// hair meshes degenerate quickly if less than full stiffness
// (too dense, too many verts?)
settings.bending = 0f;
settings.stretch = 0f;
}
else
{
settings.bending = data.bending;
settings.stretch = data.stretch;
}

settings.solverFrequency = data.solverFrequency;
settings.stiffnessFrequency = data.stiffnessFrequency;
settings.mass = data.mass;
settings.friction = data.friction;
settings.damping = data.damping;
settings.selfMargin = data.selfMargin;
settings.maxDistance = 20f;
settings.maxPenetration = 10f;
settings.colliderThreshold = PHYSICS_WEIGHT_MAP_DETECT_COLLIDER_THRESHOLD;

Texture2D weightMap = GetTextureFrom(data.weightMapPath, data.materialName, "WeightMap", out string texName, true);
if (!weightMap) weightMap = Texture2D.blackTexture;
settings.weightMap = weightMap;

settingsList.Add(settings);
hasPhysics = true;
}
}
}

if (hasPhysics)
{
WeightMapper mapper = clothTarget.GetComponent<WeightMapper>();
if (!mapper) mapper = clothTarget.AddComponent<WeightMapper>();

mapper.settings = settingsList.ToArray();
mapper.characterGUID = characterGUID;
mapper.ApplyWeightMap();
}
}

private void AddMagicaMeshCloth()
{
Expand Down Expand Up @@ -1111,6 +1113,8 @@ private bool CanAddMagicaCloth(GameObject clothTarget, string meshName) // adds

for (int i = 0; i < mesh.subMeshCount; i++)
{
if (i >= renderer.sharedMaterials.Length) break;

Material mat = renderer.sharedMaterials[i];

if (!mat) continue;
Expand Down
2 changes: 1 addition & 1 deletion Editor/Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum MaterialQuality { None, Default, High, Baked }

public static class Pipeline
{
public const string VERSION = "1.6.1";
public const string VERSION = "1.6.2";

#if HDRP_10_5_0_OR_NEWER
// version
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ Links
[HDRP Version](https://github.com/soupday/cc_unity_tools_HDRP)

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

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

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

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

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

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

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

How it works
============
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.soupday.cc3_unity_tools",
"version": "1.6.1",
"version": "1.6.2",
"displayName": "CC/iC Unity Tools HDRP",
"description": "Unity importer for Character Creator 3 & 4 and iClone 7 and 8.",
"unity": "2020.3",
Expand Down

0 comments on commit f8f4d86

Please sign in to comment.