import { __assign } from "tslib";
import { isValue, isNullOrUndefined } from "@intelligentgraphics/ig.utilities";
import { LoaderUtils } from "./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 (isNullOrUndefined(basePath) && isNullOrUndefined(hashes)) {
            return material;
        }
        var createHashedAbsoluteUrl = function (url) {
            return LoaderUtils.createAbsoluteUrl(url, basePath, hashes);
        };
        var newMaterial = __assign(__assign({}, material), { Texture: material.Texture !== undefined
                ? createHashedAbsoluteUrl(material.Texture)
                : material.Texture });
        if (isValue(material.Bump)) {
            newMaterial.Bump = __assign(__assign({}, newMaterial.Bump), { Map: createHashedAbsoluteUrl(material.Bump.Map) });
        }
        if (isValue(material.Normal)) {
            newMaterial.Normal = __assign(__assign({}, material.Normal), { Map: createHashedAbsoluteUrl(material.Normal.Map) });
        }
        if (isValue(material.Diffuse)) {
            newMaterial.Diffuse = __assign(__assign({}, material.Diffuse), { Map: createHashedAbsoluteUrl(material.Diffuse.Map) });
        }
        if (isValue(material.Alpha) && isValue(material.Alpha.Map)) {
            newMaterial.Alpha = __assign(__assign({}, material.Alpha), { Map: createHashedAbsoluteUrl(material.Alpha.Map) });
        }
        if (isValue(material.Specular) && isValue(material.Specular.Map)) {
            newMaterial.Specular = __assign(__assign({}, material.Specular), { Map: createHashedAbsoluteUrl(material.Specular.Map) });
        }
        if (isValue(material.Metalness) && isValue(material.Metalness.Map)) {
            newMaterial.Metalness = __assign(__assign({}, material.Metalness), { Map: createHashedAbsoluteUrl(material.Metalness.Map) });
        }
        if (isValue(material.Roughness) && isValue(material.Roughness.Map)) {
            newMaterial.Roughness = __assign(__assign({}, material.Roughness), { Map: createHashedAbsoluteUrl(material.Roughness.Map) });
        }
        return newMaterial;
    };
    return Material;
}());
export { Material };
