Beispiel #1
0
        private void UpdateDynamicAttachment(float stepTime)
        {
            if (enabled && m_AttachmentType == AttachmentType.Dynamic && m_Actor.isLoaded && isBound)
            {
                var solver    = m_Actor.solver;
                var blueprint = m_Actor.sourceBlueprint;

                var actorConstraints  = m_Actor.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>;
                var solverConstraints = solver.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>;

                if (actorConstraints != null && pinBatch != null)
                {
                    // deactivate constraints over the break threshold.
                    int offset      = actor.solverBatchOffsets[(int)Oni.ConstraintType.Pin][pinBatchIndex];
                    var solverBatch = solverConstraints.batches[pinBatchIndex];

                    float sqrTime = stepTime * stepTime;
                    for (int i = 0; i < pinBatch.activeConstraintCount; i++)
                    {
                        if (-solverBatch.lambdas[(offset + i) * 4 + 3] / sqrTime > pinBatch.breakThresholds[i])
                        {
                            pinBatch.DeactivateConstraint(i);
                        }
                    }
                }

                // constraints are recreated at the start of a step. if we recreate them constantly, when we arrive here there's no
                m_Actor.SetConstraintsDirty(Oni.ConstraintType.Pin);
            }
        }
Beispiel #2
0
        private void BreakDynamicAttachment(float stepTime)
        {
            if (enabled && m_AttachmentType == AttachmentType.Dynamic && m_Actor.isLoaded && isBound)
            {
                var solver = m_Actor.solver;

                var actorConstraints  = m_Actor.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>;
                var solverConstraints = solver.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>;

                bool dirty = false;
                if (actorConstraints != null && pinBatch != null)
                {
                    int pinBatchIndex = actorConstraints.batches.IndexOf(pinBatch);
                    if (pinBatchIndex >= 0)
                    {
                        int offset      = actor.solverBatchOffsets[(int)Oni.ConstraintType.Pin][pinBatchIndex];
                        var solverBatch = solverConstraints.batches[pinBatchIndex];

                        float sqrTime = stepTime * stepTime;
                        for (int i = 0; i < pinBatch.activeConstraintCount; i++)
                        {
                            // In case the handle has been created/destroyed.
                            if (pinBatch.pinBodies[i] != attachedCollider.Handle)
                            {
                                pinBatch.pinBodies[i] = attachedCollider.Handle;
                                dirty = true;
                            }

                            // in case the constraint has been broken:
                            if (-solverBatch.lambdas[(offset + i) * 4 + 3] / sqrTime > pinBatch.breakThresholds[i])
                            {
                                pinBatch.DeactivateConstraint(i);
                                dirty = true;
                            }
                        }
                    }
                }

                // constraints are recreated at the start of a step.
                if (dirty)
                {
                    m_Actor.SetConstraintsDirty(Oni.ConstraintType.Pin);
                }
            }
        }