GLTFMeshoptCompression constructor

GLTFMeshoptCompression(
  1. dynamic parser
)

Implementation

GLTFMeshoptCompression(parser) {
  this.parser = parser;

  this.loadBufferView = (index) async {
    Map<String, dynamic> json = this.parser.json;
    Map<String, dynamic> bufferView = json["bufferViews"][index];

    if (bufferView["extensions"] != null &&
        bufferView["extensions"][this.name] != null) {
      var extensionDef = bufferView["extensions"][this.name];

      var buffer =
          await this.parser.getDependency('buffer', extensionDef.buffer);
      var decoder = this.parser.options.meshoptDecoder;

      if (!decoder || !decoder.supported) {
        if (json["extensionsRequired"] != null &&
            json["extensionsRequired"].indexOf(this.name) >= 0) {
          throw ('THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files');
        } else {
          // Assumes that the extension is optional and that fallback buffer data is present
          return null;
        }
      }

      var byteOffset = extensionDef.byteOffset ?? 0;
      var byteLength = extensionDef.byteLength ?? 0;

      var count = extensionDef.count;
      var stride = extensionDef.byteStride;

      var result = new Uint8List(count * stride);
      var source = new Uint8List.view(buffer, byteOffset, byteLength);

      decoder.decodeGltfBuffer(result, count, stride, source,
          extensionDef.mode, extensionDef.filter);
      return result;
    } else {
      return null;
    }
  };
}