0.3.4 • Published 10 months ago

v128 v0.3.4

Weekly downloads
-
License
LGPL-2.1 AND BSD
Repository
github
Last release
10 months ago

v128

v128 is an high performance javascript library for 3D matrix vector calculations using 128 bits vector type from WebAssembly

Installation :

npm install v128

Getting started

Web browser :

	<script src="node_module/v128/dist/v128-min.js"></script>

Node.js :

const {v128} = require("v128");
await v128.init(4);
let cameraPos = v128.vector.new(0,2.5,-4);
let center = v128.vector.new(0,0,0);
let up = v128.vector.new(0,1,0);
let viewMatrix = v128.matrix.lookAt(cameraPos,center,up,v128.matrix.new());
let projectionMatrix = v128.matrix.perspective(Math.PI/2,4/3,0.1,1000,v128.matrix.new());
let viewProjection = v128.matrix.multiply(viewMatrix, projectionMatrix,v128.matrix.new());

WebGL compatibility :

gl.uniformMatrix4fv(projectionLocation, false, v128.memory.toArray(projectionMatrix));

How to build :

prerequisite :

step to build : just type :

 > make

API Reference

v128 : object

WebAssembly & Javascript module fast matrix vector calculations using SIMD vector 128 bits.

Kind: global namespace

v128.ready : Promise

Promise resolve when API is ready

Kind: static property of v128

v128.memory : object

memory API

Kind: static namespace of v128

memory.randomize()

Randomize all the memory

Kind: instance method of memory

memory.alloc(size) ⇒ UInt32

allocate float memory array

Kind: instance method of memory
Returns: UInt32 - the pointer from v128 memory

ParamTypeDescription
sizeNumberthe number of float to allocate

memory.free(pointer)

free float memory

Kind: instance method of memory

ParamTypeDescription
pointerUInt32the pointer to free

memory.fill(pointer, ...vals)

fill float memory with given values

Kind: instance method of memory

ParamTypeDescription
pointerUInt32
...valsNumbersnumber values to fill

memory.slice(pointer) ⇒ Float32Array

get copy of portion float memory

Kind: instance method of memory

ParamType
pointerUInt32

memory.toArray(pointer) ⇒ Float32Array

get read/write access of portion float memory

Kind: instance method of memory

ParamType
pointerUInt32

v128.matrix : object

matrix API

Kind: static namespace of v128

matrix.new(...vals) ⇒ UInt32

fast create new matrix from initial values

Kind: instance method of matrix
Returns: UInt32 - the pointer to new matrix

ParamTypeDescription
...valsNumbersnumber values to fill into matrix

matrix.free(pointer)

free the matrix

Kind: instance method of matrix

ParamTypeDescription
pointerUInt32the pointer of matrix to free

matrix.identity(pMatDest) ⇒

set or create matrix identity

Kind: instance method of matrix
Returns: the pointer of matrix identity

ParamTypeDescription
pMatDestUInt32the pointer of matrix to set

matrix.multiply(pMatA, pMatB, pMatDest) ⇒ UInt32

fast multiply 2 matrix (WebAssembly method)

Kind: instance method of matrix
Returns: UInt32 - the pointer to result matrix A*B

ParamTypeDescription
pMatAUInt32pointer of matrix A
pMatBUInt32pointer of matrix B
pMatDestUInt32pointer of result matrix A*B

matrix.transform(pMat, pVec, pVecDest) ⇒ UInt32

fast multiply matrix * vector (WebAssembly method)

Kind: instance method of matrix
Returns: UInt32 - the pointer to result transformed vector

ParamTypeDescription
pMatUInt32pointer of matrix
pVecUInt32pointer of vector
pVecDestUInt32pointer of result transformed vector (matrix * vector)

matrix.lookAt(pCamPos, pTargetPos, pUpAxis, pMatDest) ⇒ UInt32

fast create view matrix from camera position & target position (WebAssembly method)

Kind: instance method of matrix
Returns: UInt32 - the pointer to result view matrix

ParamTypeDescription
pCamPosUInt32pointer of camera position
pTargetPosUInt32pointer of target position
pUpAxisUInt32pointer of up axis
pMatDestUInt32pointer of result view matrix

