@itwin/core-common
Version:
iTwin.js components common to frontend and backend
64 lines • 2.79 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* 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
*/
function clampToNormalizedRange(value) {
return Math.max(0.0, Math.min(1.0, value));
}
/** Params for use in old CreateMaterial functions. Use [CreateRenderMaterialArgs]($frontend) instead.
* @internal
*/
export class RenderMaterialParams {
/** If the material originates from a Material element in the [[IModel]], the Id of that element. */
key;
/** Diffuse color, or undefined if this material does not override the surface's own color. */
diffuseColor;
/** Specular color. Defaults to white if undefined. */
specularColor;
/** Currently unused. @alpha */
emissiveColor;
/** Currently unused. @alpha */
reflectColor;
/** Optional pattern mapping applied to the surface. */
textureMapping;
/** Diffuse weight in [0..1] */
diffuse = 0.6;
/** Specular weight in [0..1] */
specular = 0.4;
specularExponent = 13.5;
/** Currently unused. @alpha */
reflect = 0.0;
/** Currently unused. @alpha */
refract = 1.0;
/** Currently unused. @alpha */
ambient = .3;
/** Currently unused. @alpha */
shadows = true;
_alpha;
constructor(key) { this.key = key; }
/** Obtain an immutable instance of a RenderMaterial with all default properties. */
static defaults = new RenderMaterialParams();
/** 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. */
static fromColors(key, diffuseColor, specularColor, emissiveColor, reflectColor, textureMap) {
const materialParams = new RenderMaterialParams();
materialParams.key = key;
materialParams.diffuseColor = diffuseColor;
materialParams.specularColor = specularColor;
materialParams.emissiveColor = emissiveColor;
materialParams.reflectColor = reflectColor;
materialParams.textureMapping = textureMap;
return materialParams;
}
}
Object.freeze(RenderMaterialParams.defaults);
//# sourceMappingURL=RenderMaterialParams.js.map