/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ /************************************************** SO3Engine (Ogre 3D) library Version: 1.0 Author: Bastien BOURINEAU / I-maginer Last update: 02.04.2009 **************************************************/ // Meter var iGlobalUnit = 1;; var sVoyagerDefaultResourcesPATH = "locked/voyager/3d/";; var iV3Ddebug = 0;; // Frames handling var iV3DmaxFramerate = 90;; // Maximum possible framerate var iV3DIndex = 0;; var iV3DSessionIndex = 0;; // - Mouse - var V3DCLICK_NO = 0;; var V3DCLICK_LEFT = 1;; var V3DCLICK_RIGHT = 2;; var V3DCLICK_SHIFT = 4;; var V3DCLICK_CTRL = 8;; var V3DCLICK_MIDDLE = 16;; var V3DAXIS_X = 32;; var V3DAXIS_Y = 64;; var V3DAXIS_Z = 128;; // - Struct viewport - struct V3Dviewport = [ V3D_iViewportIndex : I, V3D_viewport : SO3_VIEWPORT, V3D_iViewportX : F, V3D_iViewportY : F, V3D_iViewportW : F, V3D_iViewportH : F, V3D_iBgColor : I ] mkV3Dviewport;; // - Struct Axis - struct V3Daxis = [ V3D_axisFather : SO3_OBJECT, V3D_axisShell : SO3_OBJECT, V3D_xAxisObject : SO3_OBJECT, V3D_yAxisObject : SO3_OBJECT, V3D_zAxisObject : SO3_OBJECT, V3D_xAxisTextObject : SO3_OBJECT, V3D_yAxisTextObject : SO3_OBJECT, V3D_zAxisTextObject : SO3_OBJECT, V3D_iAxisMode : I ] mkV3Daxis;; // - Struct Helper - struct V3Dhelper = [ V3D_helperFather : SO3_OBJECT, V3D_helperIcon : SO3_OBJECT, V3D_iHelperMode : I ] mkV3Dhelper;; // - Struct Session - struct V3Dsession = [ V3D_sessionView : V3Dview, V3D_session : SO3_SCENE, V3D_lCamera : [[I SO3_OBJECT] r1], V3D_defaultCamera : SO3_OBJECT, V3D_prevDefaultCamera : SO3_OBJECT, V3D_shellNavigate : SO3_OBJECT, V3D_physics : V3Dphysics, V3D_lAxis : [[SO3_OBJECT V3Daxis] r1], V3D_lHelper : [[SO3_OBJECT V3Dhelper] r1], V3D_helperGrid : [SO3_OBJECT [SO3_OBJECT r1]], V3D_bHelpersState : I, V3D_selectedAxis : [V3Daxis I], V3D_cbAxisClick : fun [V3Dsession SO3_OBJECT I I I I] I, V3D_cbAxisUnClick : fun [V3Dsession SO3_OBJECT I I I I] I, V3D_cbAxisMove : fun [V3Dsession SO3_OBJECT I I I I F] I, V3D_bNavigate : I, V3D_lAnimations : [[S V3Danim] r1], V3D_bAnimations : I ] mkV3Dsession;; struct V3Danim = [ V3D_anim : SO3_ANIM, V3D_meshAnim : SO3_OBJECT, V3D_sAnimName : S, V3D_bAnimState : I, V3D_iAnimType : I ] mkV3Danim;; // - Struct 3D - struct V3Dview = [ V3D_win : ObjWin, V3D_buffer : SO3_BUFFER, V3D_channel : Chn, V3D_iWinW : I, V3D_iWinH : I, V3D_iWinX : I, V3D_iWinY : I, V3D_iOldWinW : I, V3D_iOldWinH : I, V3D_lSessions : [[I V3Dsession] r1], V3D_bPaused : I, // ressources V3D_iRenderTick : I, // mouse / keyboard V3D_iClickStatus : I, V3D_iClickX : I, V3D_iClickY : I, V3D_iMoveX : I, V3D_iMoveY : I, V3D_iRenderMoveX : I, V3D_iRenderMoveY : I, V3D_iMoveClickStatus : I, V3D_bMouseEnabled : I, V3D_bKeyboardEnabled : I, // Callback V3D_cbInit : fun [V3Dview] I, V3D_cbDestroy : fun [V3Dview] I, V3D_cbPreRenderEffects : fun [V3Dview] I, V3D_cbPreRender : fun [V3Dview] I, V3D_cbPostRender : fun [V3Dview] I, V3D_cbClick : fun [V3Dview I I I] I, V3D_cbDbClick : fun [V3Dview I I I] I, V3D_cbUnClick : fun [V3Dview I I I] I, V3D_cbWheel : fun [V3Dview I I I I] I, V3D_cbCursorMove : fun [V3Dview I I I] I, V3D_cbKeyDown : fun [V3Dview I I] I, V3D_cbKeyUp : fun [V3Dview I] I, V3D_cbCameraChange : fun [V3Dview V3Dsession SO3_OBJECT] I, V3D_cbResizeView : fun [V3Dview I I] I, V3D_lViewport : [[I V3Dviewport] r1], V3D_bFullScreen : I, V3D_bState : I ]mkV3Dview;; proto V3DviewSetFocus = fun [V3Dview] I;; fun V3Dlcat(p, q)= if p==nil then q else let p -> [h nxt] in h::V3Dlcat nxt q;; fun V3DisUrl(url)= if (!strcmpi "http://" (substr url 0 7)) || (!strcmpi "https://" (substr url 0 8)) || (!strcmpi "ftp://" (substr url 0 6)) || (!strcmpi "mms://" (substr url 0 6)) || (!strcmpi "rstp://" (substr url 0 7)) then 1 else 0;; fun V3DgetPathFile(longfile, file)= if (longfile==nil) || (strlen longfile)==0 || (nth_char longfile ((strlen longfile)-1)) == '/ then ( if (strfind "." file 0) != nil then [longfile file] else if file != nil then [strcatn longfile::file::"/"::nil nil] else [longfile nil]; ) else V3DgetPathFile substr longfile 0 (strlen longfile)-1 strcat substr longfile ((strlen longfile)-1) 1 file;; // return the fileName without Path and Extension fun V3DgetFileNameWithoutExt(file)= let V3DgetPathFile file "" -> [_ file2] in substr file2 0 (strfind "." file2 0);; fun V3DgetFileExt(file)= let V3DgetPathFile file "" -> [_ file2] in substr file2 ((strfind "." file2 0) + 1) 1024;; fun V3DgetFilePathWithoutExt(file)= substr file 0 (strfind "." file 0);; fun V3DremoveIdxFromList(l, idx)= if l==nil then nil else let hd l -> [id _] in if id == idx then tl l else (hd l)::V3DremoveIdxFromList tl l idx;; fun V3DremoveTupFromListBy2ndElem(l, s2nd)= if l==nil then nil else let hd l -> [_ elem] in if elem == s2nd then tl l else (hd l)::V3DremoveTupFromListBy2ndElem tl l s2nd;; fun V3DremoveTupFromListByName(l, name)= if l==nil then nil else let hd l -> [sname _] in if (!strcmp name sname) then tl l else (hd l)::V3DremoveTupFromListByName tl l name;; fun V3DgetSessionIndex(viewstr, sessionstr)= let sizelist viewstr.V3D_lSessions -> size in let nil -> idx in let 0 -> i in ( while i < size && idx == nil do ( let nth_list viewstr.V3D_lSessions i -> [sidx sstr] in if sstr != sessionstr then nil else set idx = sidx; set i = i + 1; ); idx; );; fun V3DgetSession(sessionstr)= sessionstr.V3D_session;; fun V3DgetSessionByIndex(viewstr, idx)= switch viewstr.V3D_lSessions idx;; fun V3DgetDefaultSession(viewstr)= switch viewstr.V3D_lSessions 0;; fun V3DdegToRad(f)=f *. ((2.0 *. PIf) /. 360.0);; fun V3DradToDeg(f)=f /. ((2.0 *. PIf) /. 360.0);; fun V3DgetObjectPos(obj)= SO3ObjectGetPosition obj;; fun V3DgetObjectScale(obj)= SO3ObjectGetScale obj;; fun V3DgetObjectOrientation(obj)= SO3ObjectGetOrientation obj;; fun V3DsetObjectPos(obj, pos)= SO3ObjectSetPosition obj pos; pos;; fun V3DsetObjectScale(obj, scale)= SO3ObjectSetScale obj scale; scale;; fun V3DsetObjectOrientation(obj, quat)= SO3ObjectSetOrientation obj quat; quat;; fun V3DsetCamera(camera, fovlenght, fovy, nclip, fclip)= if fovlenght == nil then nil else SO3CameraSetFocalLenght camera fovlenght; if fovy == nil then nil else SO3CameraSetFOVy camera fovy; if nclip == nil then nil else SO3CameraSetNearClipDistance camera nclip; if fclip == nil then nil else SO3CameraSetFarClipDistance camera fclip; camera;; fun V3DgetCameraByIndex(sessionstr, idx)= switch sessionstr.V3D_lCamera idx;; fun V3DgetCameraIndex(sessionstr, camera)= let sizelist sessionstr.V3D_lCamera -> size in let nil -> idx in let 0 -> i in ( while i < size && idx == nil do ( let nth_list sessionstr.V3D_lCamera i -> [sidx cam] in if cam != camera then nil else set idx = sidx; set i = i + 1; ); idx; );; fun V3DgetDefaultCamera(sessionstr)= sessionstr.V3D_defaultCamera;; fun V3DsetDefaultCamera(sessionstr, camera)= set sessionstr.V3D_prevDefaultCamera = sessionstr.V3D_defaultCamera; set sessionstr.V3D_defaultCamera = camera; exec sessionstr.V3D_sessionView.V3D_cbCameraChange with [sessionstr.V3D_sessionView sessionstr camera]; 0;; fun V3DsetCbCameraChange(viewstr, cbfun)= set viewstr.V3D_cbCameraChange = cbfun; 0;; fun V3DrestaurePreviousDefaultCamera(sessionstr)= if sessionstr.V3D_prevDefaultCamera == nil then nil else let sessionstr.V3D_defaultCamera -> camera in ( set sessionstr.V3D_defaultCamera = sessionstr.V3D_prevDefaultCamera; set sessionstr.V3D_prevDefaultCamera = camera; ); 0;; fun V3DdelCamera(sessionstr, camera)= SO3ObjectDestroy camera; let V3DgetCameraIndex sessionstr camera -> idx in set sessionstr.V3D_lCamera = V3DremoveIdxFromList sessionstr.V3D_lCamera idx; 0;; fun V3DaddCamera(sessionstr, name)= let let 0 -> i in ( while ((switch sessionstr.V3D_lCamera i) != nil) do ( set i = i + 1; ); i; ) -> idx in let SO3CameraCreate (V3DgetSession sessionstr) name -> newcam in ( set sessionstr.V3D_lCamera = V3Dlcat sessionstr.V3D_lCamera [idx newcam]::nil; if sessionstr.V3D_defaultCamera != nil then nil else set sessionstr.V3D_defaultCamera = newcam; newcam; );; fun V3DsetLight(light, type, dcolor, scolor, range, const, linear, quadr)= if (light == nil) then nil else ( SO3LightSetType light type; SO3LightSetDiffuseColor light dcolor; SO3LightSetSpecularColor light scolor; SO3LightSetAttenuation light [range const linear quadr]; light; );; fun V3DenableLight(light, state)= SO3LightSetVisible light state; 0;; fun V3DaddLight(sessionstr, name, father, type, dcolor, scolor, range, const, linear, quadr)= if sessionstr == nil then nil else let SO3LightCreate (V3DgetSession sessionstr) name -> light in ( if father == nil then nil else SO3ObjectLink light father; SO3LightSetType light type; SO3LightSetDiffuseColor light dcolor; SO3LightSetSpecularColor light scolor; SO3LightSetAttenuation light [range const linear quadr]; //SO3LightSetVisible light 0; //SO3LightSetSpotFallOff light falloff; //SO3LightSetPowerScale light 1000.0; //SO3ObjectLookAt light [0.0 0.0 0.0] 2; light; );; fun V3DaddResource(sessionstr, ressource, group, type)= SO3SceneLoadResource (V3DgetSession sessionstr) group _checkpack ressource type; 0;; fun V3DaddMesh(sessionstr, file, name, idx, group, father)= if (sessionstr == nil) || (file == nil) then nil else ( V3DaddResource sessionstr file group SO3_RESOURCE_MESH; let SO3SceneLoadEntity (V3DgetSession sessionstr) group strcatn idx::"."::name::nil _checkpack file -> mesh in ( if father == nil then nil else SO3ObjectLink mesh father; mesh; ); );; fun V3DaddShell(sessionstr, name, idx, father, pos, ang)= if sessionstr == nil then nil else let if name == nil || (!strcmp name "") then idx else if idx == nil || (!strcmp idx "") then name else strcatn idx::"."::name::nil -> name in let SO3SceneNodeCreate (V3DgetSession sessionstr) name -> shell in ( if father == nil then nil else SO3ObjectLink shell father; if pos == nil then nil else SO3ObjectSetPosition shell pos; if ang == nil then nil else SO3ObjectSetOrientation shell ang; shell; );; fun V3DgetViewportByIndex(viewstr, idx)= switch viewstr.V3D_lViewport idx;; fun V3DgetViewportIndex(viewstr, viewport)= let sizelist viewstr.V3D_lViewport -> size in let nil -> idx in let 0 -> i in ( while i < size && idx == nil do ( let nth_list viewstr.V3D_lViewport i -> [sidx view] in if view != viewport then nil else set idx = sidx; set i = i + 1; ); idx; );; fun V3DgetDefaultViewport(viewstr)= switch viewstr.V3D_lViewport 0;; fun V3DsetViewportColor(viewportstr, color)= set viewportstr.V3D_iBgColor = color; SO3ViewportSetBackgroundColor viewportstr.V3D_viewport color; 0;; fun V3DgetViewportColor(viewportstr)= SO3ViewportGetBackgroundColor viewportstr.V3D_viewport;; fun V3DdelViewport(viewstr, viewportstr)= SO3ViewportDestroy viewportstr.V3D_viewport; let V3DgetViewportIndex viewstr viewportstr -> idx in set viewstr.V3D_lViewport = V3DremoveIdxFromList viewstr.V3D_lViewport idx; 0;; fun V3DaddViewport(viewstr, x, y, w, h, backcolor)= let let 0 -> i in ( while ((switch viewstr.V3D_lViewport i) != nil) do ( set i = i + 1; ); i; ) -> idx in let mkV3Dviewport [idx nil x y w h backcolor] -> newviewport in ( set viewstr.V3D_lViewport = V3Dlcat viewstr.V3D_lViewport [idx newviewport]::nil; newviewport; );; fun V3DsetViewport(viewstr, viewportstr, sessionstr, camera)= if viewportstr.V3D_viewport == nil then ( set viewportstr.V3D_viewport = SO3ViewportCreate viewstr.V3D_channel viewstr.V3D_buffer camera viewportstr.V3D_iViewportX viewportstr.V3D_iViewportY viewportstr.V3D_iViewportW viewportstr.V3D_iViewportH viewportstr.V3D_iViewportIndex; SO3ViewportSetBackgroundColor viewportstr.V3D_viewport viewportstr.V3D_iBgColor; SO3ViewportSetShadowEnabled viewportstr.V3D_viewport 1; 0; ) else ( SO3CameraSetViewport viewportstr.V3D_viewport camera; 0; ); 0;; fun V3DgetSessionView(sessionstr) = sessionstr.V3D_sessionView;; // update axis pos and scale fun V3DupdateObjectAxis(viewstr, sessionstr, axisstr)= if (axisstr == nil) || (axisstr.V3D_axisFather) == nil then nil else let (V3DgetDefaultViewport viewstr) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3ObjectGetGlobalPosition camera -> [cx cy cz] in let SO3ObjectGetGlobalPosition axisstr.V3D_axisFather -> [ox oy oz] in let SO3ObjectGetGlobalOrientation axisstr.V3D_axisFather -> quat in let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ vw vh] in // same object size on different distances let SO3CameraGetFOVy camera -> fovy in let if fovy <=. 0.0 then 0.000001 else fovy -> fovy in let sqrt ((sqr(cx -. ox)) +. (sqr(cy -. oy)) +. (sqr(cz -. oz))) -> dist in let maxf 0.000001 ((dist /. ((itof vh) /. 2.0)) *. fovy) /. 2.0 -> scale in ( SO3ObjectSetPosition axisstr.V3D_axisShell [ox oy oz]; SO3ObjectSetOrientation axisstr.V3D_axisShell quat; SO3ObjectSetScale axisstr.V3D_axisShell [scale scale scale]; ); 0;; fun V3DupdateAxisTarget(viewstr, sessionstr)= let sizelist sessionstr.V3D_lAxis -> size in let 0 -> i in while i < size do ( let nth_list sessionstr.V3D_lAxis i -> [refobj axisstr] in V3DupdateObjectAxis viewstr sessionstr axisstr; set i = i + 1; ); 0;; fun V3DshowObjectAxis(viewstr, sessionstr, refobj, mode, state)= if (refobj == nil) then nil else if state then let (switch sessionstr.V3D_lAxis refobj) -> axisstr in let if axisstr != nil then axisstr else mkV3Daxis [nil nil nil nil nil nil nil nil mode] -> axisstr in let SO3ObjectGetName refobj -> refname in let SO3ObjectGetGlobalPosition refobj -> pos in let SO3ObjectGetGlobalOrientation refobj -> quat in let (V3DgetDefaultViewport viewstr) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in ( // reset axis if exist SO3ObjectDestroy axisstr.V3D_xAxisObject; SO3ObjectDestroy axisstr.V3D_yAxisObject; SO3ObjectDestroy axisstr.V3D_zAxisObject; SO3ObjectDestroy axisstr.V3D_xAxisTextObject; SO3ObjectDestroy axisstr.V3D_yAxisTextObject; SO3ObjectDestroy axisstr.V3D_zAxisTextObject; SO3ObjectDestroy axisstr.V3D_axisShell; set axisstr.V3D_axisFather = refobj; set axisstr.V3D_axisShell = SO3SceneNodeCreate (V3DgetSession sessionstr) strcat refname ".coord_axis"; if mode == 2 then ( set axisstr.V3D_xAxisObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_ang_axis_x" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_x.mesh"); set axisstr.V3D_yAxisObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_ang_axis_y" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_y.mesh"); set axisstr.V3D_zAxisObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_ang_axis_z" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_z.mesh"); ) else ( set axisstr.V3D_xAxisObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_axis_x" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_x.mesh"); set axisstr.V3D_yAxisObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_axis_y" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_y.mesh"); set axisstr.V3D_zAxisObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_axis_z" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_z.mesh"); ); set axisstr.V3D_xAxisTextObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_axis_text_x" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_x.mesh"); set axisstr.V3D_yAxisTextObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_axis_text_y" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_y.mesh"); set axisstr.V3D_zAxisTextObject = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".coords_axis_text_z" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_z.mesh"); SO3ObjectSetMouseForeGround axisstr.V3D_xAxisObject 1; SO3ObjectSetMouseForeGround axisstr.V3D_yAxisObject 1; SO3ObjectSetMouseForeGround axisstr.V3D_zAxisObject 1; SO3ObjectSetMouseForeGround axisstr.V3D_xAxisTextObject 1; SO3ObjectSetMouseForeGround axisstr.V3D_yAxisTextObject 1; SO3ObjectSetMouseForeGround axisstr.V3D_zAxisTextObject 1; SO3ObjectLink axisstr.V3D_xAxisObject axisstr.V3D_axisShell; SO3ObjectLink axisstr.V3D_yAxisObject axisstr.V3D_axisShell; SO3ObjectLink axisstr.V3D_zAxisObject axisstr.V3D_axisShell; SO3ObjectLink axisstr.V3D_xAxisTextObject axisstr.V3D_axisShell; SO3ObjectLink axisstr.V3D_yAxisTextObject axisstr.V3D_axisShell; SO3ObjectLink axisstr.V3D_zAxisTextObject axisstr.V3D_axisShell; SO3ObjectSetCastShadows axisstr.V3D_xAxisObject 0; SO3ObjectSetCastShadows axisstr.V3D_yAxisObject 0; SO3ObjectSetCastShadows axisstr.V3D_zAxisObject 0; SO3ObjectSetCastShadows axisstr.V3D_xAxisTextObject 0; SO3ObjectSetCastShadows axisstr.V3D_yAxisTextObject 0; SO3ObjectSetCastShadows axisstr.V3D_zAxisTextObject 0; SO3ObjectSetPosition axisstr.V3D_xAxisTextObject [95.0 0.0 0.0]; SO3ObjectSetPosition axisstr.V3D_yAxisTextObject [0.0 95.0 0.0]; SO3ObjectSetPosition axisstr.V3D_zAxisTextObject [0.0 0.0 95.0]; SO3ObjectSetPosition axisstr.V3D_axisShell pos; SO3ObjectSetOrientation axisstr.V3D_axisShell quat; SO3ObjectSetAutoTracking axisstr.V3D_xAxisTextObject camera 1 nil nil; SO3ObjectSetAutoTracking axisstr.V3D_yAxisTextObject camera 1 nil nil; SO3ObjectSetAutoTracking axisstr.V3D_zAxisTextObject camera 1 nil nil; // TODO change to render priority SO3ObjectSetRenderOverlay axisstr.V3D_xAxisObject 1; SO3ObjectSetRenderOverlay axisstr.V3D_yAxisObject 1; SO3ObjectSetRenderOverlay axisstr.V3D_zAxisObject 1; SO3ObjectSetRenderOverlay axisstr.V3D_xAxisTextObject 1; SO3ObjectSetRenderOverlay axisstr.V3D_yAxisTextObject 1; SO3ObjectSetRenderOverlay axisstr.V3D_zAxisTextObject 1; set sessionstr.V3D_lAxis = V3Dlcat sessionstr.V3D_lAxis [refobj axisstr]::nil; ) else ( let (switch sessionstr.V3D_lAxis refobj) -> axisstr in if axisstr == nil then nil else ( SO3ObjectDestroy axisstr.V3D_xAxisObject; SO3ObjectDestroy axisstr.V3D_yAxisObject; SO3ObjectDestroy axisstr.V3D_zAxisObject; SO3ObjectDestroy axisstr.V3D_xAxisTextObject; SO3ObjectDestroy axisstr.V3D_yAxisTextObject; SO3ObjectDestroy axisstr.V3D_zAxisTextObject; SO3ObjectDestroy axisstr.V3D_axisShell; set sessionstr.V3D_lAxis = V3DremoveIdxFromList sessionstr.V3D_lAxis refobj; ); ); 0;; // update axis pos and scale fun V3DupdateObjectHelper(viewstr, sessionstr, helperstr)= if (helperstr == nil) || (helperstr.V3D_helperFather) == nil then nil else let (V3DgetDefaultViewport viewstr) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3ObjectGetGlobalPosition camera -> [cx cy cz] in let SO3ObjectGetGlobalPosition helperstr.V3D_helperFather -> [ox oy oz] in let SO3ObjectGetGlobalOrientation helperstr.V3D_helperFather -> quat in let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ vw vh] in // same object size on different distances let SO3CameraGetFOVy camera -> fovy in let if fovy <=. 0.0 then 0.000001 else fovy -> fovy in let sqrt ((sqr(cx -. ox)) +. (sqr(cy -. oy)) +. (sqr(cz -. oz))) -> dist in let maxf 0.000001 ((dist /. ((itof vh) /. 2.0)) *. fovy) /. 2.0 -> scale in ( SO3ObjectSetPosition helperstr.V3D_helperIcon [ox oy oz]; SO3ObjectSetOrientation helperstr.V3D_helperIcon quat; SO3ObjectSetScale helperstr.V3D_helperIcon [scale scale scale]; ); 0;; fun V3DupdateHelpersTarget(viewstr, sessionstr)= if !sessionstr.V3D_bHelpersState then nil else let sizelist sessionstr.V3D_lHelper -> size in let 0 -> i in while i < size do ( let nth_list sessionstr.V3D_lHelper i -> [refobj helperstr] in V3DupdateObjectHelper viewstr sessionstr helperstr; set i = i + 1; ); 0;; fun V3DshowObjectHelper(viewstr, sessionstr, refobj, mode, state)= if (refobj == nil) then nil else if state then let (switch sessionstr.V3D_lHelper refobj) -> helperstr in let if helperstr != nil then helperstr else mkV3Dhelper [nil nil mode] -> helperstr in let SO3ObjectGetName refobj -> refname in let SO3ObjectGetGlobalPosition refobj -> pos in let SO3ObjectGetGlobalOrientation refobj -> quat in let (V3DgetDefaultViewport viewstr) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in ( // reset helper if exist SO3ObjectDestroy helperstr.V3D_helperIcon; set helperstr.V3D_helperFather = refobj; if !sessionstr.V3D_bHelpersState then nil else ( if mode == 4 then // light ( set helperstr.V3D_helperIcon = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".helper_light" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_light.mesh"); ) else if mode == 8 then // camera ( set helperstr.V3D_helperIcon = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".helper_camera" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_camera.mesh"); ) else // dummy ( set helperstr.V3D_helperIcon = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".helper_dummy" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_dummy.mesh"); ); //SO3ObjectSetMouseForeGround helperstr.V3D_helperIcon 1; SO3ObjectSetCastShadows helperstr.V3D_helperIcon 0; SO3ObjectSetPosition helperstr.V3D_helperIcon pos; SO3ObjectSetOrientation helperstr.V3D_helperIcon quat; // TODO change to render priority //SO3ObjectSetRenderOverlay helperstr.V3D_helperIcon 1; ); set sessionstr.V3D_lHelper = V3Dlcat sessionstr.V3D_lHelper [refobj helperstr]::nil; ) else ( let (switch sessionstr.V3D_lHelper refobj) -> helperstr in if helperstr == nil then nil else ( SO3ObjectDestroy helperstr.V3D_helperIcon; set sessionstr.V3D_lHelper = V3DremoveIdxFromList sessionstr.V3D_lHelper refobj; ); ); 0;; fun V3DisSceneHelperVisible(sessionstr)= if !sessionstr.V3D_bHelpersState then 0 else 1;; fun V3DenableHelpers(viewportstr, sessionstr, state)= let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let sizelist sessionstr.V3D_lHelper -> size in let 0 -> i in while i < size do ( let nth_list sessionstr.V3D_lHelper i -> [_ helperstr] in if state then let SO3ObjectGetGlobalPosition helperstr.V3D_helperFather -> pos in let SO3ObjectGetGlobalOrientation helperstr.V3D_helperFather -> quat in let SO3ObjectGetName helperstr.V3D_helperFather -> refname in ( // reset helper if exist SO3ObjectDestroy helperstr.V3D_helperIcon; if helperstr.V3D_iHelperMode == 4 then // light ( set helperstr.V3D_helperIcon = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".helper_light" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_light.mesh"); ) else if helperstr.V3D_iHelperMode == 8 then // camera ( set helperstr.V3D_helperIcon = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".helper_camera" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_camera.mesh"); ) else // dummy ( set helperstr.V3D_helperIcon = SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat refname ".helper_dummy" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_dummy.mesh"); ); SO3ObjectSetMouseForeGround helperstr.V3D_helperIcon 1; SO3ObjectSetCastShadows helperstr.V3D_helperIcon 0; SO3ObjectSetPosition helperstr.V3D_helperIcon pos; SO3ObjectSetOrientation helperstr.V3D_helperIcon quat; // TODO change to render priority SO3ObjectSetRenderOverlay helperstr.V3D_helperIcon 1; 0; ) else ( SO3ObjectDestroy helperstr.V3D_helperIcon; 0; ); set i = i + 1; ); set sessionstr.V3D_bHelpersState = state; 0;; fun V3DgetObjectFromHelper(sessionstr, obj)= let nil -> found in ( let sizelist sessionstr.V3D_lHelper -> size in let 0 -> i in while i < size && found == nil do ( let nth_list sessionstr.V3D_lHelper i -> [_ helperstr] in if helperstr.V3D_helperIcon != obj then nil else set found = helperstr.V3D_helperFather; set i = i + 1; ); if found == nil then obj else found; );; fun V3DgetObjectSize(sessionstr, object)= let SO3ObjectGetBoundingBoxInfo object 0 -> [size _ _] in size;; fun V3DgetGlobalObjectCenter(sessionstr, object)= let SO3ObjectGetGlobalPosition object -> [x y z] in let SO3ObjectGetBoundingBoxInfo object 0 -> [_ bpos _] in let bpos -> [bx by bz] in if bpos == nil then [x y z] else [(x +. bx) (y +. by) (z +. bz)];; fun V3DgetObjectRadius(sessionstr, object)= let V3DgetObjectSize sessionstr object -> size in let size -> [px py pz] in let if px >. py then px else py -> radius in let if radius >. pz then radius else pz -> radius in let if size == nil then 100.0 else radius -> radius in radius;; fun V3DisSceneGridVisible(sessionstr)= if sessionstr.V3D_helperGrid == nil then 0 else 1;; fun V3DshowSceneGrid(sessionstr, mode)= if (mode && (sessionstr.V3D_helperGrid != nil)) then nil else if mode then ( let SO3SceneNodeCreate (V3DgetSession sessionstr) "default_helper_grid" -> node in let SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" "default_helper_grid_square" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/default_grid_helper.mesh") -> square in let square::nil -> lobj in ( SO3ObjectSetScale square [(0.01 *. (itof iGlobalUnit)) (0.01 *. (itof iGlobalUnit)) (0.01 *. (itof iGlobalUnit))]; SO3ObjectLink square node; SO3ObjectSetCastShadows square 0; let -5 * iGlobalUnit -> i in while i < (5 * iGlobalUnit) do ( let SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat "default_helper_grid_hline_" (itoa i) _checkpack (strcat sVoyagerDefaultResourcesPATH (if i == 0 then "helpers/h_line_b.mesh" else "helpers/h_line_w.mesh")) -> hline in let SO3SceneLoadEntity (V3DgetSession sessionstr) "VoyagerDefaultResources" strcat "default_helper_grid_vline_" (itoa i) _checkpack (strcat sVoyagerDefaultResourcesPATH (if i == 0 then "helpers/v_line_b.mesh" else "helpers/v_line_w.mesh")) -> vline in ( SO3ObjectSetScale hline [(0.01 *. (itof iGlobalUnit)) (0.01 *. (itof iGlobalUnit)) (0.01 *. (itof iGlobalUnit))]; SO3ObjectSetScale vline [(0.01 *. (itof iGlobalUnit)) (0.01 *. (itof iGlobalUnit)) (0.01 *. (itof iGlobalUnit))]; SO3ObjectLink hline node; SO3ObjectLink vline node; SO3ObjectSetCastShadows hline 0; SO3ObjectSetCastShadows vline 0; SO3ObjectSetPosition hline [0.0 0.0 (itof i)]; SO3ObjectSetPosition vline [(itof i) 0.0 0.0]; set lobj = hline::vline::lobj; ); set i = i + iGlobalUnit; ); set sessionstr.V3D_helperGrid = [node lobj]; ); 0; ) else if (sessionstr.V3D_helperGrid != nil) then let sessionstr.V3D_helperGrid -> [node lobj] in ( let sizelist lobj -> size in let 0 -> i in while i < size do ( let nth_list lobj i -> obj in SO3ObjectDestroy obj; set i = i + 1; ); SO3ObjectDestroy node; set sessionstr.V3D_helperGrid = nil; 0; ) else nil; 0;; fun V3DcameraPan(sessionstr, viewportstr, x, y) = let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3CameraGetFOVy camera -> fovy in let if fovy <=. 0.0 then 0.000001 else fovy -> fovy in let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [vx vy vw vh] in let SO3ObjectGetPosition camera -> [_ _ dist] in let ((itof vw)) /. atan fovy -> dx in let ((-.dist *. ((itof vw))) /. dx /. ((itof vh))) -> coef in let (itof x) *. coef -> mx in let (itof y) *. coef -> my in let [mx my 0.0] -> vect in SO3ObjectTranslate sessionstr.V3D_shellNavigate vect SO3_LOCAL_TS; 0;; fun V3DsetShellNavPos(sessionstr, pos)= SO3ObjectSetPosition sessionstr.V3D_shellNavigate pos; 0;; fun V3DchangeCameraViewport(sessionstr, viewportstr, camera)= let if viewportstr == nil then V3DgetDefaultViewport (V3DgetSessionView sessionstr) else viewportstr -> viewportstr in V3DsetViewport (V3DgetSessionView sessionstr) viewportstr sessionstr camera; 0;; fun V3DsetAmbientLight(sessionstr, color) = SO3SceneSetAmbientLight (V3DgetSession sessionstr) color; 0;; fun V3DgetAmbientLight(sessionstr) = SO3SceneGetAmbientLight (V3DgetSession sessionstr);; fun V3DsetShadowTechnique(sessionstr, type, dist, color, self)= SO3SceneSetShadowTechnique (V3DgetSession sessionstr) (if type == nil then SO3_SHADOWTYPE_NONE else type); SO3SceneSetShadowFarDistance (V3DgetSession sessionstr) (if dist == nil then 3000.0 else dist); SO3SceneSetShadowColor (V3DgetSession sessionstr) (if color == nil then 0x000000 else color); SO3SceneSetSelfShadowTexture (V3DgetSession sessionstr) (if self == nil then 1 else self); 0;; fun V3DsetShadowCameraType(sessionstr, camtype, px, py, pz, pd)= if camtype == SO3_PLANE_SHADOW_CAMERA then ( SO3SceneSetPlaneShadowCamera (V3DgetSession sessionstr) [px py pz] pd; ) else if camtype == SO3_FOCUSED_SHADOW_CAMERA then ( SO3SceneSetFocusedShadowCamera (V3DgetSession sessionstr); ) else // SO3_DEFAULT_SHADOW_CAMERA ( SO3SceneSetDefaultShadowCamera (V3DgetSession sessionstr); ); 0;; fun V3DgetShadowCameraType(sessionstr)= SO3SceneGetShadowCameraSetup (V3DgetSession sessionstr);; fun V3DsetShadowTextureParams(sessionstr, size, count, offset, fadestart, fadestop)= SO3SceneSetShadowTextureSize (V3DgetSession sessionstr) (if size == nil then 512 else size); SO3SceneSetShadowTextureCount (V3DgetSession sessionstr) (if count == nil then 1 else count); SO3SceneSetShadowDirLightTextureOffset (V3DgetSession sessionstr) (if offset == nil then 0.0 else offset); SO3SceneSetShadowTextureFadeStart (V3DgetSession sessionstr) (if fadestart == nil then 0.7 else fadestart); SO3SceneSetShadowTextureFadeEnd (V3DgetSession sessionstr) (if fadestop == nil then 0.9 else fadestop); 0;; fun V3DsetSceneFog(sessionstr, mode, color, density, linearstart, linearend)= let if mode != nil then mode else SO3SceneGetFogMode (V3DgetSession sessionstr) -> mode in let if color != nil then color else SO3SceneGetFogColor (V3DgetSession sessionstr) -> color in let if density != nil then density else SO3SceneGetFogDensity (V3DgetSession sessionstr) -> density in let if linearstart != nil then linearstart else SO3SceneGetFogStart (V3DgetSession sessionstr) -> linearstart in let if linearend != nil then linearend else SO3SceneGetFogEnd (V3DgetSession sessionstr) -> linearend in SO3SceneSetFog (V3DgetSession sessionstr) mode color density linearstart linearend; 0;; /* ********************************************************************************************* / RENDER / ********************************************************************************************* */ fun cbV3DscenePreRender(session, sessionstr, etime, viewstr)= let _GETdesktopSize -> [sw sh] in let [viewstr.V3D_iMoveX-(viewstr.V3D_iWinW>>1) (viewstr.V3D_iWinH>>1)-viewstr.V3D_iMoveY] -> [x y] in ( // Camera rotation on mouse drag if (viewstr.V3D_iMoveClickStatus != 1) || (!sessionstr.V3D_bNavigate) || (sessionstr.V3D_selectedAxis != nil) then nil else let if viewstr.V3D_iRenderMoveX == nil then viewstr.V3D_iClickX else viewstr.V3D_iRenderMoveX -> mvx in let if viewstr.V3D_iRenderMoveY == nil then viewstr.V3D_iClickY else viewstr.V3D_iRenderMoveY -> mvy in let [(viewstr.V3D_iMoveX-mvx) (mvy-viewstr.V3D_iMoveY)] -> [dx dy] in let 3.14159265 /. ((itof sw) /. 2.0) *. (itof dx) -> fdx in let 3.14159265 /. ((itof sh) /. 2.0) *. (itof -dy) -> fdy in ( SO3ObjectRotateYaw sessionstr.V3D_shellNavigate (-. fdx) SO3_WORLD_TS; SO3ObjectRotatePitch sessionstr.V3D_shellNavigate (-. fdy) SO3_LOCAL_TS; ); if (viewstr.V3D_iMoveClickStatus != 16) || (!sessionstr.V3D_bNavigate) then nil else ( let if viewstr.V3D_iRenderMoveX == nil then viewstr.V3D_iClickX else viewstr.V3D_iRenderMoveX -> mvx in let if viewstr.V3D_iRenderMoveY == nil then viewstr.V3D_iClickY else viewstr.V3D_iRenderMoveY -> mvy in let [(viewstr.V3D_iMoveX-mvx) (mvy-viewstr.V3D_iMoveY)] -> [dx dy] in V3DcameraPan sessionstr V3DgetDefaultViewport viewstr dx dy; ); let SO3BufferGetAverageFPS viewstr.V3D_buffer -> avfps in let sizelist viewstr.V3D_lViewport -> vsize in let 0 -> v in while v < vsize do ( let nth_list viewstr.V3D_lViewport v -> [_ viewportstr] in if !(SO3DebugGetEnable viewportstr.V3D_viewport) then nil else let if (avfps <=. 0.0) then 0.0 else (1000.0 /. avfps) -> frametime in SO3DebugSetText viewportstr.V3D_viewport strcatn "FPS: "::(itoa (ftoi avfps))::"\n"::"Frametime (ms): "::(ftoa2d frametime)::"\n"::"Polygon count: "::(itoa SO3BufferGetTriangleCount viewstr.V3D_buffer)::"\n"::nil; set v = v + 1; ); ); set viewstr.V3D_iRenderTick = _tickcount; V3DupdateAxisTarget viewstr sessionstr; V3DupdateHelpersTarget viewstr sessionstr; set viewstr.V3D_iRenderMoveX = viewstr.V3D_iMoveX; set viewstr.V3D_iRenderMoveY = viewstr.V3D_iMoveY; 0;; fun cbV3DscenePostRender(session, sessionstr, etime, viewstr)= 0;; fun cbV3DbufferPreRender(buffer, viewstr)= exec viewstr.V3D_cbPreRender with [viewstr]; if viewstr.V3D_bPaused then nil else exec viewstr.V3D_cbPreRenderEffects with [viewstr]; 0;; fun cbV3DbufferPostRender(buffer, viewstr)= exec viewstr.V3D_cbPostRender with [viewstr]; 0;; fun cbV3Drender(viewstr)= 0;; fun cbV3DtickRender(tmr, viewstr)= cbV3Drender viewstr; 0;; fun V3DdeleteSession(viewstr, sessionstr)= if sessionstr == nil then nil else ( SO3SceneDelete (V3DgetSession sessionstr); let V3DgetSessionIndex viewstr sessionstr -> idx in set viewstr.V3D_lSessions = V3DremoveIdxFromList viewstr.V3D_lSessions idx; ); 0;; fun V3DcrSession(viewstr, name)= let let 0 -> i in ( while ((switch viewstr.V3D_lSessions i) != nil) do ( set i = i + 1; ); i; ) -> idx in let mkV3Dsession [viewstr nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil] -> sessionstr in ( set viewstr.V3D_lSessions = V3Dlcat viewstr.V3D_lSessions [idx sessionstr]::nil; // create the new scene set sessionstr.V3D_session = SO3SceneCreate viewstr.V3D_channel strcatn (itoa iV3DSessionIndex)::"."::name::nil; set iV3DSessionIndex = iV3DSessionIndex + 1; set sessionstr.V3D_bHelpersState = 0; SO3GroupCreate (V3DgetSession sessionstr) "VoyagerDefaultResources"; // create the default camera V3DaddCamera sessionstr "default_camera"; // create a shell set sessionstr.V3D_shellNavigate = SO3SceneNodeCreate (V3DgetSession sessionstr) "camshell"; // set the shell position SO3ObjectSetPosition sessionstr.V3D_shellNavigate [0.0 0.0 0.0]; // link the camera to the shell SO3ObjectLink (V3DgetDefaultCamera sessionstr) sessionstr.V3D_shellNavigate; // define that the camera always look at this point //SO3ObjectLookAt (V3DgetDefaultCamera sessionstr) [0.0 0.0 0.0] 2; SO3ObjectSetPosition (V3DgetDefaultCamera sessionstr) [0.0 0.0 (5.0 *. itof(iGlobalUnit))]; // set the ambient light color V3DsetAmbientLight sessionstr 0x000000; set sessionstr.V3D_bNavigate = 0; // helpers resources SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helpers.material") SO3_RESOURCE_MATERIAL; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_x.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_y.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_z.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_x.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_y.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_z.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_x.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_y.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_z.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_camera.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_dummy.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_light.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/default_grid_helper.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/h_line_b.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/h_line_w.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/v_line_b.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/v_line_w.mesh") SO3_RESOURCE_MESH; SO3CbScenePreRender (V3DgetSession sessionstr) mkfun4 @cbV3DscenePreRender viewstr sessionstr; SO3CbScenePostRender (V3DgetSession sessionstr) mkfun4 @cbV3DscenePostRender viewstr sessionstr; sessionstr; );; fun V3DresetSession(sessionstr)= SO3SceneClear (V3DgetSession sessionstr); SO3GroupDelete (V3DgetSession sessionstr) "VoyagerDefaultResources"; set sessionstr.V3D_lCamera = nil; set sessionstr.V3D_lAxis = nil; set sessionstr.V3D_lHelper = nil; set sessionstr.V3D_shellNavigate = nil; set sessionstr.V3D_lAnimations = nil; set sessionstr.V3D_prevDefaultCamera = nil; set sessionstr.V3D_defaultCamera = nil; SO3GroupCreate (V3DgetSession sessionstr) "VoyagerDefaultResources"; V3DsetCamera (V3DaddCamera sessionstr "default_camera") nil nil 0.01 nil; // create a shell set sessionstr.V3D_shellNavigate = SO3SceneNodeCreate (V3DgetSession sessionstr) "camshell"; // set the shell position SO3ObjectSetPosition sessionstr.V3D_shellNavigate [0.0 0.0 0.0]; // link the camera to the shell SO3ObjectLink (V3DgetDefaultCamera sessionstr) sessionstr.V3D_shellNavigate; SO3ObjectSetPosition (V3DgetDefaultCamera sessionstr) [0.0 0.0 (5.0 *. itof(iGlobalUnit))]; V3DchangeCameraViewport sessionstr nil (V3DgetDefaultCamera sessionstr); // helpers resources SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helpers.material") SO3_RESOURCE_MATERIAL; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_x.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_y.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/ang_axis_z.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_x.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_y.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_z.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_x.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_y.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/coords_axis_text_z.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_camera.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_dummy.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/helper_light.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/default_grid_helper.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/h_line_b.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/h_line_w.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/v_line_b.mesh") SO3_RESOURCE_MESH; SO3SceneLoadResource (V3DgetSession sessionstr) "VoyagerDefaultResources" _checkpack (strcat sVoyagerDefaultResourcesPATH "helpers/v_line_w.mesh") SO3_RESOURCE_MESH; if sessionstr.V3D_helperGrid == nil then nil else ( set sessionstr.V3D_helperGrid = nil; V3DshowSceneGrid sessionstr 1; ); 0;; fun cbV3DkillFocus(win, viewstr)= if !viewstr.V3D_iClickStatus then nil else ( if viewstr.V3D_iClickX == nil || viewstr.V3D_iClickY == nil then nil else exec viewstr.V3D_cbUnClick with [viewstr viewstr.V3D_iClickX viewstr.V3D_iClickY viewstr.V3D_iClickStatus]; set viewstr.V3D_iClickStatus = V3DCLICK_NO; ); if !viewstr.V3D_iMoveClickStatus then nil else ( if viewstr.V3D_iMoveX == nil || viewstr.V3D_iMoveY == nil then nil else exec viewstr.V3D_cbUnClick with [viewstr viewstr.V3D_iMoveX viewstr.V3D_iMoveY viewstr.V3D_iMoveClickStatus]; set viewstr.V3D_iMoveClickStatus = V3DCLICK_NO; ); 0;; fun V3DviewSetFocus(viewstr)= _SETfocus viewstr.V3D_win; 0;; fun cbV3DviewKeyDown(buffer, viewstr, key, ascode)= if key == 328 then // UP ( let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in if !sessionstr.V3D_bNavigate then nil else ( SO3ObjectRotatePitch sessionstr.V3D_shellNavigate (-.0.1) SO3_LOCAL_TS; ); set i = i + 1; ); ) else nil; if key == 336 then // DOWN ( let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in if !sessionstr.V3D_bNavigate then nil else ( SO3ObjectRotatePitch sessionstr.V3D_shellNavigate (0.1) SO3_LOCAL_TS; ); set i = i + 1; ); ) else nil; if key == 331 then // LEFT ( let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in if !sessionstr.V3D_bNavigate then nil else ( SO3ObjectRotateYaw sessionstr.V3D_shellNavigate (-.0.1) SO3_WORLD_TS; ); set i = i + 1; ); ) else nil; if key == 333 then // RIGHT ( let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in if !sessionstr.V3D_bNavigate then nil else ( SO3ObjectRotateYaw sessionstr.V3D_shellNavigate (0.1) SO3_WORLD_TS; ); set i = i + 1; ); ) else nil; if key == 60 then // F2 ( let SO3BufferGetStereoMode viewstr.V3D_buffer -> mode in if (mode == SO3_SM_NONE) then SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_ANAGLYPH_RC else if (mode == SO3_SM_ANAGLYPH_RC) then SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_ANAGLYPH_YB else if (mode == SO3_SM_ANAGLYPH_YB) then SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_INTERLACED_H else if (mode == SO3_SM_INTERLACED_H) then SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_INTERLACED_V else if (mode == SO3_SM_INTERLACED_V) then SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_INTERLACED_CB else if (mode == SO3_SM_INTERLACED_CB) then SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_SIDE_BY_SIDE else if (mode == SO3_SM_SIDE_BY_SIDE) then SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_UP_DOWN else if (mode == SO3_SM_UP_DOWN) then SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_QUAD_BUFFER else SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_NONE; SO3BufferSetStereoEyeSpacing viewstr.V3D_buffer 0.06; ) else nil; exec viewstr.V3D_cbKeyDown with [viewstr key ascode]; 0;; fun cbV3DviewKeyUp(buffer, viewstr, key)= exec viewstr.V3D_cbKeyUp with [viewstr key]; 0;; fun cbV3DviewDbClick(buffer, viewstr, posx, posy, btn)= exec viewstr.V3D_cbDbClick with [viewstr posx posy btn]; 0;; fun cbV3DviewClick(buffer, viewstr, posx, posy, btn)= V3DviewSetFocus viewstr; set viewstr.V3D_iClickX = posx; set viewstr.V3D_iClickY = posy; set viewstr.V3D_iClickStatus = if btn == nil then V3DCLICK_NO else btn; let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in if sessionstr.V3D_selectedAxis != nil then nil else let SO3BufferGetLastMouseInfos viewstr.V3D_buffer -> infos in let infos -> [_ _ obj mat _ _ _ _ _] in let sizelist sessionstr.V3D_lAxis -> size2 in let 0 -> i2 in while (i2 < size2) && (sessionstr.V3D_selectedAxis == nil) do ( let nth_list sessionstr.V3D_lAxis i2 -> [_ axisstr] in if obj == axisstr.V3D_xAxisObject then ( set sessionstr.V3D_selectedAxis = [axisstr V3DAXIS_X]; exec sessionstr.V3D_cbAxisClick with [sessionstr axisstr.V3D_axisFather V3DAXIS_X posx posy btn]; ) else if obj == axisstr.V3D_yAxisObject then ( set sessionstr.V3D_selectedAxis = [axisstr V3DAXIS_Y]; exec sessionstr.V3D_cbAxisClick with [sessionstr axisstr.V3D_axisFather V3DAXIS_Y posx posy btn] ) else if obj == axisstr.V3D_zAxisObject then ( set sessionstr.V3D_selectedAxis = [axisstr V3DAXIS_Z]; exec sessionstr.V3D_cbAxisClick with [sessionstr axisstr.V3D_axisFather V3DAXIS_Z posx posy btn] ) else nil; set i2 = i2 + 1; ); set i = i + 1; ); exec viewstr.V3D_cbClick with [viewstr posx posy btn]; 0;; fun V3DgetCursorTrans(viewstr)= if viewstr.V3D_iMoveClickStatus & (V3DCLICK_LEFT|V3DCLICK_RIGHT|V3DCLICK_MIDDLE) then [(viewstr.V3D_iMoveX-viewstr.V3D_iClickX) (viewstr.V3D_iClickY-viewstr.V3D_iMoveY)] else nil;; fun V3DisClicked(viewstr)= viewstr.V3D_iClickStatus;; fun V3DisMoveClicked(viewstr)= viewstr.V3D_iMoveClickStatus;; fun cbV3DviewUnclick(buffer, viewstr, posx, posy, btn) = if viewstr.V3D_iClickStatus == V3DCLICK_NO && viewstr.V3D_iMoveClickStatus == V3DCLICK_NO then nil else ( set viewstr.V3D_iClickStatus = V3DCLICK_NO; set viewstr.V3D_iMoveClickStatus = V3DCLICK_NO; set viewstr.V3D_iRenderMoveX = nil; set viewstr.V3D_iRenderMoveY = nil; let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in if sessionstr.V3D_selectedAxis == nil then nil else let sessionstr.V3D_selectedAxis -> [axisstr axisflag] in ( exec sessionstr.V3D_cbAxisUnClick with [sessionstr axisstr.V3D_axisFather axisflag posx posy btn]; set sessionstr.V3D_selectedAxis = nil; ); set i = i + 1; ); exec viewstr.V3D_cbUnClick with [viewstr posx posy btn]; ); 0;; fun cbV3DviewWheel(buffer, viewstr, posx, posy, delta, btn)= let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in if !sessionstr.V3D_bNavigate then nil else let if iGlobalUnit > 1 then ((itof iGlobalUnit) /. 10.0) else (itof iGlobalUnit) -> unitdiv in ( let SO3ObjectGetPosition (V3DgetDefaultCamera sessionstr) -> [_ _ z] in let ((itof -delta) *. (((absf z) +. 10.0) /. (100.0 /. unitdiv)) ) -> zm in if zm <. 0.0 && z <=. 0.0 then nil else SO3ObjectSetPosition (V3DgetDefaultCamera sessionstr) [0.0 0.0 z +. zm]; 0; ); set i = i + 1; ); exec viewstr.V3D_cbWheel with [viewstr posx posy delta btn]; 0;; fun V3DgetMoveAxis(viewstr, posx, posy, btn) = let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in if sessionstr.V3D_lAxis == nil then nil else ( let SO3BufferGetLastMouseInfos viewstr.V3D_buffer -> infos in let infos -> [_ _ obj mat _ _ _ _ _] in if sessionstr.V3D_selectedAxis != nil then let sessionstr.V3D_selectedAxis -> [selectedaxisstr axisflag] in let (V3DgetDefaultViewport viewstr) -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let SO3ObjectGetGlobalPosition camera -> [cx cy cz] in let SO3ObjectGetGlobalPosition selectedaxisstr.V3D_axisFather -> [ox oy oz] in let SO3CameraGetFOVy camera -> fovy in let if fovy <=. 0.0 then 0.000001 else fovy -> fovy in let if axisflag == V3DAXIS_X then [selectedaxisstr.V3D_xAxisObject selectedaxisstr.V3D_xAxisTextObject] else if axisflag == V3DAXIS_Y then [selectedaxisstr.V3D_yAxisObject selectedaxisstr.V3D_yAxisTextObject] else if axisflag == V3DAXIS_Z then [selectedaxisstr.V3D_zAxisObject selectedaxisstr.V3D_zAxisTextObject] else nil -> [axisobj letterobj] in let SO3ObjectGetScreenPixelCoord axisobj viewportstr.V3D_viewport -> [shpx shpy] in let SO3ObjectGetScreenPixelCoord letterobj viewportstr.V3D_viewport -> [lhpx lhpy] in let [(itof (lhpx-shpx)) (itof (lhpy-shpy))] -> [u v] in let [(posx - viewstr.V3D_iMoveX) (posy - viewstr.V3D_iMoveY)] -> [mvx mvy] in let sqrt ((sqr(cx -. ox)) +. (sqr(cy -. oy)) +. (sqr(cz -. oz))) -> dist in let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ vw vh] in // TODO find the real algo ! use global scale ? let maxf 0.000001 ((dist /. (itof vh)) *. fovy) *. 98.5 -> scale in let SO3ObjectGetParent selectedaxisstr.V3D_axisFather -> ofather in let if ofather == (SO3ObjectGetSceneRoot (V3DgetSession sessionstr)) then [1.0 1.0 1.0] else SO3ObjectGetGlobalScale ofather -> [gsx gsy gsz] in //let SO3ObjectGetGlobalScale selectedaxisstr.V3D_axisFather -> [gsx gsy gsz] in let if axisflag == V3DAXIS_X then gsx else if axisflag == V3DAXIS_Y then gsy else if axisflag == V3DAXIS_Z then gsz else 1.0 -> gscale in let ((scale *. (u *. (itof mvx) +. v *. (itof mvy))) /. sqr(0.001+.sqrt((sqr u)+.(sqr v)))) /. gscale -> coef in ( if u == nil || v == nil then nil else exec sessionstr.V3D_cbAxisMove with [sessionstr selectedaxisstr.V3D_axisFather axisflag mvx mvy btn coef]; 0; ) else ( let sizelist sessionstr.V3D_lAxis -> size2 in let 0 -> i2 in while i2 < size2 do ( let nth_list sessionstr.V3D_lAxis i2 -> [_ axisstr] in ( if obj == axisstr.V3D_xAxisObject then ( let hd (SO3EntityMaterialList axisstr.V3D_xAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 255 255 0 0); SO3MaterialSetAmbient mat (make_rgba 255 255 0 0); SO3MaterialSetDiffuse mat (make_rgba 255 255 0 0); ); let hd (SO3EntityMaterialList axisstr.V3D_yAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 0 255 0 0); SO3MaterialSetAmbient mat (make_rgba 0 255 0 0); SO3MaterialSetDiffuse mat (make_rgba 0 255 0 0); ); let hd (SO3EntityMaterialList axisstr.V3D_zAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 0 0 255 0); SO3MaterialSetAmbient mat (make_rgba 0 0 255 0); SO3MaterialSetDiffuse mat (make_rgba 0 0 255 0); ); 0; ) else if obj == axisstr.V3D_yAxisObject then ( let hd (SO3EntityMaterialList axisstr.V3D_xAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 255 0 0 0); SO3MaterialSetAmbient mat (make_rgba 255 0 0 0); SO3MaterialSetDiffuse mat (make_rgba 255 0 0 0); ); let hd (SO3EntityMaterialList axisstr.V3D_yAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 255 255 0 0); SO3MaterialSetAmbient mat (make_rgba 255 255 0 0); SO3MaterialSetDiffuse mat (make_rgba 255 255 0 0); ); let hd (SO3EntityMaterialList axisstr.V3D_zAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 0 0 255 0); SO3MaterialSetAmbient mat (make_rgba 0 0 255 0); SO3MaterialSetDiffuse mat (make_rgba 0 0 255 0); ); 0; ) else if obj == axisstr.V3D_zAxisObject then ( let hd (SO3EntityMaterialList axisstr.V3D_xAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 255 0 0 0); SO3MaterialSetAmbient mat (make_rgba 255 0 0 0); SO3MaterialSetDiffuse mat (make_rgba 255 0 0 0); ); let hd (SO3EntityMaterialList axisstr.V3D_yAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 0 255 0 0); SO3MaterialSetAmbient mat (make_rgba 0 255 0 0); SO3MaterialSetDiffuse mat (make_rgba 0 255 0 0); ); let hd (SO3EntityMaterialList axisstr.V3D_zAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 255 255 0 0); SO3MaterialSetAmbient mat (make_rgba 255 255 0 0); SO3MaterialSetDiffuse mat (make_rgba 255 255 0 0); ); 0; ) else ( let hd (SO3EntityMaterialList axisstr.V3D_xAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 255 0 0 0); SO3MaterialSetAmbient mat (make_rgba 255 0 0 0); SO3MaterialSetDiffuse mat (make_rgba 255 0 0 0); ); let hd (SO3EntityMaterialList axisstr.V3D_yAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 0 255 0 0); SO3MaterialSetAmbient mat (make_rgba 0 255 0 0); SO3MaterialSetDiffuse mat (make_rgba 0 255 0 0); ); let hd (SO3EntityMaterialList axisstr.V3D_zAxisObject) -> mat in ( SO3MaterialSetSelfIllumination mat (make_rgba 0 0 255 0); SO3MaterialSetAmbient mat (make_rgba 0 0 255 0); SO3MaterialSetDiffuse mat (make_rgba 0 0 255 0); ); 0; ); ); set i2 = i2 + 1; ); 0; ); ); set i = i + 1; ); 0;; fun cbV3DcursorMove(win, viewstr, posx, posy, btn) = let if viewstr.V3D_iClickStatus == V3DCLICK_NO then nil else btn -> btn in ( set viewstr.V3D_iMoveClickStatus = if btn == nil then V3DCLICK_NO else btn; V3DgetMoveAxis viewstr posx posy btn; set viewstr.V3D_iMoveX = posx; set viewstr.V3D_iMoveY = posy; exec viewstr.V3D_cbCursorMove with [viewstr posx posy btn]; ); 0;; fun V3DsetCbResizeView(viewstr, cbfun)= set viewstr.V3D_cbResizeView = cbfun; 0;; fun V3DsetCbPreRenderEffects(viewstr, cbfun)= set viewstr.V3D_cbPreRenderEffects = cbfun; 0;; fun V3DsetCbPreRender(viewstr, cbfun)= set viewstr.V3D_cbPreRender = cbfun; 0;; fun V3DsetCbPostRender(viewstr, cbfun)= set viewstr.V3D_cbPostRender = cbfun; 0;; fun V3DsetCbKeyDown(viewstr, cbfun)= set viewstr.V3D_cbKeyDown = cbfun; 0;; fun V3DsetCbKeyUp(viewstr, cbfun)= set viewstr.V3D_cbKeyUp = cbfun; 0;; fun V3DsetCbClick(viewstr, cbfun)= set viewstr.V3D_cbClick = cbfun; 0;; fun V3DgetCbClick(viewstr)= viewstr.V3D_cbClick;; fun V3DsetCbDbClick(viewstr, cbfun)= set viewstr.V3D_cbDbClick = cbfun; 0;; fun V3DgetCbDbClick(viewstr)= viewstr.V3D_cbDbClick;; fun V3DsetCbUnClick(viewstr, cbfun)= set viewstr.V3D_cbUnClick = cbfun; 0;; fun V3DgetCbUnClick(viewstr)= viewstr.V3D_cbUnClick;; fun V3DsetCbWheel(viewstr, cbfun)= set viewstr.V3D_cbWheel = cbfun; 0;; fun V3DgetCbWheel(viewstr)= viewstr.V3D_cbWheel;; fun V3DsetCbCursorMove(viewstr, cbfun)= set viewstr.V3D_cbCursorMove = cbfun; 0;; fun V3DgetCbCursorMove(viewstr)= viewstr.V3D_cbCursorMove;; fun V3DsetCbAxisMove(sessionstr, cbfun)= set sessionstr.V3D_cbAxisMove = cbfun; 0;; fun V3DsetCbAxisClick(sessionstr, cbfun)= set sessionstr.V3D_cbAxisClick = cbfun; 0;; fun V3DsetCbAxisUnClick(sessionstr, cbfun)= set sessionstr.V3D_cbAxisUnClick = cbfun; 0;; fun V3DenableKeyboard(viewstr, mode)= set viewstr.V3D_bKeyboardEnabled = mode; if !mode then ( _CBwinKeydown viewstr.V3D_win nil nil; _CBwinKeyup viewstr.V3D_win nil nil; ) else ( _CBwinKeydown viewstr.V3D_win @cbV3DviewKeyDown viewstr; _CBwinKeyup viewstr.V3D_win @cbV3DviewKeyUp viewstr; ); 0;; fun V3DenableMouse(viewstr, mode)= set viewstr.V3D_bMouseEnabled = mode; if !mode then ( _CBwinClick viewstr.V3D_win nil nil; _CBwinUnclick viewstr.V3D_win nil nil; _CBwinWheel viewstr.V3D_win nil nil; _CBcursorMove viewstr.V3D_win nil nil; _CBwinDClick viewstr.V3D_win nil nil; ) else ( _CBwinClick viewstr.V3D_win @cbV3DviewClick viewstr; _CBwinUnclick viewstr.V3D_win @cbV3DviewUnclick viewstr; _CBwinWheel viewstr.V3D_win @cbV3DviewWheel viewstr; _CBcursorMove viewstr.V3D_win @cbV3DcursorMove viewstr; _CBwinDClick viewstr.V3D_win @cbV3DviewDbClick viewstr; ); 0;; fun V3DenableNavigate(sessionstr, mode)= set sessionstr.V3D_bNavigate = mode; 0;; fun V3DsetCursor(viewstr, cursor)= _SETwinCursor viewstr.V3D_win cursor; 0;; fun cbV3Dsize(win, viewstr, w, h)= if w == 0 || h == 0 then nil else ( set viewstr.V3D_iWinW = w; set viewstr.V3D_iWinH = h; exec viewstr.V3D_cbResizeView with [viewstr w h]; ); 0;; fun V3DresizeView(viewstr, x, y, w, h)= set viewstr.V3D_iWinX = x; set viewstr.V3D_iWinY = y; set viewstr.V3D_iWinW = w; set viewstr.V3D_iWinH = h; _SIZEwindow viewstr.V3D_win viewstr.V3D_iWinW viewstr.V3D_iWinH viewstr.V3D_iWinX viewstr.V3D_iWinY; 0;; fun V3DgetViewPosSize(viewstr)= [viewstr.V3D_iWinX viewstr.V3D_iWinY viewstr.V3D_iWinW viewstr.V3D_iWinH];; fun V3DgetViewPos(viewstr)= [viewstr.V3D_iWinX viewstr.V3D_iWinY];; fun V3DgetViewSize(viewstr)= [viewstr.V3D_iWinW viewstr.V3D_iWinH];; fun V3DgetFullScreenState(viewstr)= viewstr.V3D_bFullScreen;; fun V3DsetScreenInfos(viewstr, x, y, width, height, fsize, fcolor)= let fcolor & 255 -> r in let (fcolor>>8) & 255 -> g in let (fcolor>>16) & 255 -> b in let make_rgba r g b 127 -> crgba in let V3DgetDefaultSession viewstr -> sessionstr in let V3DgetDefaultViewport viewstr -> viewportstr in SO3DebugDisplayProperties (V3DgetSession sessionstr) viewportstr.V3D_viewport nil crgba [x y] [width height] fsize; 0;; fun V3DenableScreenInfos(viewstr, state)= let V3DgetDefaultSession viewstr -> sessionstr in let V3DgetDefaultViewport viewstr -> viewportstr in ( SO3DebugSetEnable viewportstr.V3D_viewport state; SO3WorldShowLines (V3DgetSession sessionstr) state; ); 0;; fun V3DsetWindowedMode(viewstr)= if !viewstr.V3D_bFullScreen then nil else ( set viewstr.V3D_iWinW = viewstr.V3D_iOldWinW; set viewstr.V3D_iWinH = viewstr.V3D_iOldWinH; //_SHOWwindow viewstr.V3D_win WINDOW_UNHIDDEN; SO3BufferSetProperties viewstr.V3D_buffer 0 viewstr.V3D_iWinW viewstr.V3D_iWinH; V3DviewSetFocus viewstr; set viewstr.V3D_bFullScreen = 0; ); 0;; fun V3DEnableRender(viewstr, state)= set viewstr.V3D_bState = state; 0;; fun V3DenableView(viewstr, mode)= if mode then ( _SHOWwindow viewstr.V3D_win WINDOW_UNHIDDEN; V3DEnableRender viewstr 1; ) else if !mode then ( _SHOWwindow viewstr.V3D_win WINDOW_HIDDEN; V3DEnableRender viewstr 0; ) else nil; 0;; fun V3DsetFullScreenMode(viewstr, w, h)= if viewstr.V3D_bFullScreen then nil else ( //_SHOWwindow viewstr.V3D_win WINDOW_HIDDEN; set viewstr.V3D_iOldWinW = viewstr.V3D_iWinW; set viewstr.V3D_iOldWinH = viewstr.V3D_iWinH; set viewstr.V3D_iWinW = w; set viewstr.V3D_iWinH = h; SO3BufferSetProperties viewstr.V3D_buffer 1 viewstr.V3D_iWinW viewstr.V3D_iWinH; set viewstr.V3D_bFullScreen = 1; ); 0;; fun V3DswitchFullScreenMode(viewstr, w, h)= if viewstr.V3D_bFullScreen then V3DsetWindowedMode viewstr else V3DsetFullScreenMode viewstr w h; 0;; fun V3DcrView(chan, fatherwin, ix, iy, iw, ih, cbinit, cbdestroy, defview)= let mkV3Dview [nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil 0 1] -> viewstr in let _CRwindow chan fatherwin ix iy iw ih WN_CHILDINSIDE|WN_NOCAPTION|WN_NOBORDER strcatn (itoa iV3DIndex)::".v3dwin"::nil -> win in ( set viewstr.V3D_channel = chan; // set the buffer window set viewstr.V3D_buffer = SO3BufferCreate chan win 0 0 iw ih; SO3CbBufferPreRender viewstr.V3D_buffer @cbV3DbufferPreRender viewstr; SO3CbBufferPostRender viewstr.V3D_buffer @cbV3DbufferPostRender viewstr; _SHOWwindow win WINDOW_HIDDEN; _CBwinKillFocus win @cbV3DkillFocus viewstr; _CBwinSize win @cbV3Dsize viewstr; set viewstr.V3D_win = win; set viewstr.V3D_iWinW = iw; set viewstr.V3D_iWinH = ih; set viewstr.V3D_iWinX = ix; set viewstr.V3D_iWinY = iy; set viewstr.V3D_iMoveClickStatus = V3DCLICK_NO; set viewstr.V3D_iClickStatus = V3DCLICK_NO; set viewstr.V3D_bMouseEnabled = 0; set viewstr.V3D_bKeyboardEnabled = 0; set viewstr.V3D_bPaused = 0; set viewstr.V3D_iRenderTick = _tickcount; set viewstr.V3D_cbDestroy = cbdestroy; set viewstr.V3D_cbInit = cbinit; // default session if !defview then nil else V3DcrSession viewstr "main"; set iV3DIndex = iV3DIndex + 1; exec viewstr.V3D_cbInit with [viewstr]; viewstr; );; fun V3DdsView(viewstr)= let sizelist viewstr.V3D_lViewport -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lViewport i -> [_ viewportstr] in V3DdelViewport viewstr viewportstr; set i = i + 1; ); let sizelist viewstr.V3D_lSessions -> size in let 0 -> i in while i < size do ( let nth_list viewstr.V3D_lSessions i -> [_ sessionstr] in ( SO3GroupDelete (V3DgetSession sessionstr) "VoyagerDefaultResources"; SO3SceneDelete (V3DgetSession sessionstr); ); set i = i + 1; ); SO3DestroyBuffer viewstr.V3D_buffer; if viewstr.V3D_win == nil then nil else _DSwindow viewstr.V3D_win; exec viewstr.V3D_cbDestroy with [viewstr]; 0;; fun cbV3DdsMainWin(win, viewstr)= V3DdsView viewstr; _closemachine; 0;; fun cbV3DsizeMainWin(win, viewstr, w, h)= V3DresizeView viewstr viewstr.V3D_iWinX viewstr.V3D_iWinY w h; 0;;