Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Usage of particle position variables
#1
hi!


I see multiple variables about particle coordinates in IkSolver. They are: positions, restPositions, prevPosition, startPosition.
What is the specific update time for them?


In my case,I used two rigid bodies to try to lift the soft body.
Since I can't lift the soft body directly through friction, my design is to use collision detection to update the positions of the particles on the contact surface, so that the outer wall of the soft body is lifted by the rigid body.
For example, as shown in the following code, when OnObiCollision, the y component change of the rigid body is provided to the colliding particles. Although this implementation can make the soft body shake slightly, it still cannot be lifted completely.
If my code implementation is correct, I don't quite understand this problem. In my code, shouldn't the contact surface of the soft body be completely at the same height as the rigid body?
   

Code:
    public void OnObiCollision(ObiSolver solver, ObiNativeContactList contacts)
    {
        collisionnParticleSolverIndexes.Clear();
        leftCollisionParticleSolverIndexes.Clear();
        rightCollisionParticleSolverIndexes.Clear();

        for (int index = 0; index < contacts.count; index++)
        {
            Oni.Contact contact = contacts[index];

            int particleIndexInSolver = solver.simplices[contact.bodyA];

            ObiColliderBase collider = colliderWorld.colliderHandles[contact.bodyB].owner;
            if (collider.transform == leftClaw)
            {
                leftCollisionParticleSolverIndexes.Add(particleIndexInSolver);
            }
            else if (collider.transform == rightClaw)
            {
                rightCollisionParticleSolverIndexes.Add(particleIndexInSolver);
            }
        }

        isBind = leftCollisionParticleSolverIndexes.Count + rightCollisionParticleSolverIndexes.Count > 400;

        if (isBind)
        {
            float leftClawHeightOffset = leftClaw.transform.position.y - leftClawHeightBuffer;
            float rightClawHeightOffset = rightClaw.transform.position.y - rightClawHeightBuffer;

            for (int index = 0; index < leftCollisionParticleSolverIndexes.Count; index++)
            {
                int particleIndex = leftCollisionParticleSolverIndexes[index];

                solver.positions[particleIndex] = solver.startPositions[particleIndex] + new Vector4(0, leftClawHeightOffset, 0);
                solver.velocities[particleIndex] = Vector4.zero;
                solver.angularVelocities[particleIndex] = Vector4.zero;
                solver.externalForces[particleIndex] = Vector4.zero;
                solver.externalTorques[particleIndex] = Vector4.zero;
            }
            for (int index = 0; index < rightCollisionParticleSolverIndexes.Count; index++)
            {
                int particleIndex = rightCollisionParticleSolverIndexes[index];


                solver.positions[particleIndex] = solver.startPositions[particleIndex] + new Vector4(0, rightClawHeightOffset, 0);
                solver.velocities[particleIndex] = Vector4.zero;
                solver.angularVelocities[particleIndex] = Vector4.zero;
                solver.externalForces[particleIndex] = Vector4.zero;
                solver.externalTorques[particleIndex] = Vector4.zero;
            }
        }

        leftClawHeightBuffer = leftClaw.transform.position.y;
        rightClawHeightBuffer = rightClaw.transform.position.y;
    }

By the way, in addition to modifying the positions of the contact surface particles during the collision callback, I also tried to provide the particles with additional upward velocity. But I always feel that the particles on the contact surface seem to be given a downward momentum at some point in some way I don't know.

While retaining gravity, I hope to find a way to present the effect of the soft body being stably fixed in the air by external forces. To be honest, the effect I expected is like ObiParticleAttachment, but due to some project reasons, I can't use ObiParticleAttachment.
Reply


Messages In This Thread
Usage of particle position variables - by wenhao_zheng - 11-07-2024, 03:12 PM