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 "callByType" returning only undefined values; add cosine interpolation to vec3 #102

Open
wants to merge 4 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
4 changes: 2 additions & 2 deletions viewer/animatedvec3.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class AnimatedVec3 {
t = 1;
b = true;
}
vec3.lerp(this.tmp, this.a, this.b, t);
vec3.cerp(this.tmp, this.a, this.b, t);
if (b) {
if (this.t2) {
this.t0 = this.t1;
Expand Down Expand Up @@ -73,4 +73,4 @@ export class AnimatedVec3 {
}
}

AnimatedVec3.ACTIVE_ANIMATIONS = 0;
AnimatedVec3.ACTIVE_ANIMATIONS = 0;
21 changes: 21 additions & 0 deletions viewer/glmatrix/vec3.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,27 @@ export function lerp(out, a, b, t) {
return out;
}

/**
* Performs a cosine interpolation between two vec3's
*
* @param {vec3} out the receiving vector
* @param {ReadonlyVec3} a the first operand
* @param {ReadonlyVec3} b the second operand
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
* @returns {vec3} out
*/
export function cerp(out, a, b, t) {
let ax = a[0];
let ay = a[1];
let az = a[2];

let delta = (1-Math.cos(t*Math.PI))/2;
out[0] = ax + delta * (b[0] - ax);
out[1] = ay + delta * (b[1] - ay);
out[2] = az + delta * (b[2] - az);
return out;
}

/**
* Performs a hermite interpolation with two control points
*
Expand Down
2 changes: 1 addition & 1 deletion viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Viewer {
callByType(method, types, ...args) {
let elems = types.map((i) => this.viewObjectsByType.get(i) || [])
.reduce((a, b) => a.concat(b), [])
.map((o) => o.oid);
.map((o) => o.uniqueId);
// Assuming all passed methods return a promise
return method.call(this, elems, ...args);
}
Expand Down