// - Mouse - var MVCLICK_NO = 0;; var MVCLICK_YES = 1;; var CLICK_NO = 0;; var CLICK_YES = 1;; // Frames handling var iTheoFramerate = 128;; // Maximum possible framerate // - Struct 3D - struct T3dView = [ VIEW_win : ObjWin, VIEW_iWinW : I, VIEW_iWinH : I, VIEW_lScene : [S r1], VIEW_session : S3d, /* session */ VIEW_buffer : ObjSurface, VIEW_shell : H3d, VIEW_lightShell : H3d, VIEW_light : H3d, VIEW_cameraShell : H3d, VIEW_camera : H3d, VIEW_bgColor : I, VIEW_iClickStatus : I, VIEW_iClickX : I, VIEW_iClickY : I, VIEW_iMoveX : I, VIEW_iMoveY : I, VIEW_iMoveClickStatus : I, VIEW_trmRender : Timer, VIEW_font3D : ObjFont, VIEW_AVANIM : TAV3DANIM, VIEW_cbRender : fun [T3dView] I, VIEW_cbInit : fun [T3dView] I, VIEW_fps : I, VIEW_frameRate : I, // FPS VIEW_iCountFrame : I, VIEW_iResultFPS : I, VIEW_IFps : I ]mk3dView;; // - Struct Anims - struct TAV3DANIM = [ AV3DANIM_H3d : H3d, /* H3d */ AV3DANIM_Mesh : H3d, /* H3d */ AV3DANIM_file : S, AV3DANIM_actif : I, /* vaut 1 si l'animation est active et 0 si non. */ AV3DANIM_lecture : I, /* vaut 0 si l'animation est stoppée, 1 si lecture simple, 2 si boucle */ AV3DANIM_startframe : I, AV3DANIM_stopframe : I, AV3DANIM_taille : I, /* Taille de l'animation, en nombre de frames */ AV3DANIM_frame : I, /* Numéro de frame en cours de lecture. */ AV3DANIM_frame_zero : I /* Permet de savoir si la frame zero est active (0) ou pas (1)*/ ]mkAV3DANIM;; //------ - Light - var iLightAng = 180;; // Default Light Angular var iLightConst = 320;; // Default Light Constant var iLightQuad = 0;; // Default Light Quadri var iLightType = 3;; // Default Light type : 1 Ambient - 2 PARA - 3 OMNI - 4 SPOT var iLightX = 6000;; // Defailt Light X position var iLightY = 5500;; // Defailt Light Y position var iLightZ = (-2000);; // Defailt Light Z position //----- - Camera Configuration - var iDefCamDist = 300;; // Default Camera distance in Examine mode var iCamAngX = (-6000);; // Default X Camera rotation in Examine mode var iCamAngY = (-6000);; // Default Y Camera rotation in Examine mode var iCamFog = 42000;; // Camera Fog param var iZmiddle = 21100;; var iZclip = 1;; var sCamFile = "camera camera { 0 0 0 0 0 0 300 300 800 600 1 30000 50000 } ";; /* ********************************************************************************************* / SKELETAL Anims / ********************************************************************************************* */ fun playAv3dAnim(session, animstr)= if animstr == nil then nil else ( if (animstr.AV3DANIM_lecture != 2) then nil else ( if (animstr.AV3DANIM_frame >= animstr.AV3DANIM_stopframe) then if (animstr.AV3DANIM_frame_zero == 0) then set animstr.AV3DANIM_frame = -1 else set animstr.AV3DANIM_frame = animstr.AV3DANIM_startframe else nil; ); if (animstr.AV3DANIM_frame >= animstr.AV3DANIM_stopframe) then ( set animstr.AV3DANIM_frame = animstr.AV3DANIM_startframe; set animstr.AV3DANIM_actif = 0; 0; ) else ( set animstr.AV3DANIM_frame = animstr.AV3DANIM_frame + 1; M3setSKLAnimKey session animstr.AV3DANIM_H3d animstr.AV3DANIM_Mesh animstr.AV3DANIM_frame; 0; ); ); 0;; fun setAv3dAnimObj(session, animstr, file, h3dname, mesh, state, mode, startframe, stopframe)= let (M3getObj session h3dname) -> objh3d in let (M3getObj session mesh) -> meshh3d in ( if objh3d == nil then ( //_DLGMessageBox _channel nil "test skl" "nil" 0; 0; ) else ( M3loadAnimationFileWithSKL session file objh3d; if animstr==nil then ( set animstr = mkAV3DANIM [objh3d meshh3d file state mode startframe stopframe (M3getAnimLength session objh3d) startframe 0]; 0; ) else ( set animstr.AV3DANIM_file = file; set animstr.AV3DANIM_H3d = objh3d; set animstr.AV3DANIM_Mesh = meshh3d; set animstr.AV3DANIM_actif = state; set animstr.AV3DANIM_lecture = mode; set animstr.AV3DANIM_startframe = startframe; set animstr.AV3DANIM_stopframe = stopframe; ); 0; ); M3AttachMeshWithSKL session meshh3d objh3d; ); animstr;; fun startAv3dAnimObj(animstr)= if animstr==nil then nil else ( set animstr.AV3DANIM_actif = 1; if animstr.AV3DANIM_frame >= animstr.AV3DANIM_stopframe then set animstr.AV3DANIM_frame = 0 else nil; ); 0;; fun stopAv3dAnimObj(animstr)= if animstr==nil then nil else ( set animstr.AV3DANIM_actif = 0; ); 0;; fun startstopAv3dAnimObj(animstr)= if animstr==nil then nil else ( if animstr.AV3DANIM_actif == 0 then ( set animstr.AV3DANIM_actif = 1; if animstr.AV3DANIM_frame >= animstr.AV3DANIM_stopframe then set animstr.AV3DANIM_frame = 0 else nil; ) else set animstr.AV3DANIM_actif = 0; ); 0;; fun crAv3dAnim(viewstr, file, h3dname, mesh, state, mode, startframe, stopframe)= set viewstr.VIEW_AVANIM = setAv3dAnimObj viewstr.VIEW_session nil file h3dname mesh state mode startframe stopframe; startAv3dAnimObj viewstr.VIEW_AVANIM; 0;; /* ********************************************************************************************* / RENDER / ********************************************************************************************* */ fun render3D(tview)= playAv3dAnim tview.VIEW_session tview.VIEW_AVANIM; if tview.VIEW_iMoveClickStatus != 1 then nil else let [(tview.VIEW_iMoveX-tview.VIEW_iClickX) (tview.VIEW_iClickY-tview.VIEW_iMoveY)] -> [dx dy] in M3rotateObjExt tview.VIEW_session tview.VIEW_cameraShell [(-(4*dx)) (-(4*dy)) 0]; exec tview.VIEW_cbRender with [tview]; MX3render tview.VIEW_session tview.VIEW_buffer tview.VIEW_camera nil nil tview.VIEW_bgColor; if !tview.VIEW_fps then nil else ( let mod tview.VIEW_iCountFrame tview.VIEW_frameRate -> result in if ( result == 0) then ( set tview.VIEW_iResultFPS = tview.VIEW_IFps/tview.VIEW_frameRate ; set tview.VIEW_IFps = 0 ; set tview.VIEW_iCountFrame = 0 ; ) else nil ; _SDRAWtext tview.VIEW_buffer tview.VIEW_font3D 5 10 TD_LEFT (make_rgb 255 255 255) strcat "FPS : " itoa tview.VIEW_iResultFPS; ); 0; _BLTsurface tview.VIEW_win 0 0 tview.VIEW_buffer 0 0 tview.VIEW_iWinW tview.VIEW_iWinH; if !tview.VIEW_fps then nil else ( set tview.VIEW_iCountFrame = tview.VIEW_iCountFrame + 1 ; set tview.VIEW_IFps = tview.VIEW_IFps + (ftoi M3getFrameRate tview.VIEW_session) ; ); 0;; fun cbTickRender(tmr, tview)= render3D tview; 0;; fun cbViewClick(win, tview, posx, posy, but)= if (but & 1) then ( set tview.VIEW_iClickX = posx; set tview.VIEW_iClickY = posy; set tview.VIEW_iClickStatus = CLICK_YES; ) else nil; 0;; fun cbWinUnclick(win, tview, posx, posy, but) = set tview.VIEW_iClickStatus = CLICK_NO; set tview.VIEW_iMoveClickStatus = MVCLICK_NO; 0;; fun cbCursorMove(win, tview, posx, posy, but) = set tview.VIEW_iMoveX = posx; set tview.VIEW_iMoveY = posy; if (but & 1) then ( set tview.VIEW_iMoveClickStatus = MVCLICK_YES; ) else nil; 0;; fun init3dView(viewstr)= if viewstr.VIEW_trmRender == nil then nil else _deltimer viewstr.VIEW_trmRender; if viewstr.VIEW_buffer == nil then nil else _DSsurface viewstr.VIEW_buffer; if viewstr.VIEW_session == nil then nil else M3destroy viewstr.VIEW_session; let MX3createSession _channel -> session in let _CRsurface _channel viewstr.VIEW_iWinW viewstr.VIEW_iWinH -> nbuffer in let M3createShell session -> mainShell in let M3createShell session -> camShell in let M3createShell session -> lightShell in let M3createLight session LIGHT_AMBIENT (-30) nil nil nil nil -> amblight in let M3createColorLight session iLightType 0xf6f9ef 0xf5ffd1 0xffffff iLightAng iLightConst iLightQuad -> deflight in ( set viewstr.VIEW_session = session; set viewstr.VIEW_buffer = nbuffer; set viewstr.VIEW_shell = mainShell; set viewstr.VIEW_lightShell = lightShell; set viewstr.VIEW_light = deflight; set viewstr.VIEW_cameraShell = camShell; //M3textureSetGeneralDefaultType viewstr.VIEW_session atoi _getress "3DMipmap"; M3loadString session sCamFile mainShell; let sizelist viewstr.VIEW_lScene -> size in let 0 -> i in while i < size do ( let nth_list viewstr.VIEW_lScene i -> elem in M3load session elem mainShell; set i = i + 1; ); let M3getObj session "camera" -> camera in set viewstr.VIEW_camera = camera; M3link viewstr.VIEW_session amblight viewstr.VIEW_shell; M3link viewstr.VIEW_session viewstr.VIEW_cameraShell viewstr.VIEW_shell; M3link viewstr.VIEW_session viewstr.VIEW_camera viewstr.VIEW_cameraShell; M3link viewstr.VIEW_session viewstr.VIEW_lightShell viewstr.VIEW_shell; M3link viewstr.VIEW_session viewstr.VIEW_light viewstr.VIEW_lightShell; M3setObjVec viewstr.VIEW_session viewstr.VIEW_shell [0 0 0]; M3setObjVec viewstr.VIEW_session viewstr.VIEW_light [iLightX iLightY iLightZ]; M3setObjVec viewstr.VIEW_session viewstr.VIEW_camera [0 0 (-600)]; let M3getCamera viewstr.VIEW_session viewstr.VIEW_camera -> [ [dx dy] [sx sy] [_ _ zmax] ] in M3setCamera viewstr.VIEW_session viewstr.VIEW_camera [[dx dy] [viewstr.VIEW_iWinW/2 viewstr.VIEW_iWinH/2] [iZclip iZmiddle iCamFog]]; let (atof "29.7")/.(atof "57.29") -> d in let M3getCamera viewstr.VIEW_session viewstr.VIEW_camera -> [_ [sx sy] z] in let ftoi (itof sx)/. tan d -> dx in M3setCamera viewstr.VIEW_session viewstr.VIEW_camera [[dx dx] [sx sy] z]; exec viewstr.VIEW_cbInit with [viewstr]; set viewstr.VIEW_trmRender = _rfltimer _starttimer _channel (1000 / viewstr.VIEW_frameRate) @cbTickRender viewstr; ); viewstr;; fun crView3d(fatherwin, ix, iy, iw, ih, lm3d, backcolor, cbinit, cbfun, mouse, enablefps, ifps)= let mk3dView [nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil enablefps ifps 0 0 0] -> viewstr in let _CRwindow _channel fatherwin ix iy iw ih WN_CHILDINSIDE|WN_NOCAPTION|WN_NOBORDER "" -> win in ( set viewstr.VIEW_win = win; set viewstr.VIEW_iWinW = iw; set viewstr.VIEW_iWinH = ih; set viewstr.VIEW_lScene = lm3d; set viewstr.VIEW_bgColor = backcolor; if !mouse then nil else ( _CBwinClick viewstr.VIEW_win @cbViewClick viewstr; _CBwinUnclick viewstr.VIEW_win @cbWinUnclick viewstr; _CBcursorMove viewstr.VIEW_win @cbCursorMove viewstr; ); set viewstr.VIEW_font3D = _CRfont _channel 14 0 0 "Arial"; set viewstr.VIEW_cbRender = cbfun; set viewstr.VIEW_cbInit = cbinit; init3dView viewstr; );; fun ds3dView(viewstr)= if viewstr.VIEW_trmRender == nil then nil else _deltimer viewstr.VIEW_trmRender; if viewstr.VIEW_buffer == nil then nil else _DSsurface viewstr.VIEW_buffer; if viewstr.VIEW_session == nil then nil else M3destroy viewstr.VIEW_session; if viewstr.VIEW_win == nil then nil else _DSwindow viewstr.VIEW_win; if viewstr.VIEW_font3D == nil then nil else _DSfont viewstr.VIEW_font3D; 0;; fun reset3dView(viewstr)= init3dView viewstr; 0;; fun moveViewCamera(viewstr, vec)= M3setObjVec viewstr.VIEW_session viewstr.VIEW_camera vec; 0;;