Skip to content

Commit

Permalink
Deploying to gh-pages from @ affb147 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jul 20, 2024
1 parent 3925574 commit d921622
Show file tree
Hide file tree
Showing 34 changed files with 417 additions and 108 deletions.
82 changes: 78 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Fast 3d math library for webgpu

* [Docs](https://wgpu-matrix.org/docs)
* [Repo](https://github.com/greggman/wgpu-matrix)
* [Github](https://github.com/greggman/wgpu-matrix)
* [Tests](https://wgpu-matrix.org/test/)

## Why another 3d math library?
Expand Down Expand Up @@ -146,6 +146,80 @@ import {vec3, mat3} from 'wgpu-matrix';
* [tar](https://github.com/greggman/wgpu-matrix/tarball/main)
* [github](https://github.com/greggman/wgpu-matrix)

## Types

### wgpu-matrix functions take any compatible type as input.

Examples:

```ts
const view = mat4.lookAt( // view is Float32Array
[10, 20, 30], // position
[0, 5, 0], // target
[0, 1, 0], // up
);

const view2 = mat4.lookAt( // view2 is Float32Array
new Float32Array([10, 20, 30]), // position
new Float64Array([0, 5, 0], // target
[0, 1, 0], // up
);
```
### wgpu-matrix functions return the type passed as the destination or their default
```ts
const a = vec2.add([1, 2], [3, 4]); // a is Float32Array
const b = vec2.add([1, 2], [3, 4], [0, 0]); // b is number[]

const j = vec2d.add([1, 2], [3, 4]); // j is Float64Array
const k = vec2d.add([1, 2], [3, 4], [0, 0]); // b is number[]

const f32 = new Float32Array(2);
const x = vec2d.add([1, 2], [3, 4]); // x is number[]
const y = vec2d.add([1, 2], [3, 4], f32); // y is Float32Array
```
etc...
Note: You're unlikely to need any thing except `mat3`, `mat4`, `quat`,
`vec2`, `vec3`, and `vec4` but, there are 3 sets of functions,
each one returning a different default
```ts
mat4.identity() // returns Float32Array
mat4d.identity() // returns Float64Array
mat4n.identity() // returns number[]
```
Similarly there's `mat3d`, `mat3n`, `quatd`, `quatn`,
`vec2d`, `vec2n`, `vec3d`, `vec3n`, `vec4d`, `vec4n`.
Just to be clear, `identity`, like most functions, takes a destination so
```ts
const f32 = new Float32Array(16);
const f64 = new Float64Array(16);
const arr = new Array<number>(16).fill(0);

mat4.identity() // returns Float32Array
mat4.identity(f32) // returns Float32Array (f32)
mat4.identity(f64) // returns Float64Array (f64)
mat4.identity(arr) // returns number[] (arr)

mat4d.identity() // returns Float64Array
mat4d.identity(f32) // returns Float32Array (f32)
mat4d.identity(f64) // returns Float64Array (f64)
mat4d.identity(arr) // returns number[] (arr)

mat4n.identity() // returns number[]
mat4n.identity(f32) // returns Float32Array (f32)
mat4n.identity(f64) // returns Float64Array (f64)
mat4n.identity(arr) // returns number[] (arr)
```
The only difference between the sets of functions is what type they default to returning.
## Notes
[`mat4.perspective`](https://wgpu-matrix.org/docs/functions/mat4.perspective.html),
Expand Down Expand Up @@ -276,11 +350,11 @@ a destination it returns the type of the destination
```ts
mat4.identity() // returns Float32Array
mat4.identity(new Float32Array(16)); // returns Float32Array
mat4.identity(new Float64Array(16)); // returns Float32Array
mat4.identity(new Float64Array(16)); // returns Float64Array
mat4.identity(new Array(16)); // returns number[]
```
### Types are specific
#### Types are specific
```ts
const a: Mat4 = ...; // a = Float32Array
Expand Down Expand Up @@ -313,7 +387,7 @@ If you really want types for each concrete type there's
* `Float64Array` types: `Mat3d`, `Mat4d`, `Quatd`, `Vec2d`, `Vec3d`, `Vec4d`,
* `number[]` types: `Mat3n`, `Mat4n`, `Quatn`, `Vec2n`, `Vec3n`, `Vec4n`
### There are 3 sets of functions, each one returning a different default
#### There are 3 sets of functions, each one returning a different default
```ts
mat4.identity() // returns Float32Array
Expand Down
34 changes: 28 additions & 6 deletions dist/3.x/wgpu-matrix.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Some docs
* @namespace wgpu-matrix
*/
import { BaseArgType } from './types';
import { Mat3Arg, Mat3Type } from './mat3-impl';
import { Mat4Arg, Mat4Type } from './mat4-impl';
Expand Down Expand Up @@ -27,7 +31,10 @@ export type Vec2n = Vec2Type<number[]>;
export type Vec3n = Vec3Type<number[]>;
export type Vec4n = Vec4Type<number[]>;
export declare const
/** @namespace */
/**
* 4x4 Matrix functions that default to returning `Float32Array`
* @namespace
*/
mat4: {
create: (v0?: number | undefined, v1?: number | undefined, v2?: number | undefined, v3?: number | undefined, v4?: number | undefined, v5?: number | undefined, v6?: number | undefined, v7?: number | undefined, v8?: number | undefined, v9?: number | undefined, v10?: number | undefined, v11?: number | undefined, v12?: number | undefined, v13?: number | undefined, v14?: number | undefined, v15?: number | undefined) => Float32Array;
set: <T extends BaseArgType = Float32Array>(v0: number, v1: number, v2: number, v3: number, v4: number, v5: number, v6: number, v7: number, v8: number, v9: number, v10: number, v11: number, v12: number, v13: number, v14: number, v15: number, dst?: T | undefined) => T;
Expand Down Expand Up @@ -75,7 +82,10 @@ mat4: {
uniformScaling: <T_34 extends BaseArgType = Float32Array>(s: number, dst?: T_34 | undefined) => T_34;
uniformScale: <T_35 extends BaseArgType = Float32Array>(m: BaseArgType, s: number, dst?: T_35 | undefined) => T_35;
},
/** @namespace */
/**
* 3x3 Matrix functions that default to returning `Float32Array`
* @namespace
*/
mat3: {
clone: <T extends BaseArgType = Float32Array>(m: BaseArgType, dst?: T | undefined) => T;
create: (v0?: number | undefined, v1?: number | undefined, v2?: number | undefined, v3?: number | undefined, v4?: number | undefined, v5?: number | undefined, v6?: number | undefined, v7?: number | undefined, v8?: number | undefined) => Float32Array;
Expand Down Expand Up @@ -107,7 +117,10 @@ mat3: {
uniformScaling: <T_20 extends BaseArgType = Float32Array>(s: number, dst?: T_20 | undefined) => T_20;
uniformScale: <T_21 extends BaseArgType = Float32Array>(m: BaseArgType, s: number, dst?: T_21 | undefined) => T_21;
},
/** @namespace */
/**
* Quaternion functions that default to returning `Float32Array`
* @namespace
*/
quat: {
create: (x?: number | undefined, y?: number | undefined, z?: number | undefined, w?: number | undefined) => Float32Array;
fromValues: (x?: number | undefined, y?: number | undefined, z?: number | undefined, w?: number | undefined) => Float32Array;
Expand Down Expand Up @@ -149,7 +162,10 @@ quat: {
rotationTo: <T_20 extends BaseArgType = Float32Array>(aUnit: BaseArgType, bUnit: BaseArgType, dst?: T_20 | undefined) => T_20;
sqlerp: <T_21 extends BaseArgType = Float32Array>(a: BaseArgType, b: BaseArgType, c: BaseArgType, d: BaseArgType, t: number, dst?: T_21 | undefined) => T_21;
},
/** @namespace */
/**
* Vec2 functions that default to returning `Float32Array`
* @namespace
*/
vec2: {
create: (x?: number, y?: number) => Float32Array;
fromValues: (x?: number, y?: number) => Float32Array;
Expand Down Expand Up @@ -201,7 +217,10 @@ vec2: {
truncate: <T_27 extends BaseArgType = Float32Array>(a: BaseArgType, maxLen: number, dst?: T_27 | undefined) => T_27;
midpoint: <T_28 extends BaseArgType = Float32Array>(a: BaseArgType, b: BaseArgType, dst?: T_28 | undefined) => T_28;
},
/** @namespace */
/**
* Vec3 functions that default to returning `Float32Array`
* @namespace
*/
vec3: {
create: (x?: number | undefined, y?: number | undefined, z?: number | undefined) => Float32Array;
fromValues: (x?: number | undefined, y?: number | undefined, z?: number | undefined) => Float32Array;
Expand Down Expand Up @@ -260,7 +279,10 @@ vec3: {
truncate: <T_34 extends BaseArgType = Float32Array>(a: BaseArgType, maxLen: number, dst?: T_34 | undefined) => T_34;
midpoint: <T_35 extends BaseArgType = Float32Array>(a: BaseArgType, b: BaseArgType, dst?: T_35 | undefined) => T_35;
},
/** @namespace */
/**
* Vec3 functions that default to returning `Float32Array`
* @namespace
*/
vec4: {
create: (x?: number | undefined, y?: number | undefined, z?: number | undefined, w?: number | undefined) => Float32Array;
fromValues: (x?: number | undefined, y?: number | undefined, z?: number | undefined, w?: number | undefined) => Float32Array;
Expand Down
98 changes: 78 additions & 20 deletions dist/3.x/wgpu-matrix.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/3.x/wgpu-matrix.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/3.x/wgpu-matrix.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/3.x/wgpu-matrix.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit d921622

Please sign in to comment.