Points arranged in grid stick to UV on geo

   5491   8   1
User Avatar
Member
30 posts
Joined: March 2006
Offline
Hi Guys, some help here..

- basically I like the scatter SOP, in texture space, but I want to arrange the points in a grid.(not the copy sop on a grid)

Imagine I import a model with uv's. Then I want to generate points arranged in a grid so for 10x10 points point 1 would be at uv 0,0 and point 2 would be at uv 0,0.1 etc..

Hope this makes sense. I'd like to go into VOPs or vex, but I'm brand new to this area so I'm kinda not sure how to connect the dots.

Anything that could point me in the right direction is greatly appreciated

Cheers!

Pingo
User Avatar
Member
30 posts
Joined: March 2006
Offline
Coming from XSI and Cinema, I just thought Oh I can just use a deform by surface (UV) on a grid and get rid of the poly's.. But it seems after reading several posts there isn't a proper deform by surface node in houdini that can do this? Interesting…
User Avatar
Member
1743 posts
Joined: March 2012
Offline
The Short Answer:
If you don't have any areas of the model with the same uv's, (i.e. there's no overlap in uv space), you can use the Attribute Transfer by UV node, (though it may have a bug that I've just discovered).

The Long Answer:
On the model, copy uv to P, (if you have vertex uv's, it's a bit less nice; you have to first use Vertex Split to split points based on uv and turn on the option to promote it to a point attribute). Then, use a Ray SOP set to Minimum Distance mode with the grid of points in the first input and the model in the second input. Be sure to turn on the hitprim and hitprimuv attribute output on the Ray SOP. These indicate where on which primitives the points should stick. Then, use Attribute Interpolate with hitprim and hitprimuv and the original (or Vertex Split) model in the second input to find the corresponding correct positions for the points.

If you have animated geometry that's just deforming, you can even just use rest geometry for everything except the second input of the Attribute Interpolate, where you'd use the deforming geometry, and just have the Attribute Interpolate (and possibly the Vertex Split) cook on every frame, avoiding the cost of the Ray SOP. That's also currently not being done by the Attribute Transfer by UV node, since it'd need a 3rd input to differentiate between rest geometry and deforming geometry.

If you have overlap in uv space, it's more complicated. There's an op-hidden node that's been half-finished since 14.0 to try to do it, but it's finnicky.
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
User Avatar
Member
30 posts
Joined: March 2006
Offline
That's super, I'll have a go at it, thanks!
User Avatar
Member
1743 posts
Joined: May 2006
Offline
Here's one way. Long winded explanation follows, sorry…

The idea is to hijack off the back of the ‘attribute interpolate’ sop. It's name doesn't give many clues to its purpose, but one of its key uses is to lock scattered points to deforming geometry. Usually if you scatter on a moving surface, the scatter will change each frame. Instead you can use a timeshift to freeze the geo, scatter, connect the scatter to the first input of an attribute interpolate sop, deforming geo to the second, and the points will stick.

You have to remember to enable ‘sourceprim’ and ‘sourceprimuv’ on the scatter sop. Like those names imply, each point will store the id of the closest prim, and the uv. The attrib interpolate uses this to find the matching position on the deforming geo.

So, to your challenge. What I did was take some geo with uvs, and in a wrangle just go “@P = @uv;”. In other words, I unwrapped the uvs, but in 3d space. This means the geo goes to a flat square on the XY plane, between (0,0) and (1,1).

I create another grid of points between (0,0) and (1,1). This will become the grid mapped onto the geo.

In a wrangle I use the xyzdist() function so each point finds its closest prim, and the uv position within that prim. I store these with the same names attrib interpolate expects, ie, @sourceprim and @sourceprimuv.

Now that we have everything we need, we can take the original geo, deform it, feed it to the 2nd input of an attrib interpolate, the grid of points to the first input, and we're all done!

Attachments:
layout_points_in_uv_space.hipnc (216.3 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
1743 posts
Joined: May 2006
Offline
Heh, I took too long tidying up my example, but yes, what ndickson said.

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
30 posts
Joined: March 2006
Offline
AAh Matt, @P = @uv; I mean.. how simple. BTW Absolutely love your blog and have been trying to do this by merging some of your examples.

Ndickson I'm having some trouble getting your solutions to work. Any chance of a file with the Attribute Transfer by UV node?

Cheers both for taking the time.
User Avatar
Member
1743 posts
Joined: May 2006
Offline
Heh, glad you like it.

Btw, you wouldn't be the same Pingo I met for 30 seconds about 10 years ago now, when I visited Copenhagen and you shared studio space with Peter Hartwig? I can't imagine there's many Pingo's around, unless it's a crazy common Danish name and I'm being horribly racist…

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
30 posts
Joined: March 2006
Offline
mestela
Heh, glad you like it.

Btw, you wouldn't be the same Pingo I met for 30 seconds about 10 years ago now, when I visited Copenhagen and you shared studio space with Peter Hartwig? I can't imagine there's many Pingo's around, unless it's a crazy common Danish name and I'm being horribly racist…


That'd be me!
  • Quick Links