Home Technical Talk

[MAXScript] Viewport "Eye" Distance To Zero

interpolator
Offline / Send Message
Revel interpolator
Hello people!

Does anyone know why the callback script with #viewportChange didn't run the callback when the distance < 1000? It's fine with rotating the viewport on any distance, but it's not the same case with zoom in/out.

Might be a little bit hard to explain with word, but here is the script that I got and you can see on the listener what I mean when you run the script;
(
    callbacks.removeScripts #viewportChange id:#vpUpdate
    
    global printDistance
    
    fn getViewDirectionRay =
    (
        local
        coordSysTM = Inverse(getViewTM()),
        viewDir = -coordSysTM.row3,
        viewPt = coordSysTM.row4
        
        return ray viewPt viewDir
    )
    
    fn printDistance =
    (
        eyeRay = getViewDirectionRay()
        
        vpPosX = eyeRay.pos[1]
        vpPosY = eyeRay.pos[2]
        vpPosZ = eyeRay.pos[3]
        vpDistanceToZero = sqrt (((sqrt ((vpPosX ^2) + (vpPosY^2)))^2) + (vpPosZ^2))
        print vpDistanceToZero
    )
    
    callbacks.addScript #viewportChange "printDistance()" id:#vpUpdate
)
.. if anyone have a better suggestion or thought, please do share :)

