[Closed] Viewport Capturing – Image Aspect
Hi all,
I wrote a tool for stereograpic preview creation:
Works all fine, but I am not happy with the viewport capture functions. I used the script from the how-to in the maxscript help file and modified it a bit.
Is there an easy way to create a viewport capture image that is not distorted? Like with the “render()” command you can specify the camera and the width and height of the image. The viewport capturing is more difficult to get right.
preview_name = sequence_name
anim_bmp_left = bitmap widthP.value heightP.value filename:preview_name
format "File Preview Name and Path: %
" preview_name
select leftPEyeCam
max vpt camera
for t = startFrameP.value to endFrameP.value do
(
sliderTime = t
gw.setPos 0 0 widthP.value heightP.value
dib = gw.getViewportDib()
copy dib anim_bmp_left
runSave = save anim_bmp_left frame:t
close anim_bmp_left
)
gc()
Many thanks!
Marcus
Hi marcus,
I wrote a method recently for a tool that needed to capture the viewport according to the render resolution. Mine was a quick and dirty method so may not be accurate enough for the type of thing you are doing. But I thought I’d post it anyway in case you could get a start and maybe improve on it –
Fn LR_CaptureRenderAspectViewport =
(
local ViewCap=undefined
local cv = getViewSize()
local ratio = undefined
case of
(
(cv.x > cv.y):(ratio = cv.y/cv.x)
(cv.x = cv.y):(ratio = 1)
(cv.x < cv.y):(ratio = cv.x/cv.y)
)
VptDib =gw.getViewportDib();
ViewCap = bitmap renderwidth renderheight color:white
ViewportRatio = VptDib.width/VptDib.height as float
RenderRatio = renderwidth/renderheight as float
case of
(
(ViewportRatio <= RenderRatio):(
CapturetoRenderHeightRatio =VptDib.width/RenderRatio as float
TopEdge = ((VptDib.Height-CapturetoRenderHeightRatio)/ 2.0) as integer
FullViewcap = bitmap vptdib.width CapturetoRenderHeightRatio color:white
pasteBitmap VptDib FullViewcap (box2 0 TopEdge VptDib.width VptDib.height) [0,0]
Copy FullViewcap ViewCap)
(ViewportRatio > RenderRatio):(
CapturetoRenderHeightRatio =VptDib.height*RenderRatio as float
LeftEdge = ((VptDib.width-CapturetoRenderHeightRatio)/ 2.0) as integer
FullViewcap = bitmap CapturetoRenderHeightRatio VptDib.height color:white
pasteBitmap VptDib FullViewcap (box2 LeftEdge 0 VptDib.width VptDib.height) [0,0]
Copy FullViewcap ViewCap)
default:()
)
close VptDib
gc()
if viewcap != undefined then (setclipboardbitmap viewcap;close ViewCap;return true)else(return false)
)
tempbmp = LR_CaptureRenderAspectViewport()
display (getclipboardbitmap())
Its perfect, pete! Thank you! Put your function (with some little changes) in my for loop and it works fine. Creates folders, saves … all nice.
There is one thing that bugs me a bit. When I run the loop, after about 3 seconds, the programm freezes and becomes unresponsive (windows 7 puts a nice white shade on it) until the loop has finished. It works ok but its kind of stupid because my progress bar is not updating. You know a way to keep the program responsive? I tried with a timer and some other stuff but I think the roots of the problem lie in the for loop.
for t = startFrameP.value to endFrameP.value do
(
sliderTimePercentage = (t - startFrameP.value) * 100 / completeFrames
progressPreview.value = sliderTimePercentage
sliderTime = t
LR_CaptureRenderAspectViewport t "rightEye" selScene.selected selSequ.selected fileFormatP.selected rightPEyeCam
)
Cheers!
Marcus
I have these problems with win7 too, and my experience is that win7 is much more sensitive for long loops then XP for example. I’ve had some conformation from a adesk developer that this is indeed the case. So if max is not really crashing then you’ll have to live with it, otherwise you can try to do a viewport call every so often in the loop, but I also have mixed results with that.
-Johan
Hm, that is a pity. I almost expected an answer like this. So the only sure solution is to have hardware that can do every preview in less than 3 seconds
cheers,
marcus