Python states and StrokeState anchor new curves on existing

   616   1   1
User Avatar
Member
3 posts
Joined: 5月 2016
Offline
Hello
I want to build an hda that uses the stroke node.
Strokes would be drawn in screen space. When a new stroke is about to be made the hda will be able to intersect with a previous curve and set the projection center to that point.

I copied that snippet that work with the class State(object) I believe.
geometry = self.node.geometry(0)

        origin, direction = ui_event.ray()
        
        position = hou.Vector3()
        normal = hou.Vector3()
        uvw = hou.Vector3()
        
        intersected = geometry.intersect(origin,direction,position,normal,uvw)
        self.node.parmTuple(f"stroke_projcenter").set(position)

It is able to get the pos in space for the intersect.
Unfortunately that put in class(StrokeState) doesn't do anything.

Is there a way to achieve that for strokestate on prestroke for example ?

Thank you so much in advance.
User Avatar
Member
3 posts
Joined: 5月 2016
Offline
Well so there's a ugly answer to that question but i'm sure there's a better way.

Make a feedback loop to the draw curve itself (in a one iteration loop) and move the curves on the plane they originated from :

 // Find the prim the current point belongs to, then store the point ID
// of the first point in that prim
int point_prim = pointprims(0, @ptnum)[0];
int first_point_id = primpoints(0, point_prim)[0];
// Use projection attributes stored on the stroke primitive
// to move points
vector p0_orig = point(0, "stroke_orig", first_point_id);
vector p0_proj = point(0, "P", first_point_id);
float dist_to_p0 = length(p0_orig - p0_proj);
v@P = v@stroke_orig + ( normalize(v@stroke_dir) * dist_to_p0 ); 

Attachments:
draw3d.PNG (27.4 KB)

  • Quick Links