Replies

  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    The script works on 3dsMax 2014. Reset the viewports, run the script when the Perspective vpt is active and the distance is 250.0. Zooming in and out and in the listener the pirnted values are correct()for example 12,56, 21831.6)
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Hi miauu, thanks for testing the script. But here I'm using 3ds max 2014 as well, and funny that's not the case here..rotate the viewport printed fine on any distance, but zoom in/ out only printed above distance 1000..is it possible that it's affected by other script?
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    I don't know if the problem is another script. Add some debug lines of code and try to find why the script not works when the distance is less than 1000.
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    I asked my friend to test the script on his Max without any of my custom script and the problem was similar with my case...hmm, debug lines?care to explain abit more, miauu?
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    Something like this:
    (
        callbacks.removeScripts #viewportChange id:#vpUpdate
        
        global printDistance
        
        fn getViewDirectionRay =
        (
            print "-----------------------"
            coordSysTM = Inverse(getViewTM())
            format "coordSysTM: % \n" coordSysTM
            viewDir = -coordSysTM.row3
            viewPt = coordSysTM.row4
            format "viewDir: % viewPt:%\n" viewDir viewPt
            format "ray: % \n" (ray viewPt viewDir)
            --
            ray viewPt viewDir
        )
        
        fn printDistance =
        (
            eyeRay = getViewDirectionRay()
            format "eyeRay: % \n" eyeRay
            vpPosX = eyeRay.pos[1]
            vpPosY = eyeRay.pos[2]
            vpPosZ = eyeRay.pos[3]
            vpDistanceToZero = sqrt (((sqrt ((vpPosX ^2) + (vpPosY^2)))^2) + (vpPosZ^2))
            format "dist: % \n" vpDistanceToZero
        )
        
        callbacks.addScript #viewportChange "printDistance()" id:#vpUpdate
    )
    
    to check the value of each variable.
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Ah, I see..well at least on my case it's just printed 1 time when the distance is less then 1000 when I zoom in/ out the veiwport, for example;
    "-----------------------"
    coordSysTM: (matrix3 [0.965926,-0.258819,0] [0.0449435,0.167731,0.984808] [-0.254887,-0.951251,0.173648] [-49.5525,-191.311,29.6788]) 
    viewDir: [0.254887,0.951251,-0.173648] viewPt:[-49.5525,-191.311,29.6788]
    ray: (ray [-49.5525,-191.311,29.6788] [0.254887,0.951251,-0.173648]) 
    eyeRay: (ray [-49.5525,-191.311,29.6788] [0.254887,0.951251,-0.173648]) 
    dist: 199.841
    
    .. this is just printed 1 time, if I keep on zoom out, then it'll start printed like bellow;
    "-----------------------"
    coordSysTM: (matrix3 [0.993572,-0.113203,0] [0.011833,0.103856,0.994522] [-0.112583,-0.988129,0.104528] [-49.1689,-1005.01,21.0207]) 
    viewDir: [0.112583,0.988129,-0.104528] viewPt:[-49.1689,-1005.01,21.0207]
    ray: (ray [-49.1689,-1005.01,21.0207] [0.112583,0.988129,-0.104528]) 
    eyeRay: (ray [-49.1689,-1005.01,21.0207] [0.112583,0.988129,-0.104528]) 
    dist: 1006.43 
    "-----------------------"
    coordSysTM: (matrix3 [0.993572,-0.113203,0] [0.011833,0.103856,0.994522] [-0.112583,-0.988129,0.104528] [-49.3192,-1005.99,21.1307]) 
    viewDir: [0.112583,0.988129,-0.104528] viewPt:[-49.3192,-1005.99,21.1307]
    ray: (ray [-49.3192,-1005.99,21.1307] [0.112583,0.988129,-0.104528]) 
    eyeRay: (ray [-49.3192,-1005.99,21.1307] [0.112583,0.988129,-0.104528]) 
    dist: 1007.42 
    "-----------------------"
    coordSysTM: (matrix3 [0.993572,-0.113203,0] [0.011833,0.103856,0.994522] [-0.112583,-0.988129,0.104528] [-49.4695,-1006.98,21.2406]) 
    viewDir: [0.112583,0.988129,-0.104528] viewPt:[-49.4695,-1006.98,21.2406]
    ray: (ray [-49.4695,-1006.98,21.2406] [0.112583,0.988129,-0.104528]) 
    eyeRay: (ray [-49.4695,-1006.98,21.2406] [0.112583,0.988129,-0.104528]) 
    dist: 1008.41 
    "-----------------------"
    coordSysTM: (matrix3 [0.993572,-0.113203,0] [0.011833,0.103856,0.994522] [-0.112583,-0.988129,0.104528] [-49.6198,-1007.96,21.3505]) 
    viewDir: [0.112583,0.988129,-0.104528] viewPt:[-49.6198,-1007.96,21.3505]
    ray: (ray [-49.6198,-1007.96,21.3505] [0.112583,0.988129,-0.104528]) 
    eyeRay: (ray [-49.6198,-1007.96,21.3505] [0.112583,0.988129,-0.104528]) 
    dist: 1009.41 
    
    .. zoom out beyond the above, will printed the value like what we expected. Do you see anyhing unusual?
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    It might be a little bit hard to see with all the other codes, I didn't see any problem with my script so I tried to strip it down to be as basic as possible;
    (
        global test
        
        fn test =
            print "test"
        
        callbacks.removeScripts #viewportChange id:#vpUpdate
        callbacks.addScript #viewportChange "test()" id:#vpUpdate
    )
    
    .. and it is still showing weird behavior (unable to call the script with zoom in/ out on < 1000 distance from the world center)...I run out of idea to try to fix this if the problem lies on Maxscript's inconsistency...I'll appreciate if anyone else able to try and report back the result here. Thanks!
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    Change the display driver and try the script.
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Hmm..normally I'm using nitrous but I try to change it to legacy direct3D, it's still having the same issue. Which display driver that you using, miauu?
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    I'm using Nitrous.
    The worst method to try - reinstlal 3dsMax. :)
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Oh man, reinstalling doesn't seems like a good idea for me right now haha!
    Hey miauu, what about (un)registerRedrawViewsCallback? do you have experience with it?
    From a simple test that I did, it seems like slow down max quite noticable..

    It call the script anytime the viewport redraw including editing the object, but #viewportChange only call the script when the viewport rotate/zoom (above 1000).
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    Revel wrote: »
    Hey miauu, what about (un)registerRedrawViewsCallback? do you have experience with it?
    From a simple test that I did, it seems like slow down max quite noticable..

    It call the script anytime the viewport redraw including editing the object, but #viewportChange only call the script when the viewport rotate/zoom (above 1000).
    Your conclusions are right. Depends of the scene the slow down may be unnoticable for registerRedrawViewsCallbacks, but sometimes... :)

    Edit: Watch this video to see that your script works.
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    EDIT: Wait a minute..I know now! the problem is when I have a grid helper on scene. Oh wow, I never expected that to be the problem. Can you confirm that when you have a grid helper active on your scene then the script only callback on above 1000?

    Hey! thats the behavior that I wanted!hahaha..so weird that it's not working right here..
    Thanks for the viedo miauu, atleast I know it's not a bug or something that can't be "fixed".

    Just for information;
    3ds Max 2014 x64
    Nitrous driver (tried on Legacy Direct3D as well)
    Centimeter unit setup/ system unit setup
    Windows 7

    Hmm..I wish there's someone with a fresh max install to try it out..
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    Yep. If there is a grid helper in the scene the script prints only a distances above 1000. :)
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Well that's annoying cus the script intended to work with a custom grid :(
    It's not just about activating the grid helper, even when the non-active grid helper is on the scene, it's still printed only above 1000...
Sign In or Register to comment.