matrix-engine-wgpu
Version:
+HOTFIX raycast, webGPU powered pwa application. Crazy fast rendering with AmmoJS physics support. Simple raycaster hit object added.
1,656 lines (1,647 loc) • 331 kB
JavaScript
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.application = void 0;
var _world = _interopRequireDefault(require("./src/world.js"));
var _loaderObj = require("./src/engine/loader-obj.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
let application = exports.application = new _world.default({
useSingleRenderPass: false,
canvasSize: 'fullscreen'
}, () => {
window.app = application;
// for now
window.downloadMeshes = _loaderObj.downloadMeshes;
console.info(`%c matrix-engine-wgpu [ready]`, LOG_MATRIX);
});
},{"./src/engine/loader-obj.js":6,"./src/world.js":19}],2:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.quat = exports.mat4 = exports.mat3 = void 0;
exports.setDefaultType = setDefaultType;
exports.vec4 = exports.vec3 = exports.vec2 = exports.utils = void 0;
/* wgpu-matrix@2.5.1, license MIT */
/*
* Copyright 2022 Gregg Tavares
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
let EPSILON = 0.000001;
/**
* Set the value for EPSILON for various checks
* @param v - Value to use for EPSILON.
* @returns previous value of EPSILON;
*/
function setEpsilon(v) {
const old = EPSILON;
EPSILON = v;
return old;
}
/**
* Convert degrees to radians
* @param degrees - Angle in degrees
* @returns angle converted to radians
*/
function degToRad(degrees) {
return degrees * Math.PI / 180;
}
/**
* Convert radians to degrees
* @param radians - Angle in radians
* @returns angle converted to degrees
*/
function radToDeg(radians) {
return radians * 180 / Math.PI;
}
/**
* Lerps between a and b via t
* @param a - starting value
* @param b - ending value
* @param t - value where 0 = a and 1 = b
* @returns a + (b - a) * t
*/
function lerp$4(a, b, t) {
return a + (b - a) * t;
}
/**
* Compute the opposite of lerp. Given a and b and a value between
* a and b returns a value between 0 and 1. 0 if a, 1 if b.
* Note: no clamping is done.
* @param a - start value
* @param b - end value
* @param v - value between a and b
* @returns (v - a) / (b - a)
*/
function inverseLerp(a, b, v) {
const d = b - a;
return Math.abs(b - a) < EPSILON ? a : (v - a) / d;
}
/**
* Compute the euclidean modulo
*
* ```
* // table for n / 3
* -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 <- n
* ------------------------------------
* -2 -1 -0 -2 -1 0, 1, 2, 0, 1, 2 <- n % 3
* 1 2 0 1 2 0, 1, 2, 0, 1, 2 <- euclideanModule(n, 3)
* ```
*
* @param n - dividend
* @param m - divisor
* @returns the euclidean modulo of n / m
*/
function euclideanModulo(n, m) {
return (n % m + m) % m;
}
var utils = exports.utils = /*#__PURE__*/Object.freeze({
__proto__: null,
get EPSILON() {
return EPSILON;
},
setEpsilon: setEpsilon,
degToRad: degToRad,
radToDeg: radToDeg,
lerp: lerp$4,
inverseLerp: inverseLerp,
euclideanModulo: euclideanModulo
});
/*
* Copyright 2022 Gregg Tavares
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
*
* Vec2 math functions.
*
* Almost all functions take an optional `dst` argument. If it is not passed in the
* functions will create a new Vec2. In other words you can do this
*
* const v = vec2.cross(v1, v2); // Creates a new Vec2 with the cross product of v1 x v2.
*
* or
*
* const v = vec2.create();
* vec2.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v
*
* The first style is often easier but depending on where it's used it generates garbage where
* as there is almost never allocation with the second style.
*
* It is always safe to pass any vector as the destination. So for example
*
* vec2.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1
*
*/
let VecType$2 = Float32Array;
/**
* Sets the type this library creates for a Vec2
* @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`
* @returns previous constructor for Vec2
*/
function setDefaultType$6(ctor) {
const oldType = VecType$2;
VecType$2 = ctor;
return oldType;
}
/**
* Creates a Vec2; may be called with x, y, z to set initial values.
*
* Note: Since passing in a raw JavaScript array
* is valid in all circumstances, if you want to
* force a JavaScript array into a Vec2's specified type
* it would be faster to use
*
* ```
* const v = vec2.clone(someJSArray);
* ```
*
* Note: a consequence of the implementation is if your Vec2Type = `Array`
* instead of `Float32Array` or `Float64Array` then any values you
* don't pass in will be undefined. Usually this is not an issue since
* (a) using `Array` is rare and (b) using `vec2.create` is usually used
* to create a Vec2 to be filled out as in
*
* ```
* const sum = vec2.create();
* vec2.add(v1, v2, sum);
* ```
*
* @param x - Initial x value.
* @param y - Initial y value.
* @returns the created vector
*/
function create$5(x = 0, y = 0) {
const dst = new VecType$2(2);
if (x !== undefined) {
dst[0] = x;
if (y !== undefined) {
dst[1] = y;
}
}
return dst;
}
/*
* Copyright 2022 Gregg Tavares
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
*
* Vec3 math functions.
*
* Almost all functions take an optional `dst` argument. If it is not passed in the
* functions will create a new `Vec3`. In other words you can do this
*
* const v = vec3.cross(v1, v2); // Creates a new Vec3 with the cross product of v1 x v2.
*
* or
*
* const v = vec3.create();
* vec3.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v
*
* The first style is often easier but depending on where it's used it generates garbage where
* as there is almost never allocation with the second style.
*
* It is always safe to pass any vector as the destination. So for example
*
* vec3.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1
*
*/
let VecType$1 = Float32Array;
/**
* Sets the type this library creates for a Vec3
* @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`
* @returns previous constructor for Vec3
*/
function setDefaultType$5(ctor) {
const oldType = VecType$1;
VecType$1 = ctor;
return oldType;
}
/**
* Creates a vec3; may be called with x, y, z to set initial values.
* @param x - Initial x value.
* @param y - Initial y value.
* @param z - Initial z value.
* @returns the created vector
*/
function create$4(x, y, z) {
const dst = new VecType$1(3);
if (x !== undefined) {
dst[0] = x;
if (y !== undefined) {
dst[1] = y;
if (z !== undefined) {
dst[2] = z;
}
}
}
return dst;
}
/*
* Copyright 2022 Gregg Tavares
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
* Creates a Vec2; may be called with x, y, z to set initial values. (same as create)
* @param x - Initial x value.
* @param y - Initial y value.
* @returns the created vector
*/
const fromValues$3 = create$5;
/**
* Sets the values of a Vec2
* Also see {@link vec2.create} and {@link vec2.copy}
*
* @param x first value
* @param y second value
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector with its elements set.
*/
function set$5(x, y, dst) {
dst = dst || new VecType$2(2);
dst[0] = x;
dst[1] = y;
return dst;
}
/**
* Applies Math.ceil to each element of vector
* @param v - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector that is the ceil of each element of v.
*/
function ceil$2(v, dst) {
dst = dst || new VecType$2(2);
dst[0] = Math.ceil(v[0]);
dst[1] = Math.ceil(v[1]);
return dst;
}
/**
* Applies Math.floor to each element of vector
* @param v - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector that is the floor of each element of v.
*/
function floor$2(v, dst) {
dst = dst || new VecType$2(2);
dst[0] = Math.floor(v[0]);
dst[1] = Math.floor(v[1]);
return dst;
}
/**
* Applies Math.round to each element of vector
* @param v - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector that is the round of each element of v.
*/
function round$2(v, dst) {
dst = dst || new VecType$2(2);
dst[0] = Math.round(v[0]);
dst[1] = Math.round(v[1]);
return dst;
}
/**
* Clamp each element of vector between min and max
* @param v - Operand vector.
* @param max - Min value, default 0
* @param min - Max value, default 1
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector that the clamped value of each element of v.
*/
function clamp$2(v, min = 0, max = 1, dst) {
dst = dst || new VecType$2(2);
dst[0] = Math.min(max, Math.max(min, v[0]));
dst[1] = Math.min(max, Math.max(min, v[1]));
return dst;
}
/**
* Adds two vectors; assumes a and b have the same dimension.
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector that is the sum of a and b.
*/
function add$3(a, b, dst) {
dst = dst || new VecType$2(2);
dst[0] = a[0] + b[0];
dst[1] = a[1] + b[1];
return dst;
}
/**
* Adds two vectors, scaling the 2nd; assumes a and b have the same dimension.
* @param a - Operand vector.
* @param b - Operand vector.
* @param scale - Amount to scale b
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector that is the sum of a + b * scale.
*/
function addScaled$2(a, b, scale, dst) {
dst = dst || new VecType$2(2);
dst[0] = a[0] + b[0] * scale;
dst[1] = a[1] + b[1] * scale;
return dst;
}
/**
* Returns the angle in radians between two vectors.
* @param a - Operand vector.
* @param b - Operand vector.
* @returns The angle in radians between the 2 vectors.
*/
function angle$2(a, b) {
const ax = a[0];
const ay = a[1];
const bx = a[0];
const by = a[1];
const mag1 = Math.sqrt(ax * ax + ay * ay);
const mag2 = Math.sqrt(bx * bx + by * by);
const mag = mag1 * mag2;
const cosine = mag && dot$3(a, b) / mag;
return Math.acos(cosine);
}
/**
* Subtracts two vectors.
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector that is the difference of a and b.
*/
function subtract$3(a, b, dst) {
dst = dst || new VecType$2(2);
dst[0] = a[0] - b[0];
dst[1] = a[1] - b[1];
return dst;
}
/**
* Subtracts two vectors.
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A vector that is the difference of a and b.
*/
const sub$3 = subtract$3;
/**
* Check if 2 vectors are approximately equal
* @param a - Operand vector.
* @param b - Operand vector.
* @returns true if vectors are approximately equal
*/
function equalsApproximately$5(a, b) {
return Math.abs(a[0] - b[0]) < EPSILON && Math.abs(a[1] - b[1]) < EPSILON;
}
/**
* Check if 2 vectors are exactly equal
* @param a - Operand vector.
* @param b - Operand vector.
* @returns true if vectors are exactly equal
*/
function equals$5(a, b) {
return a[0] === b[0] && a[1] === b[1];
}
/**
* Performs linear interpolation on two vectors.
* Given vectors a and b and interpolation coefficient t, returns
* a + t * (b - a).
* @param a - Operand vector.
* @param b - Operand vector.
* @param t - Interpolation coefficient.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The linear interpolated result.
*/
function lerp$3(a, b, t, dst) {
dst = dst || new VecType$2(2);
dst[0] = a[0] + t * (b[0] - a[0]);
dst[1] = a[1] + t * (b[1] - a[1]);
return dst;
}
/**
* Performs linear interpolation on two vectors.
* Given vectors a and b and interpolation coefficient vector t, returns
* a + t * (b - a).
* @param a - Operand vector.
* @param b - Operand vector.
* @param t - Interpolation coefficients vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns the linear interpolated result.
*/
function lerpV$2(a, b, t, dst) {
dst = dst || new VecType$2(2);
dst[0] = a[0] + t[0] * (b[0] - a[0]);
dst[1] = a[1] + t[1] * (b[1] - a[1]);
return dst;
}
/**
* Return max values of two vectors.
* Given vectors a and b returns
* [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])].
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The max components vector.
*/
function max$2(a, b, dst) {
dst = dst || new VecType$2(2);
dst[0] = Math.max(a[0], b[0]);
dst[1] = Math.max(a[1], b[1]);
return dst;
}
/**
* Return min values of two vectors.
* Given vectors a and b returns
* [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])].
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The min components vector.
*/
function min$2(a, b, dst) {
dst = dst || new VecType$2(2);
dst[0] = Math.min(a[0], b[0]);
dst[1] = Math.min(a[1], b[1]);
return dst;
}
/**
* Multiplies a vector by a scalar.
* @param v - The vector.
* @param k - The scalar.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The scaled vector.
*/
function mulScalar$3(v, k, dst) {
dst = dst || new VecType$2(2);
dst[0] = v[0] * k;
dst[1] = v[1] * k;
return dst;
}
/**
* Multiplies a vector by a scalar. (same as mulScalar)
* @param v - The vector.
* @param k - The scalar.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The scaled vector.
*/
const scale$5 = mulScalar$3;
/**
* Divides a vector by a scalar.
* @param v - The vector.
* @param k - The scalar.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The scaled vector.
*/
function divScalar$3(v, k, dst) {
dst = dst || new VecType$2(2);
dst[0] = v[0] / k;
dst[1] = v[1] / k;
return dst;
}
/**
* Inverse a vector.
* @param v - The vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The inverted vector.
*/
function inverse$5(v, dst) {
dst = dst || new VecType$2(2);
dst[0] = 1 / v[0];
dst[1] = 1 / v[1];
return dst;
}
/**
* Invert a vector. (same as inverse)
* @param v - The vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The inverted vector.
*/
const invert$4 = inverse$5;
/**
* Computes the cross product of two vectors; assumes both vectors have
* three entries.
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The vector of a cross b.
*/
function cross$1(a, b, dst) {
dst = dst || new VecType$1(3);
const z = a[0] * b[1] - a[1] * b[0];
dst[0] = 0;
dst[1] = 0;
dst[2] = z;
return dst;
}
/**
* Computes the dot product of two vectors; assumes both vectors have
* three entries.
* @param a - Operand vector.
* @param b - Operand vector.
* @returns dot product
*/
function dot$3(a, b) {
return a[0] * b[0] + a[1] * b[1];
}
/**
* Computes the length of vector
* @param v - vector.
* @returns length of vector.
*/
function length$3(v) {
const v0 = v[0];
const v1 = v[1];
return Math.sqrt(v0 * v0 + v1 * v1);
}
/**
* Computes the length of vector (same as length)
* @param v - vector.
* @returns length of vector.
*/
const len$3 = length$3;
/**
* Computes the square of the length of vector
* @param v - vector.
* @returns square of the length of vector.
*/
function lengthSq$3(v) {
const v0 = v[0];
const v1 = v[1];
return v0 * v0 + v1 * v1;
}
/**
* Computes the square of the length of vector (same as lengthSq)
* @param v - vector.
* @returns square of the length of vector.
*/
const lenSq$3 = lengthSq$3;
/**
* Computes the distance between 2 points
* @param a - vector.
* @param b - vector.
* @returns distance between a and b
*/
function distance$2(a, b) {
const dx = a[0] - b[0];
const dy = a[1] - b[1];
return Math.sqrt(dx * dx + dy * dy);
}
/**
* Computes the distance between 2 points (same as distance)
* @param a - vector.
* @param b - vector.
* @returns distance between a and b
*/
const dist$2 = distance$2;
/**
* Computes the square of the distance between 2 points
* @param a - vector.
* @param b - vector.
* @returns square of the distance between a and b
*/
function distanceSq$2(a, b) {
const dx = a[0] - b[0];
const dy = a[1] - b[1];
return dx * dx + dy * dy;
}
/**
* Computes the square of the distance between 2 points (same as distanceSq)
* @param a - vector.
* @param b - vector.
* @returns square of the distance between a and b
*/
const distSq$2 = distanceSq$2;
/**
* Divides a vector by its Euclidean length and returns the quotient.
* @param v - The vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The normalized vector.
*/
function normalize$3(v, dst) {
dst = dst || new VecType$2(2);
const v0 = v[0];
const v1 = v[1];
const len = Math.sqrt(v0 * v0 + v1 * v1);
if (len > 0.00001) {
dst[0] = v0 / len;
dst[1] = v1 / len;
} else {
dst[0] = 0;
dst[1] = 0;
}
return dst;
}
/**
* Negates a vector.
* @param v - The vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns -v.
*/
function negate$4(v, dst) {
dst = dst || new VecType$2(2);
dst[0] = -v[0];
dst[1] = -v[1];
return dst;
}
/**
* Copies a vector. (same as {@link vec2.clone})
* Also see {@link vec2.create} and {@link vec2.set}
* @param v - The vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A copy of v.
*/
function copy$5(v, dst) {
dst = dst || new VecType$2(2);
dst[0] = v[0];
dst[1] = v[1];
return dst;
}
/**
* Clones a vector. (same as {@link vec2.copy})
* Also see {@link vec2.create} and {@link vec2.set}
* @param v - The vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns A copy of v.
*/
const clone$5 = copy$5;
/**
* Multiplies a vector by another vector (component-wise); assumes a and
* b have the same length.
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The vector of products of entries of a and b.
*/
function multiply$5(a, b, dst) {
dst = dst || new VecType$2(2);
dst[0] = a[0] * b[0];
dst[1] = a[1] * b[1];
return dst;
}
/**
* Multiplies a vector by another vector (component-wise); assumes a and
* b have the same length. (same as mul)
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The vector of products of entries of a and b.
*/
const mul$5 = multiply$5;
/**
* Divides a vector by another vector (component-wise); assumes a and
* b have the same length.
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The vector of quotients of entries of a and b.
*/
function divide$2(a, b, dst) {
dst = dst || new VecType$2(2);
dst[0] = a[0] / b[0];
dst[1] = a[1] / b[1];
return dst;
}
/**
* Divides a vector by another vector (component-wise); assumes a and
* b have the same length. (same as divide)
* @param a - Operand vector.
* @param b - Operand vector.
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The vector of quotients of entries of a and b.
*/
const div$2 = divide$2;
/**
* Creates a random unit vector * scale
* @param scale - Default 1
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The random vector.
*/
function random$1(scale = 1, dst) {
dst = dst || new VecType$2(2);
const angle = Math.random() * 2 * Math.PI;
dst[0] = Math.cos(angle) * scale;
dst[1] = Math.sin(angle) * scale;
return dst;
}
/**
* Zero's a vector
* @param dst - vector to hold result. If not passed in a new one is created.
* @returns The zeroed vector.
*/
function zero$2(dst) {
dst = dst || new VecType$2(2);
dst[0] = 0;
dst[1] = 0;
return dst;
}
/**
* transform Vec2 by 4x4 matrix
* @param v - the vector
* @param m - The matrix.
* @param dst - optional Vec2 to store result. If not passed a new one is created.
* @returns the transformed vector
*/
function transformMat4$2(v, m, dst) {
dst = dst || new VecType$2(2);
const x = v[0];
const y = v[1];
dst[0] = x * m[0] + y * m[4] + m[12];
dst[1] = x * m[1] + y * m[5] + m[13];
return dst;
}
/**
* Transforms vec4 by 3x3 matrix
*
* @param v - the vector
* @param m - The matrix.
* @param dst - optional Vec2 to store result. If not passed a new one is created.
* @returns the transformed vector
*/
function transformMat3$1(v, m, dst) {
dst = dst || new VecType$2(2);
const x = v[0];
const y = v[1];
dst[0] = m[0] * x + m[4] * y + m[8];
dst[1] = m[1] * x + m[5] * y + m[9];
return dst;
}
var vec2Impl = exports.vec2 = /*#__PURE__*/Object.freeze({
__proto__: null,
create: create$5,
setDefaultType: setDefaultType$6,
fromValues: fromValues$3,
set: set$5,
ceil: ceil$2,
floor: floor$2,
round: round$2,
clamp: clamp$2,
add: add$3,
addScaled: addScaled$2,
angle: angle$2,
subtract: subtract$3,
sub: sub$3,
equalsApproximately: equalsApproximately$5,
equals: equals$5,
lerp: lerp$3,
lerpV: lerpV$2,
max: max$2,
min: min$2,
mulScalar: mulScalar$3,
scale: scale$5,
divScalar: divScalar$3,
inverse: inverse$5,
invert: invert$4,
cross: cross$1,
dot: dot$3,
length: length$3,
len: len$3,
lengthSq: lengthSq$3,
lenSq: lenSq$3,
distance: distance$2,
dist: dist$2,
distanceSq: distanceSq$2,
distSq: distSq$2,
normalize: normalize$3,
negate: negate$4,
copy: copy$5,
clone: clone$5,
multiply: multiply$5,
mul: mul$5,
divide: divide$2,
div: div$2,
random: random$1,
zero: zero$2,
transformMat4: transformMat4$2,
transformMat3: transformMat3$1
});
/*
* Copyright 2022 Gregg Tavares
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
* 3x3 Matrix math math functions.
*
* Almost all functions take an optional `dst` argument. If it is not passed in the
* functions will create a new matrix. In other words you can do this
*
* const mat = mat3.translation([1, 2, 3]); // Creates a new translation matrix
*
* or
*
* const mat = mat3.create();
* mat3.translation([1, 2, 3], mat); // Puts translation matrix in mat.
*
* The first style is often easier but depending on where it's used it generates garbage where
* as there is almost never allocation with the second style.
*
* It is always save to pass any matrix as the destination. So for example
*
* const mat = mat3.identity();
* const trans = mat3.translation([1, 2, 3]);
* mat3.multiply(mat, trans, mat); // Multiplies mat * trans and puts result in mat.
*
*/
let MatType$1 = Float32Array;
// This mess is because with Mat3 we have 3 unused elements.
// For Float32Array and Float64Array that's not an issue
// but for Array it's troublesome
const ctorMap = new Map([[Float32Array, () => new Float32Array(12)], [Float64Array, () => new Float64Array(12)], [Array, () => new Array(12).fill(0)]]);
let newMat3 = ctorMap.get(Float32Array);
/**
* Sets the type this library creates for a Mat3
* @param ctor - the constructor for the type. Either `Float32Array`, `Float64Array`, or `Array`
* @returns previous constructor for Mat3
*/
function setDefaultType$4(ctor) {
const oldType = MatType$1;
MatType$1 = ctor;
newMat3 = ctorMap.get(ctor);
return oldType;
}
/**
* Create a Mat3 from values
*
* Note: Since passing in a raw JavaScript array
* is valid in all circumstances, if you want to
* force a JavaScript array into a Mat3's specified type
* it would be faster to use
*
* ```
* const m = mat3.clone(someJSArray);
* ```
*
* Note: a consequence of the implementation is if your Mat3Type = `Array`
* instead of `Float32Array` or `Float64Array` then any values you
* don't pass in will be undefined. Usually this is not an issue since
* (a) using `Array` is rare and (b) using `mat3.create` is usually used
* to create a Mat3 to be filled out as in
*
* ```
* const m = mat3.create();
* mat3.perspective(fov, aspect, near, far, m);
* ```
*
* @param v0 - value for element 0
* @param v1 - value for element 1
* @param v2 - value for element 2
* @param v3 - value for element 3
* @param v4 - value for element 4
* @param v5 - value for element 5
* @param v6 - value for element 6
* @param v7 - value for element 7
* @param v8 - value for element 8
* @returns matrix created from values.
*/
function create$3(v0, v1, v2, v3, v4, v5, v6, v7, v8) {
const dst = newMat3();
// to make the array homogenous
dst[3] = 0;
dst[7] = 0;
dst[11] = 0;
if (v0 !== undefined) {
dst[0] = v0;
if (v1 !== undefined) {
dst[1] = v1;
if (v2 !== undefined) {
dst[2] = v2;
if (v3 !== undefined) {
dst[4] = v3;
if (v4 !== undefined) {
dst[5] = v4;
if (v5 !== undefined) {
dst[6] = v5;
if (v6 !== undefined) {
dst[8] = v6;
if (v7 !== undefined) {
dst[9] = v7;
if (v8 !== undefined) {
dst[10] = v8;
}
}
}
}
}
}
}
}
}
return dst;
}
/**
* Sets the values of a Mat3
* Also see {@link mat3.create} and {@link mat3.copy}
*
* @param v0 - value for element 0
* @param v1 - value for element 1
* @param v2 - value for element 2
* @param v3 - value for element 3
* @param v4 - value for element 4
* @param v5 - value for element 5
* @param v6 - value for element 6
* @param v7 - value for element 7
* @param v8 - value for element 8
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns Mat3 set from values.
*/
function set$4(v0, v1, v2, v3, v4, v5, v6, v7, v8, dst) {
dst = dst || newMat3();
dst[0] = v0;
dst[1] = v1;
dst[2] = v2;
dst[3] = 0;
dst[4] = v3;
dst[5] = v4;
dst[6] = v5;
dst[7] = 0;
dst[8] = v6;
dst[9] = v7;
dst[10] = v8;
dst[11] = 0;
return dst;
}
/**
* Creates a Mat3 from the upper left 3x3 part of a Mat4
* @param m4 - source matrix
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns Mat3 made from m4
*/
function fromMat4(m4, dst) {
dst = dst || newMat3();
dst[0] = m4[0];
dst[1] = m4[1];
dst[2] = m4[2];
dst[3] = 0;
dst[4] = m4[4];
dst[5] = m4[5];
dst[6] = m4[6];
dst[7] = 0;
dst[8] = m4[8];
dst[9] = m4[9];
dst[10] = m4[10];
dst[11] = 0;
return dst;
}
/**
* Creates a Mat3 rotation matrix from a quaternion
* @param q - quaternion to create matrix from
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns Mat3 made from q
*/
function fromQuat$1(q, dst) {
dst = dst || newMat3();
const x = q[0];
const y = q[1];
const z = q[2];
const w = q[3];
const x2 = x + x;
const y2 = y + y;
const z2 = z + z;
const xx = x * x2;
const yx = y * x2;
const yy = y * y2;
const zx = z * x2;
const zy = z * y2;
const zz = z * z2;
const wx = w * x2;
const wy = w * y2;
const wz = w * z2;
dst[0] = 1 - yy - zz;
dst[1] = yx + wz;
dst[2] = zx - wy;
dst[3] = 0;
dst[4] = yx - wz;
dst[5] = 1 - xx - zz;
dst[6] = zy + wx;
dst[7] = 0;
dst[8] = zx + wy;
dst[9] = zy - wx;
dst[10] = 1 - xx - yy;
dst[11] = 0;
return dst;
}
/**
* Negates a matrix.
* @param m - The matrix.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns -m.
*/
function negate$3(m, dst) {
dst = dst || newMat3();
dst[0] = -m[0];
dst[1] = -m[1];
dst[2] = -m[2];
dst[4] = -m[4];
dst[5] = -m[5];
dst[6] = -m[6];
dst[8] = -m[8];
dst[9] = -m[9];
dst[10] = -m[10];
return dst;
}
/**
* Copies a matrix. (same as {@link mat3.clone})
* Also see {@link mat3.create} and {@link mat3.set}
* @param m - The matrix.
* @param dst - The matrix. If not passed a new one is created.
* @returns A copy of m.
*/
function copy$4(m, dst) {
dst = dst || newMat3();
dst[0] = m[0];
dst[1] = m[1];
dst[2] = m[2];
dst[4] = m[4];
dst[5] = m[5];
dst[6] = m[6];
dst[8] = m[8];
dst[9] = m[9];
dst[10] = m[10];
return dst;
}
/**
* Copies a matrix (same as {@link mat3.copy})
* Also see {@link mat3.create} and {@link mat3.set}
* @param m - The matrix.
* @param dst - The matrix. If not passed a new one is created.
* @returns A copy of m.
*/
const clone$4 = copy$4;
/**
* Check if 2 matrices are approximately equal
* @param a Operand matrix.
* @param b Operand matrix.
* @returns true if matrices are approximately equal
*/
function equalsApproximately$4(a, b) {
return Math.abs(a[0] - b[0]) < EPSILON && Math.abs(a[1] - b[1]) < EPSILON && Math.abs(a[2] - b[2]) < EPSILON && Math.abs(a[4] - b[4]) < EPSILON && Math.abs(a[5] - b[5]) < EPSILON && Math.abs(a[6] - b[6]) < EPSILON && Math.abs(a[8] - b[8]) < EPSILON && Math.abs(a[9] - b[9]) < EPSILON && Math.abs(a[10] - b[10]) < EPSILON;
}
/**
* Check if 2 matrices are exactly equal
* @param a Operand matrix.
* @param b Operand matrix.
* @returns true if matrices are exactly equal
*/
function equals$4(a, b) {
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10];
}
/**
* Creates a 3-by-3 identity matrix.
*
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns A 3-by-3 identity matrix.
*/
function identity$2(dst) {
dst = dst || newMat3();
dst[0] = 1;
dst[1] = 0;
dst[2] = 0;
dst[4] = 0;
dst[5] = 1;
dst[6] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = 1;
return dst;
}
/**
* Takes the transpose of a matrix.
* @param m - The matrix.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The transpose of m.
*/
function transpose$1(m, dst) {
dst = dst || newMat3();
if (dst === m) {
let t;
// 0 1 2
// 4 5 6
// 8 9 10
t = m[1];
m[1] = m[4];
m[4] = t;
t = m[2];
m[2] = m[8];
m[8] = t;
t = m[6];
m[6] = m[9];
m[9] = t;
return dst;
}
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
dst[0] = m00;
dst[1] = m10;
dst[2] = m20;
dst[4] = m01;
dst[5] = m11;
dst[6] = m21;
dst[8] = m02;
dst[9] = m12;
dst[10] = m22;
return dst;
}
/**
* Computes the inverse of a 3-by-3 matrix.
* @param m - The matrix.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The inverse of m.
*/
function inverse$4(m, dst) {
dst = dst || newMat3();
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const b01 = m22 * m11 - m12 * m21;
const b11 = -m22 * m10 + m12 * m20;
const b21 = m21 * m10 - m11 * m20;
const invDet = 1 / (m00 * b01 + m01 * b11 + m02 * b21);
dst[0] = b01 * invDet;
dst[1] = (-m22 * m01 + m02 * m21) * invDet;
dst[2] = (m12 * m01 - m02 * m11) * invDet;
dst[4] = b11 * invDet;
dst[5] = (m22 * m00 - m02 * m20) * invDet;
dst[6] = (-m12 * m00 + m02 * m10) * invDet;
dst[8] = b21 * invDet;
dst[9] = (-m21 * m00 + m01 * m20) * invDet;
dst[10] = (m11 * m00 - m01 * m10) * invDet;
return dst;
}
/**
* Compute the determinant of a matrix
* @param m - the matrix
* @returns the determinant
*/
function determinant$1(m) {
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
return m00 * (m11 * m22 - m21 * m12) - m10 * (m01 * m22 - m21 * m02) + m20 * (m01 * m12 - m11 * m02);
}
/**
* Computes the inverse of a 3-by-3 matrix. (same as inverse)
* @param m - The matrix.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The inverse of m.
*/
const invert$3 = inverse$4;
/**
* Multiplies two 3-by-3 matrices with a on the left and b on the right
* @param a - The matrix on the left.
* @param b - The matrix on the right.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The matrix product of a and b.
*/
function multiply$4(a, b, dst) {
dst = dst || newMat3();
const a00 = a[0];
const a01 = a[1];
const a02 = a[2];
const a10 = a[4 + 0];
const a11 = a[4 + 1];
const a12 = a[4 + 2];
const a20 = a[8 + 0];
const a21 = a[8 + 1];
const a22 = a[8 + 2];
const b00 = b[0];
const b01 = b[1];
const b02 = b[2];
const b10 = b[4 + 0];
const b11 = b[4 + 1];
const b12 = b[4 + 2];
const b20 = b[8 + 0];
const b21 = b[8 + 1];
const b22 = b[8 + 2];
dst[0] = a00 * b00 + a10 * b01 + a20 * b02;
dst[1] = a01 * b00 + a11 * b01 + a21 * b02;
dst[2] = a02 * b00 + a12 * b01 + a22 * b02;
dst[4] = a00 * b10 + a10 * b11 + a20 * b12;
dst[5] = a01 * b10 + a11 * b11 + a21 * b12;
dst[6] = a02 * b10 + a12 * b11 + a22 * b12;
dst[8] = a00 * b20 + a10 * b21 + a20 * b22;
dst[9] = a01 * b20 + a11 * b21 + a21 * b22;
dst[10] = a02 * b20 + a12 * b21 + a22 * b22;
return dst;
}
/**
* Multiplies two 3-by-3 matrices with a on the left and b on the right (same as multiply)
* @param a - The matrix on the left.
* @param b - The matrix on the right.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The matrix product of a and b.
*/
const mul$4 = multiply$4;
/**
* Sets the translation component of a 3-by-3 matrix to the given
* vector.
* @param a - The matrix.
* @param v - The vector.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The matrix with translation set.
*/
function setTranslation$1(a, v, dst) {
dst = dst || identity$2();
if (a !== dst) {
dst[0] = a[0];
dst[1] = a[1];
dst[2] = a[2];
dst[4] = a[4];
dst[5] = a[5];
dst[6] = a[6];
}
dst[8] = v[0];
dst[9] = v[1];
dst[10] = 1;
return dst;
}
/**
* Returns the translation component of a 3-by-3 matrix as a vector with 3
* entries.
* @param m - The matrix.
* @param dst - vector to hold result. If not passed a new one is created.
* @returns The translation component of m.
*/
function getTranslation$2(m, dst) {
dst = dst || create$5();
dst[0] = m[8];
dst[1] = m[9];
return dst;
}
/**
* Returns an axis of a 3x3 matrix as a vector with 2 entries
* @param m - The matrix.
* @param axis - The axis 0 = x, 1 = y,
* @returns The axis component of m.
*/
function getAxis$2(m, axis, dst) {
dst = dst || create$5();
const off = axis * 4;
dst[0] = m[off + 0];
dst[1] = m[off + 1];
return dst;
}
/**
* Sets an axis of a 3x3 matrix as a vector with 2 entries
* @param m - The matrix.
* @param v - the axis vector
* @param axis - The axis 0 = x, 1 = y;
* @param dst - The matrix to set. If not passed a new one is created.
* @returns The matrix with axis set.
*/
function setAxis$1(m, v, axis, dst) {
if (dst !== m) {
dst = copy$4(m, dst);
}
const off = axis * 4;
dst[off + 0] = v[0];
dst[off + 1] = v[1];
return dst;
}
/**
* Returns the scaling component of the matrix
* @param m - The Matrix
* @param dst - The vector to set. If not passed a new one is created.
*/
function getScaling$2(m, dst) {
dst = dst || create$5();
const xx = m[0];
const xy = m[1];
const yx = m[4];
const yy = m[5];
dst[0] = Math.sqrt(xx * xx + xy * xy);
dst[1] = Math.sqrt(yx * yx + yy * yy);
return dst;
}
/**
* Creates a 3-by-3 matrix which translates by the given vector v.
* @param v - The vector by which to translate.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The translation matrix.
*/
function translation$1(v, dst) {
dst = dst || newMat3();
dst[0] = 1;
dst[1] = 0;
dst[2] = 0;
dst[4] = 0;
dst[5] = 1;
dst[6] = 0;
dst[8] = v[0];
dst[9] = v[1];
dst[10] = 1;
return dst;
}
/**
* Translates the given 3-by-3 matrix by the given vector v.
* @param m - The matrix.
* @param v - The vector by which to translate.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The translated matrix.
*/
function translate$1(m, v, dst) {
dst = dst || newMat3();
const v0 = v[0];
const v1 = v[1];
const m00 = m[0];
const m01 = m[1];
const m02 = m[2];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
if (m !== dst) {
dst[0] = m00;
dst[1] = m01;
dst[2] = m02;
dst[4] = m10;
dst[5] = m11;
dst[6] = m12;
}
dst[8] = m00 * v0 + m10 * v1 + m20;
dst[9] = m01 * v0 + m11 * v1 + m21;
dst[10] = m02 * v0 + m12 * v1 + m22;
return dst;
}
/**
* Creates a 3-by-3 matrix which rotates by the given angle.
* @param angleInRadians - The angle by which to rotate (in radians).
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The rotation matrix.
*/
function rotation$1(angleInRadians, dst) {
dst = dst || newMat3();
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[0] = c;
dst[1] = s;
dst[2] = 0;
dst[4] = -s;
dst[5] = c;
dst[6] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = 1;
return dst;
}
/**
* Rotates the given 3-by-3 matrix by the given angle.
* @param m - The matrix.
* @param angleInRadians - The angle by which to rotate (in radians).
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The rotated matrix.
*/
function rotate$1(m, angleInRadians, dst) {
dst = dst || newMat3();
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[0] = c * m00 + s * m10;
dst[1] = c * m01 + s * m11;
dst[2] = c * m02 + s * m12;
dst[4] = c * m10 - s * m00;
dst[5] = c * m11 - s * m01;
dst[6] = c * m12 - s * m02;
if (m !== dst) {
dst[8] = m[8];
dst[9] = m[9];
dst[10] = m[10];
}
return dst;
}
/**
* Creates a 3-by-3 matrix which scales in each dimension by an amount given by
* the corresponding entry in the given vector; assumes the vector has three
* entries.
* @param v - A vector of
* 2 entries specifying the factor by which to scale in each dimension.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The scaling matrix.
*/
function scaling$1(v, dst) {
dst = dst || newMat3();
dst[0] = v[0];
dst[1] = 0;
dst[2] = 0;
dst[4] = 0;
dst[5] = v[1];
dst[6] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = 1;
return dst;
}
/**
* Scales the given 3-by-3 matrix in each dimension by an amount
* given by the corresponding entry in the given vector; assumes the vector has
* three entries.
* @param m - The matrix to be modified.
* @param v - A vector of 2 entries specifying the
* factor by which to scale in each dimension.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The scaled matrix.
*/
function scale$4(m, v, dst) {
dst = dst || newMat3();
const v0 = v[0];
const v1 = v[1];
dst[0] = v0 * m[0 * 4 + 0];
dst[1] = v0 * m[0 * 4 + 1];
dst[2] = v0 * m[0 * 4 + 2];
dst[4] = v1 * m[1 * 4 + 0];
dst[5] = v1 * m[1 * 4 + 1];
dst[6] = v1 * m[1 * 4 + 2];
if (m !== dst) {
dst[8] = m[8];
dst[9] = m[9];
dst[10] = m[10];
}
return dst;
}
/**
* Creates a 3-by-3 matrix which scales uniformly in each dimension
* @param s - Amount to scale
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The scaling matrix.
*/
function uniformScaling$1(s, dst) {
dst = dst || newMat3();
dst[0] = s;
dst[1] = 0;
dst[2] = 0;
dst[4] = 0;
dst[5] = s;
dst[6] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = 1;
return dst;
}
/**
* Scales the given 3-by-3 matrix in each dimension by an amount
* given.
* @param m - The matrix to be modified.
* @param s - Amount to scale.
* @param dst - matrix to hold result. If not passed a new one is created.
* @returns The scaled matrix.
*/
function uniformScale$1(m, s, dst) {
dst = dst || newMat3();
dst[0] = s * m[0 * 4 + 0];
dst[1] = s * m[0 * 4 + 1];
dst[2] = s * m[0 * 4 + 2];
dst[4] = s * m[1 * 4 + 0];
dst[5] = s * m[1 * 4 + 1];
dst[6] = s * m[1 * 4 + 2];
if (m !== dst) {
dst[8] = m[8];
dst[9] = m[9];
dst[10] = m[10];
}
return dst;
}
var mat3Impl = exports.mat3 = /*#__PURE__*/Object.freeze({
__proto__: null,
setDefaultType: setDefaultType$4,
create: create$3,
set: set$4,
fromMat4: fromMat4,
fromQuat: fromQuat$1,
negate: negate$3,
copy: copy$4,
clone: clone$4,
equalsApproximately: equalsApproximately$4,
equals: equals$4,
identity: identity$2,
transpose: transpose$1,
inverse: inverse$4,
determinant: determinant$1,
invert: invert$3,
multiply: multiply$4,
mul: mul$4,
setTranslation: setTranslation$1,
getTranslation: getTranslation$2,
getAxis: getAxis$2,
setAxis: setAxis$1,
getScaling: getScaling$2,
translation: translation$1,
translate: translate$1,
rotation: rotation$1,
rotate: rotate$1,
scaling: scaling$1,
scale: scale$4,
uniformScaling: uniformScaling$1,
uniformScale: uniformScale$1
});
/*
* Copyright 2022 Gregg Tavares
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation