/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct SkyTransitionStr = [ PST_timeSpeed : F, PST_cWindSpeed : [F F F], //src dst time PST_cWindDir : [F F F F F F], PST_cTime : [I I I I F], PST_cSunColor : [F F F F F F F F F], PST_cMoonColor : [F F F F F F F F F], PST_dlgstr : VUIDlg, PST_bDefaultLight : I ] MkSkyTransitionStr;; fun deleteOb(inst, obstr)= setPluginInstanceCbScenePreRender inst nil; VUIdestroyDialogBox obstr.PST_dlgstr; //let c3dXsession -> sessionstr in //SO3SkySetEnable (V3DgetSession sessionstr) 0; 0;; fun cbScenePreRender(inst, sessionstr, etime, obstr)= if (obstr.PST_timeSpeed <=. 0.0) then nil else let c3dXsession -> sessionstr in let if etime == 0 then 1 else etime -> etime in let (itof etime) /. 1000000.0 -> ftime in ( if (obstr.PST_cWindSpeed == nil) then nil else let obstr.PST_cWindSpeed -> [src dst tm] in let tm +. ftime -> ntm in let (((dst -. src) /. obstr.PST_timeSpeed) *. ntm) -> nval in ( if (ntm >=. obstr.PST_timeSpeed) || ((src +. nval) == dst) then ( SO3EnvironmentSetWindSpeed (V3DgetSession sessionstr) dst; set obstr.PST_cWindSpeed = nil; 0; ) else ( SO3EnvironmentSetWindSpeed (V3DgetSession sessionstr) src +. nval; mutate obstr.PST_cWindSpeed <- [_ _ ntm]; 0; ); ); if (obstr.PST_cWindDir == nil) then nil else let obstr.PST_cWindDir -> [srcx srcy dstx dsty tmx tmy] in let tmx +. ftime -> ntmx in let tmy +. ftime -> ntmy in let (((dstx -. srcx) /. obstr.PST_timeSpeed) *. ntmx) -> nvalx in let (((dsty -. srcy) /. obstr.PST_timeSpeed) *. ntmy) -> nvaly in let if ((ntmx >=. obstr.PST_timeSpeed) || ((srcx +. nvalx) == dstx)) then dstx else (srcx +. nvalx) -> nvx in let if ((ntmy >=. obstr.PST_timeSpeed) || ((srcy +. nvaly) == dsty)) then dsty else (srcy +. nvaly) -> nvy in ( SO3EnvironmentSetWindDirection (V3DgetSession sessionstr) nvx nvy; if ((nvx == dstx) && (nvy == dsty)) then set obstr.PST_cWindDir = nil else mutate obstr.PST_cWindDir <- [_ _ _ _ ntmx ntmy]; ); if (obstr.PST_cTime == nil) then nil else let obstr.PST_cTime -> [srcx srcy dstx dsty tm] in let getCurrentDateTime 1 -> [dateday datemonth dateyear _ _ _] in let getSecondsFromDateTime dateday datemonth dateyear srcx srcy 0 -> ssec in let ssec + ((dstx - srcx) * 3600) + ((dsty - srcy) * 60) -> dsec in let tm +. ftime -> ntm in let ftoi (((itof (dsec - ssec)) /. obstr.PST_timeSpeed) *. ntm) -> nval in ( if (ntm >=. obstr.PST_timeSpeed) || ((ssec + nval) == dsec) then ( let (gmtime dsec) -> [seconds minutes hours day month year _ _] in SO3EnvironmentSetDateTime (V3DgetSession sessionstr) year month day hours minutes seconds; set obstr.PST_cTime = nil; 0; ) else ( let (gmtime ssec + nval) -> [seconds minutes hours day month year _ _] in SO3EnvironmentSetDateTime (V3DgetSession sessionstr) year month day hours minutes seconds; mutate obstr.PST_cTime <- [_ _ _ _ ntm]; 0; ); ); if (obstr.PST_cSunColor == nil) then nil else let obstr.PST_cSunColor -> [sr sg sb dr dg db tmr tmg tmb] in let tmr +. ftime -> ntmr in let tmg +. ftime -> ntmg in let tmb +. ftime -> ntmb in let (((dr -. sr) /. obstr.PST_timeSpeed) *. ntmr) -> nvalr in let (((dg -. sg) /. obstr.PST_timeSpeed) *. ntmg) -> nvalg in let (((db -. sb) /. obstr.PST_timeSpeed) *. ntmb) -> nvalb in let if (ntmr >=. obstr.PST_timeSpeed) || ((sr +. nvalr) == dr) then (ftoi dr) else (ftoi (sr +. nvalr)) -> nr in let if (ntmg >=. obstr.PST_timeSpeed) || ((sg +. nvalg) == dg) then (ftoi dg) else (ftoi (sg +. nvalg)) -> ng in let if (ntmb >=. obstr.PST_timeSpeed) || ((sb +. nvalb) == db) then (ftoi db) else (ftoi (sb +. nvalb)) -> nb in ( SO3SunSetLightColor (V3DgetSession sessionstr) G2Drgb2rgba make_rgb nr ng nb 0; if ((nr == (ftoi dr)) && (ng == (ftoi dg)) && (nb == (ftoi db))) then set obstr.PST_cSunColor = nil else mutate obstr.PST_cSunColor <- [_ _ _ _ _ _ ntmr ntmg ntmb]; ); if (obstr.PST_cMoonColor == nil) then nil else let obstr.PST_cMoonColor -> [sr sg sb dr dg db tmr tmg tmb] in let tmr +. ftime -> ntmr in let tmg +. ftime -> ntmg in let tmb +. ftime -> ntmb in let (((dr -. sr) /. obstr.PST_timeSpeed) *. ntmr) -> nvalr in let (((dg -. sg) /. obstr.PST_timeSpeed) *. ntmg) -> nvalg in let (((db -. sb) /. obstr.PST_timeSpeed) *. ntmb) -> nvalb in let if (ntmr >=. obstr.PST_timeSpeed) || ((sr +. nvalr) == dr) then (ftoi dr) else (ftoi (sr +. nvalr)) -> nr in let if (ntmg >=. obstr.PST_timeSpeed) || ((sg +. nvalg) == dg) then (ftoi dg) else (ftoi (sg +. nvalg)) -> ng in let if (ntmb >=. obstr.PST_timeSpeed) || ((sb +. nvalb) == db) then (ftoi db) else (ftoi (sb +. nvalb)) -> nb in ( SO3SunSetLightColor (V3DgetSession sessionstr) G2Drgb2rgba make_rgb nr ng nb 0; if ((nr == (ftoi dr)) && (ng == (ftoi dg)) && (nb == (ftoi db))) then set obstr.PST_cMoonColor = nil else mutate obstr.PST_cMoonColor <- [_ _ _ _ _ _ ntmr ntmg ntmb]; ); ); 0;; fun enableSky(obstr, state)= let (V3DgetSession c3dXsession) -> session in ( SO3EnvironmentSetEnable session state; SO3SkySetEnable session state; if (!obstr.PST_bDefaultLight) then nil else V3DuseDefaultLight c3dXsession !state; ); 0;; fun cbEnable(inst, from, action, param, rep, obstr)= enableSky obstr 1; 0;; fun cbDisable(inst, from, action, param, rep, obstr)= enableSky obstr 0; 0;; fun cbSetTime(inst, from, action, param, rep, obstr)= let strextr param -> lp in let hd lp -> nlp in let atoi hd nlp -> datehours in let if datehours == nil then 0 else datehours -> datehours in let atoi hd tl nlp -> dateminutes in let if dateminutes == nil then 0 else dateminutes -> dateminutes in let getCurrentDateTime 1 -> [dateday datemonth dateyear _ _ _] in let c3dXsession -> sessionstr in if (obstr.PST_timeSpeed <=. 0.0) then ( SO3EnvironmentSetDateTime (V3DgetSession sessionstr) dateyear datemonth dateday datehours dateminutes 0; 0; ) else ( let SO3EnvironmentGetDateTime (V3DgetSession sessionstr) -> [yr m d h mn s] in ( set obstr.PST_cTime = [h mn datehours dateminutes 0.0]; ); 0; ); 0;; fun cbSet3dClouds(inst, from, action, param, rep, obstr)= let atoi param -> state in let c3dXsession -> sessionstr in ( if (state) then ( if (sizelist (SO3SkyGetLayeredCloudIndexes (V3DgetSession sessionstr))) <= 0 then nil else SO3SkyRemoveLayeredCloud (V3DgetSession sessionstr) (hd (SO3SkyGetLayeredCloudIndexes (V3DgetSession sessionstr))); 0; ) else ( SO3SkyAddLayeredCloud (V3DgetSession sessionstr); 0; ); SO3SkyComponentSetEnabled (V3DgetSession sessionstr) SO3_SKY_COMPONENT_VOLUMETRIC_CLOUD state; SO3SkyComponentSetEnabled (V3DgetSession sessionstr) SO3_SKY_COMPONENT_LAYERER_CLOUD !state; ); 0;; fun cbSetTimeShifting(inst, from, action, param, rep, obstr)= let atof param -> val in let c3dXsession -> sessionstr in SO3EnvironmentSetTimeSpeedFactor (V3DgetSession sessionstr) val; 0;; fun cbSetUseRealTime(inst, from, action, param, rep, obstr)= let atoi param -> value in let c3dXsession -> sessionstr in if (value) then ( let getCurrentDateTime 1 -> [day month year hours minutes seconds] in SO3EnvironmentSetDateTime (V3DgetSession sessionstr) year month day hours minutes seconds; SO3EnvironmentSetTimeSpeedFactor (V3DgetSession sessionstr) 1.0; 0; ) else ( 0; ); 0;; fun cbSetSunColor(inst, from, action, param, rep, obstr)= let if (!strcmp "0x" (substr param 0 2)) then G2Drgb2rgba G2Drgb2bgr htoi param 0 else let hd strextr param -> lp in let atoi hd lp -> r in let atoi hd tl lp -> g in let atoi hd tl tl lp -> b in make_rgba r g b 128 -> color in let c3dXsession -> sessionstr in if (obstr.PST_timeSpeed <=. 0.0) then ( SO3SunSetLightColor (V3DgetSession sessionstr) color; 0; ) else ( let get_rgba SO3SunGetLightColor (V3DgetSession sessionstr) -> [sr sg sb sa] in let get_rgba color -> [dr dg db da] in set obstr.PST_cSunColor = [(itof sr) (itof sg) (itof sb) (itof dr) (itof dg) (itof db) 0.0 0.0 0.0]; 0; ); 0;; fun cbSetMoonColor(inst, from, action, param, rep, obstr)= let if (!strcmp "0x" (substr param 0 2)) then G2Drgb2rgba G2Drgb2bgr htoi param 0 else let hd strextr param -> lp in let atoi hd lp -> r in let atoi hd tl lp -> g in let atoi hd tl tl lp -> b in make_rgba r g b 128 -> color in let c3dXsession -> sessionstr in if (obstr.PST_timeSpeed <=. 0.0) then ( SO3MoonSetLightColor (V3DgetSession sessionstr) color; 0; ) else ( let get_rgba SO3MoonGetLightColor (V3DgetSession sessionstr) -> [sr sg sb sa] in let get_rgba color -> [dr dg db da] in set obstr.PST_cMoonColor = [(itof sr) (itof sg) (itof sb) (itof dr) (itof dg) (itof db) 0.0 0.0 0.0]; 0; ); 0;; fun cbSetWindDirection(inst, from, action, param, rep, obstr)= let hd strextr param -> lp in let atof hd lp -> x in let atof hd tl lp -> y in //normalize let (absf x) +. (absf y) -> sum in let if (sum == 0.0) then 1.0 else 1.0 /. sum -> coef in let [(x *. coef) (y *. coef)] -> [x y] in let c3dXsession -> sessionstr in if (obstr.PST_timeSpeed <=. 0.0) then ( SO3EnvironmentSetWindDirection (V3DgetSession sessionstr) x y; 0; ) else ( let SO3EnvironmentGetWindDirection (V3DgetSession sessionstr) -> [dx dy] in set obstr.PST_cWindDir = [dx dy x y 0.0 0.0]; 0; ); 0;; fun cbSetWindForce(inst, from, action, param, rep, obstr)= let atof param -> value in let c3dXsession -> sessionstr in if (obstr.PST_timeSpeed <=. 0.0) then ( SO3EnvironmentSetWindSpeed (V3DgetSession sessionstr) value; 0; ) else ( set obstr.PST_cWindSpeed = [SO3EnvironmentGetWindSpeed (V3DgetSession sessionstr) value 0.0]; 0; ); 0;; fun cbSetHumidity(inst, from, action, param, rep, obstr)= let atof param -> value in let c3dXsession -> sessionstr in SO3EnvironmentSetHumidity (V3DgetSession sessionstr) value; 0;; fun cbSetCloudCeiling(inst, from, action, param, rep, obstr)= let atof param -> value in let c3dXsession -> sessionstr in SO3SkySetCloudCeiling (V3DgetSession sessionstr) value; 0;; fun cbSetTransition(inst, from, action, param, rep, obstr)= set obstr.PST_timeSpeed = atof param; 0;; fun getAlign(param)= let [1 1] -> align in let [0.0 0.0] -> pos in let strextr param -> lp in let hd lp -> lp in let 0 -> nb in ( while ((lp != nil) && (nb < 2)) do ( let hd lp -> flag in if (!strcmpi flag "top") then ( mutate align <- [_ 0]; mutate pos <- [_ 10.0]; ) else if (!strcmpi flag "bottom") then ( mutate align <- [_ 2]; mutate pos <- [_ 10.0]; ) else if (!strcmpi flag "left") then ( mutate align <- [0 _]; mutate pos <- [10.0 _]; ) else if (!strcmpi flag "right") then ( mutate align <- [2 _]; mutate pos <- [10.0 _]; ) else nil; set lp = tl lp; set nb = nb + 1; ); [pos align]; );; fun cbClickDlg(dlgstr, state, obstr)= set obstr.PST_dlgstr = nil; //SendPluginEvent obstr.PST_instance "Click Ok" nil nil; 0;; fun cbChangeValue(floatstr, value, state, p)= let p -> [obstr t dfloatstr] in ( let c3dXsession -> sessionstr in let SO3EnvironmentGetDateTime (V3DgetSession sessionstr) -> [yr m d h mn s] in let if (t == 1) then ftoi value else yr -> yr in let if (t == 2) then ftoi value else m -> m in let if (t == 3) then ftoi value else d -> d in let if (t == 4) then ftoi value else h -> h in let if (t == 5) then ftoi value else mn -> mn in let getMonthDays m yr -> nbdays in let if (d > nbdays) then nbdays else d -> d in ( VUIsetFloatMaxValue dfloatstr (itof nbdays); SO3EnvironmentSetDateTime (V3DgetSession sessionstr) yr m d h mn 0; ); ); 0;; fun cbShowDateInterface(inst, from, action, param, reply, obstr)= if (obstr.PST_dlgstr == nil) then nil else VUIdestroyDialogBox obstr.PST_dlgstr; let c3dXsession -> sessionstr in let V3DgetSessionView sessionstr -> viewstr in let SO3EnvironmentGetDateTime (V3DgetSession sessionstr) -> [yr m d h mn s] in let getMonthDays m yr -> nbdays in let VUIcreateDialogExt (V3DgetSessionView c3dXsession) inst.INST_groupstr.GRP_project.PRJ_vuiGroup [350 250] (loc "OS3DSKY_C0001") (loc "OS3DSKY_C0002") nil 95 (V3DgetVrMode viewstr) (mkfun3 @cbClickDlg obstr) "dialogBox" -> dlgstr in let VUIgetDialogFrame dlgstr -> framestr in let VUIgetElementContainer framestr -> contstr in let VUIgetThemeDef (getThemeFromInstance inst) "dialogBox" -> defstr in let VUIgetThemeFont defstr "label" -> lbfontstr in let 60 -> labelw in let VUIcreateFrame contstr framestr [0.0 10.0] [100.0 0.0] [0 0 0 0 0 0 0 0] [0 0] -> lyear in let VUIcreateFrame contstr framestr [0.0 50.0] [100.0 0.0] [0 0 0 0 0 0 0 0] [0 0] -> lmonth in let VUIcreateFrame contstr framestr [0.0 90.0] [100.0 0.0] [0 0 0 0 0 0 0 0] [0 0] -> lday in let VUIcreateFloat contstr framestr [60.0 10.0] [100.0 35.0] [0 0 1 0 0 0 (-(60 + 50)) 0] [1 0] [5 5] (-.10000.0) 10000.0 1.0 0 (itof yr) -> yfloatstr in let VUIcreateFloat contstr framestr [60.0 50.0] [100.0 35.0] [0 0 1 0 0 0 (-(60 + 50)) 0] [1 0] [5 5] 1.0 12.0 1.0 0 (itof m) -> mfloatstr in let VUIcreateFloat contstr framestr [60.0 90.0] [100.0 35.0] [0 0 1 0 0 0 (-(60 + 50)) 0] [1 0] [5 5] 1.0 (itof nbdays) 1.0 0 (itof d) -> dfloatstr in let VUIcreateFrame contstr framestr [0.0 150.0] [100.0 0.0] [0 0 0 0 0 0 0 0] [0 0] -> lhour in let VUIcreateFrame contstr framestr [0.0 190.0] [100.0 0.0] [0 0 0 0 0 0 0 0] [0 0] -> lmin in let VUIcreateFloat contstr framestr [60.0 150.0] [100.0 35.0] [0 0 1 0 0 0 (-(60 + 50)) 0] [1 0] [5 5] 0.0 23.0 1.0 0 (itof h) -> hfloatstr in let VUIcreateFloat contstr framestr [60.0 190.0] [100.0 35.0] [0 0 1 0 0 0 (-(60 + 50)) 0] [1 0] [5 5] 0.0 59.0 1.0 0 (itof mn) -> mnfloatstr in ( VUIsetElementText lyear lbfontstr (loc "OS3DSKY_C0003") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetElementText lmonth lbfontstr (loc "OS3DSKY_C0004") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetElementText lday lbfontstr (loc "OS3DSKY_C0005") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetElementText lhour lbfontstr (loc "OS3DSKY_C0006") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetElementText lmin lbfontstr (loc "OS3DSKY_C0007") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetFloatCbChange yfloatstr mkfun4 @cbChangeValue [obstr 1 dfloatstr]; VUIsetFloatCbChange mfloatstr mkfun4 @cbChangeValue [obstr 2 dfloatstr]; VUIsetFloatCbChange dfloatstr mkfun4 @cbChangeValue [obstr 3 dfloatstr]; VUIsetFloatCbChange hfloatstr mkfun4 @cbChangeValue [obstr 4 dfloatstr]; VUIsetFloatCbChange mnfloatstr mkfun4 @cbChangeValue [obstr 5 dfloatstr]; if (!strcmp "" (strtrim param)) || param == nil then nil else let getAlign param -> [pos align] in VUIsetContainerPos contstr pos align nil; set obstr.PST_dlgstr = dlgstr; VUIsetContainerClear contstr 0; VUIshowDialog dlgstr 1; ); //SendPluginEvent inst "Shown" nil nil; 0;; fun newOb(inst)= let c3dXsession -> sessionstr in let V3DgetDefaultViewport (V3DgetSessionView sessionstr) -> defaultviewportstr in let atoi (getPluginInstanceParam inst "init") -> init in let if (init == nil) then 1 else init -> init in let atof (getPluginInstanceParam inst "transitionTime") -> transitionTime in let if transitionTime == nil then 1.0 else transitionTime -> transitionTime in let MkSkyTransitionStr [transitionTime nil nil nil nil nil nil (V3DisDefaultLightEnable sessionstr)] -> obstr in ( if ((SO3EnvironmentGetEnable (V3DgetSession sessionstr)) == 1) then nil else ( SO3EnvironmentRegisterViewport (V3DgetSession sessionstr) defaultviewportstr.V3D_viewport; SO3EnvironmentSetHumidity (V3DgetSession sessionstr) 45.0; SO3EnvironmentSetWindDirection (V3DgetSession sessionstr) 1.0 0.0; SO3EnvironmentSetWindSpeed (V3DgetSession sessionstr) 1.0; SO3SkySetCloudCeiling (V3DgetSession sessionstr) 100.0; if (sizelist (SO3SkyGetLayeredCloudIndexes (V3DgetSession sessionstr))) <= 0 then nil else SO3SkyRemoveLayeredCloud (V3DgetSession sessionstr) (hd (SO3SkyGetLayeredCloudIndexes (V3DgetSession sessionstr))); SO3SkyAddLayeredCloud (V3DgetSession sessionstr); SO3SkyComponentSetEnabled (V3DgetSession sessionstr) SO3_SKY_COMPONENT_LAYERER_CLOUD 1; SO3SkyComponentSetEnabled (V3DgetSession sessionstr) SO3_SKY_COMPONENT_VOLUMETRIC_CLOUD 0; //default on paris SO3EnvironmentSetLongitude (V3DgetSession sessionstr) 2.34880; SO3EnvironmentSetLatitude (V3DgetSession sessionstr) 48.85340; SO3EnvironmentSetPaused (V3DgetSession sessionstr) 0; ); PluginRegisterAction inst "Enable" mkfun6 @cbEnable obstr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable obstr; PluginRegisterAction inst "Set time" mkfun6 @cbSetTime obstr; PluginRegisterAction inst "Set time shifting" mkfun6 @cbSetTimeShifting obstr; PluginRegisterAction inst "Use real time" mkfun6 @cbSetUseRealTime obstr; PluginRegisterAction inst "Set sun light color" mkfun6 @cbSetSunColor obstr; PluginRegisterAction inst "Set moon light color" mkfun6 @cbSetMoonColor obstr; PluginRegisterAction inst "Set wind direction" mkfun6 @cbSetWindDirection obstr; PluginRegisterAction inst "Set wind force" mkfun6 @cbSetWindForce obstr; PluginRegisterAction inst "Set humidity" mkfun6 @cbSetHumidity obstr; PluginRegisterAction inst "Set 3D clouds" mkfun6 @cbSet3dClouds obstr; PluginRegisterAction inst "Set cloud ceiling" mkfun6 @cbSetCloudCeiling obstr; PluginRegisterAction inst "Set transition time" mkfun6 @cbSetTransition obstr; PluginRegisterAction inst "Open date interface" mkfun6 @cbShowDateInterface obstr; setPluginInstanceCbScenePreRender inst mkfun4 @cbScenePreRender obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; enableSky obstr init; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;