export default function getModalPosition(viewer, dbid) {
  const tree = viewer.model.getData().instanceTree;
  const fragList = viewer.model.getFragmentList();
  const nodebBox = new window.THREE.Box3();

  // for each fragId on the list, get the bounding box
  tree.enumNodeFragments(
    dbid,
    (fragId) => {
      const fragbBox = new window.THREE.Box3();
      fragList.getWorldBounds(fragId, fragbBox);
      nodebBox.union(fragbBox); // create a unifed bounding box
    },
    true
  );
  const pos = viewer.worldToClient(nodebBox.center());
  return { left: Math.floor(pos.x), top: Math.floor(pos.y) };
}
