Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Equipping Obi cloth.
#1
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!
Reply
#2
(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!
Reply
#3
(19-10-2017, 08:09 AM)josemendez Wrote: Hi there,

You can just make prefabs out of them, then instantiate them at runtime.

cheers!

Hey Jose,
Thanks for the response! I guess I should have been more specific, so my question is with regards to "Attaching Obi Cloth/Objects" i.e. as per the documents the instructions Obi objects are be attached to another gameobject by fixing particles, handles and Pin constraints . Also, the document mentions we need to be in edit mode to perform those actions, so my question is can this be done programmatically, i.e. when a user decides to sway the clothes or weapons, how can this be done programmatically, is that even a possibility. 

Thanks,
Srikanth.


Reply
#4
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();
        }
Reply
#5
(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 Sonrisa
Reply