[Closed] callbacks change viewport
I need a callback that detects when I change active viewport to camera or any other – perspective, top…
not this:
fn theFun =
(
print "viewport changed"
)
callbacks.addScript #viewportChange "theFun()" id:#theViewCall
because it detects any change – even every mouse move, rotating inside viewport. I need only when I swap between cameras and other views like perspective, top, left etc.
Thanks in advance!!
does this help you ?
(
clearListener()
global checkVpChange
local curr_VP = viewport.getType()
print ("Current VP: " + curr_VP as string)
fn checkVpChange = (
if ( (viewport.getType())!=curr_VP ) then ( -- when viewport changes
print ("VP changed to: " + (viewport.getType()) as string)
curr_VP = viewport.getType()
)--end if
)--end fn
registerRedrawViewsCallback checkVpChange
-- do stop callback :
--unregisterRedrawViewsCallback checkVpChange
)
Thank you, Rico!
Yes, this is I need plus information about camera swap – from one camera to another
(
clearListener()
global checkVpChange
local curr_VP = viewport.getType()
fn getcam =
(
if curr_VP == #view_camera then
(
cam = try(getActiveCamera()) catch(return undefined)
return cam
)
else return undefined
)
local prevcam = getcam
print ("Current VP: " + curr_VP as string)
fn checkVpChange = (
if ( (viewport.getType())!=curr_VP ) then ( -- when viewport changes
print ("VP changed to: " + (viewport.getType()) as string)
curr_VP = viewport.getType()
)--end if
else if prevcam != getcam() then print (getcam())
)--end fn
registerRedrawViewsCallback checkVpChange
-- do stop callback :
--unregisterRedrawViewsCallback checkVpChange
)
Please, make some corrections to my script. It’s working, but I don’t like the way I did it.
callbacks.removescripts id:#viewport_monitor
callbacks.addscript #viewportChange "format \"viewport changed > active:%\
\" viewport.activeViewport" id:#viewport_monitor
Denis, your script is looking very sweet – short and clean, but it also detects every mouse move at me. Should I use also checkVpChange() ?
Just a heads up:
There is a bug in Max 2014/2015 where the viewport callback is not triggered
I reported this already, but better some aditional people report it too…
In Max 2014 and up, registering a #viewportChange callback, leads to the following, faulty behavior ( Max 2013 is fine)
when the viewport is empty, pan/zoom and orbit trigger the callback correctly. Perspective and Ortho views alike
as soon as anything is visible in the viewport ( type does not matter: geometry, helper, frozen or not ):
in ortho views, Pan/Zoom completely STOP triggering the callback
in perspective views, zooming still triggers the callback, but panning fails here too
Panning/Zooming in a camera viewport still works
Hidden objects do not cause this bug.
This just appears in Max 2014 and up, Nitrous and D3D viewport a like. Max 2013 is not affected by this bug
But at me its printing
viewport changed > active: 1
in the listener many many times and very quick –
at every mouse move. – max 2012 x64
so what? just store the previous viewport and do anything when the viewport was really changed, and ignore all other notifications.