/* PlayAnim - DMS - Jun 99 - by Christophe LOREK */ typeof class=S;; struct PlayAnim = [PAname:S, PAframerate:I, PAplaystop:I, PAlooponce:I, PAstartframe:I, PAendframe:I, PAcurrentframe:I, PAaccum:I, PAtick:I, PAfel:[I r1], PASeql:[[S I I] r1]] mkPlayAnim;; fun seqByName(x, name)= let x -> [currentname _ _] in !strcmp currentname name;; fun testFrameEvent(fel,prevframe, curframe, fpos)= if fel == nil then nil else let fel -> [keyframe nfel] in if ((prevframe < keyframe) && (keyframe <= curframe)) || ((prevframe < keyframe) && (curframe < prevframe))then fpos else testFrameEvent nfel prevframe curframe fpos+1;; fun AnimObjAnc(l,currentframe,taux)= if l == nil then nil else let l -> [[current_h3d _ _ _] nl] in ( M3setAnimKey2 session current_h3d currentframe currentframe+1 taux; AnimObjAnc nl currentframe taux; 0 );; fun AnimObjAncSingle(l,currentframe)= if l == nil then nil else let l -> [[current_h3d _ _ _] nl] in ( M3setAnimKey session current_h3d currentframe; AnimObjAncSingle nl currentframe; 0 );; fun slidepos(o,ancObList,a)= if a.PAplaystop then let _tickcount -> currenttick in ( if a.PAtick == nil then set a.PAtick = currenttick else nil; let ((currenttick - a.PAtick) * a.PAframerate) -> timeframe in let mod timeframe 1000 -> accum in let (timeframe / 1000) -> deltaframe in let a.PAcurrentframe -> prevframe in ( set a.PAaccum = a.PAaccum + accum; if a.PAaccum > 1000 then (set deltaframe = deltaframe + 1; set a.PAaccum = a.PAaccum - 1000;) else nil; set a.PAcurrentframe = a.PAcurrentframe + deltaframe; let (testFrameEvent a.PAfel prevframe a.PAcurrentframe 0)-> fpos in if fpos == nil then nil else _DMSevent this (strcatn (ObName o)::".Frame#"::(itoa (nth_list a.PAfel fpos))::nil) nil nil; if a.PAcurrentframe < a.PAendframe then ( AnimObjAnc ancObList a.PAcurrentframe (a.PAaccum * 256 / 1000); set a.PAtick = currenttick ) else ( if a.PAlooponce then (AnimObjAncSingle ancObList a.PAendframe; set a.PAplaystop = 0; set a.PAcurrentframe = a.PAstartframe; set a.PAtick = nil) else (set a.PAplaystop = 1; set a.PAcurrentframe = a.PAstartframe; set a.PAtick = nil) ); 0 ); ) else nil;; fun activate(o,from,action,param,reply,a)= let (strfind "." action 0) -> firstDotPos in let (strfind "." action firstDotPos+1) -> secondDotPos in let (substr action 0 firstDotPos) -> current_ObName in let (substr action firstDotPos+1 secondDotPos-firstDotPos-1) -> current_SeqName in let (substr action secondDotPos+1 (strlen action)-(secondDotPos)) -> current_action in if !strcmp current_ObName (ObName o) then ( if !strcmp current_action "playonce" then let a.PASeql -> SeqList in let search_in_list SeqList @seqByName current_SeqName -> [_ startframe endframe] in ( set a.PAplaystop = 1; set a.PAlooponce = 1; set a.PAstartframe = startframe; set a.PAendframe = endframe; set a.PAcurrentframe = startframe; set a.PAtick = nil; 0 ) else if !strcmp current_action "playloop" then let a.PASeql -> SeqList in let search_in_list SeqList @seqByName current_SeqName -> [_ startframe endframe] in ( set a.PAplaystop = 1; set a.PAlooponce = 0; set a.PAstartframe = startframe; set a.PAendframe = endframe; set a.PAcurrentframe = startframe; set a.PAtick = nil; 0 ) else if !strcmp current_action "stop" then (set a.PAplaystop = 0; set a.PAtick = nil; 0) else nil ) else nil;; fun cbcomm(ui,action,param,a)= let (strfind "." action 0) -> firstDotPos in let (substr action 0 firstDotPos) -> current_SeqName in let (substr action firstDotPos+1 (strlen action)-firstDotPos) -> current_action in if !strcmp current_action "playonce" then let a.PASeql -> SeqList in let search_in_list SeqList @seqByName current_SeqName -> [_ startframe endframe] in ( set a.PAplaystop = 1; set a.PAlooponce = 1; set a.PAstartframe = startframe; set a.PAendframe = endframe; set a.PAcurrentframe = startframe; set a.PAtick = nil; 0 ) else if !strcmp current_action "playloop" then let a.PASeql -> SeqList in let search_in_list SeqList @seqByName current_SeqName -> [_ startframe endframe] in ( set a.PAplaystop = 1; set a.PAlooponce = 0; set a.PAstartframe = startframe; set a.PAendframe = endframe; set a.PAcurrentframe = startframe; set a.PAtick = nil; 0 ) else if !strcmp current_action "stop" then (set a.PAplaystop = 0; set a.PAtick = nil; 0) else nil;; fun FrameEventList(l)= if l == nil then nil else let l -> [[name r] nl] in if !strcmp name "FrameEvent" then let r -> [frameNum _] in (atoi frameNum)::(FrameEventList nl) else FrameEventList nl;; fun getsequences(l)= if l == nil then nil else let l -> [paramline nl] in let paramline -> [paramname paramvalues] in if !strcmp paramname "sequence" then ( let paramvalues -> [name [startframeS [endframeS _]]] in [name (atoi startframeS) (atoi endframeS)]::(getsequences nl) ) else (getsequences nl);; fun RegisterSequenceActions(current_Ob,l,a)= if l == nil then nil else let l -> [[SeqName _ _] nl] in ( ObRegisterAction current_Ob (strcatn (ObName current_Ob)::"."::SeqName::".playonce"::nil) mkfun6 @activate a; ObRegisterAction current_Ob (strcatn (ObName current_Ob)::"."::SeqName::".playloop"::nil) mkfun6 @activate a; ObRegisterAction current_Ob (strcatn (ObName current_Ob)::"."::SeqName::".stop"::nil) mkfun6 @activate a; RegisterSequenceActions current_Ob nl a; 0 );; fun RegisterActions(current_Ob,l,a)= let getsequences l -> seqlist in RegisterSequenceActions current_Ob seqlist a;; fun prepanch(l)= if l==nil then nil else let l->[a n] in match a with (objAnchor o -> o::(prepanch n)) |(_ -> (prepanch n));; fun newOb(o)= let UgetParams ObUi o -> paramlist in let atoi hd UgetParam ObUi o "Framerate" -> framerate in let atoi hd UgetParam ObUi o "SrvAnimAutoStart" -> SrvAnimAutoStart in let prepanch ObAnchor o -> anchorObjList in let mkPlayAnim [(ObName o) framerate 0 0 0 0 0 0 _tickcount (FrameEventList paramlist) (getsequences paramlist)] -> a in ( UcbComm this ObUi o mkfun4 @cbcomm a; ObCbAnim o mkfun2 mkfun3 @slidepos a anchorObjList; RegisterActions o paramlist a; if SrvAnimAutoStart then UsendSrv this (ObUi o) "newclient" (ObName o) else nil; 0 );; fun IniPlug(file)= set class=getInfo strextr _getpack _checkpack file "name"; PlugRegister class @newOb nil; 0;;