Forge Viewer loading multiple Revit models with shared coordinates - autodesk-forge

When loading Revit models which are aligned by shared coordinates, the models does not align in Forge Viewer with globallOffset settings.
The loadModel with placementTransform option seems to be viable, but the shared coordinates data is not made available until after the model is loaded, via viewer.model.getDocumentNode().getAecModelData().refPointTransformation
earliest I have the model data is inside the onLoadModelSuccess which is too late to feed into the load options, and will require to transform the geometries.
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath(),
globalOffset: offset,
placementTranform: ???,
isAEC: true
};
viewer.loadModel(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
How would it be possible to align the models otherwise? Or maybe to load the model without rendering the geometry first to get the data then feed the transform matrix into another loadModel call?

Use the following two options together to apply Revit shared coords:
globalOffset - tells LMV not to auto centre model
applyRefPoint - tells LMV how to apply any svf positioning meta-data for Revit files
So try the below in your load options:
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath(),
globalOffset: offset,
applyRefPoint: true,
isAEC: true
};
And see this live sample here for usage reference on the placementTranform option.

Related

Loading geoJSON to Cesium does not work but I get no errors

I try to pass data from PostGIS to Cesium, I believe the simpler way is to use GeoJSON.
To test it I do a query to my PostGIS to get some geoJSON data
SELECT ST_AsGeoJSON(mygeom)
FROM mytable where id = 370;
then I copy the result to a cesium sandcastle to see how it works
var viewer = new Cesium.Viewer('cesiumContainer');
const greenPolygon = viewer.entities.add({
name: "Green extruded polygon",
polygon: {
hierarchy : Cesium.GeoJsonDataSource.load({"type":"MultiPolygon","coordinates":[[[[386788.842267334,4204512.29371444],[386804.47751787,4204512.29371444],[386804.47751787,4204510.66293459],[386788.854170836,4204510.66293459],[386788.842267334,4204512.29371444]]]]}),
extrudedHeight: 100000.0,
material: Cesium.Color.YELLOW.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.BLACK,
closeTop: true,
closeBottom: true
},
});
viewer.zoomTo(viewer.entities);
I get no errors in the cesium sandcastle console, but I also see no polygon on the map. The geometry in my PostGIS table is geometry(MultiPolygon,2100), I dont know if this is the issue.
Please advice
Thanks
CesiumJS will not understand your coordinates(ex 386788.842267334,4204512.29371444) defined in your custom spatial reference system.
You must specify coordinates using geographic latitude, and longitude.

AutoDesk Forge Viewer : Load Model Using the URN of SVF

Is it possible or there is any way to load Model through URN instead of URL.
we can load the model through URL :
this.viewer.loadModel(url, options) -> Here i know the url of the SVF
Is there any possibility to load the model using the URN, But in my case I know only URN of the svf.
In regular way,
We are loading the document using the URN of the uploaded file, on Document load success then we are loading the viewables.
var documentId = 'urn:dXJuOmFkc2sub2JqZ3Q6cGxuLW1vZGVN0L0NhZGFjR3JvdXBIUSUyMDIwMTkucnZ0';
Autodesk.Viewing.Initializer(options, function onInitialized(){
viewerApp = new Autodesk.Viewing.ViewingApplication('MyViewerDiv');
viewerApp.registerViewer(viewerApp.k3D, Autodesk.Viewing.Private.GuiViewer3D);
viewerApp.loadDocument(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});
function onDocumentLoadSuccess(doc) {
var viewables = viewerApp.bubble.search({type:'geometry', role:'3d',name:'blahblah'});
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
// Choose any of the avialble viewables
console.log(viewables[0].data);
console.log(doc.getViewablePath(viewables[0].data));
viewerApp.selectItem(viewables[0].data, onItemLoadSuccess, onItemLoadFail);
}
From above code, based on the URN of the uploaded OBJ, it is getting the manifest and loading the viewable, But In our scenario, we are doing that part at server side and getting the URN of the SVF.
But in our scenario, We have the URN of the SVF file. Is there any way to load the Model Using SVF URN.
I saw one possiblity is that appending
"https://developer.api.autodesk.com/derivativeservice/v2/derivatives/"
to my urn and calling the
viewer.loadModel(url)
Is loading the Model, But it is again a maintenance work, When there is a change in that URL from forge side we need to update it again.
Is there anyway from javascript to get the path of the model based on the URN?
To load by URN of the SVF simply pass in its, with the rest of your Viewer's environment kept the same as you would for URN of the document:
// get the URN of the SVF from the manifest, e.g. `urn%3Aadsk.viewing%3Afs.file%3AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c2JzYjIzMzMzL3NiYmJiYmIuZHdn%2Foutput%2F3a65ae5a-804e-b91b-11d1-5bc44f41866f_f2d%2F3d.svf`
Autodesk.Viewing.Initializer({
'env' : 'AutodeskProduction', getAccessToken: onGetAccessToken
}, function onInitialized(){
//...
viewer.start();
viewer.loadModel('https://developer.api.autodesk.com/derivativeservice/v2/derivatives/urn%3Aadsk.viewing%3Afs.file%3AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c2JzYjIzMzMzL3NiYmJiYmIuZHdn%2Foutput%2F3a65ae5a-804e-b91b-11d1-5bc44f41866f_f2d%2F3d.svf')
});
BTW the viewerApplication API has been deprecated as of v7 so I'd recommend to follow this migration guide here to upgrade to v7 in order to get all those new features and fixes ...

How to get AEC model data in autodesk forge?

I want to add new Autodesk Forge Minimap3DExtension to my forge viewer, but i can't get AECModelData with doc.downloadAecModelData().
I try to get data with this code is it right?
var viewables = viewerApp1.bubble.search({'type':'geometry'});
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
//explicitly call downloadAecModelData of viewer document.
doc.downloadAecModelData()
}````
I also try to get data with bubbleNode, but got only errors.
Only RVT files from Revit 2018 and later will produce the AecModelData. Please check your RVT file version. If it is supported, you can use either way below to get AecModelData
// From document
await doc.downloadAecModelData()
// From bubble
await Autodesk.Viewing.Document.getAecModelData(viewer.model.getDocumentNode())

