View Full Version : dynamically scaling objects based on vector

02 February 2011, 12:42 AM
Hello folks, what I'm trying to accomplish is this: I want to be able to drive scale attributes of moving geometry objects (whether key animation or on a motion path) based on their vector, ie, when the object makes a sharp turn, the scale increases, and when the object goes in a straight line, the scale attribute is at a smaller value. The idea is to extrude a curve on a motion path, and when this path takes a tight turn, the extrude object scales up, so that the resulting extrusion gets 'larger' in the sharp turns and has a more uneven/organic behavior.

I know a little Mel, very little. I know I have to derive some kind of vector value from the rate of change of direction of this object, then use this value to drive the scale attributes. I've been scouring resources for the right expressions, and hope someone can help me with this.

02 February 2011, 03:56 AM
I'm not sure entirely what you're going for but are you referring to motion smear?

Some people call it geometry smear, others smear deformer, etc etc but it's all interchangeable names for the same concept.

I don't know all that much MEL so if this isn't what you are talking about then I can't help you but I thought I'd ask just in case.

02 February 2011, 06:17 PM
If I understand want you want, you can probably accomplish this with some vector mathematics using dot products.

As two vectors reach perpendicular, the dot product will be closer to 0, as they become closer to the same direction, they will be closer to 1. You can use this value to drive your scale attribute based on the change of this value (you will probably have to reverse the value since you want it to become larger as the dot product becomes 0 and smaller at 1)

Knowing this, I would use an expression to store a vector from the previous frame and on the current frame, then use the dot product on these vectors to drive your scale.

I quickly made this expression for you that you can copy and paste in the expression editor and you just have to change the name of your tracking object and the object you want to drive the scale:

// storage of previous position and direction
global vector $prevPos;
global vector $prevDirection;

// get the current position of the object to track
vector $currentPos = `xform -q -t -ws objectToTrack`;

// get the vector from the previous position to the current position
vector $currentDirection = $currentPos - $prevPos;

// get the dot product of the current direction and the previous direction (use normalization)
float $dotProd = dotProduct($currentDirection, $prevDirection, 1);

// set the previous position and direction to our current for next time
$prevPos = $currentPos;
$prevDirection = $currentDirection;

// reverse the dot product to be 1 when there is a 90 degree turn and clamp it
$dotProd = clamp(0, 1, (1 - $dotProd));

// use the dot product to drive the scale of your object
objectToScale.scaleX = $dotProd;
objectToScale.scaleY = $dotProd;
objectToScale.scaleZ = $dotProd;

This will normalize the scale to be between 0 and 1, if you want to have a greater range, then you can do add your own multiplier to the dot product value.

I hope that is what you are after or gives you some help in the right direction.

Let me know and good luck,

02 February 2011, 08:20 PM
Wow dude this is awesome, it's exactly what I was trying to figure out, actually. I can modify the scaling aspects a bit so that a nominal amount in the scale is maintained and then the result of the dotprod adds to it.

But now I see that I was intending on applying this to an object on an extrude path. The extruded object has no translation information...It just stays in place and the geometry extrusion is animated by controlling subcurves to time the extrusion along the path... So This approach won't work after all. I was hoping to scale the extrude object when it takes a tight turn along the path, but looking at it now I became aware that the extrude object stays in place! I would need to rig a different system to create this geometry...

So while your expression is what I was looking for, it turns out my approach is flawed... Back to the drawing board I guess :) Thanks for showing me this though, it's a great learning experience. I might yet be able to use this if I figure how to create this geometry...

02 February 2011, 09:12 PM
Ah, I see what you trying to do. Well You could put an object on the curve as a motion path or a point on curve node to drive an object along and grab the translation from that if you can somehow sync it with the extrusion.

But I don't know exactly the type of setup you have or how are you controlling it, so just tossing that idea out there.

Good luck and at least you have some new tricks for future use :)

CGTalk Moderation
02 February 2011, 09:12 PM
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.