assignTexture method

Future<Texture?> assignTexture(
  1. dynamic materialParams,
  2. dynamic mapName,
  3. Map<String, dynamic> mapDef, [
  4. String? colorSpace,
])

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

Implementation

Future<Texture?> assignTexture(materialParams, mapName, Map<String, dynamic> mapDef, [String? colorSpace]) async {
  final parser = this;

  Texture? texture = await 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)) {
    console.warning('GLTFLoader: Custom UV set ${mapDef["texCoord"]} for texture $mapName not yet supported.');
  }

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

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


  if ( colorSpace != null ) {
    texture?.colorSpace = colorSpace;
  }

  materialParams[mapName] = texture;

  return texture;
}