Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
loader: "awesome-typescript-loader",
},
{
test: /\.(glb|mtl|png|jpe?g|gif)$/,
test: /\.(glb|mtl|png|jpe?g|gif|hdr|exr)$/,
use: [
{
loader: "file-loader",
Expand Down
11 changes: 3 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/builders/GameBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoadingManager } from "three"
import { LoadingManager, WebGLRenderer } from "three"

import CameraManager from "../managers/CameraManager"
import DataManager from "../managers/DataManager"
Expand Down Expand Up @@ -26,14 +26,16 @@ const defaultGameBuilder = async ({
defaultLoadouts
}: GameBuilderOptions) => {
const players = replayMetadata.players
const sceneManager = await defaultSceneBuilder(players, loadingManager, defaultLoadouts)
const renderer = new WebGLRenderer({ antialias: true })
const sceneManager = await defaultSceneBuilder(players, renderer, loadingManager, defaultLoadouts)
defaultAnimationBuilder(replayData, sceneManager.players, sceneManager.ball)
DataManager.init({ replayData, replayMetadata })
CameraManager.init()
KeyManager.init()

return GameManager.init({
clock,
renderer
})
}

Expand Down
12 changes: 11 additions & 1 deletion src/builders/SceneBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cache, LoadingManager, Scene } from 'three'
import { Cache, LoadingManager, Scene, WebGLRenderer, Mesh, MeshStandardMaterial } from 'three'

import GameFieldAssets from '../loaders/scenes/GameFieldAssets'
import SceneManager from '../managers/SceneManager'
Expand All @@ -11,6 +11,7 @@ import { RocketAssetManager, RocketConfig, TextureFormat } from 'rl-loadout-lib'
import { buildRocketLoadoutGroup } from './player/buildRocketLoadoutScene';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { addEnvironment } from "./scene/addEnvironment";

/**
* @description The sole purpose of this function is to initialize and tie together all of the
Expand All @@ -20,6 +21,7 @@ import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
*/
const defaultSceneBuilder = async (
playerInfo: ExtendedPlayer[],
renderer: WebGLRenderer,
loadingManager?: LoadingManager,
defaultLoadouts?: boolean
): Promise<SceneManager> => {
Expand Down Expand Up @@ -49,11 +51,19 @@ const defaultSceneBuilder = async (
await GameFieldAssets.load()
const bodies = await Promise.all(bodyPromises)

const envMap = addEnvironment(scene, renderer)
addLighting(scene)
const field = buildPlayfield(scene)
const players = bodies.map(value => buildRocketLoadoutGroup(scene, value))
const ball = buildBall(scene)

// TODO ?
Comment thread
Abbondanzo marked this conversation as resolved.
Outdated
scene.traverse( child => {
if ( (<Mesh> child).isMesh ) {
(<MeshStandardMaterial> (<Mesh> child).material).envMap = envMap
}
})

return SceneManager.init({
scene,
ball,
Expand Down
29 changes: 29 additions & 0 deletions src/builders/scene/addEnvironment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Scene, WebGLRenderer } from "three"

import { PMREMGenerator } from "three/examples/jsm/pmrem/PMREMGenerator"
import { PMREMCubeUVPacker } from "three/examples/jsm/pmrem/PMREMCubeUVPacker"
import { EquirectangularToCubeGenerator } from "three/examples/jsm/loaders/EquirectangularToCubeGenerator"
import GameFieldAssets from "../../loaders/scenes/GameFieldAssets"

export const addEnvironment = (scene: Scene, renderer: WebGLRenderer) => {
const { environment } = GameFieldAssets.getAssets()

const cubeGenerator = new EquirectangularToCubeGenerator( environment, { resolution: 2048 } );
Comment thread
Abbondanzo marked this conversation as resolved.
Outdated
Comment thread
Longi94 marked this conversation as resolved.
Outdated
cubeGenerator.update( renderer );

// @ts-ignore
const pmremGenerator = new PMREMGenerator( cubeGenerator.renderTarget.texture );
pmremGenerator.update( renderer );

const pmremCubeUVPacker = new PMREMCubeUVPacker( pmremGenerator.cubeLods );
pmremCubeUVPacker.update( renderer );

// @ts-ignore
scene.background = cubeGenerator.renderTarget;

pmremGenerator.dispose();
pmremCubeUVPacker.dispose();

const envMap = pmremCubeUVPacker.CubeUVRenderTarget.texture;
return envMap
}
8 changes: 4 additions & 4 deletions src/builders/scene/addLighting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AmbientLight, DirectionalLight, HemisphereLight, Scene } from "three"

export const addLighting = (scene: Scene) => {
// Ambient light provides uniform lighting to all objects in the scene
const ambientLight = new AmbientLight(0xffffff, 0.2)
scene.add(ambientLight)
// const ambientLight = new AmbientLight(0xffffff, 0.2)
Comment thread
Abbondanzo marked this conversation as resolved.
Outdated
// scene.add(ambientLight)

// Hemisphere light gives the cars their shine and color
const hemisphereLight = new HemisphereLight(0xffffbb, 0xffffff, 0.5)
scene.add(hemisphereLight)
// const hemisphereLight = new HemisphereLight(0xffffbb, 0xffffff, 0.5)
// scene.add(hemisphereLight)

// The directional light is purely responsible for casting shadows
const dirLight = new DirectionalLight(0xffffff, 1.5)
Expand Down
24 changes: 24 additions & 0 deletions src/loaders/operators/loadEXR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { LoadingManager, DataTexture, FloatType } from "three"
import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader"

export const loadEXR = (path: string, loadingManager?: LoadingManager) => {
return new Promise(
(
resolve: (exrTexture: DataTexture) => void,
reject: (err: Error | ErrorEvent) => void
) => {
const exrLoader = new EXRLoader(loadingManager)
exrLoader.setDataType( FloatType )
exrLoader.load(
path,
(exrTexture: DataTexture) => {
resolve(exrTexture)
},
undefined,
(error: Error | ErrorEvent) => {
reject(error)
}
)
}
)
}
24 changes: 24 additions & 0 deletions src/loaders/operators/loadRGBE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { LoadingManager, DataTexture, UnsignedByteType } from "three"
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader"

export const loadRGBE = (path: string, loadingManager?: LoadingManager) => {
return new Promise(
(
resolve: (rgbeTexture: DataTexture) => void,
reject: (err: Error | ErrorEvent) => void
) => {
const rgbeLoader = new RGBELoader(loadingManager)
rgbeLoader.setDataType( UnsignedByteType )
rgbeLoader.load(
path,
(rgbeTexture: DataTexture) => {
resolve(rgbeTexture)
},
undefined,
(error: Error | ErrorEvent) => {
reject(error)
}
)
}
)
}
12 changes: 8 additions & 4 deletions src/loaders/scenes/GameFieldAssets.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Group, LoadingManager, Object3D } from "three"
import { Group, LoadingManager, Object3D, DataTexture } from "three"

import { loadBall } from "../storage/loadBall"
import { loadField } from "../storage/loadField"
import { loadEnvironment } from "../storage/loadEnvironment"

interface AvailableAssets {
ball: Object3D
field: Group
environment: DataTexture
}

class GameFieldAssets {
Expand All @@ -20,11 +22,13 @@ class GameFieldAssets {
const lm = this.loadingManager
return Promise.all([
loadBall(lm),
loadField(lm)
]).then(([ball, field]) => {
loadField(lm),
loadEnvironment(lm)
]).then(([ball, field, environment]) => {
this.assets = {
ball,
field
field,
environment
} as AvailableAssets
})
}
Expand Down
15 changes: 15 additions & 0 deletions src/loaders/storage/loadEnvironment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { LoadingManager, DataTexture } from "three"

import { loadRGBE } from "../operators/loadRGBE"
// import { loadEXR } from "../operators/loadEXR"
import { storageMemoize } from "./storageMemoize"

export const loadEnvironment = (loadingManager?: LoadingManager) =>
storageMemoize(async () => {
const { default: hdr } = await import(
// @ts-ignore
/* webpackChunkName: "Environment" */ "../../assets/models/textures/Environment/Environment.hdr"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this made it into SharedAssets yet?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I haven't finished final render yet, current environment texture is a testrender I made.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is okay to put the test render in. It is honestly high quality enough for temporary use.

@Abbondanzo is there a way to flag the render under beta?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to flag the render under beta?

Not entirely, but we can flag the version number in package.json as 0.7.0b or something of that nature. Publishing only happens once we cut releases in this repo

)
const environmentTexture = await loadRGBE(hdr, loadingManager)
return environmentTexture as DataTexture
}, "ENVIRONMENT")
9 changes: 5 additions & 4 deletions src/managers/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ import KeyManager from "./KeyManager"
import SceneManager from "./SceneManager"

interface GameManagerOptions {
clock: FPSClock
clock: FPSClock,
renderer: WebGLRenderer
}

export class GameManager {
clock: FPSClock
private readonly renderer: WebGLRenderer
renderer: WebGLRenderer

private constructor({ clock }: GameManagerOptions) {
this.renderer = new WebGLRenderer({ antialias: true })
private constructor({ clock, renderer }: GameManagerOptions) {
this.renderer = renderer
this.renderer.shadowMap.enabled = true
this.animate = this.animate.bind(this)
this.render = this.render.bind(this)
Expand Down
4 changes: 4 additions & 0 deletions src/types/exr.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.exr" {
const value: string
export default value
}
4 changes: 4 additions & 0 deletions src/types/hdr.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.hdr" {
const value: string
export default value
}
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
},
},
{
test: /\.(glb|mtl)$/,
test: /\.(glb|mtl|hdr|exr)$/,
use: [
{
loader: "file-loader",
Expand Down