@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
71 lines (63 loc) • 1.91 kB
JavaScript
import { Matrix } from "@visactor/vutils";
import { identityMat4 } from "../common/matrix";
export const MatrixAllocate = Symbol.for("MatrixAllocate");
export const Mat4Allocate = Symbol.for("Mat4Allocate");
export function createMat4() {
return [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ];
}
export class DefaultMatrixAllocate {
constructor() {
this.pools = [];
}
allocate(a, b, c, d, e, f) {
if (!this.pools.length) return new Matrix(a, b, c, d, e, f);
const m = this.pools.pop();
return m.a = a, m.b = b, m.c = c, m.d = d, m.e = e, m.f = f, m;
}
allocateByObj(matrix) {
if (!this.pools.length) return new Matrix(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
const m = this.pools.pop();
return m.a = matrix.a, m.b = matrix.b, m.c = matrix.c, m.d = matrix.d, m.e = matrix.e,
m.f = matrix.f, m;
}
free(d) {
this.pools.push(d);
}
get length() {
return this.pools.length;
}
release(...params) {
this.pools = [];
}
}
export class DefaultMat4Allocate {
constructor() {
this.pools = [];
}
static identity(out) {
return identityMat4(out);
}
allocate() {
if (!this.pools.length) return createMat4();
const m = this.pools.pop();
return DefaultMat4Allocate.identity(m), m;
}
allocateByObj(d) {
let m;
m = this.pools.length ? this.pools.pop() : createMat4();
for (let i = 0; i < m.length; i++) m[i] = d[i];
return m;
}
free(m) {
m && this.pools.push(m);
}
get length() {
return this.pools.length;
}
release(...params) {
this.pools = [];
}
}
export const matrixAllocate = new DefaultMatrixAllocate;
export const mat4Allocate = new DefaultMat4Allocate;
//# sourceMappingURL=matrix-allocate.js.map