mesh-collision
return the contact set between two 3d meshes in motion
example
var collide = ;var mat4 = ;var transformMat4 = ;var loop = ;var lerp = ;var teapot = ;var bunny = ;var bodies =prev: mat4next:cells: bunnycellspositions: bunnypositionsvelocity:prev: mat4next:cells: teapotcellspositions: teapotpositionsvelocity:;var tmpm = mat4;var origin = 000;var engine =;engine;{ return mat4 }
output:
{ mix: 0.7277780106077933,
point: [ -1.070312, 0.234375, 0.0786932272210148 ],
normal: [ -0.5790840193768065, -0.8026245943343034, 0.14302258238508114 ] }
method
var collision =
var contact = collision(a, b)
Raycast from each point in a
onto b
.
a
and b
both must have these properties:
- next - a mat4 of the next position and rotation
- prev - a mat4 of the previous position and rotation
- positions - an array of
[x,y,z]
coordinate arrays - cells - an array of arrays of indexes
The positions
and cells
array structures are compatible with
simplicial-complex.
If there was not a collision, return null.
Otherwise return contact
, an object with these properties:
- point - contact point as an
[x,y,z]
- normal - contact normal as an
[x,y,z]
- mix - the amount of linear interpolation (
0
to1
) betweenprev
andnext
where the collision occured.
The contact object is modeled after the contact set mentioned in the SPOOK
paper but using mix
instead of a penetration depth.
install
With npm do:
npm install mesh-collision
license
MIT