Node element not in instance tree - autodesk-forge

I'm trying to hide some elements of a model using the Forge viewer API, but I can't access some of them because their dbIds aren't found in the model instance tree.
It's very strange because I can't hide them using the context menu either, in the properties panel it shows undefined in the name, and it's also not found in the model browser panel.
Any ideas about how can I find those elements and show or hide them programmatically?
In the model that has this problem, those objects are curtain wall profiles.

In the SVF format it's common to have dbIDs without any visual representation. There might be different reasons for that but the one that's most common IMHO is instancing - you can have one object as a "template" (with no geometry), and a couple of objects (with geometries) that are "instances" of that template, inheriting its properties. That is also why the dbIDs of these "template" objects are not found in the model hierarchy.

Related

Apply custom appearance to individual model fragments in forge viewer

In the viewable, the model has three leaf nodes that are named “Solid1” but have a parent name of “Tread”, how do I search by parent name to get the dbId?
Following the answer from Default material for model in Forge Viewer I can see that we can set a color. Is it possible to instead apply a texture?
Thanks!
The Viewer has a search() function so you can search for any component based on its properties. You can then go up and down the instance tree to go from Thread to Solid1 or vice versa. See e.g.
https://forge.autodesk.com/blog/selection-override
Yes, you can also use texture for materials. See e.g. https://github.com/Autodesk-Forge/library-javascript-viewer-extensions/blob/master/src/Autodesk.ADN.Viewing.Extension.Material/Autodesk.ADN.Viewing.Extension.Material.js#L273
That code is used in this sample https://forge-rcdb.autodesk.io/configurator?id=58c7ae474c6d400bfa5aaf37
Just enable the "Material" extension by clicking on it, then you will be able to assign textured materials to faces.

Mouse click vs viewer.select function selection behave differently in Autodesk Forge multi models viewer

I have been working on multi-model from the last couple of weeks and found that selection of a model object using mouse click vs viewer select function behave differently.
I have two models one architectural and another mechanical. When I select a wall or room on the architectural model using mouse click, Object select with overlay without having any problem but when I try using viewer select function with same object, it hides behind the wall and overlay doesn't work. It is only happening with the architectural model and working fine with the mechanical model.
Please suggest me if I am doing something wrong with multi-model.
To programmatically select components when working with multiple models use viewer.select(dbid, model):
let model = viewer.impl.modelQueue().getModels()[index] or viewer.impl.findModel(modelId);
viewer.select(dbid, model)
And to get selected dbids use viewer.getAggregateSelection (see doc here) the event to subscribe to AGGREGATE_SELECTION_CHANGED_EVENT (doc here) to track selection changes:
If the issue persists can you send some screenshots and your models (links via a sharing service like weTransfer/Dropbox) for further investigation over to forge.help#autodesk.com?

Highlighting only the geometry of a parent object in autodesk's online viewer

We have revit model in which a parent element has both children and its own geometry. In the online viewer it is possible to select the parent through clicking the respective geometry, in which case only the geometry for the parent is highlighted. (selected through a click)
If I select the element through the tree the whole model gets highlighted.
(selected through the model browser)
In our web application, we are unable to get the former behavior. When passing the dbId of the parent to viewer.select, the parent plus all the children get highlighted. Same happens when we click the parent element's geometry. How can we select only the parent object programmatically?
We have tried passing different selection modes (overlayed, regular, mixed) to viewer.select but that didn't help and all objects got selected regardless of that parameter.
In this question it is mentioned by autodesk staff that only leaf nodes have geometries. That doesn't seem to be the case here:
Determine if node is an assembly or part in viewer
Thanks for the sample file. I did the following: open the model, select manually and, via console, typed .getSelection(), which returns me the dbId of the selected element. Now unselect everything. Then run .select(2890) and the result is as expected: only the top element is selected (as shown in the image below). I'm using Viewer 3.3.
You can try my sample live here, it uses the Basic Application tutorial.

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.

Bind TreeView.SelectedItem to a property in the ViewModel in a WinRT app

In my Windows Store XAML app I’m using the TreeView control from the WinRTXamlToolkit and I’m attempting to two-way bind the SelectedItem property to a property on a ViewModel.
Out of the box, the SelectedItem property is read only and this makes sense because the control supports Virtualization.
I have seen some folk work around this with things like attached properties, helper methods and so forth, a great example of which is seen in this question
WPF MVVM TreeView SelectedItem
But all of the questions/solutions are not based on WinRT and all of my attempts to rework the solution code for a WinRT app have proven fruitless.
So, my question is, is this possible in a WinRT app? What am I missing?
Thanks
I'd skip trying to come up with a bindable property globally for the view model and instead use the IsSelectedBindingPath and IsExpandedBindingPath properties of the TreeView as in the debugging tools' example of the control's usage. Then when you want to select/expand an item from the view model - use a method similar to SelectItem() in my view model where I essentially set IsExpanded/IsSelected to true in item/node view models throughout the path from the root of the view model tree and load the content of the tree if the nodes in the expected path do not exist.