diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Jobs/RotateParticleJobSystem.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Jobs/RotateParticleJobSystem.cs index 5fe5fc812..05fac9621 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Jobs/RotateParticleJobSystem.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/Jobs/RotateParticleJobSystem.cs @@ -37,8 +37,8 @@ namespace RotateParticle.Jobs // // cloth // - NativeArray _clothUsedParticles = new(); - NativeArray<(SpringConstraint, SphereTriangle.ClothRect)> _clothRects = new(); + NativeArray _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 clothUsedParticles = new(); List<(SpringConstraint, SphereTriangle.ClothRect)> clothRects = new(); + _clothUsedParticles = new(_transforms.Count, Allocator.Persistent); var cloths = vrm.GetComponentsInChildren(); 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) diff --git a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSystem.cs b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSystem.cs index 50f3296ff..2ad1aa1f3 100644 --- a/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSystem.cs +++ b/Assets/VRM10_Samples/ClothSample/RotateParticle/Runtime/RotateParticleSystem.cs @@ -56,7 +56,7 @@ namespace RotateParticle return Color.gray; } - HashSet _clothUsedParticles = new(); + bool[] _clothUsedParticles; void IDisposable.Dispose() { @@ -67,6 +67,7 @@ namespace RotateParticle ParticleList list, Dictionary 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;