Determining the scale of objects to be drawn to the viewport by a DisplayConduit

rhinocommon

#1

Hi!

What is the correct way to determine the scale (or size on screen) of object that are to be drawn onto the viewport by a DisplayConduit in Rhinocommon? I have rather large geometry that has to be drawn and it’s too slow to draw the whole thing if it is scaled very small, hence I want to draw a simplified version.

Thanks
Taavi


#2

Hi @Taavi_Looke,

you could measure the size on screen by getting the bounding box of your geometry, then transform the box points into screen coordinates and measure the 2d distance of the box diagonal. If the distance is below your threshold, draw the bounding box instead. Some python pseudocode to get the diagonal length in pixels:

def DoSomething():
    id = rs.GetObject("Brep", 16, True, False)
    if not id: return
    
    bbox = rs.BoundingBox(id, None, True)
    pts = [rs.XformWorldToScreen(pt, None, True) for pt in bbox]
    
    diagonal_length = pts[0].DistanceTo(pts[6])
    
    print "diagonal_length: {} px ".format(diagonal_length)
    
DoSomething()

There is also a method GetWorldToScreenScale which might help to find out if a user has zoomed out very far away of your geometry…

c.


#3

Thanks!

I ended up using the GetWorldToScreenScale. That seems much easier, I just need a point and the method will give me back a double that I can use for deciding the level of detail.