prims.eval functionality

Hi,

I’m trying to use the prims.eval python call to get the positions on specific primitives, but the values it gives back seem to be wrong.

I have a simple 4 point grid that I’m sampling. Size (1,1) Center (0.5, 0.5, 0)

In a script, I run the following:

geo = op('grid1') P = geo.prims[0].eval(0.5, 0.5) print(P)

This returns a value of (1.0, 1.0, 0), when I assume that should give me (0.5, 0.5, 0)

I’ve attached a sample scene. Does anyone have an idea of why it’s working like this?

Thanks
prim_eval.toe (3.83 KB)

Ok, slight addition to this question. Looking in the docs, I see that when you use the eval function on a polygon, it ignores the v component. And from what I can tell, when you pass the u component, it spits back out positions that are only on the edges of the polygon.

I’m looking for a way to get a random position within the polygon. My hacky solution is to look up 2 different random positions along the edges, and average them together. It’s not great, but it kinda works.

However, is there any python function that will give a random position within a polygon?

Let’s assume for simplicity that the polygon is flat and convex.

You might consider converting 4 point polygons into 2x2 grids.
3 point polygons, could be 2x2 grids with coincident points.
Not sure a fast way of doing this with native SOPs, but you could Script SOP it.

For higher vertex counts, you can use Divide SOP, with Convex option to get them down in count.

Hi Rob,

I’m not sure if I follow how turning the polygons into 2x2 grids would help with finding a random point on it’s surface. Are you still referring to using the prims.eval method in a Script SOP?

Yes, that’s right.
Once they are 2x2 grids, prim.eval( u, v) will land on its surface always.
Cheers,
Rob.

What kind of geo is the prims.evals function expecting? Because when I pass it a single 4 point polygon, I only get values returned on the edges, not within the area of the polygon.

Also, only the ‘u’ value seems to have any effect. Changing the ‘v’ doesn’t seem to do anything.

The example I attached in the first post should demonstrate that. Although it’s always possible that I missed something simple.

If the primitive is a face (polygon, Bezier curve, or NURBs curve) then only u is used, and it
travels along the edge, as you describe.

If the primitive is a mesh (Polygonal grid, Bezier surface, NURBs surface), then both u and v are used to cover the interior surface of the primitive.

That’s why I suggest converted 4-point polygons into 2x2 grids, to a better mapping of u,v.

Ok, great thanks. That makes sense