/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ var sTmpDownloadPath = "tmp/changetexture/";; var iTexWidth = 4096;; var iTexHeight = 4096;; struct PlugChangeTexture = [ CHTX_instance : PInstance, CHTX_Material : SO3_MATERIAL, CHTX_iTechnique : I, CHTX_iPass : I, CHTX_iTexture : I, CHTX_Tex : SO3_TEXTURE, CHTX_OldTex : SO3_TEXTURE, CHTX_bUrl : I, CHTX_sPath : S ]mkPlugChangeTexture;; fun deleteOb(inst, constr)= SO3MaterialSetTexture constr.CHTX_Material constr.CHTX_OldTex constr.CHTX_iTechnique constr.CHTX_iPass constr.CHTX_iTexture; SO3TextureDestroy constr.CHTX_Tex; 0;; fun cbRevert(inst, from, action, param, reply, constr)= if (constr.CHTX_Tex == nil) then nil else SO3TextureDestroy constr.CHTX_Tex; set constr.CHTX_Tex = nil; SO3MaterialSetTexture constr.CHTX_Material constr.CHTX_OldTex constr.CHTX_iTechnique constr.CHTX_iPass constr.CHTX_iTexture; 0;; fun cbDownloaded(file, data, constr)= if data == nil then nil else let strcatn sTmpDownloadPath::(getPluginInstanceName constr.CHTX_instance)::".tmp"::nil -> tmpfile in ( _storepack data tmpfile; let G2DloadAlphaBmp _channel tmpfile -> bmp in if bmp == nil then nil else let _GETalphaBitmapSize bmp -> [bw bh] in let if ((bw > iTexWidth) || (bh > iTexHeight)) then G2DstrechAlphaBitmap _channel bmp iTexWidth iTexHeight 0 0xffffff else bmp -> bmp in let _GETalphaBitmapSize bmp -> [nw nh] in ( SO3MaterialSetTexture constr.CHTX_Material constr.CHTX_OldTex constr.CHTX_iTechnique constr.CHTX_iPass constr.CHTX_iTexture; if (constr.CHTX_Tex == nil) then nil else SO3TextureDestroy constr.CHTX_Tex; set constr.CHTX_Tex = SO3TextureCreate (V3DgetSession c3dXsession) strcat (getPluginInstanceName constr.CHTX_instance) ".chgTexture" nil (getPluginInstanceGroupName constr.CHTX_instance) nw nh; SO3TextureBlitAlpha constr.CHTX_Tex bmp; _DSalphaBitmap bmp; SO3MaterialSetTexture constr.CHTX_Material constr.CHTX_Tex constr.CHTX_iTechnique constr.CHTX_iPass constr.CHTX_iTexture; ); ); 0;; fun cbChange(inst, from, action, param, reply, constr)= let if ((param == nil) || (!strcmp (strtrim param) "")) then constr.CHTX_bUrl else strIsUrl (strtrim param) -> isurl in let if ((param == nil) || (!strcmp (strtrim param) "")) then constr.CHTX_sPath else strtrim param -> url in if !isurl then ( if ((_checkpack url) == nil) then nil else ( //restore previous texture SO3MaterialSetTexture constr.CHTX_Material constr.CHTX_OldTex constr.CHTX_iTechnique constr.CHTX_iPass constr.CHTX_iTexture; if (constr.CHTX_Tex == nil) then nil else SO3TextureDestroy constr.CHTX_Tex; set constr.CHTX_Tex = SO3TextureCreate (V3DgetSession c3dXsession) strcat (getPluginInstanceName inst) ".chgTexture" (_checkpack url) (getPluginInstanceGroupName inst) nil nil; SO3MaterialSetTexture constr.CHTX_Material constr.CHTX_Tex constr.CHTX_iTechnique constr.CHTX_iPass constr.CHTX_iTexture; ); 0; ) else ( downloadFile url mkfun3 @cbDownloaded constr; 0; ); 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") -> texture in let if texture == nil then 0 else texture -> texture in let (getPluginInstanceParam inst "path") -> path in let (getPluginInstanceParam inst "url") -> url in let atoi (getPluginInstanceParam inst "isurl") -> isurl in let atoi (getPluginInstanceParam inst "init") -> oninit in let if !isurl then path else url -> file in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in let SO3MaterialGetTexture mat technique pass texture -> otex in let mkPlugChangeTexture [inst mat technique pass texture nil otex isurl file] -> constr in ( if !oninit then nil else ( cbChange inst nil nil nil nil constr; ); PluginRegisterAction inst "Change" mkfun6 @cbChange constr; PluginRegisterAction inst "Revert" mkfun6 @cbRevert constr; setPluginInstanceCbDel inst mkfun2 @deleteOb constr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;