loadTextureImage method

dynamic loadTextureImage(
  1. dynamic textureIndex,
  2. dynamic sourceIndex,
  3. dynamic loader
)

Implementation

loadTextureImage(textureIndex, sourceIndex, loader) async {
  // print(" GLTFParser.loadTextureImage source: ${source} textureIndex: ${textureIndex} loader: ${loader} ");

  var parser = this;
  var json = this.json;

  Map textureDef = json["textures"][textureIndex];
  Map sourceDef = json["images"][sourceIndex];

  // var URL = self.URL || self.webkitURL;

  var cacheKey = '${(sourceDef["uri"] ?? sourceDef["bufferView"])}:${textureDef["sampler"]}';

  if (textureCache[cacheKey] != null) {
    // See https://github.com/mrdoob/three.js/issues/21559.
    return textureCache[cacheKey];
  }

  loader.flipY = false;
  var texture = await loadImageSource(sourceIndex, loader);

  texture.flipY = false;

  if (textureDef["name"] != null) texture.name = textureDef["name"];

  var samplers = json["samplers"] ?? {};
  Map sampler = samplers[textureDef["sampler"]] ?? {};

  texture.magFilter = webGlFilters[sampler["magFilter"]] ?? LinearFilter;
  texture.minFilter = webGlFilters[sampler["minFilter"]] ?? LinearMipmapLinearFilter;
  texture.wrapS = webGlWrappings[sampler["wrapS"]] ?? RepeatWrapping;
  texture.wrapT = webGlWrappings[sampler["wrapT"]] ?? RepeatWrapping;

  parser.associations[texture] = {"textures": textureIndex};

  textureCache[cacheKey] = texture;

  return texture;

  // String sourceURI = sourceDef["uri"] ?? "";
  // var isObjectURL = false;

  // var texture;
  // loader.flipY = false;

  // if (sourceDef["bufferView"] != null) {
  //   // Load binary image data from bufferView, if provided.

  //   // print("GLTFParser.loadTextureImage textureIndex: ${textureIndex} source->bufferView is not null TODO ");

  //   var bufferView =
  //       await parser.getDependency('bufferView', sourceDef["bufferView"]);

  //   if (sourceDef["mimeType"] == 'image/png') {
  //     // Inspect the PNG 'IHDR' chunk to determine whether the image could have an
  //     // alpha channel. This check is conservative — the image could have an alpha
  //     // channel with all values == 1, and the indexed type (colorType == 3) only
  //     // sometimes contains alpha.
  //     //
  //     // https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
  //     var colorType = new ByteData.view(bufferView, 25, 1).getUint8(0);
  //   }

  //   // should be in a isolate
  //   // var _image = Image.decodeImage( bufferView.asUint8List() );
  //   // var _pixels = _image!.getBytes();

  //   // var imageElement = ImageElement(data: _pixels, width: _image.width, height: _image.height);
  //   // texture = Texture(imageElement, null, null, null, null, null, null, null, null, null);

  //   isObjectURL = true;
  //   var blob = Blob(bufferView.asUint8List(), {"type": source["mimeType"]});
  //   // sourceURI = createObjectURL( blob );

  //   texture = await loader.loadAsync(blob, null);
  // } else if (sourceDef["uri"] == null) {
  //   throw ('THREE.GLTFLoader: Image ' +
  //       textureIndex +
  //       ' is missing URI and bufferView');
  // } else if (sourceDef["uri"] != null) {
  //   // https://github.com/wasabia/three_dart/issues/10

  //   texture = await loader.loadAsync(
  //       LoaderUtils.resolveURL(sourceURI, options["path"]), null);
  // }

  // texture.needsUpdate = true;
  // texture.flipY = false;

  // if (textureDef["name"] != null) {
  //   texture.name = textureDef["name"];
  // } else {
  //   texture.name = sourceDef["name"] ?? "";
  // }

  // var samplers = json["samplers"] ?? {};
  // var sampler = samplers[textureDef["sampler"]] ?? {};

  // texture.magFilter = WEBGL_FILTERS[sampler["magFilter"]] ?? LinearFilter;
  // texture.minFilter =
  //     WEBGL_FILTERS[sampler["minFilter"]] ?? LinearMipmapLinearFilter;
  // texture.wrapS = WEBGL_WRAPPINGS[sampler["wrapS"]] ?? RepeatWrapping;
  // texture.wrapT = WEBGL_WRAPPINGS[sampler["wrapT"]] ?? RepeatWrapping;

  // // parser.associations.set( texture, {
  // //   type: 'textures',
  // //   index: textureIndex
  // // } );

  // parser.associations[texture] = {"type": "textures", "index": textureIndex};

  // // this.textureCache[ cacheKey ] = texture;

  // return texture;
}