assignTexture method

dynamic assignTexture(
  1. dynamic materialParams,
  2. dynamic mapName,
  3. Map<String, dynamic> mapDef, [
  4. dynamic encoding,
])

Asynchronously assigns a texture to the given material parameters. @param {Object} materialParams @param {string} mapName @param {Object} mapDef @return {Promise}

Implementation

assignTexture(materialParams, mapName, Map<String, dynamic> mapDef, [encoding]) async {
  var parser = this;

  var texture = await this.getDependency('texture', mapDef["index"]);

  // Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
  // However, we will copy UV set 0 to UV set 1 on demand for aoMap
  if (mapDef["texCoord"] != null &&
      mapDef["texCoord"] != 0 &&
      !(mapName == 'aoMap' && mapDef["texCoord"] == 1)) {
    print(
        'THREE.GLTFLoader: Custom UV set ${mapDef["texCoord"]} for texture ${mapName} not yet supported.');
  }

  if (parser.extensions[EXTENSIONS["KHR_TEXTURE_TRANSFORM"]] != null) {
    var transform = mapDef["extensions"] != null
        ? mapDef["extensions"][EXTENSIONS["KHR_TEXTURE_TRANSFORM"]]
        : null;

    if (transform != null) {
      var gltfReference = parser.associations[texture];
      texture = parser.extensions[EXTENSIONS["KHR_TEXTURE_TRANSFORM"]]
          .extendTexture(texture, transform);
      parser.associations[texture] = gltfReference;
    }
  }


  if ( encoding != null ) {

    texture.encoding = encoding;

  }

  materialParams[mapName] = texture;

  return texture;
}