Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yearofthewhopper/f4b21cdbdee8b4a90da9f66bff06fc90 to your computer and use it in GitHub Desktop.
Save yearofthewhopper/f4b21cdbdee8b4a90da9f66bff06fc90 to your computer and use it in GitHub Desktop.
import Scene from 'Scene';
import FaceTracking from 'FaceTracking';
import Animation from 'Animation';
/*
Model structure:
- Model
- skeleton (null)
- Armatures (null objs)
- Petal & pollen (meshes)
- Bone*000
- Bone*[ODD]
- Bone*[EVEN]
*/
(async function () {
let modelRotationSignalValues: {[key: string]: number[]} = {};
// Get all scene objects
const [armatures, bones]: SceneObjectBase[][] = await Promise.all([
Scene.root.findByPath('**/skeleton/Arm*'),
Scene.root.findByPath('**/skeleton/**/Bone*'),
]);
// Sort
bones.sort((a, b) => {
return a.name.localeCompare(b.name);
});
// Store the value of the model bone rotations
bones.forEach(b=>{
modelRotationSignalValues[b.name] = [
b.transform.rotationX.pinLastValue(),
b.transform.rotationY.pinLastValue(),
b.transform.rotationZ.pinLastValue(),
];
});
// Star antenna :)
const faceSignalX = FaceTracking.face(0).cameraTransform.x.expSmooth(100);
const faceSignalX2 = FaceTracking.face(0).cameraTransform.x.expSmooth(96);
const faceSignalY = FaceTracking.face(0).cameraTransform.y.expSmooth(100);
const faceSignalY2 = FaceTracking.face(0).cameraTransform.y.expSmooth(96);
const generalScaleFactor = -3000;
bones.forEach((b, i)=>{
// Ignore the first bone of every armature
if (b.name.indexOf('000') != -1) return;
// Factor depending on the bone position
// The bones close to the tip of the petal should move more up and down, and less side to side
let boneFactor: number = Number(b.name.slice(-3)) % 2;
let boneFactorX = Math.max(1 - boneFactor, 0.5) * generalScaleFactor * 0.5;
let boneFactorZ = boneFactor * generalScaleFactor * 0.35;
let signalX = faceSignalY2.sub(faceSignalY).mul(boneFactorX);
let signalZ = faceSignalX2.sub(faceSignalX).mul(boneFactorZ);
b.transform.rotationX = signalX.add(signalZ.abs()) .add(modelRotationSignalValues[b.name][0]);
b.transform.rotationZ = signalZ.neg() .add(modelRotationSignalValues[b.name][2]);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment