Jump to content

trying to understand primuv function


MadMax50

Recommended Posts

Hello,

I am trying to understand primuv a little better . All I would like to do is get my particles sticking to the surface of the character in dops.

I am writing this in a pop wrangle: 

vector primuv;
int prim;

v@sample=primuv(1, "P", prim, primuv);

v@P = v@sample;

 

For some reason, it's only returning the position of 1 point. Why isn't it returning the position of all the points ?

I will attach my file for anyone that wants to take a look

Thank you

 

primuv_understanding.hipnc

primuv.jpg

Link to comment
Share on other sites

Well, you're not really defining what "prim" and "primuv" are. You're initializing them as variables, but you have to actually set them to something to be useful.

Primuv() usually works alongside xyzdist()... xyzdist can fetch the "prim" and "primuv" values from the nearest point on the surface, and then you can pass those values along to primuv. It's a little confusing because xyzdist() has some quirks in its arguments. If you look at the docs for xyzdist(), there's a little "&" following the prim and primuv arguments. This means that even though xyzdist officially returns a float (the distance to the surface from your lookup position), it can also write to those & arguments.

So the full code would look something a little more like this:

int prim;
vector primuv;

float dist = xyzdist(1, @P, prim, primuv); // this actually WRITES to prim and primuv!
vector sample = primuv(1, "P", prim, primuv); // this is fetching P from the prim and primuv coords supplied
v@P = sample;

 

  • Like 1
Link to comment
Share on other sites

@toadstorm

Thanks for the reply toadstorm. That makes a lot more sense. 

I wanted to do some examples only using the primuv so that I have a solid understanding of this function before I use it in conjunction with xyzdist. 

That being said, can I throw another problem at you? I'm using the primuv function inside of a for loop and my goal is to set a point in the middle of each primitive of a grid. I have 20 points and im feeding it into a wrangle like this:

vector uv = set(0.5, 0.5, 0);

for(int i=0; i<20; i++){
    @P=primuv(1,"P", i ,uv);
}

However, the points only move towards 1 primitive. I thought that using the iteration number as the primnum would work but it seems like i'm missing something here

Thanks for the help

 

 

 

primuv_understanding2.hipnc

Link to comment
Share on other sites

This is because, I assume, you're doing this in a point wrangle. The problem is that point wrangles are inherently a for/each loop, looping over each point. This means that every one of your points is looping over all 20 primitives, then stopping on the 20th primitive, simultaneously.

Instead, assuming you have 20 points and 20 prims:

vector uv = set(0.5, 0.5, 0);
@P = primuv(1, "P", @elemnum, uv);

@elemnum, @ptnum, @primnum, etc. are automatic attributes inside the wrangle that tell you which point, prim, or whatever you're currently iterating on.

  • Like 1
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...