日本語のREADMEはこちらです: README.ja.md
gl-matrix is a JavaScript matrix and vector library that is designed to perform well in high-performance WebGL applications.
- High Performance: Optimized for situations where performance is critical.
- Comprehensive Math: Supports a wide range of vector, matrix, and quaternion operations.
vec2,vec3,vec4mat2,mat2d,mat3,mat4quat,quat2(Dual Quaternions)
- Modern JavaScript: Distributed as ES6 modules.
- Tree-Shakable: Import only the functions you need, minimizing your bundle size.
- Zero Dependencies: A lightweight library with no external dependencies.
- Fully Typed: Includes TypeScript definitions.
Install via npm:
npm install gl-matrixgl-matrix is designed for efficiency, and as such, most functions write their results to a dedicated out parameter. This allows you to reuse existing objects and avoid unnecessary memory allocations.
Import the specific modules you need. This is the best approach for production applications as it allows bundlers like Webpack or Rollup to "tree-shake" the library, resulting in a smaller final bundle.
import { mat4, vec3 } from 'gl-matrix';
// Create a mat4 for our model-view matrix
const modelViewMatrix = mat4.create();
// Translate it
mat4.translate(modelViewMatrix, // destination matrix
modelViewMatrix, // matrix to translate
[-0.0, 0.0, -6.0]); // amount to translate
// Create a vec3 for scaling
const scaleVector = vec3.fromValues(2, 2, 2);
// Scale the matrix
mat4.scale(modelViewMatrix, modelViewMatrix, scaleVector);You can also use the UMD build directly in the browser. A global glMatrix object will be available.
<script src="node_modules/gl-matrix/dist/gl-matrix.js"></script>
<script>
const { mat4, vec3 } = glMatrix;
const matrix = mat4.create();
mat4.rotate(matrix, matrix, Math.PI / 4, [0, 0, 1]);
console.log(matrix);
</script>For a complete list of all available functions, see the API Documentation.
- Brandon Jones (@toji)
- Colin MacKenzie IV (@sinisterchipmunk)
gl-matrix is licensed under the MIT License.