/* ----------------------------------------------------------------------------- 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 PlugMatList = [ PMATL_instance : PInstance, PMATL_object : SO3_OBJECT, PMATL_idx : I, PMATL_lMaterials : [SO3_MATERIAL r1], PMATL_iCurMat : I, PMATL_lOldMat : [SO3_MATERIAL r1], PMATL_bWhole : I, PMATL_bLoop : I, PMATL_dlgstr : VUIDlg, PMATL_sTitle : S, PMATL_sOkButton : S, PMATL_sCancelButton : S ]mkPlugMatList;; fun applyOldMaterials(obstr)= if (obstr.PMATL_bWhole) then ( let sizelist obstr.PMATL_lOldMat -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.PMATL_lOldMat i -> oldmat in SO3EntitySetMaterial obstr.PMATL_object oldmat i; set i = i + 1; ); ) else ( let nth_list obstr.PMATL_lOldMat obstr.PMATL_idx -> oldmat in SO3EntitySetMaterial obstr.PMATL_object oldmat obstr.PMATL_idx; ); set obstr.PMATL_iCurMat = -1; 0;; fun deleteOb(inst, obstr)= applyOldMaterials obstr; VUIdestroyDialogBox obstr.PMATL_dlgstr; 0;; fun cbRevert(inst, from, action, param, reply, obstr)= applyOldMaterials obstr; SendPluginEvent inst "Reverted" param nil; 0;; fun applyListMaterial(obstr, matidx)= let nth_list obstr.PMATL_lMaterials matidx -> mat in if (obstr.PMATL_bWhole) then ( let sizelist obstr.PMATL_lOldMat -> size in let 0 -> i in while (i < size) do ( SO3EntitySetMaterial obstr.PMATL_object mat i; set i = i + 1; ); ) else SO3EntitySetMaterial obstr.PMATL_object mat obstr.PMATL_idx; set obstr.PMATL_iCurMat = matidx; 0;; fun cbClickDlg(dlgstr, state, p)= let p -> [obstr iprevmat] in ( if (state == 1) then SendPluginEvent obstr.PMATL_instance "Changed" nil nil else ( if (iprevmat < 0) then applyOldMaterials obstr else applyListMaterial obstr iprevmat; ); set obstr.PMATL_dlgstr = nil; SendPluginEvent obstr.PMATL_instance "Interface closed" nil nil; ); 0;; fun cbInterfaceMatSelect(listelem, obstr)= let sizelist obstr.PMATL_lMaterials -> size in let 0 -> i in while i < size do ( let nth_list obstr.PMATL_lMaterials i -> mat in if (strcmp listelem.VUILE_sValue (SO3MaterialGetName mat)) != 0 then nil else applyListMaterial obstr i; set i = i + 1; ); 0;; fun getAlign(param)= let [1 1] -> align in let [0.0 0.0] -> pos in let strextr param -> lp in let hd lp -> lp in let 0 -> nb in ( while ((lp != nil) && (nb < 2)) do ( let hd lp -> flag in if (!strcmpi flag "top") then ( mutate align <- [_ 0]; mutate pos <- [_ 10.0]; ) else if (!strcmpi flag "bottom") then ( mutate align <- [_ 2]; mutate pos <- [_ 10.0]; ) else if (!strcmpi flag "left") then ( mutate align <- [0 _]; mutate pos <- [10.0 _]; ) else if (!strcmpi flag "right") then ( mutate align <- [2 _]; mutate pos <- [10.0 _]; ) else nil; set lp = tl lp; set nb = nb + 1; ); [pos align]; );; fun cbSelectionInterface(inst, from, action, param, reply, obstr)= if obstr.PMATL_dlgstr != nil then nil else let V3DgetSessionView c3dXsession -> viewstr in let if ((strcmp obstr.PMATL_sTitle "") == 0) then (loc "OS3DMATLIST_C0001") else obstr.PMATL_sTitle -> title in let if ((strcmp obstr.PMATL_sOkButton "") == 0) then (loc "OS3DMATLIST_C0002") else obstr.PMATL_sOkButton -> okbutton in let if ((strcmp obstr.PMATL_sCancelButton "") == 0) then (loc "OS3DMATLIST_C0003") else obstr.PMATL_sCancelButton -> cancelbutton in let VUIcreateDialogExt viewstr inst.INST_groupstr.GRP_project.PRJ_vuiGroup [350 150] title okbutton cancelbutton 95 (V3DgetVrMode viewstr) (mkfun3 @cbClickDlg [obstr obstr.PMATL_iCurMat]) "dialogBox" -> dlgstr in let VUIgetDialogFrame dlgstr -> framestr in let VUIgetElementContainer framestr -> contstr in let VUIcreateList contstr framestr [0.0 0.0] [100.0 100.0] [0 1 1 1 0 0 0 0] [1 0] [5 5] 0 [15 5] -> liststr in ( let sizelist obstr.PMATL_lMaterials -> size in let 0 -> i in while i < size do ( let nth_list obstr.PMATL_lMaterials i -> mat in let VUIaddListElement liststr nil SO3MaterialGetName mat nil 1 -> listelem in VUIsetListElementCbSelect listelem mkfun2 @cbInterfaceMatSelect obstr; set i = i + 1; ); if (!strcmp "" (strtrim param)) || param == nil then nil else let getAlign param -> [pos align] in VUIsetContainerPos contstr pos align nil; set obstr.PMATL_dlgstr = dlgstr; VUIshowDialog dlgstr 1; ); SendPluginEvent inst "Interface opened" nil nil; 0;; fun cbNext(inst, from, action, param, reply, obstr)= if obstr.PMATL_iCurMat + 1 == (sizelist obstr.PMATL_lMaterials) then ( if !obstr.PMATL_bLoop then nil else ( set obstr.PMATL_iCurMat = 0; applyListMaterial obstr obstr.PMATL_iCurMat; SendPluginEvent inst "Changed" param nil; ); ) else ( set obstr.PMATL_iCurMat = obstr.PMATL_iCurMat + 1; applyListMaterial obstr obstr.PMATL_iCurMat; SendPluginEvent inst "Changed" param nil; ); 0;; fun cbPrevious(inst, from, action, param, reply, obstr)= if obstr.PMATL_iCurMat == 0 then ( if !obstr.PMATL_bLoop then nil else ( set obstr.PMATL_iCurMat = (sizelist obstr.PMATL_lMaterials) - 1; applyListMaterial obstr obstr.PMATL_iCurMat; SendPluginEvent inst "Changed" param nil; ); ) else ( set obstr.PMATL_iCurMat = obstr.PMATL_iCurMat - 1; applyListMaterial obstr obstr.PMATL_iCurMat; SendPluginEvent inst "Changed" param nil; ); 0;; fun cbChange(inst, from, action, param, reply, obstr)= let atoi param -> matidx in if param == nil || matidx < 0 || matidx >= (sizelist obstr.PMATL_lMaterials) then nil else ( applyListMaterial obstr matidx; SendPluginEvent inst "Changed" param nil; ); 0;; fun cbSetObject(inst, from, action, param, reply, obstr)= if param == nil then nil else ( let V3DgetObjectByName c3dXsession param -> object in ( set obstr.PMATL_object = object; set obstr.PMATL_lOldMat = SO3EntityMaterialList object; ); ); 0;; fun loadMaterialsList(inst, obj)= let (SO3EntityGetResourceGroup obj) -> grpname in let 0 -> i in let nil -> matlist in let getPluginInstanceParam inst (strcat "material_" (itoa i)) -> matname in ( while (matname != nil) do ( set i = i + 1; let SO3SceneGetMaterial (V3DgetSession c3dXsession) grpname matname -> mat in set matlist = mat::matlist; set matname = getPluginInstanceParam inst (strcat "material_" (itoa i)); ); revertlist matlist; );; fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objname in let atoi (getPluginInstanceParam inst "idx") -> idx in let if idx == nil then 0 else idx -> idx in let atoi (getPluginInstanceParam inst "whole") -> whole in let if whole == nil then 0 else whole -> whole in let getPluginInstanceParam inst "title" -> title in let if title == nil then "" else title -> title in let getPluginInstanceParam inst "okbutton" -> okbutton in let if okbutton == nil then "" else okbutton -> okbutton in let getPluginInstanceParam inst "cancelbutton" -> cancelbutton in let if cancelbutton == nil then "" else cancelbutton -> cancelbutton in let atoi (getPluginInstanceParam inst "loop") -> loop in let if loop == nil then 1 else loop -> loop 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 loadMaterialsList inst obj -> lmat in let SO3EntityMaterialList obj -> lomat in let mkPlugMatList [inst obj idx lmat (-1) lomat whole loop nil title okbutton cancelbutton] -> obstr in ( if !init then nil else cbChange inst nil nil "0" nil obstr; PluginRegisterAction inst "Open selection interface" mkfun6 @cbSelectionInterface obstr; PluginRegisterAction inst "Next" mkfun6 @cbNext obstr; PluginRegisterAction inst "Previous" mkfun6 @cbPrevious obstr; PluginRegisterAction inst "Change by Index" mkfun6 @cbChange obstr; PluginRegisterAction inst "Revert" mkfun6 @cbRevert obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= VUIsetEnable c3dXsession 1; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;