Looping particle positions
#11
(05-17-2019, 10:37 PM)tyFlow Wrote: For a deforming mesh you need to be able to construct a TM that can be created at any frame, which will correspond to the same location on the mesh. Obviously the object's TM won't work, but luckily such a TM is easy to construct.

You need 4 vectors to create such a TM: Forward, right, up and translation. The process for creating these is as follows:

First, at frame 0, find the closest point on the mesh and get the face index as well as the barycentric coordinates. From the face, get vertex1, 2 and 3 which create the face.

For the forward vector, use (vertex1 - vertex2) and normalize it.
For the right vector, use the cross product of (vertex1 - vertex2) and (vertex3 - vertex2) and normalize it.
For the up vector, use the cross product of forward and right.
Finally, orthogonalize the TM by resetting the right vector as the cross of up and forward.

For the translation, multiply the barycentric coordinates by the vertex1, 2 and 3 coordinates (v1 * b.x + v2 * b.y + v3 * b.z).

Use all 4 vectors to construct your TM (Matrix3 tm = new Matrix3(forward, right, up, translation); )

Then, store the barycentric coordinates and face index in custom data channels for later access.

Later, at any given frame, reconstruct the TM using the face index (to get v1, v2, v3) and barycentric coordinates. Use the method previous explained in this thread to also get the localTM you'll be storing and loading from using this new deformation-compatible TM.

I see. The way i was going about deforming meshes was to try and create a duplicate birth event that stays stuck on the deforming mesh using Object Bind, storing the TM of the particles, then Getting the TMs back by using the index offset you mentioned in another thread.
In your approach, correct me if i'm wrong, but you're basically  doing the following in the step iteration:

For each particle in the event:
Get particle SimIndex
if event age =0 then find the faceID of the closest Face to the particle and store it in a CustomFloat (using simIndex)?

Then when you wanna retrieve the position, in another script Op you would do something like:

For each particle in the event:

get simindex
Get customFloat (simindex)
Get v1, v2, v3
calculate the 3 vectors
Construct the newTM, barycentric coordinate etc..

SetTM(simIndex, newTM)


something like that maybe?

---

Scripting in c# is a really different beast.
  Reply


Messages In This Thread
Looping particle positions - by moonjam - 04-24-2019, 11:31 AM
RE: Looping particle positions - by alexgiel - 04-24-2019, 01:07 PM
RE: Looping particle positions - by moonjam - 04-24-2019, 03:05 PM
RE: Looping particle positions - by tyFlow - 04-25-2019, 05:38 AM
RE: Looping particle positions - by insertmesh - 05-15-2019, 10:43 AM
RE: Looping particle positions - by chromodome - 05-16-2019, 12:37 PM
RE: Looping particle positions - by insertmesh - 05-16-2019, 03:20 PM
RE: Looping particle positions - by chromodome - 05-17-2019, 03:53 PM
RE: Looping particle positions - by insertmesh - 05-17-2019, 08:37 PM
RE: Looping particle positions - by tyFlow - 05-17-2019, 10:37 PM
RE: Looping particle positions - by chromodome - 05-18-2019, 12:16 AM
RE: Looping particle positions - by tyFlow - 05-18-2019, 02:52 AM
RE: Looping particle positions - by tyFlow - 05-20-2019, 04:17 AM
RE: Looping particle positions - by insertmesh - 05-20-2019, 08:21 AM
RE: Looping particle positions - by Pflow - 01-28-2020, 11:17 PM

Forum Jump: