I’m trying to implement a viewer able to load several GLTF models and add/remove them into scene.
The KHR_interactivity only works when assets are immediately loaded into scene, but not when they’re loaded into AssetContainer and then added to scene.
Apparently, that’s because extension’s KHR_interactivity.onReady immediately creates and starts FlowGraphCoordinator even before assets are actually added into scene.
Thanks for the report! We will investigate this when we work on the interactivity implementation in a few weeks. Let us know if this is urgent for you for some reason.
Ok, i see the problem: the FlowGraphs cannot be deactivated, but only disposed.
So they should be recreated every time corresponding assets are added to the scene.
That seems like a big mess when assets are added individually.
Anyway, I’d suggest some API similar to the KHR_materials_variants.
At least it should work fine when gltf models are added/removed in whole.
interface FlowGraphController {
activate(); // or something
deactivate();
}
async function LoadMyModel(url) {
const model = new MyModel(); // extends AbstractAssetContainer or something
const options = deepMerge(GLTFOPTIONS, {
extensionOptions: {
KHR_materials_variants: {
onLoaded: (ctrl: MaterialVariantsController) => model.materialCtrl = ctrl
},
KHR_interactivity: {
onLoaded: (ctrl: FlowGraphController) => model.flowCtrl = ctrl
}
},
});
...
}
function attachMyModel(model: MyModel) {
model.addAllToScene();
model.flowCtrl.activate();
}
function detachMyModel(model: MyModel) {
model.flowCtrl.deactivate();
model.removeAllFromScene();
}