PDA

View Full Version : Object Callback Event?


Dov Sherman
04-08-2005, 11:57 AM
I'm trying to set up a simple callback-based event that will look at the position of an object, measure it's X-rotation angle relative to it's parent object, and store the value in something that can be used in a Wire.

Is this possible? What callback event should I use?

If I use this script to cause a second object to change based on the Wire, would I need to have the script create keyframes before rendering or is there a callback event that occurs during render time between each frame?

Bobo
04-08-2005, 04:30 PM
I'm trying to set up a simple callback-based event that will look at the position of an object, measure it's X-rotation angle relative to it's parent object, and store the value in something that can be used in a Wire.

Is this possible? What callback event should I use?

If I use this script to cause a second object to change based on the Wire, would I need to have the script create keyframes before rendering or is there a callback event that occurs during render time between each frame?


Don't use callbacks for this!
Btw, Wire controllers are a special form of scripted controllers. Note that in Max 7 you can resize the Wire dialog and enter as much MAXScript code as you want, including multi-line code, local and global variables, any expression you would write in a Scripted controller, with the only difference that the code is executed not when the controlled object is updated, but when the controlling object is updated.

For example,

*Create a Box, a Cylinder and a Sphere
*Wire the Height of the Box to the Height of the Cylinder
*Enter in the Box01's Expression field:

theRadius = $Sphere01.radius
Height*theRadius

If you would now animate the height of the cylinder, the box's height will also change, but using the radius of the Sphere as multiplier.

Changing the sphere's radius interactively will NOT update the box's height in the viewport, because the Wire does not know it depends on the Sphere. (dependsOn does not work either). But if the Wire is being updated on every frame because of the Cylinder's animation, if you would also keyframe the Radius of the Sphere, the multiplier will be taken into account correctly during the animation playback and rendering, because the Wire will be forced to update thanks to the Cylinder's animation.

Obviously, you can write global variables out of the Wire expression, or use other Scripted Controllers to provide global variables to be used by the Wire controller.

global theSphereRadius = $Sphere01.radius
Height*theSphereRadius

Callbacks are mainly used for UI updates, background checks and operations on the scene when certain system events occur, but should NOT be used as an animation tool!

Dov Sherman
04-11-2005, 12:52 PM
Thank you very, very much! This is extremely helpful. I've been struggling to find a way to wire using Biped bones as source targets but it wasn't working because Biped bones don't seem to update their parameters in a way that can be wired easily.

I believe I should be able to use the method you described to dynamically measure angles with a little trigonometry (between the bone, its parent bone, and a dummy object) in the wire dialog.

Dov Sherman
04-11-2005, 01:56 PM
I tried the technique and I've had mixed results.

I created a simple Biped and three Dummy objects. The Dummy objects were placed as follows:


Dummy object ($DLUA1) at the pivot point of the left upper arm, attached to the left upper arm
Dummy object ($DLUA2) partway along the left upper arm, attached to the left upper arm
Dummy object ($DLUA2) at the pivot point of the left clavicle, attached to the clavicle
Then I created a new Dummy object ($Dummy01) off to the side. I set a wire between the x-rotation of $Dummy01 and available-rotation the Biped's Left Upper Arm. Then I set the code for the wire to solve for the angle of the arm based on the position of the boxes, as follows...

c = sqrt ( (($DLUA1.pos.x - $DLUA2.pos.x) ^ 2) + (($DLUA1.pos.y - $DLUA2.pos.y) ^ 2) + (($DLUA1.pos.z - $DLUA2.pos.z) ^ 2) )
b = sqrt ( (($DLUA1.pos.x - $DLUA3.pos.x) ^ 2) + (($DLUA1.pos.y - $DLUA3.pos.y) ^ 2) + (($DLUA1.pos.z - $DLUA3.pos.z) ^ 2) )
a = sqrt ( (($DLUA3.pos.x - $DLUA2.pos.x) ^ 2) + (($DLUA3.pos.y - $DLUA2.pos.y) ^ 2) + (($DLUA3.pos.z - $DLUA2.pos.z) ^ 2) )
s = (a + b + c) / 2
acos (1 - ((2 * (s - b) * (s - c)) / (b * c)))



When I clicked the Update button in the Wire Parameters dialog, $Dummy01 moved to the correct angle. But when I moved the left upper arm, the angle of $Dummy01 did not update. It would only update when I manually clicked the Update button.

What am I doing wrong here? Since I'm not actually using the Available-rotation property of the Biped bone, it doesn't really matter if I use a different property. But to what can I wire so that it will update when the Biped bones change position?

CGTalk Moderation
04-11-2005, 01:56 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.