Home Coding, Scripting, Shaders

[3ds Max] - viewport status display Maxscript Help!

polycounter lvl 7
Offline / Send Message
dg3duy polycounter lvl 7
I need help, I can not draw behind each text a black rectangle and that this rectangle when maximizing or adjusting the screen is kept next to the text.
I don't understand how to use Viewport Drawing Methods to make the black rectangular drawing stay behind the text




macroScript StatisticsInfo
category:"DG3Duy" 
toolTip:"StatisticsInfo" 
buttonText:"StatisticsInfo"

(
fn CoordStatistics =
(
try (MaterialName =  getRefCoordSys() ) catch(MaterialName = "")
GW.hText [GW.GetWinSizeX()*0.45,30,0] MaterialName color:yellow
gw.updateScreen()

(
fn playAndStopAnimation =
(
if isAnimPlaying() != true do
forcecompleteRedraw doDisabled:true
)
playAndStopAnimation()
)
)
unRegisterRedrawViewsCallback CoordStatistics
registerRedrawViewsCallback CoordStatistics
CoordStatistics ()

--------------------------------------------------------------------------------------------------

fn TransformationsStatistics =
(
try (MaterialName =  toolMode.commandmode) catch(MaterialName = "")
GW.hText [GW.GetWinSizeX()*0.35,30,0] MaterialName color:yellow
gw.updateScreen()

)
unRegisterRedrawViewsCallback TransformationsStatistics
registerRedrawViewsCallback TransformationsStatistics
TransformationsStatistics ()

-------------------------------------------------------------------------------------------------


fn SubselectionStatistics =
(
try (MaterialName =  $.GetEPolySelLevel()) catch(MaterialName = "")
GW.hText [GW.GetWinSizeX()*0.55,30,0] MaterialName color:yellow
gw.updateScreen()

)
unRegisterRedrawViewsCallback SubselectionStatistics
registerRedrawViewsCallback SubselectionStatistics
SubselectionStatistics ()


--------------------------------------------------------------------------------------------------

fn NameselectionStatistics =
(
try (MaterialName =  objName = selection[1].name) catch(MaterialName = "")
GW.hText [GW.GetWinSizeX()*0.65,30,0] MaterialName color:yellow
gw.updateScreen()

)
unRegisterRedrawViewsCallback NameselectionStatistics
registerRedrawViewsCallback NameselectionStatistics
NameselectionStatistics ()

--------------------------------------------------------------------------------------------------

fn meshStatistics =
if(classof (modPanel.getCurrentObject()) == Editable_Mesh) Then
(
SOLevelName = case SubObjectLevel of
(
    0: #Object
    1: #Vertex
    2: #Edge
    3: #face 
)
try (SOLevelName = SubObjectLevel() ) catch(MaterialName = "")
GW.hText [GW.GetWinSizeX()*0.55,30,0] SOLevelName color:yellow
gw.updateScreen()

)
unRegisterRedrawViewsCallback meshStatistics
registerRedrawViewsCallback meshStatistics
meshStatistics ()


--------------------------------------------------------------------------------------------------
)

