Home Technical Talk

[Maya] Conform Poly Vertex To A CV Curve With Mel

polycounter lvl 11
Offline / Send Message
daniellooartist polycounter lvl 11
Hello everyone. I model a lot of shapes with wide flowing curved surfaces. I already wrote a script to convert my selected poly edge to a curve and automatically rebuild it with a specified number of spans. I do this so that I can have a nice smooth guide to conform my verts to. The problem is that I have to do this manually. I would like to write a script that automaticly snaps each of the selected verts to the closest point on the curve. Problem is I have no earthly idea how that would be done. Any ideas?

btw here is my first script.

global proc UpdateProc ()
{
string $sel[] = `ls -sl`;
rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 6 -d 3 -tol 0.01 $sel;
// change -s 6 to -s the number of number of spans you want the curve to be. for example -s 12 will make 12 spans.
}
//start
polyToCurve -form 2 -degree 3;
DeleteAllHistory;
UpdateProc ();


Replies

  • throttlekitty
    Options
    Offline / Send Message
    Have you tried the Wire tool? It doesn't snap 1:1 like you're asking, but it does have some other paramaters to mess with.

    For scripting your own, you could try the closest point on curve function, and create clusters for your affected vertices. Then constrain the clusters to the point on curve node, I'm not sure how to go directly from vertex > point on curve.
  • IxenonI
    Options
    Offline / Send Message
    IxenonI interpolator
    I`m looking for something like this as well. Max has some great scripts, but all the ones that I`ve found in maya are just not as flexible / fast / intuitive. 
    Let me know if you find anything...
  • daniellooartist
    Options
    Offline / Send Message
    daniellooartist polycounter lvl 11
    I plan on writing a script that does a few things.

    1. grab a list of all the verticies I have selected with ls -sl.
    2. find a way to output the number of lines in that list.
    3. find a way to cycle through something that can output the item in a specified line number.
    4. for each of those create a cluster.
    5. output a list of all the clusters in my scene.
    6. find a way to output the number of clusters in that list.
    7. find a way to cycle through something that can output the cluster item in a specified line number.
    8. for each cluster, run the function that constrains it to the closest point on curve.

    There are 3 things I can not find out how to do. I don't know how to output the number of lines in the selection list and I also do not know how to read specific lines in said selection list. I also don't know how to create a cluster deformer on a specific item command. The CreateCluster command just assumes it should created 1 deformer on all selected items. Anyone know how to any of that or am I WAY off with how it should be done?
  • throttlekitty
    Options
    Offline / Send Message
    I'm not sure what you mean by "number of lines", can you clarify? I noticed a script called "djRivet.mel" that has some similar features that you want to do. Might want to check that out for examples.

    This script:

    string $verts[] = `ls -sl`; print $verts;

    Returns: "pCube1.vtx[0:7]". Adding -fl to the ls command will "flatten" the list so each vertex would appear on it's own line if you need. But if you wanted only the numeric values in the array, I think you use the match command to do that. I don't have a good example of doing that offhand, sorry. This next example will create a cluster handle for each vertex.

    <div>{
    
    </div><div>string $verts[] = `ls -sl -fl`;
    
    </div><div>print $verts;
    
    </div><div>for ($i = 0; $i < size($verts); $i++){
    
    </div><div>&nbsp; &nbsp; string $vertCluster[] = `cluster -n "vertCluster#" $verts[$i]`;
    
    </div><div>&nbsp; &nbsp; }
    
    </div><div>}</div>
  • daniellooartist
    Options
    Offline / Send Message
    daniellooartist polycounter lvl 11
    That worked pretty well. I can see how the script works now that it's written in front of me. The only thing I don't get is why there is a # sign at the end of vertCluster$ and a ` after the [$i]. What do those do?
  • throttlekitty
    Options
    Offline / Send Message
    The # is part of the naming creation syntax, I can't remember the doc page for that. It ensures that "vertCluster" will always have a number in the name. Without it, the first would be vertCluster, followed by vertCluster1, vertCluster2. This would be bad if another part of the script expects to pick one by number.

    $verts[$i] refers to the current iteration in the index of $verts for creating both the cluster node and the cluster handle (its transform). You can see that with just $verts, it creates a single handle. if you add a "print $vertCluster;" you can see the makeup of that array, where it's been created as cluster/clusterhandle. But what I don't understand why this numbering starts at 1 instead of 0, maybe someone else can answer that? (e: oh yes i do. it's because when using name#, numbering starts at 1.)
Sign In or Register to comment.