I'm developing a configurator and to view our 3D model I'm using the Autodesk Viewer.
It is sometimes a bit laggy/slow so I wanted to experiment hosting the models myself to see if this improves loading speed. I found the example https://github.com/Autodesk-Forge/viewer-javascript-offline.sample/tree/gh-pages here and after adapting this I can succesfully load my model from the public directory.
However, I am only able to set the model on initialization of the viewer. I would like to load the models dynamically from a react app.
I adapted the react wrapper from here: https://github.com/autodesk-platform-services/viewer-react-sample/blob/master/src/components/Viewer.jsx
But loading the model only works when I load it in the initialization:
this.viewer = new Autodesk.Viewing.Viewer3D(this.container);
this.viewer.start(this.props.path);
Is it possible to dynamically load nodes/models in the same manner as when fetching the models from the app OSS? Below does not load the model. Eventually I would like to try to load the models from my own server i.c.m. the AggregatedView / Loading multiple models.
onDocumentLoadSuccess(doc) {
this.viewer.loadDocumentNode(doc, doc.getRoot().getDefaultGeometry()),
console.log('loaded document node')
}
updateViewerState(prevProps) {
if (this.props.path && this.props.path !== prevProps.path) {
Autodesk.Viewing.Document.load(this.props.path, (doc) =>
onDocumentLoadSuccess(),
// failure
(code, message, errors) => console.error(code, message, errors),
);
}
else if (!this.props.path && this.viewer.model) {
this.viewer.unloadModel(this.viewer.model);
}
}
Document.load()
you have to pass in a URN or the URL to a bubble.json
file.loadModel()
(that Viewer.start()
uses as well) you have to pass in a URN or the URL to a *.svf
file. This is what you'd need to use.Further info that still seems more or less correct: https://stackoverflow.com/a/39758123/4654233