Viewing Revit Drafting Views with the Forge API's

It seems to be possible to view and navigate Revit Drafting View(s) graphics using the Forge API's based on how the BIM 360 Document Management web browser interface does it with our own Revit (.rvt) model having published Drafting Views where it list the 2D Drafting Views (thumbnails) in the left panel and the actual detail of the selected Drafting View in the right viewer. We do have one of the more recent Forge API Viewer examples setup and working, and tried modifying some of its code, but is seems to be designed to only work with Models (.rvt) components in the left panel, and its not obvious where and what code needs to be modify to change it to list 2D sheets/views like the Document Manager does. We are having difficulty locating a Forge API example that shows how to do this using the Forge API's and would like to obtain a working example that illustrates how to do this using the Forge API's?
Tried changing the ViewingApplication.bubble.search to include role 2d type view
function onDocumentLoadSuccess(doc) {
// We could still make use of Document.getSubItemsWithProperties()
// However, when using a ViewingApplication, we have access to the
*bubble** attribute,
// which references the root node of a graph that wraps each object from the Manifest JSON.
//var viewables = viewerApp.bubble.search({ 'type': 'geometry' });
var viewables = viewerApp.bubble.search({ 'role': '2d', 'type': 'view' });
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
The drafting view is kind of 2d role geometry, Therefore you can load it with the same way for the 2D view.
const rootItem = doc.getRoot();
const filter = { type: 'geometry', role: '2d' };
const viewables = rootItem.search( filter );
if( viewables.length === 0 ) {
return onLoadModelError( 'Document contains no viewables.' );
}
// Take the first viewable out as the loading target
const initialViewable = viewables[0];
const loadOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath()
};
viewer.loadDocumentNode(doc, initialViewable.data, modelOptions).then(onItemLoadSuccess).catch(onItemLoadFail);
To show a list of views like the BIM360 Docs, you could load Autodesk.DocumentBrowser extension. It will show viewable items on it, and just click on it to switch. See below snapshot:

Unable to retrieve frag IDs in autodesk forge viewer

I am currently looking at trying to get a very simple solution working as a proof of concept before going any further with forge. I have gone through the basic application quick start guide and the basic extension guide and the viewer it self works perfectly with a file I created using Autodesk pipe 3D (tried both as a dwg file and a dwfx).
All I am trying to do is change the colour of the model, all the guides I could find all use similar methods but they all require you to get the list of FragIDs to apply a material
var it = viewer.model.getData().instanceTree;
var allDbIds = Object.keys(it.nodeAccess.dbIdToIndex);
for (var i=0; i<allDbIds.length; i++) {
var dbid = allDbIds[i];
var fragIds = []
try {
it.enumNodeFragments(dbid, function(fragId){
fragIds.push(fragId)
})
}catch(error) {
console.error(error);
}
fragIds.forEach(function(fragId) {
//code to actually change colour
})
It manages to get the dbid fine and brings back many however when it tries to get the frag ids it doesnt bring back anything. It does not break it just brings back nothing but am having trouble finding where to actually look in to why or where to even start
First thing would be to define the fragIds array outside of the for loop, so it's not getting overridden at each iteration.
You can use the following code to set a specific material to a fragId:
fragIds.forEach((fragId) => {
model.getFragmentList().setMaterial(
fragId, material)
})
Take a look at this thread for more info how the topic:
Forge Viewer THREE.MeshLambertMaterial