1

I have used below code to get bounding box of 2D element.

function find2DBounds( fragList, fragId, dbId, bc ) {
    const mesh = fragList.getVizmesh( fragId );
    const vbr = new Autodesk.Viewing.Private.VertexBufferReader( mesh.geometry );
    vbr.enumGeomsForObject( dbId, bc );
}

function get2DBounds( dbId, model ) {
    const it = model.getData().instanceTree;
    const fragList = model.getFragmentList();

    let bounds = new THREE.Box3();
    let bc = new Autodesk.Viewing.Private.BoundsCallback( bounds );
    const dbId2fragId = model.getData().fragments.dbId2fragId;
    const fragIds = dbId2fragId[dbId];

    if( Array.isArray( fragIds ) ) {
        for( let i = 0; i < fragIds.length; i++ ) {
            find2DBounds( fragList, fragIds[i], dbId, bc );
        }
    } else if( typeof fragIds === 'number' ) {
        find2DBounds( fragList, fragIds, dbId, bc );
    }

    return bc.bounds;
}


var model = this.viewer.model; 
 var modelData = model.getData();
 var itree = modelData.instanceTree;
itree.enumNodeChildren(itree.getRootId(), function (dbId) {   
// Here you go
cosnt bondingBox = get2DBounds( dbId, viewer.model );

}

This code is correctly in browser and getting correct bounding box for 2D elements. But when I tried to execute this code in browser through IOS, I am not getting bounding box for 2D elements.

Process of use above code through IOS : - Design a UIWebView in IOS - Embed html page - Embed above java script code to into html page - Get all element ids for 2D sheet. - Get bounding box for those using above code.

observed that bounding box are infinity for all 2D entities.

Could you please tell me what is wrong with these approach?

  • This might be an issue of the Forge Viewer, I'm checking with our engineering team, and will get you back A.S.A.P. – Eason Kang Jan 16 '18 at 02:18

1 Answers1

2

This might be an issue of the viewer internal API. I have logged a request as LMV-3154 in our internal case system to let our engineering team allocate time to investigate. It might take time to figure out what happened. You can send the request id to forge.help@autodesk.com to track updates in the future.

Apologies for any inconvenience caused.

Update 2021

Here is the working code snippet for viewer v7.x

function find2DBounds( fragList, fragId, dbId, bc ) {
    const mesh = fragList.getVizmesh( fragId );
    const vbr = new Autodesk.Viewing.Private.VertexBufferReader( mesh.geometry );
    vbr.enumGeomsForObject( dbId, bc );
}

function get2DBounds( dbId, model, useInstancing ) {
    const it = model.getData().instanceTree;
    const fragList = model.getFragmentList();

    let bounds = new THREE.Box3();
    let bc = new Autodesk.Viewing.Private.BoundsCallback( bounds );
    const dbId2fragId = model.getData().fragments.dbId2fragId;
    const remappedId = model.reverseMapDbId(dbId);
    const fragIds = dbId2fragId[remappedId];

    if( Array.isArray( fragIds ) ) {
        for( let i = 0; i < fragIds.length; i++ ) {
            find2DBounds( fragList, fragIds[i], remappedId, bc );
        }
    } else if( typeof fragIds === 'number' ) {
        find2DBounds( fragList, fragIds, remappedId, bc );
    }

    return bc.bounds;
}

// Here you go
let bondingBox = get2DBounds( 5314, viewer.model );

Update:

The fix for LMV-3154 has been released since v4.2.2, here is the updated code. With this patch, you have to pass use2dInstancing to VertexBufferReader to avoid the infinite bounds issue on the iOS.

function find2DBounds( fragList, fragId, dbId, useInstancing, bc ) {
    const mesh = fragList.getVizmesh( fragId );
    const vbr = new Autodesk.Viewing.Private.VertexBufferReader( mesh.geometry, useInstancing );
    vbr.enumGeomsForObject( dbId, bc );
}

function get2DBounds( dbId, model, useInstancing ) {
    const it = model.getData().instanceTree;
    const fragList = model.getFragmentList();

    let bounds = new THREE.Box3();
    let bc = new Autodesk.Viewing.Private.BoundsCallback( bounds );
    const dbId2fragId = model.getData().fragments.dbId2fragId;
    const fragIds = dbId2fragId[dbId];

    if( Array.isArray( fragIds ) ) {
        for( let i = 0; i < fragIds.length; i++ ) {
            find2DBounds( fragList, fragIds[i], dbId, useInstancing, bc );
        }
    } else if( typeof fragIds === 'number' ) {
        find2DBounds( fragList, fragIds, dbId, useInstancing, bc );
    }

    return bc.bounds;
}

let use2dInstancing = viewer.impl.use2dInstancing;
// Here you go
let bondingBox = get2DBounds( 5314, viewer.model, use2dInstancing );
Eason Kang
  • 6,155
  • 1
  • 7
  • 24