Repository navigation
Highlights: a faster Camera3d, its work per frame up to 72% faster with no change to your game, and real 3D physics: with the new @melonjs/rapier3d-adapter, bodies tumble, stack and topple in 3D, with collision shapes built straight from your models. Also new: skinned glTF characters with crossfades, mesh picking, an orthographic Camera3d for isometric views, and toon shading with outlines. The new features are opt-in: a game that sets none of them renders as before.
Added
- 3D: skinned glTF meshes (
JOINTS_0/WEIGHTS_0, as exported by Mixamo and Quaternius) deform with their skeleton, on the CPU, so alike on WebGPU, WebGL and Canvas; up to four joints per vertex, no morph targets. A skinned asset loads as oneGLTFModel, whose nodes and joints are reached by name withgetNodeNames(),getNodeTransform()andaddChildToNode()(a sword in a hand) - 3D:
GLTFModelcrossfades between clips withsetCurrentAnimation(name, { crossfade }), or by default with thecrossfadeproperty and option;setAnimationTime(),getCurrentAnimationTime()andreverseAnimation()as on aSprite - 3D: picking.
Camera3d#screenToRay(),screenToWorld()andpick(),Mesh#intersectRay(),Ray3d, andpointer.hit3don mesh pointer events;pickable = falseleaves a mesh out ofpick() - 3D:
Camera3dprojection: "orthographic", sized byorthoHeightororthoWidthand zoomed byzoom, for isometric, top-down and diorama views - 3D: toon shading and outlines on lit meshes:
toonBands,outlineWidth,outlineColorandoutlineMode(world units or screen pixels), and arimLight/rimColorglow along the silhouette;GLTFModel,GLTFSceneandlevel.loadoptions too - glTF: the parsed descriptor carries the asset's
skins, and each skinned primitive itsjoints,weightsandskin - Physics:
Capsule3d,ConvexHull3dandTriangleMesh3dcollision shapes, the last two built from a model withfromMesh(); the built-in physics collides them as their bounding box (#1846) - Physics: the adapter API takes a
Vector3dwherever it takes aVector2d(setVelocity,applyForce,applyImpulse,setPosition,gravity), with optionalgetVelocity3d,getRotation/setRotationandgetAngularVelocity3dfor a 3D adapter; the built-in applies them along its depth axis. AVector2dworks as before. A joint's anchors and axis and a body'smaxVelocitymay carry az, which a 2D adapter ignores - Physics: the built-in says once in the console when it is asked for 3D it can only approximate (those three shapes, or a turn or spin about X or Y), naming
@melonjs/rapier3d-adapter - Physics: optional
isSleeping()on the adapter API, whether the engine has put a body to rest; alwaysfalseon the built-in, which has no sleeping - 3D:
Camera3d#orbit(target, yaw, pitch, distance)places the camera on a sphere around a point, looking at it, for a model viewer, a level overview or a third-person view;lookAtthe other way round - Math:
Quaternion, an orientation in 3D, built and used as aMatrix3dis:rotate(angle, axis),multiply,invert,apply/applyInverse,fromMat3d/toMatrix3d;slerpbetween two, andsetFromUnitVectors(from, to), the shortest turn that takes one direction onto another - Math:
Matrix3d#compose(translation, rotation, scale)sets a matrix from a position, aQuaternionand a scale;Matrix3d#rotate()andRenderable#rotate()also take aQuaternion - Input:
event.POINTERUPandevent.POINTERCANCEL, a pointer released, or taken away by the browser, wherever it happened: over a region or not, over the canvas or not. The end of a drag, asevent.POINTERMOVEfollows it, in place of a rawpointeruplistener on the page - State:
state.reload()builds the current stage again, for a "play again" or a level restart, with the arguments it was entered with or new ones;state.change()to the current state still does nothing
Performance
Camera3d: the camera builds its orientation once, from aQuaternion, whenyaw,pitchorrollchanges, and the view, the frustum, the fog andgetBasis()all reuse it, where each rebuilt it from three rotations; the view is taken off the world container by restoring its transform instead of turning it back. The camera's view work per frame is about 48% faster with the camera moving (1.49 to 0.78 µs) and 72% faster with it still (1.15 to 0.32 µs)
Fixed
Matrix3d#rotate,Matrix2d#rotateandRenderable#rotate: an angle or an axis that is not a finite number filled the whole matrix with NaN, and the renderable vanished; it now turns nothingCamera2dandCamera3d: taking the view back off the world container every frame, by the opposite move (and turns), left a rounding error in its transform, larger the farther the camera was from the origin; it is now restored exactly, at no extra cost in 2D. Ayaw,pitchorrollthat is not a number no longer fills the view with NaN: that turn is left outMesh#shadowGroundNormal: a normal with a part along Z was not normalized on Z, so the ground shadow was laid on a wrongly tilted planeWorld#setAdapter: a body a 3D adapter tilted (turned about X or Y) is built again with its whole rotation on an adapter withsetRotation; it lost all but its turn about Z. A turned body is also turned back on the outgoing adapter first, so an adapter that turns a renderable from how it stood when its body was made does not turn it a second time- Input: under a
Camera3d, pointer events on a mesh are hit-tested by the ray through the pointer against its triangles; they were tested against 2D bounds that a perspective view misplaces - Input: under a
Camera3d, overlappingfloatingregions are asked for a pointer event in the order they are drawn, the smaller depth first; they were asked by raw z, so a full-screen floating region at depth 4 took the press meant for aUITextButtonat depth 1 drawn over it - glTF: a skinned mesh was placed and bounded by its own node's transform, which glTF says it ignores, so a rigged character could load offset and with wrong
bounds GLTFModel: a clip at a negativespeedfroze on its first frame and never ended; it now plays backwardsCamera3d: with azoomother than 1,worldToScreenandscreenToRaycalled while drawing answered for the wrong size- TypeScript: the declarations of
InstancedMeshandRenderable#translate()no longer fail to type-check in a project withoutskipLibCheck;translate()is now typed to take any{x, y}point, as it already did at runtime - Tiled: a tile layer or infinite-map chunk whose data holds more or fewer tiles than its cells throws, naming the layer; missing cells were left empty
- Tiled: loading a compressed map without the inflate plugin throws an error that names
@melonjs/tiled-inflate-plugin, the plugin to register Color#toArray(): its documentation now says it returns the color's own array, not a copy, so writing into it changes the color. The maths skill says so too, with a symptom row- Skills: the scenes skill now says that
savekeeps its keys in memory where there is nolocalStorage(a sandboxed iframe, cookies blocked), so it needs notry/catch, and how to tell withdevice.localStorage
Full Changelog: 20.15.1...20.16.0