Notifications
Clear all

[Closed] 2 problems with Viewport Redraw Callback Mechanism

I’m testing a simple script and a couple of things are causing problems.

1st problem:

fn DisplayData =
(
gw.setTransform(matrix3 1)
for o in selection do
(
gw.text o.pos o.name color:yellow
print o.name
)
gw.enlargeUpdateRect #whole
gw.updateScreen()
)
DisplayData()

The names are printed in the listener as expected but in the viewport the objects are redrawn on top of them, so I need to be in wireframe mode to see them (and I can see the wireframes are drawn on top of the names).

2nd problem:

unregisterRedrawViewsCallback DisplayData
fn DisplayData =
(
gw.setTransform(matrix3 1)
for o in selection do
(
gw.text o.pos o.name color:yellow
print o.name
)
gw.enlargeUpdateRect #whole
gw.updateScreen()
)
registerRedrawViewsCallback DisplayData

Now I’m using a callback to call the same funtion. When I move in the viewport, again the names appear in the listener, so the callback works fine. But the names do not show in the viewport, not even in wireframe mode.

Any help is much appreciated, as I have absolutely no idea what to do.
Using max 9, if that’s relevant. Thanks.

2 Replies

Hi Pat,
you cannot see the text in viewport because the method you’re using (gw.text) draws text in 3D space taking into account Z-Buffer, and it actually fits inside your geometry. Try to create a very small Sphere and execute it again, you’ll see part of the name as it is inside geometry.

To go around this issue you can set viewport drawing limits to avoid considering #zBuffer (that’s what happens in wireframe mode), draw your text on top, revert viewport render limits to original state.

fn DisplayData =
(
    gw.setTransform(Matrix3 1)

    -- get current viewport render limits
    local anRndLimits = gw.getRndLimits()
    
    -- look for #zBuffer flag
    local iFlag = findItem anRndLimits #zBuffer
    
    -- if found copy render limits, remove zBuffer flag, set new limits
    if (iFlag != 0) do
    (
        local anNewLimits = deepCopy anRndLimits
        deleteItem anNewLimits iFlag
        gw.setRndLimits anNewLimits
    )

    for o in selection do
    (
        gw.text o.pos o.name color:yellow
        print o.name
    )
    
    -- revert viewport render limits to original state
    gw.setRndLimits anRndLimits
    
    gw.enlargeUpdateRect #whole
    gw.updateScreen()
)

DisplayData()

If you plan to register the redraw view callback, you can use gw.wText with gw.wTransPoint which actually draws text in screen space on top of everything.

fn DisplayData =
(
    gw.setTransform(Matrix3 1)

    local p3TextPos = [0,0,0]
    for o in selection do
    (
        p3TextPos = gw.wTransPoint o.pos
        gw.wText p3TextPos o.name color:yellow
        print o.name
    )

    gw.enlargeUpdateRect #whole
    gw.updateScreen()
)

registerRedrawViewsCallback DisplayData
forceCompleteRedraw()
  • Enrico

Thanks for the very clear explanations, Enrico. You saved my day