Aligning texture coordinates based on longest edge length



Hi everyone,

I was trying to find a way to apply and orient 3D procedural textures for many (wooden) objects in a single mesh easily, but UV maps are 2D, and the other options seemed difficult or impossible, so I made a geometry nodes group for the task. It looks at each mesh island and finds its longest edge, finds that edge’s direction, and aligns a coordinate’s z axis to that direction. The result is used in a shader. It works pretty well.

On the shading side of things, a vector attribute named ‘atc position’ is used instead of the usual texture coordinates. Two other attributes are available as well: atc direction, and atc index, to allow for various effects. I used the former in the rendered image to translate each texture randomly per mesh island.

Because of how it works, if a texture isn’t oriented correctly a single vertex can be extruded in the desired direction.

It has a couple shortcomings… the coordinates will be rotated around the z axis whichever way. Also, the center-finding technique I used averages the position of all points in an island, instead of finding the actual center. (I’m still researching the solution.)

Lastly, the geometry nodes modifier can be applied and the meshes deformed, and the texture coordinates will hold fast. Useful for bending wooden objects.

P.S. If there’s an easier method to do this I’m all ears :smiley:

12 Likes

Wow, I feel this is important for procedural wood texture.
But I’m unfamiliar to geometry node.

1 Like

Hi Cheng,

Here’s an example .blend file. Maybe you’ll find it useful:

GN-AlignTexCoordsByLength.blend (1.1 MB)

4 Likes