I really had to dig in the FB group for this one. Here’s a script from Jamie Poole from 2018! I haven’t tested it, but maybe it will work for you. You’ll need to use the new syntax for finding scene objects, but other than that I think it will do the trick.
const Scene = require('Scene');
const Diagnostics = require('Diagnostics');
class WorldToPixels {
constructor() {
this.Scene = require('Scene');
this.Patches = require('Patches');
this.camera = this.Scene.root.child('Device').child('Camera');
this.screenSize = this.Patches.getPoint2DValue('screenSize');
this.widthTan = this.camera.focalPlane.width.div(2).div(this.camera.focalPlane.distance);
this.heightTan = this.camera.focalPlane.height.div(2).div(this.camera.focalPlane.distance);
}
convert(objectToTrack) {
let focalPlaneWidthAtObject = objectToTrack.worldTransform.z.mul(this.widthTan).mul(2);
let focalPlaneHeightAtObject = objectToTrack.worldTransform.z.mul(this.heightTan).mul(2);
let pixelX = this.screenSize.x.div(focalPlaneWidthAtObject).mul(objectToTrack.worldTransform.x).mul(-1).add(this.screenSize.x.div(2));
let pixelY = this.screenSize.y.div(focalPlaneHeightAtObject).mul(objectToTrack.worldTransform.y).mul(-1).add(this.screenSize.y.div(2));
return {
x: pixelX,
y: pixelY
};
}
}
let wp = new WorldToPixels();
let FaceMeshPixelPositions = wp.convert(Scene.root.find('FaceMesh'));
Diagnostics.watch('FaceMesh Pixel X', FaceMeshPixelPositions.x);
Diagnostics.watch('FaceMesh Pixel Y', FaceMeshPixelPositions.y);