Skip to content

Commit

Permalink
Merge pull request #92 from soupday/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
soupday authored Jan 28, 2024
2 parents 67373c4 + 404657b commit 9e60f48
Show file tree
Hide file tree
Showing 17 changed files with 1,041 additions and 217 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.1
- Magica Cloth 2 support for hair physics.
- Magica Cloth and collider navigation tools added.

### 1.6.0
- Fixes to root bones and physics components in LOD combiner.
- Support for Magica Cloth 2 Physics (if present) - Cloth simulation and spring bones.
Expand Down
40 changes: 33 additions & 7 deletions Editor/CharacterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public enum ShaderFeatureFlags
{
NoFeatures = 0,
Tessellation = 1,
ClothPhysics = 2,
HairPhysics = 4,
SpringBoneHair = 8,
ClothPhysics = 2, // group flag to allow selection between UnityClothPhysics & MagicaCloth
HairPhysics = 4, // group flag to allow selection between UnityClothHairPhysics & MagicaClothHairPhysics
SpringBoneHair = 8, // dynamic bone springbones
WrinkleMaps = 16,
MagicaCloth = 32,
MagicaBone = 64,
UnityClothPhysics = 128,
UnityClothHairPhysics = 256
MagicaCloth = 32, // Magica Mesh Cloth for clothing items
MagicaBone = 64, // Magica Bone Cloth for hair
UnityClothPhysics = 128, // Unity Cloth for clothing items
UnityClothHairPhysics = 256, // Unity Cloth for hair items
MagicaClothHairPhysics = 512, // Magica Mesh Cloth for hair items
SpringBonePhysics = 1024 // group flag to allow selection between SpringBoneHair & MagicaBone
}

// 'radio groups' of mutually exclusive settings
Expand All @@ -52,6 +54,11 @@ public enum ShaderFeatureFlags
public static ShaderFeatureFlags[] hairGroup =
{
ShaderFeatureFlags.UnityClothHairPhysics, // UnityEngine.Cloth instance for hair objects
ShaderFeatureFlags.MagicaClothHairPhysics // Magica Cloth 2 'Mesh Cloth' for hair objects
};

public static ShaderFeatureFlags[] springGroup =
{
ShaderFeatureFlags.SpringBoneHair, // DynamicBone springbones
ShaderFeatureFlags.MagicaBone // MagicaCloth2 instance set to 'Bone Cloth' mode for springbones
};
Expand Down Expand Up @@ -982,6 +989,25 @@ public void EnsureDefaultsAreSet(ShaderFeatureFlags flag)
ShaderFlags |= ShaderFeatureFlags.UnityClothHairPhysics;
}

break;
}
case ShaderFeatureFlags.SpringBonePhysics:
{
bool dyn = ImporterWindow.Current.DynamicBoneAvailable;
bool mag = ImporterWindow.Current.MagicaCloth2Available;

if (dyn && mag)
{
ShaderFlags |= ShaderFeatureFlags.MagicaBone;
}
else
{
if (mag)
ShaderFlags |= ShaderFeatureFlags.MagicaBone;
else if (dyn)
ShaderFlags |= ShaderFeatureFlags.SpringBoneHair;
}

break;
}
}
Expand Down
271 changes: 226 additions & 45 deletions Editor/ColliderManagerEditor.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Editor/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public GameObject Import(bool batchMode = false)
if ((clothPhysics || hairPhysics || springBoneHair) && jsonPhysicsData != null)
{
Physics physics = new Physics(characterInfo, prefabInstance);
physics.AddPhysics(false);
physics.AddPhysics(true);
}

if (blenderProject)
Expand Down
76 changes: 73 additions & 3 deletions Editor/ImporterFeaturesWindow.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (C) 2021 Victor Soupday
* This file is part of CC_Unity_Tools <https://github.com/soupday/CC_Unity_Tools>
*
* CC_Unity_Tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CC_Unity_Tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CC_Unity_Tools. If not, see <https://www.gnu.org/licenses/>.
*/

