/* ----------------------------------------------------------------------------- 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 PlugChangeMaterial = [ CHMAT_instance : PInstance, CHMAT_object : SO3_OBJECT, CHMAT_idx : I, CHMAT_Material : SO3_MATERIAL, CHMAT_lOldMat : [SO3_MATERIAL r1], CHMAT_bWholeObj : I ]mkPlugChangeMaterial;; fun applyOldMaterials(constr)= if (constr.CHMAT_bWholeObj) then ( let sizelist constr.CHMAT_lOldMat -> size in let 0 -> i in while (i < size) do ( let nth_list constr.CHMAT_lOldMat i -> oldmat in SO3EntitySetMaterial constr.CHMAT_object oldmat i; set i = i + 1; ); ) else ( let nth_list constr.CHMAT_lOldMat constr.CHMAT_idx -> oldmat in SO3EntitySetMaterial constr.CHMAT_object oldmat constr.CHMAT_idx; ); 0;; fun applyMaterial(constr, mat)= if (constr.CHMAT_bWholeObj) then ( let sizelist constr.CHMAT_lOldMat -> size in let 0 -> i in while (i < size) do ( SO3EntitySetMaterial constr.CHMAT_object mat i; set i = i + 1; ); ) else SO3EntitySetMaterial constr.CHMAT_object mat constr.CHMAT_idx; 0;; fun deleteOb(inst, constr)= applyOldMaterials constr; 0;; fun cbRevert(inst, from, action, param, reply, constr)= applyOldMaterials constr; SendPluginEvent inst "Reverted" param nil; 0;; fun cbChange(inst, from, action, param, reply, constr)= let if param == nil || ((SO3SceneGetMaterial (V3DgetSession c3dXsession) (getPluginInstanceGroupName inst) param) == nil) then constr.CHMAT_Material else (SO3SceneGetMaterial (V3DgetSession c3dXsession) (getPluginInstanceGroupName inst) param) -> mat in applyMaterial constr mat; SendPluginEvent inst "Changed" param nil; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objname in let (getPluginInstanceParam inst "material") -> matname in let atoi (getPluginInstanceParam inst "wholeobj") -> wholeobj in let if (wholeobj == nil) then 0 else wholeobj -> wholeobj in let atoi (getPluginInstanceParam inst "idx") -> idx in let if idx == nil then 0 else idx -> idx in let atoi (getPluginInstanceParam inst "init") -> oninit in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let SO3SceneGetMaterial (V3DgetSession c3dXsession) (getPluginInstanceGroupName inst) matname -> mat in let SO3EntityMaterialList obj -> lomat in let mkPlugChangeMaterial [inst obj idx mat lomat wholeobj] -> 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;;