|
@@ -1,5 +1,10 @@
|
|
import * as THREE from 'three'
|
|
import * as THREE from 'three'
|
|
-import { GLTFLoader, EXRLoader, RGBELoader, OrbitControls } from 'three/examples/jsm/Addons.js'
|
|
|
|
|
|
+import { GLTFLoader, EXRLoader, RGBELoader, OrbitControls, ShaderPass, GammaCorrectionShader } from 'three/examples/jsm/Addons.js'
|
|
|
|
+import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer';
|
|
|
|
+import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass';
|
|
|
|
+import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass';
|
|
|
|
+import { OutputPass } from 'three/examples/jsm/postprocessing/OutputPass';
|
|
|
|
+import { OutlinePass } from 'three/examples/jsm/postprocessing/OutlinePass.js';
|
|
import { init, update, onClick, onKeyPress } from './game.js'
|
|
import { init, update, onClick, onKeyPress } from './game.js'
|
|
import gsap from 'gsap'
|
|
import gsap from 'gsap'
|
|
import { MotionPathPlugin } from 'gsap/MotionPathPlugin.js'
|
|
import { MotionPathPlugin } from 'gsap/MotionPathPlugin.js'
|
|
@@ -7,7 +12,7 @@ import Howler from 'howler'
|
|
|
|
|
|
gsap.registerPlugin(MotionPathPlugin)
|
|
gsap.registerPlugin(MotionPathPlugin)
|
|
Howler.autoUnlock = true
|
|
Howler.autoUnlock = true
|
|
-
|
|
|
|
|
|
+
|
|
const game = {}
|
|
const game = {}
|
|
game.entities = []
|
|
game.entities = []
|
|
game.loadingManager = new THREE.LoadingManager()
|
|
game.loadingManager = new THREE.LoadingManager()
|
|
@@ -25,14 +30,46 @@ game.lookAtFocus = new THREE.Vector3(0, 0, 0)
|
|
|
|
|
|
function loaded() {
|
|
function loaded() {
|
|
game.renderer = new THREE.WebGLRenderer({
|
|
game.renderer = new THREE.WebGLRenderer({
|
|
- canvas:game.canvas,
|
|
|
|
|
|
+ canvas: game.canvas,
|
|
antialias: true,
|
|
antialias: true,
|
|
|
|
|
|
})
|
|
})
|
|
|
|
+ game.renderer.outputColorSpace = THREE.SRGBColorSpace
|
|
game.renderer.setSize(game.canvas.offsetWidth, game.canvas.offsetHeight)
|
|
game.renderer.setSize(game.canvas.offsetWidth, game.canvas.offsetHeight)
|
|
game.renderer.shadowMap.enabled = true
|
|
game.renderer.shadowMap.enabled = true
|
|
game.renderer.shadowMap.type = THREE.PCFSoftShadowMap
|
|
game.renderer.shadowMap.type = THREE.PCFSoftShadowMap
|
|
|
|
|
|
|
|
+ /******************
|
|
|
|
+ * Postprocessing *
|
|
|
|
+ ******************/
|
|
|
|
+
|
|
|
|
+ const renderPass = new RenderPass(game.scene, game.camera)
|
|
|
|
+
|
|
|
|
+ const bloomPass = new UnrealBloomPass(new THREE.Vector2(game.canvas.offsetWidth, game.canvas.offsetHeight));
|
|
|
|
+ bloomPass.threshold = 0.5
|
|
|
|
+ bloomPass.strength = 0.25
|
|
|
|
+ bloomPass.radius = 0.0
|
|
|
|
+
|
|
|
|
+ // Highlight
|
|
|
|
+ game.outlinePass = new OutlinePass(new THREE.Vector2(game.canvas.offsetWidth, game.canvas.offsetHeight), game.scene, game.camera)
|
|
|
|
+ // game.outlinePass.edgeThickness = 1
|
|
|
|
+ // game.outlinePass.edgeGlow = 0
|
|
|
|
+ game.outlinePass.edgeStrength = 4
|
|
|
|
+ game.outlinePass.pulsePeriod = 4
|
|
|
|
+ game.outlinePass.visibleEdgeColor = new THREE.Color(1, 1, 1)
|
|
|
|
+ game.outlinePass.hiddenEdgeColor = new THREE.Color(1, 1, 1)
|
|
|
|
+
|
|
|
|
+ const gammaCorrection = new ShaderPass( GammaCorrectionShader )
|
|
|
|
+
|
|
|
|
+ const outputPass = new OutputPass()
|
|
|
|
+
|
|
|
|
+ game.effectComposer = new EffectComposer(game.renderer)
|
|
|
|
+ game.effectComposer.addPass(renderPass)
|
|
|
|
+ game.effectComposer.addPass(game.outlinePass)
|
|
|
|
+ game.effectComposer.addPass(bloomPass)
|
|
|
|
+ // game.effectComposer.addPass( gammaCorrection )
|
|
|
|
+ game.effectComposer.addPass(outputPass)
|
|
|
|
+
|
|
game.orbitControls = new OrbitControls(game.camera, game.renderer.domElement)
|
|
game.orbitControls = new OrbitControls(game.camera, game.renderer.domElement)
|
|
game.orbitControls.enabled = false
|
|
game.orbitControls.enabled = false
|
|
onResize()
|
|
onResize()
|
|
@@ -40,7 +77,7 @@ function loaded() {
|
|
document.getElementById("loading").style.display = "none"
|
|
document.getElementById("loading").style.display = "none"
|
|
game.clock.start()
|
|
game.clock.start()
|
|
attachAnimationFrame()
|
|
attachAnimationFrame()
|
|
- })
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
function onResize() {
|
|
function onResize() {
|
|
@@ -52,13 +89,15 @@ function onResize() {
|
|
}
|
|
}
|
|
|
|
|
|
function renderOneFrame() {
|
|
function renderOneFrame() {
|
|
-
|
|
|
|
|
|
+
|
|
update(game)
|
|
update(game)
|
|
game.orbitControls.update()
|
|
game.orbitControls.update()
|
|
- if(!game.orbitControls.enabled) {
|
|
|
|
|
|
+ if (!game.orbitControls.enabled) {
|
|
game.camera.lookAt(game.lookAtFocus)
|
|
game.camera.lookAt(game.lookAtFocus)
|
|
}
|
|
}
|
|
- game.renderer.render(game.scene, game.camera)
|
|
|
|
|
|
+
|
|
|
|
+ game.effectComposer.render()
|
|
|
|
+ //game.renderer.render(game.scene, game.camera)
|
|
}
|
|
}
|
|
|
|
|
|
function attachAnimationFrame() {
|
|
function attachAnimationFrame() {
|
|
@@ -75,16 +114,16 @@ export default async function main(canvasElement) {
|
|
game.mousePosition.y = -2 * (event.clientY / game.canvas.offsetHeight - 0.5)
|
|
game.mousePosition.y = -2 * (event.clientY / game.canvas.offsetHeight - 0.5)
|
|
})
|
|
})
|
|
game.canvas.addEventListener('touchmove', event => {
|
|
game.canvas.addEventListener('touchmove', event => {
|
|
- if(event.touches.length == 1) {
|
|
|
|
- game.mousePosition.x = 2 * ( event.touches[0].clientX / game.canvas.offsetWidth - 0.5)
|
|
|
|
- game.mousePosition.y = -2 * ( event.touches[0].clientY / game.canvas.offsetHeight - 0.5)
|
|
|
|
|
|
+ if (event.touches.length == 1) {
|
|
|
|
+ game.mousePosition.x = 2 * (event.touches[0].clientX / game.canvas.offsetWidth - 0.5)
|
|
|
|
+ game.mousePosition.y = -2 * (event.touches[0].clientY / game.canvas.offsetHeight - 0.5)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
game.canvas.addEventListener('touchstart', event => {
|
|
game.canvas.addEventListener('touchstart', event => {
|
|
- if(event.touches.length == 1) {
|
|
|
|
- game.mousePosition.x = 2 * ( event.touches[0].clientX / game.canvas.offsetWidth - 0.5)
|
|
|
|
- game.mousePosition.y = -2 * ( event.touches[0].clientY / game.canvas.offsetHeight - 0.5)
|
|
|
|
|
|
+ if (event.touches.length == 1) {
|
|
|
|
+ game.mousePosition.x = 2 * (event.touches[0].clientX / game.canvas.offsetWidth - 0.5)
|
|
|
|
+ game.mousePosition.y = -2 * (event.touches[0].clientY / game.canvas.offsetHeight - 0.5)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
game.canvas.addEventListener('mousedown', event => {
|
|
game.canvas.addEventListener('mousedown', event => {
|