/* Lights Plugin - DMS - sept 99 - by Sylvain HUET */ /* rev December 99 - by Sebastien DENEUX*/ /*to do : variation p1, p2, p3 +timer anim en cours (actuellement action setParam désactivée)*/ typeof class = S;; var defaultAnimLength=2000;; 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, a, b, c, d) = if l==nil then nil else let l->[x n] in let match x with (objAnchor [h _ _ _] -> let M3createLight session a b c d nil nil -> nl in ( M3link session nl h; nl ) ) |(_->nil) -> y in if y==nil then crLight n a b c d else y::crLight n a b c d ;; fun createlights(o)= let hd UgetParam ObUi o "type" -> type 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 "p1" -> p1 in crLight ObAnchor o lightbyname type a b p1 /* if !strcmp type "LIGHT_AMBIENT" then crLight ObAnchor o lightbyname hd UgetParam ObUi o "type" atoi hd UgetParam ObUi o "Ambient_puissance" nil nil else if !strcmp type "LIGHT_PARA" then crLight ObAnchor o lightbyname hd UgetParam ObUi o "type" atoi hd UgetParam ObUi o "Para_avant" atoi hd UgetParam ObUi o "Para_arriere" nil else if !strcmp type "LIGHT_OMNI" then crLight ObAnchor o lightbyname hd UgetParam ObUi o "type" atoi hd UgetParam ObUi o "Omni_min" atoi hd UgetParam ObUi o "Omni_max" atoi hd UgetParam ObUi o "Omni_distance" else if !strcmp type "LIGHT_SPOT" then crLight ObAnchor o lightbyname hd UgetParam ObUi o "type" atoi hd UgetParam ObUi o "Spot_min" atoi hd UgetParam ObUi o "Spot_max" atoi hd UgetParam ObUi o "Spot_distance" else nil */ ;; /*fun setParams(l,type,a,b,p1,p2,p3)= if l==nil then nil else let l -> [t q] in (M3setLight session t [type a b p1 p2 p3]; setParams q type a b p1 p2 p3; 0);; fun _seta(timer,z)= let z -> [l currentp deltaa a] in let currentp -> [type cura curb curp1 curp2 curp3] in ( mutate currentp <- [_ cura+deltaa _ _ _ _]; setParams l type cura+deltaa curb curp1 curp2 curp3; if cura+deltaa==a then _deltimer timer else nil );; fun _setb(timer,z)= let z -> [l currentp deltab b] in let currentp -> [type cura curb curp1 curp2 curp3] in ( mutate currentp <- [_ _ curb+deltab _ _ _]; setParams l type cura curb+deltab curp1 curp2 curp3; if curb+deltab==b then _deltimer timer else nil );; fun setParam(o,from,action,param,reply,z)= let z-> [_ l] in let strextr param -> s in let atoi getInfo s "a" -> a in let atoi getInfo s "b" -> b in let atoi getInfo s "p1" -> p1 in let atoi getInfo s "p2" -> p2 in let atoi getInfo s "p3" -> p3 in let getInfo s "animLength" -> tmp in let if tmp==nil then defaultAnimLength else atoi tmp -> animLength in let M3getLight session hd l -> currentp in let currentp -> [type cura curb curp1 curp2 curp3] in let if a==nil then 0 else if cura>a then -1 else if cura deltaa in let if b==nil then 0 else if curb>b then -1 else if curb deltab in ( if deltaa!=0 then _rfltimer _starttimer _channel (animLength/(abs cura-a)-1) @_seta [l currentp deltaa a] else nil; if deltab!=0 then _rfltimer _starttimer _channel (animLength/(abs curb-b)-1) @_setb [l currentp deltab b] else nil; if deltaa!=0 || deltab!=0 then ( mutate currentp <- [_ cura+deltaa curb+deltab _ _ _]; setParams l type cura+deltaa curb+deltab curp1 curp2 curp3 ) else nil; 0 );;*/ 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 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)::".setParam"::nil) mkfun6 @setParam 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 ;;