Skip to content

v20.16.0

Latest

Choose a tag to compare

@github-actions github-actions released this 17 Nov 23:32
· 7 commits to master since this release
fa9f282

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 one GLTFModel, whose nodes and joints are reached by name with getNodeNames(), getNodeTransform() and addChildToNode() (a sword in a hand)
  • 3D: GLTFModel crossfades between clips with setCurrentAnimation(name, { crossfade }), or by default with the crossfade property and option; setAnimationTime(), getCurrentAnimationTime() and reverseAnimation() as on a Sprite
  • 3D: picking. Camera3d#screenToRay(), screenToWorld() and pick(), Mesh#intersectRay(), Ray3d, and pointer.hit3d on mesh pointer events; pickable = false leaves a mesh out of pick()
  • 3D: Camera3d projection: "orthographic", sized by orthoHeight or orthoWidth and zoomed by zoom, for isometric, top-down and diorama views
  • 3D: toon shading and outlines on lit meshes: toonBands, outlineWidth, outlineColor and outlineMode (world units or screen pixels), and a rimLight / rimColor glow along the silhouette; GLTFModel, GLTFScene and level.load options too
  • glTF: the parsed descriptor carries the asset's skins, and each skinned primitive its joints, weights and skin
  • Physics: Capsule3d, ConvexHull3d and TriangleMesh3d collision shapes, the last two built from a model with fromMesh(); the built-in physics collides them as their bounding box (#1846)
  • Physics: the adapter API takes a Vector3d wherever it takes a Vector2d (setVelocity, applyForce, applyImpulse, setPosition, gravity), with optional getVelocity3d, getRotation / setRotation and getAngularVelocity3d for a 3D adapter; the built-in applies them along its depth axis. A Vector2d works as before. A joint's anchors and axis and a body's maxVelocity may carry a z, 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; always false on 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; lookAt the other way round
  • Math: Quaternion, an orientation in 3D, built and used as a Matrix3d is: rotate(angle, axis), multiply, invert, apply / applyInverse, fromMat3d / toMatrix3d; slerp between two, and setFromUnitVectors(from, to), the shortest turn that takes one direction onto another
  • Math: Matrix3d#compose(translation, rotation, scale) sets a matrix from a position, a Quaternion and a scale; Matrix3d#rotate() and Renderable#rotate() also take a Quaternion
  • Input: event.POINTERUP and event.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, as event.POINTERMOVE follows it, in place of a raw pointerup listener 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 a Quaternion, when yaw, pitch or roll changes, and the view, the frustum, the fog and getBasis() 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#rotate and Renderable#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 nothing
  • Camera2d and Camera3d: 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. A yaw, pitch or roll that is not a number no longer fills the view with NaN: that turn is left out
  • Mesh#shadowGroundNormal: a normal with a part along Z was not normalized on Z, so the ground shadow was laid on a wrongly tilted plane
  • World#setAdapter: a body a 3D adapter tilted (turned about X or Y) is built again with its whole rotation on an adapter with setRotation; 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, overlapping floating regions 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 a UITextButton at 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 negative speed froze on its first frame and never ended; it now plays backwards
  • Camera3d: with a zoom other than 1, worldToScreen and screenToRay called while drawing answered for the wrong size
  • TypeScript: the declarations of InstancedMesh and Renderable#translate() no longer fail to type-check in a project without skipLibCheck; 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 save keeps its keys in memory where there is no localStorage (a sandboxed iframe, cookies blocked), so it needs no try / catch, and how to tell with device.localStorage

Full Changelog: 20.15.1...20.16.0