/* SnapAv Avatar - DMS2 - september 99 - by Sylvain HUET */ /* rev. June 00 - by Sebastien DENEUX*/ var avfile="Dms/3d/Plugins/SnapAv/av.m3d";; typeof class=S;; typeof dev=Video;; typeof win=ObjWin;; typeof win2=ObjWin;; typeof bmpSnapAv=ObjBitmap;; typeof lastone=ObjBitmap;; typeof newone=ObjBitmap;; typeof text=ObjText;; typeof lastbmp=S;; typeof lastsent=S;; typeof refreshTimer=Timer;; typeof avatar=H3d;; typeof loop=ObjCheck;; typeof snapShotButton=ObjButton;; typeof curvideo=Ob;; var vw=128;; var vh=128;; var quality=40;; var compress=1;; var ackvideo=1;; var refreshPeriod=5;; fun endcapt() = if dev==nil then nil else ( _SETcapVideoStop dev; _DScapWindow dev ); set dev=nil ;; fun destroyPho(o)= M3delObj session M3getFather session ObGetMain o; endcapt; _DSbitmap lastone; _DSbitmap newone; _DSwindow win; /* _RSCabort this itoa UgetId UgetUser ObUi o;*/ 0 ;; fun destroy2Pho(o)= M3delObj session ObGetMain o; /* _RSCabort this itoa UgetId UgetUser ObUi o;*/ 0 ;; fun animPho(o, q) = let q->[h x] in let (100+x)&4095 -> x in let if x&2048 then 3072-x else x-1024 -> z in ( let M3getObjAng session h -> [a _ c] in M3setObjAng session h [a z c]; let M3getObjVec session h -> [a _ c] in M3setObjVec session h [a (z>>6) c]; mutate q<-[_ x]; 0 ) ;; fun _paintevent(a, b) = _BLTbitmap win lastone 0 0 ;; proto applyface=fun[S [Ob S S S]] I;; fun applyface(f, z) = let z->[o _ _ file] in let _getpack _checkpack strcatn file::"_"::(itoa UgetId UgetUser ObUi owner)::".sav"::nil -> s in if s==nil then nil else let if (nth_char s 0)=='Z then _c32to15 _JDecomp (substr s 1 strlen s) vh vw quality else (substr s 1 strlen s) -> fs in let _CRbitmap _channel vw vh -> image in let if o==owner then ( _SETbitmap lastone fs; _paintevent nil nil; let M3getFirstSon session ObGetMain o -> h in M3getBrother session h /* NEW */ ) else M3getFirstSon session ObGetMain o -> h in let M3copyObjMaterial session h hd M3listOfMaterials session h-> mat in ( _SETbitmap image fs; M3blitTexture16 session (M3copyMaterialTexture session mat) image; _DSbitmap image ); let z->[o _ nxt file] in ( if o==curvideo then set ackvideo=1 else nil; if nxt==nil then ( mutate z<-[_ nil nil _]; 0 ) else ( mutate z<-[_ nxt nil _]; _RSCdownload this file (strcatn file::"_"::(itoa UgetId UgetUser ObUi owner)::".sav"::nil) mknode @applyface z 3; 0 ) ) ;; fun _showSnapButton(t, b) = _deltimer refreshTimer; set refreshTimer=nil; _ENbutton snapShotButton 1 ;; fun _event(a, o) = if refreshTimer!=nil then nil else ( if refreshPeriod!=0 then ( _ENbutton snapShotButton 0; set refreshTimer=_rfltimer _starttimer _channel refreshPeriod*1000 @_showSnapButton nil ) else nil; _SETbitmap newone lastbmp; set lastsent=_FILEbitmap newone; if lastbmp==nil then nil else let if compress then ( _JCompInit quality; strcat "Z" _JComp (_c15to32 lastbmp)vw vh ) else strcat "N" lastbmp -> fs in let mzip fs -> s in ( let 0->i in while i temp in let if temp==nil || temp==-1 then 0 else temp -> vid in ( set dev=_CRcapWindow _channel win vid 272 0 vw vh 1 500000; _SETcapVideoStart dev @capfun o ) else ( endcapt; nil ); _SETbuttonName a if dev==nil then (_loc this "SNAP_START" nil) else (_loc this "SNAP_STOP" nil) ;; fun _destroyevent(a, b) = endcapt; _DSbitmap lastone; _DSbitmap newone; set win=nil; set lastone=nil; 0 ;; /* save / load */ typeof oldpath=S;; fun lastslash(s)= let 0-> i in let 0-> l in ( while i s in if s==nil then nil else ( set oldpath=substr s 0 lastslash s; _storepack b s ) ;; fun _save(a,b)= _DLGrflsave (_DLGSaveFile _channel win oldpath nil "Bitmap (*.bmp)\0*.BMP\0\0") @_SaveSnap lastsent ;; fun _OpenSnap(d,o,s)= let _PtoScol s -> name in if name==nil then nil else ( set oldpath=substr name 0 lastslash name; let _LDbitmap _channel s-> xx in let if xx==nil then _LDjpeg _channel s else xx ->x in if x==nil then nil else let _GETbitmapSize x-> [w h] in ( _SCPbitmap lastone 0 0 vw-1 vh-1 x 0 0 w-1 h-1 nil; set lastbmp=_GETbitmap lastone; _DSbitmap x; _event nil o ) ) ;; fun _load(a, o) = _DLGrflopen (_DLGOpenFile _channel win oldpath nil "Bitmap (*.bmp,*.jpg)\0*.BMP;*.JPG\0\0") @_OpenSnap o ;; /* interface */ fun _endB(s) = _DSbitmap bmpSnapAv; set win2=nil; _DMSreleaseZone this "SnapAv"; 0 ;; fun _paintE(wn, b) = let b->[w h] in let _CRbitmap _channel w h -> bmp in ( _SCPbitmap bmp 0 0 w-1 h-1 bmpSnapAv 0 0 64-1 64-1 nil; _BLTbitmap wn bmp 0 0; _DSbitmap bmp; 0 ) ;; fun _recoverB(s) = _DSwindow win2; _endB nil; 0 ;; fun _resizeB(x, s) = let x->[wn x y w h] in ( _SIZEwindow win2 w h x y; _paintE win2 [w h]; 0 ) ;; /* interface */ fun createbutton(o)= let _DMSgetZone this "SnapAv" @_recoverB @_resizeB @_endB ->[wn x y w h] in if wn==nil then nil else ( set win2= _CRwindow _channel wn x y w h WN_CHILDINSIDE|WN_NOCAPTION|WN_NOBORDER "snapAv"; set bmpSnapAv = _LDjpeg _channel _checkpack "Dms/3d/plugins/SnapAv/cam.jpg"; _CBwinPaint win2 @_paintE [w h]; _paintE win2 [w h]; 0 ); let _DMSgetZone this "SnapAvInterface" nil nil nil ->[wn x y w h] in ( if wn!=nil then set win=_CRwindow _channel wn x y w h WN_CHILDINSIDE|WN_NOCAPTION|WN_NOBORDER "SnapshotAvatar" else set win=_CRwindow _channel nil 200 100 400 148 WN_MENU+WN_MINBOX "SnapshotAvatar"; _CBwinDestroy win @_destroyevent 0; set text=_CRtext _channel win 150 125 100 20 ET_DOWN ""; set newone=_CRbitmap _channel vw vh; set lastone=_CRbitmap _channel vw vh; _FILLbitmap lastone 0xc0; _CBwinPaint win @_paintevent 0; set snapShotButton=_CBbutton (_CRbutton _channel win 150 20 100 20 0 (_loc this "SNAP_SNAPSHOT"nil)) @_event o; _CBbutton (_CRbutton _channel win 150 40 100 20 0 (_loc this "SNAP_START" nil)) @_startstop o; _CBbutton (_CRbutton _channel win 150 60 100 20 0 (_loc this "SNAP_SAVE" nil)) @_save o; _CBbutton (_CRbutton _channel win 150 80 100 20 0 (_loc this "SNAP_LOAD" nil)) @_load o; if !strcmpi hd Obgetglobalress strcat class ".noCompression" "yes" then _SETcheck (_CBcheck (_CRcheck _channel win 150 100 100 20 0 "Compression") @_chgcom o) 1 else nil; if !strcmpi hd Obgetglobalress strcat class ".loop" "yes" then set loop=_CRcheck _channel win 150 0 100 18 0 "Loop" else nil; _paintevent nil nil; 0 ) ;; fun cbcomm(ui,action,param,z)= let z->[o cur nxt file] in if !strcmp action "PhotoChg" then if param==nil then nil else if cur==nil then ( mutate z<-[_ param nil _]; _RSCdownload this file (strcatn file::"_"::(itoa UgetId UgetUser ObUi owner)::".sav"::nil) mknode @applyface z 3; 0 ) else ( mutate z<-[_ _ param _]; 0 ) else if !strcmp action "setName" then ( mutate z <- [_ _ _ param]; UsendSrv this ui "Photo?" nil; 0 ) else nil ;; fun newOb(o) = if o==owner then let M3createShell session -> sh in let M3createShell session -> sh0 in ( M3setObjVec session sh0 [0 160 0]; let M3createSphere session 100 ->h in ( M3setObjVec session h [0 110 0]; M3link session h sh ); M3link session sh0 sh; M3link session sh shellav; let M3copyObj session avatar -> hnew in /* NEW */ ( M3recursFillMatObj session hnew; M3link session hnew sh0; ObCbAnim o mkfun2 @animPho [hnew 0]; /* FIN NEW */ ); ObSetMain o sh0; ObCbDestroy o @destroyPho; ObSetCam o; createbutton o; UcbComm this ObUi o mkfun4 @cbcomm [o nil nil nil]; UsendSrv this ObUi o "Name?" nil; 0 ) else let M3createShell session -> sh in let M3copyObj session avatar -> hnew in ( M3recursFillMatObj session hnew; M3link session hnew sh; ObSetMain o sh; ObCbAnim o mkfun2 @animPho [hnew 0]; ObCbDestroy o @destroy2Pho; UcbComm this ObUi o mkfun4 @cbcomm [o nil nil nil]; UsendSrv this ObUi o "Name?" nil; 0 ) ;; fun IniPlug(file) = set class=getInfo strextr _getpack _checkpack file "name"; let atoi hd Obgetglobalress strcat class ".refreshPeriod" -> tmp in if tmp!=nil && tmp>=0 then set refreshPeriod = tmp else nil; M3load session avfile nil; set avatar=M3getObj session "snap"; PlugRegister class @newOb nil; 0 ;;