Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wiggle expression #3132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
"no-param-reassign": "off",
"vars-on-top": "off",
"no-use-before-define": "off",
"-------": "off"
"-------": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"puppeteer": "^20.5.0",
"rollup": "^2.61.0",
"rollup-plugin-terser": "^7.0.2",
"simplex-noise": "^4.0.3",
"uglify-js": "^3.4.9",
"watch": "^1.0.2"
},
Expand Down
46 changes: 19 additions & 27 deletions player/js/utils/expressions/ExpressionManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable camelcase */
import { createNoise2D } from 'simplex-noise';

import {
degToRads,
Expand Down Expand Up @@ -442,36 +443,27 @@ const ExpressionManager = (function () {

var active = !this.data || this.data.hd !== true;

var noise;

var wiggle = function wiggle(freq, amp) {
var iWiggle;
var j;
var lenWiggle = this.pv.length ? this.pv.length : 1;
var addedAmps = createTypedArray('float32', lenWiggle);
freq = 5;
var iterations = Math.floor(time * freq);
iWiggle = 0;
j = 0;
while (iWiggle < iterations) {
// var rnd = BMMath.random();
for (j = 0; j < lenWiggle; j += 1) {
addedAmps[j] += -amp + amp * 2 * BMMath.random();
// addedAmps[j] += -amp + amp*2*rnd;
}
iWiggle += 1;
}
// var rnd2 = BMMath.random();
var periods = time * freq;
var perc = periods - Math.floor(periods);
var arr = createTypedArray('float32', lenWiggle);
if (lenWiggle > 1) {
for (j = 0; j < lenWiggle; j += 1) {
arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc;
// arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
// arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
if (!noise) noise = createNoise2D();

const noisePosition = (time * freq) / 2;

if (this.pv.length) {
const result = createTypedArray('float32', this.pv.length);

for (let i = 0; i < this.pv.length; i += 1) {
const noiseValue = noise(noisePosition, i) * amp;

result[i] = this.pv[i] + noiseValue;
}
return arr;

return result;
}
return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc;

const noiseValue = noise(noisePosition, 0) * amp;
return this.pv + noiseValue;
}.bind(this);

if (thisProperty.loopIn) {
Expand Down