/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2014 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 ObjEDistStr = [ EDIST_inst : PInstance, EDIST_child : SO3_OBJECT, EDIST_lLines : [SO3_OBJECT r1], EDIST_fDist : F, EDIST_bEdit : I, EDIST_bPLay : I ]mkObjEDistStr;; typeof lDistPreview = [[PInstance ObjEDistStr] r1];; fun destroyHelper(edstr)= setPluginInstanceEditorCbPreRender edstr.EDIST_inst nil; while (edstr.EDIST_lLines != nil) do ( SO3ObjectDestroy hd edstr.EDIST_lLines; set edstr.EDIST_lLines = tl edstr.EDIST_lLines; ); 0;; fun cbDestroyEdit(edstr)= if ((getPluginInstanceShowHelper edstr.EDIST_inst) && (edstr.EDIST_bPLay == 0)) then nil else destroyHelper edstr; set edstr.EDIST_bEdit = 0; 0;; fun cbEditorPreRender(inst, sessionstr, etime, edstr)= if (edstr.EDIST_child == nil) then nil else let SO3ObjectGetGlobalPosition edstr.EDIST_child -> [px py pz] in let SO3ObjectGetGlobalOrientation edstr.EDIST_child -> quat in let nil -> lpoints in let nil -> lpoints2 in ( let edstr.EDIST_fDist -> r in let (2.0 *. PIf) /. 32.0 -> step in let 0.0 -> pv in ( while (pv <=. (2.0 *. PIf)) do ( let [(px +. (r *. cos(pv))) py (pz +. (r *. sin(pv)))] -> ppos in set lpoints = ppos::lpoints; set pv = pv +. step; ); set pv = 0.0; while (pv <=. (2.0 *. PIf)) do ( let [(px +. (r *. cos(pv))) (py +. (r *. sin(pv))) pz] -> ppos in set lpoints = ppos::lpoints; set pv = pv +. step; ); set pv = 0.0; while (pv <=. (2.0 *. PIf)) do ( let [px (py +. (r *. sin(pv))) (pz +. (r *. cos(pv))) ] -> ppos in set lpoints2 = ppos::lpoints2; set pv = pv +. step; ); ); if (edstr.EDIST_lLines == nil) then ( set edstr.EDIST_lLines = lcat edstr.EDIST_lLines (SO3LineEntityCreate (V3DgetSession sessionstr) (strcat (getPluginInstanceName inst) (itoa 1)) lpoints 0xff000000)::nil; set edstr.EDIST_lLines = lcat edstr.EDIST_lLines (SO3LineEntityCreate (V3DgetSession sessionstr) (strcat (getPluginInstanceName inst) (itoa 2)) lpoints2 0xff000000)::nil; 0; ) else ( SO3LineEntitySetPoints hd edstr.EDIST_lLines lpoints; SO3LineEntitySetPoints hd tl edstr.EDIST_lLines lpoints2; 0; ); SO3ObjectSetVisible hd edstr.EDIST_lLines ((SO3ObjectGetVisible edstr.EDIST_child) || edstr.EDIST_bEdit) 1; SO3ObjectSetVisible hd tl edstr.EDIST_lLines ((SO3ObjectGetVisible edstr.EDIST_child) || edstr.EDIST_bEdit) 1; ); 0;; fun changeHelperState(state, edstr)= if (!state) then ( destroyHelper edstr; 0; ) else ( setPluginInstanceEditorCbPreRender edstr.EDIST_inst mkfun4 @cbEditorPreRender edstr; 0; ); 0;; fun cbEditorHelperState(inst, state, edstr)= if (edstr.EDIST_bEdit) then nil else changeHelperState state edstr; 0;; fun cbCloseEdit(p)= let p -> [ctrlobjname1 ctrlobjname2 ctrldist ctrldebounce ctrlinit] in let getEdCtrlTextLineValue ctrlobjname1 -> objname1 in let getEdCtrlTextLineValue ctrlobjname2 -> objname2 in let getEdCtrlFloatValue ctrldist -> dist in let ftoi getEdCtrlFloatValue ctrldebounce -> debounce in let getEdCtrlCheckState ctrlinit -> init in ["object" objname1]:: ["object2" objname2]:: ["distance" ftoa dist]:: ["debounce" itoa debounce]:: ["init" itoa init]:: nil;; fun cbSelectObj(val, type, p)= let p -> [inst winstr edstr viewstr ctrlobjname objname] in let V3DgetDefaultSession viewstr -> sessionstr in let SO3SceneGetObject (V3DgetSession sessionstr) val -> obj in if (obj != nil) || (!strcmpi "Current camera" val) || (!strcmpi "Current camera shell" val) then ( setEdCtrlTextLineValue ctrlobjname val; if (edstr == nil) then nil else ( while (edstr.EDIST_lLines != nil) do ( SO3ObjectDestroy hd edstr.EDIST_lLines; set edstr.EDIST_lLines = tl edstr.EDIST_lLines; ); set edstr.EDIST_child = V3DgetObjectByName sessionstr val; ); mutate p <- [_ _ _ _ _ val]; ) else nil; 0;; fun cbCloseRes(ctrlbtn)= setEdCtrlButtonEnable ctrlbtn 1; 0;; fun cbBtnPickObj(ctrlbtn, p)= let p -> [inst winstr edstr viewstr ctrlobjname objname] in ( setEdCtrlButtonEnable ctrlbtn 0; dlgSelectPluginInstanceResource inst winstr iTypeGroup|iTypeEntity|iTypeNode|iTypeLight|iTypeBone|iTypeCamera|iTypeParticle|iTypeCubeMap objname mkfun3 @cbSelectObj p mkfun1 @cbCloseRes ctrlbtn 0; ); 0;; fun cbRefreshBtn(pickbtn, p)= let p -> [ctrlobjname edstr] in ( setEdCtrlTextLineValue ctrlobjname ""; if (edstr == nil) then nil else ( while (edstr.EDIST_lLines != nil) do ( SO3ObjectDestroy hd edstr.EDIST_lLines; set edstr.EDIST_lLines = tl edstr.EDIST_lLines; ); set edstr.EDIST_child = nil; ); ); 0;; fun cbEditDist(ctrl, value, edstr)= set edstr.EDIST_fDist = value; 0;; fun loadParams(inst)= let (getPluginInstanceParam inst "object") -> objname1 in let (getPluginInstanceParam inst "object2") -> objname2 in //for compatibility let if (atoi (getPluginInstanceParam inst "iscamera")) == 1 then (loc "OS3DDISTANCE_0002") else objname2 -> objname2 in let atof (getPluginInstanceParam inst "distance") -> dist in let if dist == nil then 1.0 else dist -> dist in let atof (getPluginInstanceParam inst "debounce") -> debounce in let if debounce == nil then 0.0 else debounce -> debounce in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in [objname1 objname2 dist debounce init];; fun dynamicedit(winstr, inst, viewstr, applybtn)= let [420 160] -> [iw ih] in ( setEdWindowSize winstr iw ih; let loadParams inst -> [objname1 objname2 dist debounce init] in let switch lDistPreview inst -> edstr in let crEdCtrlLabel winstr 10 12 160 20 (loc "OS3DDISTANCE_0006") nil -> labelobj in let crEdCtrlTextLine winstr 180 10 140 20 objname1 nil EDWIN_RESIZE_MW -> ctrlobjname1 in let crEdCtrlButton winstr 325 10 55 20 "..." nil -> pickbtn1 in let crEdCtrlButton winstr 385 10 35 20 "X" nil -> refreshobjname1 in let crEdCtrlLabel winstr 10 37 160 20 (loc "OS3DDISTANCE_0007") nil -> labelobj in let crEdCtrlTextLine winstr 180 35 140 20 objname2 nil EDWIN_RESIZE_MW -> ctrlobjname2 in let crEdCtrlButton winstr 325 35 55 20 "..." nil -> pickbtn2 in let crEdCtrlButton winstr 385 35 35 20 "X" nil -> refreshobjname2 in let crEdCtrlLabel winstr 10 62 160 20 (loc "OS3DDISTANCE_0004") nil -> labeldist in let crEdCtrlFloat winstr 180 60 110 20 dist 0.0 1000000.0 0.01 5 nil EDWIN_RESIZE_MW -> ctrldist in let crEdCtrlLabel winstr 10 87 160 40 (loc "OS3DDISTANCE_0003") nil -> labeldebounce in let crEdCtrlFloat winstr 180 85 110 20 debounce 0.0 100000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrldebounce in let crEdCtrlCheck winstr 10 125 280 20 (loc "OS3DDISTANCE_0005") EDWIN_RESIZE_MW -> ctrlinit in ( set edstr.EDIST_bEdit = 1; changeHelperState 1 edstr; setEdCtrlButtonCb pickbtn1 mkfun2 @cbBtnPickObj [inst winstr edstr viewstr ctrlobjname1 objname1]; setEdCtrlTextLineEnable ctrlobjname1 0; setEdCtrlButtonCb refreshobjname1 mkfun2 @cbRefreshBtn [ctrlobjname1 edstr]; setEdCtrlButtonCb pickbtn2 mkfun2 @cbBtnPickObj [inst winstr nil viewstr ctrlobjname2 objname2]; setEdCtrlTextLineEnable ctrlobjname2 0; setEdCtrlButtonCb refreshobjname2 mkfun2 @cbRefreshBtn [ctrlobjname2 nil]; setEdCtrlFloatCbChange ctrldist mkfun3 @cbEditDist edstr; setEdCtrlCheckState ctrlinit init; [mkfun1 @cbCloseEdit [ctrlobjname1 ctrlobjname2 ctrldist ctrldebounce ctrlinit] mkfun1 @cbDestroyEdit edstr]; ); );; // stop play mode fun dynamicstop(inst)= let switch lDistPreview inst -> edstr in ( set edstr.EDIST_bPLay = 0; changeHelperState (getPluginInstanceShowHelper inst) edstr; ); 0;; // start play mode fun dynamicstart(inst)= let switch lDistPreview inst -> edstr in ( set edstr.EDIST_bPLay = 1; if (edstr.EDIST_bEdit) then nil else destroyHelper edstr; ); 0;; fun dynamicdelete(inst)= let switch lDistPreview inst -> edstr in ( destroyHelper edstr; set lDistPreview = removeInstFromList lDistPreview inst; ); 0;; fun dynamicinit(inst)= let loadParams inst -> [objname1 objname2 dist debounce init] in let SO3SceneGetObject (V3DgetSession c3dXsession) objname1 -> child in let mkObjEDistStr [inst child nil dist 0 0] -> edstr in ( changeHelperState (getPluginInstanceShowHelper inst) edstr; setPluginInstanceEditorCbHelperState inst mkfun3 @cbEditorHelperState edstr; set lDistPreview = [inst edstr]::lDistPreview; ); 0;;