/* ----------------------------------------------------------------------------- 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 SlicePlaneStr = [ PSP_father : SO3_OBJECT, PSP_gizmo : SO3_OBJECT, PSP_gizmoMaterial : SO3_MATERIAL, PSP_initPos : [[F F F] [F F F F]], PSP_bInvert : I, PSP_bShowGizmo : I, PSP_bState : I ]mkSlicePlaneStr;; fun deleteOb(inst, obstr)= SO3EnableSlicePlane 0; setPluginInstanceCbScenePreRender2 inst nil; let obstr.PSP_initPos -> [pos quat] in ( SO3ObjectSetPosition obstr.PSP_father pos; SO3ObjectSetOrientation obstr.PSP_father quat; ); SO3ObjectDestroy obstr.PSP_gizmo; SO3MaterialDestroy obstr.PSP_gizmoMaterial; SO3GroupDelete (V3DgetSession c3dXsession) getPluginInstanceName inst; 0;; fun getPlaneDir(obstr)= let SO3ObjectGetGlobalPosition obstr.PSP_father -> vec in let SO3ObjectGetGlobalOrientation obstr.PSP_father -> quat in let normalizeVectorF (SO3MathsQuatGetDirection quat [0.0 0.0 (if (obstr.PSP_bInvert) then (-.1.0) else 1.0)]) -> dir in let dotVectorF vec dir -> lenght in ( //update the gizmo size here so we don't have to call global position twice on the plane let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportCamera viewportstr -> cam in let if (!V3DgetOrthographicMode cam) then let SO3ObjectGetGlobalPosition cam -> campos in getVectorDistanceF vec campos else V3DgetOrthographicScale cam -> cscale in SO3ObjectSetScale obstr.PSP_gizmo [cscale cscale cscale]; [dir (-.lenght)]; );; fun cbGetPreRender(inst, sessionstr, etime, obstr)= if (obstr.PSP_father == nil) then nil else ( let getPlaneDir obstr -> [dir dist] in SO3SetSlicePlane dir dist; ); 0;; fun cbEnable(inst, from, action, param, rep, obstr)= setPluginInstanceCbScenePreRender2 inst mkfun4 @cbGetPreRender obstr; if (obstr.PSP_father == nil) then nil else ( if (!obstr.PSP_bShowGizmo) then nil else SO3ObjectSetVisible obstr.PSP_gizmo 1 0; let getPlaneDir obstr -> [dir dist] in SO3SetSlicePlane dir dist; ); SO3EnableSlicePlane 1; set obstr.PSP_bState = 1; 0;; fun cbDisable(inst, from, action, param, rep, obstr)= setPluginInstanceCbScenePreRender2 inst nil; SO3ObjectSetVisible obstr.PSP_gizmo 0 0; SO3EnableSlicePlane 0; set obstr.PSP_bState = 0; 0;; fun cbShowPlane(inst, from, action, param, rep, obstr)= if (!obstr.PSP_bState) then nil else SO3ObjectSetVisible obstr.PSP_gizmo 1 0; set obstr.PSP_bShowGizmo = 1; 0;; fun cbHidePlane(inst, from, action, param, rep, obstr)= SO3ObjectSetVisible obstr.PSP_gizmo 0 0; set obstr.PSP_bShowGizmo = 0; 0;; fun cbInvert(inst, from, action, param, rep, obstr)= set obstr.PSP_bInvert = !obstr.PSP_bInvert; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objname in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in let atoi (getPluginInstanceParam inst "show") -> show in let if show == nil then 0 else show -> show in let V3DgetObjectByName c3dXsession objname -> obj in let SO3ObjectGetPosition obj -> cpos in let SO3ObjectGetOrientation obj -> cquat in let mkSlicePlaneStr [obj nil nil [cpos cquat] 0 show init] -> obstr in let getPluginInstanceName inst -> iname in ( SO3GroupCreate (V3DgetSession c3dXsession) iname; if (obj == nil) then nil else ( let SO3MaterialCreate (V3DgetSession c3dXsession) (strcat iname ".material") iname -> mat in let SO3PlaneCreate (V3DgetSession c3dXsession) iname (strcat iname ".gizmo") [1.0 1.0] nil nil -> plane in ( set obstr.PSP_gizmo = plane; set obstr.PSP_gizmoMaterial = mat; SO3ObjectSetCastShadows plane 0; //SO3MaterialIsLighting mat 0; SO3MaterialSetReceiveShadows mat 0; SO3MaterialSetIgnoreSlicePlane mat 1; SO3EntitySetMaterial plane mat 0; SO3MaterialSetPassDepthWriteEnabled mat 0 0 0; SO3MaterialSetPassCullingEnable mat 0 0 0; //SO3MaterialSetPassSceneBlending mat 0 0 SO3_SCENE_BLEND_FACTOR_ONE SO3_SCENE_BLEND_FACTOR_ONE nil nil; SO3MaterialSetPassSceneBlending mat 0 0 SO3_SCENE_BLEND_FACTOR_SOURCE_ALPHA SO3_SCENE_BLEND_FACTOR_ONE_MINUS_SOURCE_ALPHA nil nil; SO3MaterialSetAmbient mat (make_rgba 255 0 0 15); SO3MaterialSetDiffuse mat (make_rgba 255 0 0 15); SO3MaterialSetSpecular mat (make_rgba 255 0 0 15); SO3MaterialSetShininess mat 0.0; SO3ObjectSetMouseClick plane 0; SO3ObjectLink plane obj; SO3ObjectSetPosition plane [0.0 0.0 0.0]; SO3ObjectSetVisible plane 0 0; //turn 90° on X SO3ObjectSetOrientation plane SO3MathsEulerXYZToQuat [(SO3MathsDegreeToRadian (-.180.0)) (SO3MathsDegreeToRadian 90.0) 0.0]; ); ); SO3EnableSlicePlane init; if (!init || (obj == nil)) then nil else cbEnable inst nil nil nil nil obstr; PluginRegisterAction inst "Enable" mkfun6 @cbEnable obstr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable obstr; PluginRegisterAction inst "Show plane" mkfun6 @cbShowPlane obstr; PluginRegisterAction inst "Hide plane" mkfun6 @cbHidePlane obstr; PluginRegisterAction inst "Invert" mkfun6 @cbInvert obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;