Example #1
0
        public override void Merge(ObiActor actor, IObiConstraintsBatch other)
        {
            var batch = other as ObiSkinConstraintsBatch;

            if (batch != null)
            {
                particleIndices.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                skinPoints.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                skinNormals.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                skinRadiiBackstop.ResizeUninitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 3);
                skinCompliance.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                lambdas.ResizeInitialized(m_ActiveConstraintCount + batch.activeConstraintCount);

                skinPoints.CopyFrom(batch.skinPoints, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                skinNormals.CopyFrom(batch.skinNormals, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                skinCompliance.CopyFrom(batch.skinCompliance, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                skinRadiiBackstop.CopyFrom(batch.skinRadiiBackstop, 0, m_ActiveConstraintCount * 3, batch.activeConstraintCount * 3);

                for (int i = 0; i < batch.activeConstraintCount; ++i)
                {
                    particleIndices[m_ActiveConstraintCount + i] = actor.solverIndices[batch.particleIndices[i]];
                }

                base.Merge(actor, other);
            }
        }
Example #2
0
        public override void Merge(ObiActor actor, IObiConstraintsBatch other)
        {
            var batch = other as ObiBendConstraintsBatch;
            var user  = actor as IBendConstraintsUser;

            if (batch != null && user != null)
            {
                if (!user.bendConstraintsEnabled)
                {
                    return;
                }

                particleIndices.ResizeUninitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 3);
                restBends.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                bendingStiffnesses.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                plasticity.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                lambdas.ResizeInitialized(m_ActiveConstraintCount + batch.activeConstraintCount);

                restBends.CopyFrom(batch.restBends, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                bendingStiffnesses.CopyReplicate(new Vector2(user.maxBending, user.bendCompliance), m_ActiveConstraintCount, batch.activeConstraintCount);
                plasticity.CopyReplicate(new Vector2(user.plasticYield, user.plasticCreep), m_ActiveConstraintCount, batch.activeConstraintCount);

                for (int i = 0; i < batch.activeConstraintCount * 3; ++i)
                {
                    particleIndices[m_ActiveConstraintCount * 3 + i] = actor.solverIndices[batch.particleIndices[i]];
                }

                base.Merge(actor, other);
            }
        }
        public override void Merge(ObiActor actor, IObiConstraintsBatch other)
        {
            var batch = other as ObiPinConstraintsBatch;

            if (batch != null)
            {
                particleIndices.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);

                colliderIndices.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                offsets.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                restDarbouxVectors.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                stiffnesses.ResizeUninitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 2);
                breakThresholds.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                lambdas.ResizeInitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 4);

                offsets.CopyFrom(batch.offsets, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                restDarbouxVectors.CopyFrom(batch.restDarbouxVectors, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                stiffnesses.CopyFrom(batch.stiffnesses, 0, m_ActiveConstraintCount * 2, batch.activeConstraintCount * 2);
                breakThresholds.CopyFrom(batch.breakThresholds, 0, m_ActiveConstraintCount, batch.activeConstraintCount);

                for (int i = 0; i < batch.activeConstraintCount; ++i)
                {
                    particleIndices[m_ActiveConstraintCount + i] = batch.particleIndices[i];
                    colliderIndices[m_ActiveConstraintCount + i] = batch.pinBodies[i] != null ? batch.pinBodies[i].index : -1;
                }

                base.Merge(actor, other);
            }
        }
        public override void Merge(ObiActor actor, IObiConstraintsBatch other)
        {
            var batch = other as ObiVolumeConstraintsBatch;
            var user  = actor as IVolumeConstraintsUser;

            if (batch != null && user != null)
            {
                if (!user.volumeConstraintsEnabled)
                {
                    return;
                }

                int initialIndexCount = particleIndices.count;

                int numActiveTriangles = 0;
                for (int i = 0; i < batch.constraintCount; ++i)
                {
                    numActiveTriangles += batch.numTriangles[i];
                }

                particleIndices.ResizeUninitialized(initialIndexCount + numActiveTriangles * 3);
                firstTriangle.ResizeUninitialized(firstTriangle.count + batch.activeConstraintCount);
                numTriangles.ResizeUninitialized(numTriangles.count + batch.activeConstraintCount);
                restVolumes.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                pressureStiffness.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                lambdas.ResizeInitialized(m_ActiveConstraintCount + batch.activeConstraintCount);

                numTriangles.CopyFrom(batch.numTriangles, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                restVolumes.CopyFrom(batch.restVolumes, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                pressureStiffness.CopyReplicate(new Vector2(user.pressure, user.compressionCompliance), m_ActiveConstraintCount, batch.activeConstraintCount);

                for (int i = 0; i < numActiveTriangles * 3; ++i)
                {
                    particleIndices[initialIndexCount + i] = actor.solverIndices[batch.particleIndices[i]];
                }

                for (int i = 0; i < batch.activeConstraintCount + 1; ++i)
                {
                    firstTriangle[m_ActiveConstraintCount + i] = initialIndexCount / 3 + batch.firstTriangle[i];
                }

                base.Merge(actor, other);
            }
        }
        public override void Merge(ObiActor actor, IObiConstraintsBatch other)
        {
            var batch = other as ObiStretchShearConstraintsBatch;
            var user  = actor as IStretchShearConstraintsUser;

            if (batch != null && user != null)
            {
                if (!user.stretchShearConstraintsEnabled)
                {
                    return;
                }

                particleIndices.ResizeUninitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 2);
                orientationIndices.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                restLengths.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                restOrientations.ResizeUninitialized(lambdas.count + batch.activeConstraintCount);
                stiffnesses.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                lambdas.ResizeInitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 3);

                restLengths.CopyFrom(batch.restLengths, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                restOrientations.CopyFrom(batch.restOrientations, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                stiffnesses.CopyReplicate(new Vector3(user.stretchCompliance, user.shear1Compliance, user.shear2Compliance), m_ActiveConstraintCount, batch.activeConstraintCount);

                for (int i = 0; i < batch.activeConstraintCount * 2; ++i)
                {
                    particleIndices[m_ActiveConstraintCount * 2 + i] = actor.solverIndices[batch.particleIndices[i]];
                }

                for (int i = 0; i < batch.activeConstraintCount; ++i)
                {
                    orientationIndices[m_ActiveConstraintCount + i] = actor.solverIndices[batch.orientationIndices[i]];
                }

                base.Merge(actor, other);
            }
        }