Revit 3D View Camera Settings

Revit 3D View Camera Settings

ahmedabid933
Explorer Explorer
3,026 Views
14 Replies
Message 1 of 15

Revit 3D View Camera Settings

ahmedabid933
Explorer
Explorer

Hello,

 

We are trying to replicate the view from Forge Viewer into a perspective view within Revit 2023.

 

To achieve this, we followed this article: Map Forge Viewer Camera back to Revit.

In Revit, when the internal origin is located at the center of the model, the views matched perfectly.

 

However, we have encountered an issue when the internal origin is not positioned at the center of the model. We couldn't find the same view.

This discrepancy in camera positioning appears to be the root of the problem.

 

If you have any insights or suggestions on resolving this issue, we would greatly appreciate your assistance.

0 Likes
Accepted solutions (3)
3,027 Views
14 Replies
Replies (14)
Message 2 of 15

jeremy_tammik
Alumni
Alumni

Maybe Eason can help you, being the author of the post you refer to, so I sent him a message informing him of your question here.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 15

eason.kangEDLV4
Autodesk Support
Autodesk Support

Could you elaborate on what "internal origin is not positioned at the center of the model" means? Is it in viewer or in Revit? 


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 4 of 15

ahmedabid933
Explorer
Explorer

Thanks for your reply.
In Revit, I am testing on a first model, where the Internal origin is at the center of the model as shown in the photo below:

ahmedabid933_0-1710176911740.png

This works fine.

On another model, I noticed that the model is a bit far from the Internal origin point, and there I don't have the same view as on Forge.

ahmedabid933_2-1710177073121.png

 

 

 

 

 

 

0 Likes
Message 5 of 15

eason.kangEDLV4
Autodesk Support
Autodesk Support
Accepted solution

Thank you for getting back to me. If I understand correctly, this issue happens when mapping APS/Forge viewer's camera back to Revit, right? But that should be irrelevant to Revit's internal origin but related to how we map points in the viewer's coordinate space to Revit's internal coordinate space.

 

If so, please try to re-map the position and target from viewer's coordinate space to Revit one by multiplying the transform we get from `model.getInverseModelToViewerTransform()` in the viewer.

const state = viewer.getState({ viewport: true });
const model = viewer.getAllModels()[0];
const invTransform = model.getInverseModelToViewerTransform();

const currentTarget = new THREE.Vector3().fromArray( state.viewport.target );
// {x: -14.770469665527344, y: 36.571967124938965, z: -1.212925910949707}

const currentPosition = new THREE.Vector3().fromArray( state.viewport.eye );
// {x: -14.870469093322754, y: 36.57156276702881, z: -1.212925910949707}

const originTarget = currentTarget.clone().applyMatrix4( invTransform );
// {x: -15.02436066552734, y: -8.984211875061035, z: 4.921260089050291}

const originPosition = currentPosition.clone().applyMatrix4( invTransform );
// {x: -15.12436009332275, y: -8.984616232971192, z: 4.921260089050291}

 

And then in Revit,

public void SyncCamera() {
  using(var trans = new Transaction(dbDocument, "Map viewer Camera")) {
    try {
      if (trans.Start() == TransactionStatus.Started) {
        var view3D = activeDbView as View3D;
        // By default, the 3D view uses a default orientation.
        // Change the orientation by creating and setting a ViewOrientation3D 
        var position = new XYZ(-15.02436066552734, -8.984211875061035, 4.921260089050291); ///!<<< viewer camera's position or state.viewport.eye
        var target = new XYZ(12.322365033072593, -154.95122627204464, -37.64853761076602); ///!<<< viewer camera's target or state.viewport.target
        var up = new XYZ(0, 0, 1); ///!<<< viewer camera's up or state.viewport.up
        var fov = 90.68087674208; ///!<<< viewer state.viewport.fov
        var aspectRatio = 0.10000024532334; ///!<<< viewer state.viewport.aspectRatio

        var sightDir = target.Subtract(position).Normalize();
        var right = sightDir.CrossProduct(up);
        var adjustedUp = right.CrossProduct(sightDir);

        var orientation = new ViewOrientation3D(position, adjustedUp, sightDir);
        view3D.SetOrientation(orientation);

        var zoomCorners = this.CalculateZoomCorners(view3D, position, target, fov, aspectRatio);
        var uiView = activeUIDocument.GetOpenUIViews().FirstOrDefault(v => v.ViewId == view3D.Id);
        uiView.ZoomAndCenterRectangle(zoomCorners[0], zoomCorners[1]);

        activeUIDocument.RefreshActiveView();
        activeUIDocument.UpdateAllOpenViews();

        trans.Commit();
      }
    } catch (Exception ex) {
      trans.RollBack();
      TaskDialog.Show("Revit", ex.Message);
    }
  }
}

