/************************************************************* Bastien BOURINEAU 03/2004 **************************************************************/ /**************** 3D functions ******************/ fun Navigate ()= let [iClickX iClickY] -> [ox oy] in let [(iMoveX-ox) (oy-iMoveY)] -> [dx dy] in let M3getObjAng Session shellCam -> [Sx Sy Sz] in let M3getObjAng Session Camera -> [Cax Cay Caz] in let M3getObjVec Session Camera -> [Cx Cy Cz] in ( if MoveClickStatus == MVCLICK_YES then ( // Move Examine if MoveMode==1 then ( let if Sy>MinYrot then ( M3setObjAng Session shellCam [Sx (MinYrot) Sz]; 0;) else if Sy deltaY in M3rotateObjExt Session shellCam [(2*dx) deltaY 0]; ) // Move Walk else if MoveMode==2 then ( M3movObj Session shellCam [0 0 (dy/10)]; M3rotateObjExt Session shellCam [(-(2*dx)) 0 0]; ) // Move FLY else if MoveMode==3 then ( M3movObj Session shellCam [0 0 (dy/10)]; M3rotateObj Session shellCam [(-(2*dx)) 0 0]; ) else nil; ) else nil; // WeelMouse if WeelStatus != 1 then nil else ( // Move Examine if MoveMode==1 then ( let WeelDelta*((abs Cz)/ZoomStep) -> nZoomStep in if Cz>(-MinCamdist) then M3setObjVec Session Camera [Cx Cy (-MinCamdist)] else if Cz<(-MaxCamdist) then M3setObjVec Session Camera [Cx Cy (-MaxCamdist)] else M3movObjExt Session Camera [0 0 (nZoomStep)]; set WeelStatus = 0; ) else // Move Walk if MoveMode==2 then ( let WeelDelta*((65534/360)*5) -> nRotStep in if Cay>MinYrot then M3setObjAng Session Camera [Cax MinYrot Caz] else if Cay nRotStep in if Sy>MinYrot then M3setObjAng Session shellCam [Sx MinYrot Sz] else if Sy [a nxt] in ( if a.ETATANIM_H3d==elem then a else find_anim_list nxt elem; ) ;; fun Rotate (timer, param)= let param -> [hobj axe speed] in if axe == 0 then /* Rotation autour de x */ ( M3rotateObjExt Session hobj [0 (-(speed*20)) 0]; ) else if axe == 1 then /* Rotation autour de y */ ( M3rotateObj Session hobj [(-(speed*20)) 0 0]; M3movObj Session hobj [0 0 0]; ) else if axe == 2 then /* Rotation autour de z */ ( M3rotateObj Session hobj [0 0 (-(speed*20))]; ) else if axe == 3 then /* Rotation autour de x */ ( M3rotateObj Session hobj [0 (speed*20) 0]; M3movObj Session hobj [0 0 0]; ) else if axe == 4 then /* Rotation autour de y */ ( M3rotateObj Session hobj [(speed*20) 0 0]; M3movObj Session hobj [0 0 0]; ) else if axe == 5 then /* Rotation autour de z */ ( M3rotateObj Session hobj [0 0 (speed*20)]; M3movObj Session hobj [0 0 0]; ) else 0 ;; fun GoRotate (hobj, axe, speed) = let _starttimer _channel speed -> timer_rot in _rfltimer timer_rot @Rotate [hobj axe speed]; 0 ;; fun Target (timer, hobj)= let M3calcPosRef Session hobj shell -> [src _] in let M3calcPosRef Session Camera shell -> [dst _] in let M3angularTarget src dst -> [an bn _] in let M3getObjAng Session hobj -> [_ _ c] in let dst -> [dx dy dz] in let M3setObjAng Session hobj [an bn c]-> rotob in rotob; 0 ;; fun GoTarget (hobj)= let _starttimer _channel (1000 / 30) -> timer_targ in _rfltimer timer_targ @Target hobj; 0 ;; fun cbTime_PlayAnim (Animstr)= let Animstr.ETATANIM_H3d -> hobj in if Animstr.ETATANIM_actif==1 then ( if Animstr.ETATANIM_lecture==2 then ( if (Animstr.ETATANIM_frame >= Animstr.ETATANIM_stopframe) then if (Animstr.ETATANIM_frame_zero == 0) then set Animstr.ETATANIM_frame = -1 else set Animstr.ETATANIM_frame = 0 else 0; )else nil; if (Animstr.ETATANIM_frame >= Animstr.ETATANIM_stopframe) then ( set Animstr.ETATANIM_frame = Animstr.ETATANIM_stopframe; set Animstr.ETATANIM_actif = 0; 0 ) else ( set Animstr.ETATANIM_frame = Animstr.ETATANIM_frame + 1; M3setAnimKey Session hobj Animstr.ETATANIM_frame; /* Affichage de la scène */ 0 ) ) else nil; 0 ;; fun cbTime_PlayAnimList (l)= if l == nil then nil else let l -> [elem next] in ( cbTime_PlayAnim elem; cbTime_PlayAnimList next; ); 0 ;; fun PlayAnim (timer, param_objet)= cbTime_PlayAnimList AnimList; 0 ;; fun Get_Link(l, curHname)= if l==nil then nil else let l -> [first next] in ( if ((strcmp first curHname)==0) then ( // anim on click let (hd tl tl tl tl tl tl next) -> link_anim in let (hd tl tl tl tl tl tl tl next) -> startF in let (hd tl tl tl tl tl tl tl tl next) -> stopF in let (hd tl tl tl tl tl tl tl tl tl next) -> startF2 in let (hd tl tl tl tl tl tl tl tl tl tl next) -> stopF2 in let M3getObj Session curHname -> h3dObj in let if startF==nil then 0 else atoi startF -> startFrame in let if stopF==nil then (M3getAnimLength Session h3dObj) else atoi stopF -> stopFrame in let if startF2==nil then 0 else atoi startF2 -> startFrame2 in let if stopF2==nil then (M3getAnimLength Session h3dObj) else atoi stopF2 -> stopFrame2 in ( if ((strcmp link_anim "1")==0) then ( let find_anim_list AnimList h3dObj -> existAnim in if existAnim==nil then ( let mkEtatAnim [h3dObj 1 1 75 startFrame stopFrame (M3getAnimLength Session h3dObj) startFrame 0] -> mkanim in set AnimList = mkanim::AnimList; 0; ) else ( set existAnim.ETATANIM_actif = 1; set existAnim.ETATANIM_lecture = 1; set existAnim.ETATANIM_vitesse = 75; if existAnim.ETATANIM_frame == stopFrame then ( set existAnim.ETATANIM_startframe = startFrame2; set existAnim.ETATANIM_stopframe = stopFrame2; set existAnim.ETATANIM_taille = (M3getAnimLength Session h3dObj); set existAnim.ETATANIM_frame = startFrame2; ) else ( set existAnim.ETATANIM_startframe = startFrame; set existAnim.ETATANIM_stopframe = stopFrame; set existAnim.ETATANIM_taille = (M3getAnimLength Session h3dObj); set existAnim.ETATANIM_frame = startFrame; ); 0; ); ) else if ((strcmp link_anim "2")==0) then ( let find_anim_list AnimList h3dObj -> existAnim in if existAnim==nil then ( let mkEtatAnim [h3dObj 1 2 75 startFrame stopFrame (M3getAnimLength Session h3dObj) startFrame 0] -> mkanim in set AnimList = mkanim::AnimList; 0; ) else ( if existAnim.ETATANIM_frame == stopFrame then ( set existAnim.ETATANIM_startframe = startFrame2; set existAnim.ETATANIM_stopframe = stopFrame2; set existAnim.ETATANIM_taille = (M3getAnimLength Session h3dObj); set existAnim.ETATANIM_frame = startFrame2; ) else ( set existAnim.ETATANIM_startframe = startFrame; set existAnim.ETATANIM_stopframe = stopFrame; set existAnim.ETATANIM_taille = (M3getAnimLength Session h3dObj); set existAnim.ETATANIM_frame = startFrame; ); 0; ); ) else 0; ); // Url let (hd tl tl tl tl tl tl tl tl tl tl tl next) -> url in if ((url==nil)||((strcmp url "0")==0)) then 0 else ( _openbrowserhttp url; _fooS strcat ">>>>>> open url : " url; 0; ); ) else 0; 0; ) ;; fun Init_Link (l, curHname)= if l==nil then nil else let l -> [[first next] nextline] in ( Get_Link first::next curHname; Init_Link nextline curHname; ); 0 ;; fun Get_hand(l, curHname)= let l -> [first next] in ( if ((strcmp first curHname)==0) then ( let (hd tl tl tl tl tl next) -> hand in if (((strcmp hand "0")==0)||(hand==nil)) then set handon=0 else set handon = 1; ) else 0; ) ;; fun Init_hand (l, curHname)= if l==nil then 0 else let l -> [[first next] nextline] in ( Get_hand first::next curHname; Init_hand nextline curHname; ) ;; fun paint (notuse, notuse2)= Navigate; let BackgroundColor -> [r g b] in if View3D==0 then ( if loadScreen==1 then ( _Bitmap2Surface Buffer 0 0 load_bitmap 0 0 winW winH 0; 0; ) else ( if Rendu_filaire == 1 then ( MX3wire Session Buffer Camera 0 0 (make_rgb r g b); 0 ) else ( let iMoveX - (winW / 2) -> iMoveXP in let (winH / 2) - iMoveY -> iMoveYP in let MX3render Session Buffer Camera iMoveXP iMoveYP (make_rgb r g b) -> mesh in let M3objName Session mesh -> curHname in ( Init_hand H3dFileList curHname; if handon == 1 then _SETwinCursor Win csrHand else _SETwinCursor Win nil; if (iClickStatus == CLICK_YES) then ( Init_Link H3dFileList curHname; set iClickStatus = CLICK_NO; 0; ) else 0; ); 0 ); ) ) else ( if loadScreen==1 then ( _Bitmap2Surface Buffer 0 0 load_bitmap 0 0 winW winH 0; _BLTsurface Win 0 0 Buffer 0 0 winW winH; 0; ) else ( if Rendu_filaire == 1 then ( MX3wire Session Buffer CameraR 0 0 (make_rgb r g b); 0 ) else ( let iMoveX - (winW / 2) -> iMoveXP in let (winH / 2) - iMoveY -> iMoveYP in let MX3render Session BufferLeft CameraL iMoveXP iMoveYP (make_rgb r g b) -> mesh1 in let MX3render Session BufferRight CameraR iMoveXP iMoveYP (make_rgb r g b) -> mesh in let M3objName Session mesh -> curHname in ( Init_hand H3dFileList curHname; if handon == 1 then _SETwinCursor Win csrHand else _SETwinCursor Win nil; if (iClickStatus == CLICK_YES) then ( Init_Link H3dFileList curHname; set iClickStatus = CLICK_NO; 0; ) else 0; _Surface2Bitmap LeftBitmap 0 0 BufferLeft 0 0 winW winH nil; // _Surface2Bitmap RightBitmap 0 0 BufferRight 0 0 winW winH nil; _NOTbitmap LeftBitmap 0 0 winW winH; // _NOTbitmap RightBitmap 0 0 winW winH; // let _ANDbitmap RightBitmap 0 0 winW winH LeftBitmap 0 0 -> newbmp in _Bitmap2Surface Buffer 0 0 LeftBitmap 0 0 winW winH nil; 0; ); ); ); ); if Back3d==1 && loadScreen==0 then let BackTransColor -> [r g b] in _Bitmap2Surface Buffer 0 0 back_bitmap 0 0 winW winH (make_rgb r g b) else nil; _BLTsurface Win 0 0 Buffer 0 0 winW winH; 0 ;; // particle fun applyOnAllBrothers(elem)= if elem == nil then 0 else ( M3setEmitterState Session elem PCL_RESTART; applyOnAllBrothers (M3getBrother Session elem); let M3objName Session elem -> obname in _fooS strcat ">>>>>>>>> obname : " obname; 0; ); 0 ;; fun GoParticle(h)= M3setEmitterState Session h PCL_RESTART; let M3getFirstSon Session h -> PartH3D in if PartH3D == nil then nil else applyOnAllBrothers PartH3D ;; fun ApplyFX (h3dmake)= let M3getObj Session h3dmake.H3dName -> h3dObj in ( if (atoi h3dmake.FxType)==1 then (//_fooS "ROTATE !!!!!!!!!!!!!!"; GoRotate h3dObj 1 5 ) else if (atoi h3dmake.FxType)==2 then (//_fooS "ROTATE !!!!!!!!!!!!!!"; GoRotate h3dObj 4 5 ) else if (atoi h3dmake.FxType)==3 then (//_fooS "TARGET !!!!!!!!!!!!!!"; GoTarget h3dObj; ) else if (atoi h3dmake.FxType)==4 then (//_fooS "Particle !!!!!!!!!!!!!!"; GoParticle h3dObj; ) else 0; if (atoi h3dmake.FxAnim)==1 then ( let find_anim_list AnimList h3dObj -> existAnim in if existAnim==nil then ( let mkEtatAnim [h3dObj 1 1 75 (atoi h3dmake.StartFrame) (atoi h3dmake.StopFrame) (M3getAnimLength Session h3dObj) (atoi h3dmake.StartFrame) 0] -> mkanim in set AnimList = mkanim::AnimList; 0; ) else ( set existAnim.ETATANIM_actif = 1; set existAnim.ETATANIM_lecture = 1; set existAnim.ETATANIM_vitesse = 75; set existAnim.ETATANIM_startframe = (atoi h3dmake.StartFrame); set existAnim.ETATANIM_stopframe = (atoi h3dmake.StopFrame); set existAnim.ETATANIM_taille = (M3getAnimLength Session h3dObj); set existAnim.ETATANIM_frame = (atoi h3dmake.StartFrame); 0; ); ) else if (atoi h3dmake.FxAnim)==2 then (//_fooS "ANIMLOOP !!!!!!!!!!!!!!"; let find_anim_list AnimList h3dObj -> existAnim in if existAnim==nil then ( let mkEtatAnim [h3dObj 1 2 75 (atoi h3dmake.StartFrame) (atoi h3dmake.StopFrame) (M3getAnimLength Session h3dObj) (atoi h3dmake.StartFrame) 0] -> mkanim in set AnimList = mkanim::AnimList; 0; ) else ( set existAnim.ETATANIM_actif = 1; set existAnim.ETATANIM_lecture = 2; set existAnim.ETATANIM_vitesse = 75; set existAnim.ETATANIM_startframe = (atoi h3dmake.StartFrame); set existAnim.ETATANIM_stopframe = (atoi h3dmake.StopFrame); set existAnim.ETATANIM_taille = (M3getAnimLength Session h3dObj); set existAnim.ETATANIM_frame = (atoi h3dmake.StartFrame); 0; ); ) else 0; if (atoi h3dmake.CamLink)==1 then (//_fooS "CAMLINK !!!!!!!!!!!!!!"; M3unLink Session h3dObj; M3link Session h3dObj Camera; M3setObjVec Session h3dObj [12 (-10) 28]; ) else 0; ) ;; fun Get_h3dlist(l)= if l==nil then nil else let l -> [first next] in ( let mkTH3dFx [first (hd next) (hd tl next) (hd tl tl next) (hd tl tl tl next) (hd tl tl tl tl next)] -> h3dmake in ApplyFX h3dmake; ); 0 ;; fun init_h3dlist(l)= if l==nil then nil else let l -> [[first next] nextline] in ( Get_h3dlist first::next; init_h3dlist nextline; ); 0 ;; fun MakeH3dTypeLine (l)= if l==nil then nil else let l -> [first next] in ( if (strcmp first "mesh") == 0 || (strcmp first "shell") == 0 then ( _fooS strcat ">>>>>>>> mesh : " (hd next); set H3dFromM3dList = (M3getObj Session (hd next))::H3dFromM3dList; ) else if (strcmp first "colorlight") == 0 then set LightFromM3dList = (M3getObj Session (hd next))::LightFromM3dList else if (strcmp first "emitter") == 0 then set EmitFromM3dList = (M3getObj Session (hd next))::EmitFromM3dList else nil ); 0 ;; fun MakeH3dTypeList (l)= if l==nil then nil else let l -> [[first next] nextline] in ( MakeH3dTypeLine first::next; MakeH3dTypeList nextline; ); 0 ;; fun RunH3dAnim (l)= if l==nil then nil else let l -> [first next] in ( let mkEtatAnim [first 1 2 75 0 (M3getAnimLength Session first) (M3getAnimLength Session first) 0 0] -> mkanim in set AnimList = mkanim::AnimList; RunH3dAnim next; ); 0 ;; fun RunH3dLight (l)= if l==nil then nil else let l -> [first next] in ( let M3getColorLight Session first -> [type c1 c2 c3 ang const quad] in if (_GETengineState == ENGINE_HARDWARE) then nil else M3link Session (M3createLight Session LightType 20 10 2000 nil nil) first; RunH3dLight next; ); 0 ;; fun RunH3dParticle (l)= if l==nil then nil else let l -> [first next] in ( GoParticle first; RunH3dParticle next; ); 0 ;; fun GetObjsize (l)= if l==nil then nil else let l -> [first next] in ( let (M3getRadius Session first)+(M3distance Session first shell) -> curObjDist in ( if curObjDist!=nil && curObjDist > ObjDist then let (atof "29.7")/.(atof "57.29") -> d in let ftoi (itof curObjDist)/. tan d -> dx in set ObjDist = curObjDist+(dx) else nil; if ObjDist==nil || ObjDist<1 then set ObjDist=Camdist else nil; _fooS strcat ">>>>>>>> distance : " (itoa ObjDist); ); GetObjsize next; ); 0 ;; fun load_m3d_list(mfile)= let strextr (_getpack (_checkpack mfile)) -> h3dfilelist in let strextr (_getpack (_checkpack scenefile)) -> M3dfilelist in let MakeH3dTypeList M3dfilelist -> maketmp in let init_h3dlist h3dfilelist -> initfxtmp in ( set H3dFileList = h3dfilelist; if autoAnim==1 then RunH3dAnim H3dFromM3dList else nil; if autoParticle==1 then RunH3dParticle EmitFromM3dList else nil; ); if LightFromM3dList==nil || autoLight==0 then ( // Color light set h3dShlLight = M3createShell Session; M3link Session h3dShlLight shell; M3setObjVec Session h3dShlLight [LightX LightY LightZ]; if (_GETengineState == ENGINE_HARDWARE) then ( set h3dCLight = M3createColorLight Session LightType 0xf6f9ef 0xf5ffd1 0xffffff LightAng LightConst LightQuad; 0; ) else ( set h3dCLight = M3createLight Session LightType 20 10 ((M3distance Session h3dShlLight shell)+1000) nil nil; 0; ); M3link Session h3dCLight h3dShlLight; ) else if autoLight==1 then RunH3dLight LightFromM3dList else nil; if EmitFromM3dList!=nil then _ENmenuItem PMenu else _DImenuItem PMenu; if H3dFromM3dList==nil then (set ObjDist = Camdist) else GetObjsize H3dFromM3dList; if autoFit==1 then ( set Camdist = ObjDist; )else nil; set MaxCamdist = ObjDist+MaxCamdist; 0 ;; /* ****************************** */ /* Convert Material for Soft Mode */ /* ****************************** */ fun setMatType (mat, b)= let M3getType Session mat -> curtype in ( if curtype & MAT_TEXTURED_BIS then ( M3setType Session mat MAT_TEXTURED; let M3textureBISFromMaterial Session mat -> tex in M3chgMaterialTexture Session mat tex; ) else if curtype & MAT_ENV && curtype & MAT_TRANSP then M3setType Session mat MAT_TEXTURED|MAT_TRANSP else if curtype & MAT_ENV then M3setType Session mat (M3getType Session mat)|MAT_ENV else if curtype & MAT_TRANSP then M3setType Session mat (M3getType Session mat)|MAT_TRANSP else if curtype & MAT_LIGHT then M3setType Session mat (M3getType Session mat)|MAT_LIGHT else if curtype & MAT_GOURAUD then M3setType Session mat (M3getType Session mat)|MAT_GOURAUD else nil; ); 0 ;; fun ExamineMode ()= M3setObjAng Session shellCam [CamangX CamangY 0]; M3setObjVec Session shellCam [0 0 0]; M3setObjVec Session Camera [0 0 (-Camdist)]; M3setObjAng Session Camera [0 0 0]; 0 ;; fun AvMode ()= let M3getObjVec Session shellCam -> [x y z] in let M3getObjAng Session shellCam -> [xa ya za] in ( M3setObjAng Session shellCam [xa 0 0]; M3setObjVec Session shellCam [x 0 z]; M3setObjVec Session Camera [0 170 0]; M3setObjAng Session Camera [0 0 0]; ); 0 ;; fun FlyMode ()= let M3getObjVec Session shellCam -> [x y z] in let M3getObjAng Session shellCam -> [xa _ za] in let M3getObjAng Session Camera -> [_ ya _] in ( M3setObjVec Session Camera [0 0 0]; M3setObjAng Session Camera [0 0 0]; M3setObjAng Session shellCam [xa 0 za]; M3setObjVec Session shellCam [x (y+170) z]; ); 0 ;; fun Init_3D_Scene()= set shell = M3createShell Session; M3load Session scenefile shell; M3recursFillMatObj Session shell; set shellCam = M3createShell Session; if View3D==0 then ( set Camera = M3getObj Session "camera"; if Camera == nil then ( M3load Session camfile shell; set Camera = M3getObj Session "camera"; ) else nil; M3link Session shellCam shell; M3link Session Camera shellCam; M3setObjVec Session shell [0 0 0]; let M3getCamera Session Camera -> [ [dx dy] [sx sy] [zclip zmiddle zmax] ] in M3setCamera Session Camera [[dx dy] [winW/2 winH/2] [1 zmiddle 12000000]]; let (atof "29.7")/.(atof "57.29") -> d in let M3getCamera Session Camera ->[_ [sx sy] z] in let ftoi (itof sx)/. tan d -> dx in M3setCamera Session Camera [[dx dx] [sx sy] z]; ) else ( set Camera = M3createShell Session; M3load Session camfile3D shell; M3link Session shellCam shell; M3link Session Camera shellCam; M3setObjVec Session shell [0 0 0]; M3setObjVec Session Camera [0 150 (-600)]; M3setObjAng Session Camera [0 (-2700) 0]; // Left Camera set CameraL = M3getObj Session "cameraL"; M3link Session CameraL Camera; let M3getCamera Session CameraL -> [ [dx dy] [sx sy] [zclip zmiddle zmax] ] in M3setCamera Session CameraL [[dx dy] [winW/2 winH/2] [1 zmiddle 12000000]]; let (atof "29.7")/.(atof "57.29") -> d in let M3getCamera Session CameraL ->[_ [sx sy] z] in let ftoi (itof sx)/. tan d -> dx in M3setCamera Session CameraL [[dx dx] [sx sy] z]; // Right Camera set CameraR = M3getObj Session "cameraR"; M3link Session CameraR Camera; let M3getCamera Session CameraR -> [ [dx dy] [sx sy] [zclip zmiddle zmax] ] in M3setCamera Session CameraR [[dx dy] [winW/2 winH/2] [1 zmiddle 12000000]]; let (atof "29.7")/.(atof "57.29") -> d in let M3getCamera Session CameraR ->[_ [sx sy] z] in let ftoi (itof sx)/. tan d -> dx in M3setCamera Session CameraR [[dx dx] [sx sy] z]; ); // Ambient light set h3dALight = M3createLight Session LIGHT_AMBIENT (2-30) nil nil nil nil; M3link Session h3dALight shell; // Software Mat convert if (_GETengineState == ENGINE_HARDWARE) then nil else let M3listALLMaterials Session -> l in apply_on_list l @setMatType nil; load_m3d_list ObjFxfile; // Default navmode if MoveMode == 1 then ExamineMode else if MoveMode == 2 then AvMode else if MoveMode == 3 then FlyMode else nil; 0;; fun Init_3D_Session() = // Reset all variable _deltimer timer_Anim; set timer_Anim = nil; set Camera = nil; set shellCam = nil; set shell = nil; set ObjDist = nil; set h3dCLight = nil; set h3dShlLight = nil; set h3dALight = nil; set H3dFileList = nil; set H3dFromM3dList = nil; set LightFromM3dList = nil; set EmitFromM3dList = nil; set AnimList = nil; set Camdist=DefCamdist; set MaxCamdist=DefMaxCamdist; _freememory; // create 3D if Session ==nil then set Session = MX3createSession _channel else nil; M3reset Session; M3textureSetGeneralDefaultType Session TEX_MIPMAP; // loading bitmap Init_3D_Scene; set loadScreen=0; set timer_Anim = _starttimer _channel (1000 / 30); _rfltimer timer_Anim @PlayAnim nil; 0;;