Models created with `SceneBuilder` in `AggregatedView` disappear/reappear on rotate/zoom when loaded in combination with larger models - autodesk-forge

Custom objects disappear on every orbit zoom or rotation for about one second, then reappear again when added to a aggregated view in combination with a large model. While the objects are hidden, I can see that there is some reloading/rerendering of the other unrelated model going on.
Overlays (meshes rendered directly into threejs) obviously don't show this behavior.
I'm using viewer version 7.85 and the sample code from here: https://aps.autodesk.com/blog/custom-models-forge-viewer
modelBuilder.addFragment(sphereGeometry, sphereMaterial, sphereTransform);
Is there any way I can prioritize rendering of my custom model or disconnect the rendering from other loaded models?

Related

WebGL with Viewer - Can't use multiple render targets. Falling back to two passes

How it is reproduced:
I go to the page where the viewer is used. Let's say, while waiting for it to fully load (it doesn't matter), there is no error in the console. Next, I go to another page on the site where the viewer is used.
When I load the page, an error appears in the console(attach a screenshot). After that, if I try to draw the model in the viewer, the viewer does not draw the model completely. And the viewer does not allow you to work with elements (for example, selection).
As a result of what could this error appear?
I didn't do anything special with the initialization of the viewer
Viewer verssion - 7.65
It is definitely possible to run the viewer in multiple browsers/tabs at the same time. Each tab should be using its own GPU context. I just tried loading the following URLs in different browsers at the same time, and all the viewers are rendering the models correctly:
https://forge-basic-app.herokuapp.com/#dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Zm9yZ2UtYmFzaWMtYXBwLWJ1Y2tldC9yYWNfYWR2YW5jZWRfc2FtcGxlX3Byb2plY3QucnZ0
https://forge-basic-app.herokuapp.com/#dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Zm9yZ2UtYmFzaWMtYXBwLWJ1Y2tldC9TcG9ydHMlMjBDYXIuZHdmeA
Are you seeing this issue with any Forge app (like the one I linked to), or just with your own one? And have you tried other browsers and other devices? It could also be hardware-related. Perhaps your hardware has fewer resources, and when one of the browser tabs loses context, the viewer cannot recover from that?

How to make sure the building is loaded in the right orientation?

I use the grid on the scene. The Building A (first image) setup is to be expected. But when I uploaded Building B, the orientation didn't match. Do I have to set it up in Revit ? or can I do it programatically.
Every model you load into the viewer is coming with its own metadata such as:
what is the "up" direction of the model
what is the offset of the model from the origin
what units is the model defined in
By default the viewer honors all these settings which means that, for example, if you load a Revit model that is defined in feet (and uses the Z-axis as the "up" direction), and then an Inventor model that is defined in meters (and uses the Y-axis as the "up" direction), the two models will have different scale and orientation.
To work around this issue, when loading (aggregating) multiple models in Forge Viewer, you can override any unit scaling, offset, or general 4x4 transformation that is applied to each model. For more details, look at https://forge.autodesk.com/blog/multi-model-refresher.

Forge viewer Display anomaly

I have a situation where two construction models are loaded in the viewer.
The stair model is moved (whith placement transform) in the building model.
The stair model is now obscured by the building model also behind glass elements
see this gif
Depending on the camera position the stair is visible again.
Viewer is 7.38.1
Typically, when a model is loaded, the opaque objects are rendered first and the transparent objects are rendered last. If you are loading the first model which contains the transparent objects and then the stair model, the transparent objects might be rendering before the stair model. This might be causing this issue.
I would suggest trying the following: load the stair model first and then the model with the transparent objects. If the above statement is correct, this might fix the issue.
In any case, It would be useful to get the repro steps for this and maybe the model assets.
Last, are you using AggregatedView or are you loading the models using Viewer3D#loadModel?
We logged the issue as LMV-5962

How to make selection work for 2D multi-models in Autodesk-Forge Viewer

I have a couple of DWG drawings which I have converted into F2D files for offline viewing.
There is a base model which I load on the viewer initialization. Other drawings are loaded using viewer.loadModel as in when required.
These drawings get loaded fine. The problem is that it messes up the selection. Only one of the loaded models gets selected (and gets highlighted) on mouse down.
When I check the selection on the event received in AggregateSelectionChangedEvent, the selection has only the first model. So, I cannot even distinguish the model which has been selected.
Since some of the drawings can be loaded multiple times, (Consider a car drawing where one can load same wheel drawing and place at 4 positions) the dbId of the selected entity is same for multiple models. So, dbId can not be used as the only parameter. What I need is dbId + model.id combination to tell the selected object apart.
As per the suggestion received from elsewhere, I was setting
renderer.settings.numIdTargets = 2.
This made the selection work for multi-model pretty much as normal selection.
It worked a while, then suddenly stopped working. I am not able to figure out why.
Can anyone suggest a lasting solution to this problem?

How to set opacity of each nodes

Is there anyway to set opacity of some nodes of the model?
For instance, create a override material and use it in renderer for some nodes rather than whole scene.
When loading a model, the viewer builds its internal spatial indexing structures (BVHs), and one of the factors it takes into account is the transparency of the different fragments. This is in order to ensure that semi-transparent objects are rendered after the opaque ones.
However, when changing the material of a fragment on-the-fly (after initial load of your model), the order is not updated because the viewer doesn't have a way to rebuild the BVHs on demand, and you can end up with something like opaque objects hidden by transparent ones ... We have a pending change request in order to add an API that would allow developers to rebuild BVHs, unfortunately it has not yet been added yet.
You may take a look at the following resources for example of modifying materials in the viewer:
Autodesk.ADN.Viewing.Extension.Material
Forge Viewer Custom Shaders - Part 1
Forge Viewer Custom Shaders - Part 2
Custom transparent meshes with View & Data API
Hope that helps
Yes, sure.
The ForgeFader app creates and sets override materials on certain nodes in the viewer:
Check it out in:
src/client/viewer.components/Viewing.Extension.Fader/Viewing.Extension.Fader.Core.js.