I have used this dirty hack (viewport.zoom .75) in code below to approximately get the viewport of the perspective to fill the viewport as best it can and also reset the VP the way I like.
viewport.ResetAllViews() --resets to Max Standard
actionMan.executeAction 0 "311" --frames all viewports
viewport.zoom .75 --fix to make perspective view appear closer
viewport.setGridVisibility #all false --turns off all grids
actionMan.executeAction 0 "40829" --show statistics
actionMan.executeAction 0 "63547" -- Views: Viewport Materials Display as Realistic with Maps
This works fine but I was searching for a more accurate solution and I got a fn from Dennis T on another forum to get the bounding size of objects in a scene. I've searched hi and low for the answer on how the viewport.ZoomToBounds System Global Variable actually works in relation to this and also how to get the zoom to work. Searching now 3 hours and no luck.
CODE I HAVE SO FAR:
global ZoomToObjBB
fn ZoomToObjBB = (
viewport.ResetAllViews() --resets to Max Standard
actionMan.executeAction 0 "311" --frames all viewports
--viewport.zoom .75 --fix to make perspective view appear closer
viewport.setGridVisibility #all false --turns off all grids
actionMan.executeAction 0 "40829" --show statistics
actionMan.executeAction 0 "63547" -- Views: Viewport Materials Display as Realistic with Maps
nodes = for node in objects where iskindof node GeometryClass collect node
if nodes.count > 0 do
(
view = viewport.activeViewport
local bmin = [1e9,1e9,0], bmax = [-1e9,-1e9,0]
gw.setTransform (matrix3 1)
transPoint = gw.hTransPoint
for node in nodes do
(
mesh = snapshotasmesh node
for v=1 to mesh.numverts do
(
vp = transPoint (GetVert mesh v)
if vp.x < bmin.x do bmin.x = vp.x
if vp.x > bmax.x do bmax.x = vp.x
if vp.y < bmin.y do bmin.y = vp.y
if vp.y > bmax.y do bmax.y = vp.y
)
free mesh
)
w = (bmax.x - bmin.x) as integer
h = (bmax.y - bmin.y) as integer
print bmin.x
print bmin.y
print bmax.x
print bmax.y
print w
print h
viewport.ZoomToBounds false (point3 w h 0) (point3 w h 0)
completeRedraw()
)
)
ZoomToObjBB()Any help would be greatly appreciated from you experts out there :)
By 3dwannab · 2015-07-27