public override void Merge(ObiActor actor, IObiConstraintsBatch other)
        {
            var batch = other as ObiAerodynamicConstraintsBatch;
            var user  = actor as IAerodynamicConstraintsUser;

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

                particleIndices.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                aerodynamicCoeffs.ResizeUninitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 3);

                for (int i = 0; i < batch.activeConstraintCount; ++i)
                {
                    particleIndices[m_ActiveConstraintCount + i]             = actor.solverIndices[batch.particleIndices[i]];
                    aerodynamicCoeffs[(m_ActiveConstraintCount + i) * 3]     = batch.aerodynamicCoeffs[i * 3];
                    aerodynamicCoeffs[(m_ActiveConstraintCount + i) * 3 + 1] = user.drag;
                    aerodynamicCoeffs[(m_ActiveConstraintCount + i) * 3 + 2] = user.lift;
                }

                base.Merge(actor, other);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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 ObiDistanceConstraintsBatch;
            var user  = actor as IDistanceConstraintsUser;

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

                particleIndices.ResizeUninitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 2);
                restLengths.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                stiffnesses.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                lambdas.ResizeInitialized(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)
                {
                    float restLength = batch.restLengths[i] * user.stretchingScale;
                    restLengths[m_ActiveConstraintCount + i] = restLength; // TODO: use nativelist methods?
                    stiffnesses[m_ActiveConstraintCount + i] = new Vector2(user.stretchCompliance, user.maxCompression * restLength);
                }

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

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

                particleIndices.ResizeUninitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 2);
                maxLengthsScales.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                stiffnesses.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                lambdas.ResizeInitialized(m_ActiveConstraintCount + batch.activeConstraintCount);

                stiffnesses.CopyReplicate(user.tetherCompliance, 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)
                {
                    maxLengthsScales[m_ActiveConstraintCount + i] = new Vector2(batch.maxLengthsScales[i].x, user.tetherScale);
                }

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

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

                int initialIndexCount = particleIndices.count;

                // shape matching constraint particle indices are not reordered when deactivating constraints,
                // so instead of using batch.activeConstraintCount, batch.constraintCount. We need all of them.
                int numActiveIndices = 0;
                for (int i = 0; i < batch.constraintCount; ++i)
                {
                    numActiveIndices += batch.numIndices[i];
                }

                particleIndices.ResizeUninitialized(initialIndexCount + numActiveIndices);
                firstIndex.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                numIndices.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                explicitGroup.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                materialParameters.ResizeUninitialized((m_ActiveConstraintCount + batch.activeConstraintCount) * 5);

                restComs.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                coms.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                orientations.ResizeUninitialized(m_ActiveConstraintCount + batch.activeConstraintCount);
                lambdas.ResizeInitialized(m_ActiveConstraintCount + batch.activeConstraintCount);

                numIndices.CopyFrom(batch.numIndices, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                explicitGroup.CopyFrom(batch.explicitGroup, 0, m_ActiveConstraintCount, batch.activeConstraintCount);
                orientations.CopyReplicate(actor.actorLocalToSolverMatrix.rotation, m_ActiveConstraintCount, batch.activeConstraintCount);

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

                for (int i = 0; i < batch.activeConstraintCount; ++i)
                {
                    firstIndex[m_ActiveConstraintCount + i] = batch.firstIndex[i] + initialIndexCount;
                    materialParameters[(m_ActiveConstraintCount + i) * 5]     = user.deformationResistance;
                    materialParameters[(m_ActiveConstraintCount + i) * 5 + 1] = user.plasticYield;
                    materialParameters[(m_ActiveConstraintCount + i) * 5 + 2] = user.plasticCreep;
                    materialParameters[(m_ActiveConstraintCount + i) * 5 + 3] = user.plasticRecovery;
                    materialParameters[(m_ActiveConstraintCount + i) * 5 + 4] = user.maxDeformation;
                }

                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);
            }
        }
Esempio n. 9
0
        public void PushDataToSolver()
        {
            if (!inSolver)
            {
                return;
            }

            // set solver constraint data:
            particleIndices.ResizeUninitialized(stitches.Count * 2);
            stiffnesses.ResizeUninitialized(stitches.Count);

            for (int i = 0; i < stitches.Count; i++)
            {
                particleIndices[i * 2]     = actor1.solverIndices[stitches[i].particleIndex1];
                particleIndices[i * 2 + 1] = actor2.solverIndices[stitches[i].particleIndex2];
                stiffnesses[i]             = 0;
            }

            Oni.SetStitchConstraints(batch, particleIndices.GetIntPtr(), stiffnesses.GetIntPtr(), stitches.Count);
            Oni.SetActiveConstraints(batch, stitches.Count);
        }
Esempio n. 10
0
        public void PushDataToSolver()
        {
            if (!inSolver)
            {
                return;
            }

            // set solver constraint data:
            lambdas.Clear();
            particleIndices.ResizeUninitialized(stitches.Count * 2);
            stiffnesses.ResizeUninitialized(stitches.Count);
            lambdas.ResizeUninitialized(stitches.Count);

            for (int i = 0; i < stitches.Count; i++)
            {
                particleIndices[i * 2]     = actor1.solverIndices[stitches[i].particleIndex1];
                particleIndices[i * 2 + 1] = actor2.solverIndices[stitches[i].particleIndex2];
                stiffnesses[i]             = 0;
                lambdas[i] = 0;
            }

            m_BatchImpl.SetStitchConstraints(particleIndices, stiffnesses, lambdas, stitches.Count);
        }
        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);
            }
        }