/* ----------------------------------------------------------------------------- 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 PlugTextureShift = [ PTEX_shell : SO3_OBJECT, PTEX_material : SO3_MATERIAL, PTEX_iTechnique : I, PTEX_iPass : I, PTEX_iTextureUnit : I, PTEX_fUspeed : F, PTEX_fVspeed : F, PTEX_tOrigin : [F F], PTEX_tCurrent : [F F], PTEX_bState : I ]mkPlugTextureShift;; fun deleteOb(inst, shiftparams)= setPluginInstanceCbPostRender inst nil; SO3MaterialSetTextureScrollAnimation shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit 0.0 0.0; let shiftparams.PTEX_tOrigin -> [uorigin vorigin] in ( SO3MaterialSetTextureUScroll shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit uorigin; SO3MaterialSetTextureVScroll shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit vorigin; ); 0;; fun cbGetCurrentUvPos(inst, viewstr, shiftparams)= let SO3MaterialGetTextureUScroll shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit -> ucurrent in let SO3MaterialGetTextureVScroll shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit -> vcurrent in let shiftparams.PTEX_tOrigin -> [uorigin vorigin] in let shiftparams.PTEX_tCurrent -> [uprev vprev] in ( if (shiftparams.PTEX_fUspeed != 0.0) then ( if (shiftparams.PTEX_fUspeed >. 0.0) then ( if ((uprev <=. uorigin) && (ucurrent >=. uorigin)) then ( // EVENT! SendPluginEvent inst "Loop U" nil nil; 0; ) else nil; 0; ) else if ((ucurrent <=. uorigin) && (uprev >=. uorigin)) then ( // EVENT! SendPluginEvent inst "Loop U" nil nil; 0; ) else nil; ) else nil; if (shiftparams.PTEX_fVspeed != 0.0) then ( if (shiftparams.PTEX_fVspeed >. 0.0) then ( if ((vprev <=. vorigin) && (vcurrent >=. vorigin)) then ( // EVENT! SendPluginEvent inst "Loop V" nil nil; 0; ) else nil; 0; ) else if ((vcurrent <=. vorigin) && (vprev >=. vorigin)) then ( // EVENT! SendPluginEvent inst "Loop V" nil nil; 0; ) else nil; ) else nil; set shiftparams.PTEX_tCurrent = [ucurrent vcurrent]; ); 0;; fun cbEnableShifting(inst, from, action, param, reply, shiftparams)= set shiftparams.PTEX_bState = 1; SO3MaterialSetTextureScrollAnimation shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit shiftparams.PTEX_fUspeed shiftparams.PTEX_fVspeed; setPluginInstanceCbPostRender inst mkfun3 @cbGetCurrentUvPos shiftparams; 0;; fun cbDisableShifting(inst, from, action, param, reply, shiftparams)= set shiftparams.PTEX_bState = 0; setPluginInstanceCbPostRender inst nil; SO3MaterialSetTextureScrollAnimation shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit 0.0 0.0; 0;; fun cbResetUvPosition(inst, from, action, param, reply, shiftparams)= let shiftparams.PTEX_tOrigin -> [uorigin vorigin] in ( SO3MaterialSetTextureUScroll shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit uorigin; SO3MaterialSetTextureVScroll shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit vorigin; ); 0;; fun cbSetUvPosition(inst, from, action, param, reply, shiftparams)= let hd strextr param -> lp in let atof hd lp -> u in let atof hd tl lp -> v in let shiftparams.PTEX_tOrigin -> [uorigin vorigin] in ( SO3MaterialSetTextureUScroll shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit u; SO3MaterialSetTextureVScroll shiftparams.PTEX_material shiftparams.PTEX_iTechnique shiftparams.PTEX_iPass shiftparams.PTEX_iTextureUnit v; ); 0;; fun cbSetUvSpeed(inst, from, action, param, reply, shiftparams)= let hd strextr param -> lp in let atof hd lp -> u in let atof hd tl lp -> v in let shiftparams.PTEX_tOrigin -> [uorigin vorigin] in ( set shiftparams.PTEX_fUspeed = u; set shiftparams.PTEX_fVspeed = v; if (!shiftparams.PTEX_bState) then nil else cbEnableShifting inst nil nil nil nil shiftparams; ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objname in let (getPluginInstanceParam inst "material") -> matname in let atoi (getPluginInstanceParam inst "technique") -> technique in let if technique == nil then 0 else technique -> technique in let atoi (getPluginInstanceParam inst "pass") -> pass in let if pass == nil then 0 else pass -> pass in let atoi (getPluginInstanceParam inst "texture") -> textureunit in let if textureunit == nil then 0 else textureunit -> textureunit in let atof (getPluginInstanceParam inst "uspeed") -> uspeed in let if uspeed == nil then 0.0 else uspeed -> uspeed in let atof (getPluginInstanceParam inst "vspeed") -> vspeed in let if vspeed == nil then 0.0 else vspeed -> vspeed in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 0 else init -> init in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> material in let SO3MaterialGetTextureUScroll material technique pass textureunit -> uorigin in let SO3MaterialGetTextureVScroll material technique pass textureunit -> vorigin in let mkPlugTextureShift [obj material technique pass textureunit uspeed vspeed [uorigin vorigin] [uorigin vorigin] 0] -> shiftparams in ( PluginRegisterAction inst "Enable" mkfun6 @cbEnableShifting shiftparams; PluginRegisterAction inst "Disable" mkfun6 @cbDisableShifting shiftparams; PluginRegisterAction inst "Reset UV position" mkfun6 @cbResetUvPosition shiftparams; PluginRegisterAction inst "Set UV position" mkfun6 @cbSetUvPosition shiftparams; PluginRegisterAction inst "Set UV speed" mkfun6 @cbSetUvSpeed shiftparams; if (!init) then nil else cbEnableShifting inst nil nil nil nil shiftparams; setPluginInstanceCbDel inst mkfun2 @deleteOb shiftparams; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;