using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -172,6 +190,10 @@ void OnGUI()
if (DrawFlagSelectionLine(line++, CharacterInfo.ShaderFeatureFlags.UnityClothHairPhysics, "Unity Hair Physics", SUB_SECTION_INDENT, CharacterInfo.hairGroup))
flagChanged = true;

if (DrawFlagSelectionLine(line++, CharacterInfo.ShaderFeatureFlags.MagicaClothHairPhysics, "Magica Cloth 2 Hair Physics", SUB_SECTION_INDENT, CharacterInfo.hairGroup))
flagChanged = true;

/*
if (importerWindow.DynamicBoneAvailable)
{
if (DrawFlagSelectionLine(line++, CharacterInfo.ShaderFeatureFlags.SpringBoneHair, "Dynamic Bone Springbones", SUB_SECTION_INDENT, CharacterInfo.hairGroup))
Expand All @@ -182,9 +204,33 @@ void OnGUI()
if (DrawFlagSelectionLine(line++, CharacterInfo.ShaderFeatureFlags.MagicaBone, "Magica Bone Springbones", SUB_SECTION_INDENT, CharacterInfo.hairGroup))
flagChanged = true;
}
*/
}
}

// Spring Bone Physics
if (importerWindow.DynamicBoneAvailable || importerWindow.MagicaCloth2Available)
{
if (DrawFlagSelectionLine(line++, CharacterInfo.ShaderFeatureFlags.SpringBonePhysics, "Enable Spring Bone Physics", SECTION_INDENT))
flagChanged = true;

if (contextCharacter.ShaderFlags.HasFlag(CharacterInfo.ShaderFeatureFlags.SpringBonePhysics))
{
if (importerWindow.MagicaCloth2Available)
{
if (DrawFlagSelectionLine(line++, CharacterInfo.ShaderFeatureFlags.MagicaBone, "Magica Bone Springbones", SUB_SECTION_INDENT, CharacterInfo.springGroup))
flagChanged = true;
}
if (importerWindow.DynamicBoneAvailable)
{
if (DrawFlagSelectionLine(line++, CharacterInfo.ShaderFeatureFlags.SpringBoneHair, "Dynamic Bone Springbones", SUB_SECTION_INDENT, CharacterInfo.springGroup))
flagChanged = true;
}
}
}

DrawLabelLine(line++, "");

