Search code examples
autodesk-forgeautodesk-viewer

How does Forge Viewer calculate globalOffset?


In our application, we draw rooms by reading information from an IFC file and then generate custom objects which are added to the model builder. For each vertex, we substract the globalOffset, so that the rooms align nicely with the model. This works perfectly for most models we have. However, for one model, the globalOffset is huge and thus, the custom objects will be drawn far away from the model.

globalOffset is far too high

The vertices we read from the IFC file are located in a reasonable space around {0, 0, 0}.

vertice example

My question now is: How is the globalOffset calculated? What properties of the IFC file are taken into account?

As already stated, the other models work fine when we subtract the globalOffset from each vertex. Here is an example:

enter image description here

Thanks in advance for any form of help!

EDIT: For everyone interested in the origin of the global offset in the IFC file: search for "ifcsite", there should be a reference to a local placement and this may contain a rather big translation (at least in my case).


Solution

  • The global offset is the mid-point of the model bounding box by default like the below:

    var bboxMeta = model.getData().metadata["world bounding box"];
    var min = new THREE.Vector3(bbox.minXYZ[0], bbox.minXYZ[1], bbox.minXYZ[2]);
    var max = new THREE.Vector3(bbox.maxXYZ[0], bbox.maxXYZ[1], bbox.maxXYZ[2]);
    
    var bbox = new THREE.Box3(min, max);
    
    var globalOffset = bbox.center();
    

    It's used to avoid floating point precision issues for models that are far away from the viewer's origin. By default, Forge Viewer will use this offset to move the whole model to the viewer's origin.