Skip to content

Commit

Permalink
Ambient occlusion implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoes committed Jul 31, 2024
1 parent f2206bb commit a2105d4
Show file tree
Hide file tree
Showing 28 changed files with 769 additions and 181 deletions.
67 changes: 57 additions & 10 deletions src/GLViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GLViewer {

private callback: any;
private defaultcolors: any;
private config: any;
private config: ViewerSpec;
private nomouse = false;
private bgColor: any;
private camerax: number;
Expand Down Expand Up @@ -164,7 +164,9 @@ export class GLViewer {
canvas: this.config.canvas,
//cannot initialize with zero size - render will start out lost
containerWidth: this.WIDTH,
containerHeight: this.HEIGHT
containerHeight: this.HEIGHT,
ambientOcclusion: this.config.ambientOcclusion,
outline: this.config.outline
});
this.renderer.domElement.style.width = "100%";
this.renderer.domElement.style.height = "100%";
Expand Down Expand Up @@ -620,7 +622,7 @@ export class GLViewer {
this.defaultcolors = this.config.defaultcolors;
if (!this.defaultcolors)
this.defaultcolors = elementColors.defaultColors;
this.nomouse = this.config.nomouse;
this.nomouse = Boolean(this.config.nomouse);
this.bgColor = 0;
this.config.backgroundColor = this.config.backgroundColor || "#ffffff";
if (typeof (this.config.backgroundColor) != 'undefined') {
Expand All @@ -630,7 +632,7 @@ export class GLViewer {

this.camerax = 0;
if (typeof (this.config.camerax) != 'undefined') {
this.camerax = parseFloat(this.config.camerax);
this.camerax = typeof(this.config.camerax) === 'string' ? parseFloat(this.config.camerax) : this.config.camerax;
}
this._viewer = this;
this.container = element; //we expect container to be HTMLElement
Expand Down Expand Up @@ -674,7 +676,7 @@ export class GLViewer {

this.initContainer(this.container);
if (this.config.style) { //enable setting style in constructor
this.setViewStyle(this.config);
this.setViewStyle(this.config as ViewStyle);
}

window.addEventListener("resize", this.resize.bind(this));
Expand Down Expand Up @@ -830,10 +832,10 @@ export class GLViewer {
};

/**
* Set the configuration object. Note that some setting may only
* Set the configuration object. Note that some settings may only
* have an effect at viewer creation time.
*/
public setConfig(c) {
public setConfig(c: ViewerSpec) {
this.config = c;
};

Expand Down Expand Up @@ -1341,15 +1343,26 @@ export class GLViewer {
});
*
*/
public setViewStyle(parameters) {
if (parameters.style === "outline") {
public setViewStyle(parameters: ViewStyle) {
parameters = parameters || {};
parameters.style = parameters.style || "";

if (parameters.style.includes("outline")) {
var params: any = {};
if (parameters.color) params.color = CC.color(parameters.color);
if (parameters.width) params.width = parameters.width;
this.renderer.enableOutline(params);
} else {
this.renderer.disableOutline();
}
if (parameters.style.includes("ambientOcclusion")) {
var params: any = {};
if (parameters.strength) params.strength = parameters.strength;
if (parameters.radius) params.radius = parameters.radius;
this.renderer.enableAmbientOcclusion(params);
} else {
this.renderer.disableAmbientOcclusion();
}
return this;
};

Expand Down Expand Up @@ -4971,6 +4984,34 @@ export function createStereoViewer(element) {

};


/**
* Outline style configuration parameters
*/
export interface OutlineStyle {
/** Width of the outline */
width?: number;
/** Color of the outline */
color?: ColorSpec;
}

/**
* AmbientOcclusion style configuration parameters
*/
export interface AmbientOcclusionStyle {
/** Strength (darkness) of shading (default 1.0) */
strength?: number;
/** Radius (in Angstroms) used to detect occlusions (default 5.0). */
radius?: number;
}

/**
* View style configuration
*/
export interface ViewStyle extends OutlineStyle, AmbientOcclusionStyle {
/** How to style viewer: outline|ambientOcclusion|none */
style?: string;
}
/**
* GLViewer input specification
*/
Expand All @@ -4993,7 +5034,7 @@ export interface ViewerSpec {
/** Alpha transparency of canvas background */
backgroundAlpha?: number;
/** */
camerax?: number;
camerax?: number|string;
/** */
hoverDuration?: number;
/** id of the canvas */
Expand Down Expand Up @@ -5025,6 +5066,12 @@ export interface ViewerSpec {
orthographic?: boolean;
/** Disable fog, default to false */
disableFog?: boolean;
/** outline or ambientOcclusion **deprecated** */
style?: string;
/** Outline parameters */
outline?: OutlineStyle;
/** Ambient occlusion settings */
ambientOcclusion?: AmbientOcclusionStyle;

};

Expand Down
Loading

0 comments on commit a2105d4

Please sign in to comment.