Skip to content

Commit

Permalink
1.5.0
Browse files Browse the repository at this point in the history
-
  • Loading branch information
soupday committed Jul 11, 2023
1 parent 4415c29 commit 9ec7f15
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 27 deletions.
15 changes: 15 additions & 0 deletions Editor/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ public static bool ANIMPLAYER_ON_BY_DEFAULT
}
}

public static bool USE_SELF_COLLISION
{
get
{
if (EditorPrefs.HasKey("RL_Importer_Use_Self_Collision"))
return EditorPrefs.GetBool("RL_Importer_Use_Self_Collision");
return false;
}

set
{
EditorPrefs.SetBool("RL_Importer_Use_Self_Collision", value);
}
}

public static bool RECONSTRUCT_FLOW_NORMALS
{
get
Expand Down
5 changes: 5 additions & 0 deletions Editor/ImporterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,10 @@ private void OnGUISettingsArea(Rect settingsBlock)
new GUIContent("Animation Player On", "Always show the animation player when opening the preview scene."));
GUILayout.Space(ROW_SPACE);

Importer.USE_SELF_COLLISION = GUILayout.Toggle(Importer.USE_SELF_COLLISION,
new GUIContent("Use self collision", "Use the self collision distances from the Character Creator export."));
GUILayout.Space(ROW_SPACE);

GUILayout.Space(10f);
GUILayout.BeginVertical(new GUIContent("", "Override mip-map bias for all textures setup for the characters."), importerStyles.labelStyle);
GUILayout.Label("Mip-map Bias");
Expand Down Expand Up @@ -1427,6 +1431,7 @@ public static void ResetOptions()
Importer.RECONSTRUCT_FLOW_NORMALS = false;
Importer.REBAKE_BLENDER_UNITY_MAPS = false;
Importer.ANIMPLAYER_ON_BY_DEFAULT = false;
Importer.USE_SELF_COLLISION = false;
Importer.USE_AMPLIFY_SHADER = true;
Importer.USE_DIGITAL_HUMAN_SHADER = false;
Physics.PHYSICS_SHRINK_COLLIDER_RADIUS = 0.5f;
Expand Down
29 changes: 27 additions & 2 deletions Editor/MassProcessingWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void BatchQueueNextBuild(float delay)
EditorApplication.update -= BatchUpdateTimer;
Selection.activeObject = null;

if (buildQueue == null || buildQueue.Count == 0)
if (buildQueue == null || buildQueue.Count == 0 || ImporterWindow.Current == null)
{
Util.LogInfo("Done batch processing!");
batchTimer = 0f;
Expand All @@ -196,6 +196,12 @@ public void BatchQueueNextBuild(float delay)

public void BatchBuildNextQueueCharacter()
{
if (ImporterWindow.Current == null)
{
buildQueue = null;
return;
}

if (buildQueue == null || buildQueue.Count == 0) return;

CharacterInfo batchCharacter = buildQueue[0];
Expand Down Expand Up @@ -497,6 +503,11 @@ orderby character.name.Substring(0, 1) descending

private void OnGUI()
{
if (ImporterWindow.Current == null)
{
CloseWindow();
return;
}
if (!initDone) InitData();
if (windowStyles == null) windowStyles = new Styles();
if (workingList == null) workingList = BuildCharacterInfoList();
Expand All @@ -520,9 +531,11 @@ private void OnGUI()
//TestShowArea(controlsRect, Color.red);
//TestShowArea(listRect, Color.magenta);

EditorGUI.BeginDisabledGroup(EditorApplication.isPlaying);
ONGUIControlsArea(controlsRect);
OnGUINameFlterArea(nameFilterRect);
OnGUIDetailWorkingDisplayListArea(listRect);
EditorGUI.EndDisabledGroup();

if (windowMode == WindowMode.extended)
{
Expand Down Expand Up @@ -1301,7 +1314,12 @@ private void BakePrefabOptionSelected(object sel)
private void OnDisable()
{
ResetWindow();
buildQueue = null;
buildQueue = null;
}

private void OnEnable()
{
initDone = false; //if the window is open during play mode - then this forces a refresh of the character list after exiting play mode (currently the window is closed on entering play mode)
}

private void ResetWindow()
Expand All @@ -1310,5 +1328,12 @@ private void ResetWindow()
windowMode = WindowMode.standard;
SetWindowSize();
}

private void CloseWindow()
{
ResetWindow();
buildQueue = null;
this.Close();
}
}
}
2 changes: 1 addition & 1 deletion Editor/Physics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ private void DoCloth(GameObject clothTarget, string meshName)
settings.name = sourceName;
settings.activate = data.activate;
settings.gravity = data.gravity;
settings.selfCollision = data.selfCollision;
settings.selfCollision = Importer.USE_SELF_COLLISION ? data.selfCollision : false;
settings.softRigidCollision = data.softRigidCollision;
settings.softRigidMargin = data.softRigidMargin;

Expand Down
58 changes: 34 additions & 24 deletions Runtime/WeightMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class PhysicsSettings
public float damping;
[HideInInspector]
[Range(0f, 1f)]
public float drag;
public float drag;
[Range(0f, 100f)]
public float stretch;
[Range(0f, 100f)]
Expand All @@ -77,7 +77,7 @@ public class PhysicsSettings
public float stiffnessFrequency;
[Space(8)]
[HideInInspector]
[Range(0f, 1f)]
[Range(0f, 1f)]
public float colliderThreshold;

public PhysicsSettings()
Expand Down Expand Up @@ -114,8 +114,8 @@ public void Copy(PhysicsSettings p)
solverFrequency = p.solverFrequency;
stiffnessFrequency = p.stiffnessFrequency;
colliderThreshold = p.colliderThreshold;
}
}
}