if (Event.current.type == EventType.Repaint)
{
minSize = new Vector2(DROPDOWN_WIDTH, GUILayoutUtility.GetLastRect().yMax);
Expand Down Expand Up @@ -247,21 +293,35 @@ private void SetFeatureFlag(CharacterInfo.ShaderFeatureFlags flag, bool value)
{
contextCharacter.ShaderFlags ^= flag; // toggle changed to OFF => bitwise XOR to remove flag

// since the section flag is being unset then all the entries should be unset too
switch(flag)
// if the group flag is being unset then all the 'radio group' entries should be unset too
switch (flag)
{
case CharacterInfo.ShaderFeatureFlags.ClothPhysics:
{
foreach (CharacterInfo.ShaderFeatureFlags groupFlag in CharacterInfo.clothGroup)
{
if (contextCharacter.ShaderFlags.HasFlag(groupFlag))
contextCharacter.ShaderFlags ^= groupFlag;
}

/*
if (contextCharacter.ShaderFlags.HasFlag(CharacterInfo.ShaderFeatureFlags.MagicaCloth))
contextCharacter.ShaderFlags ^= CharacterInfo.ShaderFeatureFlags.MagicaCloth;
if (contextCharacter.ShaderFlags.HasFlag(CharacterInfo.ShaderFeatureFlags.UnityClothPhysics))
contextCharacter.ShaderFlags ^= CharacterInfo.ShaderFeatureFlags.UnityClothPhysics;

*/
break;
}
case CharacterInfo.ShaderFeatureFlags.HairPhysics:
{
foreach (CharacterInfo.ShaderFeatureFlags groupFlag in CharacterInfo.hairGroup)
{
if (contextCharacter.ShaderFlags.HasFlag(groupFlag))
contextCharacter.ShaderFlags ^= groupFlag;
}

/*
if (contextCharacter.ShaderFlags.HasFlag(CharacterInfo.ShaderFeatureFlags.MagicaBone))
contextCharacter.ShaderFlags ^= CharacterInfo.ShaderFeatureFlags.MagicaBone;
Expand All @@ -270,6 +330,16 @@ private void SetFeatureFlag(CharacterInfo.ShaderFeatureFlags flag, bool value)
if (contextCharacter.ShaderFlags.HasFlag(CharacterInfo.ShaderFeatureFlags.UnityClothHairPhysics))
contextCharacter.ShaderFlags ^= CharacterInfo.ShaderFeatureFlags.UnityClothHairPhysics;
*/
break;
}
case CharacterInfo.ShaderFeatureFlags.SpringBonePhysics:
{
foreach (CharacterInfo.ShaderFeatureFlags groupFlag in CharacterInfo.springGroup)
{
if (contextCharacter.ShaderFlags.HasFlag(groupFlag))
contextCharacter.ShaderFlags ^= groupFlag;
}

break;
}
Expand Down
71 changes: 69 additions & 2 deletions Editor/ImporterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ private void OnGUISettingsArea(Rect settingsBlock)
GUILayout.Label("Mip-map Bias");
GUILayout.Space(ROW_SPACE);
GUILayout.BeginHorizontal();
Importer.MIPMAP_BIAS = GUILayout.HorizontalSlider(Importer.MIPMAP_BIAS, -1f, 1f);
Importer.MIPMAP_BIAS = GUILayout.HorizontalSlider(Importer.MIPMAP_BIAS, -1f, 1f, GUILayout.Width(160f));
GUILayout.Label(Importer.MIPMAP_BIAS.ToString("0.00"),
GUILayout.Width(40f));
GUILayout.EndHorizontal();
Expand All @@ -1114,13 +1114,73 @@ private void OnGUISettingsArea(Rect settingsBlock)
GUILayout.Label("Physics Collider Shrink");
GUILayout.Space(ROW_SPACE);
GUILayout.BeginHorizontal();
Physics.PHYSICS_SHRINK_COLLIDER_RADIUS = GUILayout.HorizontalSlider(Physics.PHYSICS_SHRINK_COLLIDER_RADIUS, -2, 2f);
Physics.PHYSICS_SHRINK_COLLIDER_RADIUS = GUILayout.HorizontalSlider(Physics.PHYSICS_SHRINK_COLLIDER_RADIUS, -2, 2f, GUILayout.Width(160f));
GUILayout.Label(Physics.PHYSICS_SHRINK_COLLIDER_RADIUS.ToString("0.00"),
GUILayout.Width(40f));
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.Space(ROW_SPACE);


if (MagicaCloth2Available)
{
GUILayout.Space(10f);
GUILayout.BeginVertical(new GUIContent("", "Set global values for Magica Cloth 2 proxy mesh reduction settings. NB these settings will only be applied the next time the character physics are built."), importerStyles.labelStyle);
GUILayout.Label("Magica Cloth 2 - Reduction Settings");
GUILayout.Space(ROW_SPACE);
GUILayout.Label("Cloth Objects");
GUILayout.BeginHorizontal();
GUILayout.Space(20f);
GUILayout.Label("Simple Distance", GUILayout.Width(100f));
Physics.CLOTHSIMPLEDISTANCE = (float)Math.Round(GUILayout.HorizontalSlider(Physics.CLOTHSIMPLEDISTANCE, 0f, 0.2f, GUILayout.Width(100f)), 3);
GUILayout.Label(Physics.CLOTHSIMPLEDISTANCE.ToString("0.000"),
GUILayout.Width(40f));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Space(20f);
GUILayout.Label("Shape Distance", GUILayout.Width(100f));
Physics.CLOTHSHAPEDISTANCE = (float)Math.Round(GUILayout.HorizontalSlider(Physics.CLOTHSHAPEDISTANCE, 0f, 0.2f, GUILayout.Width(100f)), 3);
GUILayout.Label(Physics.CLOTHSHAPEDISTANCE.ToString("0.000"),
GUILayout.Width(40f));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

GUILayout.Label("Hair Objects");
GUILayout.BeginHorizontal();
GUILayout.Space(20f);
GUILayout.Label("Simple Distance", GUILayout.Width(100f));
Physics.HAIRSIMPLEDISTANCE = (float)Math.Round(GUILayout.HorizontalSlider(Physics.HAIRSIMPLEDISTANCE, 0f, 0.2f, GUILayout.Width(100f)), 3);
GUILayout.Label(Physics.HAIRSIMPLEDISTANCE.ToString("0.000"),
GUILayout.Width(40f));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Space(20f);
GUILayout.Label("Shape Distance", GUILayout.Width(100f));
Physics.HAIRSHAPEDISTANCE = (float)Math.Round(GUILayout.HorizontalSlider(Physics.HAIRSHAPEDISTANCE, 0f, 0.2f, GUILayout.Width(100f)), 3);
GUILayout.Label(Physics.HAIRSHAPEDISTANCE.ToString("0.000"),
GUILayout.Width(40f));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

GUILayout.Space(ROW_SPACE);
GUILayout.EndVertical();
GUILayout.BeginVertical(new GUIContent("", "Set the threshold for conversion of the PhysX weightmap into the 'Fixed/Moveable' system used by Magica Cloth 2. When a very low value is set then any slight movement allowed by PhysX will also allow movement in Magica Cloth 2."), importerStyles.labelStyle);

GUILayout.Label("Weightmap Threshold %", GUILayout.Width(140f));
GUILayout.BeginHorizontal();
GUILayout.Space(12f);
Physics.MAGICA_WEIGHTMAP_THRESHOLD_PC = (float)Math.Round(GUILayout.HorizontalSlider(Physics.MAGICA_WEIGHTMAP_THRESHOLD_PC, 0f, 20f, GUILayout.Width(214f)), 2);
GUILayout.Label(Physics.MAGICA_WEIGHTMAP_THRESHOLD_PC.ToString("0.00") + " %",
GUILayout.Width(50f));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

GUILayout.EndVertical();
GUILayout.Space(ROW_SPACE);
}

/*
GUILayout.Space(10f);
GUILayout.BeginVertical(new GUIContent("", "When assigning weight maps, the system analyses the weights of the mesh to determine which colliders affect the cloth simulation.Only cloth weights above this threshold will be considered for collider detection. Note: This is the default value supplied to the WeightMapper component, it can be further modified there."), importerStyles.labelStyle);
Expand Down Expand Up @@ -1497,6 +1557,13 @@ public static void ResetOptions()
Importer.USE_DIGITAL_HUMAN_SHADER = false;
Physics.PHYSICS_SHRINK_COLLIDER_RADIUS = 0.5f;
Physics.PHYSICS_WEIGHT_MAP_DETECT_COLLIDER_THRESHOLD = 0.25f;

Physics.CLOTHSIMPLEDISTANCE = Physics.CLOTHSHAPEDISTANCE_DEFAULT;
Physics.CLOTHSHAPEDISTANCE = Physics.CLOTHSHAPEDISTANCE_DEFAULT;
Physics.HAIRSIMPLEDISTANCE = Physics.HAIRSIMPLEDISTANCE_DEFAULT;
Physics.HAIRSHAPEDISTANCE = Physics.HAIRSHAPEDISTANCE_DEFAULT;
Physics.MAGICA_WEIGHTMAP_THRESHOLD_PC = Physics.MAGICA_WEIGHTMAP_THRESHOLD_PC_DEFAULT;

Util.LOG_LEVEL = 0;
ICON_AREA_WIDTH = ICON_WIDTH;
}
Expand Down
Loading

0 comments on commit 9e60f48

Please sign in to comment.