I am currently working with Hoops Communicator and have successfully loaded a primary model (model1.scz) into the scene using the WebViewer as follows:
javascript
Copy code
let params = {
containerId: "divId",
streamMode: window.Communicator.StreamingMode.All,
rendererType: window.Communicator.RendererType.Client,
streamCutoffScale: streamCutoffScale,
endpointUri: uri,
boundingPreviewMode: Communicator.BoundingPreviewMode.None,
model: 'model1.scz'
};
let _viewer = new window.Communicator.WebViewer(params);
_viewer.start();
I would like to load an additional model (model2.scz) into the same scene without replacing the primary model. Could you guide me on the best way to achieve this?
We would expect your call to load the second model (model2.scz) to succeed provided that the model is accessible and configured as such in the server. For example, if the second model is in the same directory as the first model (model1.scz), it should load in the viewer.
It looks like you are taking the substring of filepath as the model name to load. Provided that the model name is correct and the directory to that model is properly set up in the server configuration, your call to loadSubtreeFromModel should work.
Are you getting any errors in the web browser console?
The exception Incompatible load types indicates that you are loading a Stream Cache model into an existing non-streaming session designed for loading SCS files. You can do one of the following options:
Call the function loadSubtreeFromScsFile instead of loadSubtreeFromModel, for example, hwv.model.loadSubtreeFromScsFile(nodeId, "modelName.scs");
OR launch a streaming session in the Web Viewer so that you can still use loadSubtreeFromModel
Apologies for reviving this thread, but I had a similar issue and wanted to share how I solved it.
I am getting the same error and config as @nivedita.srivastava when I create the WebViewer without passing a model name in. However, if I pass a model name in (i.e. load a streaming model when WebViewer is created) I can use loadSubtreeFromModel().
It appears to me that if the WebViewer is not created with a model, the streaming setting does not take hold properly even though streamingMode is set.
This example does not work:
window.onload = function () {
let server = new ServerConnection("http://localhost:11182");
server.connect().then(async function () {
const hwv = new Communicator.WebViewer({
containerId: "myContainer",
enginePath: "./",
endpointUri: server._endpointuri
});
hwv.setCallbacks({
modelStructureReady: () => {
var rootid = hwv.model.getAbsoluteRootNode();
var nodeid = hwv.model.createNode(rootid, "Another Model");
hwv.model.loadSubtreeFromModel(nodeid, "anotherModel");
}
})
await hwv.start();
})
}
But this does:
window.onload = function () {
let server = new ServerConnection("http://localhost:11182");
server.connect().then(async function () {
const hwv = new Communicator.WebViewer({
containerId: "myContainer",
enginePath: "./",
endpointUri: server._endpointuri,
model: "FirstModel" // Only change, added a model at start
});
hwv.setCallbacks({
modelStructureReady: () => {
var rootid = hwv.model.getAbsoluteRootNode();
var nodeid = hwv.model.createNode(rootid, "Another Model");
hwv.model.loadSubtreeFromModel(nodeid, "anotherModel");
}
})
await hwv.start();
})
}