/* ----------------------------------------------------------------------------- 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 PlugAnimTrans = [ PANIMT_inst : PInstance, PANIMT_anim1 : V3Danim, PANIMT_anim2 : V3Danim, PANIMT_bFade1 : I, PANIMT_bFade2 : I, PANIMT_fSpeed : F, PANIMT_iTick : I ]mkPlugAnimTrans;; fun deleteOb(inst, panimstr)= V3DstopAnimation panimstr.PANIMT_anim1; V3DenableAnimation panimstr.PANIMT_anim1 0; V3DstopAnimation panimstr.PANIMT_anim2; V3DenableAnimation panimstr.PANIMT_anim2 0; setPluginInstanceCbPreRender inst nil; 0;; fun cbGetAnimFadeIn(inst, view3d, panimstr)= let V3DgetAnimationWeight panimstr.PANIMT_anim1 -> weight1 in let V3DgetAnimationWeight panimstr.PANIMT_anim2 -> weight2 in let (itof (_tickcount - panimstr.PANIMT_iTick)) /. 1000.0 -> deltatime in ( //fade out if !panimstr.PANIMT_bFade1 then nil else let weight1 -. (deltatime *. panimstr.PANIMT_fSpeed) -> nweight in ( V3DsetAnimationWeight panimstr.PANIMT_anim1 (SO3MathsClampValue nweight 0.0 1.0); if /*(V3DgetAnimationState panimstr.PANIMT_anim1) ||*/ (nweight <=. 0.0) then nil else V3DplayAnimation panimstr.PANIMT_anim1; if (nweight <=. 0.0) || (!V3DgetAnimationState panimstr.PANIMT_anim1) then ( if (V3DgetAnimationLoop panimstr.PANIMT_anim1) then nil else V3DpauseAnimation panimstr.PANIMT_anim1; set panimstr.PANIMT_bFade1 = 0; ) else nil; ); //fade in if !panimstr.PANIMT_bFade2 then nil else let weight2 +. (deltatime *. panimstr.PANIMT_fSpeed) -> nweight in let if (V3DgetAnimationWeight panimstr.PANIMT_anim2) >=. 1.0 then (V3DgetAnimationWeight panimstr.PANIMT_anim2) else nweight -> nweight in ( V3DsetAnimationWeight panimstr.PANIMT_anim2 (SO3MathsClampValue nweight 0.0 1.0); if V3DgetAnimationState panimstr.PANIMT_anim2 then nil else V3DplayAnimation panimstr.PANIMT_anim2; if (nweight >=. 1.0) /*|| (!V3DgetAnimationState panimstr.PANIMT_anim2)*/ then set panimstr.PANIMT_bFade2 = 0 else nil; ); set panimstr.PANIMT_iTick = _tickcount; if panimstr.PANIMT_bFade1 || panimstr.PANIMT_bFade2 then nil else ( setPluginInstanceCbPreRender inst nil; SendPluginEvent inst "Transition ended" nil nil; ); ); 0;; fun cbGetAnimFadeOut(inst, view3d, panimstr)= let V3DgetAnimationWeight panimstr.PANIMT_anim1 -> weight1 in let V3DgetAnimationWeight panimstr.PANIMT_anim2 -> weight2 in let (itof (_tickcount - panimstr.PANIMT_iTick)) /. 1000.0 -> deltatime in ( //fade out if !panimstr.PANIMT_bFade2 then nil else let weight2 -. (deltatime *. panimstr.PANIMT_fSpeed) -> nweight in ( V3DsetAnimationWeight panimstr.PANIMT_anim2 (SO3MathsClampValue nweight 0.0 1.0); if /*(V3DgetAnimationState panimstr.PANIMT_anim2) ||*/ (nweight <=. 0.0) then nil else V3DplayAnimation panimstr.PANIMT_anim2; if (nweight <=. 0.0) || (!V3DgetAnimationState panimstr.PANIMT_anim2) then ( if (V3DgetAnimationLoop panimstr.PANIMT_anim2) then nil else V3DpauseAnimation panimstr.PANIMT_anim2; set panimstr.PANIMT_bFade2 = 0; ) else nil; ); //fade in if !panimstr.PANIMT_bFade1 then nil else let weight1 +. (deltatime *. panimstr.PANIMT_fSpeed) -> nweight in let if (V3DgetAnimationWeight panimstr.PANIMT_anim1) >=. 1.0 then (V3DgetAnimationWeight panimstr.PANIMT_anim1) else nweight -> nweight in ( V3DsetAnimationWeight panimstr.PANIMT_anim1 (SO3MathsClampValue nweight 0.0 1.0); if V3DgetAnimationState panimstr.PANIMT_anim1 then nil else V3DplayAnimation panimstr.PANIMT_anim1; if (nweight >=. 1.0) /*|| (!V3DgetAnimationState panimstr.PANIMT_anim1)*/ then set panimstr.PANIMT_bFade1 = 0 else nil; ); set panimstr.PANIMT_iTick = _tickcount; if panimstr.PANIMT_bFade1 || panimstr.PANIMT_bFade2 then nil else ( setPluginInstanceCbPreRender inst nil; SendPluginEvent inst "Transition ended" nil nil; ); ); 0;; fun cbFadeIn(inst, from, action, param, rep, panimstr) = set panimstr.PANIMT_iTick = _tickcount; set panimstr.PANIMT_bFade1 = 1; set panimstr.PANIMT_bFade2 = 1; V3DsetAnimationWeight panimstr.PANIMT_anim2 0.0; SendPluginEvent inst "Transition started" nil nil; setPluginInstanceCbPreRender inst mkfun3 @cbGetAnimFadeIn panimstr; 0;; fun cbFadeOut(inst, from, action, param, rep, panimstr) = set panimstr.PANIMT_iTick = _tickcount; set panimstr.PANIMT_bFade1 = 1; set panimstr.PANIMT_bFade2 = 1; V3DsetAnimationWeight panimstr.PANIMT_anim1 0.0; SendPluginEvent inst "Transition started" nil nil; setPluginInstanceCbPreRender inst mkfun3 @cbGetAnimFadeOut panimstr; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "anim1") -> animname1 in let (getPluginInstanceParam inst "anim2") -> animname2 in let atof (getPluginInstanceParam inst "speed") -> speed in let if speed == nil then 1.0 else speed -> speed in let V3DgetAnimationByName c3dXsession animname1 -> anim1str in let V3DgetAnimationByName c3dXsession animname2 -> anim2str in let mkPlugAnimTrans [inst anim1str anim2str 0 0 speed nil] -> panimstr in ( PluginRegisterAction inst "Fade in" mkfun6 @cbFadeIn panimstr; PluginRegisterAction inst "Fade out" mkfun6 @cbFadeOut panimstr; setPluginInstanceCbDel inst mkfun2 @deleteOb panimstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;