engine icon indicating copy to clipboard operation
engine copied to clipboard

Add glTF extension registry

Open querielo opened this issue 3 years ago • 1 comments

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?

  1. It can help to split glb-parser.js to different files with different parsers.
  2. 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(...) {
  
  }
}

querielo avatar Sep 06 '22 08:09 querielo

Initial suggestion that I found: https://github.com/playcanvas/engine/pull/4409#pullrequestreview-1032788429

querielo avatar Sep 06 '22 22:09 querielo