PDA

View Full Version : Constrain objects at the Vertex Level...??


futurcraft
11-06-2006, 03:58 AM
Is there a way by which I can constrain the vertices of my object to its original position in space and move the same object's main pivot to a different location in space...? I know its possible by manually parent constraining the object and deleting th constraint.. and then going to vertex mode and moving manually the positions of all the vertices back to the original location... but can anyone help me out with the code what to use to constrain the object at a vertex level....?

This is the code I use as most of u may already be aware of... but its for the whole object... how do we do similar stuff at the vertex level....?

string $selection[] = `ls -sl`;
pointConstraint ($selection[0]) ($selection[1]);
orientConstraint ($selection[0]) ($selection[1]);


Would appreciate feedback from u guys out there....
thanks...

Nikhil.

sparaig
11-06-2006, 05:31 AM
Is there a way by which I can constrain the vertices of my object to its original position in space and move the same object's main pivot to a different location in space...? I know its possible by manually parent constraining the object and deleting th constraint.. and then going to vertex mode and moving manually the positions of all the vertices back to the original location... but can anyone help me out with the code what to use to constrain the object at a vertex level....?

This is the code I use as most of u may already be aware of... but its for the whole object... how do we do similar stuff at the vertex level....?

string $selection[] = `ls -sl`;
pointConstraint ($selection[0]) ($selection[1]);
orientConstraint ($selection[0]) ($selection[1]);


Would appreciate feedback from u guys out there....
thanks...

Nikhil.

Maybe this?

geometryConstraint

Though thatappears to point constrain TO geometry. You want to point constraint the object's geometry, right?

Seems to me that you can automate your manual technique by using a scriptJob that triggers on the individual points being moved but I don't see any built-in function that does it automatically...

And I'm not even sure how automatable it is since at least some components only exist or at least are only accessable via MEL when the object is selected.

futurcraft
11-06-2006, 06:52 AM
Yea... I am actually askin of what kinda Mel code to use to constrain a vertex of an object to a specific position in space...

kojala
11-06-2006, 10:33 AM
you can do it with clusters.

I made a test scene where i had a cube and I made for it a cluster node. then I connected the cubes translate to a reverse node then to plus/minus node and the operation to sum. then I made an extra locator to define the place for the vertices. locator was connected to plus/minus second input and then I made a third input in plus/minus and typed in each section -1.

now I could move the objects origin where ever I liked and the object doesnt move at all an when I move the locator It moves the object vertices.

hope this was what you wanted.

futurcraft
11-06-2006, 10:43 AM
Hey Kojala..!
This very much seems to be what I am looking for... I'll try it out and get back in case I have any issues... thanks newayz...! :thumbsup:

Nikhil.

futurcraft
11-06-2006, 11:19 AM
if u dont mind.. could u post a pic of the hypergraph framework snapshot ofthe conections...?

cause.. connecting the locator to the + - node's second inpot.. is 2D... could u kinda explain the exact node connections...?

kojala
11-06-2006, 12:01 PM
There is a bug in plus/minus node.
At least in my maya 6.0.1. It doesnt have any visible inputs in connection editor so I always first connect the plus/minus node to itself (I used 3D inputs) in this case three times. then when it has created the inputs I unplug them.

wireframe:

I click the plus/minus in hypershade with MMB and drag it to 3D input [0] and same with [1] and [2]. then I open connection editor (in both sides is the plus/minus) then I unplug them.

futurcraft
11-06-2006, 01:16 PM
I am not sure if I am getting wht I need... let me explain.... actually.. I have a piece of geometry A... whose pivot had to be parent constrained & moved to the location of another object B's Pivot.. but the vertices of object A need to stay in its original place.. and the end result must be that when object B moves, object A also moves from its original location. this is possible by manually repositioning the vertices after parent constraining the geometry to bring the pivots in the same location... but since I have about 100 such objects... I am looking for a simplified method... like a process or procedure which can be coded based on the steps...

kojala
11-06-2006, 02:04 PM
Ok. Ill try to do it with mel. Ill be back.

