Skip to content

Commit

Permalink
Merge pull request #307 from casual-simulation/feat/add_defaultLighti…
Browse files Browse the repository at this point in the history
…ng_tag_for_gridPortal_and_miniGridPortal

Feat/add default lighting tag for grid portal and mini grid portal
  • Loading branch information
KallynGowdy authored Nov 1, 2023
2 parents 32e59f4 + a02e76f commit 7a28697
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/docs/tags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,24 @@ Additionally, this tag does nothing when in VR.
</PossibleValueCode>
</PossibleValuesTable>

### `defaultLighting`
<Badges>
<GridPortalBadge/>
<MiniGridPortalBadge/>
</Badges>

Sets the default lighting in the gridPortalBot/miniGridPortal

#### Possible values are:
<PossibleValuesTable>
<PossibleValueCode value='true'>
(Default)
</PossibleValueCode>
<PossibleValueCode value='false'>
Disables default lighting
</PossibleValueCode>
</PossibleValuesTable>

### `portalLocked`
<Badges>
<GridPortalBadge/>
Expand Down
3 changes: 3 additions & 0 deletions src/aux-common/bots/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,8 @@ export const DEFAULT_PORTAL_PANNABLE = true;
*/
export const DEFAULT_PORTAL_ROTATABLE = true;

export const DEFAULT_GRID_PORTAL_LIGHTING = true;

/**
* Whether portals are zoomable by default.
*/
Expand Down Expand Up @@ -2535,6 +2537,7 @@ export const KNOWN_TAGS: string[] = [
'pixelHeight',
'pixelRatio',
'defaultPixelRatio',
'defaultLighting',
'pageTitle',
'pointerPixelX',
'pointerPixelY',
Expand Down
7 changes: 7 additions & 0 deletions src/aux-server/aux-web/aux-player/scene/MiniSimulation3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export class MiniSimulation3D extends PlayerSimulation3D {
return this.miniConfig.backgroundAddress || super.backgroundAddress;
}

/**
* Gets the default lighting that the simulation defines.
*/
get defaultLighting() {
return this.miniConfig.defaultLighting;
}

/**
* Gets the pannability of the mini camera that the simulation defines.
*/
Expand Down
23 changes: 23 additions & 0 deletions src/aux-server/aux-web/aux-player/scene/PlayerGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export class PlayerGame extends Game {
private miniScene: Scene;
private mapScene: Scene;
private miniMapScene: Scene;
private _miniAmbientLight: AmbientLight;
private _miniDirectionalLight: DirectionalLight;

// /**
// * A scene that is used to allow the main scene to render
Expand Down Expand Up @@ -257,6 +259,13 @@ export class PlayerGame extends Game {
);
}

getDefaultLighting(): boolean {
return this._getSimulationValue(
this.playerSimulations,
'defaultLighting'
);
}

getPannable(): boolean {
return this._getSimulationValue(this.playerSimulations, 'pannable');
}
Expand Down Expand Up @@ -422,6 +431,13 @@ export class PlayerGame extends Game {
);
}

getMiniDefaultLighting(): boolean {
return this._getSimulationValue(
this.miniSimulations,
'defaultLighting'
);
}

