text: import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
  import { GLTFLoader } from "../glTFLoader";
  var NAME = "KHR_materials_clearcoat";
  /**
   * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_clearcoat/README.md)
   * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
   */
  var KHR_materials_clearcoat = /** @class */ (function () {
      /** @hidden */
      function KHR_materials_clearcoat(loader) {
          /**
           * The name of this extension.
           */
          this.name = NAME;
          /**
           * Defines a number that determines the order the extensions are applied.
           */
          this.order = 190;
          this._loader = loader;
          this.enabled = this._loader.isExtensionUsed(NAME);
      }
      /** @hidden */
      KHR_materials_clearcoat.prototype.dispose = function () {
          this._loader = null;
      };
      /** @hidden */
      KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
          var _this = this;
          return GLTFLoader.LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
              var promises = new Array();
              promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
              promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
              return Promise.all(promises).then(function () { });
          });
      };
      KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
          if (!(babylonMaterial instanceof PBRMaterial)) {
              throw new Error(context + ": Material type not supported");
          }
          var promises = new Array();
          babylonMaterial.clearCoat.isEnabled = true;
          babylonMaterial.clearCoat.useRoughnessFromMainTexture = false;
          babylonMaterial.clearCoat.remapF0OnInterfaceChange = false;
          if (properties.clearcoatFactor != undefined) {
              babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
          }
          else {
              babylonMaterial.clearCoat.intensity = 0;
          }
          if (properties.clearcoatTexture) {
              promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
                  texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
                  babylonMaterial.clearCoat.texture = texture;
              }));
          }
          if (properties.clearcoatRoughnessFactor != undefined) {
              babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
          }
          else {
              babylonMaterial.clearCoat.roughness = 0;
          }
          if (properties.clearcoatRoughnessTexture) {
              properties.clearcoatRoughnessTexture.nonColorData = true;
              promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
                  texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
                  babylonMaterial.clearCoat.textureRoughness = texture;
              }));
          }
          if (properties.clearcoatNormalTexture) {
              properties.clearcoatNormalTexture.nonColorData = true;
              promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
                  texture.name = babylonMaterial.name + " (ClearCoat Normal)";
                  babylonMaterial.clearCoat.bumpTexture = texture;
              }));
              babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
              babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
              if (properties.clearcoatNormalTexture.scale != undefined) {
                  babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
              }
          }
          return Promise.all(promises).then(function () { });
      };
      return KHR_materials_clearcoat;
  }());
  export { KHR_materials_clearcoat };
  GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  //# sourceMappingURL=KHR_materials_clearcoat.js.map