Search code examples
autodesk-forgeautodesk-viewer

Loading DWGs into AggregatedView


I'm having issues getting several models aligned in an AggregatedView using APS (Forge). I have several Revit-files loaded, they share coordinates and are loaded into the view correctly aligned to each other. But after user input I am loading several more models (this time DWGs) into the same instance. These DWGs I of course want to be aligned to the Revit files, but however I try it I just can't seem to align them. The Revit files have a Project Base Point of 142000,6584000,0, (which gives the correct Shared Coordinates to the DWGs) but when I load the Revit files into the viewer the get a globalOffset of: x: 473184.78.., y: 21616569.45.., z: -52.18... Which doesn't seem right to me. And when I look at the unitScale of the model they have a unit scale of 0.3048 even though they have "Length" and "Distance" in meter. When I then load the DWGs I use:

// revitModel is the first Revit model loaded into the view
const revitTransform = revitModel.getData().refPointTransform.elements;
const revitOffset = revitModel.getData().globalOffset;
var coordinates_alter = new THREE.Vector3(revitTransform[12]-142000, revitTransform[13]-6584000, revitTransform[14]);
var transform = new THREE.Matrix4().makeTranslation(coordinates_alter.x,coordinates_alter.y,coordinates_alter.z);

To give me the options:

        const options = {
            placementTransform: transform,
            globalOffset: revitOffset,
            applyRefPoint: true,
        };

This puts my models "kinda" correctly, which means within a couple of km.. But however else I try the models gets placed insanely far away. Could really use some help, sadly looking at other questions hasn't revealed to me what I'm doing wrong here.

Thanks!

I tried loading both the Revit models and DWGs with "applyScaling: 'meter'", but with that option the Revit models no longer load correctly aligned to each other, and looking at the unitScale of the models only the first model gets the applied scaling, the rest keeps 0.3048 (the DWGs already have the correct scaling of 1). When I measure the models I see that the DWGs are about 1/3 as big as they should be in comparison to the Revit files, which would make sense considering the scaling but sadly applying scaling doesn't work for the Revit files.

I have tried redoing the variable "coordinates_alter" with other subtractions/additions but I can nog get the models closer to what I have at the moment.

I have also tried loading them in "vanilla" or with different globalOffset but neither places them correctly.


Solution

  • Getting model offsets right is a pain. This is what worked for me:

    applyRefPoint: false,
    applyScaling: "m"
    

    Then mostly ignoring all model specific globalOffset, refPointTransform and placementTransform, instead only considering AggregatedView.globalOffset. This vector will dynamically change when loading or unloading models from the aggregated viewer.

    If you actually need to apply a transform to a model (it has an incorrect position, rotation or scaling if loaded in combination with other models in eg. Revit) I think you should only use placementTransform, no additional offsets. This is a Matrix4 which you can use to arbitrarily translate, rotate or scale your model. Using additional offsets is only going to be confusing.