Trying to deform any mesh into a sphere. How to translate the vertex position to lie on a sphere?

32 views
Skip to first unread message

Nagaraj Raparthi

unread,
Apr 22, 2019, 2:11:46 PM4/22/19
to Python Programming for Autodesk Maya

I am trying to write a deformer script for maya, using the maya API which deforms any mesh into a sphere by translating it's vertices.


What i already have is a deformer which translates every vertex of mesh in the direction of it's normal with the amount specified. This is done using the below equation.


point += normals[itGeo.index()] * bulgeAmount * w * env;


Where, point is the vertex on the mesh. normals[itGeo.index()] is a vector array which represents the normals of each vertex. w and env are to control the weights of the deformation and the envelope.


What this code basically does is, it translates the vertex in the direction of the normal with the amount specified. While this works for a sphere, because a sphere's vertex normals would point at the center. It would not work for other meshes as the normals would not point at the center of the mesh.



    float bulgeAmount = data.inputValue(aBulgeAmount).asFloat();
    float env = data.inputValue(envelope).asFloat();
    MPoint point;
    float w;
    for (; !itGeo.isDone(); itGeo.next())
    {
        w = weightValue(data, geomIndex, itGeo.index());

        point = itGeo.position();

        point += normals[itGeo.index()] * bulgeAmount * w * env;

        itGeo.setPosition(point);
    }


I initially thought changing the direction of translation would solve the problem. As in, if we can find the vector in the direction from the center of the mesh to each vertex and translate it along that direction for an amount specified would solve it. Like so :


point += (Center - point) * bulgeAmount * w * env;


Where, Center is the center of the mesh. But this does not give the desired result. I also would want the deformer to be setup in such a way that the user can input radius "r" value and can also change the amount attribute from 0 to 1 to deform the mesh from it's original state to a spherical one. So that he can choose a value in between if her desires and the mesh would be something between a sphere and it's original shape.


This is my very first post in this group. I apologize if the format does not follow the community expectations. Any help on this will be greatly appreciated.


Thank You.

fruit...@gmail.com

unread,
Apr 23, 2019, 2:42:46 PM4/23/19
to Python Programming for Autodesk Maya
hi ,

not sure I understood what you want to achieve. Ultimately, you want your mesh to look like a sphere ? If yes, I'd suggest you take the longest centroid->vertex to define a sphere radius, then you do a line/sphere intersection between each vector centroid->vertex (normalized) and your implicit sphere.
But depending on how your initial mesh looks like, you might have some weird results, so if you want something smoother, I'd go for an iterative operation (e.g. laplacian smooth + push several times)
Reply all
Reply to author
Forward
0 new messages