Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions examples/ar-avatar.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<!-- Scene -->
<pc-scene>
<!-- Camera -->
<pc-entity name="camera" position="0 0 1">
<pc-entity name="camera">
<pc-camera clear-color="0 0 0 0" fov="80"></pc-camera>
<pc-scripts>
<pc-script name="cameraFeed"></pc-script>
Expand All @@ -37,7 +37,7 @@
<pc-light></pc-light>
</pc-entity>
<!-- Raccoon Avatar -->
<pc-entity name="raccoon" scale="-1 1 1">
<pc-entity name="raccoon" scale="100 100 100">
<pc-model asset="raccoon"></pc-model>
<pc-scripts>
<pc-script name="morphUpdate"></pc-script>
Expand Down
2 changes: 1 addition & 1 deletion examples/assets/scripts/camera-feed.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class CameraFeed extends Script {
* @type {boolean}
* @attribute
*/
mirror = true;
mirror = false;

/**
* @type {HTMLVideoElement|null}
Expand Down
12 changes: 11 additions & 1 deletion examples/assets/scripts/face-landmarks.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FaceLandmarker, FilesetResolver } from '@mediapipe/tasks-vision';
import { Script } from 'playcanvas';
import { Mat4, Script } from 'playcanvas';

export class FaceLandmarks extends Script {
/** @type {FaceLandmarker} */
Expand Down Expand Up @@ -27,6 +27,16 @@ export class FaceLandmarks extends Script {
if (video && video.readyState >= HTMLMediaElement.HAVE_ENOUGH_DATA) {
const detections = this.faceLandmarker.detectForVideo(video, Date.now());
if (detections && detections.faceBlendshapes) {
if (detections.facialTransformationMatrixes.length > 0) {
const { data } = detections.facialTransformationMatrixes[0];
const matrix = new Mat4();
matrix.set(data).invert();
const position = matrix.getTranslation();
const rotation = matrix.getEulerAngles();
this.entity.setPosition(position);
this.entity.setEulerAngles(rotation);
}

if (detections.faceBlendshapes.length > 0) {
const { categories } = detections.faceBlendshapes[0];
this.app.fire('face:blendshapes', categories);
Expand Down