Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Added autopinning, custom slot canidate scanning #75

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions Components/Physics/Cloth/ClothSimulation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using BaseX;
using FrooxEngine.LogiX;
using FrooxEngine.UIX;
using System;
using System.Linq;

namespace FrooxEngine
{
Expand Down Expand Up @@ -28,9 +30,10 @@ public class Cloth : MeshRenderer // Need to extend MeshRenderer to avoid Unity
public readonly Sync<float> SolverFrequency;
public readonly Sync<float> SleepThreshold;

public readonly SyncRefList<Slot> ColliderCanidateRoots;
public readonly SyncRefList<ClothCollider> ClothColliders;
public readonly SyncList<ClothCoefficent> PinningCoefficients;

protected override void OnAttach()
{
base.OnAttach();
Expand Down Expand Up @@ -58,14 +61,27 @@ protected override void OnStart()
ClothColliders.ElementsAdded += (a, b, c) => ClothColliders.CleanList();
ClothColliders.ElementsRemoved += (a, b, c) => ClothColliders.CleanList();
ClothColliders.Changed += (a) => ClothColliders.CleanList();
PinningCoefficients.ElementsAdded += IncreaseCoefficientCount;
}
}

private void IncreaseCoefficientCount(SyncElementList<ClothCoefficent> list, int startIndex, int count)
{
int counter = 0;
var arr = list.Elements.ToArray();
for (int i = startIndex; i < startIndex + count; i++)
{
arr[i].VertexIndex.Value = (ulong)(startIndex + counter);
counter += 1;
}
}

public override void BuildInspectorUI(UIBuilder ui)
{
base.BuildInspectorUI(ui);
ui.Button("Add all colliders in world".AsLocaleKey()).SetUpActionTrigger(SetupWorldColliders);
ui.Button("Add all user colliders".AsLocaleKey()).SetUpActionTrigger(SetupUserColliders);
ui.Button("Add all colliders on users".AsLocaleKey()).SetUpActionTrigger(SetupUserColliders);
ui.Button("Add all colliders under the canidate slots".AsLocaleKey()).SetUpActionTrigger(SetupSlotColliders);
ui.Button("Remove all colliders".AsLocaleKey()).SetUpActionTrigger(ClearColliders);
ui.Button("Remove all pinning coefficients".AsLocaleKey()).SetUpActionTrigger(ClearCoefficients);
ui.Button("Reset cloth simulation".AsLocaleKey()).SetUpActionTrigger(Reset);
Expand All @@ -76,11 +92,8 @@ public void SetupWorldColliders()
{
foreach (var slot in Engine.Current.WorldManager.FocusedWorld.RootSlot.GetAllChildren())
{
foreach (var sphere in slot.GetComponentsInChildren<ClothSphereCollider>())
ClothColliders.AddUnique(sphere);

foreach (var capsule in slot.GetComponentsInChildren<ClothCapsuleCollider>())
ClothColliders.AddUnique(capsule);
foreach (var col in slot.GetComponentsInChildren<ClothCollider>())
ClothColliders.AddUnique(col);
}
}

Expand All @@ -89,16 +102,20 @@ public void SetupUserColliders()
{
foreach (var user in Engine.Current.WorldManager.FocusedWorld.AllUsers)
{
foreach (var sphere in user.Root.Slot.GetComponentsInChildren<ClothSphereCollider>())
ClothColliders.AddUnique(sphere);

foreach (var capsule in user.Root.Slot.GetComponentsInChildren<ClothCapsuleCollider>())
ClothColliders.AddUnique(capsule);
foreach (var col in user.Root.Slot.GetComponentsInChildren<ClothCollider>())
ClothColliders.AddUnique(col);
}
}

[ImpulseTarget] public void ClearColliders() => ClothColliders.Clear();
[ImpulseTarget]
public void SetupSlotColliders()
{
foreach (var col in ColliderCanidateRoots.Where(x => x != null))
ClothColliders.AddRangeUnique(col.GetComponentsInChildren<ClothCollider>());
}

[ImpulseTarget] public void ClearCoefficients() => PinningCoefficients.Clear();
[ImpulseTarget] public void ClearColliders() => ClothColliders.Clear();
[ImpulseTarget] public void Reset() => ShouldReset.Value = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion NEOSPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<HintPath>$(NeosPath)Neos_Data/Managed/UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityNeos">
<HintPath>$(NeosPath)Neos_Data/UnityNeos.dll</HintPath>
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\NeosVR\Neos_Data\Managed\UnityNeos.dll</HintPath>
dfgHiatus marked this conversation as resolved.
Show resolved Hide resolved
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down