kojala
11-06-2006, 04:57 PM
global proc move_pivot_to_obj()
{
string $objs[] = `ls -sl`;
string $old_pivot = $objs[0];
vector $old_pos = `xform -q -ws -t $old_pivot`;
string $new_pivot = $objs[1];

string $cluster[] = `cluster $old_pivot`;
$cluster = `listConnections -s 1 -d 0 ($cluster[0] + ".matrix")`;
string $reverse = `shadingNode -asUtility reverse`;
string $plus = `shadingNode -asUtility plusMinusAverage`;
string $helper = `group -empty`;
move ($old_pos.x) ($old_pos.y) ($old_pos.z) $helper;

connectAttr -f ($old_pivot + ".translate") ($reverse + ".input");
connectAttr -f ($reverse + ".output") ($plus + ".input3D[0]");
connectAttr -f ($helper + ".translate") ($plus + ".input3D[1]");

setAttr ($plus + ".input3D[2].input3Dx") -1;
setAttr ($plus + ".input3D[2].input3Dy") -1;
setAttr ($plus + ".input3D[2].input3Dz") -1;

connectAttr -f ($plus + ".output3D") ($cluster[0] + ".translate");

pointConstraint -offset 0 0 0 -weight 1 $new_pivot $old_pivot;
pointConstraint -mo -weight 1 $new_pivot $helper;
orientConstraint -mo -weight 1 $new_pivot $helper;
orientConstraint -mo -weight 1 $helper $cluster[0];
}

move_pivot_to_obj();

try this: first select object A then object B. then this mel As origin will go to B. there might be bugs.

sunit
11-06-2006, 05:44 PM
whose pivot had to be parent constrained & moved to the location of another object B's Pivot.. but the vertices of object A need to stay in its original place.. and the end result must be that when object B moves, object A also moves from its original location.

so, you want to transform objectA based on objectB transformations, but you want to maintain the initial offset? why not simply use a parentConstraint with maintain offset turned on?

perhaps you can elaborate what it is you want to accomplish...

-sunit

futurcraft
11-06-2006, 10:28 PM
Hi Kajola...!
The code works perfect.... but there is still one thing... now that we have successfully moved object A's pivot to Object B's pivot location... using ur code... can we now have a way to retain the pivot's position and delete all the new modes that were created...? I mean. when we have a 100 objects... dont u think it would be better to have a cleaner hierarchy... by deleting all the nodes.. created by the script after it has served its purpose...? cause... after I used ur code... then I move object B. like the way I move a joint(imagine that object B is an Elbow Joint and Object A is the elbow Geometry) then what happens here is, on moving the joint, the geometry does not exactly move the way it would move if I have done it the manual method as described earlier...

so now that we have moved the object A's pivot.... if there is a way by which we could retain its position and then parent constrain the object A to the Joint wich is object B then this code can be made very powerful....

can we do that...?

futurcraft
11-06-2006, 10:45 PM
so, you want to transform objectA based on objectB transformations, but you want to maintain the initial offset? why not simply use a parentConstraint with maintain offset turned on?


Sunit....

-sunit

To be frank with U... I tried the parent constrain again this time.... I did the very same parent constrain earlier... but for some crazy reason.. all the geometry started acting funny by jumping around when I bring the joints back to the default pose...

but Now... I jus dunno why... but everythin is workin jus perfect...!

I dont understand... WY ON EARTH Maya made me look a a D*** Fool... :scream:

But.. anywayz... this whole episode was a great learning experience...!

thanks guys,,, Sunit... for making me try it out again... and Kajola... for ur time... for developing that piece of code for me....

really appreciate it...

Regards,

Nikhil.

sparaig
11-07-2006, 07:33 AM
To be frank with U... I tried the parent constrain again this time.... I did the very same parent constrain earlier... but for some crazy reason.. all the geometry started acting funny by jumping around when I bring the joints back to the default pose...

but Now... I jus dunno why... but everythin is workin jus perfect...!

I dont understand... WY ON EARTH Maya made me look a a D*** Fool... :scream:

But.. anywayz... this whole episode was a great learning experience...!

thanks guys,,, Sunit... for making me try it out again... and Kajola... for ur time... for developing that piece of code for me....

really appreciate it...

Regards,

Nikhil.

Something my son pointed out to me: when Maya starts making you feel foolish, maybe iit is time to delete the preferences...

kojala
11-07-2006, 07:43 AM
Hi Kajola...!
The code works perfect.... but there is still one thing... now that we have successfully moved object A's pivot to Object B's pivot location... using ur code... can we now have a way to retain the pivot's position and delete all the new modes that were created...? I mean. when we have a 100 objects... dont u think it would be better to have a cleaner hierarchy... by deleting all the nodes.. created by the script after it has served its purpose...? cause... after I used ur code... then I move object B. like the way I move a joint(imagine that object B is an Elbow Joint and Object A is the elbow Geometry) then what happens here is, on moving the joint, the geometry does not exactly move the way it would move if I have done it the manual method as described earlier...

