VEX code issue

   1583   5   1
User Avatar
Member
13 posts
Joined: Sept. 2017
Offline
Hello guys


I am still quite a beginner with VEX coding. I am currently working on a project, where emitted particles needs to be sort out to clusters based on the distance and then to be attracted together inside the clusters.

The code is written in SOP solver inside POPNET.

I was more or less able to sort out the particles into the clusters, but there is one strange thing about the result of the code. I have placed all particles of AGE less then 0,05s to a group. Then I have created ARRAYS based on the function NEARPOINTS. Every point in the array gets an attribute called ATTRACT_G and CNT. CNT attribute gets value equal to the length of the array and ATTRACT_G attribute gets value of the current frame.

If I understand well, the function FOREACH should go through every point in the array and assign the value of the current frame to the attribute ATTRACT_G. When I check the CNT attribute it shows fxp number of 5. It means there are 5 points in the array. Here I would expect to see 5 identical values of the attribute ATTRACT_G, but the number of the same values varies.

Any idea why the same value of the ATTRACT_G attribute are not shown the same times like the number of points in the array? Here is the code and many thanks for any advice.

if (@age<0.05){
setpointgroup(0, “attraction”, @ptnum, 1);
}

float searchrad = 0.3;

int nbrs;

if (inpointgroup(0, “attraction”, @ptnum) == 1){//setpointgroup(0, “vse_g”, @ptnum, 1);
//int vse_array = expandpointgroup(0, “vse_g”);

//foreach(int bod; vse_array){
nbrs = nearpoints(0, “attraction”, @P, searchrad, 6);
}

if((len(nbrs)>4) && (inpointgroup(0,“attraction”, @ptnum))==1){

foreach(int nbr; nbrs){
setpointgroup(0, sprintf(“pokus%d”, @ptnum), nbr, 1);

setpointgroup(0, “attraction”, nbr, 0);

s@groups = detailintrinsic(0, “pointgroups”);

string groups = detailintrinsic(0, “pointgroups”);

i@cnt = len(nbrs);
f@attract_g = @Frame;

}
}

Attachments:
ParticleGravitationalAttraction.hipnc (306.1 KB)

User Avatar
Member
2536 posts
Joined: June 2008
Offline
I think I would break it into two wrangles, one that creates the group attraction and one that process the attraction group.

Attachments:
ap_ParticleGravitationalAttraction.hipnc (328.4 KB)

Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
13 posts
Joined: Sept. 2017
Offline
Thank you for the quick answer and the advice. It is a good idea to give it a better and more logical order. But I am still having the same issue. If the array is made of fxp 6 points, I should have in the spreadsheet 6 same values for ATTRACT_G attribute, but it still varies - please check the pic.

The thing is, that I would like to use the same or similar vex code as it is written in the disabled wrangler nodes on the left side. I would like to be able to control better the amount of points in the arrays better. I need to make groups based on the value of the ATTRACT_G attribute. Points with the same value of the attribute will belong to one group and then every group should be treated separately - points belonging to GROUP_1 will be attracted to each other, point belonging to GROUP_2 will be attracted to each other and so on.

Any idea how to treat points separately for each group?

Attachments:
Spreadsheet_1a.jpg (410.9 KB)

User Avatar
Member
13 posts
Joined: Sept. 2017
Offline
I have found another curious result in the spreadsheet. One point belongs to two different groups. I think it shouldn't happen according to the VEX code. Another effect of the points belonging to two different groups are different ATTRACT_G values even though it should be the same or maybe two values when the points are in two groups at the same time. I must be missing something. After all day the VEX coding of this I think simple thing still surprise me.

I anybody could explain me why this is happening plus the previous issue I would be very grateful.

Attachments:
Spreadsheet_2a.jpg (199.2 KB)
Spreadsheet_3a.jpg (314.8 KB)

User Avatar
Member
13 posts
Joined: Sept. 2017
Offline
One more curious example of the VEX code results. I have used SOP partition to create groups based on the attribute value ATTRACT_G. For some reason the point 179 is placed to two different groups even though the attribute attract_g has one value 46.

Is there any logical explanation? Maybe it has something to do with some kind of internal rounding?

Attachments:
Spreadsheet_4a.jpg (191.6 KB)
Spreadsheet_5a.jpg (406.6 KB)

User Avatar
Member
13 posts
Joined: Sept. 2017
Offline
I forgot to share the file with SOP partition, so here it is.

Attachments:
ap_ParticleGravitationalAttraction_01.hipnc (308.9 KB)

  • Quick Links