/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ var GLBL_xmargin = 5;; var GLBL_ymargin = 3;; struct LabelStr = [ LBL_label : VUIcontainer, LBL_textElement : VUIelement, LBL_parentObject : SO3_OBJECT, LBL_offset : [F F], LBL_fScale : F, LBL_iAlignFlags : I, LBL_iMaxWidth : I, LBL_font : VUIfont, LBL_iFontColor : I, LBL_iBgColor : I, LBL_sText : S, LBL_point : SO3_OBJECT, LBL_pointMat : SO3_MATERIAL, LBL_iPointColor : I, LBL_iClick : I, LBL_fVisibilityDist : F, LBL_bAutoScale : I, LBL_fMaxAutoscaleDist : F, LBL_bShowOnTop : I, LBL_bLabelShowState : I, LBL_bPointShowState : I ]mkLabelStr;; fun deleteOb(inst, obstr)= if (obstr.LBL_label == nil) then nil else VUIdestroyContainer obstr.LBL_label; if (obstr.LBL_point == nil) then nil else ( SO3ObjectDestroy obstr.LBL_point; SO3MaterialDestroy obstr.LBL_pointMat; ); VUIdelFont obstr.LBL_font; SO3GroupDelete (V3DgetSession c3dXsession) getPluginInstanceName inst; 0;; fun updatePoint(obstr, point)= let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ _ vh] in let if (vh <= 0) then 1 else if (viewstr.V3D_bVRmode) then iVUIBASEVRHEIGHT else vh -> vh in let V3DgetViewportCamera viewportstr -> cam in let V3DgetOrthographicMode cam -> ortho in let if ortho then V3DgetOrthographicScale cam else 0.0 -> cscale in let if (viewstr.V3D_bVRmode) then SO3MathsDegreeToRadian iVUIBASEVRFOV else (SO3CameraGetFOVy cam) -> fovy in let if ((fovy <=. 0.0) || ortho) then 1.0 else fovy -> fovy in let SO3ObjectGetGlobalPosition cam -> campos in let SO3ObjectGetGlobalOrientation cam -> quat in let SO3ObjectGetGlobalPosition point -> ppos in let if (ppos == nil) then [0.0 0.0 0.0] else ppos -> ppos in let 80.0 -> scalecoef in let if (cscale != 0.0) then cscale *. scalecoef else if (viewstr.V3D_bVRmode) then (getVectorDistanceF campos ppos) *. scalecoef else let normalizeVectorF (SO3MathsQuatGetDirection quat [0.0 0.0 (-.1.0)]) -> dir in (dotVectorF (subVectorF ppos campos) dir) *. scalecoef -> dist in let maxf 0.000001 ((dist /. ((itof vh) /. 2.0)) *. fovy) /. 2.0 -> cdist in let obstr.LBL_fScale *. (if (viewstr.V3D_bVRmode) then 0.2 else 0.6) -> maxscale in let getVectorDistanceF campos ppos -> ccdist in let if ((obstr.LBL_fVisibilityDist != 0.0) && (ccdist >=. obstr.LBL_fVisibilityDist)) then 0 else 1 -> state in ( if (cdist >. maxscale) then SO3ObjectSetScale point [maxscale maxscale maxscale] else SO3ObjectSetScale point [cdist cdist cdist]; if (!obstr.LBL_bLabelShowState) then nil else VUIset3DContainerVisible obstr.LBL_label state; if (!obstr.LBL_bPointShowState) then nil else SO3ObjectSetVisible point state 1; ); 0;; fun cbPreRender(inst, viewstr, obstr)= let SO3ObjectGetGlobalPosition obstr.LBL_parentObject -> pos in SO3ObjectSetGlobalPosition obstr.LBL_point pos; updatePoint obstr obstr.LBL_point; 0;; fun cbShowLabel(inst, from, action, param, reply, obstr)= if obstr.LBL_label != nil then VUIshowContainer obstr.LBL_label 1 else ( let VUIgetTextSize obstr.LBL_font obstr.LBL_sText (obstr.LBL_iMaxWidth - 2 * GLBL_xmargin) obstr.LBL_iAlignFlags -> [tw th] in let SO3ObjectGetPosition obstr.LBL_parentObject -> pos in ( //addLogMessage strcatn "label textsize: ["::(itoa tw)::" "::(itoa th)::"]"::nil; set obstr.LBL_label = VUIcreate3dContainer c3dXsession inst.INST_groupstr.GRP_project.PRJ_vuiGroup pos obstr.LBL_offset [(itof (tw + 2 * GLBL_xmargin)) (itof (th + 2 * GLBL_ymargin))] obstr.LBL_fScale obstr.LBL_bAutoScale obstr.LBL_fMaxAutoscaleDist 1 100 obstr.LBL_bShowOnTop; VUIset3DContainerParentTarget obstr.LBL_label obstr.LBL_parentObject; set obstr.LBL_textElement = VUIcreateFrame obstr.LBL_label nil [0.0 0.0] [100.0 100.0] [0 0 1 1 0 0 0 0] [1 1]; //set obstr.LBL_textElement = VUIcreateEditText obstr.LBL_label nil [0 0] [100 100] [0 0 1 1 0 0 0 0] [1 1] obstr.LBL_font [5 5] obstr.LBL_sText obstr.LBL_iFontColor 1; VUIsetContainerBackground obstr.LBL_label obstr.LBL_iBgColor nil nil nil nil 0 1 0; VUIsetContainerInputsEnable obstr.LBL_label 0; //VUIsetElementResource obstr.LBL_textElement (_checkpack VUI_defResTxt) VUI_ResSplited 0 nil 1 0; VUIsetElementText obstr.LBL_textElement VUIcreateFontInterface obstr.LBL_font obstr.LBL_sText [0 0] [0 0] [GLBL_xmargin GLBL_ymargin] obstr.LBL_iAlignFlags if (obstr.LBL_iMaxWidth == 0) then VUI_TextAuto else VUI_TextAutoHeight 1; VUIsetElementResource obstr.LBL_textElement nil nil nil nil nil nil nil nil nil; VUIshowContainer obstr.LBL_label 1; ); ); set obstr.LBL_bLabelShowState = 1; SendPluginEvent inst "Shown" nil nil; 0;; fun cbHideLabel(inst, from, action, param, reply, obstr)= if obstr.LBL_label == nil then nil else VUIshowContainer obstr.LBL_label 0; set obstr.LBL_bLabelShowState = 0; SendPluginEvent inst "Hidden" nil nil; 0;; fun cbDbClick(inst, viewstr, x, y, btn, obstr)= let V3DgetLastMouseData viewstr 0 -> [_ _ obj mat _ _ _ _ _] in if ((btn != 1) || (obstr.LBL_point != obj) || (obstr.LBL_pointMat != mat)) then nil else ( if obstr.LBL_bLabelShowState == 0 then cbShowLabel inst nil nil nil nil obstr else cbHideLabel inst nil nil nil nil obstr; ); 0;; fun cbInputClick(inst, viewstr, id, x, y, btn, pdata, obstr)= let pdata -> [obj mat _ _ _ _] in if ((btn != 1) || (obstr.LBL_point != obj) || (obstr.LBL_pointMat != mat)) then nil else ( if obstr.LBL_bLabelShowState == 0 then cbShowLabel inst nil nil nil nil obstr else cbHideLabel inst nil nil nil nil obstr; ); 0;; fun cbInputUpdate(inst, viewstr, id, x, y, btn, pdata, obstr)= let pdata -> [obj mat _ _ _ _] in if ((obstr.LBL_point != obj) || (obstr.LBL_pointMat != mat)) then ( if (obstr.LBL_bLabelShowState == 0) then nil else cbHideLabel inst nil nil nil nil obstr; ) else ( if (obstr.LBL_bLabelShowState == 1) then nil else cbShowLabel inst nil nil nil nil obstr; ); 0;; fun cbShowPoint(inst, from, action, param, reply, obstr)= set obstr.LBL_bPointShowState = 1; let getPluginInstanceName inst -> iname in if (obstr.LBL_point != nil) then SO3ObjectSetVisible obstr.LBL_point 1 1 else ( set obstr.LBL_point = SO3OctahedronCreate (V3DgetSession c3dXsession) iname (strcat iname "_point") 0.14 0.1 0.1; SO3ObjectSetGlobalPosition obstr.LBL_point SO3ObjectGetGlobalPosition obstr.LBL_parentObject; let SO3MaterialCreate (V3DgetSession c3dXsession) (strcat iname ".material") iname -> mat in ( set obstr.LBL_pointMat = mat; SO3MaterialSetReceiveShadows mat 0; SO3MaterialSetIgnoreSlicePlane mat 1; if (obstr.LBL_bShowOnTop == 0) then nil else ( SO3MaterialSetPassDepthFunction mat 0 0 SO3_COMPARE_FUNCTION_ALWAYS_PASS; SO3MaterialSetPassDepthWriteEnabled mat 0 0 0; SO3ObjectSetMouseForeGround obstr.LBL_point 1; SO3ObjectSetRenderOverlay obstr.LBL_point 1; ); SO3MaterialSetAmbient mat obstr.LBL_iPointColor; SO3MaterialSetDiffuse mat obstr.LBL_iPointColor; SO3MaterialSetSelfIllumination mat obstr.LBL_iPointColor; SO3MaterialSetSpecular mat obstr.LBL_iPointColor; SO3MaterialSetShininess mat 128.0; SO3MaterialSetPassSceneBlending mat 0 0 SO3_SCENE_BLEND_FACTOR_SOURCE_ALPHA SO3_SCENE_BLEND_FACTOR_ONE_MINUS_SOURCE_ALPHA nil nil; ); SO3ObjectSetCastShadows obstr.LBL_point 0; SO3EntitySetMaterial obstr.LBL_point obstr.LBL_pointMat 0; ); if (obstr.LBL_iClick == 1) then ( setPluginInstanceCbInputClick inst mkfun8 @cbInputClick obstr; 0; ) else if (obstr.LBL_iClick == 2) then ( setPluginInstanceCbDbClick inst mkfun6 @cbDbClick obstr; 0; ) else if (obstr.LBL_iClick == 3) then ( setPluginInstanceCbInputUpdate inst mkfun8 @cbInputUpdate obstr; 0; ) else nil; //force update to avoid strange flash on first show updatePoint obstr obstr.LBL_point; 0;; fun cbHidePoint(inst, from, action, param, reply, obstr)= if (obstr.LBL_point == nil) then nil else SO3ObjectSetVisible obstr.LBL_point 0 1; setPluginInstanceCbInputClick inst nil; setPluginInstanceCbInputUpdate inst nil; setPluginInstanceCbDbClick inst nil; set obstr.LBL_bPointShowState = 0; 0;; fun cbSetObject(inst, from, action, param, reply, obstr)= let V3DgetObjectByName c3dXsession param -> obj in if (obj == nil) then nil else ( set obstr.LBL_parentObject = obj; VUIset3DContainerPosition obstr.LBL_label SO3ObjectGetPosition obj; ); 0;; fun cbSetOffset(inst, from, action, param, reply, obstr)= if (!strcmp "" (strtrim param)) || (param == nil) then nil else let strextr param -> lp in let [(atof (nth_list (hd lp) 0)) (atof (nth_list (hd lp) 1))] -> offset in ( set obstr.LBL_offset = offset; VUIset3DContainerOffset obstr.LBL_label offset; ); 0;; fun cbSetText(inst, from, action, param, reply, obstr)= if ((strcmp param obstr.LBL_sText) == 0) then nil else ( set obstr.LBL_sText = param; VUIsetElementTextContent obstr.LBL_textElement obstr.LBL_sText; let VUIgetTextSize obstr.LBL_font obstr.LBL_sText (obstr.LBL_iMaxWidth - 2 * GLBL_xmargin) obstr.LBL_iAlignFlags -> [tw th] in VUIsetContainerSize obstr.LBL_label [(itof (tw + 2 * GLBL_xmargin)) (itof (th + 2 * GLBL_ymargin))] nil; ); 0;; fun cbSetMaxWidth(inst, from, action, param, reply, obstr)= set obstr.LBL_iMaxWidth = atoi param; 0;; fun getHalign(mode)= if (mode == 1) then iVUITEXT_HALIGNCENTER else if (mode == 2) then iVUITEXT_HALIGNRIGHT else iVUITEXT_HALIGNLEFT;; fun cbNewOb(inst)= let (getPluginInstanceParam inst "object") -> objname in let atof (getPluginInstanceParam inst "xoffset") -> xoffset in let if xoffset == nil then 0.5 else xoffset -> xoffset in let atof (getPluginInstanceParam inst "yoffset") -> yoffset in let if yoffset == nil then 0.5 else yoffset -> yoffset in let atof (getPluginInstanceParam inst "scale") -> scale in let if scale == nil then 1.0 else scale -> scale in let atoi (getPluginInstanceParam inst "fontsize") -> fsize in let if fsize == nil then 12 else fsize -> fsize in let atoi (getPluginInstanceParam inst "maxwidth") -> maxwidth in let if maxwidth == nil then 0 else maxwidth -> maxwidth in let atoi (getPluginInstanceParam inst "fontcolor") -> fcolor in let if fcolor == nil then 0xffffff else fcolor -> fcolor in let atoi (getPluginInstanceParam inst "backgroundcolor") -> bcolor in let if bcolor == nil then 80 else bcolor -> bcolor in let atoi (getPluginInstanceParam inst "horalign") -> halign in let if halign == nil then BT_TEXT_HORIZ_CENTERED else getHalign halign -> halign in let getPluginInstanceParam inst "text" -> text in let if text == nil then "" else text -> text in let atoi (getPluginInstanceParam inst "pointcolor") -> pcolor in let if pcolor == nil then 80 else pcolor -> pcolor in let atoi (getPluginInstanceParam inst "pointclick") -> click in let if click == nil then 0 else click -> click in let atoi (getPluginInstanceParam inst "point") -> point in let if point == nil then 0 else point -> point in let atof (getPluginInstanceParam inst "visibility") -> visibility in let if visibility == nil then 0.0 else visibility -> visibility in let atoi (getPluginInstanceParam inst "autoscale") -> autoscale in let if autoscale == nil then 1 else autoscale -> autoscale in let atof (getPluginInstanceParam inst "maxautoscaledist") -> maxautoscaledist in let if maxautoscaledist == nil then 5.0 else maxautoscaledist -> maxautoscaledist in let atoi (getPluginInstanceParam inst "showontop") -> showontop in let if showontop == nil then 1 else showontop -> showontop in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let VUIcreateFont "Sans" fsize 0 fcolor 1 -> font in let mkLabelStr[nil nil obj [xoffset yoffset] scale halign maxwidth font fcolor bcolor text nil nil pcolor click visibility autoscale maxautoscaledist showontop 0 point] -> obstr in ( SO3GroupCreate (V3DgetSession c3dXsession) getPluginInstanceName inst; if (init == 0 || click == 3) then nil else cbShowLabel inst nil nil nil nil obstr; if (point == 0) then cbHidePoint inst nil nil nil nil obstr else cbShowPoint inst nil nil nil nil obstr; setPluginInstanceCbPreRender2 inst mkfun3 @cbPreRender obstr; PluginRegisterAction inst "Set object" mkfun6 @cbSetObject obstr; PluginRegisterAction inst "Set offset" mkfun6 @cbSetOffset obstr; PluginRegisterAction inst "Set text" mkfun6 @cbSetText obstr; PluginRegisterAction inst "Set max width" mkfun6 @cbSetMaxWidth obstr; PluginRegisterAction inst "Show label" mkfun6 @cbShowLabel obstr; PluginRegisterAction inst "Hide label" mkfun6 @cbHideLabel obstr; PluginRegisterAction inst "Show point" mkfun6 @cbShowPoint obstr; PluginRegisterAction inst "Hide point" mkfun6 @cbHidePoint obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file) = VUIsetEnable c3dXsession 1; PlugRegister @cbNewOb nil; setPluginEditor @dynamicedit; 0;;