Hello there,
I just purchased Obi cloth and very excited to build using the same. As per the videos, the possibilities look amazing. I am working on a project where I need to build a bunch of Obi clothes or objects(guns to hang around by the belt etc). In the game, users can swap the clothes or objects and I am not sure how this can be implemented using Obi cloth. Any suggestions would be really helpful.
Thanks!
(18-10-2017, 07:47 PM)sriky Wrote: [ -> ]Hello there,
I just purchased Obi cloth and very excited to build using the same. As per the videos, the possibilities look amazing. I am working on a project where I need to build a bunch of Obi clothes or objects(guns to hang around by the belt etc). In the game, users can swap the clothes or objects and I am not sure how this can be implemented using Obi cloth. Any suggestions would be really helpful.
Thanks!
Hi there,
You can just make prefabs out of them, then instantiate them at runtime.
cheers!
You can pin any object with an obiCollider on it with this. It can be update to support multiple partciles per collider if that whats needed by changing the dictionary to <ObiCollider, int[]> and a little bit more work.
Code:
public Dictionary<ObiCollider, int> pinnedColliders = new Dictionary<ObiCollider, int>();
public ObiCloth actor;
public void PinObiColliderToParticle(ObiCollider obiCollider, int particleIndex, Vector3? pinOffset = null, int? pinStiffness = null)
{
if (pinnedColliders.ContainsKey(obiCollider))
return;
ObiPinConstraintBatch batch = actor.PinConstraints.GetBatches()[0] as ObiPinConstraintBatch;
actor.PinConstraints.RemoveFromSolver(null);
// Set the pin as the next availiable index in the batch
pinnedColliders.Add(obiCollider, batch.ConstraintCount);
batch.AddConstraint(particleIndex, obiCollider, pinOffset == null ? Vector3.zero : pinOffset.Value, pinStiffness == null ? 1 : pinStiffness.Value);
actor.PinConstraints.AddToSolver(null);
actor.PinConstraints.PushDataToSolver();
}
public void UnpinObiCollider(ObiCollider obiCollider)
{
if (!pinnedColliders.ContainsKey(obiCollider))
return;
ObiPinConstraintBatch batch = actor.PinConstraints.GetBatches()[0] as ObiPinConstraintBatch;
actor.PinConstraints.RemoveFromSolver(null);
int pinIndex = pinnedColliders[obiCollider];
batch.RemoveConstraint(pinIndex);
pinnedColliders.Remove(obiCollider);
List<ObiCollider> keys = new List<ObiCollider>(pinnedColliders.Keys);
// Decrement the pinned indices that are greater than the removed index
foreach (ObiCollider collider in keys)
{
int checkIndex = pinnedColliders[collider];
if (checkIndex >= 0 && checkIndex > pinIndex)
{
pinnedColliders[collider]--;
}
}
actor.PinConstraints.AddToSolver(null);
actor.PinConstraints.PushDataToSolver();
}
(19-10-2017, 11:35 PM)niZmo Wrote: [ -> ]You can pin any object with an obiCollider on it with this. It can be update to support multiple partciles per collider if that whats needed by changing the dictionary to <ObiCollider, int[]> and a little bit more work.
Code:
public Dictionary<ObiCollider, int> pinnedColliders = new Dictionary<ObiCollider, int>();
public ObiCloth actor;
public void PinObiColliderToParticle(ObiCollider obiCollider, int particleIndex, Vector3? pinOffset = null, int? pinStiffness = null)
{
if (pinnedColliders.ContainsKey(obiCollider))
return;
ObiPinConstraintBatch batch = actor.PinConstraints.GetBatches()[0] as ObiPinConstraintBatch;
actor.PinConstraints.RemoveFromSolver(null);
// Set the pin as the next availiable index in the batch
pinnedColliders.Add(obiCollider, batch.ConstraintCount);
batch.AddConstraint(particleIndex, obiCollider, pinOffset == null ? Vector3.zero : pinOffset.Value, pinStiffness == null ? 1 : pinStiffness.Value);
actor.PinConstraints.AddToSolver(null);
actor.PinConstraints.PushDataToSolver();
}
public void UnpinObiCollider(ObiCollider obiCollider)
{
if (!pinnedColliders.ContainsKey(obiCollider))
return;
ObiPinConstraintBatch batch = actor.PinConstraints.GetBatches()[0] as ObiPinConstraintBatch;
actor.PinConstraints.RemoveFromSolver(null);
int pinIndex = pinnedColliders[obiCollider];
batch.RemoveConstraint(pinIndex);
pinnedColliders.Remove(obiCollider);
List<ObiCollider> keys = new List<ObiCollider>(pinnedColliders.Keys);
// Decrement the pinned indices that are greater than the removed index
foreach (ObiCollider collider in keys)
{
int checkIndex = pinnedColliders[collider];
if (checkIndex >= 0 && checkIndex > pinIndex)
{
pinnedColliders[collider]--;
}
}
actor.PinConstraints.AddToSolver(null);
actor.PinConstraints.PushDataToSolver();
}
Wow! Thanks @niZmo. It sounds very promising and I will surely give it a try and let you know what happens