Notifications
Clear all

[Closed] Viewport drawing methods: draw at constant size

Heyya,

So – I have encountered the following problem:

I am using the viewport drawing functions to draw arrows between objects in the scene to display target relations for a plguin i’m working on.

Since the gw.Polyline() and gw.marker() can not be zbuffered properly I changed my approach to use multiple gw.triangle() calls to create my arrows.
This however comes with the drawback that my shapes won’t stick to a constant size on screen and disappear entirely when the user zooms out too far.

In theory, from what I found while digging through the docs, this should be solveable by multiplieing my shape defining parameters by the factor returned by:

gw.nonScalingObjectSize()

Sadly, calling this function allways returns 1.0 for me.
I don’t know wether I am using it wrong or if it’s simply broken in max 2016.

I have come up with an alternate solution for this, which works but I bet there are more elegant solutions to this and I’d also like to hear about your experiences with the aforementioned function.


fn DrawTargetLine start end =
(    
    local col = rootNode.entLinkcol    
    
    gw.setTransform(matrix3 1)
    
    local start2 = -start
    local lineCenter = (end-start2)*0.5
    local camRay = getViewDirectionRay()
    
    local xdir = normalize (end - start)
    local cdir = normalize (cross xdir (camRay.dir))
    
    local targetdist = length (end - start)   
    --The following is where I would have liked to use gw.nonScalingObjectSize()
    local distfactor = if gw.IsPerspView() then (getScreenScaleFactor [0,0,0])/125. else (getScreenScaleFactor [0,0,0])/250.
    
    local RMax = 0.1332
    local LMax = 0.333
    local WMax = 1
    
    local rad = if 8 * distfactor < targetdist * RMax then 8 * distfactor else targetdist * RMax
    local height = if 20 * distfactor < targetdist * LMax then 20 * distfactor else targetdist * LMax
    local width = 0.5 * distfactor
    
    gw.startTriangles() 
    gw.triangle #( (start + cdir * width),  (start - cdir * width), (end - cdir * width)) #(col, col, col)
    gw.triangle #( (end - cdir * width), (end + cdir * width), (start + cdir * width)) #(col, col, col)
    gw.triangle #( (lineCenter + xdir * height), (linecenter + cdir * rad), (linecenter - cdir * rad)) #(col, col, col)
    gw.endTriangles()
        
)