Spline to UV map... is this even possible?
-
Hey guys!
I didn't mean to put "is this even possible?" as some kind of cheap way to get your attention, I promise. I mean it when I say that I don't know if this is possible.
I've been scouring the forum for the past 1-2 days trying to figure out how I could get this done, and while I did get bits of insight about how GetWeights() does indeed return barycentric coordinates for a point on the surface of a polygon, I've had a really hard time wrapping my head around the idea of programmatically drawing a (or many) spline that is resting at the surface of any geometry onto the (assumed) proper UV map of said geometry.
For example, in the image below, I quickly Photoshopped the "Flower Spline" onto the UV map of the Sphere to demonstrate what I'd like to achieve.
I'm not sure if I can explain this better, so hopefully the text above explains what I want to achieve clearly, but if not, I'm happy to expand on it.
Any insight or guidance would be massively appreciated!
Thank you very much in advance. I don't take your assistance for granted.
-
Hi, first of all there is no built-in way to achieve what you are looking, with that's said what you should do, is for each sampling point of your spline, you need to find the nearest polygon then you on this polygon, there is two ways for that:
- Shooting ray from the sampled spline position to the center of the object and hope that it will hit a polygon. This can be done with the GeRayCollider class. Since you are using a projection deformer you can use the same vector as ray direction.
- Build an accelerated structure to spatialize your search. In C++ we do have KD-Tree unfortunately this is not available in Python, so you will need to build your own.
Then once you have the hit position on the polygon, you need to compute the barycentric coordinate of this position according to the polygon and then compute it on the UV polygon. This is demonstrated in Convert Barycentric coords to UV coords? topic.
Cheers,
Maxime. -
Hey @m_adam,
I never thanked you for your very helpful and thorough reply, so allow me to do so now: thank you very much! Your reply ended up being extremely useful, as it guided me in implementing the KD-Tree within my Python script, as well as helping me convert the Barycentric coordinates to UV coordinates. So, for that, once again; thank you!
Now that this is implemented, I am faced with a challenge: it appears that the precision of the drawing of the Spline greatly depends on the subdivision/triangulation level of my geometry (for example, the Sphere in my parent message). In other words, if the geometry whose UV map I am drawing the shape of my Spline onto is very low-poly, the drawing of said Spline will be incredibly imprecise. It seems like the precision increases as I increase the amount of polygons on the geometry.
Just curiously, without necessarily pasting my code here, I was wondering if - at the top of your head - this behavior was to be expected? Does this mean that, with the KD-Tree and Barycentric conversion method, I would never be able to programmatically draw a perfectly round circle Spline on a Plane object that, despite having a perfect UV map, only has 2 polygons?
I can work around those constraints, but it'd be great to know if the current imprecision of my drawing approach isn't caused by something else.
Thanks!