In Maya how to create a bunch of points on surface with pure python(like houdini's scatterAlign)?

Basically I want to create an equivelant of houdini’s ‘scatterAlign’ node in maya. Here are my plan in steps:

1. create points on surface;
2. get relevent information like normal vector, world position, UV coordinates…etc, and put it all in a numpy array to manage data;
3. copy to points;

I now stuck at step 1, what are the methods to create points on surface, I don’t want to use UV, meaning scatter points in uv space, and see which one is inside the surface uvshell, and then use uv coordinate to get world position. Reason why is then I’ll have to deal with how to determine if point is inside uvshell, and need to process every base mesh to cover as much uv space as possible, not very automated for my project.
What are the remaining methods to create points on surface, uniformly?

Do you need to do it in “pure python”? That sounds like a perfect job for the Bifrost Graph or even MASH. If you’re not familiar with either of those two Maya componenets I’d check them out first. There are a ton of Youtube videos on how to scatter points using both those things.

If you really don’t want to/cant use those, the most straight forward way is probably to use particles. set your surface as a particle emittor, emit 20,000 particles and then you have 20,000 positions and direction vectors (use particle velocity) to use as surface points.

Another possible way is to use the Maya retopologize, and use the vertices from the re-topo’d mesh as your scattered points.

Sometimes, the vertices that makes aren’t EXACTLY on your original surface, so you could add a shrinkwrap deformer to the re-topo’d mesh, and snap the verts to the original surface

1 Like

Hi Tyler, yeah that’s my current solution, thankfully retopo can be done in code for batch processing.

This question is just out of curious, just don’t know how software “touch” shape, after searching around and mostly chatGPT, seems like maya achieve “snap on surface” simply running closestPointOnSurface really fast under the hood?

Base on that then maybe I can create a bunch of direction vector in the mesh’s center and use raycasting to find all the point’s on surface, but still has a lot of problem, like how to deal with concave and convex shape, how to relax points for evenly distribution…

just want to know. Like are there a different “coordinate system” a shape has? that allows me to not using uv to find any points on surface, I vaguely remember a quad on a shape has it’s own coordinate system, it’s not call uv, but I can’t remember and don’t know what keyword to search

I’m going of topic, shrinkwrap it back, that’s a good tip, thanks~

Finding the closest point on a surface is usually done in 2 steps. First, you take all the faces and you divide them into a big nested hierarchy (If you want to learn more, here’s some google terms: octree, kd-tree, Bounding Volume Hierarchy). Second, you use that hierarchy to quickly find the closest point. Luckily, you can reuse that hierarchy.

If you just use a closestPointOnSurface node, you could reuse that hierarchy, but each closest point calculation would have to go through the whole process of maya updating a scene.
If you use a shrink wrap, it can loop over all the points VERY quickly because there’s no scene recalculation overhead. So you should DEFINITELY use a shrink wrap over any other way.

Also, look at the shrink wrap deformer options. There are a bunch of different ways to snap your vertices to another mesh, including different kinds of raycasts.

And the coordinate system you’re probably looking for is “barycentric”, but that’s for triangles, not quads. Full disclosure: there are some kinds of coordinates for quads, but they’ll lead you down a very thorny path of mathematics for not much gain over barycentric coords.

1 Like

Yeah, tried shrinkWrap the retopo mesh back to original high res this morning, get it done perfectly, for tree truck and roots.

I’ve been slowly digesting this book for “fundamental on computer graphic” since last time we talked, just looking at the content page,
https://www.pbr-book.org/4ed/contents
do you think this one is a good fit? or do you have other resource than can be recommanded?

1 Like

I’ve heard most (I think?) of those terms, but I basically only know/use about 20% of what that book is talking about. There’s a lot about rendering and light transport, which isn’t my forte, but maybe it’ll be yours.
It seems like an overview of a lot of topics, which is a good thing. Even if it doesn’t go really deep into anything, or you don’t remember it all word-for-word, It’s a GREAT thing just knowing what’s out there so you can say “Hey! I remember something that should work for this, let me go look it up”.

1 Like

Bifrost is great in fact I love it, but in my case, I need to to create a bunch of nonlinear deformer for each object(in my case stylized “leaves” and “bushes”), both bifrost and MASH doesn’t allow that, so I need to scatter points and get all the information I need.

Since retopo and wrap it back works for getting the points position and number, I now struggle with getting the rotation right, I can have the leaf pointing to the point’s normal direction, but the leaf’s front side/Z-Axis always point to the world Z-Axis.

How do I get the Z-Axis? And is vertice tangent is the suppose X-Axis?

The only information you get from the surface point itself is a single normal, so the tangent and bi-normals have to be calculated from some other information, which is usually UVs afaik. If your retopo mesh has “inherited” the transferred uvs from the original mesh you can probably just use those directly, but if not you may have to cast onto the underlying mesh to read the original uvs.
Here’s the info on how Maya calculates that data, maybe this will help: