@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
29 lines (28 loc) • 824 B
JavaScript
;
import { Vector3 } from "three";
import { randFloat } from "../../math/_Module";
const _offset = new Vector3();
const _p = new Vector3();
const _points = [];
export function jitterOffset(i, seed, mult, amount, target) {
target.set(
2 * (randFloat(i * 75 + 764 + seed) - 0.5),
2 * (randFloat(i * 5678 + 3653 + seed) - 0.5),
2 * (randFloat(i * 657 + 48464 + seed) - 0.5)
);
target.normalize();
target.multiply(mult);
target.multiplyScalar(amount * randFloat(i * 78 + 54 + seed));
}
export function jitterPositions(coreGroup, options) {
const { amount, mult, seed } = options;
coreGroup.points(_points);
let i = 0;
for (const point of _points) {
jitterOffset(i, seed, mult, amount, _offset);
point.position(_p);
_p.add(_offset);
point.setPosition(_p);
i++;
}
}