Replies

  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    I don't know the answer to your question, but I wrote a similar script to yours a while ago that may give you some ideas how to make your code more compact:

    fn vpSelStats_fn = (
        vpWidth = gw.getWinSizeX()
    
        selType = try(($.baseObject) as string)catch("n/a")
        SelName = try(($.name) as string)catch("n/a")
        selMod = try (((modpanel.getCurrentObject()).name) as string)catch("n/a") --Only works if Modifier Tab is active.
        selSub = try (subobjectLevel as string)catch("n/a")
    
        allInfo = ("Type: " + selType + "  |  ") + ("Name: " + SelName + "  |  ") + ("Modifier: " + selMod + "  |  ") + ("Sub Object Level: " + selSub)
        viewCenterX = (vpWidth / 2) - (((gw.getTextExtent allInfo).x) / 2)
    
        gw.setTransform (Matrix3 1)
        gw.wtext [viewCenterX,30,0] allInfo color:Yellow
        gw.UpdateScreen()
    )
    
    if (vpSelStatsState == undefined or vpSelStatsState == "Off") then (
        registerRedrawViewsCallback vpSelStats_fn
        global vpSelStatsState = "On"
    )
    else (
        UnregisterRedrawViewsCallback vpSelStats_fn
        vpSelStatsState = "Off"
    )
    
    redrawViews<br>
  • dg3duy
    Offline / Send Message
    dg3duy polycounter lvl 7
    PolyHertz said:
    I don't know the answer to your question, but I wrote a similar script to yours a while ago that may give you some ideas how to make your code more compact:

    fn vpSelStats_fn = (
        vpWidth = gw.getWinSizeX()
    
        selType = try(($.baseObject) as string)catch("n/a")
        SelName = try(($.name) as string)catch("n/a")
        selMod = try (((modpanel.getCurrentObject()).name) as string)catch("n/a") --Only works if Modifier Tab is active.
        selSub = try (subobjectLevel as string)catch("n/a")
    
        allInfo = ("Type: " + selType + "  |  ") + ("Name: " + SelName + "  |  ") + ("Modifier: " + selMod + "  |  ") + ("Sub Object Level: " + selSub)
        viewCenterX = (vpWidth / 2) - (((gw.getTextExtent allInfo).x) / 2)
    
        gw.setTransform (Matrix3 1)
        gw.wtext [viewCenterX,30,0] allInfo color:Yellow
        gw.UpdateScreen()
    )
    
    if (vpSelStatsState == undefined or vpSelStatsState == "Off") then (
        registerRedrawViewsCallback vpSelStats_fn
        global vpSelStatsState = "On"
    )
    else (
        UnregisterRedrawViewsCallback vpSelStats_fn
        vpSelStatsState = "Off"
    )
    
    redrawViews<br>
    Woouuu looks great on screen, thanks for the input.
  • Revel
    Offline / Send Message
    Revel interpolator
    Awesome @PolyHertz just wondering will it impact viewport performance?
  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    @Revel Theres a small performance impact but I very much doubt you'd notice it unless your working in an extremely heavy scene where every frame counts. That said, this method does affect performance the more items you draw on screen. If you notice the script I posted above actually draws just one item to the screen which is a compiled string of all the info at once, where as the one dg3duy posted draws each piece of info separately resulting in 4x the performance cost. I did a test a while ago where had the index numbers of all object components floating above them using this method, so thousands of items, and that absolutely destroyed the framerate. But yea, for this script there's not enough being drawn to really matter.
  • Revel
    Offline / Send Message
    Revel interpolator
    @PolyHertz cool! thanks for the info man!
  • dg3duy
    Offline / Send Message
    dg3duy polycounter lvl 7

    This way you can place a box in the background to highlight the text. @PolyHertz  @Revel
    Visually it is perfect but at code level I imagine it is very bad :)




    fn drawThis =
    (
        boxHW=[400,20]
    messageText=#(test)
    boxColor = (lightGray=white/4)
    TextColor = black

    scrSize=getViewSize()-400/2*2
    gw.setTransform(Matrix3 1)

    for i in messageText do
    (
    posInScreen=[scrSize.x,scrSize.y]
    BoxPosX=(posInScreen.x)/2
    BoxPosY=(posInScreen.y)+380/2*2
    txtRect = (box2 BoxPosX BoxPosY boxHW.x boxHW.y) --(box2 (pos.x) (pos.y) width height  )
    gw.wrect txtRect boxColor
    )

    gw.enlargeUpdateRect #whole
    gw.updateScreen()
    )

    unRegisterRedrawViewsCallback drawThis
    registerRedrawViewsCallback drawThis
    drawThis ()

    forceCompleteRedraw()

Sign In or Register to comment.