Load model by headless viewer - autodesk-forge

I have tried setting up Forge Viewer in headless mode using the following link: https://forge.autodesk.com/en/docs/viewer/v6/tutorials/headless.
I have hard-coded the URN and the access token but the model is not displaying.
Please provide any sample source code to load the model.

Here's a couple of tips:
Check the browser console. Perhaps the URN or the access token is incorrect, which is why the model does not load.
The link you're working with is for an older version of Forge Viewer (v6). I'd suggest using version 7.*. Try using this basic app as a starting point: https://github.com/petrbroz/forge-basic-app, and replace this line of code:
const viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('preview'));
with
const viewer = new Autodesk.Viewing.Viewer3D(document.getElementById('preview'));
With this I've been able to load a model with a headless viewer:

Related

Extension Autodesk Forge: My IFC 4 model can not connect to my extension

I uploaded my IFC version 4 to Autodesk forge and then added my extension, unfortunately, my control panel can not work and connect to my model.
Also, I had this problem with the Revit model but solved it with a solution from Mr. Petr Broz.
Please check this (Extension Autodesk Forge: My control panel doesn't connect to the Revit model after adding my own extension to the package).
unfortunately, the solution for the Revit model doesn't work for the IFC4 model.
Would you please Guide me on how I can solve it?
I cannot see the full extension code from the thread you pointed out, but this problem should not be related to IFC4.
From your code snippet, I can see that there is a great possibility that thesetTransformation function would be called before the geometries are loaded completely. Before completely loaded geometries, fragment info like transform matrix, bounding box, and so on would not be completed. Therefore, I would advise you to setTransformation function after Autodesk.Viewing.GEOMETRY_LOADED_EVENT is triggered to avoid this problem.
if(model.isLoadDone() ) {
viewer.addEventListner(
`Autodesk.Viewing.GEOMETRY_LOADED_EVENT`,
() => {
this.setTransformation();
}, { once: true }); //!<<< run this even handler once
} else {
this.setTransformation();
}
Or call the async function viewer.waitForLoadDone() before calling setTransformation function to ensure geometries are loaded completely.
await viewer.waitForLoadDone();
this.setTransformation();

How to view local drawing DWF file with correct font?

I am trying to view local dwf files in browser using forge viewer.
I followed this: https://aps.autodesk.com/blog/dwf-and-pdf-support-forge-viewer
example to load local dwf file into the viewer.
let option = { env: "Local" };
Autodesk.Viewing.Initializer(option, async function () {
const viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer'));
viewer.start();
viewer.setTheme('dark-theme');
viewer.loadExtension('Autodesk.DWF').then(() => {
console.log("Extension Loaded")
console.log(path);
try {
viewer.loadModel(virtualPath + path);
} catch (e) {
console.log(e)
alert("Nepodařilo se načíst požadovaný soubor!")
}
});
});
But there is a problem with font:
forge-viewer-result
When I view the same file with "Autodesk Design Review" the font is correct:
design-review-result
Detailed problems I have in my implementation of Forge Viewer:
It is not the correct ISOCPEUR and it does not support characters with diacritics.
Also it uses blue background and looks different compared to other Autodesk viewing apps I have seen. (Vault Thin Client, DR)
The image (company logo) is blurred
Am I missing some sort of setting to the viewer?
I don't think you're missing any settings. The native DWF loading in JavaScript is a relatively new feature, and there may be areas that require some polishing. If you wouldn't mind sharing one of the DWFs with us (confidentially via forge (dot) help (at) autodesk (dot) com; the file would not be shared with anyone outside of Autodesk), we can ask the viewer engineering team to look at it.
In the meantime, have you tried converting the DWF into the viewer format using the Model Derivative service? While this operation has some cost (0.1 flex tokens per DWF), it uses AutoCAD to process the DWF, so it is generally more robust.

Autodesk Forge Viewer - GLTF Extension

I am trying to use GLTF extension in forge viewer and open a gltf file by using this extension, but I am getting the error, "The item you are trying to view was not processed completely."
I have tried to run below code, but it is not working properly.
viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById(divId),config3d);
viewer.start();
viewer.setTheme('light-theme');
viewer.loadExtension('Autodesk.glTF');
viewer.loadModel('./belediye.gltf');
Loading Forge extension is an async task, we need to use Promise.then or await to make sure the GLTF extension is loaded.
viewer.loadExtension('Autodesk.glTF').then(() => {
viewer.loadModel('./belediye.gltf');
});
//or
await viewer.loadExtension('Autodesk.glTF');
viewer.loadModel('./belediye.gltf');

How to load propertyDb for f2d files in local environment

I am using Forge extractor in order to translate model into SVF format and load them in the local environment using Forge Viewer v7. I've selected both 3D Views and 2D Floor Plans from Revit for translation and I can see that they are converted successfully.
I am loading the 3D view using this method:
Autodesk.Viewing.Initializer(options, function () {
viewer.start("Resource/3D View/{3D} xxxxxx/{3D}.svf", options);
I can see that the properties for the elements can be loaded succesfully and I can view the properties/attributes for this element using the Properties Panel.
However, when I am loading a 2D Floor plan (f2d) file using this method:
Autodesk.Viewing.Initializer(options, function () {
viewer.start("2c627223-65bc-e4f4-6518-dda3dc1960dc_f2d/primaryGraphics.f2d", options);
The properties for elements can not be displayed correctly.
May I know is there a way to also display properties for objects in 2D Floor Plan? Thanks!
Unfortunately that extractor has been officially retired recently so we would not be supporting it going forward ...
Try other tools like this, this and this etc to download the SVFs
Coming back to the issues you were experiencing - apparently the property db was not loaded ... see your console output and check for any 404 errors for getting object*.json - these files are the property db...:
attrs: [path + "objects_attrs.json.gz"],
values: [path + "objects_vals.json.gz"],
avs: [path + "objects_avs.json.gz"],
offsets: [path + "objects_offs.json.gz"],
ids: [path + "objects_ids.json.gz"]
Once you use a tool that downloads all the dependencies for f2d derivatives properly or implement the process correctly yourself then everything would be functioning properly again ...

How to load otg from Bim360?

I would like to to read my bim360 models which is in otg format in my Forgeviewer (version 7.3). The projects have been converted using the https://otg-bim.herokuapp.com/ app.
Is there any guidelines of how to make my Forge viewer read otg format from Bim360? I found this guideline (https://github.com/wallabyway/OTG-client-sample/blob/552c78b1fe8e1177f6694fd947a17fd189a8505b/public/js/ForgeViewer.js#L26-L29), however it uses Autodesk.Viewing.ViewingApplication which I find in version 2 of the Forge API, but not in version 7.3.
You can use this version of the ForgeViewer.js to work with latest versions of the viewer. https://github.com/jaimerosales/OTG-client-sample/blob/master/public/js/ForgeViewer.js
It seems that it is the same svn. Fault was that options requires autorization, even though I am allready autorized through bim360 login. Providing the access token there, uncomment useCookie and useCrentials and it works.
const options = {
env: 'FluentProduction',
api: 'fluent',
//useCookie: false,
//useCredentials: false,
accessToken: "add access token even though you are allready authorized in in bim360"
};
So far, I have seen a significant improvement loading using otg :-).
The latest version of svf2 works fine when using buckets instead of bim360. I have not vertified it with bim360. Example code which was helpfull for me was this npm package. https://www.npmjs.com/package/ng2-adsk-forge-viewer