# @jsantell/mini-webgl

> Mini toy WebGL library

Latest version **1.0.4** (published 2017-11-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jsantell/mini-webgl
pnpm add @jsantell/mini-webgl
yarn add @jsantell/mini-webgl
bun add @jsantell/mini-webgl
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-11-10 |
| First published | 2017-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Jordan Santell |
| Maintainers | jsantell |

## Links

- npm: https://www.npmjs.com/package/@jsantell/mini-webgl
- Repository: https://github.com/jsantell/mini-webgl
- Homepage: https://github.com/jsantell/mini-webgl#readme
- Issues: https://github.com/jsantell/mini-webgl/issues
- npm.io page: https://npm.io/package/@jsantell/mini-webgl

## Dependencies (1)

- [gl-matrix](https://npm.io/package/gl-matrix.md) ^2.3.2

## Recent versions

- 1.0.4 (latest) — 2017-11-10
- 1.0.3 — 2017-11-10
- 1.0.2 — 2017-11-10
- 1.0.1 — 2017-11-10
- 1.0.0 — 2017-11-10

## README

# mini-webgl

Mini toy WebGL library

For educational purposes. **Do not use this library.**
This is a barebones, unoptimized abstraction around WebGL. API ideas inspired by THREE.js.

![mini-webgl](https://jsantell.github.io/mini-webgl/assets/screenshot.gif)

## What and How it Works

* Basic rendering of a [scene](src/scene.js) graph with [perspective camera](src/camera.js).
* [Models](src/model.js) are represented by a geometry and material, updating position/rotation/scale when local coordinates change.
* Barebones [Math](src/math.js) library for managing Vector and Matrix types and track if dirty to minimize rebuilding matrices. Mostly a wrapper around [glMatrix](http://glmatrix.net/).
* [Geometries](src/geometries) have a vertex buffer, and optionally an indices buffer.
  * Implemented: [Triangle](src/geometries/triangle.js), [Cube](src/geometries/cube.js)
* [Materials](src/materials) take a vertex and fragment shader and define `uniforms` and `attributes` properties that can be updated and pushed to the GPU. Uniforms/attribs are initialized by readingInstances have their own uniform/attribute values, but reuse the same program if it can (based on vertex/fragment shader source), so for example, all instances of `BasicMaterial` use the same underlying WebGLProgram.
  * Implemented: [BasicMaterial](src/materials/basic-material.js)
* The scene's [renderer](src/renderer.js) queues up the scene graph's nodes and passes it to the [GLWrapper](src/webgl/index.js) which manages all the WebGL calls, so all the API abstractions of models and materials are in [src/](src/), and translating that abstraction to WebGL lives in [src/webgl/](src/webgl/).

## Example

* [triangle animations](https://jsantell.github.io/mini-webgl/examples/complex.html)

### Example Code

```js
  var scene = new MiniWebGL.Scene(canvas);
  var camera = new MiniWebGL.Camera();
  var cube = new MiniWebGL.Model(
    new MiniWebGL.Cube(),
    new MiniWebGL.BasicMaterial()
  );

  scene.useCamera(camera);
  cube.position.set(0, 0.5, -3);
  cube.scale.set(0.5, 0.5, 0.5);
  scene.add(cube);

  var t, x, y, z = 0;
  function tick () {
    t = performance.now();
    x = Math.cos(t * 0.001) + Math.PI;
    y = Math.sin(t * 0.001) + Math.PI;
    cube.rotation.set(x, y, z);
    cube.material.uniforms.color.setX(Math.abs(Math.sin(t * 0.001)));
    scene.render();
    requestAnimationFrame(tick);
  }
  tick();
```

## License

MIT License, Copyright (c) 2017 Jordan Santell

---
_Source: https://npm.io/package/@jsantell/mini-webgl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
