/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ /******************************************************************************* Plugin ARCapture Capture Player permettant de lire des media reconnus par Capture Client part Version: 4.0 Author: Bastien BOURINEAU Date: 21/01/2007 Last update: 02/04/2009 *******************************************************************************/ struct PlugCapture = [ CAP_instance : PInstance, CAP_Device : ObjCapture, CAP_iDeviceIndex : I, CAP_CamParam : ObjArCameraParam, CAP_tCamSize : [I I], CAP_tLastCamSize : [I I], CAP_tLastCamSizeCheck : [I I], CAP_bAutoSize : I, CAP_iMatrixMode : I, CAP_lastCamera : SO3_OBJECT, CAP_bOnMaterial : I, CAP_Material : SO3_MATERIAL, CAP_iTechnique : I, CAP_iPass : I, CAP_iTexture : I, CAP_win : SO3_WIDGET, CAP_iPosX : I, CAP_iPosY : I, CAP_iWidth : I, CAP_iHeight : I, CAP_tPercent : [I I I I I I I I], CAP_tAlign : [I I], CAP_iOpacity : I, CAP_sYmlFile : S, CAP_bMirror : I, CAP_bArDebug : I, CAP_bBackground : I, CAP_bShow : I, CAP_bAdjustMatrix : I, CAP_bUpdateNext : I, CAP_bTouchFocus : I, CAP_bTorch : I, CAP_gyroCb : ObjSensorCB, CAP_accelCb : ObjSensorCB, CAP_tImuState : [[F F F] [F F F]] ] MkPlugCapture;; fun computePosSize(capstr, vw, vh)= let capstr.CAP_tPercent -> [px py pw ph xo yo wo ho] in let capstr.CAP_tAlign -> [ax ay] in let if pw then (ftoi (((itof capstr.CAP_iWidth) /. 100.0) *. (itof vw))) + wo else capstr.CAP_iWidth -> pw in let if ph then (ftoi (((itof capstr.CAP_iHeight) /. 100.0) *. (itof vh))) + ho else capstr.CAP_iHeight -> ph in let if px then (ftoi (((itof capstr.CAP_iPosX) /. 100.0) *. (itof vw))) + xo else capstr.CAP_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 capstr.CAP_iPosY) /. 100.0) *. (itof vh))) + yo else capstr.CAP_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 [px py pw ph];; fun scaleProjectionMatrix(m, scale)= let scale -> [sx sy] in let m -> [[m0 m1 m2 m3] [m4 m5 m6 m7] v3 v4] in [[m0 *. sx m1 *. sx m2 m3] [m4 m5 *. sy m6 *. sx m7] v3 v4];; fun updateViewSize(capstr, force)= let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let [1.0 1.0] -> bscale in ( if (camera == capstr.CAP_lastCamera) then nil else ( //reset camera matrix if (capstr.CAP_lastCamera == nil) then nil else SO3CameraSetProjectionMatrix capstr.CAP_lastCamera nil; set capstr.CAP_lastCamera = camera; set force = 1; ); //TODO set CAP_CamParam clipping if (!force) then nil else ( let computePosSize capstr vw vh -> [px py pw ph] in let capstr.CAP_tLastCamSize -> [cw ch] in if (cw == nil || cw == 0 || ch == nil || ch == 0) then nil else let (itof cw) /. (itof ch) -> camratio in let (itof pw) /. (itof ph) -> bgratio in if (camratio == bgratio) then nil else ( let if (bgratio <. camratio) then [ftoi ((itof ph) *. camratio) ph] else [pw ftoi ((itof pw) /. camratio)] -> [npw nph] in let [(px - ((npw - pw) / 2)) (py - ((nph - ph) / 2))] -> [px py] in ( SO3WidgetSetPosition capstr.CAP_win px py; SO3WidgetSetSize capstr.CAP_win npw nph; set bscale = [((itof npw) /. (itof pw)) ((itof nph) /. (itof ph))]; ); ); let scaleProjectionMatrix (_GETarProjectionMatrix capstr.CAP_CamParam vw vh) bscale -> cmat in SO3CameraSetProjectionMatrix capstr.CAP_lastCamera cmat; ); ); 0;; fun cbRenderCapture(inst, sessionstr, etime, capstr) = let _GETcaptureBufferExt capstr.CAP_Device -> [buff bw bh bc] in if (buff == nil) then nil else ( _SETcameraSensorsQuat capstr.CAP_CamParam _GetDeviceQuaternionOrientation (etime / 1000); _UPDATEarMarkersBuff buff bw bh bc capstr.CAP_CamParam capstr.CAP_bMirror capstr.CAP_bArDebug; if ((capstr.CAP_bShow && capstr.CAP_bAdjustMatrix && (capstr.CAP_iMatrixMode == 0)) || (capstr.CAP_iMatrixMode == 1)) then updateViewSize capstr 0 else nil; if (!capstr.CAP_bShow) then nil else ( if (capstr.CAP_bMirror != 1) then nil else _BTFLIPbuffer buff bw bh bc; SO3BitmapWidgetBlitBuffer capstr.CAP_win buff bw bh bc; ); ); 0;; fun restoreTexture(capstr)= if (capstr.CAP_Device == nil) then nil else ( V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) capstr.CAP_win; SO3WidgetDestroy capstr.CAP_win; set capstr.CAP_win = nil; ); 0;; fun cbShow(inst, from, action, param, reply, capstr)= SO3WidgetSetVisibility capstr.CAP_win 1; set capstr.CAP_bShow = 1; if (((capstr.CAP_bAdjustMatrix) && (capstr.CAP_iMatrixMode == 0)) || (capstr.CAP_iMatrixMode == 1)) then updateViewSize capstr 1 else nil; 0;; fun cbHide(inst, from, action, param, reply, capstr)= SO3WidgetSetVisibility capstr.CAP_win 0; //reset camera matrix if (capstr.CAP_iMatrixMode != 0) then nil else SO3CameraSetProjectionMatrix capstr.CAP_lastCamera nil; set capstr.CAP_bShow = 0; 0;; fun updateCameraSize(capstr, pw, ph)= //addLogMessage strcatn "ARCapture update camera size: "::(itoa pw)::"x"::(itoa ph)::nil; let capstr.CAP_tLastCamSizeCheck -> [ow oh] in let capstr.CAP_tCamSize -> [camw camh] in let if (!capstr.CAP_bAutoSize) then [camw camh] else if (((pw >= ph) && (pw > camw)) || ((ph > pw) && (ph > camw))) then if ((max camw camh) >= 1920) then if (pw >= ph) then [pw ph] else [ph pw] else if ((max camw camh) >= 1280) then if (pw >= ph) then [(ftoi ((itof pw) /. 1.25)) (ftoi ((itof ph) /. 1.25))] else [(ftoi ((itof ph) /. 1.25)) (ftoi ((itof pw) /. 1.25))] else if ((max camw camh) >= 640) then if (pw >= ph) then [(ftoi ((itof pw) /. 1.25)) (ftoi ((itof ph) /. 1.25))] else [(ftoi ((itof ph) /. 1.25)) (ftoi ((itof pw) /. 1.25))] else if (pw >= ph) then [(ftoi ((itof pw) /. 1.5)) (ftoi ((itof ph) /. 1.5))] else [(ftoi ((itof ph) /. 1.5)) (ftoi ((itof pw) /. 1.5))] else [pw ph] -> [ncw nch] in if ((ow == ncw) && (oh == nch)) then nil else ( addLogMessage strcatn "Try cam size: "::(itoa ncw)::"x"::(itoa nch)::nil; set capstr.CAP_tLastCamSizeCheck = [ncw nch]; _SETcaptureSize capstr.CAP_Device ncw nch; let capstr.CAP_tLastCamSize -> [ocw och] in let _GETcaptureSize capstr.CAP_Device -> [cw ch] in if ((ocw == ncw) && (och == ch)) then nil else ( addLogMessage strcatn "Get cam size: "::(itoa cw)::"x"::(itoa ch)::nil; set capstr.CAP_tLastCamSize = [cw ch]; if (capstr.CAP_CamParam == nil) then nil else _DSarCameraParam capstr.CAP_CamParam; let V3DgetDefaultViewport (V3DgetSessionView c3dXsession) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3CameraGetNearClipDistance camera -> nclip in let SO3CameraGetFarClipDistance camera -> fclip in ( if (capstr.CAP_lastCamera == nil) then nil else ( //reset camera matrix SO3CameraSetProjectionMatrix capstr.CAP_lastCamera nil; set capstr.CAP_lastCamera = nil; ); set capstr.CAP_CamParam = _CRarCameraParam _channel cw ch nclip fclip _checkpack capstr.CAP_sYmlFile; ); ); ); 0;; fun cbResizeCtrl(inst, viewstr, ww, wh, capstr)= let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in ( if capstr.CAP_win == nil then nil else ( if capstr.CAP_bOnMaterial then nil else let computePosSize capstr vw vh -> [px py pw ph] in let if (capstr.CAP_bOnMaterial) then [capstr.CAP_iWidth capstr.CAP_iHeight] else [pw ph] -> [cw ch] in ( updateCameraSize capstr cw ch; SO3WidgetSetPosition capstr.CAP_win px py; SO3WidgetSetSize capstr.CAP_win pw ph; ); //update camera setting on current camera change if ((capstr.CAP_bShow && capstr.CAP_bAdjustMatrix && (capstr.CAP_iMatrixMode == 0)) || (capstr.CAP_iMatrixMode == 1)) then updateViewSize capstr 1 else nil; ); ); 0;; fun cbSetPosition(inst, from, action, param, reply, capstr)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in ( let 0 -> xpercent in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ( set xpercent = 1; atoi sx; ) else atoi sx -> px in let 0 -> ypercent in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ( set ypercent = 1; atoi sy; ) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in ( mutate capstr.CAP_tPercent <- [xpercent ypercent _ _ _ _ _ _]; set capstr.CAP_iPosX = px; set capstr.CAP_iPosY = py; let computePosSize capstr vw vh -> [px py pw ph] in let if (capstr.CAP_bOnMaterial) then [capstr.CAP_iWidth capstr.CAP_iHeight] else [pw ph] -> [cw ch] in ( updateCameraSize capstr cw ch; SO3WidgetSetPosition capstr.CAP_win px py; SO3WidgetSetSize capstr.CAP_win pw ph; ); ); ); 0;; fun cbSetSize(inst, from, action, param, reply, capstr)= if param == nil then nil else ( let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in ( let 0 -> wpercent in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ( set wpercent = 1; atoi sx; ) else atoi sx -> px in let 0 -> hpercent in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ( set hpercent = 1; atoi sy; ) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in ( mutate capstr.CAP_tPercent <- [_ _ wpercent hpercent _ _ _ _]; set capstr.CAP_iWidth = px; set capstr.CAP_iHeight = py; let computePosSize capstr vw vh -> [px py pw ph] in let if (capstr.CAP_bOnMaterial) then [capstr.CAP_iWidth capstr.CAP_iHeight] else [pw ph] -> [cw ch] in ( updateCameraSize capstr cw ch; SO3WidgetSetPosition capstr.CAP_win px py; SO3WidgetSetSize capstr.CAP_win pw ph; ); ); ); ); 0;; fun getVideoSize(inst, from, action, param, rep, capstr)= let _GETcaptureSize capstr.CAP_Device -> [w h] in SendPluginEvent inst "Video size" strcatn (itoa w)::" "::(itoa h)::nil nil; 0;; fun cbClick(inst, viewstr, id, x, y, btn, pdata, capstr)= if (btn != 1) || (id != 0) then nil else let let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let (itof viewstr.V3D_iWinW) /. (itof vw) -> wr in let (itof viewstr.V3D_iWinH) /. (itof vh) -> hr in let ftoi (if capstr.CAP_bMirror then (wr *. (itof (viewstr.V3D_iWinW - x))) else (wr *. (itof x))) -> x in let ftoi (hr *. (itof y)) -> y in [x y] -> [posx posy] in _SETcaptureFocusPoint capstr.CAP_Device posx posy; 0;; fun cbAccelData(sensorCb, capstr, vec, val, delta)= let capstr.CAP_tImuState -> [gyro _] in if (gyro != nil) then ( _AddcameraSensorsImu capstr.CAP_CamParam gyro vec delta; //addLogMessageVector3F "Gyro " gyro; //addLogMessageVector3F "Accel " vec; mutate capstr.CAP_tImuState <- [nil nil]; ) else ( mutate capstr.CAP_tImuState <- [_ vec]; ); 0;; fun cbGyroData(sensorCb, capstr, vec, val, delta)= let capstr.CAP_tImuState -> [_ accel] in if (accel != nil) then ( _AddcameraSensorsImu capstr.CAP_CamParam vec accel delta; //addLogMessageVector3F "Gyro " vec; //addLogMessageVector3F "Accel " accel; mutate capstr.CAP_tImuState <- [nil nil]; ) else ( mutate capstr.CAP_tImuState <- [vec _]; ); 0;; fun connectCapture(inst, from, action, param, rep, capstr)= if (capstr.CAP_Device != nil) then nil else let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let if (capstr.CAP_bOnMaterial) then [0 0 capstr.CAP_iWidth capstr.CAP_iHeight] else computePosSize capstr vw vh -> [px py pw ph] in ( if !(_IsSensorAvailable SENSOR_TYPE_ORIENTATION) then nil else _SetSensorEnable SENSOR_TYPE_ORIENTATION 1; //if (!(_IsSensorAvailable SENSOR_TYPE_ACCELEROMETER) || !(_IsSensorAvailable SENSOR_TYPE_GYROSCOPE)) then nil else //( // _SetSensorEnable SENSOR_TYPE_ACCELEROMETER 1; // _SetSensorEnable SENSOR_TYPE_GYROSCOPE 1; // set capstr.CAP_accelCb = _CrSensorCallBack _channel SENSOR_TYPE_ACCELEROMETER @cbAccelData capstr; // set capstr.CAP_gyroCb = _CrSensorCallBack _channel SENSOR_TYPE_GYROSCOPE @cbGyroData capstr; //); set capstr.CAP_Device = _CRcapture _channel capstr.CAP_iDeviceIndex; // try to find one let 0 -> i in while capstr.CAP_Device == nil && (i < 8) do ( set capstr.CAP_Device = _CRcapture _channel i; set capstr.CAP_iDeviceIndex = i; set i = i + 1; ); if (capstr.CAP_Device == nil) then nil else ( //set the camera size, if this is not support it switch to the default size let capstr.CAP_tCamSize -> [camw camh] in let if (!capstr.CAP_bAutoSize) then [camw camh] else if (((pw >= ph) && (pw > camw)) || ((ph > pw) && (ph > camw))) then if ((max camw camh) >= 1920) then if (pw >= ph) then [pw ph] else [ph pw] else if ((max camw camh) >= 1280) then if (pw >= ph) then [(ftoi ((itof pw) /. 1.25)) (ftoi ((itof ph) /. 1.25))] else [(ftoi ((itof ph) /. 1.25)) (ftoi ((itof pw) /. 1.25))] else if ((max camw camh) >= 640) then if (pw >= ph) then [(ftoi ((itof pw) /. 1.25)) (ftoi ((itof ph) /. 1.25))] else [(ftoi ((itof ph) /. 1.25)) (ftoi ((itof pw) /. 1.25))] else if (pw >= ph) then [(ftoi ((itof pw) /. 1.5)) (ftoi ((itof ph) /. 1.5))] else [(ftoi ((itof ph) /. 1.5)) (ftoi ((itof pw) /. 1.5))] else [pw ph] -> [ncw nch] in ( set capstr.CAP_tLastCamSizeCheck = [ncw nch]; addLogMessage strcatn "Try cam size: "::(itoa ncw)::"x"::(itoa nch)::nil; _SETcaptureSize capstr.CAP_Device ncw nch; ); _SETcaptureMirror capstr.CAP_Device capstr.CAP_bMirror; _SETcaptureTorchState capstr.CAP_Device capstr.CAP_bTorch; if (capstr.CAP_Device == nil) then nil else let _GETcaptureSize capstr.CAP_Device -> [cw ch] in ( addLogMessage strcatn "Get cam size: "::(itoa cw)::"x"::(itoa ch)::nil; set capstr.CAP_tLastCamSize = [cw ch]; // change the global variable set c3dxCameraSize = [cw ch]; set c3dxCameraFlip = capstr.CAP_bMirror; let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3CameraGetNearClipDistance camera -> nclip in let SO3CameraGetFarClipDistance camera -> fclip in set capstr.CAP_CamParam = _CRarCameraParam _channel cw ch nclip fclip _checkpack capstr.CAP_sYmlFile; if capstr.CAP_win != nil then nil else ( V3DremoveWidgetControl viewportstr capstr.CAP_win; SO3WidgetDestroy capstr.CAP_win; if capstr.CAP_bOnMaterial then ( set capstr.CAP_win = SO3BitmapWidgetCreateOnMaterial (V3DgetSession c3dXsession) capstr.CAP_Material (strcat (getPluginInstanceName inst) "_ARcaptureCtrl") capstr.CAP_iWidth capstr.CAP_iHeight capstr.CAP_iTechnique capstr.CAP_iPass capstr.CAP_iTexture; 0; ) else if capstr.CAP_bBackground then ( if (!pw || !ph || (capstr.CAP_iWidth != 100) || (capstr.CAP_iWidth != 100)) then nil else set capstr.CAP_bAdjustMatrix = 1; set capstr.CAP_win = SO3BitmapWidgetCreateBackground (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_ARcaptureCtrl") px py pw ph; 0; ) else ( set capstr.CAP_win = SO3BitmapWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_ARcaptureCtrl") px py pw ph 100; SO3WidgetSetTopOnFocus capstr.CAP_win 0; SO3WidgetSetForeground capstr.CAP_win 1; 0; ); V3DaddWidgetControl viewportstr capstr.CAP_win; SO3WidgetSetKeyboardEnable capstr.CAP_win 0; SO3WidgetSetMouseEnable capstr.CAP_win 0; SO3WidgetSetOpacity capstr.CAP_win (itof capstr.CAP_iOpacity) *. 0.01; ); if (capstr.CAP_iMatrixMode == 1) then ( set capstr.CAP_bAdjustMatrix = 1; ) else if (capstr.CAP_iMatrixMode == 2) then ( set capstr.CAP_bAdjustMatrix = 0; ) else nil; setPluginInstanceCbScenePostRender inst mkfun4 @cbRenderCapture capstr; if (!capstr.CAP_bTouchFocus) then nil else setPluginInstanceCbInputClick inst mkfun8 @cbClick capstr; getVideoSize inst nil nil nil nil capstr; SendPluginEvent inst "Connected" (itoa capstr.CAP_iDeviceIndex) nil; ); ); ); 0;; fun disconnectCapture(inst, from, action, param, rep, capstr)= //_DsSensorCallBack capstr.CAP_accelCb; //_DsSensorCallBack capstr.CAP_gyroCb; if !(_IsSensorAvailable SENSOR_TYPE_ORIENTATION) then nil else _SetSensorEnable SENSOR_TYPE_ORIENTATION 0; //if (!(_IsSensorAvailable SENSOR_TYPE_ACCELEROMETER) || !(_IsSensorAvailable SENSOR_TYPE_GYROSCOPE)) then nil else //( // _SetSensorEnable SENSOR_TYPE_ACCELEROMETER 0; // _SetSensorEnable SENSOR_TYPE_GYROSCOPE 0; //); setPluginInstanceCbInputClick inst nil; setPluginInstanceCbScenePostRender inst nil; restoreTexture capstr; if (capstr.CAP_Device == nil) then nil else ( _DScapture capstr.CAP_Device; set capstr.CAP_Device = nil; _DSarCameraParam capstr.CAP_CamParam; set capstr.CAP_CamParam = nil; //reset camera matrix SO3CameraSetProjectionMatrix capstr.CAP_lastCamera nil; set capstr.CAP_lastCamera = nil; SendPluginEvent inst "Disconnected" (itoa capstr.CAP_iDeviceIndex) nil; ); 0;; fun cbDeviceList(inst, from, action, param, rep, capstr)= SendPluginEvent inst "Devices list" strcatnSep _GETcaptureDeviceList "\n" nil; 0;; fun cbSetActiveDevice(inst, from, action, param, rep, capstr)= if ((atoi param) == nil) then nil else ( set capstr.CAP_iDeviceIndex = (atoi param); if (capstr.CAP_Device == nil) then nil else ( disconnectCapture inst nil nil nil nil capstr; connectCapture inst nil nil nil nil capstr; ); ); 0;; fun cbSetMirror(inst, from, action, param, rep, capstr)= set capstr.CAP_bMirror = if (atoi param) >= 1 then 1 else 0; _SETcaptureMirror capstr.CAP_Device capstr.CAP_bMirror; set c3dxCameraFlip = capstr.CAP_bMirror; 0;; fun setVideoSize(inst, from, action, param, rep, capstr)= if param == nil then nil else ( let strextr param -> lp in let atoi (nth_list (hd lp) 0) -> sx in let atoi (nth_list (hd lp) 1) -> sy in set capstr.CAP_tCamSize = [sx sy]; //reconnect if (capstr.CAP_Device == nil) then nil else ( let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let if (capstr.CAP_bOnMaterial) then [0 0 capstr.CAP_iWidth capstr.CAP_iHeight] else computePosSize capstr vw vh -> [px py pw ph] in updateCameraSize capstr pw ph; ); ); 0;; fun cbSetTorchOn(inst, from, action, param, rep, capstr)= _SETcaptureTorchState capstr.CAP_Device 1; 0;; fun cbSetTorchOff(inst, from, action, param, rep, capstr)= _SETcaptureTorchState capstr.CAP_Device 0; 0;; // Destroy instance fun deleteOb(inst, capstr)= disconnectCapture inst nil nil nil nil capstr; SendPluginEvent inst "Disconnected" nil nil; 0;; fun cbNewOb(inst)= let atoi (getPluginInstanceParam inst "istexture") -> istexture in let if istexture == nil then 0 else istexture -> istexture in let (getPluginInstanceParam inst "object") -> objname in let (getPluginInstanceParam inst "material") -> matname in let atoi (getPluginInstanceParam inst "technique") -> technique in let if technique == nil then 0 else technique -> technique in let atoi (getPluginInstanceParam inst "pass") -> pass in let if pass == nil then 0 else pass -> pass in let atoi (getPluginInstanceParam inst "texture") -> texture in let if texture == nil then 0 else texture -> texture 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 "xoffset") -> xoffset in let if xoffset == nil then 0 else xoffset -> xoffset in let atoi (getPluginInstanceParam inst "yoffset") -> yoffset in let if yoffset == nil then 0 else yoffset -> yoffset in let atoi (getPluginInstanceParam inst "woffset") -> woffset in let if woffset == nil then 0 else woffset -> woffset in let atoi (getPluginInstanceParam inst "hoffset") -> hoffset in let if hoffset == nil then 0 else hoffset -> hoffset in let atoi (getPluginInstanceParam inst "xalign") -> xalign in let atoi (getPluginInstanceParam inst "yalign") -> yalign in let atoi (getPluginInstanceParam inst "background") -> background in let if (background == nil) then 0 else background -> background in let atoi (getPluginInstanceParam inst "opacity") -> opacity in let if opacity == nil then 100 else opacity -> opacity in let (getPluginInstanceParam inst "ymlfile") -> ymlfile in let if ymlfile == nil then nil else ymlfile -> ymlfile in let atoi (getPluginInstanceParam inst "camindex") -> camindex in let if camindex == nil then (atoi _getress "videocapture") else camindex -> camindex in let atoi (getPluginInstanceParam inst "mirror") -> mirror in let if (mirror == nil) then 0 else mirror -> mirror in let atoi (getPluginInstanceParam inst "camsize") -> icamsize in let if (icamsize == 0) then [320 240] else if (icamsize == 1) then [640 480] else if (icamsize == 2) then [1280 720] else if (icamsize == 3) then [1920 1080] else [640 480] -> camsize in let atoi (getPluginInstanceParam inst "autosize") -> autosize in let if (autosize == nil) then 1 else autosize -> autosize in let atoi (getPluginInstanceParam inst "ardebug") -> ardebug in let if (ardebug == nil) then 0 else ardebug -> ardebug in let atoi (getPluginInstanceParam inst "init") -> init in let if (init == nil) then 1 else init -> init in let atoi (getPluginInstanceParam inst "show") -> show in let if (show == nil) then 1 else show -> show in let atoi (getPluginInstanceParam inst "touchfocus") -> touchfocus in let if (touchfocus == nil) then 1 else touchfocus -> touchfocus in let atoi (getPluginInstanceParam inst "torch") -> torch in let if (torch == nil) then 0 else torch -> torch in let atoi (getPluginInstanceParam inst "matrixmode") -> matrixmode in let if (matrixmode == nil) then 0 else matrixmode -> matrixmode in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let if !istexture then nil else SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in let MkPlugCapture [inst nil camindex nil camsize nil nil autosize matrixmode nil istexture mat technique pass texture nil posx posy width height [xpercent ypercent wpercent hpercent xoffset yoffset woffset hoffset] [xalign yalign] opacity ymlfile mirror ardebug background 1 0 0 touchfocus torch nil nil [nil nil]] -> capstr in ( if capstr.CAP_bOnMaterial then nil else setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl capstr; if !init then nil else connectCapture inst nil nil nil nil capstr; if show then ( SO3WidgetSetVisibility capstr.CAP_win 1; set capstr.CAP_bShow = 1; ) else ( SO3WidgetSetVisibility capstr.CAP_win 0; set capstr.CAP_bShow = 0; ); PluginRegisterAction inst "Connect" mkfun6 @connectCapture capstr; PluginRegisterAction inst "Disconnect" mkfun6 @disconnectCapture capstr; PluginRegisterAction inst "Show" mkfun6 @cbShow capstr; PluginRegisterAction inst "Hide" mkfun6 @cbHide capstr; PluginRegisterAction inst "Set position" mkfun6 @cbSetPosition capstr; PluginRegisterAction inst "Set size" mkfun6 @cbSetSize capstr; PluginRegisterAction inst "Get devices list" mkfun6 @cbDeviceList capstr; PluginRegisterAction inst "Set active device" mkfun6 @cbSetActiveDevice capstr; PluginRegisterAction inst "Get video size" mkfun6 @getVideoSize capstr; PluginRegisterAction inst "Set mirror mode" mkfun6 @cbSetMirror capstr; PluginRegisterAction inst "Set video size" mkfun6 @setVideoSize capstr; PluginRegisterAction inst "Set torch on" mkfun6 @cbSetTorchOn capstr; PluginRegisterAction inst "Set torch off" mkfun6 @cbSetTorchOff capstr; setPluginInstanceCbDel inst mkfun2 @deleteOb capstr; ); 0;; fun IniPlug(file) = PlugRegister @cbNewOb nil; setPluginEditor @dynamicedit; 0;;