public PhysicsSettings[] settings;
public bool updateColliders = true;
Expand All @@ -127,22 +127,22 @@ public void Copy(PhysicsSettings p)
public string characterGUID;

public void ApplyWeightMap()
{
{
GameObject clothTarget = gameObject;
SkinnedMeshRenderer renderer = clothTarget.GetComponent<SkinnedMeshRenderer>();
if (!renderer) return;
Mesh mesh = renderer.sharedMesh;
if (!mesh) return;

// object scale
Vector3 objectScale = renderer.gameObject.transform.localScale;
Vector3 objectScale = renderer.gameObject.transform.localScale;
float modelScale = 0.03f / (objectScale.x + objectScale.y + objectScale.z);
float worldScale = (objectScale.x + objectScale.y + objectScale.z) / 3f;

// add cloth component
Cloth cloth = clothTarget.GetComponent<Cloth>();
if (!cloth) cloth = clothTarget.AddComponent<Cloth>();

// generate a mapping dictionary of cloth vertices to mesh vertices
Dictionary<long, int> uniqueVertices = new Dictionary<long, int>();
int count = 0;
Expand All @@ -154,22 +154,22 @@ public void ApplyWeightMap()
{
uniqueVertices.Add(hash, count++);
}
}
}

// fetch UV's
List<Vector2> uvs = new List<Vector2>();
mesh.GetUVs(0, uvs);

AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

List<uint> selfCollisionIndices = new List<uint>();
List<Collider> colliders = new List<Collider>();
List<Collider> detectedColliders = new List<Collider>(colliders.Count);
ColliderManager colliderManager = gameObject.GetComponentInParent<ColliderManager>();
ColliderManager colliderManager = gameObject.GetComponentInParent<ColliderManager>();
if (colliderManager) colliders.AddRange(colliderManager.colliders);
else colliders.AddRange(gameObject.transform.parent.GetComponentsInChildren<Collider>());

ClothSkinningCoefficient[] coefficients = new ClothSkinningCoefficient[cloth.coefficients.Length];
Array.Copy(cloth.coefficients, coefficients, coefficients.Length);

Expand Down Expand Up @@ -205,9 +205,8 @@ public void ApplyWeightMap()
cloth.collisionMassScale = data.mass;
cloth.friction = data.friction;
cloth.damping = Mathf.Pow(data.damping, 0.333f);
bool IGNORESELFCOLLISION = true;
cloth.selfCollisionDistance = IGNORESELFCOLLISION ? 0f : selfMargin;
cloth.selfCollisionStiffness = 0.2f;
cloth.selfCollisionDistance = USE_SELF_COLLISION ? selfMargin : 0f;
cloth.selfCollisionStiffness = 0.2f;

bool doColliders = updateColliders && data.softRigidCollision;

Expand Down Expand Up @@ -261,7 +260,7 @@ public void ApplyWeightMap()
{
Vector3 vert = meshVertices[vertIdx];
if (uniqueVertices.TryGetValue(SpatialHash(vert), out int clothVert))
{
{
Vector2 coord = uvs[vertIdx];
x = Mathf.Max(0, Mathf.Min(wm1, Mathf.FloorToInt(0.5f + coord.x * wm1)));
y = Mathf.Max(0, Mathf.Min(hm1, Mathf.FloorToInt(0.5f + coord.y * hm1)));
Expand All @@ -270,33 +269,33 @@ public void ApplyWeightMap()
float maxDistance = data.maxDistance * weight * modelScale;
float maxPenetration = data.maxPenetration * weight * modelScale;
float modelMax = Mathf.Max(maxDistance, maxPenetration);
float worldMax = modelMax * worldScale;
float worldMax = modelMax * worldScale;
coefficients[clothVert].maxDistance = maxDistance;
coefficients[clothVert].collisionSphereDistance = maxPenetration;

if (data.selfCollision && modelMax > selfMargin)
{
selfCollisionIndices.Add((uint)clothVert);
}

if (doColliders && optimizeColliders &&
//weight >= data.colliderThreshold &&
modelMax > rigidMargin)
{
Vector3 world = transform.localToWorldMatrix * vert;

for (int ci = 0; ci < colliders.Count; ci++)
{
Collider cc = colliders[ci];

if (cc.bounds.Contains(world))
{
{
detectedColliders.Add(cc);
colliders.Remove(cc);
ci--;
}
else if (cc.bounds.SqrDistance(world) < worldMax * worldMax)
{
{
detectedColliders.Add(cc);
colliders.Remove(cc);
ci--;
Expand All @@ -311,10 +310,10 @@ public void ApplyWeightMap()

// set coefficients
if (updateConstraints)
{
{
cloth.coefficients = coefficients;
}

cloth.SetSelfAndInterCollisionIndices(selfCollisionIndices);

// set colliders
Expand All @@ -330,7 +329,7 @@ public void ApplyWeightMap()
}
cloth.capsuleColliders = detectedCapsuleColliders.ToArray();
}
}
}

private static long SpatialHash(Vector3 v)
{
Expand All @@ -344,7 +343,18 @@ private static long SpatialHash(Vector3 v)
long z = (long)(v.z * discrete);

return (x * p1) ^ (y * p2) ^ (z * p3);
}
}

private static bool USE_SELF_COLLISION
{
get
{
if (EditorPrefs.HasKey("RL_Importer_Use_Self_Collision"))
return EditorPrefs.GetBool("RL_Importer_Use_Self_Collision");
return false;
}
}

#endif
}
}

0 comments on commit 9ec7f15

Please sign in to comment.