Skip to content

eulerjs API / @eulerjs/core/extend

@eulerjs/core/extend ​

@eulerjs/core/extend: for plugins that teach the JavaScript backend new collider shapes, such as @eulerjs/bvh's triangle meshes. A new shape is a Collider subclass with its own shape name, plus either collision tests against the shapes it meets, or, for a shape made of triangles, a description of which triangles lie where, from which the engine derives its collisions with every convex shape, ray casts, shape casts and overlap tests.

Interfaces ​

InterfaceDescription
ContactPointWhere two colliders touch, or nearly do. normal is a unit vector from B toward A (the way A must move to separate), pointA and pointB are the closest (or deepest) points of each, and depth is how far they overlap along the normal, (pointB - pointA) · normal: negative for a gap, which a contact within the margin can have.
SweepHitWhere a ray or swept shape first touches a collider.
TriangleShapeA shape made of triangles, such as a heightfield or a mesh, described by the triangles it has in a region.

Type Aliases ​

Type AliasDescription
CollisionTestAdds the contacts between two colliders to contacts, including points still up to margin apart: the bodies may close that gap during the step.
RayTestA ray or shape registered by a plugin with its own way of casting against a shape, such as a mesh's bounding volume tree.
TriangleTestAdds the contacts between the collider it was made for and the triangle (first, second, third), counting points up to margin apart. A one-sided triangle, such as a piece of terrain, only ever pushes out of the side its corners wind anticlockwise around.
TriangleVisitorReceives one triangle in world space, wound anticlockwise seen from its front, and its active edges (see TriangleTest).

Variables ​

VariableDescription
ALL_EDGESAll three edges active.

Functions ​

FunctionDescription
collideEvery contact between two colliders at the given poses, counting points up to margin apart. None if they don't touch or no test is registered for the pair of shapes.
isActiveEdgeWhether the edge from start to end of a triangle with unit normal normal should push on its own: yes on the border of a surface (no neighbour), and where the surface folds away from the triangle's front by more than a few degrees, a ridge; no where it is nearly flat, or folds up into a valley, where the faces either side do all the pushing.
rayTriangleWhere a ray meets a triangle (Möller and Trumbore 1997), from the front only if oneSided.
registerCollisionTestTeaches the engine how two shapes collide. Register each pair once; the reverse order is handled for you.
registerRayTestGives a shape a ray cast of its own, used instead of the general one.
registerTriangleShapeTeaches the engine a shape made of triangles: from the triangles it gives in a region, it collides with every convex shape, and scene queries (ray casts, shape casts, overlaps) work against it.
triangleTestForThe test of collider at pose against triangles, set up once to be run on many: undefined for shapes that can't collide with triangles, such as planes and other triangle shapes.

Released under the MIT License.