How to merge point caches together with unique IDs

   2016   3   0
User Avatar
Member
65 posts
Joined: Nov. 2013
Offline
I have to merge together multiple pop sim caches together. I didn't make them. They have IDs. However, the IDs overlap because they come from multiple wedge sims. How can I merge multiple point caches together and give them unique IDs?

Thanks.
User Avatar
Member
7801 posts
Joined: Sept. 2011
Offline
The easiest way is to add a big number to the id, offset by the wedge index.

@id = @id + 1000000 * i@wedge;

This example will work if the caches have less than a million points each, and if there are less than 1000 wedges, otherwise the numbers will become larger than int max.

Another, more sophisticated way is to use a hash function.

vector4 vhash = set( @id % 65536, @id / 65536 , i@wedge % 65536, @wedge / 65536 );
@id = random_fhash( vhash );

Keep in mind the hashes generated are very large numbers, that are non contiguous. They can be used for id matching, or for random number generation without any additional effort. But the numbers are generally too large to convert to float without precision loss. Too convert to a float, either use a random function/vop or use modulus first.
User Avatar
Member
65 posts
Joined: Nov. 2013
Offline
Awesome! Thanks for the help.
User Avatar
Member
8591 posts
Joined: July 2007
Online
the safe way is to ensure alternate ids

process each wedge with following code before merging:
i@id = i@id*numwedges + wedgenum;

where:
numwedges is total number of wedges(merge inputs) you are merging
wedgenum is current wedge(merge input) number (0 based)

that would work no matter how many particles is in each wedge (of course as long as the ids within each wedge are unique to begin with) until you reach int limit
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links