@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
38 lines (28 loc) • 848 B
JavaScript
import { Vector3 } from "three";
/**
* some useful references:
* https://stackoverflow.com/questions/29438398/cheap-way-of-calculating-cubic-bezier-length
* https://stackoverflow.com/questions/1147249/connecting-catmull-rom-splines-together-and-calculating-its-length
* @param {Path} path
* @param {number} epsilon
*/
export function estimatePathViaIterativeIntegral(path, epsilon) {
let sum = 0;
let p0 = new Vector3();
let p1 = new Vector3();
if (!path.sample(p0, 0)) {
// path has 0 length
return 0;
}
for (let p = epsilon; ; p += epsilon) {
const ended = path.sample(p1, p);
if (ended) {
break;
}
sum += p0.distanceTo(p1);
const swap = p1;
p1 = p0;
p0 = swap;
}
return sum;
}