/* ----------------------------------------------------------------------------- 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 InstProj = [ INSTPROJ_iId : I, INSTPROJ_project : Project ]mkInstProj;; struct PlugInstantiate = [ INSTANTIATE_inst : PInstance, INSTANTIATE_sPath : S, INSTANTIATE_bUseEnv : I, INSTANTIATE_parent : SO3_OBJECT, INSTANTIATE_bSons : I, INSTANTIATE_iIndex : I, INSTANTIATE_lProjects : [InstProj r1], INSTANTIATE_bLoaded : I, INSTANTIATE_bHide : I ]mkPlugInstantiate;; fun deleteOb(inst, instantiatestr)= let (V3DgetSessionView c3dXsession) -> viewstr in while (instantiatestr.INSTANTIATE_lProjects != nil) do ( let hd instantiatestr.INSTANTIATE_lProjects -> instprojstr in deleteProject instprojstr.INSTPROJ_project viewstr; ); set instantiatestr.INSTANTIATE_iIndex = 0; if (!instantiatestr.INSTANTIATE_bUseEnv) then nil else loadEnvironmentPlayer inst.INST_groupstr.GRP_project (V3DgetSessionView c3dXsession) inst.INST_groupstr.GRP_xmlMark; 0;; fun cbSceneLoaded(projstr, instantiatestr, instprojstr)= SendPluginEvent instantiatestr.INSTANTIATE_inst "Instance loaded" (itoa instprojstr.INSTPROJ_iId) nil; 0;; fun cbSceneDestroyed(projstr, instantiatestr, instprojstr)= SendPluginEvent instantiatestr.INSTANTIATE_inst "Instance destroyed" (itoa instprojstr.INSTPROJ_iId) nil; set instantiatestr.INSTANTIATE_lProjects = remove_from_list instantiatestr.INSTANTIATE_lProjects instprojstr; 0;; fun addInstance(inst, from, action, param, rep, instantiatestr)= if (instantiatestr.INSTANTIATE_sPath == nil) then nil else let strextr param -> lp in let if (atof (nth_list (hd lp) 0)) == nil then 0.0 else (atof (nth_list (hd lp) 0)) -> px in let if (atof (nth_list (hd lp) 1)) == nil then 0.0 else (atof (nth_list (hd lp) 1)) -> py in let if (atof (nth_list (hd lp) 2)) == nil then 0.0 else (atof (nth_list (hd lp) 2)) -> pz in let if (atof (nth_list (hd tl lp) 0)) == nil then 0.0 else (atof (nth_list (hd tl lp) 0)) -> ax in let if (atof (nth_list (hd tl lp) 1)) == nil then 0.0 else (atof (nth_list (hd tl lp) 1)) -> ay in let if (atof (nth_list (hd tl lp) 2)) == nil then 0.0 else (atof (nth_list (hd tl lp) 2)) -> az in let if (atof (nth_list (hd tl tl lp) 0)) == nil then 1.0 else (atof (nth_list (hd tl tl lp) 0)) -> sx in let if (atof (nth_list (hd tl tl lp) 1)) == nil then 1.0 else (atof (nth_list (hd tl tl lp) 1)) -> sy in let if (atof (nth_list (hd tl tl lp) 2)) == nil then 1.0 else (atof (nth_list (hd tl tl lp) 2)) -> sz in let SO3MathsEulerXYZToQuat [(SO3MathsDegreeToRadian ax) (SO3MathsDegreeToRadian ay) (SO3MathsDegreeToRadian az)] -> quat in let (V3DgetSessionView c3dXsession) -> viewstr in let crProject instantiatestr.INSTANTIATE_sPath (strcatn (itoa instantiatestr.INSTANTIATE_iIndex)::"."::(getPluginInstanceName inst)::nil) 2 inst.INST_sName -> projstr in let mkInstProj [instantiatestr.INSTANTIATE_iIndex projstr] -> instprojstr in ( set projstr.PRJ_bHideOnClose = instantiatestr.INSTANTIATE_bHide; set instantiatestr.INSTANTIATE_lProjects = instprojstr::instantiatestr.INSTANTIATE_lProjects; set instantiatestr.INSTANTIATE_iIndex = instantiatestr.INSTANTIATE_iIndex + 1; setProjectCbSceneLoaded instprojstr.INSTPROJ_project mkfun2 mkfun3 @cbSceneLoaded instprojstr instantiatestr; setProjectCbSceneDestroyed instprojstr.INSTPROJ_project mkfun2 mkfun3 @cbSceneDestroyed instprojstr instantiatestr; if (!instantiatestr.INSTANTIATE_bHide) then loadProject instprojstr.INSTPROJ_project viewstr instantiatestr.INSTANTIATE_parent [px py pz] quat [sx sy sz] instantiatestr.INSTANTIATE_bUseEnv else preLoadProject instprojstr.INSTPROJ_project viewstr instantiatestr.INSTANTIATE_parent [px py pz] quat [sx sy sz] instantiatestr.INSTANTIATE_bUseEnv; ); 0;; fun removeInstance(inst, from, action, param, rep, instantiatestr)= let (V3DgetSessionView c3dXsession) -> viewstr in let atoi param -> id in if id == nil then nil else ( let 0 -> found in let instantiatestr.INSTANTIATE_lProjects -> l in let sizelist l -> size in let 0 -> i in while ((i < size) && !found) do ( let nth_list l i -> instprojstr in if (id != instprojstr.INSTPROJ_iId) then nil else ( deleteProject instprojstr.INSTPROJ_project viewstr; set found = 1; ); set i = i + 1; ); ); 0;; fun removeAllInstances(inst, from, action, param, rep, instantiatestr)= deleteOb inst instantiatestr; set instantiatestr.INSTANTIATE_bLoaded = 0; SendPluginEvent instantiatestr.INSTANTIATE_inst "Unloaded" nil nil; 0;; fun hideInstance(inst, from, action, param, rep, instantiatestr)= let (V3DgetSessionView c3dXsession) -> viewstr in let atoi param -> id in if id == nil then nil else ( let 0 -> found in let instantiatestr.INSTANTIATE_lProjects -> l in let sizelist l -> size in let 0 -> i in while ((i < size) && !found) do ( let nth_list l i -> instprojstr in if (id != instprojstr.INSTPROJ_iId) then nil else ( hideProject instprojstr.INSTPROJ_project viewstr; SendPluginEvent inst "Hidden" param nil; set found = 1; ); set i = i + 1; ); ); 0;; fun hideAllInstances(inst, from, action, param, rep, instantiatestr)= let (V3DgetSessionView c3dXsession) -> viewstr in let instantiatestr.INSTANTIATE_lProjects -> l in let sizelist l -> size in let 0 -> i in while (i < size) do ( let nth_list l i -> instprojstr in hideProject instprojstr.INSTPROJ_project viewstr; set i = i + 1; ); SendPluginEvent inst "Hidden" nil nil; 0;; fun showInstance(inst, from, action, param, rep, instantiatestr)= let (V3DgetSessionView c3dXsession) -> viewstr in let atoi param -> id in if id == nil then nil else ( let 0 -> found in let instantiatestr.INSTANTIATE_lProjects -> l in let sizelist l -> size in let 0 -> i in while ((i < size) && !found) do ( let nth_list l i -> instprojstr in if (id != instprojstr.INSTPROJ_iId) then nil else ( showProject instprojstr.INSTPROJ_project viewstr; SendPluginEvent inst "Shown" param nil; set found = 1; ); set i = i + 1; ); ); 0;; fun showAllInstances(inst, from, action, param, rep, instantiatestr)= let (V3DgetSessionView c3dXsession) -> viewstr in let instantiatestr.INSTANTIATE_lProjects -> l in let sizelist l -> size in let 0 -> i in while (i < size) do ( let nth_list l i -> instprojstr in showProject instprojstr.INSTPROJ_project viewstr; set i = i + 1; ); SendPluginEvent inst "Shown" nil nil; 0;; fun cbSortNodes(s1, s2)= strcmpi SO3ObjectGetName s1 SO3ObjectGetName s2;; fun loadChildren(parent, instantiatestr)= let (V3DgetSessionView c3dXsession) -> viewstr in let quicksort SO3ObjectGetChildren parent @cbSortNodes -> lchild in while (lchild != nil) do ( let hd lchild -> child in ( loadChildren child instantiatestr; let crProject instantiatestr.INSTANTIATE_sPath (strcatn (itoa instantiatestr.INSTANTIATE_iIndex)::"."::(getPluginInstanceName instantiatestr.INSTANTIATE_inst)::nil) 2 instantiatestr.INSTANTIATE_inst.INST_sName -> projstr in let mkInstProj [instantiatestr.INSTANTIATE_iIndex projstr] -> instprojstr in ( set projstr.PRJ_bHideOnClose = instantiatestr.INSTANTIATE_bHide; set instantiatestr.INSTANTIATE_lProjects = instprojstr::instantiatestr.INSTANTIATE_lProjects; set instantiatestr.INSTANTIATE_iIndex = instantiatestr.INSTANTIATE_iIndex + 1; setProjectCbSceneLoaded instprojstr.INSTPROJ_project mkfun2 mkfun3 @cbSceneLoaded instprojstr instantiatestr; setProjectCbSceneDestroyed instprojstr.INSTPROJ_project mkfun2 mkfun3 @cbSceneDestroyed instprojstr instantiatestr; loadProject instprojstr.INSTPROJ_project viewstr child [0.0 0.0 0.0] [0.0 0.0 0.0 1.0] [1.0 1.0 1.0] instantiatestr.INSTANTIATE_bUseEnv; if (!instantiatestr.INSTANTIATE_bHide) then nil else SO3ObjectSetVisible instprojstr.INSTPROJ_project.PRJ_group.GRP_shell 0 1; ); ); set lchild = tl lchild; ); 0;; fun loadInstance(inst, from, action, param, rep, instantiatestr)= if ((instantiatestr.INSTANTIATE_sPath == nil) || (instantiatestr.INSTANTIATE_bLoaded)) then nil else let (V3DgetSessionView c3dXsession) -> viewstr in ( set instantiatestr.INSTANTIATE_bLoaded = 1; if (instantiatestr.INSTANTIATE_bSons) then ( loadChildren instantiatestr.INSTANTIATE_parent instantiatestr; 0; ) else ( let crProject instantiatestr.INSTANTIATE_sPath (strcatn (itoa instantiatestr.INSTANTIATE_iIndex)::"."::(getPluginInstanceName instantiatestr.INSTANTIATE_inst)::nil) 2 inst.INST_sName -> projstr in let mkInstProj [instantiatestr.INSTANTIATE_iIndex projstr] -> instprojstr in ( set projstr.PRJ_bHideOnClose = instantiatestr.INSTANTIATE_bHide; set instantiatestr.INSTANTIATE_lProjects = instprojstr::instantiatestr.INSTANTIATE_lProjects; set instantiatestr.INSTANTIATE_iIndex = instantiatestr.INSTANTIATE_iIndex + 1; setProjectCbSceneLoaded instprojstr.INSTPROJ_project mkfun2 mkfun3 @cbSceneLoaded instprojstr instantiatestr; setProjectCbSceneDestroyed instprojstr.INSTPROJ_project mkfun2 mkfun3 @cbSceneDestroyed instprojstr instantiatestr; if (!instantiatestr.INSTANTIATE_bHide) then loadProject instprojstr.INSTPROJ_project viewstr instantiatestr.INSTANTIATE_parent [0.0 0.0 0.0] [0.0 0.0 0.0 1.0] [1.0 1.0 1.0] instantiatestr.INSTANTIATE_bUseEnv else preLoadProject instprojstr.INSTPROJ_project viewstr instantiatestr.INSTANTIATE_parent [0.0 0.0 0.0] [0.0 0.0 0.0 1.0] [1.0 1.0 1.0] instantiatestr.INSTANTIATE_bUseEnv; 0; ); ); SendPluginEvent instantiatestr.INSTANTIATE_inst "Loaded" nil nil; ); 0;; fun cbLoaded(inst, instantiatestr)= loadInstance inst nil nil nil nil instantiatestr; 0;; fun setProjectPath(inst, from, action, param, rep, instantiatestr)= set instantiatestr.INSTANTIATE_sPath = param; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "path") -> path in let atoi (getPluginInstanceParam inst "env") -> env in let if env == nil then 0 else env -> env in let (getPluginInstanceParam inst "object") -> objname in let atoi (getPluginInstanceParam inst "sons") -> sons in let if sons == nil then 0 else sons -> sons in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 0 else init -> init in let atoi (getPluginInstanceParam inst "hide") -> hide in let if hide == nil then 0 else hide -> hide in let V3DgetObjectByName c3dXsession objname -> parent in let mkPlugInstantiate [inst path env parent sons 0 nil 0 hide] -> instantiatestr in ( PluginRegisterAction inst "Add instance" mkfun6 @addInstance instantiatestr; PluginRegisterAction inst "Remove instance" mkfun6 @removeInstance instantiatestr; PluginRegisterAction inst "Remove all instances" mkfun6 @removeAllInstances instantiatestr; PluginRegisterAction inst "Hide instance" mkfun6 @hideInstance instantiatestr; PluginRegisterAction inst "Hide all instances" mkfun6 @hideAllInstances instantiatestr; PluginRegisterAction inst "Show instance" mkfun6 @showInstance instantiatestr; PluginRegisterAction inst "Show all instances" mkfun6 @showAllInstances instantiatestr; PluginRegisterAction inst "Load" mkfun6 @loadInstance instantiatestr; PluginRegisterAction inst "Set project path" mkfun6 @setProjectPath instantiatestr; if (!init) then nil else ( if inst.INST_groupstr.GRP_project.PRJ_bPluginsLoaded then ( loadInstance inst nil nil nil nil instantiatestr; 0; ) else ( setPluginInstanceCbAllPluginsLoaded inst mkfun2 @cbLoaded instantiatestr; 0; ); ); setPluginInstanceCbDel inst mkfun2 @deleteOb instantiatestr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;