Skip to content

Commit

Permalink
Slight refactor in how env properties are passed down to the various …
Browse files Browse the repository at this point in the history
…classes
  • Loading branch information
sachamorgese committed Jun 3, 2024
1 parent 4962516 commit 567ac8a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ export class LocalAvatarClient {
);
this.cameraManager.camera.add(this.audioListener);

this.composer = new Composer(this.scene, this.cameraManager.camera, true);
this.composer = new Composer({
scene: this.scene,
camera: this.cameraManager.camera,
spawnSun: true,
});
this.composer.useHDRJPG(hdrJpgUrl);
this.element.appendChild(this.composer.renderer.domElement);

Expand Down
2 changes: 2 additions & 0 deletions example/multi-user-3d-web-experience/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ const app = new Networked3dWebExperienceClient(holder, {
},
hdrJpgUrl,
mmlDocuments: [{ url: `${protocol}//${host}/mml-documents/example-mml.html` }],
environmentConfiguration: {},
});

app.update();
1 change: 1 addition & 0 deletions packages/3d-web-client-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export { CollisionsManager } from "./collisions/CollisionsManager";
export { Sun } from "./sun/Sun";
export { GroundPlane } from "./ground-plane/GroundPlane";
export { LoadingScreen } from "./loading-screen/LoadingScreen";
export { EnvironmentConfiguration } from "./rendering/composer";
67 changes: 45 additions & 22 deletions packages/3d-web-client-core/src/rendering/composer.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import { EnvironmentConfiguration } from "@mml-io/3d-web-experience-client";
import { HDRJPGLoader } from "@monogrid/gainmap-js";
import {
BlendFunction,
BloomEffect,
EdgeDetectionMode,
EffectComposer,
RenderPass,
EffectPass,
FXAAEffect,
NormalPass,
PredicationMode,
RenderPass,
ShaderPass,
BloomEffect,
SMAAEffect,
SMAAPreset,
SSAOEffect,
BlendFunction,
TextureEffect,
ToneMappingEffect,
SMAAEffect,
SMAAPreset,
EdgeDetectionMode,
PredicationMode,
NormalPass,
} from "postprocessing";
import {
AmbientLight,
Color,
EquirectangularReflectionMapping,
Euler,
Fog,
HalfFloatType,
LinearSRGBColorSpace,
LoadingManager,
PMREMGenerator,
MathUtils,
PerspectiveCamera,
SRGBColorSpace,
PMREMGenerator,
Scene,
ShadowMapType,
SRGBColorSpace,
ToneMapping,
Vector2,
WebGLRenderer,
EquirectangularReflectionMapping,
MathUtils,
Euler,
} from "three";
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader.js";

Expand All @@ -52,6 +51,30 @@ import { BrightnessContrastSaturation } from "./post-effects/bright-contrast-sat
import { GaussGrainEffect } from "./post-effects/gauss-grain";
import { N8SSAOPass } from "./post-effects/n8-ssao/N8SSAOPass";

type ComposerContructorArgs = {
scene: Scene;
camera: PerspectiveCamera;
spawnSun: boolean;
environmentConfiguration?: EnvironmentConfiguration;
};

export type EnvironmentConfiguration = {
hdr?: {
intensity?: number;
blurriness?: number;
azimuthalAngle?: number;
polarAngle?: number;
};
sun?: {
intensity?: number;
polarAngle?: number;
azimuthalAngle?: number;
};
postProcessing?: {
bloomIntensity?: number;
};
};

export class Composer {
private width: number = 1;
private height: number = 1;
Expand Down Expand Up @@ -91,17 +114,17 @@ export class Composer {
private readonly gaussGrainPass: ShaderPass;

private ambientLight: AmbientLight | null = null;
private environmentConfiguration: EnvironmentConfiguration;
private environmentConfiguration?: EnvironmentConfiguration;

public sun: Sun | null = null;
public spawnSun: boolean;

constructor(
scene: Scene,
camera: PerspectiveCamera,
spawnSun: boolean,
environmentConfiguration: EnvironmentConfiguration,
) {
constructor({
scene,
camera,
spawnSun = false,
environmentConfiguration,
}: ComposerContructorArgs) {
this.scene = scene;
this.postPostScene = new Scene();
this.camera = camera;
Expand Down Expand Up @@ -160,7 +183,7 @@ export class Composer {

this.fxaaEffect = new FXAAEffect();

if (environmentConfiguration.postProcessing?.bloomIntensity) {
if (environmentConfiguration?.postProcessing?.bloomIntensity) {
extrasValues.bloom = environmentConfiguration.postProcessing.bloomIntensity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {
CollisionsManager,
Composer,
decodeCharacterAndCamera,
EnvironmentConfiguration,
getSpawnPositionInsideCircle,
GroundPlane,
KeyInputManager,
LoadingScreen,
MMLCompositionScene,
TimeManager,
TweakPane,
GroundPlane,
LoadingScreen,
VirtualJoystick,
} from "@mml-io/3d-web-client-core";
import { ChatNetworkingClient, FromClientChatMessage, TextChatUI } from "@mml-io/3d-web-text-chat";
Expand Down Expand Up @@ -52,24 +53,6 @@ type MMLDocumentConfiguration = {
};
};

export type EnvironmentConfiguration = {
enableTweakPane?: boolean;
hdr?: {
intensity?: number;
blurriness?: number;
azimuthalAngle?: number;
polarAngle?: number;
},
sun?: {
intensity?: number;
polarAngle?: number;
azimuthalAngle?: number;
},
postProcessing?: {
bloomIntensity?: number;
},
}

export type Networked3dWebExperienceClientConfig = {
sessionToken: string;
chatNetworkAddress?: string;
Expand All @@ -79,6 +62,7 @@ export type Networked3dWebExperienceClientConfig = {
animationConfig: AnimationConfig;
environmentConfiguration?: EnvironmentConfiguration;
hdrJpgUrl: string;
enableTweakPane?: boolean;
};

export class Networked3dWebExperienceClient {
Expand Down Expand Up @@ -148,11 +132,17 @@ export class Networked3dWebExperienceClient {
mouse_support: false,
});

this.composer = new Composer(this.scene, this.cameraManager.camera, true, this.config.environmentConfiguration);
this.composer = new Composer({
scene: this.scene,
camera: this.cameraManager.camera,
spawnSun: true,
environmentConfiguration: this.config.environmentConfiguration,
});

this.composer.useHDRJPG(this.config.hdrJpgUrl);
this.element.appendChild(this.composer.renderer.domElement);

if (this.config.environmentConfiguration?.enableTweakPane !== false) {
if (this.config.enableTweakPane !== false) {
this.tweakPane = new TweakPane(
this.element,
this.composer.renderer,
Expand Down

0 comments on commit 567ac8a

Please sign in to comment.