"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ig_utilities_1 = require("@intelligentgraphics/ig.utilities");
var Loader_1 = require("./Loader");
/** Representation of IG.GFX materials. This structure is also used
 * for material definitions embedded into IGXC files.
 * The basic parameters, from Ambient to Transparency, are defined by
 * the Phong material model.
 */
var Material = /** @class */ (function () {
    function Material() {
        this.name = undefined;
        this.Ambient = 0;
        this.DiffuseR = 0;
        this.DiffuseG = 0;
        this.DiffuseB = 0;
        this.SpecularR = 0;
        this.SpecularG = 0;
        this.SpecularB = 0;
        this.Shininess = 0;
        this.EmissiveR = 0;
        this.EmissiveG = 0;
        this.EmissiveB = 0;
        this.Transparency = 0;
        this.Meta = {
            Taxonomy: {},
        };
    }
    /**
     * Replaces all paths with absolute hashed versions
     *
     *
     * @param {IMaterialData} { material, hashes, basePath }
     */
    Material.fixMaterialPaths = function (material, basePath, hashes) {
        if (ig_utilities_1.isNullOrUndefined(basePath) && ig_utilities_1.isNullOrUndefined(hashes)) {
            return material;
        }
        var createHashedAbsoluteUrl = function (url) {
            return Loader_1.LoaderUtils.createAbsoluteUrl(url, basePath, hashes);
        };
        var newMaterial = tslib_1.__assign(tslib_1.__assign({}, material), { Texture: material.Texture !== undefined
                ? createHashedAbsoluteUrl(material.Texture)
                : material.Texture });
        if (ig_utilities_1.isValue(material.Bump)) {
            newMaterial.Bump = tslib_1.__assign(tslib_1.__assign({}, newMaterial.Bump), { Map: createHashedAbsoluteUrl(material.Bump.Map) });
        }
        if (ig_utilities_1.isValue(material.Normal)) {
            newMaterial.Normal = tslib_1.__assign(tslib_1.__assign({}, material.Normal), { Map: createHashedAbsoluteUrl(material.Normal.Map) });
        }
        if (ig_utilities_1.isValue(material.Diffuse)) {
            newMaterial.Diffuse = tslib_1.__assign(tslib_1.__assign({}, material.Diffuse), { Map: createHashedAbsoluteUrl(material.Diffuse.Map) });
        }
        if (ig_utilities_1.isValue(material.Alpha) && ig_utilities_1.isValue(material.Alpha.Map)) {
            newMaterial.Alpha = tslib_1.__assign(tslib_1.__assign({}, material.Alpha), { Map: createHashedAbsoluteUrl(material.Alpha.Map) });
        }
        if (ig_utilities_1.isValue(material.Specular) && ig_utilities_1.isValue(material.Specular.Map)) {
            newMaterial.Specular = tslib_1.__assign(tslib_1.__assign({}, material.Specular), { Map: createHashedAbsoluteUrl(material.Specular.Map) });
        }
        if (ig_utilities_1.isValue(material.Metalness) && ig_utilities_1.isValue(material.Metalness.Map)) {
            newMaterial.Metalness = tslib_1.__assign(tslib_1.__assign({}, material.Metalness), { Map: createHashedAbsoluteUrl(material.Metalness.Map) });
        }
        if (ig_utilities_1.isValue(material.Roughness) && ig_utilities_1.isValue(material.Roughness.Map)) {
            newMaterial.Roughness = tslib_1.__assign(tslib_1.__assign({}, material.Roughness), { Map: createHashedAbsoluteUrl(material.Roughness.Map) });
        }
        return newMaterial;
    };
    return Material;
}());
exports.Material = Material;
