Skip to content

Commit 575052d

Browse files
add env map & update build workflow
1 parent 063aba4 commit 575052d

File tree

7 files changed

+48
-8
lines changed

7 files changed

+48
-8
lines changed

.github/workflows/build_and_deploy.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ jobs:
1010
- name: Checkout 🛎️
1111
uses: actions/checkout@v2
1212

13+
- name: Setup Node.js 12.22.12
14+
uses: actions/setup-node@v2
15+
with:
16+
node-version: 12.22.12
17+
18+
- name: Install Yarn
19+
run: npm install -g yarn
20+
1321
- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
1422
env:
1523
PUBLIC_PATH: https://breathingcyborg.github.io/mediapipe-face-effects/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@mediapipe/drawing_utils": "^0.3.1620248257",
1818
"@mediapipe/face_mesh": "^0.4.1633559619",
1919
"core-js": "2",
20-
"three": "^0.136.0"
20+
"three": "^0.174.0"
2121
},
2222
"devDependencies": {
2323
"@babel/core": "^7.16.7",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as THREE from 'three';
2+
import { RoomEnvironment } from 'three/examples/jsm/environments/RoomEnvironment.js';
3+
4+
export class Environment {
5+
constructor(scene, renderer) {
6+
this.scene = scene;
7+
this.renderer = renderer;
8+
this.setup();
9+
}
10+
11+
async setup() {
12+
const pmremGenerator = new THREE.PMREMGenerator( this.renderer );
13+
this.scene.environment = pmremGenerator.fromScene( new RoomEnvironment(), 0.04 ).texture;
14+
}
15+
}

src/js/three_components/scene_manager.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as THREE from 'three';
22
import { FaceMask } from './face_mask';
33
import { Glasses } from './glasses';
44
import { VideoBackground } from './video_bg';
5-
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
5+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
6+
import { Environment } from './environment';
67

78
/**
89
*
@@ -32,14 +33,24 @@ export class SceneManager {
3233
this.useOrtho = useOrtho;
3334
this.renderer = new THREE.WebGLRenderer({
3435
canvas: this.canvas,
35-
devicePixelRation: window.devicePixelRatio || 1
36+
devicePixelRation: window.devicePixelRatio || 1,
37+
antialias: true,
3638
});
39+
this.renderer.outputColorSpace = THREE.SRGBColorSpace;
40+
this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
41+
this.renderer.toneMappingExposure = 1;
42+
3743
this.fov = 63;
3844
this.buildCamera();
3945
this.buildControls();
4046
this.buildVideoBg();
4147
this.buildFaceMask();
4248
this.buildGlasses();
49+
this.buildEnvironment();
50+
}
51+
52+
buildEnvironment() {
53+
this.environment = new Environment(this.scene, this.renderer);
4354
}
4455

4556
buildVideoBg() {

src/js/three_components/video_bg.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ export class VideoBackground {
5252
color: new THREE.Color(0xcccccc)
5353
});
5454
}
55+
56+
const videoTexture = new THREE.CanvasTexture(this.image);
57+
videoTexture.colorSpace = THREE.SRGBColorSpace;
58+
5559
let material = new THREE.MeshBasicMaterial({
56-
map: new THREE.CanvasTexture(this.image),
60+
map: videoTexture,
5761
});
5862
return material;
5963
}

src/styles.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ body {
66
.video-container {
77
display: flex;
88
flex-direction: column;
9-
max-width: 1024px;
9+
max-width: 100%;
10+
padding: 0 2rem;
1011
margin: 0 auto;
1112
position: relative;
1213
}

yarn.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,9 +3061,10 @@ terser@^5.10.0, terser@^5.7.2:
30613061
source-map "~0.7.2"
30623062
source-map-support "~0.5.20"
30633063

3064-
three@^0.136.0:
3065-
version "0.136.0"
3066-
resolved "https://registry.yarnpkg.com/three/-/three-0.136.0.tgz#b1504db021b46398ef468aa7849f3dcabb814f50"
3064+
three@^0.174.0:
3065+
version "0.174.0"
3066+
resolved "https://registry.yarnpkg.com/three/-/three-0.174.0.tgz#53f46d6fd27515231b2af321f798f1e0ecf3f905"
3067+
integrity sha512-p+WG3W6Ov74alh3geCMkGK9NWuT62ee21cV3jEnun201zodVF4tCE5aZa2U122/mkLRmhJJUQmLLW1BH00uQJQ==
30673068

30683069
thunky@^1.0.2:
30693070
version "1.1.0"

0 commit comments

Comments
 (0)