Jump to content

Copy multiple objects to multiple point in loop


cgartashish

Recommended Posts

Hi,

I have attached a scene file for reference, in the scene, I have fractured a box and used a for each loop to adjust its pivot points and position and again I have used a grid and scattered point to copy it. I have used for each loop to and a copy to points node.

My problem is that, all of my fractured geometry gets copied to each point, while I know copy stamp method but is there any other way that I can use to copy each fractured piece coming out of a loop randomly over the scattered points via a copy to points node.

Please let me know, I have attached a file below.

* Also can you please let me know how to add strings in attribute vop node, suppose I want to create a string called "piece" inside the vop node and add the id or any random number to it and combine both the values as strings and also export it as a string attribute.

 

Thanks

copyToPoints.hipnc

Link to comment
Share on other sites

use random to delete rbd pieces by id of the input point and frame like this:

int id = point(1,"id",0);
int idp = int(rint(fit01(rand(id+@Frame),0,numRBDpieces)));
if(@ptnum!=idp)
	removepoint(0,@ptnum);

 

Link to comment
Share on other sites

30 minutes ago, tamagochy said:

use random to delete rbd pieces by id of the input point and frame like this:


int id = point(1,"id",0);
int idp = int(rint(fit01(rand(id+@Frame),0,numRBDpieces)));
if(@ptnum!=idp)
	removepoint(0,@ptnum);

 

Thanks for your help, can you please elaborate. Its not working for me and it would really help me out. Pleaseee

Link to comment
Share on other sites

Hey there !
copyToPoints_1.hipnc

Here's what I did.
Your pieces were already packed, which is needed for my setup.
In the for each loop where you copy the pieces to the points, I added a wrangle that gathers the iteration value of the loop. Based on that, I generated a random number going from 0 to the max number of points (rand(iteration)*pointCount), which gave me the piece that will be copied onto the point of the current loop iteration. I then created a group containing only that piece (yesh I know I could have used an attribute instead, but the group is simpler to understand) and deleted what's not in that group.

Hope that's useful !
Have a great day :)

Link to comment
Share on other sites

On 5/12/2019 at 9:16 PM, Alain2131 said:

Hey there !
copyToPoints_1.hipnc

Here's what I did.
Your pieces were already packed, which is needed for my setup.
In the for each loop where you copy the pieces to the points, I added a wrangle that gathers the iteration value of the loop. Based on that, I generated a random number going from 0 to the max number of points (rand(iteration)*pointCount), which gave me the piece that will be copied onto the point of the current loop iteration. I then created a group containing only that piece (yesh I know I could have used an attribute instead, but the group is simpler to understand) and deleted what's not in that group.

Hope that's useful !
Have a great day :)

Hi,

Thanks a ton for your help. It works but I am sorry to bother you again, can you please explain me this, "int ptCount = npoints(0);", I mean what does actually npoints(0) brings in? I am also curious about the second method where you could have used the attributes instead of delete node. Please let me know if it is possible. Thanks again.

Link to comment
Share on other sites

On 5/12/2019 at 9:16 PM, Alain2131 said:

Hey there !
copyToPoints_1.hipnc

Here's what I did.
Your pieces were already packed, which is needed for my setup.
In the for each loop where you copy the pieces to the points, I added a wrangle that gathers the iteration value of the loop. Based on that, I generated a random number going from 0 to the max number of points (rand(iteration)*pointCount), which gave me the piece that will be copied onto the point of the current loop iteration. I then created a group containing only that piece (yesh I know I could have used an attribute instead, but the group is simpler to understand) and deleted what's not in that group.

Hope that's useful !
Have a great day :)

Hi, I have gone through the help and have sorted out some confusions but I am still stuck here. 

setdetailattrib(0, "toKeep", toKeep);
setpointgroup(0, "toKeep", toKeep, 1);

I know what the above functions does, but I cannot understand how these functions are working for the current scene. Please can you explain what these functions are actually doing in this scene. I am really sorry to bother you again and again.

