17-07-2023, 07:01 AM
(This post was last modified: 17-07-2023, 07:02 AM by josemendez.)
(15-07-2023, 02:55 PM)domopuff Wrote: Thanks for the reply! I managed to get the collisions detection working but performance did take a heavy hit.
If you iterate trough all contacts in the main thread using a simple for loop and there's many contacts in your scene, performance will of course be less than good. Try doing this using jobs instead.
(15-07-2023, 02:55 PM)domopuff Wrote: Any way we can try get the center points of a cloth instead?
Sure, iterate trough all particles in the cloth and calculate their center of mass. There's a snippet in the manual that does just this, pasting it here for convenience:
http://obi.virtualmethodstudio.com/manua...icles.html
Code:
using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiActor))]
public class ActorCOM : MonoBehaviour {
ObiActor actor;
void Awake(){
actor = GetComponent<ObiActor>();
}
void OnDrawGizmos(){
if (actor == null || !actor.isLoaded)
return;
Gizmos.color = Color.red;
Vector4 com = Vector4.zero;
float massAccumulator = 0;
// Iterate over all particles in an actor:
for (int i = 0; i < actor.solverIndices.Length; ++i){
// retrieve the particle index in the solver:
int solverIndex = actor.solverIndices[i];
// look up the inverse mass of this particle:
float invMass = actor.solver.invMasses[solverIndex];
// accumulate it:
if (invMass > 0)
{
massAccumulator += 1.0f / invMass;
com += actor.solver.positions[solverIndex] / invMass;
}
}
com /= massAccumulator;
Gizmos.DrawWireSphere(com,0.1f);
}
}
Again, doing this in the main thread using a for loop will be slow. Note you can directly use Obi solver arrays in a job, see the "Using Jobs to process particles" section at the end of the page linked above.
kind regards,