Script Op: TM from one particle source to another
#1
Two similar events A and B.
One object "myPlane".
Events have a birth surface operator emitting on all particles on frame 0.
each particle in the flow should have a unique simulation index.
But for each particle in eventA there should be a particle in eventB with the same particle ID, no?

in eventB, i placed a script operator.  i want to loop through all particles of event A, get their position or TM and plug them in the corresponding particles of eventB where the particle ID is the same.
Something like this: (ignore the syntax)

---
get particles from eventA (list that returns indices of particles in eventA)

For i in 1 to eventParticles.count do the following
{
     sInx = GetSimIndex(i);
     eventA_TM = get TM of particle in eventA[i];
     setTM of sInx to eventA_TM
    
}

   
  Reply
#2
If you have exactly the same number of particles on each object, just offset your simIndex by the number of particles to get the other half of the particles. So something like this: (untested)

Code:
int numPlaneVertices = 25;
int sInx = tf.GetSimIndex(i)
int sInx2 = sInx + numPlaneVertices;
tf.SetTM(sInx2, tf.GetTM(sInx));
  Reply
#3
(05-17-2019, 10:23 PM)tyFlow Wrote: If you have exactly the same number of particles on each object, just offset your simIndex by the number of particles to get the other half of the particles. So something like this: (untested)

Code:
int numPlaneVertices = 25;
int sInx = tf.GetSimIndex(i)
int sInx2 = sInx + numPlaneVertices;
tf.SetTM(sInx2, tf.GetTM(sInx));

Thx Tyson, this works, but begs the question: How are the indices first assigned? based on the user dragging the first birth operator on stage?
Say i dragged a birth operator, and event is created "Event001", then i duplicate that. Indices of Event002 start after event001. If i delete Event001, are the indices offset back? kept the same? Is there like an event index?
If i had other events in my scene before doing that index offset you mentioned, how are you sure that the offset is equal to the event particle count only (that would only work if the event in question were created last). I hope this isn't too confusing
Thx
  Reply
#4
Indices are created with a few rules in place:

1) they are assigned in order of birth

2) they do not necessarily correspond to birth ID (they may be pushed to random places in the overall particle system where deleted particles are found)

3) they remain the same for any given particle until the particle is deleted

Further explanations of those rules:

If event001 spawns 3 particles and event002 spawns 3 particles, the sim indices will look like this:

Code:
0 //event001, particle 1, ID 0
1 //event001, particle 2, ID 1
2 //event001, particle 3, ID 2
3 //event002, particle 1, ID 3
4 //event002, particle 2, ID 4
5 //event002, particle 3, ID 5

If you then delete event001, the indices will look like this:

Code:
0 //event002, particle 1, ID 0
1 //event002, particle 2, ID 1
2 //event002, particle 3, ID 2

If you create a new event and rename it event001, the indices will look like this (birth operators are processed in order of event creation, not based on event name!):

Code:
0 //event002, particle 1, ID 0
1 //event002, particle 2, ID 1
2 //event002, particle 3, ID 2
3 //event001, particle 1, ID 3
4 //event001, particle 2, ID 4
5 //event001, particle 3, ID 5

If you then take that previous setup (where event001 was created/renamed after event002 was created) add an operator to event002 that deletes its second particle, the indices will look like this:

Code:
0 //event001, particle 1, ID 0
1 //event002, particle 1, ID 3
2 //event001, particle 3, ID 2
3 //event002, particle 2, ID 4
4 //event002, particle 3, ID 5

So my previous post represents the simplest case, where you don't delete any particles and the particles are birthed in order. More complex cases may require you to track particles by their ID instead of their sim index in order to match them up. A particle's ID never changes and is never assigned to more than 1 particle in the flow....whereas a sim index can be assigned to more than 1 particle, if the original particle is deleted and thus a new particle takes it (note: neither sim index or ID will ever be assigned to more than 1 living particle at the same time).
  Reply


Forum Jump: