0
votes

I'm making a simple fan in 3DS MAX, and creating a GUI to control the object. At the moment on the GUI i can control PlayAnimation() and StopAnimation() with a On/Off button. But i'm trying to make a Slider which then controls the speed of the animation. This will (in this case) increase the rotation speed of the fan blades.

But this is where i'm stuck at, i'm not 100% sure on how to do this, and couldn't find anything on Google that will help me use a Slider to increase the animation speed.

Any help and guidance would be very appreciated !

MaxScript so far:

try(DestroyDialog GUI)catch()
Rollout GUI "GUI"
(
Label lbl_name "Power"
button btn_on "ON" across:2
button btn_off "OFF"
Label lbl_speed "Speed Levels"
Slider slider
on btn_on pressed do
(
   PlayAnimation()
) 
on btn_off pressed do
(
   StopAnimation()
) 
//Slider Here...
)
CreateDialog GUI
2

2 Answers

0
votes

You're looking for the playbackSpeed:

try destroyDialog ::GUI catch()
rollout GUI "GUI"
(
    checkButton chb_switch "Power" width:50
    label lbl_speed "Speed Levels" offset:[0,10]
    slider sld_speed type:#integer range:[1,5,timeConfiguration.playbackSpeed]

    on chb_switch changed playing do
        if playing then playAnimation() else stopAnimation()

    on sld_speed changed val do timeConfiguration.playbackSpeed = val
)
createDialog GUI
0
votes

Changing the playback speed changes it for the entire scene. Anything animated in the scene will be affected...

How I'd approach this is for your specific needs:

  • Change the fan object/bone's rotation controller to a linear controller.
  • Set two keys on rotation, one at frame 0 and another at frame 100, both set with a value of 0.
  • Set the rotation curve in/out of range types, to relative repeat.
  • Add a check button to select your fan to the UI. (You might want to manipulate different fans in the same scene).

Here's the ui:

try destroyDialog ::GUI catch()
rollout GUI "GUI"
(
    -- this local variable stores the two initial keys of your fan
    local keys = undefined

    pickbutton pkb_fan "Select Fan" message:"Please select animated fan" autoDisplay:true
    checkbutton chb_switch "Power"
    slider sld_speed    "Fan Speed" type:#float range:[0, 100.0, 0]

    -- when the fan is selected, assign its linear rotation keys to the keys variable
    on pkb_fan picked obj do
    (
        if (obj != undefined) then 
        (
            keys = obj.rotation.controller.keys
        )
        else (keys = undefined)
    )
    -- turning on the fan is setting the second key frame's rotation to a             
    -- non-zero value. 
    -- turning it off is setting it to zero.
    -- in this scenario the fan is rotating on its Y axis.
    on chb_switch changed playing do
    (
        if (keys != undefined) and (keys.count >= 2) then
        (
            if (playing) then (keys[2].value = quat 0 1 0 1)
            else (keys[2].value = quat 0 0 0 1)
        )
    )
    -- changing the speed of the fan is moving the second keyframe; assuming 
    -- the key frame value is always the same,
    -- the closer it moves to the first key frame, the faster it spins, the 
    -- more distant, the slower it spins
    on sld_speed changed val do
    (
        if (keys != undefined) and (keys.count >= 2) then
        (
            local t = 0f
            if (val > 0.0) then (t = 1.0 / val * 100.00)

            keys[2].time = t
        )
    )
)

createDialog GUI

This is a simple scenario. If you need to animate/record the varying speed, the approach changes somewhat.

Hopefully this gets you started.