Refine a polyline with 3 points

   1572   7   0
User Avatar
Member
74 posts
Joined: Jan. 2015
Offline
I want to add a point to a line at a location closest to a point A (just outside the line). If the line has only 2 points (start,end), I can use the "xyzdist" expression to find the uv on the line closest to point A, and use Refine SOP to add a point. It works. But if the line has 3 points (start, end, and a point somewhere in the middle), the uv reported by "xyzdist" and passed on to Refine looks wrong, it's not where it used to be. I suspect it's an issue with parametric uv's with more than 2 points on a line. I tried to re-order the 3 points on the 3-point line, but it doesn't make any difference. I can use the Convert-Line SOP to fix this, i.e. convert the 3-point line to 2 separate lines: the "xyzdist" expression works again. Can this be done without the Convert-Line SOP?
Edited by element33 - Nov. 23, 2022 00:17:29

Attachments:
primpt.png (19.2 KB)

User Avatar
Member
4516 posts
Joined: Feb. 2012
Offline
Hi,

What you can do is to create a normalized float attribute before changing topology, and then find the closest point on the line using your point, and create this point in VEX.

Then comparing the value of the above float attribute of the old points and the new one, insert the new point into the array of old points using the primpoints function.

After this, delete the current primitive and recreate it using the new point list.

If you want to interpolate point, vertex, primitive attributes for all types, and preserve point, vertex, edge and primitive groups, you have to do a lot more work of course.

I would recommend creating tracking attributes and using Attribute Interpolate SOP to do the heavy lifting. But each one have to be handled differently. Doing all of this in VEX would be a ton of code and unimaginably slow.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
679 posts
Joined: Feb. 2017
Offline
I made a poor man's version, using standard nodes only.


Cheers
CYTE
Edited by CYTE - Nov. 23, 2022 03:33:15

Attachments:
InsertPoint.hip (99.6 KB)

User Avatar
Member
74 posts
Joined: Jan. 2015
Offline
Thanks, it works and I'll use it. The ( resample/transfer attribs ) part seems unnecessarily complex for just inserting one point at a known location. Maybe one day I'll find a simpler way.
Edited by element33 - Nov. 23, 2022 08:12:13
User Avatar
Member
74 posts
Joined: Jan. 2015
Offline
I found a one-SOP method that keeps the attribs. On the 3 point line, it turns out the uv coord reported by "xyzdist" is for the nearest segment of the 3-point line (the shorter part of the 3-pt line in the pic above). Instead of Refine, I can use a PolySplit, with the split location defined as p(a)-(b): (r) where (a) and (b) are point numbers defining the shorter segment, and (r) is the uv reported by "xyzdist".
Edited by element33 - Nov. 23, 2022 08:55:11
User Avatar
Member
679 posts
Joined: Feb. 2017
Offline
Hey element33,

Cool, could you post your solution?

Cheers
CYTE
User Avatar
Member
74 posts
Joined: Jan. 2015
Offline
Screenshot OK? I load a bunch of dependencies by default, I'd have to clean up the hip. It's just one "xyzdist" expression. My case is 2D (no "Z"). Also, I already know the IDs of the closest points on the line. To generalize, you'd need to ID them first.
Edited by element33 - Nov. 23, 2022 12:13:15

Attachments:
polysplit3.png (138.3 KB)

User Avatar
Member
134 posts
Joined: Dec. 2006
Offline
something like this? I just used a ray and a polysplit.

Attachments:
insert point.gif (766.7 KB)
insert point.hiplc (119.6 KB)

  • Quick Links