[Closed] grabviewport script
Here is part of a script that i’m writing, its suppuse to grabvieport of the selected camera and save it.
the active viewport for that test is top view.
press the add_camera button first and then the creat_prev.
the problem is that the saved img is the top view and not the camera view, if you’ll run the script line by line you will see that its working properly and the saved image is the camera view.
can someone help me understand what am i doing wrong here?
the script :
global maincam
global newcam
global bmp1
rollout Test_c “Test Camera” width:181 height:100
(
button Add_cam “Add Camera” pos:[9,6] width:107 height:23
button Make_prev “Make_prev” pos:[90,70] width:80 height:23
on Add_cam pressed do
(
mainCam = $
)
on Make_prev pressed do
(
bmp_name = selectSaveBitMap()
viewport.setCamera maincam
viewport.SetRenderLevel #smoothhighlights
bmp1 = gw.getViewportDib()
bmp1.filename = bmp_name
save bmp1
)
)
createdialog Test_c
it get’s the currently selected viewport.
and not the camera.
add this function after switching camera and changing draw mode:
redrawViews()
replace this line:
viewport.setCamera maincam
with:
viewport.setCamera (maincam)
this makes sure it switches the viewport to the selected camera, and refreshes the view.
final code:
global maincam
global newcam
global bmp1
rollout Test_c "Test Camera" width:181 height:100
(
button Add_cam "Add Camera" pos:[9,6] width:107 height:23
button Make_prev "Make_prev" pos:[90,70] width:80 height:23
on Add_cam pressed do
(
mainCam = $
)
on Make_prev pressed do
(
bmp_name = selectSaveBitMap()
viewport.setCamera (maincam)
viewport.SetRenderLevel #smoothhighlights
redrawViews()
bmp1 = gw.getViewportDib()
bmp1.filename = bmp_name
save bmp1
)
)
createdialog Test_c
also remember to check the settings when someone uses Nitrous, it has it’s own settings for the view. (wireframe view, realistic etc). so remember to include this in your tool.
There is a grabviewport tool on my site if it can help.
http://xoliulshader.com/download
it is made by a friend of mine called “Leslie Van den Broeck”
I do it like this:
view_size = getViewSize() --get's the current viewport size
anim_bmp = bitmap view_size.x view_size.y filename:("C: est.bmp")
dib = gw.getViewportDib()
copy dib anim_bmp
save anim_bmp
close anim_bmp
Hi thanks for the reply
I would like to save the bitmap at specific size , lets say 640*480 which is diffrent then my viewport size.
is that possible?
Here I modified original code to make it save 800×600.
It copies the viewport image and pastes it into a 800×600 bitmap.
I don’t check aspect ratio or anything like that.
but it should get you started.
global maincam
global newcam
global bmp1
rollout Test_c "Test Camera" width:181 height:100
(
button Add_cam "Add Camera" pos:[9,6] width:107 height:23
button Make_prev "Make_prev" pos:[90,70] width:80 height:23
on Add_cam pressed do
(
mainCam = $
)
on Make_prev pressed do
(
bmp_name = selectSaveBitMap()
viewport.setCamera (maincam)
viewport.SetRenderLevel #smoothhighlights
redrawViews()
bmp1 = gw.getViewportDib()
finalbitmap = bitmap 800 600
copy bmp1 finalbitmap
finalbitmap.filename = bmp_name
save finalbitmap
)
)
createdialog Test_c