PDA

View Full Version : key VertexPosition in wordlSpace?


demdike
07-10-2007, 04:06 PM
good day everybody,

I'm looking for a way to set keyframes for the position of every vertex in a polyPlane in worldSpace. This is necessary because I want to use the softModificationTool on the plane, move the vertices around, set a keyframe for their new position and then delete the Deformer and thereby make the shape change over time (I hope that is possible).

This is what I got so far:

select -r pPlane1 ;

$MaxVerts=120;
$vertObj="pPlane1";

for($x=0;$x<$MaxVerts;++$x){
$pos=pointPosition ($vertObj+".vtx["+$x+"]");
setKeyframe -breakdown 0 -hierarchy none -controlPoints 1 {"pPlane1.vtx["+$x+"]"};
}

That does key the vertices, but only in local space, each vertices XYZ reading 0 0 0.
If I try to add the pointPositionflag -world to the loop, I receive this error:

// Error: $pos=pointPosition -w ($vertObj+".vtx["+$x+"]"); //
// Error: Invalid use of Maya object "pointPosition". //

So, is there a way to make this work?

seema
07-10-2007, 04:50 PM
it needs to be given like this:

$pos=`pointPosition -w ($vertObj+".vtx["+$x+"]")`;

Hope it helps,
Seema

demdike
07-10-2007, 06:04 PM
Thank you very much seema, the error's gone:)

Unfortunately, the script still seems to key them in localSpace, not in worldSpace; when I move the softModificationTool, the vertice's values do change and I can key them, but as soon as I remove the deformer, they snap back into their initial position and all deformations are lost...

Maybe I need to store each vertice's position, delete the deformer and then move them back to where they were while being deformed...all in worldSpace of course...to be honest, I have no idea how to do that:shrug:

Thanks for your help, any further advice will of course be highly appreciated, meanwhile I'll see if I figure somthing out.

demdike
07-11-2007, 09:31 AM
Still couldn't find a solution...

Even if I move the Vertices with the SoftmodifocationTool, store their positions in Worldspace, delete the deformer and put them back in place afterwards, I can't key them and my problem remains unsolved.

So...does anybody know if it's even possible to key the position of a Vertex in worldSpace; the setkeyframe command doesn't seem to offer a flag like -worldspace, -w or -ws.

I'm lost!:scream:

Robken
07-11-2007, 01:04 PM
what you're trying to do is going to kill your playback rate.

a better solution would be to bake the deformation to a blendshape or something.

but ok, I'll take a shot.

My guess is you could create a cluster for a every single vertex at every single frame...that'll give you what position the vertex was in on THAT frame. then just make a second loop that snaps the vertex to the correct cluster. Then set a keyframe on the vertex.

actually, you can use locators instead of clusters....or any other transform.

you just first need to query the position of the point (pointPosition -w command) create a transform there....then afterwards snap the vertex back to the correct transform and key it.

demdike
07-12-2007, 01:05 AM
Thank you very much Robken, the locator's are a good idea.

The problem with blendshapes is that I want to animate the plane's shape, if necessary on a per frame basis and I can't imagine how to manage all the blendshapes that would arise during an animation over hundreds of frames.

Anyway, I'll try again tomorrow, being a novice to mel-scripting I didn't succeed in snapping the vertices today. I still got problems in transferring them in localSpace to a locator's worldSpace position.

There's something else confusing me, what's wrong with this:

if (`window -q -ex "chooseResolution"`) deleteUI "chooseResolution";
window -t "chooseResolution";
columnLayout -cat both 5;
intField -ec "cres" "res" ;
showWindow;

proc cres()
{
$resSize = `intField -q -v "res"`;
print $resSize;
latticeAutoparent "lattice -n GridDeformer -dv $resSize $resSize 2 -cp -oc true -ldv 30 30 2 -ol 1";
}

The printCommand spits out the value I entered in the intfield but I always get:

11// Error: line 0: Number of divisions cannot be less than 2. //

I'm sure it's happening due to an insultingly stupid typo, but no matter what I try, it doesn't work.

Robken
07-12-2007, 07:50 AM
why not just duplicate the plane at every frame and use the resulting duplicates as inbetween targets for1 single blendshape, nothing hard about it :)

you can use the "move" command to move the vertices where you want them to be.
find the worldposition of the locator, and then use the move -w command :).

btw the error in your script is probably because the value in your intfield is set to 0 or 1. A lattice needs to have at least 2 divisions on each axis. Try making the default value in your intfield 2.

demdike
07-13-2007, 12:53 AM
I got it!

...well, sort of. And not the verticesToLocators-thingy, been very busy at work today and I couldn't convince my boss that private research and development should come first;)

But I hear you Robken, thanks for your patience and advice, I hope I'll find some time tomorrow.

Anyway, if anybody ever needs to set a lattice's divisions like in the code posted earlier - using an intfield where the user types in an integer that gets later querried in a proc AND is not more clever than I am - try this workaround:

if (`window -q -ex "chooseResolution"`) deleteUI "chooseResolution";
window -t "chooseResolution";
columnLayout -cat both 5;
intField -ec "cres" "res" ;
showWindow;

proc cres()
{
$resSize = `intField -q -v "res"`;
print $resSize;
//create the lattice with any kind of value, I used the lowest possible for speed
latticeAutoparent "lattice -n GridDeformer -dv 2 2 2 -cp -oc true -ldv 30 30 2 -ol 1";
//change it's resolution after creation
setAttr "GridDeformerLatticeShape.sDivisions" $resSize;
setAttr "GridDeformerLatticeShape.tDivisions" $resSize;
}

It's definitely not elegant, but since I could set everything else using this variable (translate of a cube, resolution in x and y of a polyplane; all kinds of crap works - except the one I'm after) there must be something special about the lattice I haven't discovered yet.

CGTalk Moderation
07-13-2007, 12:53 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.