Skip to content

Commit 89fa7ad

Browse files
committed
default flip face in face tracking selfie mode
1 parent 1ad668d commit 89fa7ad

10 files changed

+33
-16
lines changed

examples/face-tracking/example1.html

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
position: absolute;
1919
width: 100%;
2020
height: 100%;
21-
transform: scaleX(-1);
2221
}
2322
</style>
2423
</head>

examples/face-tracking/example2.html

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
position: absolute;
4444
width: 100%;
4545
height: 100%;
46-
transform: scaleX(-1);
4746
}
4847
.options-panel {
4948
position: fixed;

examples/face-tracking/example3.html

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
position: absolute;
5959
width: 100%;
6060
height: 100%;
61-
transform: scaleX(-1);
6261
}
6362

6463
#example-control-overlay {

examples/face-tracking/three-css.html

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
height: 100vh;
3232
position: relative;
3333
overflow: hidden;
34-
transform: scaleX(-1);
3534
}
3635
#ar-div {
3736
width: 1000px;
@@ -46,7 +45,6 @@
4645
color: white;
4746
}
4847
#ar-div > div {
49-
transform: scaleX(-1);
5048
}
5149
</style>
5250
</head>

examples/face-tracking/three-facemesh.html

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
height: 100vh;
3939
position: relative;
4040
overflow: hidden;
41-
transform: scaleX(-1);
4241
}
4342
</style>
4443
</head>

examples/face-tracking/three.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
filterMinCF: 0.001,
2222
filterBeta: 10,
2323
userDeviceId,
24-
environmentDeviceId
24+
environmentDeviceId,
2525
});
2626

2727
const anchor = mindarThree.addAnchor(1);
@@ -94,7 +94,6 @@
9494
height: 100vh;
9595
position: relative;
9696
overflow: hidden;
97-
transform: scaleX(-1);
9897
}
9998

10099
#control {

src/face-target/aframe.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ AFRAME.registerSystem('mindar-face-system', {
88
video: null,
99
shouldFaceUser: true,
1010
lastHasFace: false,
11+
disableFaceMirror: false,
1112

1213
init: function() {
1314
this.anchorEntities = [];
1415
this.faceMeshEntities = [];
1516
},
1617

17-
setup: function({uiLoading, uiScanning, uiError, filterMinCF, filterBeta}) {
18+
setup: function({uiLoading, uiScanning, uiError, filterMinCF, filterBeta, disableFaceMirror}) {
1819
this.ui = new UI({uiLoading, uiScanning, uiError});
1920
this.filterMinCF = filterMinCF;
2021
this.filterBeta = filterBeta;
22+
this.disableFaceMirror = disableFaceMirror;
2123
},
2224

2325
registerFaceMesh: function(el) {
@@ -160,7 +162,9 @@ AFRAME.registerSystem('mindar-face-system', {
160162
});
161163
this._resize();
162164

163-
await this.controller.setup();
165+
const flipFace = this.shouldFaceUser && !this.disableFaceMirror;
166+
167+
await this.controller.setup(flipFace);
164168
await this.controller.dummyRun(this.video);
165169

166170
for (let i = 0; i < this.faceMeshEntities.length; i++) {
@@ -208,6 +212,12 @@ AFRAME.registerSystem('mindar-face-system', {
208212
this.video.style.width = vw + "px";
209213
this.video.style.height = vh + "px";
210214

215+
if (this.shouldFaceUser && !this.disableFaceMirror) {
216+
video.style.transform = 'scaleX(-1)';
217+
} else {
218+
video.style.transform = 'scaleX(1)';
219+
}
220+
211221
const sceneEl = container.getElementsByTagName("a-scene")[0];
212222
sceneEl.style.top = this.video.style.top;
213223
sceneEl.style.left = this.video.style.left;
@@ -227,6 +237,7 @@ AFRAME.registerComponent('mindar-face', {
227237
uiError: {type: 'string', default: 'yes'},
228238
filterMinCF: {type: 'number', default: -1},
229239
filterBeta: {type: 'number', default: -1},
240+
disableFaceMirror: {type: 'boolean', default: 'false'},
230241
},
231242

232243
init: function() {
@@ -244,6 +255,7 @@ AFRAME.registerComponent('mindar-face', {
244255
uiError: this.data.uiError,
245256
filterMinCF: this.data.filterMinCF === -1? null: this.data.filterMinCF,
246257
filterBeta: this.data.filterBeta === -1? null: this.data.filterBeta,
258+
disableFaceMirror: this.data.disableFaceMirror,
247259
});
248260

249261
if (this.data.autoStart) {

src/face-target/controller.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Controller {
2727
this.faceScaleFilter = new OneEuroFilter({minCutOff: this.filterMinCF, beta: this.filterBeta});
2828
}
2929

30-
async setup() {
30+
async setup(flipFace) {
3131
await waitCV();
32-
this.faceMeshHelper = new FaceMeshHelper();
32+
this.faceMeshHelper = new FaceMeshHelper(flipFace);
3333
}
3434

3535
onInputResized(input) {

src/face-target/face-mesh-helper.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {FaceMesh} from "@mediapipe/face_mesh";
22

33
class FaceMeshHelper {
4-
constructor() {
4+
constructor(flipFace) {
55
this.detectResolve = null;
66

77
let _FaceMesh = FaceMesh;
@@ -14,12 +14,15 @@ class FaceMeshHelper {
1414
return `https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/${file}`;
1515
}});
1616

17+
console.log("flipFace", flipFace);
18+
1719
this.faceMesh.setOptions({
1820
maxNumFaces: 1,
1921
//refineLandmarks: true,
2022
refineLandmarks: false,
2123
minDetectionConfidence: 0.5,
22-
minTrackingConfidence: 0.5
24+
minTrackingConfidence: 0.5,
25+
selfieMode: flipFace
2326
});
2427

2528
this.faceMesh.onResults((results) => {

src/face-target/three.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const THREE={BufferGeometry,BufferAttribute};
88

99
export class MindARThree {
1010
constructor({container, uiLoading="yes", uiScanning="yes", uiError="yes", filterMinCF=null, filterBeta=null,
11-
userDeviceId = null, environmentDeviceId = null
11+
userDeviceId = null, environmentDeviceId = null, disableFaceMirror = false,
1212
}) {
1313
this.container = container;
1414
this.ui = new UI({ uiLoading, uiScanning, uiError });
@@ -17,6 +17,7 @@ export class MindARThree {
1717
filterMinCF: filterMinCF,
1818
filterBeta: filterBeta,
1919
});
20+
this.disableFaceMirror = disableFaceMirror;
2021
this.scene = new Scene();
2122
this.cssScene = new Scene();
2223
this.renderer = new WebGLRenderer({ antialias: true, alpha: true });
@@ -183,7 +184,9 @@ export class MindARThree {
183184
}
184185
this._resize();
185186

186-
await this.controller.setup();
187+
const flipFace = this.shouldFaceUser && !this.disableFaceMirror;
188+
189+
await this.controller.setup(flipFace);
187190
await this.controller.dummyRun(video);
188191

189192
this._resize();
@@ -227,6 +230,12 @@ export class MindARThree {
227230
video.style.width = vw + "px";
228231
video.style.height = vh + "px";
229232

233+
if (this.shouldFaceUser && !this.disableFaceMirror) {
234+
video.style.transform = 'scaleX(-1)';
235+
} else {
236+
video.style.transform = 'scaleX(1)';
237+
}
238+
230239
const canvas = renderer.domElement;
231240
const cssCanvas = cssRenderer.domElement;
232241

0 commit comments

Comments
 (0)