/* ----------------------------------------------------------------------------- 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 PlugCameraTexture = [ CAMTX_instance : PInstance, CAMTX_Material : SO3_MATERIAL, CAMTX_iTechnique : I, CAMTX_iPass : I, CAMTX_iTexture : I, CAMTX_Rtt : SO3_OBJECT, CAMTX_Camera : SO3_OBJECT, CAMTX_iSize : I, CAMTX_sScheme : S, CAMTX_sCompositor : S ]mkPlugCameraTexture;; fun deleteOb(inst, constr)= SO3ObjectDestroy constr.CAMTX_Rtt; 0;; fun cbEnable(inst, from, action, param, reply, constr)= SO3RenderToTextureSetEnable constr.CAMTX_Rtt 1; 0;; fun cbDisable(inst, from, action, param, reply, constr)= SO3RenderToTextureSetEnable constr.CAMTX_Rtt 0; 0;; fun cbSetMaterialScheme(inst, from, action, param, reply, constr)= set constr.CAMTX_sScheme = param; SO3RenderToTextureSetMaterialScheme constr.CAMTX_Rtt constr.CAMTX_sScheme; 0;; fun cbEnableAuto(inst, from, action, param, reply, constr)= SO3RenderToTextureSetAutoUpdate constr.CAMTX_Rtt 1; 0;; fun cbDisableAuto(inst, from, action, param, reply, constr)= SO3RenderToTextureSetAutoUpdate constr.CAMTX_Rtt 0; 0;; fun cbUpdate(inst, from, action, param, reply, constr)= SO3RenderToTextureUpdate constr.CAMTX_Rtt; 0;; fun setCompositor(constr, compositor)= if (!strcmp compositor "") then nil else ( SO3RenderToTextureAddCompositor constr.CAMTX_Rtt compositor nil; SO3RenderToTextureCompositorSetEnable constr.CAMTX_Rtt compositor 1; ); 0;; fun cbChangeCamera(inst, viewstr, sessionstr, camera, constr)= if (camera != V3DgetDefaultCamera c3dXsession) then nil else ( set constr.CAMTX_Camera = camera; if (constr.CAMTX_Rtt == nil) then nil else let SO3RenderToTextureGetEnable constr.CAMTX_Rtt -> enable in let SO3RenderToTextureGetAutoUpdate constr.CAMTX_Rtt -> auto in ( SO3ObjectDestroy constr.CAMTX_Rtt; set constr.CAMTX_Rtt = SO3RenderToTextureCreate (V3DgetSession c3dXsession) strcat (getPluginInstanceName inst) "_RTT" camera; SO3RenderToTextureSetTextureSize constr.CAMTX_Rtt constr.CAMTX_iSize; SO3RenderToTextureSetAutoUpdate constr.CAMTX_Rtt auto; SO3RenderToTextureSetTargetMaterial constr.CAMTX_Rtt constr.CAMTX_Material constr.CAMTX_iTechnique constr.CAMTX_iPass constr.CAMTX_iTexture; SO3RenderToTextureSetMaterialScheme constr.CAMTX_Rtt constr.CAMTX_sScheme; setCompositor constr constr.CAMTX_sCompositor; SO3RenderToTextureSetEnable constr.CAMTX_Rtt enable; ); ); 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 "camera") -> scamera in let atoi (getPluginInstanceParam inst "autoupdate") -> autoupdate in let if autoupdate == nil then 1 else autoupdate -> autoupdate in let atoi (getPluginInstanceParam inst "size") -> size in let if size == nil then 256 else size -> size in let (getPluginInstanceParam inst "scheme") -> scheme in let if scheme == nil then "Default" else scheme -> scheme in let (getPluginInstanceParam inst "compositor") -> compositor in let if compositor == nil then "" else compositor -> compositor in let atoi (getPluginInstanceParam inst "init") -> oninit in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in let V3DgetObjectByName c3dXsession scamera -> camera in let SO3RenderToTextureCreate (V3DgetSession c3dXsession) strcat (getPluginInstanceName inst) "_RTT" camera -> rtt in let mkPlugCameraTexture [inst mat technique pass texture rtt camera size scheme compositor] -> constr in ( SO3RenderToTextureSetTextureSize constr.CAMTX_Rtt constr.CAMTX_iSize; SO3RenderToTextureSetAutoUpdate constr.CAMTX_Rtt autoupdate; SO3RenderToTextureSetTargetMaterial constr.CAMTX_Rtt constr.CAMTX_Material constr.CAMTX_iTechnique constr.CAMTX_iPass constr.CAMTX_iTexture; SO3RenderToTextureSetMaterialScheme constr.CAMTX_Rtt constr.CAMTX_sScheme; SO3RenderToTextureSetEnable constr.CAMTX_Rtt oninit; setCompositor constr constr.CAMTX_sCompositor; if (strcmpi "Current camera" scamera) then nil else setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera constr; PluginRegisterAction inst "Enable" mkfun6 @cbEnable constr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable constr; PluginRegisterAction inst "Enable auto update" mkfun6 @cbEnableAuto constr; PluginRegisterAction inst "Disable auto update" mkfun6 @cbDisableAuto constr; PluginRegisterAction inst "Update" mkfun6 @cbUpdate constr; PluginRegisterAction inst "Set scheme" mkfun6 @cbSetMaterialScheme constr; setPluginInstanceCbDel inst mkfun2 @deleteOb constr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;