Link to comment
Share on other sites

No worries :)

The two functions do something similar
setdetailattrib -> There are points, vertex, primitive and detail attribute on any piece of geo. Detail is an convenient way to set something that is "global" to the piece of geo you currently have, as it is only there once in memory (instead of on all the points/verts/prims). So go in the details tab of the geometry spreadsheet, and you'll see a "toKeep" attribute. For its use, see below..
setpointgroup -> It does what it says - it sets a point group, much like the group node does. See in the points tab of the geometry spreadsheet, when seleting the wrangle you'll have a new group, named "toKeep". For its use, again, see below..

Oh well, I've just seen that you said that you know what the functions does. Eh ¯\_(ツ)_/¯

Why I said that using groups is easier is for what's below the wrangle. There are two blast node. Why two ? One to showcase the attribute workflow (setdetailattribute), and the other to showcase the group workflow (setpointgroup).
If you see the blast nodes underneath the wrangle, one is for the group workflow, and one is for the attribute workflow.
The only difference is what's in the "Group" parameter.
Using the group workflow, you simply put "toKeep". That's it, easy enough.
Using the attribute workflow, the syntax is weirder.
`detail(0, "toKeep", 0)`
This means "go and get me a detail attribute of the input 0 (the only one in this case) with the name of 'toKeep'", and the last 0 I'm not sure.
And the `` are important. I think this is used to return a string, but don't quote me on that.

image.png.24f825ac8b26c0feaa2e3b32873fe3a2.png

Now, why I said that I could have used an attribute instead is that it is just a bit less expensive memory side, since it's just one attribute instead of one on all the points.
But the gain is sooooooooo small that eh, whatever (unless you have millions of pieces, in that case maybe consider it).
It all boils down to your personal preference

Hope that clears it up a bit !

Edited by Alain2131
Link to comment
Share on other sites

20 hours ago, Alain2131 said:

No worries :)

The two functions do something similar
setdetailattrib -> There are points, vertex, primitive and detail attribute on any piece of geo. Detail is an convenient way to set something that is "global" to the piece of geo you currently have, as it is only there once in memory (instead of on all the points/verts/prims). So go in the details tab of the geometry spreadsheet, and you'll see a "toKeep" attribute. For its use, see below..
setpointgroup -> It does what it says - it sets a point group, much like the group node does. See in the points tab of the geometry spreadsheet, when seleting the wrangle you'll have a new group, named "toKeep". For its use, again, see below..

Oh well, I've just seen that you said that you know what the functions does. Eh ¯\_(ツ)_/¯

Why I said that using groups is easier is for what's below the wrangle. There are two blast node. Why two ? One to showcase the attribute workflow (setdetailattribute), and the other to showcase the group workflow (setpointgroup).
If you see the blast nodes underneath the wrangle, one is for the group workflow, and one is for the attribute workflow.
The only difference is what's in the "Group" parameter.
Using the group workflow, you simply put "toKeep". That's it, easy enough.
Using the attribute workflow, the syntax is weirder.
`detail(0, "toKeep", 0)`
This means "go and get me a detail attribute of the input 0 (the only one in this case) with the name of 'toKeep'", and the last 0 I'm not sure.
And the `` are important. I think this is used to return a string, but don't quote me on that.

image.png.24f825ac8b26c0feaa2e3b32873fe3a2.png

Now, why I said that I could have used an attribute instead is that it is just a bit less expensive memory side, since it's just one attribute instead of one on all the points.
But the gain is sooooooooo small that eh, whatever (unless you have millions of pieces, in that case maybe consider it).
It all boils down to your personal preference

Hope that clears it up a bit !

Hi,

Thank you so much, your explanation solved a lot of problems for me, I just have one last question, hopefully. I am a bit confused about the "setpointgroup" expression. Is it not possible to create a group by group node here and why is it necessary to first write a detail attribute and then make a group out of it? Is it not possible to directly make a group. One more question, I am sorry to ask so many things, your explanations are good, why do we multiply "npoints"? Can you please explain on multiplying "npoints" what exactly happens? Can't we use the fit range node in attribute vop or fit01 expression in wrangle to fit the random incoming value and if I do so, what should be the source min/max and dest min/max? 

