Reputation: 117
I'm using the Forge Viewer to display simple geometry extractions from buildings. However, when loading them the orientation of the model/view cube is not matching the expected use case (see image). Basically I would need to swap the "Front View" with the "Top View". Is this possible to achieve such a thing through e.g. default settings on the viewer object?
My set up is basically identical to the one in this 3rd-party react wrapper of the Forge Viewer: https://github.com/outer-labs/react-forge-viewer
Thank you already very much.
Daniel
EDIT: The model is in STP format
Upvotes: 1
Views: 1165
Reputation: 7070
Basically, you can archive this with following steps via Viewer APIs after the model is loaded completely and can be separated into two parts.
(Preproccess) Get the Front
view state of the Viewer that your want to make it as the Top
:
a. Orient the current view to Front
view: viewer.setViewCube( 'front' )
.
b. Obtain current view statue of the viewport: var viewState = .getState( { viewport: true } )
.
c. Save this viewState
to somewhere, your js file or database.
Restore view state and set it as the Top
view:
a. Obtain the viewState
from somewhere (e.g. js file or database) that you got from the step1.
b. Restore view state via viewer.restoreState( viewState )
.
c. Set the current view as Top
view: viewer.autocam.setCurrentViewAsTop()
.
d. Set the current view as Home to avoid the state of the viewcube to be reset: viewer.autocam.setCurrentViewAsHome()
.
The code snippet for step2:
viewer.addEventListener(
Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
function( event ) {
console.log( '%cGEOMETRY_LOADED_EVENT: !!!Geometries loaded!!!', 'color: green;' );
setTimeout(() => {
const onOrientTopViewCompleted = function() {
viewer.removeEventListener(
Autodesk.Viewing.CAMERA_TRANSITION_COMPLETED,
onOrientTopViewCompleted
);
viewer.autocam.setCurrentViewAsTop();
viewer.autocam.setCurrentViewAsHome();
console.log( 'CAMERA_TRANSITION_COMPLETED' );
};
viewer.addEventListener(
Autodesk.Viewing.CAMERA_TRANSITION_COMPLETED,
onOrientTopViewCompleted
);
var viewState = '....'; //!<< the view state of the original `Front` view.
viewer.restoreState( viewState )
}, 1000);
});
Hope it helps!
Upvotes: 2