mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-27 21:34:38 -05:00
batch count 1
This commit is contained in:
@@ -29,6 +29,7 @@ namespace UniVRM10.ClothWarp.Components
|
||||
s.SetEnabled(false);
|
||||
root.Add(s);
|
||||
}
|
||||
root.Add(new PropertyField { bindingPath = nameof(_target.UseJob) });
|
||||
root.Add(new PropertyField { bindingPath = nameof(_target.Warps) });
|
||||
root.Add(new PropertyField { bindingPath = nameof(_target.Cloths) });
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
|
||||
NativeArray<Vector3> _strandCollision;
|
||||
NativeArray<int> _clothCollisionCount;
|
||||
NativeArray<Vector3> _clothCollisionDelta;
|
||||
NativeArray<Vector3> _clothCollision;
|
||||
NativeArray<Vector3> _forces;
|
||||
|
||||
//
|
||||
@@ -72,7 +72,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
if (_nextRotations.IsCreated) _nextRotations.Dispose();
|
||||
if (_strandCollision.IsCreated) _strandCollision.Dispose();
|
||||
if (_clothCollisionCount.IsCreated) _clothCollisionCount.Dispose();
|
||||
if (_clothCollisionDelta.IsCreated) _clothCollisionDelta.Dispose();
|
||||
if (_clothCollision.IsCreated) _clothCollision.Dispose();
|
||||
if (_forces.IsCreated) _forces.Dispose();
|
||||
|
||||
if (_warps.IsCreated) _warps.Dispose();
|
||||
@@ -213,7 +213,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
_info = new(info.ToArray(), Allocator.Persistent);
|
||||
_strandCollision = new(pos.Length, Allocator.Persistent);
|
||||
_clothCollisionCount = new(pos.Length, Allocator.Persistent);
|
||||
_clothCollisionDelta = new(pos.Length, Allocator.Persistent);
|
||||
_clothCollision = new(pos.Length, Allocator.Persistent);
|
||||
_forces = new(pos.Length, Allocator.Persistent);
|
||||
|
||||
//
|
||||
@@ -269,7 +269,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
Forces = _forces,
|
||||
|
||||
CollisionCount = _clothCollisionCount,
|
||||
CollisionDelta = _clothCollisionDelta,
|
||||
CollisionDelta = _clothCollision,
|
||||
}.Schedule(_transformAccessArray, handle);
|
||||
|
||||
// spring(cloth weft)
|
||||
@@ -279,7 +279,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
CurrentPositions = _currentPositions,
|
||||
|
||||
Force = _forces,
|
||||
}.Schedule(_clothRects.Length, 128, handle);
|
||||
}.Schedule(_clothRects.Length, 1, handle);
|
||||
|
||||
// verlet
|
||||
handle = new VerletJob
|
||||
@@ -293,7 +293,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
|
||||
NextPositions = _nextPositions,
|
||||
NextRotations = _nextRotations,
|
||||
}.Schedule(_info.Length, 128, handle);
|
||||
}.Schedule(_info.Length, 1, handle);
|
||||
|
||||
// 親子の長さで拘束
|
||||
handle = new ParentLengthConstraintJob
|
||||
@@ -301,7 +301,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
Warps = _warps,
|
||||
Info = _info,
|
||||
NextPositions = _nextPositions,
|
||||
}.Schedule(_warps.Length, 16, handle);
|
||||
}.Schedule(_warps.Length, 1, handle);
|
||||
|
||||
// collision
|
||||
{
|
||||
@@ -314,7 +314,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
NextPositions = _nextPositions,
|
||||
ClothUsedParticles = _clothUsedParticles,
|
||||
StrandCollision = _strandCollision,
|
||||
}.Schedule(_info.Length, 128, handle);
|
||||
}.Schedule(_info.Length, 1, handle);
|
||||
|
||||
var handle1 = new ClothCollisionJob
|
||||
{
|
||||
@@ -324,10 +324,10 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
Info = _info,
|
||||
NextPositions = _nextPositions,
|
||||
CollisionCount = _clothCollisionCount,
|
||||
CollisionDelta = _clothCollisionDelta,
|
||||
ClothCollision = _clothCollision,
|
||||
|
||||
ClothRects = _clothRects,
|
||||
}.Schedule(_clothRects.Length, 128, handle);
|
||||
}.Schedule(_clothRects.Length, 1, handle);
|
||||
|
||||
handle = JobHandle.CombineDependencies(handle0, handle1);
|
||||
|
||||
@@ -336,9 +336,9 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
ClothUsedParticles = _clothUsedParticles,
|
||||
StrandCollision = _strandCollision,
|
||||
ClothCollisionCount = _clothCollisionCount,
|
||||
ClothCollisionDelta = _clothCollisionDelta,
|
||||
ClothCollision = _clothCollision,
|
||||
NextPosition = _nextPositions,
|
||||
}.Schedule(_info.Length, 128, handle);
|
||||
}.Schedule(_info.Length, 1, handle);
|
||||
}
|
||||
|
||||
// 親子の長さで拘束. TODO: ApplyRotationJob と合体
|
||||
@@ -347,7 +347,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
Warps = _warps,
|
||||
Info = _info,
|
||||
NextPositions = _nextPositions,
|
||||
}.Schedule(_warps.Length, 16, handle);
|
||||
}.Schedule(_warps.Length, 1, handle);
|
||||
// NextPositions から NextRotations を作る
|
||||
handle = new ApplyRotationJob
|
||||
{
|
||||
@@ -356,7 +356,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
CurrentTransforms = _inputData,
|
||||
NextPositions = _nextPositions,
|
||||
NextRotations = _nextRotations,
|
||||
}.Schedule(_warps.Length, 16, handle);
|
||||
}.Schedule(_warps.Length, 1, handle);
|
||||
|
||||
// output
|
||||
handle = new OutputTransformJob
|
||||
|
||||
@@ -141,24 +141,35 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
[ReadOnly] public NativeArray<TransformInfo> Info;
|
||||
[ReadOnly] public NativeArray<Vector3> NextPositions;
|
||||
[NativeDisableParallelForRestriction] public NativeArray<int> CollisionCount;
|
||||
[NativeDisableParallelForRestriction] public NativeArray<Vector3> CollisionDelta;
|
||||
[NativeDisableParallelForRestriction] public NativeArray<Vector3> ClothCollision;
|
||||
|
||||
// cloth
|
||||
[ReadOnly] public NativeArray<(SpringConstraint, ClothRect)> ClothRects;
|
||||
|
||||
private void CollisionMove(int particleIndex, Vector3 delta)
|
||||
private void CollisionMove(int particleIndex, LineSegment l, BlittableCollider c)
|
||||
{
|
||||
#if false
|
||||
CollisionCount[particleIndex] = 1;
|
||||
ClothCollision[particleIndex] = l.GetPoint(c.radius);
|
||||
#else
|
||||
var delta = l.GetDelta(c.radius);
|
||||
|
||||
#if false
|
||||
// 足して割る
|
||||
CollisionCount[particleIndex] += 1;
|
||||
CollisionDelta[particleIndex] += delta;
|
||||
#elif false
|
||||
// 足す
|
||||
CollisionCount[particleIndex] = 1;
|
||||
CollisionDelta[particleIndex] += delta;
|
||||
#else
|
||||
// 深いのに1回当てる
|
||||
if (CollisionDelta[particleIndex].sqrMagnitude < delta.sqrMagnitude)
|
||||
// max
|
||||
if (delta.sqrMagnitude > ClothCollision[particleIndex].sqrMagnitude)
|
||||
{
|
||||
CollisionCount[particleIndex] = 1;
|
||||
CollisionDelta[particleIndex] = delta;
|
||||
ClothCollision[particleIndex] = delta;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -206,15 +217,15 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
|
||||
if (TryCollide(collider, collider_matrix, _triangle0, out var l0))
|
||||
{
|
||||
CollisionMove(rect._a, l0.GetDelta(collider.radius));
|
||||
CollisionMove(rect._b, l0.GetDelta(collider.radius));
|
||||
CollisionMove(rect._c, l0.GetDelta(collider.radius));
|
||||
CollisionMove(rect._a, l0, collider);
|
||||
CollisionMove(rect._b, l0, collider);
|
||||
CollisionMove(rect._c, l0, collider);
|
||||
}
|
||||
if (TryCollide(collider, collider_matrix, _triangle1, out var l1))
|
||||
{
|
||||
CollisionMove(rect._c, l1.GetDelta(collider.radius));
|
||||
CollisionMove(rect._d, l1.GetDelta(collider.radius));
|
||||
CollisionMove(rect._a, l1.GetDelta(collider.radius));
|
||||
CollisionMove(rect._c, l1, collider);
|
||||
CollisionMove(rect._d, l1, collider);
|
||||
CollisionMove(rect._a, l1, collider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,7 +319,7 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
[ReadOnly] public NativeArray<bool> ClothUsedParticles;
|
||||
[ReadOnly] public NativeArray<Vector3> StrandCollision;
|
||||
[ReadOnly] public NativeArray<int> ClothCollisionCount;
|
||||
[ReadOnly] public NativeArray<Vector3> ClothCollisionDelta;
|
||||
[ReadOnly] public NativeArray<Vector3> ClothCollision;
|
||||
[NativeDisableParallelForRestriction] public NativeArray<Vector3> NextPosition;
|
||||
|
||||
public void Execute(int particleIndex)
|
||||
@@ -317,7 +328,8 @@ namespace UniVRM10.ClothWarp.Jobs
|
||||
{
|
||||
if (ClothCollisionCount[particleIndex] > 0)
|
||||
{
|
||||
NextPosition[particleIndex] += (ClothCollisionDelta[particleIndex] / ClothCollisionCount[particleIndex]);
|
||||
NextPosition[particleIndex] += (ClothCollision[particleIndex] / ClothCollisionCount[particleIndex]);
|
||||
// NextPosition[particleIndex] = ClothCollision[particleIndex];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user