@itwin/core-common
Version:
iTwin.js components common to frontend and backend
62 lines • 2.5 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 DisplayStyles
*/
import { JsonUtils } from "@itwin/core-bentley";
import { ColorByName } from "./ColorByName";
import { ColorDef } from "./ColorDef";
import { RgbColor } from "./RgbColor";
const defaultColor = RgbColor.fromColorDef(ColorDef.fromTbgr(ColorByName.grey));
/** Settings controlling display of solar shadows for a [[DisplayStyle3dSettings]].
* Solar shadows are imposed as a color scaling on geometry occluded from solar lighting.
* @public
*/
export class SolarShadowSettings {
/** Shadow color. */
color;
/** @internal */
bias;
constructor(props) {
this.bias = JsonUtils.asDouble(props.bias, 0.001);
if (undefined === props.color || null === props.color)
this.color = defaultColor;
else
this.color = RgbColor.fromColorDef(ColorDef.fromJSON(props.color));
}
static defaults = new SolarShadowSettings({});
static fromJSON(props) {
return props ? new SolarShadowSettings(props) : this.defaults;
}
toJSON() {
const defaults = SolarShadowSettings.defaults;
if (this.equals(defaults))
return undefined;
const props = {};
if (!this.color.equals(defaults.color))
props.color = this.color.toColorDef().toJSON();
if (this.bias !== defaults.bias)
props.bias = this.bias;
return props;
}
equals(rhs) {
return this.bias === rhs.bias && this.color.equals(rhs.color);
}
/** Create a copy of these settings.
* @param changedProps Any property explicitly defined will be overridden in the copy.
* @returns A settings object equivalent to this one except for any properties explicitly overridden by `changedProps`.
*/
clone(changedProps) {
if (!changedProps)
return this;
const props = this.toJSON() ?? {};
if (changedProps.color)
props.color = changedProps.color;
if (undefined !== changedProps.bias)
props.bias = changedProps.bias;
return SolarShadowSettings.fromJSON(props);
}
}
//# sourceMappingURL=SolarShadows.js.map