/* ----------------------------------------------------------------------------- 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 ObjLinkStr = [ POBL_father : SO3_OBJECT, POBL_defson : SO3_OBJECT, POBL_lSons : [[SO3_OBJECT [SO3_OBJECT [[F F F] [F F F] [F F F F]]]] r1], POBL_pos : [[F F F] [F F F F]], POBL_iFatherMode : I, POBL_iSonMode : I, POBL_bReset : I, POBL_bState : I ]mkObjLinkStr;; fun deleteOb(inst, oblinkstr)= setPluginInstanceCbCameraChange inst nil; let sizelist oblinkstr.POBL_lSons -> size in let 0 -> i in while i < size do ( let nth_list oblinkstr.POBL_lSons i -> [son [father [pos scale quat]]] in ( SO3ObjectLink son father; SO3ObjectSetPosition son pos; SO3ObjectSetOrientation son quat; SO3ObjectSetScale son scale; ); set i = i + 1; ); 0;; fun cbLinkObject(inst, from, action, param, reply, oblinkstr)= /*if oblinkstr.POBL_iFatherMode == 0 then nil else set oblinkstr.POBL_father = V3DgetCameraByType c3dXsession V3DgetDefaultCamera c3dXsession oblinkstr.POBL_iFatherMode; if oblinkstr.POBL_iSonMode == 0 then nil else set oblinkstr.POBL_defson = V3DgetCameraByType c3dXsession V3DgetDefaultCamera c3dXsession oblinkstr.POBL_iSonMode; */ let V3DgetObjectByName c3dXsession param -> obj in let if obj == nil then oblinkstr.POBL_defson else obj -> obj in if (obj == nil) then nil else ( let switch oblinkstr.POBL_lSons obj -> known in if known != nil then nil else let SO3ObjectGetPosition obj -> cpos in let SO3ObjectGetOrientation obj -> cquat in let SO3ObjectGetScale obj -> cscale in let SO3ObjectGetParent obj -> cfather in set oblinkstr.POBL_lSons = [obj [cfather [cpos cscale cquat]]]::oblinkstr.POBL_lSons; let oblinkstr.POBL_pos -> [pos quat] in let SO3ObjectGetGlobalScale obj -> cgscale in ( SO3ObjectLink obj oblinkstr.POBL_father; SO3ObjectSetPosition obj pos; SO3ObjectSetOrientation obj quat; SO3ObjectSetGlobalScale obj cgscale; ); set oblinkstr.POBL_bState = 1; ); 0;; fun cbUnLinkObject(inst, from, action, param, reply, oblinkstr)= let SO3SceneGetObject (V3DgetSession c3dXsession) param -> obj in let if obj == nil then oblinkstr.POBL_defson else obj -> obj in if (obj == nil) then nil else ( let switch oblinkstr.POBL_lSons obj -> known in if known == nil then nil else let known -> [father [pos scale quat]] in ( let SO3ObjectGetGlobalPosition obj -> gpos in let SO3ObjectGetGlobalOrientation obj -> gquat in ( SO3ObjectLink obj father; if (oblinkstr.POBL_bReset) then ( SO3ObjectSetPosition obj pos; SO3ObjectSetOrientation obj quat; ) else ( SO3ObjectSetGlobalPosition obj gpos; SO3ObjectSetGlobalOrientation obj gquat; ); ); SO3ObjectSetScale obj scale; ); set oblinkstr.POBL_bState = 0; ); 0;; fun cbChangeCamera(inst, viewstr, sessionstr, camera, oblinkstr)= if ((!oblinkstr.POBL_iFatherMode) /*|| (camera != V3DgetDefaultCamera c3dXsession)*/) then nil else ( set oblinkstr.POBL_father = V3DgetCameraByType sessionstr camera oblinkstr.POBL_iFatherMode; if (!oblinkstr.POBL_bState) then nil else ( let oblinkstr.POBL_pos -> [pos quat] in let sizelist oblinkstr.POBL_lSons -> size in let 0 -> i in while i < size do ( let nth_list oblinkstr.POBL_lSons i -> [obj _] in let SO3ObjectGetGlobalScale obj -> cgscale in ( SO3ObjectLink obj oblinkstr.POBL_father; SO3ObjectSetPosition obj pos; SO3ObjectSetOrientation obj quat; SO3ObjectSetGlobalScale obj cgscale; ); set i = i + 1; ); ); ); if !oblinkstr.POBL_iSonMode then nil else ( if (!oblinkstr.POBL_bState) then nil else ( let switch oblinkstr.POBL_lSons oblinkstr.POBL_defson -> known in if known == nil then nil else let known -> [father [pos scale quat]] in ( SO3ObjectLink oblinkstr.POBL_defson father; SO3ObjectSetPosition oblinkstr.POBL_defson pos; SO3ObjectSetOrientation oblinkstr.POBL_defson quat; SO3ObjectSetScale oblinkstr.POBL_defson scale; ); ); set oblinkstr.POBL_defson = V3DgetCameraByType sessionstr camera oblinkstr.POBL_iSonMode; if (!oblinkstr.POBL_bState) then nil else ( let oblinkstr.POBL_pos -> [pos quat] in ( SO3ObjectLink oblinkstr.POBL_defson oblinkstr.POBL_father; SO3ObjectSetPosition oblinkstr.POBL_defson pos; SO3ObjectSetOrientation oblinkstr.POBL_defson quat; ); ); ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objname in // for compatibility let if ((atoi (getPluginInstanceParam inst "iscamera")) == 1) then "Current camera" else objname -> objname in let (getPluginInstanceParam inst "objectson") -> objnameson in let atof (getPluginInstanceParam inst "posx") -> posx in let atof (getPluginInstanceParam inst "posy") -> posy in let atof (getPluginInstanceParam inst "posz") -> posz in let atof (getPluginInstanceParam inst "angx") -> angx in let atof (getPluginInstanceParam inst "angy") -> angy in let atof (getPluginInstanceParam inst "angz") -> angz in let atoi (getPluginInstanceParam inst "reset") -> reset in let if reset == nil then 1 else reset -> reset in let atoi (getPluginInstanceParam inst "init") -> init in let SO3MathsEulerXYZToQuat [(SO3MathsDegreeToRadian angy) (SO3MathsDegreeToRadian angx) (SO3MathsDegreeToRadian angz)] -> quat in let V3DgetObjectByName c3dXsession objname -> father in let V3DgetObjectTypeByName objname -> isourcemode in let V3DgetObjectByName c3dXsession objnameson -> obj in let V3DgetObjectTypeByName objnameson -> idestmode in let mkObjLinkStr [father obj nil [[posx posy posz] quat] isourcemode idestmode reset 0] -> oblinkstr in ( PluginRegisterAction inst "Link" mkfun6 @cbLinkObject oblinkstr; PluginRegisterAction inst "Unlink" mkfun6 @cbUnLinkObject oblinkstr; if !isourcemode && !idestmode then nil else setPluginInstanceCbCameraChange inst mkfun5 @cbChangeCamera oblinkstr; if !init then nil else cbLinkObject inst nil nil nil nil oblinkstr; setPluginInstanceCbDel inst mkfun2 @deleteOb oblinkstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;