private XYZ[] CalculateZoomCorners(View3D view, XYZ position, XYZ target, double fov, double aspectRatio) {
  var sightVec = position - target;
  var halfHeight = Math.Tan((fov / 2) * Math.PI / 180) * sightVec.GetLength();
  var halfWidth = halfHeight * aspectRatio;

  var upDirectionVec = sightVec.CrossProduct(view.RightDirection).Normalize() * halfHeight;
  var rightDirectionVecOnNearPlane = sightVec.CrossProduct(upDirectionVec).Normalize() * halfWidth;
  var diagonalVec = upDirectionVec.Add(rightDirectionVecOnNearPlane);

  var corner1 = target.Add(diagonalVec);
  var corner2 = target.Add(diagonalVec.Negate());

  return new XYZ[] {
    corner1,
    corner2
  };
}

 

Cheers,


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

Message 6 of 15

eason.kangEDLV4
Autodesk Support
Autodesk Support
Accepted solution

Hi @ahmedabid933,

 

I haven't had the luck to hear back from you yet. But I updated my sample here. Maybe you can try to see if it works for you.

 

https://github.com/yiskang/aps-viewer-revit-camera-sync

 

Cheers,


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

Message 7 of 15

jeremy_tammik
Alumni
Alumni
Accepted solution

Eason explored further to resolve this and many other aspects and published his results in two blog posts:
  

  

The solution looks very exhaustive indeed. Thank you very much for that, Eason! 
  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 8 of 15

ahmedabid933
Explorer
Explorer

Hi @eason.kangEDLV4 and @jeremy_tammik ,
I want to express my gratitude for your invaluable assistance and support.
I tried the solution and it worked fine. It's really exhaustive.

ahmedabid933_0-1710887139858.pngahmedabid933_1-1710887157050.png

 

Thanks to your expertise and willingness to help, I was able to understand the problem and resolve it.
Thank you very much for your valuable assistance.
Best regards,

0 Likes
Message 9 of 15

eason.kangEDLV4
Autodesk Support
Autodesk Support

It's our great honor to help you with the topic. Thank you very much for your kind testing and good news!

 

I'm also glad to hear my sample and blog posts work for you. 🙂

 

Cheers,

 

 


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 10 of 15

igor.barcelosC54YD
Enthusiast
Enthusiast

Hi Eason, I hope you're doing well. 

 

So I've implemented the full solution as you have documented here : https://github.com/yiskang/aps-viewer-revit-camera-sync

I could notice that there is still some differences between the Revit and Forge cameras, most precisly the distance to the borders.

 

in Revit : 

igorbarcelosC54YD_0-1741793491629.png

 

In Forge : 

 

igorbarcelosC54YD_1-1741793553990.png

 

 

Reading you tutorial, you've written : 

 "As we mentioned in the previous blog post, please be aware that the camera parameters in APS Viewer and Revit are different, so the mapping results would not be perfectly matched."

 

Is that the case ? 

 

 

0 Likes
Message 11 of 15

eason.kangEDLV4
Autodesk Support
Autodesk Support

Hi Igor,

 

Yes, it should be the case because the cameras in Revit and APS Viewer are different. We have only limited ways to control both cameras, so I put the disclaimer there.

 

Sorry for providing  imperfect solution. 

 

Cheers,


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 12 of 15

igor.barcelosC54YD
Enthusiast
Enthusiast

Hi Eason, I hope you're doing well. 

 

I'm still facing some problems when mapping Revit camera's back to Forge. I'm in perspective mode.

The problem is that the zoom in Forge viewer is very different from Revit.

 

I know that there is no perfect solution but I got a felling that the results should not be that bad. 

 

Revit :

igorbarcelosC54YD_0-1751441228958.png

 

Forge :

igorbarcelosC54YD_1-1751441292829.png

 

Any ideias  ?

 

0 Likes
Message 13 of 15

eason.kangEDLV4
Autodesk Support
Autodesk Support

Well ... It's hard to tell without examining the Revit model. It could be case by case. Please consider sharing a non-confidential test model. If your model contains personal or confidential information, please remove it before sharing.

 

If you're a paid ADN member, you can share the test model through the ADN portal (https://aps.autodesk.com/adn) by creating a support case.


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 14 of 15

igor.barcelosC54YD
Enthusiast
Enthusiast

Hi Eason, 

 

Below you can find the Revit file that I've tested.

 

In Revit I have the following camera properties:   

igorbarcelosC54YD_0-1751558425432.png

 

igorbarcelosC54YD_2-1751558508067.png

 

 

In Forge I found this : 

 

igorbarcelosC54YD_3-1751558566242.png

 

As you can see the zoom in Forge is quite different from Revit's. 

What could explain this behaviour ? 

 

 

 

0 Likes
Message 15 of 15

Sleepingfish_Kuo
Advocate
Advocate
IsPerspective: False

When exporting a perspective 3D view in Revit, the camera position and direction are included.
However, when exporting an orthographic view, only the direction is retained, the model size and offset is gone.

0 Likes