matrix.invert(pMat, pMatDest) ⇒ UInt32

fast invert matrix (WebAssembly method)

Kind: instance method of matrix
Returns: UInt32 - the pointer to inversed matrix

ParamTypeDescription
pMatUInt32pointer of th matrix
pMatDestUInt32pointer of inversed matrix

matrix.perspective(fovy, aspect, near, far, pMatDest) ⇒ UInt32

create projection matrix from perspective data

Kind: instance method of matrix
Returns: UInt32 - the pointer to result projection matrix

ParamTypeDescription
fovynumberVertical field of view in radians
aspectnumberAspect ratio. typically viewport width/height
nearnumberNear clipping bound of the frustum
farnumberFar clipping bound of the frustum
pMatDestUInt32pointer of result projection matrix

matrix.fromTranslation(pVec, pMatDest) ⇒ UInt32

Creates a matrix from a vector translation

Kind: instance method of matrix
Returns: UInt32 - the pointer to result translated matrix

ParamTypeDescription
pVecUInt32pointer of Translation vector
pMatDestUInt32pointer of result translated matrix

matrix.fromScaling(pVec, pMatDest) ⇒ UInt32

Creates a matrix from a vector scaling

Kind: instance method of matrix
Returns: UInt32 - the pointer to result scaled matrix

ParamTypeDescription
pVecUInt32pointer of scaling vector
pMatDestUInt32pointer of result scaled matrix

matrix.fromXRotation(rad, pMatDest) ⇒ UInt32

Creates a matrix from the given angle around the X axis

Kind: instance method of matrix
Returns: UInt32 - the pointer to result rotated matrix

ParamTypeDescription
radNumberthe angle to rotate the matrix by
pMatDestUInt32pointer of result rotated matrix

matrix.fromYRotation(rad, pMatDest) ⇒ UInt32

Creates a matrix from the given angle around the Y axis

Kind: instance method of matrix
Returns: UInt32 - the pointer to result rotated matrix

ParamTypeDescription
radNumberthe angle to rotate the matrix by
pMatDestUInt32pointer of result rotated matrix

matrix.fromZRotation(rad, pMatDest) ⇒ UInt32

Creates a matrix from the given angle around the Z axis

Kind: instance method of matrix
Returns: UInt32 - the pointer to result rotated matrix

ParamTypeDescription
radNumberthe angle to rotate the matrix by
pMatDestUInt32pointer of result rotated matrix

matrix.rotateX(pMat, angle, pMatDest) ⇒ UInt32

Rotates a matrix by the given angle around the X axis

Kind: instance method of matrix
Returns: UInt32 - the pointer of the receiving matrix

ParamTypeDescription
pMatUInt32pointer of matrix to rotate
angleNumberthe angle in radian to rotate the matrix by
pMatDestUInt32pointer of the receiving matrix

matrix.rotateY(pMat, angle, pMatDest) ⇒ UInt32

Rotates a matrix by the given angle around the Y axis

Kind: instance method of matrix
Returns: UInt32 - the pointer of the receiving matrix

ParamTypeDescription
pMatUInt32pointer of matrix to rotate
angleNumberthe angle in radian to rotate the matrix by
pMatDestUInt32pointer of the receiving matrix

matrix.rotateZ(pMat, angle, pMatDest) ⇒ UInt32

Rotates a matrix by the given angle around the Z axis

Kind: instance method of matrix
Returns: UInt32 - the pointer of the receiving matrix

ParamTypeDescription
pMatUInt32pointer of matrix to rotate
angleNumberthe angle in radian to rotate the matrix by
pMatDestUInt32pointer of the receiving matrix

matrix.rotateX(pMat, pVec, pMatDest) ⇒ UInt32

Translates a matrix by the given vector

Kind: instance method of matrix
Returns: UInt32 - the pointer of the receiving matrix

ParamTypeDescription
pMatUInt32pointer of matrix to translate
pVecNumberpointer of vector to translate by
pMatDestUInt32pointer of the receiving matrix

v128.vector : object

vector API

Kind: static namespace of v128

vector.new(...vals) ⇒ UInt32

