/* Lights Plugin - DMS - sept 99 - by Sylvain HUET */ /* rev December 99 - by Sebastien DENEUX*/ /* REV: Arkeon */ /* Last update: 07.04.02 */ typeof class = S;; typeof light3d = H3d;; fun lightbyname(s) = if !strcmp s "LIGHT_AMBIENT" then LIGHT_AMBIENT else if !strcmp s "LIGHT_PARA" then LIGHT_PARA else if !strcmp s "LIGHT_OMNI" then LIGHT_OMNI else LIGHT_SPOT ;; fun dellights(o,x) = M3delObj session o ;; fun crLight(l, type, ambient, diffuse, specular, angle, const, quadr) = if l==nil then nil else let l->[x n] in let match x with (objAnchor [h _ _ _] -> let M3createColorLight session type ambient diffuse specular angle const quadr -> nl in ( M3link session nl h; set light3d = nl; nl ) ) |(_->nil) -> y in if y==nil then crLight n type ambient diffuse specular angle const quadr else y::crLight n type ambient diffuse specular angle const quadr ;; fun crLightSoft(l, type, a, b, c) = if l==nil then nil else let l->[x n] in let match x with (objAnchor [h _ _ _] -> let M3createLight session type a b c nil nil -> nl in ( M3link session nl h; set light3d = nl; nl ) ) |(_->nil) -> y in if y==nil then crLightSoft n type a b c else y::crLightSoft n type a b c ;; fun createlights(o)= let hd UgetParam ObUi o "type" -> type in let htoi hd UgetParam ObUi o "ambient" -> amb in let htoi hd UgetParam ObUi o "diffuse" -> dif in let htoi hd UgetParam ObUi o "specular" -> spec in let atoi hd UgetParam ObUi o "angle" -> ang in let atoi hd UgetParam ObUi o "const" -> con in let atoi hd UgetParam ObUi o "quadr" -> qua in let atoi hd UgetParam ObUi o "a" -> a in let atoi hd UgetParam ObUi o "b" -> b in let atoi hd UgetParam ObUi o "c" -> c in let _GETengineState -> state in if (state==ENGINE_HARDWARE) then ( crLight ObAnchor o lightbyname type amb dif spec ang con qua ) else if (state==ENGINE_SOFTWARE) then ( crLightSoft ObAnchor o lightbyname type a b c ) else nil ;; fun cbcomm(ui, action, param, z) = let z->[o l] in if !strcmp action "setState" then let atoi param -> state in ( apply_on_list l @dellights nil; mutate z<-[_ if state then createlights o else nil] ) else nil; 0 ;; fun delete(o,z) = let z -> [_ l] in apply_on_list l @dellights nil; 0 ;; fun Activate (o, from, action, param, reply, z)= let z -> [_ l] in ( apply_on_list l @dellights nil; if !strcmp action (strcatn (ObName o)::".onC"::nil) then mutate z<-[_ createlights o] else mutate z<-[_ nil]; ); 0 ;; fun newOb(o) = let [o nil] -> z in ( UcbComm this ObUi o mkfun4 @cbcomm z; UsendSrv this ObUi o "state?" nil; ObCbDestroy o mkfun2 @delete z; ObRegisterAction o (strcatn (ObName o)::".onC"::nil) mkfun6 @Activate z; ObRegisterAction o (strcatn (ObName o)::".offC"::nil) mkfun6 @Activate z; 0 ) ;; fun IniPlug(file)= set class=getInfo strextr _getpack _checkpack file "name"; PLUGsetinfo thisplug PLUGIN_ONLINE_EDITING|PLUGIN_OBJECT|PLUGIN_NOTRESERVED; PLUGdefineEditor thisplug @dynamicedit; PlugRegister class @newOb nil; 0 ;;