Thanks again, even if I dont get a reply for this one, you have helped me a lot. So, Thank You.

PS: I have attached a file, I followed your file and tried to make it with an attribute vop node, if you have some extra time, please see if it could have been better.

copyToPoints_1.hipnc

Link to comment
Share on other sites

Hey there,

So for the setpointgroup
You misunderstood the process a bit. It does not actually use the detail attribute - the detail attribute is simply set, and not used anymore in the wrangle.

int iteration = detail(1, "iteration"); // Gets the current iteration value of the loop, using the detail attribute of foreach_begin1_metadata2 (that is the input 1)
int ptCount = npoints(0); // This returns the number of points (in this case, how many chunks you have)

// The rand() function produces a random number between 0 and 1
// Using it with the iteration value makes it yield a different number for each scattered point
// Since the number is between 0 and 1, if I multiply it by the number of chunks (in this case 20), you'll have a number ranging from 0 to 20
// Doing fit01(rand(iteration + ch("seed")), 0, ptCount) would essentially give the same result. Make use of what you're most confortable with !
int toKeep = int(rand(iteration + ch("seed")) * ptCount);

// Maybe that using the same names for those next lines was a bit confusing
setdetailattrib(0, "toKeep", toKeep); // This places the variable toKeep in a detail attribute named toKeep. A simple copy/paste
setpointgroup(0, "toKeep", toKeep, 1); // This uses the variable toKeep (which has nothing to do with the detail attribute) to say "I want to set a group on the points, please use the geometry of the input 0, the group name is "toKeep" (if it doesn't exist, it creates it), put it on the point number toKeep (which contains a value ranging from 0 to 20), and tell that point to be in the group (the 1 takes care of that)". Because by default groups are initialised at 0, all the other points won't be in the group

Another way of doing it is this

int iteration = detail(1, "iteration");
int ptCount = npoints(0);

int toKeep = fit01(rand(iteration + ch("seed")), 0, ptCount);

setpointgroup(0, "currentChunk", toKeep, 1);

Hopefully this isn't more confusing :)

To understand the nmin/nmax values in the fit01, you need to understand the principle behind the whole wrangle.
Just to mention, those stands for OMin (Original Min), OMax (Original Max), NMin (New Min), NMax (New Max)
The idea is to give a different number for each scattered point that represents one of the chunk you have.
So if the number is 13, well, simply keep the chunk #13, remove everything else, and copy that chunk on the current scattered point of the loop.
So for the nmin, we want the lowest chunk number, which is 0. You can see that in the geometry spreadsheet.
As for the nmax, in this case this is the number of chunks that you have, since this is the whole idea of that setup. So, it is ptCount.
There is no omin/omax, this is only for the fit() function. The fit01() assumes omin=0 and omax=1.

As for the Attribute VOP method, I can't currently produce a scene file since I'm at work. But here's a picture of a few corrections

image.thumb.png.e6708c43b8d3b8850e090f33a60a340a.png

You were using the ptnum output, which is the current number of the point. Just use the numpt, this is the point count (hovering your mouse over it tells you what it is)
Using the fit does the exact same result as the multiply. Use what you want !
As for creating a group from the detail attribute, I now understand what you mean. It's because of the VOP method that doesn't have an easy way of doing groups. As far as I know.
I've never created groups with it (although is it definitely possible), so I don't know how to set a group the way we need in VOP. Sorry 'bout that.

 

EDIT :
I don't know if that makes it simpler, but this may make the connection a bit better between VEX and VOP

int iteration = detail(1, "iteration");

int toKeep = int(rand(iteration + ch("seed")) * @numpt); // Using the @numpt, which is the same name as in VOP
// That way we get rid of the whole ptCount line

