/* Camera Plugin client - DMS - July 2000 - by Nadège SONNET */ /* Rev. Nov. 2000 - by Nadège SONNET */ /* Rev. Nov. 2003 - by BLG */ typeof class = S;; var avfile = "dms/3d/plugins/camera/x.m3d";; struct CAM = [ textureName : S, CAtxt : HTx3d, /* texture courante de l'objet */ CAshell : H3d, CAcamera : H3d, /* camera pour le rendu3D */ CAbuffer : ObjSurface, /* Buffer de rendu */ CAbitmap : ObjBitmap /* Bitmap du rendu sert pour le blitTexture */ ] mkCAM;; /* Get the first material in the anchor */ fun get_first_mat(list) = if (list == nil) then nil else let list -> [a nxt] in match a with (objAnchor [ob mat _ _] -> [ob mat]) | (_->get_first_mat nxt);; /* Refresh of the camera view in the materials texture */ fun refresh_mat(o, v, param) = let param -> [z y am] in let y+1 -> y in ( if (y > 2) then ( set y=0; MX3render session z.CAbuffer z.CAcamera 0 0 0; let _GETsurfaceSize z.CAbuffer -> [w h] in _Surface2Bitmap z.CAbitmap 0 0 z.CAbuffer 0 0 w h nil; M3blitTexture16 session z.CAtxt z.CAbitmap; M3chgMaterialTexture session am z.CAtxt; M3setType session am (M3getType session am)|MAT_TEXTURED; 0; ) else 0; mutate param <- [z y _]; 0; );; /* Restore the texture when instance is destroyed */ fun cbDestroy(o, z) = ObCbPostRender o nil; match hd ObAnchor o with (objAnchor [ah am _ _] -> ( M3delObj session z.CAshell; M3delObj session z.CAcamera; _DSsurface z.CAbuffer; _DSbitmap z.CAbitmap; M3renameTexture session z.CAtxt z.textureName; M3blitTexture16 session z.CAtxt openBMP z.textureName; M3chgMaterialTexture session am z.CAtxt; M3setType session am (M3getType session am)|MAT_TEXTURED; 0; ) ) | (_ -> nil); 0;; fun RefreshCamMat(a, v, param) = let param -> [sec oldsec l] in if (_tickcount >= (oldsec + sec)) then ( refresh_mat a v l; mutate param <- [ _ _tickcount _ ]; 0; ) else nil;; fun cbRegister(o,from,action,param,reply,z)= let z -> [l sp] in if !strcmp sp "auto" then ObCbPostRender o mkfun3 @refresh_mat l /***Automatic Render***/ else ObCbPostRender o mkfun3 @RefreshCamMat [atoi sp nil l];/***Custom Render***/ 0;; fun cbUnregister(o,from,action,param,reply)= ObCbPostRender o nil; 0;; fun newOb(o) = /* récupère paramètres caméra */ let atoi hd UgetParam ObUi o "DistX" -> DistX in let atoi hd UgetParam ObUi o "DistY" -> DistY in let atoi hd UgetParam ObUi o "Width" -> Width in let atoi hd UgetParam ObUi o "Height" -> Height in let atoi hd UgetParam ObUi o "ClippingDist" -> ClippingDist in let atoi hd UgetParam ObUi o "FogDist" -> FogDist in let atoi hd UgetParam ObUi o "Faraway" -> Faraway in let atoi hd UgetParam ObUi o "VecCam1" -> VecCam1 in let atoi hd UgetParam ObUi o "VecCam2" -> VecCam2 in let atoi hd UgetParam ObUi o "VecCam3" -> VecCam3 in let atoi hd UgetParam ObUi o "AngCam1" -> AngCam1 in let atoi hd UgetParam ObUi o "AngCam2" -> AngCam2 in let atoi hd UgetParam ObUi o "AngCam3" -> AngCam3 in let get_first_mat ObAnchor o -> [ah am] in if (am == nil) then /* not mat in anchor */ nil else let if ((VecCam1 != nil) && (VecCam2 != nil) && (VecCam3 != nil) && (AngCam1 != nil) && (AngCam2 != nil) && (AngCam3 != nil)) then /* dynamic */ [[VecCam1 VecCam2 VecCam3] [AngCam1 AngCam2 AngCam3]] else /* static */ nil -> [vec ang] in if ((vec == nil) || (ang == nil)) then nil else /*OK, there is at least one material or object in the anchor */ let mkCAM [nil nil nil nil nil nil] -> z in ( /*seb*/ let M3textureFromMaterial session am -> oldTxt in let M3textureName session oldTxt -> name in set z.textureName=name; M3load session avfile nil; set z.CAtxt = M3copyMaterialTexture session M3getMat session "snapmater"; /*fin seb*/ set z.CAshell=M3createShell session; /* Display parameters */ M3link session z.CAshell shell; M3load session "dms/3d/Plugins/Camera/cam2.m3d" z.CAshell; set z.CAcamera=M3getObj session "camera2"; M3setObjVec session z.CAcamera vec; M3setObjAng session z.CAcamera ang; ObCbDestroy o mkfun2 @cbDestroy z; M3setCamera session z.CAcamera [[DistX/2 DistY/2] [Width/2 Height/2] [ClippingDist FogDist Faraway]]; set z.CAbuffer = _CRsurface _channel Width Height; set z.CAbitmap = _CRbitmap _channel Width Height; /* refresh of the display in the texture */ let [z 0 am] -> l in let hd UgetParam ObUi o "a"-> sp in if !strcmpi hd UgetParam ObUi o "registeredClientsOnly" "yes" then ( ObRegisterAction o (strcatn (ObName o)::".register"::nil) mkfun6 @cbRegister [l sp]; ObRegisterAction o (strcatn (ObName o)::".unregister"::nil) @cbUnregister; 0; ) else if !strcmp sp "auto" then (ObCbPostRender o mkfun3 @refresh_mat l;0;) /***Automatic Render***/ else (ObCbPostRender o mkfun3 @RefreshCamMat [atoi sp nil l];0;)/***Custom Render***/ );; /********************************/ /********************************/ /********************************/ fun IniPlug(file)= set class = getInfo strextr _getpack _checkpack file "name"; PLUGsetinfo thisplug PLUGIN_ONLINE_EDITING|PLUGIN_RESERVED|PLUGIN_MATERIAL; PLUGdefineEditor thisplug @dynamicedit; PlugRegister class @newOb nil; 0;;