How to set opacity of each nodes - autodesk-forge

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.

Related

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

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?

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.

Autodesk Forge Viewer: how to set object occlusion

I'm playing around with the Autodesk forge viewer and adding custom elements, like it is done in the Autodesk's scene builder example.
I am looking for a possibility to set the "visibility" of one of the new objects - e.g. when moving around the camera, the green cube should remain on it's 3D-position but should not be occluded by any other object (like it is somehow in blue with outline when it is selected). Or maybe even better: if it is covered by another object, it should shine through (with configurable opacity).
Unfortunately after discussing with Engineering it's not yet possible - will continue the conversation to see if we could come up with a workaround for the upcoming releases ...
Like I suggested in the comments try append your geometry to Viewer3DImpl.sceneAfter for the time being (which will be publicly documented and exposed as Viewer3D.sceneAfter in a couple of weeks) or an overlay. Then setting depthTest to false should do what you want...
The choice of sceneAfter or an overlay depends on how you want the objects to be drawn during progressive rendering. sceneAfter is only drawn once at the end of everything else. Overlays are redrawn for each progressive frame...

Cloning a viewer material

I want to override the color of a component in the viewer, in order to conserve the same rendering effect than other components I would like to clone an existing material and simply modify the color of the clone.
I can change the color of an existing material as follow:
var renderProxy =
viewer.impl.getRenderProxy(
model, fragIds[0])
renderProxy.material.setHex(0xFF0000)
This affects all other components in the model which are using that material, which is not the desired result.
For that purpose I would like to clone material, modify it and affect the new material to a specific component. Invoking the material.clone() method is working:
var newMat = renderProxy.material.clone()
newMat.setHex(0xFF0000)
But the new material will loose all the specific properties that makes it look nice by the renderer.
So my question "is there a way to -easily- clone a viewer material without writing the cloning code for each property"?
You will need to clone the 'prism' material, rather than the 3js phong-material.
Start with this repo: https://github.com/wallabyway/fusion-chair-configurator
as an example, to create a 'metal' material, use these two lines of code (and copy the initPaint() function).
https://github.com/wallabyway/fusion-chair-configurator/blob/c6d5bd575cdf40194c9fbdd1c5f9bb27c70b356e/docs/js/app.js#L107-L108
The szPrism json string, contains lots of parameters. Prism materials are rather complex, but you can find out more about what these parameters do by understanding this article for the Autodesk Cloud Render ART help page (the real-time renderer built inside Revit2019, Fusion360, etc)...
http://help.autodesk.com/view/ARENDERING/ENU/?guid=GUID-49345267-CE6A-4006-BB58-5BEAFD8B0D0E
Try experimenting with Fusion360's 'render' mode. Start by opening 'appearance' and creating some custom materials. You can modify their parameters in real-time to better understand what they do and get the effect you are looking for.
Here is a tutorial video on Fusion360 custom materials: https://www.youtube.com/watch?v=D9AS5rQhtPo
Let me know if that helps.

Forge viewer: Auto-start animation

We would like to trigger/auto-start an animation/simulation of a specific object (Revit ElementID) when the model loads in the Forge viewer. The goal would be to move a cube (Revit ElementID) back and forth on the floor in a repeating loop. Would this be possible using any relevant extension or code?
Yes it is possible but there is no built-in extension you can use out of the box. The animation logic has to be a custom implementation.
From a given ElementId/UniqueId you need to find the corresponding dbId, see that reply for a starting point on how to do that.
From a given dbId, you can obtain fragmentIds and use those to apply transforms to the components in the viewer. The animation logic has to be by your own application. You can refer to that article How to create animations in the viewer? or one of the several demos I wrote performing animations:
Kinematics - source
Physics - source
You can use the Autodesk.Viewing.GEOMETRY_LOADED_EVENT and Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT to trigger the animation logic, so you can make sure the model is fully loaded. See also that article: Asynchronous viewer events notification.
Hope that helps.