Search code examples
autodesk-forgeautodesk-viewerautodesk

How to locale the level or floor of the object in autodesk forge viewer


I am getting the dbid of object and using the dbid I thought I would get the level of object from the properties which is defined as Layer but unfortunately few of my object does not have layer defined so is there any other way round where I can identify the level or floor where the object is present ??


Solution

  • If your model is RVT generated by Revit 2018 and later, you can get Level data and dbIds of the level occluder (e.g. floor, ceilings) by reading the AecModelData. Once you have AecModelData loaded, then you can take advantage of Autodesk.AEC.LevelsExtension to get z ranges of each level.

    const floorData viewer.getExtension('Autodesk.Aec.LevelsExtension').floorSelector.floorData;
    
    const currentLevel = floorData[0];
    const currentLevelZmin = currentLevel.zMin;
    const currentLevelZmax = currentLevel.zMax;
    

    Afterward, compare the z value of the object you want with the level ranges to check if it's inside the level.

    const minZ = currentLevel.zMin;
    const maxZ = currentLevel.zMax;
    
    let nodeBox = new Float32Array(6);
    instanceTree.getNodeBox(dbId, nodeBox);
    
    const nodeBoxMinZ = nodeBox[2];
    const nodeBoxMaxZ = nodeBox[5];
    
    let insideLevel = false;
    
    if ((nodeBoxMinZ >= minZ && nodeBoxMinZ <= maxZ) ||
        (nodeBoxMaxZ >= minZ && nodeBoxMaxZ <= maxZ) ||
        (nodeBoxMinZ <= minZ && nodeBoxMaxZ >= maxZ)) {
    
        insideLevel = true;
    }
    
    if( insideLevel ) {
      // Do someting
    }
    

    BTW, if you load Autodesk.AEC.LevelsExtension with the ifcLevelsEnabled: true, then this extension works for the IFC model, too. It will rebuild floor data for the IFC model on-the-fly.

    viewer.loadExtension('Autodesk.AEC.LevelsExtension', {ifcLevelsEnabled: true});