getMiniPortalColor(): Color | Texture {
return this._getSimulationValue(
this.miniSimulations,
Expand Down Expand Up @@ -1236,6 +1252,11 @@ export class PlayerGame extends Game {
// }
this.miniSceneBackgroundUpdate();

const defaultLighting = this.getMiniDefaultLighting();

this._miniAmbientLight.visible = defaultLighting;
this._miniDirectionalLight.visible = defaultLighting;

this.renderer.setViewport(
this.miniViewport.x,
this.miniViewport.y,
Expand Down Expand Up @@ -1392,10 +1413,12 @@ export class PlayerGame extends Game {
// miniGridPortal ambient light.
const invAmbient = baseAuxAmbientLight();
this.miniScene.add(invAmbient);
this._miniAmbientLight = invAmbient;

// miniGridPortal direction light.
const invDirectional = baseAuxDirectionalLight();
this.miniScene.add(invDirectional);
this._miniDirectionalLight = invDirectional;
}

private _createGlobeMask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ export class PlayerPageSimulation3D extends PlayerSimulation3D {
return this.pageConfig.rotatable;
}

/**
* Gets the default lighting of the simulation.
*/
get defaultLighting() {
return this.pageConfig.defaultLighting;
}

/**
* Gets if zooming is allowed in the miniGridPortal that the simulation defines.
*/
Expand Down
17 changes: 17 additions & 0 deletions src/aux-server/aux-web/aux-player/scene/PortalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getPortalCursor,
getTagPosition,
getTagRotation,
DEFAULT_GRID_PORTAL_LIGHTING,
} from '@casual-simulation/aux-common';
import { Color, Texture } from '@casual-simulation/three';
import {
Expand Down Expand Up @@ -48,6 +49,7 @@ export class PortalConfig implements SubscriptionLike {
private _zoomMin: number = null;
private _zoomMax: number = null;
private _rotatable: boolean = null;
private _gridPortalDefaultLighting: boolean = null;
private _playerZoom: number = null;
private _playerRotationX: number = null;
private _playerRotationY: number = null;
Expand Down Expand Up @@ -147,6 +149,14 @@ export class PortalConfig implements SubscriptionLike {
}
}

get defaultLighting() {
if (this._gridPortalDefaultLighting != null) {
return this._gridPortalDefaultLighting;
} else {
return DEFAULT_GRID_PORTAL_LIGHTING;
}
}

/**
* Gets if zooming is allowed in the miniGridPortal that the simulation defines.
*/
Expand Down Expand Up @@ -432,6 +442,13 @@ export class PortalConfig implements SubscriptionLike {
this._cursor = getPortalCursor(calc, bot);
this.gridScale = this._calculateGridScale(calc, bot);

this._gridPortalDefaultLighting = calculateBooleanTagValue(
calc,
bot,
`defaultLighting`,
DEFAULT_GRID_PORTAL_LIGHTING
);

// TODO:
// const dimensionLocked = isDimensionLocked(calc, bot);
// if (dimensionLocked) {
Expand Down
14 changes: 14 additions & 0 deletions src/aux-server/aux-web/shared/scene/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
sRGBEncoding,
VideoTexture,
Object3D,
AmbientLight,
DirectionalLight,
} from '@casual-simulation/three';
import { IGameView } from '../vue-components/IGameView';
import { ArgEvent } from '@casual-simulation/aux-common/Events';
Expand Down Expand Up @@ -110,6 +112,8 @@ export abstract class Game {
private _currentBackgroundAddress: string;
private _backgroundVideoElement: HTMLVideoElement;
private _backgroundVideoSubscription: Subscription;
private _ambientLight: AmbientLight;
private _directionalLight: DirectionalLight;

mainCameraRig: CameraRig = null;
mainViewport: Viewport = null;
Expand Down Expand Up @@ -280,6 +284,8 @@ export abstract class Game {

abstract getBackground(): Color | Texture;

abstract getDefaultLighting(): boolean;

abstract getBackgroundAddress(): string;

/**
Expand Down Expand Up @@ -866,10 +872,12 @@ export abstract class Game {
// Main scene ambient light.
const ambient = baseAuxAmbientLight();
this.mainScene.add(ambient);
this._ambientLight = ambient;

// Main scene directional light.
const directional = baseAuxDirectionalLight();
this.mainScene.add(directional);
this._directionalLight = directional;

//
// [Html Mixer Context]
Expand Down Expand Up @@ -981,6 +989,12 @@ export abstract class Game {
if (renderBackground) {
this.mainSceneBackgroundUpdate();
}

const defaultLighting = this.getDefaultLighting();

this._ambientLight.visible = defaultLighting;
this._directionalLight.visible = defaultLighting;

this.renderer.render(this.mainScene, this.mainCameraRig.mainCamera);

// Render debug object manager if it's enabled.
Expand Down

0 comments on commit 7a28697

Please sign in to comment.