Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Multiple Rope Cursors on single rope
#6
(02-11-2019, 08:35 AM)josemendez Wrote: Hi,

Adding new particles to a baked simulation won't behave nicely (since the new particles do not have any cached information, it's impossible to expect the playback to work). Anyway the baker is undocumented, unmaintained and pretty much unsupported as of now (in fact, it's entirely gone in 5.0). It was written way back in Obi 1.0 when there was no good way of getting baked simulations into Unity, but nowadays Alembic does a much better job of importing them so there's little motivation to maintain a system that does the same, but worse.  See this thread:
http://obi.virtualmethodstudio.com/forum...p?tid=1455

When adding particles from a rope, particles are appended/removed from the particle list, but aren't sorted in any particular way. If for some reason you need to get all particles in the rope in order (from first to last), you need to iterate over structural constraints (distance constraints for ropes, stretch/shear constraints for rods). Each structural constraint holds 2 particles together, and unlike particles, they are guaranteed to alway be correctly sorted:

Code:
int constraintCount = rope.GetStructuralConstraintCount();
for (int i = 0; i < constraintCount; ++i)
{
    int particle1 = -1, particle2 = -1;
    if (rope.GetStructuralConstraintParticles(i,ref particle1,ref particle2))
       {
        Vector3 pos1 = rope.GetParticlePosition(particle1)
               Vector3 pos2 = rope.GetParticlePosition(particle2));
    }
}

Or if you just want to iterate over all active particles in no particular order:
Code:
for (int i = 0; i < rope.particleIndices.Length; ++i)
{
    if (rope.active[i])
    {
    //do stuff
    }
}

I created this solution meanwhile. Seems to work so far with a single cursor. Will have to do some more tests, but it seems like this at least orders the particles correctly so that the prefab instantiated stays with he particle (and doesn't jump around as the rope is extended/shortened).

Code:
for (int i = 0; i < actor.active.Length; i++)
       {
           if (actor.active[i]) //if the particle is on the rope
           {
               Vector3 tempPos = actor.GetParticlePosition(i);
               if(i >= 0 && i < particleSystems.Count && particleSystems[i] != null) //if the reference is not null or out of bounds
                   particleSystems[i].transform.position = tempPos;
               else if ((i >= 0 && i < particleSystems.Count)) //if not out of bounds
               {
                   if(particleSystems[i] == null)
                   {
                       print("ReAdding");
                       GameObject particleSystem = Instantiate(WaterParticlePrefab, waterParticlesRoot);
                       particleSystem.transform.position = tempPos;
                       particleSystems[i] = particleSystem;
                   }
               }
               else if (!(i >= 0 && i < particleSystems.Count)) //if the index is out of bounds
               {
                   print("Adding new");
                   GameObject particleSystem = Instantiate(WaterParticlePrefab, waterParticlesRoot);
                   particleSystem.transform.position = tempPos;
                   particleSystems.Add(particleSystem);
               }        
           }
           else //if the particle is NOT on the rope (in the pool)
           {
               if(i >= 0 && i < particleSystems.Count && particleSystems[i] != null) //if the reference is not null or out of bounds
                   Destroy(particleSystems[i].gameObject);
           }
       }
Reply


Messages In This Thread
Multiple Rope Cursors on single rope - by TheMunk - 30-10-2019, 04:32 PM
RE: Multiple Rope Cursors on single rope - by TheMunk - 04-11-2019, 11:02 AM