[Closed] Viewport in separate window
I want to have an aditional viewport in a macro ui, anybody knows if is it possible???
thanks.
Can’t put a fully interactive viewport in a separate window/dialog – the 4/3/2/1 that max allows you to see by default are the ones you’ll have to work with.
If you just want a bitmap of the viewport’s view, see:
http://forums.cgsociety.org/showthread.php?f=98&t=703923
thanks ZeBoxx2, i could solve my problem by the moment. but there is any way to get the bitmap from one of the other viewports, not from active one???
thanks again.
nope – but you could temporary switch to the other viewport using ‘viewport.activeviewport = N’, then grab the bitmap, then switch back
Hi guy,
just made an example on how to capture viewport using .net and I also put some
example on how to use color matrix in maxscript , since there not to many info on this
subject !
I think that it could run faster, if the captured bitmap could stay in memory instead of
writing it to the disk, if you have any idea on how to do this , let me know !
try (VptForm.close()) catch ()
(
dotNet.loadAssembly (getdir #maxroot +"\\MaxCustomControls.dll")
--//--
Global VptForm=(dotnetobject "maxcustomcontrols.maxform")
--//--
Global Vpt_Timer=(dotnetobject "System.Windows.Forms.timer") --//-- Protected
local ExTimer = (dotnetobject "System.Windows.Forms.timer") --//-- Protected
--//--
local PicBox_1=(dotnetobject "system.windows.forms.picturebox") --//-- Protected
local Button_1=(dotnetobject "system.windows.forms.button")
local Dinfo=(dotnetobject "system.windows.forms.label") --//-- Protected
local Group_1 = (dotnetobject "system.windows.forms.groupbox")
local Group_2 = (dotnetobject "system.windows.forms.groupbox")
local Group_3 = (dotnetobject "system.windows.forms.groupbox")
local Rdo_vp1 = (dotnetobject "system.windows.forms.radiobutton")
local Rdo_vp2 = (dotnetobject "system.windows.forms.radiobutton")
local Rdo_vp3 = (dotnetobject "system.windows.forms.radiobutton")
local Rdo_vp4 = (dotnetobject "system.windows.forms.radiobutton")
local TabPanel_1=(dotnetobject "system.windows.forms.tablelayoutpanel")
local TabPanel_2=(dotnetobject "system.windows.forms.tablelayoutpanel")
--//-- init needed class
local Colorclass=(dotnetclass "System.Drawing.Color")
local XUnit=(dotnetclass "System.Drawing.GraphicsUnit").Pixel
local CPer=(dotNetclass "System.Windows.Forms.SizeType").Percent
local CAbs=(dotNetclass "System.Windows.Forms.SizeType").Absolute
local Xout=(dotnetclass "System.Drawing.Imaging.ImageFormat").Bmp
local XPixelOp=(dotnetclass "System.Drawing.CopyPixelOperation").SourceCopy
local Xformat=(dotnetclass "System.Drawing.Imaging.PixelFormat").Format24bppRgb
--//-- init needed value
local Xpath=(getdir #scripts +"\\martroyx_viewport_capture.bmp")
local XAttr=undefined
local YAttr=undefined
local XSize=undefined
local XRect=undefined
local XUpdate=undefined
local GarbageCounter=0
local VptIdx=1
--//--
struct ViewportCap (
--//--
fn SetColorMatrix =
(
XAttr=(dotnetobject "System.Drawing.Imaging.ImageAttributes") --color matrix
YAttr=(dotnetobject "System.Drawing.Imaging.ImageAttributes") --Black&White matrix
--//--
Matrix=(dotnetobject "System.Single[][]" 5 5)
MatrixRow=(dotnetobject "System.Single[]" 5) -->Row1<--Red
MatrixRow.set 0 1.0 -->Identity Matrix
MatrixRow.set 1 0
MatrixRow.set 2 0
MatrixRow.set 3 0
MatrixRow.set 4 0
Matrix.set 0 MatrixRow
MatrixRow=(dotnetobject "System.Single[]" 5) -->Row2<--Green
MatrixRow.set 0 0
MatrixRow.set 1 1.0 -->Identity Matrix
MatrixRow.set 2 0
MatrixRow.set 3 0
MatrixRow.set 4 0
Matrix.set 1 MatrixRow
MatrixRow=(dotnetobject "System.Single[]" 5) -->Row3<--Blue
MatrixRow.set 0 0
MatrixRow.set 1 0
MatrixRow.set 2 1.0 -->Identity Matrix
MatrixRow.set 3 0
MatrixRow.set 4 0
Matrix.set 2 MatrixRow
MatrixRow=(dotnetobject "System.Single[]" 5) -->Row4<--Alpha
MatrixRow.set 0 0
MatrixRow.set 1 0
MatrixRow.set 2 0
MatrixRow.set 3 1.0 -->Identity Matrix
MatrixRow.set 4 0
Matrix.set 3 MatrixRow
MatrixRow=(dotnetobject "System.Single[]" 5) -->Row5<--W
MatrixRow.set 0 0
MatrixRow.set 1 0
MatrixRow.set 2 0
MatrixRow.set 3 0
MatrixRow.set 4 1.0
Matrix.set 4 MatrixRow
--//--
XColorMatrix=(dotnetobject "System.Drawing.Imaging.ColorMatrix" Matrix)
XAttr.SetColorMatrix XColorMatrix
XAttr.SetGamma 1.0
--//--
YAttr.SetOutputChannel (dotnetclass "System.Drawing.Imaging.ColorChannelFlag").ColorChannelK
),
--//--
fn GetShoot Xfile =
(
XTemplate=(dotnetobject "System.Drawing.Bitmap" XSize.w XSize.h Xformat)
XGraphics=(dotnetclass "System.Drawing.Graphics").FromImage XTemplate
XGraphics.CopyFromScreen XSize.x XSize.y 0 0 (dotnetobject "System.Drawing.size" XSize.w XSize.h) XPixelOp
--//--
--//-- Apply the color matrix ... this step is optional
--//-- XAttr:color YAttr:black&white
--//--
--XGraphics.DrawImage XTemplate XRect 0 0 XSize.w XSize.h XUnit YAttr
--//--
XTemplate.save Xfile Xout
--//--
XTemplate.dispose()
XGraphics.dispose()
),
--//--
fn UpdateViewSize =
(
local XVpt=viewport.activeViewport
try (viewport.activeViewport=VptIdx) catch (viewport.activeViewport=1)
local Vpos=(mouse.screenPos-mouse.pos)
local VSize=getViewSize()
viewport.activeViewport=XVpt
XSize=Box2 Vpos.x Vpos.y VSize.x VSize.y
XRect=(dotnetobject "system.drawing.rectangle" 0 0 XSize.w XSize.h)
XUpdate=getViewSize()
Dinfo.text=("Viewport Size : "+(XSize.w as string)+"x"+(XSize.h as string))
),
--//--
fn RegisterCallbacks =
(
callbacks.addScript #viewportChange "(
if not Vpt_Timer.enabled then Vpt_Timer.start()
)" id:#MarTroYx_viewportChange
),
--//--
fn UnRegisterCallbacks =
(
callbacks.removeScripts id:#MarTroYx_viewportChange
)
--//--
)
--//--
fn MainFunction =
(
GarbageCounter+=1
--//--
ViewportCap.GetShoot Xpath
PicBox_1.imagelocation=Xpath
--//--
if GarbageCounter==10 then
(
gc light:true
GarbageCounter=0
)
--//--
)
--//--
--//-- EventHandler
--//--
fn ExTimer_Tick s e =
(
try (MainFunction()) catch (ExTimer.stop())
)
--//--
fn Vpt_Timer_Tick s e =
(
if VptForm.MouseButtons==VptForm.MouseButtons.none and (not isCreatingObject()) then
(
if XUpdate==(getViewSize()) then
(
Vpt_Timer.stop()
)
else
(
ViewportCap.UpdateViewSize()
Vpt_Timer.stop()
)
)
)
--//--
fn VptForm_closed s e =
(
ExTimer.stop()
ExTimer=undefined
Vpt_Timer.stop()
Vpt_Timer=undefined
ViewportCap.UnRegisterCallbacks()
VptForm=undefined
(dotnetclass "system.gc").collect()
gc()
)
--//--
fn Button_1_click s e =
(
if s.forecolor==s.forecolor.black then
(
s.forecolor=s.forecolor.red
ExTimer.start()
)
else
(
s.forecolor=s.forecolor.black
ExTimer.stop()
)
)
--//--
fn RdoVpt_click s e =
(
VptIdx=(s.name as integer)
ViewportCap.UpdateViewSize()
)
--//--
--//-- Interface initialisation
--//--
fn Initdotnet =
(
--//--
--//-- ExTimer
--//--
dotNet.addEventHandler ExTimer "Tick" ExTimer_Tick
ExTimer.tag = dotnetMXSValue ExTimer
--//--
--//-- Vpt_Timer
--//--
Vpt_Timer.interval=100
dotNet.addEventHandler Vpt_Timer "Tick" Vpt_Timer_Tick
Vpt_Timer.tag = dotnetMXSValue Vpt_Timer
--//--
--//-- TabPanel_1
--//--
TabPanel_1.name="TabPanel_1"
TabPanel_1.BackColor=Colorclass.transparent
TabPanel_1.Dock=TabPanel_1.Dock.Fill
TabPanel_1.RowCount = 2
TabPanel_1.ColumnCount = 1
Style=(dotNetobject "System.Windows.Forms.ColumnStyle" CPer 100)
TabPanel_1.ColumnStyles.Add Style
Style=(dotNetobject "System.Windows.Forms.RowStyle" CPer 100)
TabPanel_1.RowStyles.Add Style
Style=(dotNetobject "System.Windows.Forms.RowStyle" CAbs 100)
TabPanel_1.RowStyles.Add Style
--//--
--//-- TabPanel_2
--//--
TabPanel_2.name="TabPanel_2"
TabPanel_2.BackColor=Colorclass.transparent
TabPanel_2.Padding=dotNetobject "System.Windows.Forms.Padding" 0 0 0 0
TabPanel_2.Dock=TabPanel_2.Dock.Fill
TabPanel_2.RowCount = 1
TabPanel_2.ColumnCount = 3
Style=(dotNetobject "System.Windows.Forms.ColumnStyle" CPer 33.333)
TabPanel_2.ColumnStyles.Add Style
Style=(dotNetobject "System.Windows.Forms.ColumnStyle" CPer 33.333)
TabPanel_2.ColumnStyles.Add Style
Style=(dotNetobject "System.Windows.Forms.ColumnStyle" CPer 33.333)
TabPanel_2.ColumnStyles.Add Style
Style=(dotNetobject "System.Windows.Forms.RowStyle" CPer 100)
TabPanel_2.RowStyles.Add Style
--//--
--//-- Group_1
--//--
Group_1.name="Group_1"
Group_1.dock=Group_1.dock.fill
Group_1.Margin = dotNetobject "System.Windows.Forms.Padding" 0 0 0 0
Group_1.Padding = dotNetobject "System.Windows.Forms.Padding" 14 18 14 28
--//--
--//-- Group_2
--//--
Group_2.name="Group_2"
Group_2.dock=Group_2.dock.fill
Group_2.Margin = dotNetobject "System.Windows.Forms.Padding" 0 0 0 0
--//--
--//-- Group_3
--//--
Group_3.name="Group_3"
Group_3.dock=Group_3.dock.fill
Group_3.Margin = dotNetobject "System.Windows.Forms.Padding" 0 0 0 0
--//--
--//-- Button_1
--//--
Button_1.name="Button_1"
Button_1.text="Start"
Button_1.dock=Button_1.dock.fill
Button_1.BackColor=Button_1.BackColor.fromargb 255 128 128 128
Button_1.forecolor=Colorclass.black
Button_1.Font=(dotNetobject "System.Drawing.Font" Button_1.Font.FontFamily 12)
dotNet.addEventHandler Button_1 "click" Button_1_click
Button_1.tag = dotnetMXSValue Button_1
--//--
--//-- Rdo_vp1
--//--
Rdo_vp1.name="1"
Rdo_vp1.FlatStyle=Rdo_vp1.FlatStyle.Flat
Rdo_vp1.Dock=Rdo_vp1.Dock.top
Rdo_vp1.Size=dotNetobject "System.Drawing.Size" 22 14
Rdo_vp1.Text="Viewport 1"
Rdo_vp1.checked=true
dotNet.addEventHandler Rdo_vp1 "click" RdoVpt_click
Rdo_vp1.tag = dotnetMXSValue Rdo_vp1
--//--
--//-- Rdo_vp2
--//--
Rdo_vp2.name="2"
Rdo_vp2.FlatStyle=Rdo_vp2.FlatStyle.Flat
Rdo_vp2.Dock=Rdo_vp2.Dock.top
Rdo_vp2.Size=dotNetobject "System.Drawing.Size" 22 14
Rdo_vp2.Text="Viewport 2"
dotNet.addEventHandler Rdo_vp2 "click" RdoVpt_click
Rdo_vp2.tag = dotnetMXSValue Rdo_vp2
--//--
--//-- Rdo_vp3
--//--
Rdo_vp3.name="3"
Rdo_vp3.FlatStyle=Rdo_vp3.FlatStyle.Flat
Rdo_vp3.Dock=Rdo_vp3.Dock.top
Rdo_vp3.Size=dotNetobject "System.Drawing.Size" 22 14
Rdo_vp3.Text="Viewport 3"
dotNet.addEventHandler Rdo_vp3 "click" RdoVpt_click
Rdo_vp3.tag = dotnetMXSValue Rdo_vp3
--//--
--//-- Rdo_vp4
--//--
Rdo_vp4.name="4"
Rdo_vp4.FlatStyle=Rdo_vp4.FlatStyle.Flat
Rdo_vp4.Dock=Rdo_vp4.Dock.top
Rdo_vp4.Size=dotNetobject "System.Drawing.Size" 22 14
Rdo_vp4.Text="Viewport 4"
dotNet.addEventHandler Rdo_vp4 "click" RdoVpt_click
Rdo_vp4.tag = dotnetMXSValue Rdo_vp4
--//--
--//-- PicBox_1
--//--
PicBox_1.name="PicBox_1"
PicBox_1.Dock=PicBox_1.Dock.Fill
PicBox_1.BorderStyle=PicBox_1.BorderStyle.FixedSingle
PicBox_1.WaitOnLoad=true
PicBox_1.SizeMode=PicBox_1.SizeMode.Zoom
PicBox_1.BackColor=PicBox_1.BackColor.fromargb 255 192 192 192
--//--
--//-- Dinfo
--//--
Dinfo.name="Dinfo"
Dinfo.dock=Dinfo.dock.bottom
Dinfo.backcolor=Colorclass.transparent
Dinfo.forecolor=Colorclass.navy
Dinfo.TextAlign=Dinfo.TextAlign.MiddleCenter
Dinfo.Font=(dotNetobject "System.Drawing.Font" Dinfo.Font.FontFamily 10)
--//--
--//-- VptForm
--//--
VptForm.name="VptForm"
VptForm.text=".Net Viewport Capture by MarTroYx"
VptForm.SizeGripStyle=VptForm.SizeGripStyle.Show
VptForm.ControlBox=true
VptForm.Padding=dotNetobject "System.Windows.Forms.Padding" 8 8 8 8
VptForm.MinimumSize = dotNetobject "System.Drawing.Size" 300 360
VptForm.startposition=VptForm.startposition.centerscreen
VptForm.FormBorderStyle=VptForm.FormBorderStyle.Sizable
VptForm.BackColor=VptForm.BackColor.fromargb 255 220 220 220
VptForm.forecolor=VptForm.forecolor.fromargb 255 0 0 0
VptForm.Size=dotNetobject "System.Drawing.Size" 600 600
VptForm.ShowIcon=true
VptForm.showintaskbar=false
VptForm.topmost=false
dotnet.addeventhandler VptForm "closed" VptForm_closed
--//-- Adding Controls
VptForm.controls.add TabPanel_1
TabPanel_1.controls.add PicBox_1 1 0
TabPanel_1.controls.add TabPanel_2 1 1
--//--
TabPanel_2.controls.add Group_1 0 0
Group_1.controls.add Button_1
--//--
TabPanel_2.controls.add Group_2 1 0
--//--
TabPanel_2.controls.add Group_3 2 0
Group_3.controls.add Rdo_vp4
Group_3.controls.add Rdo_vp3
Group_3.controls.add Rdo_vp2
Group_3.controls.add Rdo_vp1
--//--
PicBox_1.controls.add Dinfo
--//--
--//-- Cleanup
--//--
Button_1=undefined
Group_1=undefined
Group_2=undefined
Group_3=undefined
Rdo_vp1=undefined
Rdo_vp2=undefined
Rdo_vp3=undefined
Rdo_vp4=undefined
TabPanel_1=undefined
TabPanel_2=undefined
--//--
gc light:true
)
--//-- Init sequence
Initdotnet()
VptForm.ShowModeless()
ViewportCap.RegisterCallbacks()
ViewportCap.SetColorMatrix()
Vpt_Timer.start()
--//--
ok
)
Ho, that was easy, the image was already in memory so I just used that instead :shrug:
try to put winamp in front of the capturing viewport, it’s funny
martin
thanks martroyx, this is very usefull, thanks a lot for your help. Now i only have to find out how to interactuate with the scene object from this separate window.
thanks again.
I did a test with sharpgl sometime ago, if you want to interact with object this may be more what you’re looking for
http://www.sharpgl.com/download/index.php
try (NewForm1.close()) catch () ( dotNet.loadAssembly (getdir #maxroot +"MaxCustomControls.dll") dotnet.loadAssembly (getdir #scripts + "\\SharpGL.dll") --//-- Variable Definition Start --//-- (Designer look for this line, Please DO NOT REMOVE) Global NewForm1 = (dotnetobject "maxcustomcontrols.maxform") Global NewCtrl = (dotnetobject "SharpGL.SceneGraph.OpenGLCtrl") local NewForm1_GRP_1 = (dotnetobject "system.windows.forms.groupbox") local NewForm1_BT_1 = (dotnetobject "system.windows.forms.button") local NewForm1_BT_2 = (dotnetobject "system.windows.forms.button") --//-- Variable Definition End --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- Main Function fn NewForm1_closed s e = ( dotnetgc = (dotnetclass "system.gc") NewForm1 = undefined dotnetgc.collect() gc() ) fn NewCtrl_OpenGLDraw s e = ( s.scene.Draw() ) --//-- Controls Initialization Start --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- --//-- NewCtrl --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- NewCtrl.scene.drawextras = true NewCtrl.BorderStyle = NewCtrl.BorderStyle.FixedSingle NewCtrl.Dock = NewCtrl.Dock.Fill NewCtrl.name="NewCtrl" dotnet.addeventhandler NewCtrl "OpenGLDraw" NewCtrl_OpenGLDraw --//-- --//-- NewForm1_GRP_1 --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- NewForm1_GRP_1.Padding = dotNetobject "System.Windows.Forms.Padding" 10 10 10 10 NewForm1_GRP_1.Text = "Parameters" NewForm1_GRP_1.Size = dotNetobject "System.Drawing.Size" 317 70 NewForm1_GRP_1.Dock = NewForm1_GRP_1.Dock.Bottom NewForm1_GRP_1.name = "NewForm1_GRP_1" --//-- --//-- NewForm1_BT_1 --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- NewForm1_BT_1.BackColor = NewForm1_BT_1.BackColor.fromargb 255 220 220 220 NewForm1_BT_1.ForeColor = NewForm1_BT_1.ForeColor.fromargb 255 0 0 128 NewForm1_BT_1.Font = (dotNetobject "System.Drawing.Font" "Microsoft Sans Serif" 12.0 (dotnetclass "System.Drawing.FontStyle").Regular ) NewForm1_BT_1.Text = "Close" NewForm1_BT_1.Size = dotNetobject "System.Drawing.Size" 146 37 NewForm1_BT_1.Dock = NewForm1_BT_1.Dock.Left NewForm1_BT_1.name = "NewForm1_BT_1" --//-- --//-- NewForm1_BT_2 --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- NewForm1_BT_2.Font = (dotNetobject "System.Drawing.Font" "Microsoft Sans Serif" 12.0 (dotnetclass "System.Drawing.FontStyle").Regular ) NewForm1_BT_2.ForeColor = NewForm1_BT_2.ForeColor.fromargb 255 0 0 128 NewForm1_BT_2.BackColor = NewForm1_BT_2.BackColor.fromargb 255 220 220 220 NewForm1_BT_2.Text = "Refresh" NewForm1_BT_2.Size = dotNetobject "System.Drawing.Size" 146 37 NewForm1_BT_2.Dock = NewForm1_BT_2.Dock.Right NewForm1_BT_2.name = "NewForm1_BT_2" --//-- Controls Initialization End --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- Form Initialization Start --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- --//-- NewForm1 --//-- (Designer look for this line, Please DO NOT REMOVE) --//-- NewForm1.Padding = dotNetobject "System.Windows.Forms.Padding" 5 5 5 5 NewForm1.name = "NewForm1" NewForm1.startposition = NewForm1.startposition.centerscreen NewForm1.FormBorderStyle = NewForm1.FormBorderStyle.SizableToolWindow NewForm1.backcolor = NewForm1.backcolor.fromargb 255 220 220 220 NewForm1.forecolor = NewForm1.forecolor.fromargb 255 0 0 0 NewForm1.Size = dotNetobject "System.Drawing.Size" 323 426 NewForm1.Text = "MarTroYx Test OpenGL" NewForm1.ShowIcon = true NewForm1.showintaskbar = false NewForm1.topmost = true --//-- set this to true to ensure the form is on top when in design mode. dotnet.addeventhandler NewForm1 "closed" NewForm1_closed NewForm1.controls.add NewCtrl NewForm1.controls.add NewForm1_GRP_1 NewForm1_GRP_1.controls.add NewForm1_BT_1 NewForm1_GRP_1.controls.add NewForm1_BT_2 --//-- Form Initialization End --//-- (Designer look for this line, Please DO NOT REMOVE) NewForm1.ShowModeless()--//-- open the form --//-- (Designer look for this line, Please DO NOT REMOVE) )
the tricky part is to get the object in , but I think it support 3ds file format so maybe
there’s something to do with this !
Best regard,
martin
thanks Martin, i`ll try it to see if it can help me. thanks for all.