Skip to content

Commit

Permalink
feat(playcanvas): cached quat factory
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Sep 26, 2019
1 parent 34dc1e9 commit 7beb643
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/adapter/playcanvas.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
import {
operatorCalc, cachedValueOf, defineVectorLength, cachedFactory
operatorCalc, cachedValueOf, defineVectorLength, cachedFactory, cachedFunction
} from '../operator';

function fallbackWindow() {
Expand Down Expand Up @@ -59,9 +59,15 @@ export function hijackPlayCanvas(pc) {
throw new Error('set up not allowed');
}
});
Quat.fromDir = function (dir, up = Vec3.UP) {
return new Quat().setFromMat4(new Mat4().setLookAt(Vec3.ZERO, dir, up));
};
pc.quat = cachedFunction((x, y, z, w) => {
if (typeof dir === 'number') {
return new Quat(x, y, z, w);
}
if (!x) {
return new Quat();
}
return new Quat().setFromMat4(new Mat4().setLookAt(Vec3.ZERO, x, y || Vec3.UP));
});
}

// eslint-disable-next-line no-undef
Expand Down
4 changes: 4 additions & 0 deletions src/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,7 @@ export function defineVectorLength(VectorClass, value) {
export function cachedFactory(VectorClass) {
return bindCache((...args) => new VectorClass(...args));
}

export function cachedFunction(realFactory) {
return bindCache((...args) => realFactory(...args));
}

0 comments on commit 7beb643

Please sign in to comment.