_clothRects

This commit is contained in:
ousttrue
2024-11-22 21:13:52 +09:00
parent 67004592e7
commit 1970b44cd7
2 changed files with 26 additions and 21 deletions

View File

@@ -37,8 +37,8 @@ namespace RotateParticle.Jobs
//
// cloth
//
NativeArray<int> _clothUsedParticles = new();
NativeArray<(SpringConstraint, SphereTriangle.ClothRect)> _clothRects = new();
NativeArray<bool> _clothUsedParticles;
NativeArray<(SpringConstraint, SphereTriangle.ClothRect)> _clothRects;
void IDisposable.Dispose()
{
@@ -53,6 +53,9 @@ namespace RotateParticle.Jobs
if (_prevPositions.IsCreated) _prevPositions.Dispose();
if (_nextPositions.IsCreated) _nextPositions.Dispose();
if (_nextRotations.IsCreated) _nextRotations.Dispose();
if (_clothUsedParticles.IsCreated) _clothUsedParticles.Dispose();
if (_clothRects.IsCreated) _clothRects.Dispose();
}
(int index, bool isNew) GetTransformIndex(Transform t,
@@ -178,8 +181,8 @@ namespace RotateParticle.Jobs
//
// cloths
//
HashSet<int> clothUsedParticles = new();
List<(SpringConstraint, SphereTriangle.ClothRect)> clothRects = new();
_clothUsedParticles = new(_transforms.Count, Allocator.Persistent);
var cloths = vrm.GetComponentsInChildren<RectCloth>();
foreach (var cloth in cloths)
{
@@ -196,10 +199,10 @@ namespace RotateParticle.Jobs
var b = s1.Particles[j];
var c = s1.Particles[j - 1];
var d = s0.Particles[j - 1];
clothUsedParticles.Add(_transforms.IndexOf(a.Transform));
clothUsedParticles.Add(_transforms.IndexOf(b.Transform));
clothUsedParticles.Add(_transforms.IndexOf(c.Transform));
clothUsedParticles.Add(_transforms.IndexOf(d.Transform));
_clothUsedParticles[_transforms.IndexOf(a.Transform)] = true;
_clothUsedParticles[_transforms.IndexOf(b.Transform)] = true;
_clothUsedParticles[_transforms.IndexOf(c.Transform)] = true;
_clothUsedParticles[_transforms.IndexOf(d.Transform)] = true;
if (i % 2 == 1)
{
// 互い違いに
@@ -234,10 +237,10 @@ namespace RotateParticle.Jobs
var b = s1.Particles[j];
var c = s1.Particles[j - 1];
var d = s0.Particles[j - 1];
clothUsedParticles.Add(_transforms.IndexOf(a.Transform));
clothUsedParticles.Add(_transforms.IndexOf(b.Transform));
clothUsedParticles.Add(_transforms.IndexOf(c.Transform));
clothUsedParticles.Add(_transforms.IndexOf(d.Transform));
_clothUsedParticles[_transforms.IndexOf(a.Transform)] = true;
_clothUsedParticles[_transforms.IndexOf(b.Transform)] = true;
_clothUsedParticles[_transforms.IndexOf(c.Transform)] = true;
_clothUsedParticles[_transforms.IndexOf(d.Transform)] = true;
if (i % 2 == 1)
{
// 互い違いに
@@ -263,6 +266,7 @@ namespace RotateParticle.Jobs
}
}
}
_clothRects = new(clothRects.ToArray(), Allocator.Persistent);
}
private static BlittableColliderType TranslateColliderType(VRM10SpringBoneColliderTypes colliderType)

View File

@@ -56,7 +56,7 @@ namespace RotateParticle
return Color.gray;
}
HashSet<int> _clothUsedParticles = new();
bool[] _clothUsedParticles;
void IDisposable.Dispose()
{
@@ -67,6 +67,7 @@ namespace RotateParticle
ParticleList list,
Dictionary<WarpRoot, Strand> strandMap)
{
_clothUsedParticles = new bool[_list._particles.Count];
for (int i = 1; i < cloth.Warps.Count; ++i)
{
var s0 = strandMap[cloth.Warps[i - 1]];
@@ -80,10 +81,10 @@ namespace RotateParticle
var b = s1.Particles[j];
var c = s1.Particles[j - 1];
var d = s0.Particles[j - 1];
_clothUsedParticles.Add(a.Init.Index);
_clothUsedParticles.Add(b.Init.Index);
_clothUsedParticles.Add(c.Init.Index);
_clothUsedParticles.Add(d.Init.Index);
_clothUsedParticles[a.Init.Index] = true;
_clothUsedParticles[b.Init.Index] = true;
_clothUsedParticles[c.Init.Index] = true;
_clothUsedParticles[d.Init.Index] = true;
if (i % 2 == 1)
{
// 互い違いに
@@ -116,10 +117,10 @@ namespace RotateParticle
var b = s1.Particles[j];
var c = s1.Particles[j - 1];
var d = s0.Particles[j - 1];
_clothUsedParticles.Add(a.Init.Index);
_clothUsedParticles.Add(b.Init.Index);
_clothUsedParticles.Add(c.Init.Index);
_clothUsedParticles.Add(d.Init.Index);
_clothUsedParticles[a.Init.Index] = true;
_clothUsedParticles[b.Init.Index] = true;
_clothUsedParticles[c.Init.Index] = true;
_clothUsedParticles[d.Init.Index] = true;
if (i % 2 == 1)
{
// 互い違いに
@@ -268,7 +269,7 @@ namespace RotateParticle
for (int j = 0; j < _list._particles.Count; ++j)
{
// using var prof = new ProfileSample("Collision: Strand");
if (_clothUsedParticles.Contains(j))
if (_clothUsedParticles[j])
{
// 布で処理された
continue;