/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ /************************************************** OpenSpace 3D Player Version: 0.1a Author: Bastien BOURINEAU / I-maginer Last update: 11.16.2010 **************************************************/ var iWinW = 800;; var iWinH = 600;; typeof mainWindow = EdWindow;; typeof netcomOS3D = NetComm;; typeof sCurrentScenePath = S;; typeof loadedProject = Project;; struct DlProgressBar=[ DLPG_widget : SO3_WIDGET, DLPG_bmp : ObjBitmap, DLPG_iBgColor : I, DLPG_iFillColor : I, DLPG_iTextColor : I, DLPG_sFontName : S, DLPG_font : ObjFont, DLPG_fLength : F, DLPG_fValue : F ] mkDlProgressBar;; typeof MainProgressBar = DlProgressBar;; fun getProjectSetting(key)= let XMLgetMarkByValue loadedProject.PRJ_xmlFile "project" -> srcprjmark in let XMLgetMarkByValueFromMarkSons srcprjmark "setting" -> srcsettingmark in XMLgetData (XMLgetMarkByValueFromMarkSons srcsettingmark key);; /** cbV3DdsMainWin [Edwindow] I * callback on destroy main window * * private * * return 0 **/ fun cbV3DdsMainWin(winstr)= _closemachine; 0;; /** initScene [V3Dview V3Dsession] I * init default scene parameters * * parameters are : * - view 3d structure * - session 3d structure * * return 0 **/ fun initScene(viewstr, sessionstr)= clearModLinks this; destroyAllPluginInstances; V3DenableNavigate sessionstr 1; V3DresetSession sessionstr; // reset resources groups let SO3GroupList (V3DgetSession sessionstr) -> l in let sizelist l -> size in let 0 -> i in while i < size do ( let nth_list l i -> resgroup in if (!strcmp resgroup sV3DResourcesGroup) then nil else SO3GroupDelete (V3DgetSession sessionstr) resgroup; set i = i + 1; ); VUIreset sessionstr; let V3DgetDefaultViewport viewstr -> viewportstr in ( V3DuseDefaultLight sessionstr 1; V3DenableView viewstr 1; V3DenableKeyboard viewstr 1; V3DenableMouse viewstr 1; V3DenableNavigate sessionstr 1; // set the Ambient light color V3DsetAmbientLight sessionstr make_rgba 0 0 0 0; V3DsetViewportColor viewportstr make_rgba 0 0 0 0; V3DsetCamera (V3DgetDefaultCamera sessionstr) nil 1.0 0.01 100000.0; ); 0;; fun cbOpenError(dlg, p, rep)= _closemachine; 0;; // progress bar fun destroyProgressBar()= SO3WidgetDestroy MainProgressBar.DLPG_widget; _DSbitmap MainProgressBar.DLPG_bmp; _DSfont MainProgressBar.DLPG_font; set MainProgressBar = nil; 0;; fun updateProgressBar(size)= _FILLbitmap MainProgressBar.DLPG_bmp MainProgressBar.DLPG_iBgColor; set MainProgressBar.DLPG_fValue = MainProgressBar.DLPG_fValue +. (itof size); let _GETbitmapSize MainProgressBar.DLPG_bmp -> [w h] in let ftoi (((itof w) /. MainProgressBar.DLPG_fLength) *. MainProgressBar.DLPG_fValue) -> nw in let ftoi ((100.0 /. MainProgressBar.DLPG_fLength) *. MainProgressBar.DLPG_fValue) -> percent in ( _DRAWrectangle MainProgressBar.DLPG_bmp 0 0 nw h DRAW_INVISIBLE 0 0 DRAW_SOLID MainProgressBar.DLPG_iFillColor; _DRAWtext MainProgressBar.DLPG_bmp MainProgressBar.DLPG_font (w / 2) ((h / 2) - (h / 4)) TD_CENTER MainProgressBar.DLPG_iTextColor strcatn "Downloading "::(itoa percent)::" %"::nil; ); SO3BitmapWidgetBlit MainProgressBar.DLPG_widget MainProgressBar.DLPG_bmp; 0;; fun resizeProgressBar(x, y, w, h)= if (MainProgressBar == nil) then nil else ( _DSbitmap MainProgressBar.DLPG_bmp; _DSfont MainProgressBar.DLPG_font; SO3WidgetSetPosition MainProgressBar.DLPG_widget x y; SO3WidgetSetSize MainProgressBar.DLPG_widget w h; set MainProgressBar.DLPG_bmp = _CRbitmap _channel w h; set MainProgressBar.DLPG_font = _CRfont _channel (h - (h / 2)) 0 FF_PIXEL|FF_WEIGHT MainProgressBar.DLPG_sFontName; updateProgressBar 0; ); 0;; fun createProgressBar(viewstr, sessionstr, viewportstr, x, y, w, h, bgcolor, fillcolor, textcolor, fontname, fulllength, value)= if (MainProgressBar != nil) then nil else let SO3BitmapWidgetCreate (V3DgetSession sessionstr) viewportstr.V3D_viewport "ProgressBar" x y w h 110 -> progresswidget in let _CRbitmap _channel w h -> bmp in let _CRfont _channel (h - (h / 2)) 0 FF_PIXEL|FF_WEIGHT fontname -> font in ( set MainProgressBar = mkDlProgressBar[progresswidget bmp bgcolor fillcolor textcolor fontname font fulllength value]; updateProgressBar 0; ); 0;; /** cbView3dResize [V3Dview I I] I * callback view resize * * private * * return 0 **/ fun cbView3dResize(viewstr, w, h, loadwidget)= SO3WidgetSetPosition loadwidget 0 0; SO3WidgetSetSize loadwidget w h; resizeProgressBar 0 0 w 25; cbPlugView3dResize viewstr w h; 0;; fun cbPlugLoaded(trm, p)= let p -> [viewstr loadwidget] in if bPluginsLoaded then ( addLogMessage "Loading screen hidden!"; _deltimer trm; SO3WidgetDestroy loadwidget; V3DsetCbResizeView viewstr @cbPlugView3dResize; 0; ) else ( addLogMessage "Loading screen keep waiting!"; 0; ); 0;; fun cbProjectLoaded(projstr, p)= _rfltimer _starttimer _channel 400 @cbPlugLoaded p; addLogMessage strcatn "Project loaded : "::projstr.PRJ_sPath::nil; 0;; /** cbDlgOpenScene [MessageBox [V3Dview SO3Widget] P] I * callback on dlg open * * private * * return 0 **/ fun cbDlgOpenScene(dlg, p, pfile)= let p -> [viewstr loadwidget] in if pfile == nil then ( _closemachine; 0; ) else let _PtoScol pfile -> file in let getFileExt file -> ext in if (file == nil) || ((strcmpi "xos" ext) && (strcmpi "pak" ext) && (strcmpi "pkos" ext)) then ( _DLGrflmessage _DLGMessageBox _channel mainWindow.EDW_win "Error" "Your file have to be in a scol partition.\nOpenSpace 3D Player will exit." 0 @cbOpenError nil; 0; ) else let V3DgetDefaultSession viewstr -> sessionstr in ( set sCurrentScenePath = file; set loadedProject = crProject sCurrentScenePath nil 0 ""; if (!strcmpi (getFileExt file) "PAK") then ( // enable cache _cacheActivate; set loadedProject.PRJ_xmlFile = XMLloadString mkUnpakProject file; ) else if (!strcmpi (getFileExt file) "PKOS") then ( // enable cache _cacheActivate; set loadedProject.PRJ_xmlFile = XMLload mkUnpakOS3DProject _checkpack file nil 0; ) else nil; setProjectCbSceneLoaded loadedProject mkfun2 @cbProjectLoaded p; loadProject loadedProject viewstr nil nil nil nil 1; 0; ); 0;; fun cbDestroyView3d(viewstr)= dsEdWindow mainWindow; 0;; fun cbDownloadPak(curlobj, p, data, code)= let p -> [url wfile [viewstr loadwidget fulllength]] in if (code == -1) then ( _appendpack data wfile; //update progress bar updateProgressBar (strlen data); 0; ) // download finished else if (code == 0) then ( updateProgressBar (strlen data); set lHTTP_REQUEST = remove_from_list lHTTP_REQUEST curlobj; set loadedProject = crProject sCurrentScenePath nil 0 ""; if (!strcmpi (getFileExt sCurrentScenePath) "PAK") then ( set loadedProject.PRJ_xmlFile = XMLloadString mkUnpakProject sCurrentScenePath; ) else if (!strcmpi (getFileExt sCurrentScenePath) "PKOS") then ( set loadedProject.PRJ_xmlFile = XMLload mkUnpakOS3DProject _checkpack sCurrentScenePath nil 0; ) else nil; destroyProgressBar; setProjectCbSceneLoaded loadedProject mkfun2 @cbProjectLoaded [viewstr loadwidget]; loadProject loadedProject viewstr nil nil nil nil 1; 0; ) else ( destroyProgressBar; _fooS strcatn ">>>>>>>>> Http download failed : "::url::" whith code : "::(itoa code)::nil; set lHTTP_REQUEST = remove_from_list lHTTP_REQUEST curlobj; 0; ); 0;; fun downloadPak(url, p)= let makeHtmlCookie url -> cookie in let _CRcurlRequest _channel url -> objcurl in ( _SETcurlOption objcurl CURLOPT_SSL_VERIFYPEER 0; _SETcurlOption objcurl CURLOPT_CONNECTTIMEOUT iCURL_REQUEST_TIMEOUT; if (cookie == nil) then nil else _SETcurlOptionS objcurl CURLOPT_COOKIE cookie; let getPathFile url nil -> [_ fname] in set sCurrentScenePath = strcat "tmp/paks/" fname; //remove data in the existing file first, we could also check the file timestamp and size //if there is a way to keep it somewhere and load the file directly is there is no change _storepack "" sCurrentScenePath; let _getmodifypack sCurrentScenePath -> wfile in set lHTTP_REQUEST = (_CALLcurlRequest objcurl @cbDownloadPak [url wfile p])::lHTTP_REQUEST; ); 0;; fun cbGetProjectUrlLength(url, fulllength, p)= let p -> [viewstr sessionstr viewportstr loadwidget] in if (fulllength == nil) then ( _DLGMessageBox _channel mainWindow.EDW_win "Error" strcat "File not found : " url 0; 0; ) else ( let [viewstr loadwidget fulllength] -> param in ( createProgressBar viewstr sessionstr viewportstr 0 0 viewstr.V3D_iWinW 25 0xaaaaaa 0x555555 0xffffff "Arial" itof fulllength 0.0; downloadPak url param; ); 0; ); 0;; /** initOs3dPlayer [S S S S I] I * initialize the application * * return 0 **/ fun initOs3dPlayer(file, projname, pw ,ph, fullscreen) = set sCurrentScenePath = file; InitMainChannel; InitDefaultGlobalVar; getOs3dVersion; if (pw == nil) || ((atoi pw) <= 0) then nil else set iWinW = atoi pw; if (ph == nil) || ((atoi ph) <= 0) then nil else set iWinH = atoi ph; // set lib 2D default res path set sG2DDEFAULTRESOURCESPATH = strcat APPBASEDIR "os3dlib/res/"; set sV3DDEFAULTRESOURCESPATH = strcat APPBASEDIR "os3dlib/res/"; set sKEYBDEFAULTRESOURCESPATH = strcat APPBASEDIR "os3dlib/res/def/"; set sTreeBitmapScene = strcat APPBASEDIR sTreeBitmapScene; set sTreeBitmapGroup = strcat APPBASEDIR sTreeBitmapGroup; set sTreeBitmapNode = strcat APPBASEDIR sTreeBitmapNode; set sTreeBitmapLight = strcat APPBASEDIR sTreeBitmapLight; set sTreeBitmapCamera = strcat APPBASEDIR sTreeBitmapCamera; set sTreeBitmapEntity = strcat APPBASEDIR sTreeBitmapEntity; set sTreeBitmapSky = strcat APPBASEDIR sTreeBitmapSky; set sTreeBitmapAnim = strcat APPBASEDIR sTreeBitmapAnim; set sTreeBitmapCompositor = strcat APPBASEDIR sTreeBitmapCompositor; set sTreeBitmapBone = strcat APPBASEDIR sTreeBitmapBone; set sTreeBitmapParticle = strcat APPBASEDIR sTreeBitmapParticle; set sTreeBitmapCubeMap = strcat APPBASEDIR sTreeBitmapCubeMap; set sTreeBitmapReflectionMap = strcat APPBASEDIR sTreeBitmapReflectionMap; set sWinMainIcon = strcat APPBASEDIR sWinMainIcon; set sWinDlgIcon = strcat APPBASEDIR sWinDlgIcon; set sWinPlayerMainIcon = strcat APPBASEDIR sWinPlayerMainIcon; set sPLUGINSPATH = strcat APPBASEDIR sPLUGINSPATH; let _GETdesktopSize -> [sw sh] in ( set mainWindow = setEdWindowIcon (crEdMainWindow _channel nil ((sw / 2) - (iWinW / 2)) ((sh / 2) - (iWinH / 2)) iWinW iWinH nil strcatn "OpenSpace3D Player : "::getVersionName::" ("::getVersionDate::") - "::projname::nil) sWinPlayerMainIcon; // size the window with borders if (getEdWindowIsAX mainWindow) then nil else setEdWindowPosSizeEx mainWindow ((sw / 2) - (iWinW / 2)) ((sh / 2) - (iWinH / 2)) iWinW + 1 iWinH + 1; ); let getEdWindowSize mainWindow -> [nw nh] in let G2DloadAlphaBmp _channel strcat APPBASEDIR "os3dplayer/splash.png" -> splash in /*let _GETalphaBitmaps splash -> [bmp _] in let _GETbitmapSize bmp -> [bw bh] in let if (bw == nw) && (bh == nh) then bmp else let _CRbitmap _channel nw nh -> newbmp in _SCPbitmap newbmp 0 0 nw nh bmp 0 0 bw bh nil -> bmp in let _BLTbitmap mainWindow.EDW_win bmp 0 0 -> _ in*/ let crEdCtrl3D mainWindow 0 0 nw nh EDWIN_RESIZE_MW|EDWIN_RESIZE_MH -> ctrl3dviewstr in let getEdCtrlView3d ctrl3dviewstr -> viewstr in let V3DgetDefaultSession viewstr -> sessionstr in ( setEdCtrl3DdestroyCb ctrl3dviewstr @cbDestroyView3d; V3DaddViewport viewstr 0.0 0.0 1.0 1.0 0x0; initScene viewstr sessionstr; //Loading screen let V3DgetDefaultViewport viewstr -> viewportstr in let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ ivw ivh] in let SO3BitmapWidgetCreate (V3DgetSession sessionstr) viewportstr.V3D_viewport "Loading" 0 0 ivw ivh 10000 -> loadwidget in ( addLogMessage strcatn "Viewport size : "::(itoa ivw)::"x"::(itoa ivh)::nil; SO3BitmapWidgetBlitAlpha loadwidget splash; _DSalphaBitmap splash; SO3BufferUpdate viewstr.V3D_buffer; // init keyboards definition KEYBloadMaps; // init default global network callbacks set netcomOS3D = netCreateMinimum; netSetCbConnected netcomOS3D @cbPlugNetConnected; netSetCbSConnected netcomOS3D @cbPlugNetSConnected; netSetCbClosed netcomOS3D @cbPlugNetClosed; netSetCbSrvMessage netcomOS3D @cbPlugNetSrvMessage; netSetCbUserMessage netcomOS3D @cbPlugNetUserMessage; netSetCbUserPrivateMessage netcomOS3D @cbPlugNetUserPrivateMessage; netSetCbUserChangeLogin netcomOS3D @cbPlugUserChangeLogin; netSetCbNewUser netcomOS3D @cbPlugNewUser; netSetCbDelUser netcomOS3D @cbPlugDelUser; netSetCbGetFile netcomOS3D @cbPlugGetFile; netSetCbUserGetItem netcomOS3D @cbPlugUserGetItem; netSetCbRoomGetItem netcomOS3D @cbPlugRoomGetItem; netSetCbNbUsers netcomOS3D @cbPlugNbUsers; netSetCbRoomChanged netcomOS3D @cbPlugRoomChanged; set s3dMainSession = sessionstr; set v3dMain = viewstr; V3DsetCbClick viewstr @cbPlugView3dClick; V3DsetCbUnClick viewstr @cbPlugView3dUnClick; V3DsetCbKeyDown viewstr @cbPlugView3dKeyDown; V3DsetCbKeyUp viewstr @cbPlugView3dKeyUp; V3DsetCbPreRender viewstr @cbPlugView3dPreRender; V3DsetCbPreRender2 viewstr @cbPlugView3dPreRender2; V3DsetCbPostRender viewstr @cbPlugView3dPostRender; V3DsetCbScenePreRender sessionstr @cbPlugScenePreRender; V3DsetCbScenePreRender2 sessionstr @cbPlugScenePreRender2; V3DsetCbScenePreRenderPhysic sessionstr @cbPlugScenePreRenderPhysic; V3DsetCbScenePostRender sessionstr @cbPlugScenePostRender; V3DsetCbNavigateControlState sessionstr @cbPlugNavigateControlState; V3DsetCbCursorMove viewstr @cbPlugView3dCursorMove; V3DsetCbDbClick viewstr @cbPlugView3dDbClick; V3DsetCbWheel viewstr @cbPlugView3dWheel; V3DsetCbInputClick viewstr @cbPlugView3dInputClick; V3DsetCbInputUnClick viewstr @cbPlugView3dInputUnClick; V3DsetCbInputUpdate viewstr @cbPlugView3dInputUpdate; V3DsetCbCameraChange viewstr @cbPlugView3dCameraChange; V3DsetCbResizeView viewstr mkfun4 @cbView3dResize loadwidget; V3DsetCbFocusView viewstr @cbPlugView3dFocus; V3DsetCbKillFocusView viewstr @cbPlugView3dKillFocus; V3DsetCbDropFile viewstr @cbPlugView3dDropFile; V3DsetCbVrModeChanged viewstr @cbPlugViewVrMode; //multi touch V3DsetViewTouchPointAddCb viewstr @cbPlugView3dTouchPointAdd; V3DsetViewTouchPointRemoveCb viewstr @cbPlugView3dTouchPointRemove; V3DsetViewTouchPointUpdateCb viewstr @cbPlugView3dTouchPointUpdate; //V3DsetScreenInfos viewstr 5 5 300 200 14 0xffffff; //V3DenableScreenInfos viewstr 0; setEdwindowCbDestroy mainWindow @cbV3DdsMainWin; // load plugins files loadPlugins sPLUGINSPATH; if (file == nil) || (!strcmp (strtrim file) "") then ( _DLGrflopen _DLGOpenFile _channel mainWindow.EDW_win nil nil "OpenSpace 3D scene\0*.xos;*.pkos;*.pak;\0All\0*.*\0\0" @cbDlgOpenScene [viewstr loadwidget]; 0; ) else ( if !fullscreen then nil else //let _GETdesktopSize -> [sw sh] in V3DsetFullScreenMode viewstr iWinW iWinH; if (strIsUrl file) then ( // enable cache _cacheActivate; getUrlContentLenght file mkfun3 @cbGetProjectUrlLength [viewstr sessionstr viewportstr loadwidget]; 0; ) else ( set loadedProject = crProject sCurrentScenePath nil 0 ""; if (!strcmpi (getFileExt file) "pak") then ( // enable cache _cacheActivate; set loadedProject.PRJ_xmlFile = XMLloadString mkUnpakProject file; ) else if (!strcmpi (getFileExt file) "PKOS") then ( // enable cache _cacheActivate; set loadedProject.PRJ_xmlFile = XMLload mkUnpakOS3DProject _checkpack file nil 0; ) else nil; setProjectCbSceneLoaded loadedProject mkfun2 @cbProjectLoaded [viewstr loadwidget]; loadProject loadedProject viewstr nil nil nil nil 1; 0; ); 0; ); ); ); 0;;