Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revit DirectContext3d preview server #13

Open
wants to merge 2 commits into
base: reope/performance-base
Choose a base branch
from

Conversation

bendikberg
Copy link
Collaborator

@bendikberg bendikberg commented Oct 31, 2024

Purpose

This PR adds replaces the current Dynamo preview inside the Revit viewport.

Explanation

The current implementation uses the SetForTransientDisplay method, which modifies the active document, and requires native Revit geometry to display content. This method is slow due the fact that all the preview objects in Dynamo have to be converted to Revit geometry, which then has to be inserted into the document for display purposes. The resulting display geometry is visible in Revit, but does not react to any sort of user input, and has a big impact on the viewport performance in Revit in cases where a lot of Dynamo geometry is being displayed.

The new method implements IDirectContext3DServer instead, which lets Revit display any mesh, line or point geometry without having to interact with the document at all. By not using SetForTransientDisplay, it is able to skip the step of converting from Dynamo to Revit geometry, which is a big time saver. The preview server implementation is also flexible enough to be styled by Dynamo, so that the preview geometry can be visually distinct depeneing on node state, meaning selections can be shown in Revit as well.

By using the preview server to display custom mesh and line geometry, instead of native Revit geometry, we can use an IRenderPackage to display geometry instead, since this is cheaper to create from DesignScript geometry. Since the Helix 3d view already creates it's own render packages which already contain the geometry we are interested in, we can entirely skip creating our own preview geometry for Revit display purposes. This means the Revit preview goes from taking a substantial amount of time in a graph execution to being essentially free, and more featureful.

From testing with a large amount of objects, specifically a scene where Dynamo has to draw 125 000 separate objects, the current implementation takes about 12 minutes on my computer, where about 8 minutes is spent creating the transient display geometry and setting up Revit. The viewport then becomes unresponsive and sluggish due to the amount of native Revit geometry it has to display, which makes it all unusable. In the scene, my computer ends up using around 20 GB of memory in total.

In contrast, the preview server implmentation spends about 4 minutes creating the same scene, where about 1 minute is spent in graph execution and the rest is spent creating Helix render packages from the scene geometry. This is also where the remaining time is spent in the other example with the Transient Display method. Since Helix has already done the hard work of creating the display geometry, the preview server spends somewhere between 5 and 10 seconds creating display geometry and updating the Revit viewport, meaning it is essentially free. The result is a viewport display which is much snappier and a lower memory footprint, at around 17 GB on my computer. This is also likely due to a bit of geometry caching, which could likely be reduced further.

Media

Dynamo scene
RnClEDCBqV

Transient display demo
https://github.com/user-attachments/assets/c6f71807-5dc1-4c98-8930-b8dfb027b638

Preview server demo
https://github.com/user-attachments/assets/fbbf4438-1379-4691-907e-5e825f2ca20d

Selection demo
https://github.com/user-attachments/assets/5350cc0b-ff69-494e-9d84-3d847be8eb1d

Declarations

Check these if you believe they are true

  • The code base is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • Snapshot of UI changes, if any.

Reviewers

(FILL ME IN) Reviewer 1 (If possible, assign the Reviewer for the PR)

(FILL ME IN, optional) Any additional notes to reviewers or testers.

FYIs

(FILL ME IN, Optional) Names of anyone else you wish to be notified of

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant