Search code examples
autodesk-forgeautodesk-viewerautodesk-model-derivativeautodesk-data-management

Forge Viewer - Markups - can we get xy coordinates of the current selection?


I am using markup extension to draw on my viewer, after drawing, on selection of markup event, can I get its center coordinates of current selection or any coordinates inside of it? if not, at least can I get dbId behind current selection?

Thanks in advance


Solution

  • Yelp~ it's the case, and see also:

    // Get the markup's position in browser pixel space. the (0,0) is top left
    Markup#getClientPosition()
    
    // Get the markup's bounding rect in browser pixel space.
    
    Markup#getClientSize()
    
    // get the markup's bounding rect in browser pixel space, including the stroke width
    
    Markup#getBoundingRect()
    

    BTW, to obtain dbId within the markup boundary, you can do this:

    1. Get markup's BoundingRect in browser's pixel space
    2. Convert coordinates of the rect's vertices into viewer's 3d space via Viewer3D#clientToWorld
    3. Do bounding box collision to find out intersected mesh for the dbId, see here for the example: https://forge.autodesk.com/blog/custom-window-selection-forge-viewer-simpler-extension