engine
engine copied to clipboard
Add glTF extension registry
Right now, all glTF extensions are processed in glb-parser.js.
It would be great to have something like extension registry. So, an extension parser can register callbacks in extension registry. And then these callbacks would be passed into ContainerHandler.
WHY?
- It can help to split glb-parser.js to different files with different parsers.
- It would make easier to develop new extensions and parsers.
So, extension parser could be written like this:
class NodeExtension {
name = "COMPANY_node_extension";
register(registry) {
// Register parser on "node" resource
registry.node.add(this);
}
// It is a callback that is executed according to
// https://developer.playcanvas.com/en/api/pc.ContainerHandler.html
preprocess(...) {
}
// It is a callback that is executed according to
// https://developer.playcanvas.com/en/api/pc.ContainerHandler.html
// Pass into the callback:
// 1) PC object on which the extension parser is executed
// 2) extension data,
// 3) gltf data,
// 4) array of already constructed textures,
// 5) array of constructed buffers
postprocess(...) {
}
}
Initial suggestion that I found: https://github.com/playcanvas/engine/pull/4409#pullrequestreview-1032788429