Home Technical Talk

Maxscript - Spinner to control object in viewport lags. Ideas?

polycounter lvl 12
Offline / Send Message
gamedev polycounter lvl 12
I'm working on a tool that uses a spinner to tweak the projection modifier cage in the view port in real time (yes, I realize that's how the projection modifier already works - bear w/ me :poly124:). Pretty much trying to mimic the same spinner in the command panel of the projection mod. Mine however lags like crazy and multiplies the users input. I'm not getting a 1:1 ratio if that makes sense. Clicking on the arrows works fine, its when I try and drag that things go awry.

Any ideas on this? I've already tried flagging meshes as foreground / background, but I think the problem lies elsewhere.

Thanks!

-Tyler

Replies

  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    try these 2 commands

    enableSceneRedraw();
    completeRedraw();

    maybe sceneRedraw is not activated, or try to force a redraw ( completeRedraw(); )on each spinner change iteration
  • gamedev
    Options
    Offline / Send Message
    gamedev polycounter lvl 12
    Thanks for the input, still lags like crazy :(. I'm starting to think the exposed commands to maxscript aren't quite right.

    From the docs:
    [php]Projection>.pushValue Float default: 0.0 -- world units; Push_Value[/php]

    Its a getter / setter. Setting it though just updates the spinner field, but doesn't actually fire off a changed event. So that's useless.

    Next step was trying this method (which I'm using, but its lagging!!!!!!):
    Projection : Modifier[php]<void>pushCage <float>amount[/php]

    To see what I mean, toss a projection modifier on a mesh, then eval this and use the spinner. Going one direction is fine, but try to go back and forth (positive and negative spins):

    [php]rollout projSpin "Projection Mod Spinnerl"
    (
    spinner sPushCage "Push Cage:" range:[-500,500,0] type:#integer
    on sPushCage changed val do
    (
    $.modifiers[1].pushCage(val)
    )
    )
    theNewFloater = newRolloutFloater "Test" 300 220
    addRollout projSpin theNewFloater[/php]

    Am I missing something? BTW, I tried this bit of code w/ the redraw and flag foreground stuff. No luck there.

    -Tyler
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Well, if you're having it evaluate that value every time you change the spinner, of course it's going to seem to "multiply" the effect. You probably don't want to pushCage by "val" but in fact push it by the difference between the previous value and the value which was just set. Otherwise it'll keep pushing out more as your spinner value increases.
  • gamedev
    Options
    Offline / Send Message
    gamedev polycounter lvl 12
    Hey MoP,

    I had attempted to trap the last push value, however the spinner works in an odd way. Once a value is applied, it gets zeroed out, which means getting the last value always returns 0. Which should mean you don't need to subtract the previous push amount from the amount you're about to add.

    Nonetheless, I had the same thoughts you did in that the lag is because the push amount is constantly being multiplied. Just not sure how to get around it because the spinner keeps zeroing out.

    Any ideas? Maybe I'm looking at this the wrong way?

    -Tyler
  • SyncViewS
    Options
    Offline / Send Message
    SyncViewS polycounter lvl 13
    Hi gamedev,
    I'd say it's not your fault. The pushCage function applies two transformations in one shot, the first is like setting the Push Amount value, and the second is like setting the Percent value at 100%, meaning you got the first shift doubled for each amount variation, so it looks like a multiplication.

    Here is a working code: sets the Percent at -100% each time the spinner is accessed and revert it to 0% after the shift.
    rollout projSpin "Projection Mod Spinnerl"
    (
        spinner sPushCage "Push Cage:" range:[-500,500,0] type:#integer
    
        local fPrePush = 0.0
    
        on sPushCage buttonDown do
        (
            $.modifiers[1].pushValue = 0.0
            $.modifiers[1].pushPercent = -100.0
        )
    
        on sPushCage changed val do
        (
            $.modifiers[1].pushCage(val - fPrePush)
            fPrePush = val
        )    
    
        on sPushCage buttonUp do
        (
            $.modifiers[1].pushPercent = 0
            -- uncomment this to reset the spinner after each adjustment
            -- sPushCage.value = 0.0
        )
    )
    theNewFloater = newRolloutFloater "Test" 300 220
    addRollout projSpin theNewFloater
    
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Heh, nice fix SyncViewS... shame it's such a silly problem, it shouldn't need to be fixed! :(
  • SyncViewS
    Options
    Offline / Send Message
    SyncViewS polycounter lvl 13
    Indeed, I had to understand how the Amount and Percent worked in Max before getting it in MaxScript and still don't understand why there aren't two separate functions to handle the two values adjustments. Anyway, never surrender to the machine! :)
  • gamedev
    Options
    Offline / Send Message
    gamedev polycounter lvl 12
    Hey SyncViewS,

    Thanks for the fix! One question for you though -

    [php]-- uncomment this to reset the spinner after each adjustment
    -- sPushCage.value = 0.0[/php]

    Did you actually get this to work as well? It resets the spinner to zero (just the projection mod does), however on the next spin the cage gets reset as well. It's more of a nit picky item.

    Cheers on the fix! I too have no idea why two values are needed for this one operation.

    -Tyler
  • SyncViewS
    Options
    Offline / Send Message
    SyncViewS polycounter lvl 13
    Hey Tyler, you're right, I forgot to reset the fPrePush variable as well, sorry.
    New buttonUp event:
    on sPushCage buttonUp do
    (
        $.modifiers[1].pushPercent = 0.0
        -- uncomment this to reset the spinner after each adjustment
        sPushCage.value = 0.0
        [B]fPrePush = 0.0[/B]
    )
    
    It should work well now (tested). :)
  • gamedev
    Options
    Offline / Send Message
    gamedev polycounter lvl 12
    haha, yea, I had just put in the same line. Thanks for the help, its much appreciated!

    -Tyler
Sign In or Register to comment.