Beispiel #1
0
        private void EnableAttachment(AttachmentType type)
        {
            if (enabled && m_Actor.isLoaded && isBound)
            {
                var solver = m_Actor.solver;

                switch (type)
                {
                case AttachmentType.Dynamic:

                    var pins = m_Actor.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiPinConstraintsData;
                    attachedCollider = m_Target.GetComponent <ObiColliderBase>();

                    if (pins != null && attachedCollider != null && pinBatch == null)
                    {
                        // create a new data batch with all our pin constraints:
                        pinBatch = new ObiPinConstraintsBatch(pins);
                        for (int i = 0; i < m_SolverIndices.Length; ++i)
                        {
                            pinBatch.AddConstraint(m_SolverIndices[i],
                                                   attachedCollider,
                                                   m_PositionOffsets[i],
                                                   m_OrientationOffsets[i],
                                                   m_Compliance,
                                                   constrainOrientation ? 0 : 10000,
                                                   m_BreakThreshold);

                            pinBatch.activeConstraintCount++;
                        }

                        // add the batch to the actor:
                        pins.AddBatch(pinBatch);

                        // store the attached collider's handle:
                        attachedColliderHandleIndex = -1;
                        if (attachedCollider.Handle != null)
                        {
                            attachedColliderHandleIndex = attachedCollider.Handle.index;
                        }

                        m_Actor.SetConstraintsDirty(Oni.ConstraintType.Pin);
                    }

                    break;

                case AttachmentType.Static:

                    for (int i = 0; i < m_SolverIndices.Length; ++i)
                    {
                        if (m_SolverIndices[i] >= 0 && m_SolverIndices[i] < solver.invMasses.count)
                        {
                            solver.invMasses[m_SolverIndices[i]] = 0;
                        }
                    }

                    if (m_Actor.usesOrientedParticles && m_ConstrainOrientation)
                    {
                        for (int i = 0; i < m_SolverIndices.Length; ++i)
                        {
                            if (m_SolverIndices[i] >= 0 && m_SolverIndices[i] < solver.invRotationalMasses.count)
                            {
                                solver.invRotationalMasses[m_SolverIndices[i]] = 0;
                            }
                        }
                    }

                    m_Actor.UpdateParticleProperties();

                    break;
                }
            }
        }
        private void Enable(AttachmentType type)
        {
            var solver    = m_Actor.solver;
            var blueprint = m_Actor.blueprint;

            if (isBound && blueprint != null && m_Actor.solver != null)
            {
                switch (type)
                {
                case AttachmentType.Dynamic:

                    var             pins             = m_Actor.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>;
                    ObiColliderBase attachedCollider = m_Target.GetComponent <ObiColliderBase>();

                    if (pins != null && attachedCollider != null)
                    {
                        // create a new data batch with all our pin constraints:
                        pinBatch = new ObiPinConstraintsBatch();
                        for (int i = 0; i < m_PositionOffsets.Length; ++i)
                        {
                            pinBatch.AddConstraint(0, attachedCollider, m_PositionOffsets[i], m_OrientationOffsets[i]);
                            pinBatch.activeConstraintCount++;
                        }

                        // add the batch to the solver:
                        pins.AddBatch(pinBatch);
                        pinBatch.AddToSolver(pins);

                        // override the pin indices with the ones we got at bind time:
                        for (int i = 0; i < m_SolverIndices.Length; ++i)
                        {
                            pinBatch.particleIndices[i]     = m_SolverIndices[i];
                            pinBatch.stiffnesses[i * 2]     = m_Compliance;
                            pinBatch.stiffnesses[i * 2 + 1] = constrainOrientation?0:10000;
                            pinBatch.breakThresholds[i]     = m_BreakThreshold;
                        }

                        // enable the batch:
                        pinBatch.SetEnabled(true);
                    }

                    break;

                case AttachmentType.Static:

                    for (int i = 0; i < m_SolverIndices.Length; ++i)
                    {
                        solver.invMasses[m_SolverIndices[i]] = 0;
                    }

                    if (m_Actor.usesOrientedParticles && m_ConstrainOrientation)
                    {
                        for (int i = 0; i < m_SolverIndices.Length; ++i)
                        {
                            solver.invRotationalMasses[m_SolverIndices[i]] = 0;
                        }
                    }

                    m_Actor.UpdateParticleProperties();

                    break;
                }
            }
        }