fast create new vector from initial values

Kind: instance method of vector
Returns: UInt32 - the pointer to new vector

ParamTypeDescription
...valsNumbersnumber values to fill into vector

vector.free(pointer)

free the vector

Kind: instance method of vector

ParamTypeDescription
pointerUInt32the pointer of vector to free

vector.length(pVec) ⇒ Number

get fast length of 3D Homogeneous coordinates vector (WebAssembly method)

Kind: instance method of vector
Returns: Number - the length of vector

ParamTypeDescription
pVecUInt32pointer of vector

vector.normalize(pVec, pVecDest) ⇒ UInt32

fast normalize 3D Homogeneous coordinates vector (WebAssembly method)

Kind: instance method of vector
Returns: UInt32 - the pointer of normalized vector

ParamTypeDescription
pVecUInt32pointer of vector
pVecDestUInt32pointer of receive normalized vector

vector.add(pVecA, pVecB, pVecDest) ⇒ UInt32

fast add two 3D Homogeneous coordinates vector (WebAssembly method)

Kind: instance method of vector
Returns: UInt32 - the pointer of result vector

ParamTypeDescription
pVecAUInt32pointer of vector A
pVecBUInt32pointer of vector B
pVecDestUInt32pointer of receive sum result vector ( A + B )

vector.sub(pVecA, pVecB, pVecDest) ⇒ UInt32

fast sub two 3D Homogeneous coordinates vector (WebAssembly method)

Kind: instance method of vector
Returns: UInt32 - the pointer of result vector

ParamTypeDescription
pVecAUInt32pointer of vector A
pVecBUInt32pointer of vector B
pVecDestUInt32pointer of receive sum result vector ( A - B )

vector.mul(pVecA, pVecB, pVecDest) ⇒ UInt32

fast multiply two 3D Homogeneous coordinates vector (WebAssembly method)

Kind: instance method of vector
Returns: UInt32 - the pointer of result vector

ParamTypeDescription
pVecAUInt32pointer of vector A
pVecBUInt32pointer of vector B
pVecDestUInt32pointer of receive multiply result vector ( A * B )

vector.div(pVecA, pVecB, pVecDest) ⇒ UInt32

fast divide two 3D Homogeneous coordinates vector (WebAssembly method)

Kind: instance method of vector
Returns: UInt32 - the pointer of result vector

ParamTypeDescription
pVecAUInt32pointer of vector A
pVecBUInt32pointer of vector B
pVecDestUInt32pointer of receive divide result vector ( A / B )

vector.cross(pVecA, pVecB, pVecDest) ⇒ UInt32

fast cross product of two 3D Homogeneous coordinates vector (WebAssembly method)

Kind: instance method of vector
Returns: UInt32 - the pointer of result vector

ParamTypeDescription
pVecAUInt32pointer of vector A
pVecBUInt32pointer of vector B
pVecDestUInt32pointer of receive cross product result vector ( A.B )

vector.dot(pVecA, pVecB) ⇒ Number

fast dot product of two 3D Homogeneous coordinates vector (WebAssembly method)

Kind: instance method of vector
Returns: Number - the pointer of result vector

ParamTypeDescription
pVecAUInt32pointer of vector A
pVecBUInt32pointer of vector B

vector.scale(pVec, scale, pVecDest) ⇒ UInt32

fast scale vector by a scalar number

Kind: instance method of vector
Returns: UInt32 - the pointer of result vector

ParamTypeDescription
pVecUInt32pointer of vector to scale
scaleNumberamount to scale the vector by
pVecDestUInt32pointer of receive result vector

v128.uniformBlock : object

WebGL2 Uniform Buffer Objects API (UBOs) using std140 layout.

Kind: static namespace of v128

v128.vertexBuffer : object

WebGL Vertex Buffer Objects API (VBOs)

Kind: static namespace of v128

v128.init(size) ⇒ Promise

Initialize the v128 API

Kind: static method of v128
Returns: Promise - resolve when API is ready

ParamTypeDescription
sizeNumberthe number of page for v128 Memory (page = 64Kb)
0.3.4

10 months ago

0.3.3

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.0

10 months ago