"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Rendering
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.RenderMaterial = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
/** Represents a material which can be applied to a surface to control aspects of its appearance such as color, reflectivity, texture, and so on.
 * @public
 */
class RenderMaterial {
    constructor(params) {
        this.key = params.key;
        this.textureMapping = params.textureMapping;
        this._guid = core_bentley_1.Guid.createValue();
    }
    get hasTexture() {
        return undefined !== this.textureMapping?.texture;
    }
    /** An [OrderedComparator]($bentley) that compares this material against `other`. */
    compare(other) {
        return (0, core_bentley_1.compareStrings)(this._guid, other._guid);
    }
}
exports.RenderMaterial = RenderMaterial;
/** @public */
(function (RenderMaterial) {
    function clampToNormalizedRange(value) {
        return Math.max(0.0, Math.min(1.0, value));
    }
    /** @deprecated in 3.x. Use [CreateRenderMaterialArgs]($frontend). */
    class Params {
        constructor(key) {
            /** Diffuse weight in [0..1] */
            this.diffuse = 0.6;
            /** Specular weight in [0..1] */
            this.specular = 0.4;
            this.specularExponent = 13.5;
            /** Currently unused. @alpha */
            this.reflect = 0.0;
            /** Currently unused. @alpha */
            this.refract = 1.0;
            /** Currently unused. @alpha */
            this.ambient = .3;
            /** Currently unused. @alpha */
            this.shadows = true;
            this.key = key;
        }
        /** A value from 0.0 (fully-transparent) to 1.0 (fully-opaque) controlling the transparency of surfaces to which this material is applied;
         * or undefined if this material does not override surface transparency.
         */
        get alpha() { return this._alpha; }
        set alpha(alpha) {
            this._alpha = undefined !== alpha ? clampToNormalizedRange(alpha) : undefined;
        }
        /** Create a RenderMaterial params object using specified key and ColorDef values, as well as an optional texture mapping. */
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        static fromColors(key, diffuseColor, specularColor, emissiveColor, reflectColor, textureMap) {
            // eslint-disable-next-line @typescript-eslint/no-deprecated
            const materialParams = new Params();
            materialParams.key = key;
            materialParams.diffuseColor = diffuseColor;
            materialParams.specularColor = specularColor;
            materialParams.emissiveColor = emissiveColor;
            materialParams.reflectColor = reflectColor;
            materialParams.textureMapping = textureMap;
            return materialParams;
        }
    }
    /** Obtain an immutable instance of a RenderMaterial with all default properties. */
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    Params.defaults = new Params();
    RenderMaterial.Params = Params;
})(RenderMaterial || (exports.RenderMaterial = RenderMaterial = {}));
// eslint-disable-next-line @typescript-eslint/no-deprecated
Object.freeze(RenderMaterial.Params.defaults);
//# sourceMappingURL=RenderMaterial.js.map