Jump to content

How does priminteriorweights work


AntoineSfx

Recommended Posts

input 0 is a poly

input 1 is a point (preferably inside the poly but it should work  if it's outside, even though it's not really an interesting case)

I have a ray SOP in input 2 that computes the hitprimUV and hitprim, the coordinates of the point inside the poly from input0

I'm successfully reconstructing the  projected point  in the variable sampled with this wrangle:

 

vector2 v= point(2,"hitprimuv",0);

vector sampled;
int res  = prim_attribute(0, sampled, "P", 0, v);  // result written in sampled, it's passed by reference

int smp = addpoint(0,sampled);
setpointgroup(0,"sampled",smp,1,"set");

int x;
int verts[];
float weights[];

int pi = priminteriorweights(0,0,v,  verts, weights);

i[]@verts = verts;
f[]@w     = weights;

 

 

This KINDA works: for a triangle and a square, I'm able to reconstruct the projected point with those 2 detail wrangles in succession:

#dw1

 

int verts[] = prim(0,"verts",0);
float w[] = prim(0,"w",0);
foreach(int idx; verts) {
setpointattrib(0,"w",idx,w[idx],"add");
}

#dw2

vector I  = set(0,0,0);
foreach(int idx; expandpointgroup(0,"")) {
vector v = point(0,"P",idx);
float  w = point(0,"w",idx);
I += w*v;
}

int np  = addpoint(0,I);
setpointgroup(0,"interior",np,1,"set");

 

which is the weighted sum of points with their barycentric coordinates

It is actually always equal to 1, which is good;

But, starting from 5 points and more, the verts array starts receiving more elements than the number of points, and the two reconstructed points no longer match.

 

 

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...