/* ----------------------------------------------------------------------------- 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 PlugMatColor = [ PMAT_shell : SO3_OBJECT, PMAT_material : SO3_MATERIAL, PMAT_iTechnique : I, PMAT_iPass : I, PMAT_defColors : [[I [[I [[I I I I] [I I I I I]]] r1]] r1], PMAT_newColors : [I I I I], PMAT_bAllMat : I ]mkPlugMatColor;; fun deleteOb(inst, strmat)= if (!strmat.PMAT_bAllMat) then ( let switch (switch strmat.PMAT_defColors strmat.PMAT_iTechnique) strmat.PMAT_iPass -> [[ambient diffuse specular selfillumination] [csrc cdst asrc adst dw]] in ( SO3MaterialSetAmbientByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass ambient; SO3MaterialSetDiffuseByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass diffuse; SO3MaterialSetSpecularByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass specular; SO3MaterialSetSelfIlluminationByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass selfillumination; SO3MaterialSetPassDepthWriteEnabled strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass dw; SO3MaterialSetPassSceneBlending strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass csrc cdst asrc adst; ); ) else ( let 0 -> itec in while (itec < (sizelist strmat.PMAT_defColors)) do ( let switch strmat.PMAT_defColors itec -> lpass in let 0 -> ipass in while (ipass < (sizelist lpass)) do ( let switch lpass ipass -> [[ambient diffuse specular selfillumination] [csrc cdst asrc adst dw]] in ( SO3MaterialSetAmbientByTechAndPass strmat.PMAT_material itec ipass ambient; SO3MaterialSetDiffuseByTechAndPass strmat.PMAT_material itec ipass diffuse; SO3MaterialSetSpecularByTechAndPass strmat.PMAT_material itec ipass specular; SO3MaterialSetSelfIlluminationByTechAndPass strmat.PMAT_material itec ipass selfillumination; SO3MaterialSetPassDepthWriteEnabled strmat.PMAT_material itec ipass dw; SO3MaterialSetPassSceneBlending strmat.PMAT_material itec ipass csrc cdst asrc adst; ); set ipass = ipass + 1; ); set itec = itec + 1; ); ); 0;; fun cbEnableColors(inst, from, action, param, reply, strmat)= let strmat.PMAT_newColors -> [ambient diffuse specular selfillumination] in ( let get_rgba ambient -> [_ _ _ am] in let get_rgba diffuse -> [_ _ _ ad] in let if (am < 126) || (ad < 126) then [SO3_SCENE_BLEND_FACTOR_SOURCE_ALPHA SO3_SCENE_BLEND_FACTOR_ONE_MINUS_SOURCE_ALPHA] else [nil nil] -> [cop aop] in let if (am < 126) || (ad < 126) then 0 else 1 -> dw in if (!strmat.PMAT_bAllMat) then ( SO3MaterialSetAmbientByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass ambient; SO3MaterialSetDiffuseByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass diffuse; SO3MaterialSetSpecularByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass specular; SO3MaterialSetSelfIlluminationByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass selfillumination; SO3MaterialSetPassDepthWriteEnabled strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass dw; SO3MaterialSetPassSceneBlending strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass cop aop nil nil; ) else ( SO3MaterialSetAmbient strmat.PMAT_material ambient; SO3MaterialSetDiffuse strmat.PMAT_material diffuse; SO3MaterialSetSpecular strmat.PMAT_material specular; SO3MaterialSetSelfIllumination strmat.PMAT_material selfillumination; let 0 -> itec in while (itec < (sizelist strmat.PMAT_defColors)) do ( let switch strmat.PMAT_defColors itec -> lpass in let 0 -> ipass in while (ipass < (sizelist lpass)) do ( SO3MaterialSetPassDepthWriteEnabled strmat.PMAT_material itec ipass dw; SO3MaterialSetPassSceneBlending strmat.PMAT_material itec ipass cop aop nil nil; set ipass = ipass + 1; ); set itec = itec + 1; ); ); ); 0;; fun cbDisableColors(inst, from, action, param, reply, strmat)= if (!strmat.PMAT_bAllMat) then ( let switch (switch strmat.PMAT_defColors strmat.PMAT_iTechnique) strmat.PMAT_iPass -> [[ambient diffuse specular selfillumination] [csrc cdst asrc adst dw]] in ( SO3MaterialSetAmbientByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass ambient; SO3MaterialSetDiffuseByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass diffuse; SO3MaterialSetSpecularByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass specular; SO3MaterialSetSelfIlluminationByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass selfillumination; SO3MaterialSetPassDepthWriteEnabled strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass dw; SO3MaterialSetPassSceneBlending strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass csrc cdst asrc adst; ); ) else ( let 0 -> itec in while (itec < (sizelist strmat.PMAT_defColors)) do ( let switch strmat.PMAT_defColors itec -> lpass in let 0 -> ipass in while (ipass < (sizelist lpass)) do ( let switch lpass ipass -> [[ambient diffuse specular selfillumination] [csrc cdst asrc adst dw]] in ( SO3MaterialSetAmbientByTechAndPass strmat.PMAT_material itec ipass ambient; SO3MaterialSetDiffuseByTechAndPass strmat.PMAT_material itec ipass diffuse; SO3MaterialSetSpecularByTechAndPass strmat.PMAT_material itec ipass specular; SO3MaterialSetSelfIlluminationByTechAndPass strmat.PMAT_material itec ipass selfillumination; SO3MaterialSetPassDepthWriteEnabled strmat.PMAT_material itec ipass dw; SO3MaterialSetPassSceneBlending strmat.PMAT_material itec ipass csrc cdst asrc adst; ); set ipass = ipass + 1; ); set itec = itec + 1; ); ); 0;; fun cbChangeAmbient(inst, from, action, param, reply, strmat)= let htoi param -> ambient in ( if (!strmat.PMAT_bAllMat) then SO3MaterialSetAmbientByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass ambient else SO3MaterialSetAmbient strmat.PMAT_material ambient; mutate strmat.PMAT_newColors <- [ambient _ _ _]; ); 0;; fun cbChangeDiffuse(inst, from, action, param, reply, strmat)= let htoi param -> diffuse in ( if (!strmat.PMAT_bAllMat) then SO3MaterialSetDiffuseByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass diffuse else SO3MaterialSetDiffuse strmat.PMAT_material diffuse; mutate strmat.PMAT_newColors <- [_ diffuse _ _]; ); 0;; fun cbChangeSpecular(inst, from, action, param, reply, strmat)= let htoi param -> specular in ( if (!strmat.PMAT_bAllMat) then SO3MaterialSetSpecularByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass specular else SO3MaterialSetSpecular strmat.PMAT_material specular; mutate strmat.PMAT_newColors <- [_ _ specular _]; ); 0;; fun cbChangeSelfIllumination(inst, from, action, param, reply, strmat)= let htoi param -> selfillumination in ( if (!strmat.PMAT_bAllMat) then SO3MaterialSetSelfIlluminationByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass selfillumination else SO3MaterialSetSelfIllumination strmat.PMAT_material selfillumination; mutate strmat.PMAT_newColors <- [_ _ _ selfillumination]; ); 0;; fun cbChangeAmbientRGB(inst, from, action, param, reply, strmat)= let hd strextr param -> lp in let atoi hd lp -> pr in let atoi hd tl lp -> pg in let atoi hd tl tl lp -> pb in let atoi hd tl tl tl lp -> pa in let make_rgba (if pr == nil then 0 else pr) (if pg == nil then 0 else pg) (if pb == nil then 0 else pb) (if pa == nil then 127 else (pa / 2)) -> ambient in ( if (!strmat.PMAT_bAllMat) then SO3MaterialSetAmbientByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass ambient else SO3MaterialSetAmbient strmat.PMAT_material ambient; mutate strmat.PMAT_newColors <- [ambient _ _ _]; ); 0;; fun cbChangeDiffuseRGB(inst, from, action, param, reply, strmat)= let hd strextr param -> lp in let atoi hd lp -> pr in let atoi hd tl lp -> pg in let atoi hd tl tl lp -> pb in let atoi hd tl tl tl lp -> pa in let make_rgba (if pr == nil then 0 else pr) (if pg == nil then 0 else pg) (if pb == nil then 0 else pb) (if pa == nil then 127 else (pa / 2)) -> diffuse in ( if (!strmat.PMAT_bAllMat) then SO3MaterialSetDiffuseByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass diffuse else SO3MaterialSetDiffuse strmat.PMAT_material diffuse; mutate strmat.PMAT_newColors <- [_ diffuse _ _]; ); 0;; fun cbChangeSpecularRGB(inst, from, action, param, reply, strmat)= let hd strextr param -> lp in let atoi hd lp -> pr in let atoi hd tl lp -> pg in let atoi hd tl tl lp -> pb in let atoi hd tl tl tl lp -> pa in let make_rgba (if pr == nil then 0 else pr) (if pg == nil then 0 else pg) (if pb == nil then 0 else pb) (if pa == nil then 127 else (pa / 2)) -> specular in ( if (!strmat.PMAT_bAllMat) then SO3MaterialSetSpecularByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass specular else SO3MaterialSetSpecular strmat.PMAT_material specular; mutate strmat.PMAT_newColors <- [_ _ specular _]; ); 0;; fun cbChangeSelfIlluminationRGB(inst, from, action, param, reply, strmat)= let hd strextr param -> lp in let atoi hd lp -> pr in let atoi hd tl lp -> pg in let atoi hd tl tl lp -> pb in let atoi hd tl tl tl lp -> pa in let make_rgba (if pr == nil then 0 else pr) (if pg == nil then 0 else pg) (if pb == nil then 0 else pb) (if pa == nil then 127 else (pa / 2)) -> selfillumination in ( if (!strmat.PMAT_bAllMat) then SO3MaterialSetSelfIlluminationByTechAndPass strmat.PMAT_material strmat.PMAT_iTechnique strmat.PMAT_iPass selfillumination else SO3MaterialSetSelfIllumination strmat.PMAT_material selfillumination; mutate strmat.PMAT_newColors <- [_ _ _ selfillumination]; ); 0;; fun cbChangeOpacity(inst, from, action, param, reply, strmat)= let atoi param -> opacity in let strmat.PMAT_material -> mat in let SO3MaterialNumberOfTechniques mat -> sizet in let 0 -> itec in let if opacity < 126 then [SO3_SCENE_BLEND_FACTOR_SOURCE_ALPHA SO3_SCENE_BLEND_FACTOR_ONE_MINUS_SOURCE_ALPHA] else [SO3_SCENE_BLEND_FACTOR_ONE SO3_SCENE_BLEND_FACTOR_ZERO] -> [cop aop] in let if opacity < 126 then 0 else 1 -> dw in if (sizet == nil) then nil else while (itec < sizet) do ( let SO3MaterialNumberOfPassesByTechnique mat itec -> sizep in let 0 -> ipass in while (ipass < sizep) do ( let SO3MaterialGetAmbientByTechAndPass mat itec ipass -> defamb in let SO3MaterialGetDiffuseByTechAndPass mat itec ipass -> defdiff in let SO3MaterialGetSpecularByTechAndPass mat itec ipass -> defspec in let SO3MaterialGetSelfIlluminationByTechAndPass mat itec ipass -> defself in ( SO3MaterialSetPassDepthWriteEnabled mat itec ipass dw; SO3MaterialSetPassSceneBlending mat itec ipass cop aop nil nil; let get_rgba defamb -> [r g b a] in SO3MaterialSetAmbientByTechAndPass mat itec ipass (make_rgba r g b (min opacity 127)); let get_rgba defdiff -> [r g b a] in SO3MaterialSetDiffuseByTechAndPass mat itec ipass (make_rgba r g b (min opacity 127)); let get_rgba defspec -> [r g b a] in SO3MaterialSetSpecularByTechAndPass mat itec ipass (make_rgba r g b (min opacity 127)); let get_rgba defself -> [r g b a] in SO3MaterialSetSelfIlluminationByTechAndPass mat itec ipass (make_rgba r g b (min opacity 127)); ); set ipass = ipass + 1; ); set itec = itec + 1; ); 0;; fun getAllCurrentColors(sessionstr, mat)= let nil -> lcolors in ( let SO3MaterialNumberOfTechniques mat -> sizet in let 0 -> itec in if (sizet == nil) then nil else while (itec < sizet) do ( let nil -> lc0 in ( let SO3MaterialNumberOfPassesByTechnique mat itec -> sizep in let 0 -> ipass in while (ipass < sizep) do ( let SO3MaterialGetAmbientByTechAndPass mat itec ipass -> defamb in let SO3MaterialGetDiffuseByTechAndPass mat itec ipass -> defdiff in let SO3MaterialGetSpecularByTechAndPass mat itec ipass -> defspec in let SO3MaterialGetSelfIlluminationByTechAndPass mat itec ipass -> defself in let SO3MaterialGetPassDepthWriteEnabled mat itec ipass -> dw in let SO3MaterialGetPassSourceBlendFactor mat itec ipass -> csrc in let SO3MaterialGetPassDestBlendFactor mat itec ipass -> cdst in let SO3MaterialGetPassSourceBlendFactorAlpha mat itec ipass -> asrc in let SO3MaterialGetPassDestBlendFactorAlpha mat itec ipass -> adst in set lc0 = [ipass [[defamb defdiff defspec defself] [csrc cdst asrc adst dw]]]::lc0; set ipass = ipass + 1; ); set lcolors = [itec lc0]::lcolors; ); set itec = itec + 1; ); lcolors; );; 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 "allmat") -> allmat in let if allmat == nil then 1 else allmat -> allmat in let atoi (getPluginInstanceParam inst "ambient") -> ambient in let atoi (getPluginInstanceParam inst "diffuse") -> diffuse in let atoi (getPluginInstanceParam inst "specular") -> specular in let atoi (getPluginInstanceParam inst "selfillumination") -> selfillumination 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 getAllCurrentColors c3dXsession material -> lcolors in let mkPlugMatColor [obj material technique pass lcolors [ambient diffuse specular selfillumination] allmat] -> strmat in ( PluginRegisterAction inst "Enable" mkfun6 @cbEnableColors strmat; PluginRegisterAction inst "Disable" mkfun6 @cbDisableColors strmat; PluginRegisterAction inst "Change ambient" mkfun6 @cbChangeAmbient strmat; PluginRegisterAction inst "Change diffuse" mkfun6 @cbChangeDiffuse strmat; PluginRegisterAction inst "Change specular" mkfun6 @cbChangeSpecular strmat; PluginRegisterAction inst "Change self illumination" mkfun6 @cbChangeSelfIllumination strmat; PluginRegisterAction inst "Change opacity" mkfun6 @cbChangeOpacity strmat; PluginRegisterAction inst "Change ambient rgb" mkfun6 @cbChangeAmbientRGB strmat; PluginRegisterAction inst "Change diffuse rgb" mkfun6 @cbChangeDiffuseRGB strmat; PluginRegisterAction inst "Change specular rgb" mkfun6 @cbChangeSpecularRGB strmat; PluginRegisterAction inst "Change self illumination rgb" mkfun6 @cbChangeSelfIlluminationRGB strmat; if (!init) then nil else cbEnableColors inst nil nil nil nil strmat; setPluginInstanceCbDel inst mkfun2 @deleteOb strmat; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;