/* ----------------------------------------------------------------------------- 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 Stereo Capture Player Client part Version: 1.0 Author: Bastien BOURINEAU Date: 03/02/2021 Last update: 03/02/2021 *******************************************************************************/ struct PlugCaptureStereo = [ SCAP_instance : PInstance, SCAP_DeviceMode : I, SCAP_DeviceLeft : ObjCapture, SCAP_DeviceRight : ObjCapture, SCAP_iLeftDeviceIndex : I, SCAP_lCamIntrinsics : [I [F F] [F F]], SCAP_iRightDeviceIndex : I, SCAP_rCamIntrinsics : [I [F F] [F F]], SCAP_CamParam : ObjArCameraParam, SCAP_tCamSize : [I I], SCAP_tLastCamSize : [I I], SCAP_tLastCamSizeCheck : [I I], SCAP_bAutoSize : I, SCAP_bitmapBuffer : ObjBitmap, SCAP_bitmapDetectBuffer : ObjBitmap, SCAP_fIpd : F, SCAP_iMatrixMode : I, SCAP_lastCamera : SO3_OBJECT, SCAP_bOnMaterial : I, SCAP_Material : SO3_MATERIAL, SCAP_iTechnique : I, SCAP_iPass : I, SCAP_iTexture : I, SCAP_win : SO3_WIDGET, SCAP_iPosX : I, SCAP_iPosY : I, SCAP_iWidth : I, SCAP_iHeight : I, SCAP_tPercent : [I I I I I I I I], SCAP_tAlign : [I I], SCAP_iOpacity : I, SCAP_bArDebug : I, SCAP_bBackground : I, SCAP_bShow : I, SCAP_bAdjustMatrix : I, SCAP_bUpdateNext : I, SCAP_bTouchFocus : I, SCAP_bTorch : I, SCAP_gyroCb : ObjSensorCB, SCAP_accelCb : ObjSensorCB, SCAP_tImuState : [[F F F] [F F F]] ] MkPlugCaptureStereo;; fun computePosSize(capstr, vw, vh)= let capstr.SCAP_tPercent -> [px py pw ph xo yo wo ho] in let capstr.SCAP_tAlign -> [ax ay] in let if pw then (ftoi (((itof capstr.SCAP_iWidth) /. 100.0) *. (itof vw))) + wo else capstr.SCAP_iWidth -> pw in let if ph then (ftoi (((itof capstr.SCAP_iHeight) /. 100.0) *. (itof vh))) + ho else capstr.SCAP_iHeight -> ph in let if px then (ftoi (((itof capstr.SCAP_iPosX) /. 100.0) *. (itof vw))) + xo else capstr.SCAP_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.SCAP_iPosY) /. 100.0) *. (itof vh))) + yo else capstr.SCAP_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.SCAP_lastCamera) then nil else ( //reset camera matrix if (capstr.SCAP_lastCamera == nil) then nil else SO3CameraSetProjectionMatrix capstr.SCAP_lastCamera nil; set capstr.SCAP_lastCamera = camera; set force = 1; ); //TODO set SCAP_CamParam clipping if (!force) then nil else ( let computePosSize capstr vw vh -> [px py pw ph] in let capstr.SCAP_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.SCAP_win px py; SO3WidgetSetSize capstr.SCAP_win npw nph; set bscale = [((itof npw) /. (itof pw)) ((itof nph) /. (itof ph))]; ); ); let scaleProjectionMatrix (_GETarProjectionMatrix capstr.SCAP_CamParam vw vh) bscale -> cmat in SO3CameraSetProjectionMatrix capstr.SCAP_lastCamera cmat; ); ); 0;; fun cbRenderCapture(inst, sessionstr, etime, capstr) = if ((capstr.SCAP_DeviceMode > 0) || (capstr.SCAP_bitmapBuffer != nil)) then nil else ( let capstr.SCAP_tLastCamSize -> [cw ch] in set capstr.SCAP_bitmapBuffer = (_FILLbitmap _CRbitmap _channel (cw * 2) ch 0xff0000); ); if (capstr.SCAP_DeviceMode > 0) then ( let _GETcaptureBufferExt capstr.SCAP_DeviceLeft -> [lbuff lbw lbh lbc] in if (lbuff == nil) then nil else ( if (capstr.SCAP_bitmapDetectBuffer != nil) then nil else ( let capstr.SCAP_tLastCamSize -> [cw ch] in set capstr.SCAP_bitmapDetectBuffer = (_FILLbitmap _CRbitmap _channel cw ch 0); ); _SETcameraSensorsQuat capstr.SCAP_CamParam _GetDeviceQuaternionOrientation (etime / 1000); let _GETbitmapSize capstr.SCAP_bitmapDetectBuffer -> [bw bh] in let _BTGETbitmapBuffer capstr.SCAP_bitmapDetectBuffer -> buff in let if (capstr.SCAP_DeviceMode == 1) then [0 0 lbw/2 lbh] else if (capstr.SCAP_DeviceMode == 2) then [0 0 lbw (lbh / 2)] else [0 (lbh / 2) lbw (lbh / 2)] -> cprect in ( _BTCPbitmapBufferRect buff bw bh 3 [0 0 bw bh] lbuff lbw lbh lbc cprect; _UPDATEarMarkersBuff buff bw bh 3 capstr.SCAP_CamParam 0 capstr.SCAP_bArDebug; ); if ((capstr.SCAP_bShow && capstr.SCAP_bAdjustMatrix && (capstr.SCAP_iMatrixMode == 0)) || (capstr.SCAP_iMatrixMode == 1)) then updateViewSize capstr 0 else nil; if (!capstr.SCAP_bShow) then nil else ( SO3BitmapWidgetBlitBuffer capstr.SCAP_win lbuff lbw lbh lbc; ); ); ) else ( let _GETbitmapSize capstr.SCAP_bitmapBuffer -> [bw bh] in let _BTGETbitmapBuffer capstr.SCAP_bitmapBuffer -> buff in ( let _GETcaptureBufferExt capstr.SCAP_DeviceLeft -> [lbuff lbw lbh lbc] in if (lbuff == nil) then nil else ( _SETcameraSensorsQuat capstr.SCAP_CamParam _GetDeviceQuaternionOrientation (etime / 1000); _UPDATEarMarkersBuff lbuff lbw lbh lbc capstr.SCAP_CamParam 0 capstr.SCAP_bArDebug; if ((capstr.SCAP_bShow && capstr.SCAP_bAdjustMatrix && (capstr.SCAP_iMatrixMode == 0)) || (capstr.SCAP_iMatrixMode == 1)) then updateViewSize capstr 0 else nil; if (!capstr.SCAP_bShow) then nil else _BTCPbitmapBufferRect buff bw bh 3 [0 0 (bw / 2) bh] lbuff lbw lbh lbc [0 0 lbw lbh]; ); let _GETcaptureBufferExt capstr.SCAP_DeviceRight -> [rbuff rbw rbh rbc] in if ((!capstr.SCAP_bShow) || (rbuff == nil)) then nil else _BTCPbitmapBufferRect buff bw bh 3 [((bw / 2) - 1) 0 (bw / 2) bh] rbuff rbw rbh rbc [0 0 rbw rbh]; if (!capstr.SCAP_bShow) then nil else SO3BitmapWidgetBlitBuffer capstr.SCAP_win buff bw bh 3; ); ); 0;; fun restoreTexture(capstr)= if (capstr.SCAP_DeviceLeft == nil) then nil else ( V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) capstr.SCAP_win; SO3WidgetDestroy capstr.SCAP_win; set capstr.SCAP_win = nil; ); 0;; fun cbShow(inst, from, action, param, reply, capstr)= SO3WidgetSetVisibility capstr.SCAP_win 1; set capstr.SCAP_bShow = 1; if (((capstr.SCAP_bAdjustMatrix) && (capstr.SCAP_iMatrixMode == 0)) || (capstr.SCAP_iMatrixMode == 1)) then updateViewSize capstr 1 else nil; 0;; fun cbHide(inst, from, action, param, reply, capstr)= SO3WidgetSetVisibility capstr.SCAP_win 0; //reset camera matrix if (capstr.SCAP_iMatrixMode != 0) then nil else SO3CameraSetProjectionMatrix capstr.SCAP_lastCamera nil; set capstr.SCAP_bShow = 0; 0;; fun updateCameraSize(capstr, pw, ph)= //addLogMessage strcatn "ARCapture update camera size: "::(itoa pw)::"x"::(itoa ph)::nil; let capstr.SCAP_tLastCamSizeCheck -> [ow oh] in let capstr.SCAP_tCamSize -> [camw camh] in let if (!capstr.SCAP_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 ( set capstr.SCAP_tLastCamSizeCheck = [ncw nch]; addLogMessage strcatn "Try cam size: "::(itoa ncw)::"x"::(itoa nch)::nil; _SETcaptureSize capstr.SCAP_DeviceLeft ncw nch; let _GETcaptureSize capstr.SCAP_DeviceLeft -> [ocw och] in let if (capstr.SCAP_DeviceMode == 1) then [(ocw / 2) och] else if ((capstr.SCAP_DeviceMode == 2) || (capstr.SCAP_DeviceMode == 3)) then [ocw (och / 2)] else [ocw och] -> [cw ch] in ( if (capstr.SCAP_DeviceRight == nil) then nil else _SETcaptureSize capstr.SCAP_DeviceRight ocw och; addLogMessage strcatn "Get cam size: "::(itoa cw)::"x"::(itoa ch)::nil; set capstr.SCAP_tLastCamSize = [cw ch]; if (capstr.SCAP_CamParam == nil) then nil else _DSarCameraParam capstr.SCAP_CamParam; if (capstr.SCAP_lastCamera == nil) then nil else ( //reset camera matrix SO3CameraSetProjectionMatrix capstr.SCAP_lastCamera nil; set capstr.SCAP_lastCamera = nil; ); let V3DgetDefaultViewport (V3DgetSessionView c3dXsession) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3CameraGetNearClipDistance camera -> nclip in let SO3CameraGetFarClipDistance camera -> fclip in let capstr.SCAP_lCamIntrinsics -> [iauto [fx fy] [cx cy]] in if (iauto) then set capstr.SCAP_CamParam = _CRarCameraParam _channel cw ch nclip fclip nil else set capstr.SCAP_CamParam = _CRarCameraParamIntrinsics _channel cw ch nclip fclip [fx fy] [cx cy]; _SETcameraOffset capstr.SCAP_CamParam [(capstr.SCAP_fIpd *. (-.0.5)) 0.0 0.0]; //reset buffer if (capstr.SCAP_bitmapBuffer == nil) then nil else ( _DSbitmap capstr.SCAP_bitmapBuffer; set capstr.SCAP_bitmapBuffer = nil; ); if (capstr.SCAP_bitmapDetectBuffer == nil) then nil else ( _DSbitmap capstr.SCAP_bitmapDetectBuffer; set capstr.SCAP_bitmapDetectBuffer = nil; ); ); ); 0;; fun cbResizeCtrl(inst, viewstr, ww, wh, capstr)= let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in ( if capstr.SCAP_win == nil then nil else ( if capstr.SCAP_bOnMaterial then nil else let computePosSize capstr vw vh -> [px py pw ph] in let if (capstr.SCAP_bOnMaterial) then [capstr.SCAP_iWidth capstr.SCAP_iHeight] else [pw ph] -> [cw ch] in ( updateCameraSize capstr cw ch; SO3WidgetSetPosition capstr.SCAP_win px py; SO3WidgetSetSize capstr.SCAP_win pw ph; ); //update camera setting on current camera change if ((capstr.SCAP_bShow && capstr.SCAP_bAdjustMatrix && (capstr.SCAP_iMatrixMode == 0)) || (capstr.SCAP_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.SCAP_tPercent <- [xpercent ypercent _ _ _ _ _ _]; set capstr.SCAP_iPosX = px; set capstr.SCAP_iPosY = py; let computePosSize capstr vw vh -> [px py pw ph] in let if (capstr.SCAP_bOnMaterial) then [capstr.SCAP_iWidth capstr.SCAP_iHeight] else [pw ph] -> [cw ch] in ( updateCameraSize capstr cw ch; SO3WidgetSetPosition capstr.SCAP_win px py; SO3WidgetSetSize capstr.SCAP_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.SCAP_tPercent <- [_ _ wpercent hpercent _ _ _ _]; set capstr.SCAP_iWidth = px; set capstr.SCAP_iHeight = py; let computePosSize capstr vw vh -> [px py pw ph] in let if (capstr.SCAP_bOnMaterial) then [capstr.SCAP_iWidth capstr.SCAP_iHeight] else [pw ph] -> [cw ch] in ( updateCameraSize capstr cw ch; SO3WidgetSetPosition capstr.SCAP_win px py; SO3WidgetSetSize capstr.SCAP_win pw ph; ); ); ); ); 0;; fun getVideoSize(inst, from, action, param, rep, capstr)= let _GETcaptureSize capstr.SCAP_DeviceLeft -> [ocw och] in let if (capstr.SCAP_DeviceMode == 1) then [(ocw / 2) och] else if ((capstr.SCAP_DeviceMode == 2) || (capstr.SCAP_DeviceMode == 3)) then [ocw (och / 2)] else [ocw och] -> [cw ch] in SendPluginEvent inst "Video size" strcatn (itoa cw)::" "::(itoa ch)::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 (wr *. (itof x)) -> x in let ftoi (hr *. (itof y)) -> y in [x y] -> [posx posy] in _SETcaptureFocusPoint capstr.SCAP_DeviceLeft posx posy; 0;; fun cbAccelData(sensorCb, capstr, vec, val, delta)= let capstr.SCAP_tImuState -> [gyro _] in if (gyro != nil) then ( _AddcameraSensorsImu capstr.SCAP_CamParam gyro vec delta; //addLogMessageVector3F "Gyro " gyro; //addLogMessageVector3F "Accel " vec; mutate capstr.SCAP_tImuState <- [nil nil]; ) else ( mutate capstr.SCAP_tImuState <- [_ vec]; ); 0;; fun cbGyroData(sensorCb, capstr, vec, val, delta)= let capstr.SCAP_tImuState -> [_ accel] in if (accel != nil) then ( _AddcameraSensorsImu capstr.SCAP_CamParam vec accel delta; //addLogMessageVector3F "Gyro " vec; //addLogMessageVector3F "Accel " accel; mutate capstr.SCAP_tImuState <- [nil nil]; ) else ( mutate capstr.SCAP_tImuState <- [vec _]; ); 0;; fun connectCapture(inst, from, action, param, rep, capstr)= if (capstr.SCAP_DeviceLeft != nil) then nil else let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let if (capstr.SCAP_bOnMaterial) then [0 0 capstr.SCAP_iWidth capstr.SCAP_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.SCAP_accelCb = _CrSensorCallBack _channel SENSOR_TYPE_ACCELEROMETER @cbAccelData capstr; // set capstr.SCAP_gyroCb = _CrSensorCallBack _channel SENSOR_TYPE_GYROSCOPE @cbGyroData capstr; //); set capstr.SCAP_DeviceLeft = _CRcapture _channel capstr.SCAP_iLeftDeviceIndex; // try to find one let 0 -> i in while capstr.SCAP_DeviceLeft == nil && (i < 8) do ( set capstr.SCAP_DeviceLeft = _CRcapture _channel i; set capstr.SCAP_iLeftDeviceIndex = i; set i = i + 1; ); if (capstr.SCAP_DeviceLeft == nil) then nil else ( //set the camera size, if this is not support it switch to the default size let capstr.SCAP_tCamSize -> [camw camh] in let if (!capstr.SCAP_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.SCAP_tLastCamSizeCheck = [ncw nch]; addLogMessage strcatn "Try cam size: "::(itoa ncw)::"x"::(itoa nch)::nil; _SETcaptureSize capstr.SCAP_DeviceLeft ncw nch; ); _SETcaptureTorchState capstr.SCAP_DeviceLeft capstr.SCAP_bTorch; if (capstr.SCAP_DeviceLeft == nil) then nil else let _GETcaptureSize capstr.SCAP_DeviceLeft -> [ocw och] in let if (capstr.SCAP_DeviceMode == 1) then [(ocw / 2) och] else if ((capstr.SCAP_DeviceMode == 2) || (capstr.SCAP_DeviceMode == 3)) then [ocw (och / 2)] else [ocw och] -> [cw ch] in ( addLogMessage strcatn "Get cam size: "::(itoa cw)::"x"::(itoa ch)::nil; set capstr.SCAP_tLastCamSize = [cw ch]; // change the global variable set c3dxCameraSize = [cw ch]; set c3dxCameraFlip = 0; let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3CameraGetNearClipDistance camera -> nclip in let SO3CameraGetFarClipDistance camera -> fclip in let capstr.SCAP_lCamIntrinsics -> [iauto [fx fy] [cx cy]] in if (iauto) then set capstr.SCAP_CamParam = _CRarCameraParam _channel cw ch nclip fclip nil else set capstr.SCAP_CamParam = _CRarCameraParamIntrinsics _channel cw ch nclip fclip [fx fy] [cx cy]; _SETcameraOffset capstr.SCAP_CamParam [(capstr.SCAP_fIpd *. (-.0.5)) 0.0 0.0]; if (capstr.SCAP_DeviceMode > 0) then nil else ( set capstr.SCAP_DeviceRight = _CRcapture _channel capstr.SCAP_iRightDeviceIndex; // try to find one let capstr.SCAP_iLeftDeviceIndex + 1 -> i in while capstr.SCAP_DeviceRight == nil && (i < 16) do ( set capstr.SCAP_DeviceRight = _CRcapture _channel i; set capstr.SCAP_iRightDeviceIndex = i; set i = i + 1; ); if (capstr.SCAP_DeviceRight != nil) then ( _SETcaptureSize capstr.SCAP_DeviceRight cw ch; _SETcaptureTorchState capstr.SCAP_DeviceRight capstr.SCAP_bTorch; 0; ) else ( addLogMessage "Stereo camera: right camera failed!"; 0; ); ); if capstr.SCAP_win != nil then nil else ( V3DremoveWidgetControl viewportstr capstr.SCAP_win; SO3WidgetDestroy capstr.SCAP_win; if capstr.SCAP_bOnMaterial then ( set capstr.SCAP_win = SO3BitmapWidgetCreateOnMaterial (V3DgetSession c3dXsession) capstr.SCAP_Material (strcat (getPluginInstanceName inst) "_ARcaptureCtrl") capstr.SCAP_iWidth capstr.SCAP_iHeight capstr.SCAP_iTechnique capstr.SCAP_iPass capstr.SCAP_iTexture; 0; ) else if capstr.SCAP_bBackground then ( if (!pw || !ph || (capstr.SCAP_iWidth != 100) || (capstr.SCAP_iWidth != 100)) then nil else set capstr.SCAP_bAdjustMatrix = 1; set capstr.SCAP_win = SO3BitmapWidgetCreateBackground (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_ARcaptureCtrl") px py pw ph; 0; ) else ( set capstr.SCAP_win = SO3BitmapWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_ARcaptureCtrl") px py pw ph 100; SO3WidgetSetTopOnFocus capstr.SCAP_win 0; SO3WidgetSetForeground capstr.SCAP_win 1; 0; ); V3DaddWidgetControl viewportstr capstr.SCAP_win; SO3WidgetSetKeyboardEnable capstr.SCAP_win 0; SO3WidgetSetMouseEnable capstr.SCAP_win 0; SO3WidgetSetStereo capstr.SCAP_win if (capstr.SCAP_DeviceMode == 0) then 1 else capstr.SCAP_DeviceMode; SO3WidgetSetOpacity capstr.SCAP_win (itof capstr.SCAP_iOpacity) *. 0.01; ); if (capstr.SCAP_iMatrixMode == 1) then ( set capstr.SCAP_bAdjustMatrix = 1; ) else if (capstr.SCAP_iMatrixMode == 2) then ( set capstr.SCAP_bAdjustMatrix = 0; ) else nil; setPluginInstanceCbScenePostRender inst mkfun4 @cbRenderCapture capstr; if (!capstr.SCAP_bTouchFocus) then nil else setPluginInstanceCbInputClick inst mkfun8 @cbClick capstr; getVideoSize inst nil nil nil nil capstr; SendPluginEvent inst "Connected" (itoa capstr.SCAP_iLeftDeviceIndex) nil; ); ); ); 0;; fun disconnectCapture(inst, from, action, param, rep, capstr)= //_DsSensorCallBack capstr.SCAP_accelCb; //_DsSensorCallBack capstr.SCAP_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.SCAP_DeviceLeft == nil) then nil else ( _DScapture capstr.SCAP_DeviceLeft; set capstr.SCAP_DeviceLeft = nil; _DSarCameraParam capstr.SCAP_CamParam; set capstr.SCAP_CamParam = nil; //reset camera matrix SO3CameraSetProjectionMatrix capstr.SCAP_lastCamera nil; set capstr.SCAP_lastCamera = nil; SendPluginEvent inst "Disconnected" (itoa capstr.SCAP_iLeftDeviceIndex) nil; ); if (capstr.SCAP_DeviceRight == nil) then nil else ( _DScapture capstr.SCAP_DeviceRight; set capstr.SCAP_DeviceRight = nil; SendPluginEvent inst "Disconnected" (itoa capstr.SCAP_iRightDeviceIndex) nil; ); if (capstr.SCAP_bitmapBuffer == nil) then nil else ( _DSbitmap capstr.SCAP_bitmapBuffer; set capstr.SCAP_bitmapBuffer = nil; ); if (capstr.SCAP_bitmapDetectBuffer == nil) then nil else ( _DSbitmap capstr.SCAP_bitmapDetectBuffer; set capstr.SCAP_bitmapDetectBuffer = nil; ); 0;; fun cbDeviceList(inst, from, action, param, rep, capstr)= SendPluginEvent inst "Devices list" strcatnSep _GETcaptureDeviceList "\n" nil; 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.SCAP_tCamSize = [sx sy]; //reconnect if (capstr.SCAP_DeviceLeft == nil) then nil else ( let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let if (capstr.SCAP_bOnMaterial) then [0 0 capstr.SCAP_iWidth capstr.SCAP_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.SCAP_DeviceLeft 1; _SETcaptureTorchState capstr.SCAP_DeviceRight 1; 0;; fun cbSetTorchOff(inst, from, action, param, rep, capstr)= _SETcaptureTorchState capstr.SCAP_DeviceLeft 0; _SETcaptureTorchState capstr.SCAP_DeviceRight 0; 0;; // Destroy instance fun deleteOb(inst, capstr)= disconnectCapture inst nil nil nil nil capstr; 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 atoi (getPluginInstanceParam inst "cammode") -> cammode in let if cammode == nil then 0 else cammode -> cammode in let atoi (getPluginInstanceParam inst "lcamindex") -> lcamindex in let if lcamindex == nil then (atoi _getress "videocapture") else lcamindex -> lcamindex in let atoi (getPluginInstanceParam inst "rcamindex") -> rcamindex in let if rcamindex == nil then (atoi _getress "videocapture") + 1 else rcamindex -> rcamindex in let atoi (getPluginInstanceParam inst "lautomat") -> lautomat in let if lautomat == nil then 1 else lautomat -> lautomat in let atof (getPluginInstanceParam inst "lfx") -> lfx in let if lfx == nil then 640.0 else lfx -> lfx in let atof (getPluginInstanceParam inst "lfy") -> lfy in let if lfy == nil then 640.0 else lfy -> lfy in let atof (getPluginInstanceParam inst "lcx") -> lcx in let if lcx == nil then 320.0 else lcx -> lcx in let atof (getPluginInstanceParam inst "lcy") -> lcy in let if lcy == nil then 240.0 else lcy -> lcy in let atoi (getPluginInstanceParam inst "rautomat") -> rautomat in let if rautomat == nil then 1 else rautomat -> rautomat in let atof (getPluginInstanceParam inst "rfx") -> rfx in let if rfx == nil then 640.0 else rfx -> rfx in let atof (getPluginInstanceParam inst "rfy") -> rfy in let if rfy == nil then 640.0 else rfy -> rfy in let atof (getPluginInstanceParam inst "rcx") -> rcx in let if rcx == nil then 320.0 else rcx -> rcx in let atof (getPluginInstanceParam inst "rcy") -> rcy in let if rcy == nil then 240.0 else rcy -> rcy 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 atof (getPluginInstanceParam inst "ipd") -> ipd in let if (ipd == nil) then 0.065 else ipd /. 100.0 -> ipd 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 MkPlugCaptureStereo [inst cammode nil nil lcamindex [lautomat [lfx lfy] [lcx lcy]] rcamindex [rautomat [rfx rfy] [rcx rcy]] nil camsize nil nil autosize nil nil ipd matrixmode nil istexture mat technique pass texture nil posx posy width height [xpercent ypercent wpercent hpercent xoffset yoffset woffset hoffset] [xalign yalign] opacity 0 background 1 0 0 touchfocus torch nil nil [nil nil]] -> capstr in ( if capstr.SCAP_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.SCAP_win 1; set capstr.SCAP_bShow = 1; ) else ( SO3WidgetSetVisibility capstr.SCAP_win 0; set capstr.SCAP_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 "Get video size" mkfun6 @getVideoSize 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;;