setpointgroup(0, "toKeep", toKeep, 1);

 

Edited by Alain2131
Link to comment
Share on other sites

On 5/15/2019 at 2:14 AM, Alain2131 said:

Hey there,

So for the setpointgroup
You misunderstood the process a bit. It does not actually use the detail attribute - the detail attribute is simply set, and not used anymore in the wrangle.


int iteration = detail(1, "iteration"); // Gets the current iteration value of the loop, using the detail attribute of foreach_begin1_metadata2 (that is the input 1)
int ptCount = npoints(0); // This returns the number of points (in this case, how many chunks you have)

// The rand() function produces a random number between 0 and 1
// Using it with the iteration value makes it yield a different number for each scattered point
// Since the number is between 0 and 1, if I multiply it by the number of chunks (in this case 20), you'll have a number ranging from 0 to 20
// Doing fit01(rand(iteration + ch("seed")), 0, ptCount) would essentially give the same result. Make use of what you're most confortable with !
int toKeep = int(rand(iteration + ch("seed")) * ptCount);

// Maybe that using the same names for those next lines was a bit confusing
setdetailattrib(0, "toKeep", toKeep); // This places the variable toKeep in a detail attribute named toKeep. A simple copy/paste
setpointgroup(0, "toKeep", toKeep, 1); // This uses the variable toKeep (which has nothing to do with the detail attribute) to say "I want to set a group on the points, please use the geometry of the input 0, the group name is "toKeep" (if it doesn't exist, it creates it), put it on the point number toKeep (which contains a value ranging from 0 to 20), and tell that point to be in the group (the 1 takes care of that)". Because by default groups are initialised at 0, all the other points won't be in the group

Another way of doing it is this


int iteration = detail(1, "iteration");
int ptCount = npoints(0);

int toKeep = fit01(rand(iteration + ch("seed")), 0, ptCount);

setpointgroup(0, "currentChunk", toKeep, 1);

Hopefully this isn't more confusing :)

To understand the nmin/nmax values in the fit01, you need to understand the principle behind the whole wrangle.
Just to mention, those stands for OMin (Original Min), OMax (Original Max), NMin (New Min), NMax (New Max)
The idea is to give a different number for each scattered point that represents one of the chunk you have.
So if the number is 13, well, simply keep the chunk #13, remove everything else, and copy that chunk on the current scattered point of the loop.
So for the nmin, we want the lowest chunk number, which is 0. You can see that in the geometry spreadsheet.
As for the nmax, in this case this is the number of chunks that you have, since this is the whole idea of that setup. So, it is ptCount.
There is no omin/omax, this is only for the fit() function. The fit01() assumes omin=0 and omax=1.

As for the Attribute VOP method, I can't currently produce a scene file since I'm at work. But here's a picture of a few corrections

image.thumb.png.e6708c43b8d3b8850e090f33a60a340a.png

You were using the ptnum output, which is the current number of the point. Just use the numpt, this is the point count (hovering your mouse over it tells you what it is)
Using the fit does the exact same result as the multiply. Use what you want !
As for creating a group from the detail attribute, I now understand what you mean. It's because of the VOP method that doesn't have an easy way of doing groups. As far as I know.
I've never created groups with it (although is it definitely possible), so I don't know how to set a group the way we need in VOP. Sorry 'bout that.

 

EDIT :
I don't know if that makes it simpler, but this may make the connection a bit better between VEX and VOP


int iteration = detail(1, "iteration");

int toKeep = int(rand(iteration + ch("seed")) * @numpt); // Using the @numpt, which is the same name as in VOP
// That way we get rid of the whole ptCount line

setpointgroup(0, "toKeep", toKeep, 1);

 

Hi,

Thank you so much for helping me out here, thank you for your efforts. :) 

Finally I have understood the concept and now I am able to execute it entirely in vop, many thanks.

And I have found out a way to create group inside vop network, I have attached a file here, in case you want to take a look.

Thanks again. :) 

copyTest.hip

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...