/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ //TODO add HDR and SSAO parameters from the main viewport (add this in option) struct PlugViewport = [ PVP_instance : PInstance, PVP_Camera : SO3_OBJECT, PVP_iObjMode : I, PVP_viewstr : V3Dview, PVP_viewport : V3Dviewport, PVP_iPosX : I, PVP_iPosY : I, PVP_iWidth : I, PVP_iHeight : I, PVP_tPercent : [I I I I], PVP_tAlign : [I I], PVP_bClearColor : I, PVP_bClearDepth : I, PVP_bEnableKeyboard : I, PVP_bEnableMouse : I, PVP_iBgColor : I, PVP_compositor : S, PVP_bIsBuffer : I, PVP_iMonitorIndex : I ]mkPlugViewport;; fun deleteOb(inst, constr)= setPluginInstanceCbResizeView inst nil; let (V3DgetSessionView c3dXsession) -> viewstr in V3DdelViewport viewstr constr.PVP_viewport; if (constr.PVP_viewstr == nil) then nil else V3DdsView constr.PVP_viewstr; set constr.PVP_viewport = nil; 0;; fun cbCreate(inst, from, action, param, reply, constr)= if (constr.PVP_viewport != nil) then nil else ( if (constr.PVP_bIsBuffer) then ( if ((_GETmonitorInfos constr.PVP_iMonitorIndex) == nil) then nil else ( let constr.PVP_tPercent -> [px py pw ph] in let constr.PVP_tAlign -> [ax ay] in let _GETmonitorInfos constr.PVP_iMonitorIndex -> [vx vy vw vh] in let if pw then ftoi (((itof constr.PVP_iWidth) /. 100.0) *. (itof vw)) else constr.PVP_iWidth -> pw in let if ph then ftoi (((itof constr.PVP_iHeight) /. 100.0) *. (itof vh)) else constr.PVP_iHeight -> ph in let if px then ftoi (((itof constr.PVP_iPosX) /. 100.0) *. (itof vw)) else constr.PVP_iPosX -> px in let vx + if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in let if py then ftoi (((itof constr.PVP_iPosY) /. 100.0) *. (itof vh)) else constr.PVP_iPosY -> py in let vy + if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in let V3DcrView _channel nil px py pw ph nil nil 0 -> viewstr in ( set constr.PVP_viewstr = viewstr; set constr.PVP_viewport = V3DaddViewport viewstr 0.0 0.0 1.0 1.0 constr.PVP_iBgColor; V3DsetViewport constr.PVP_viewstr constr.PVP_viewport constr.PVP_Camera; SO3ViewportSetOverlayEnable constr.PVP_viewport.V3D_viewport 0; SO3ViewportSetClearDepth constr.PVP_viewport.V3D_viewport constr.PVP_bClearDepth; SO3ViewportSetClearColor constr.PVP_viewport.V3D_viewport constr.PVP_bClearColor; SO3ViewportSetSkyEnable constr.PVP_viewport.V3D_viewport (!constr.PVP_bClearDepth); SO3ViewportSetVisibilityMaskIndexEnable constr.PVP_viewport.V3D_viewport 11 0; //SO3EnvironmentRegisterViewport (V3DgetSession c3dXsession) constr.PVP_viewport.V3D_viewport; V3DenableKeyboard viewstr 1; V3DenableMouse viewstr 1; V3DsetCbClick viewstr @cbPlugView3dClick; V3DsetCbUnClick viewstr @cbPlugView3dUnClick; V3DsetCbKeyDown viewstr @cbPlugView3dKeyDown; V3DsetCbKeyUp viewstr @cbPlugView3dKeyUp; V3DsetCbPreRender viewstr @cbPlugView3dPreRender; V3DsetCbPostRender viewstr @cbPlugView3dPostRender; V3DsetCbCursorMove viewstr @cbPlugView3dCursorMove; V3DsetCbDbClick viewstr @cbPlugView3dDbClick; V3DsetCbWheel viewstr @cbPlugView3dWheel; V3DsetCbInputClick viewstr @cbPlugView3dInputClick; V3DsetCbInputUnClick viewstr @cbPlugView3dInputUnClick; V3DsetCbInputUpdate viewstr @cbPlugView3dInputUpdate; //V3DsetCbCameraChange viewstr @cbPlugbView3dCameraChange; //V3DsetCbResizeView viewstr @cbPlugView3dResize; V3DsetCbDropFile viewstr @cbPlugView3dDropFile; //V3DsetCbFocusView viewstr @cbPlugView3dFocus; //V3DsetCbKillFocusView viewstr @cbPlugView3dKillFocus; SO3ViewportAddCompositor constr.PVP_viewport.V3D_viewport constr.PVP_compositor ""; V3DenableView viewstr 1; ); ); ) else if constr.PVP_viewport != nil then nil else ( let (V3DgetSessionView c3dXsession) -> viewstr in let constr.PVP_tPercent -> [px py pw ph] in let constr.PVP_tAlign -> [ax ay] in let V3DgetDefaultViewport viewstr -> viewportstr in let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ vw vh] in let if pw then ftoi (((itof constr.PVP_iWidth) /. 100.0) *. (itof vw)) else constr.PVP_iWidth -> pw in let if ph then ftoi (((itof constr.PVP_iHeight) /. 100.0) *. (itof vh)) else constr.PVP_iHeight -> ph in let if px then ftoi (((itof constr.PVP_iPosX) /. 100.0) *. (itof vw)) else constr.PVP_iPosX -> px in let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in let if py then ftoi (((itof constr.PVP_iPosY) /. 100.0) *. (itof vh)) else constr.PVP_iPosY -> py in let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in ( set constr.PVP_viewport = V3DaddViewport viewstr ((itof px) /. (itof vw)) ((itof py) /. (itof vh)) ((itof pw) /. (itof vw)) ((itof ph) /. (itof vh)) constr.PVP_iBgColor; V3DsetViewport viewstr constr.PVP_viewport constr.PVP_Camera; SO3ViewportSetOverlayEnable constr.PVP_viewport.V3D_viewport 0; SO3ViewportSetClearDepth constr.PVP_viewport.V3D_viewport constr.PVP_bClearDepth; SO3ViewportSetClearColor constr.PVP_viewport.V3D_viewport constr.PVP_bClearColor; SO3ViewportSetSkyEnable constr.PVP_viewport.V3D_viewport (!constr.PVP_bClearDepth); SO3ViewportSetVisibilityMaskIndexEnable constr.PVP_viewport.V3D_viewport 11 0; //SO3EnvironmentRegisterViewport (V3DgetSession c3dXsession) constr.PVP_viewport.V3D_viewport; SO3ViewportAddCompositor constr.PVP_viewport.V3D_viewport constr.PVP_compositor ""; ); ); ); 0;; fun cbDestroy(inst, from, action, param, reply, constr)= //SO3EnvironmentUnregisterViewport (V3DgetSession c3dXsession) constr.PVP_viewport.V3D_viewport; let (V3DgetSessionView c3dXsession) -> viewstr in V3DdelViewport viewstr constr.PVP_viewport; if (constr.PVP_viewstr == nil) then nil else ( V3DdsView constr.PVP_viewstr; set constr.PVP_viewstr = nil; ); set constr.PVP_viewport = nil; 0;; fun cbResizeCtrl(inst, viewstr, vw, vh, constr)= if (constr.PVP_viewport == nil) || (viewstr != constr.PVP_viewstr) then nil else ( let (V3DgetSessionView c3dXsession) -> viewstr in let constr.PVP_tPercent -> [px py pw ph] in let constr.PVP_tAlign -> [ax ay] in let if pw then ftoi (((itof constr.PVP_iWidth) /. 100.0) *. (itof vw)) else constr.PVP_iWidth -> pw in let if ph then ftoi (((itof constr.PVP_iHeight) /. 100.0) *. (itof vh)) else constr.PVP_iHeight -> ph in let if px then ftoi (((itof constr.PVP_iPosX) /. 100.0) *. (itof vw)) else constr.PVP_iPosX -> px in let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in let if py then ftoi (((itof constr.PVP_iPosY) /. 100.0) *. (itof vh)) else constr.PVP_iPosY -> py in let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in V3DsetViewportPositionSize constr.PVP_viewport ((itof px) /. (itof vw)) ((itof py) /. (itof vh)) ((itof pw) /. (itof vw)) ((itof ph) /. (itof vh)); ); 0;; fun cbChangeCamera(inst, viewstr, sessionstr, camera, constr)= if ((!constr.PVP_iObjMode) || (camera != V3DgetDefaultCamera c3dXsession)) then nil else ( set constr.PVP_Camera = camera; if (constr.PVP_viewport == nil) then nil else SO3CameraSetViewport constr.PVP_viewport.V3D_viewport constr.PVP_Camera; ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "camera") -> objname in let atoi (getPluginInstanceParam inst "posx") -> posx in let atoi (getPluginInstanceParam inst "posy") -> posy in let atoi (getPluginInstanceParam inst "width") -> width in let atoi (getPluginInstanceParam inst "height") -> height in let atoi (getPluginInstanceParam inst "xpercent") -> xpercent in let atoi (getPluginInstanceParam inst "ypercent") -> ypercent in let atoi (getPluginInstanceParam inst "wpercent") -> wpercent in let atoi (getPluginInstanceParam inst "hpercent") -> hpercent in let atoi (getPluginInstanceParam inst "xalign") -> xalign in let atoi (getPluginInstanceParam inst "yalign") -> yalign in let atoi (getPluginInstanceParam inst "enablekeyboard") -> enablekeyboard in let if enablekeyboard == nil then 1 else enablekeyboard -> enablekeyboard in let atoi (getPluginInstanceParam inst "enablemouse") -> enablemouse in let if enablemouse == nil then 1 else enablekeyboard -> enablemouse in let atoi (getPluginInstanceParam inst "bgcolor") -> bgcolor in let (getPluginInstanceParam inst "compositor") -> compositor in let atoi (getPluginInstanceParam inst "ccolor") -> ccolor in let if ccolor == nil then 1 else ccolor -> ccolor in let atoi (getPluginInstanceParam inst "cdepth") -> cdepth in let if cdepth == nil then 1 else cdepth -> cdepth in let atoi (getPluginInstanceParam inst "init") -> oninit in let atoi (getPluginInstanceParam inst "isbuffer") -> isbuffer in let if isbuffer == nil then 0 else isbuffer -> isbuffer in let atoi (getPluginInstanceParam inst "screenindex") -> screenindex in let if screenindex == nil then 0 else screenindex -> screenindex in let V3DgetObjectByName c3dXsession objname -> obj in let V3DgetObjectTypeByName objname -> objmode in let mkPlugViewport [inst obj objmode nil nil posx posy width height [xpercent ypercent wpercent hpercent] [xalign yalign] ccolor cdepth enablekeyboard enablemouse bgcolor compositor isbuffer screenindex] -> constr in ( if !objmode then nil else setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera constr; if !oninit then nil else cbCreate inst nil nil nil nil constr; setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl constr; PluginRegisterAction inst "Create" mkfun6 @cbCreate constr; PluginRegisterAction inst "Destroy" mkfun6 @cbDestroy constr; setPluginInstanceCbDel inst mkfun2 @deleteOb constr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;