so now that we have moved the object A's pivot.... if there is a way by which we could retain its position and then parent constrain the object A to the Joint wich is object B then this code can be made very powerful....

can we do that...?


I was thinking about that. It is possible just wait a minute...

kojala
11-07-2006, 07:51 AM
Ill make a mell to clean the new nodes,
but I noticed that the only way to get rid off the cluster is to delete object As history. is that a problem? do you have important history on your nodes (like skinning)?

kojala
11-07-2006, 08:21 AM
global proc delete_pivot_nodes()
{
string $old_pivot[] = `ls -sl`;
delete -ch $old_pivot;

string $constr_p_1[] = `listConnections -s 1 -d 0 ($old_pivot[0] + ".translateX")`;
string $reverse[] = `listConnections -s 0 -d 1 -scn 1 ($old_pivot[0] + ".translate")`;
string $plus[] = `listConnections -s 0 -d 1 -scn 1 ($reverse[0] + ".output")`;
string $cluster[] = `listConnections -s 0 -d 1 -scn 1 ($plus[0] + ".output3D")`;
string $constr_o_1[] = `listConnections -s 1 -d 0 ($cluster[0] + ".rotateX")`;
string $helper[] = `listConnections -s 1 -d 0 -scn 1 ($plus[0] + ".input3D[1]")`;
string $constr_p_2[] = `listConnections -s 1 -d 0 ($helper[0] + ".translateX")`;
string $constr_o_2[] = `listConnections -s 1 -d 0 ($helper[0] + ".rotateX")`;

delete $constr_p_1 $reverse $plus $cluster $helper $constr_p_2 $constr_o_1 $constr_o_2;
}

delete_pivot_nodes;


Heres deletion proc. You have to select the object A (which pivot is in object B).
I havent tested mel with multiselected As..

So I notised that you made it work with parentConstraint.

well.. I made this anyway
because i needen it myself a while ago but I didnt have it then.

bye.

isoparmB
11-07-2006, 12:16 PM
Is there a way by which I can constrain the vertices of my object to its original position in space and move the same object's main pivot to a different location in space...? I know its possible by manually parent constraining the object and deleting th constraint.. and then going to vertex mode and moving manually the positions of all the vertices back to the original location... but can anyone help me out with the code what to use to constrain the object at a vertex level....?

This is the code I use as most of u may already be aware of... but its for the whole object... how do we do similar stuff at the vertex level....?

string $selection[] = `ls -sl`;
pointConstraint ($selection[0]) ($selection[1]);
orientConstraint ($selection[0]) ($selection[1]);


Would appreciate feedback from u guys out there....
thanks...

Nikhil.

Might I suggest you use a blendshape operation with the World origin turned on.

What you do is duplicate your original object and leave that duplicate at the world (parented to nothing). Select the duplicate, then the original and do a blendshape operation with the origin setting set to world. Turn on the target weight. Then, try constraining your original object or translating it to whatever you want. The object will remain where the original is, but will receive the transformations being applied to the pivot (if that's what your after). You can even select which vertices stay put by editing the membership of the blendshape node and ctrl-selecting the vertices you want to be free of the blendshape constraint effect.

Later you can bake the deformations of this object if you want to get rid of the history.

futurcraft
11-08-2006, 01:52 AM
Might I suggest you use a blendshape operation with the World origin turned on.


Hi IsoparmB...
The blendshape method is quite an innovative one... I would try it next time cause as of now.. the parent constraint method has started workin fine ...
thanks for ur feedback anywayz...


Heres deletion proc. You have to select the object A (which pivot is in object B).
bye.

Yeah Kojala...
the deletion of the clusters was where I kinda got stuck.. but with deleting construction history.. a way I neva thought of but u did.. tht seems to work jus fine...;)
anywayz.. thanks for ur code n takin time to develop it..

Something my son pointed out to me: when Maya starts making you feel foolish, maybe iit is time to delete the preferences...

Hi Sparaig...
I did jus that after u told me to... everything works fine now. I jus brught back my shelf settings... n Icons n its back to being stable ....
thanks for ut tip...

Thank u guys all of u for ur replies...!

Regards,

Nikhil.

CGTalk Moderation
11-08-2006, 01:52 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.