Skip to content

Instantly share code, notes, and snippets.

View Ctrlmonster's full-sized avatar

Brian Breiholz Ctrlmonster

View GitHub Profile
@Ctrlmonster
Ctrlmonster / extract-root-motion.ts
Last active January 17, 2024 08:55
extract the root motion from a three.js AnimationClip
// Adapted from https://github.com/donmccurdy/three.js/blob/feat/extract-root-motion/examples/jsm/utils/SkeletonUtils.js#L606
import {AnimationClip, Bone, BufferAttribute, Object3D, Quaternion, Vector3, Vector4} from "three";
function getRootBone(rootNode: Object3D) {
const rootBones: Bone[] = [];
rootNode.traverse(function (object) {
// @ts-ignore
@Ctrlmonster
Ctrlmonster / makeContinuable.ts
Created January 6, 2023 18:45
small helper function to promisify via callbacks
export type Work = (...args: any[]) => any;
// Pass a function that provides a callback as single argument and returns another function F that calls that
// callback at some point. The result of makeContinuable will be a function that returns a promise that will
// resolve to the return value of F, once the callback is called.
export function makeContinuable<F extends Work>(wrapperFn: (cb: () => void) => F) {
return async (...args: Parameters<F>) => {
const outerPromise = new Promise<ReturnType<F>>(async (resolve1) => {
let res = null as ReturnType<F>;
// create another promise in whose executioner we'll call the passed function