melonjs-3d
Was er macht
Es erklärt, wie 3D und 2,5D in melonJS funktionieren, einschließlich seiner Koordinatenregeln, die umgekehrt zur üblichen OpenGL-Konvention sind. Es richtet sich an Spieleentwickler, die einem melonJS-Spiel Tiefe hinzufügen.
Wann du ihn nutzt
- ✓Wenn ein Entwickler eine perspektivische Kamera oder 3D-Objekte in einem melonJS-Spiel will.
- ✓Wenn 3D-Objekte eines Entwicklers kopfüber oder hinter der Kamera erscheinen.
- ✓Wenn ein Entwickler Lichter oder Bodenschatten in einer 3D-Szene in melonJS will.
Link zum Skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-3d/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Meine 3D-Objekte erscheinen in melonJS kopfüber. Wie funktionieren die Koordinaten?”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Die Fähigkeit erklärt, dass die vertikale Achse nach unten zeigt und die Tiefe nach vorne wächst. Danach beschreibt sie die Kameraeinstellungen und wie man die Ansicht richtig neigt oder rollt.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
3D and 2.5D in melonJS
melonJS is a 2D engine that grew a real 3D tier: perspective cameras, meshes, instancing, glTF scenes and 3D lights. Most of what a model "knows" about 3D graphics comes from the OpenGL convention, and melonJS's is the inverse. Read the conventions section before writing any 3D code.
Coordinate conventions — the inverse of OpenGL
This is the single most important thing on this page.
| melonJS | OpenGL convention | |
|---|---|---|
| vertical | Y-down — higher y is lower on screen |
Y-up |
| depth | +Z forward — higher z is farther away |
−Z forward |
Camera3d exposes three rotation angles: camera.pitch
(X, look up/down), camera.yaw (Y, look left/right) and camera.roll (Z, bank
the horizon). The view is R(yaw) ∘ R(pitch) ∘ R(roll) inverted, and the frustum
planes come off that same matrix — so culling follows a banked view.
The basis those angles produce is readable and writable: getBasis(right, up, forward) reads it, setBasis(right, up, forward) poses the camera from
one.
camera.rotate() is NOT the way to bank a 3D camera. It writes the inherited
currentTransform, which a 3D view never reads, so the call is silently inert.
Set roll. (On a Camera2d it is the other way round: roll IS that transform's
rotation, which is why worldToLocal / localToWorld compensate for it.)
The payoff is that 2D code translates directly — anywhere you used pos.x /
pos.y, add pos.z and the maths still holds. The cost is that every
OpenGL-shaped instinct is backwards.
Consequence that bites immediately: "behind everything" is the largest depth when the camera looks along +Z. Put a backdrop on the wrong side and it either paints over the whole scene (it is nearer than everything else) or disappears without trace (it falls in front of the near plane and the GPU clips it). Which sign means "far" depends on which side the camera sits, so check the camera before picking a backdrop depth.
glTF assets are authored Y-up right-handed. level.load converts them by
rotation (rightHanded: true is its default), so you do not apply a flip
yourself. The Mesh constructor defaults rightHanded to false, which
bridges by mirroring instead — geometry you hand to a Mesh directly comes in
flipped left/right unless you pass rightHanded: true. See
melonjs-3d-assets.
Opting in
3D starts with the camera class, and nothing else has to change. Set it once on
the Application:
import { Application, Camera3d } from "melonjs";
const app = new Application(1024, 768, {
parent: "screen",
cameraClass: Camera3d, // ← the opt-in
});
await app.init();
That flips the world's sort to "depth", switches the broadphase to a 3D index,
and renders sprites and meshes with perspective projection. Camera3d extends
Camera2d, so follow, fade, shake and post effects all still work.
Keep the camera, do not fish it back out
app.viewport is the active stage's default camera, so it is typed
Camera2d: a stage overrides the application's cameraClass, and the
built-in loading screen does exactly that. Reading your Camera3d back out of
it therefore needs a cast, and a cast that is wrong while the loader is up:
const camera = app.viewport as Camera3d; // works, until it does not
Own it instead. Pass the camera in and keep the typed reference, and nothing downstream ever narrows:
class GameStage extends Stage {
readonly camera: Camera3d;
constructor(app) {
const camera = new Camera3d(0, 0, app.renderer.width, app.renderer.height);
super({ cameras: [camera] });
this.camera = camera;
}
}
A freshly built camera is named "default", and a stage registers its
cameras by name, so this IS the stage's default camera: app.viewport
returns the same instance.
The two patterns differ in LIFETIME, and that decides which you want
This is the part that bites. cameraClass builds a fresh camera for each
stage, which the engine does deliberately so "Camera3d state shouldn't
bleed across stages". An owned camera passed through super({ cameras }) is
built once and lives as long as the stage object, which for a stage you
register with state.set() means as long as the application.
So anything you attach to the camera now outlives the visit:
// in onResetEvent — runs EVERY time the stage is entered
app.viewport.addPostEffect(bloom);
With `cameraClass
Häufige Fragen
Warum sehen meine Objekte kopfüber aus?
melonJS nutzt eine nach unten gerichtete vertikale Achse, das Gegenteil der gängigen OpenGL-Konvention.
Wie rolle ich die Kamera?
Die Fähigkeit sagt, man setzt den Rollwert, weil ein Kamera-Rotationsaufruf auf eine 3D-Ansicht keine Wirkung hat.
Funktioniert 3D auf jedem Gerät?
Die Fähigkeit merkt an, dass manche Funktionen im Canvas-Ersatz nicht laufen, der ein GPU-Backend braucht.
Details
Originalbeschreibung des Autors
Use this skill for anything 3D or 2.5D in melonJS — Camera3d, Mesh, InstancedMesh, Sprite3d billboards, Light3d, ground shadows, glTF/GLB scenes, and depth sorting. Covers the Y-down/+Z-forward convention that is the inverse of OpenGL, the cameraClass opt-in, clip planes, and what does not work on the Canvas fallback. Triggers on: Camera3d, Mesh, InstancedMesh, Sprite3d, Trail3d, ribbon, exhaust trail, Light3d, billboard, glTF, glb, 3D, 2.5D, depth, cameraClass, fov, setClipPlanes, setFog, fog, distance fog, height fog, heightFalloff, transparent, transparency, alpha, blendMode, fade, castGrou
repo: melonjs/melonJS
Beliebtheit
- GitHub-Sterne
- 6.4k
- Platz im Ranking
- #14196
- Lizenz
- MIT
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
melonjs-20-migration
6.4kHilft deinem Agenten, melonJS-Spielcode für Version 20 zu schreiben und veraltete Methoden aus älteren Versionen zu vermeiden, etwa den nun nötigen asynchronen Start.
melonjs-3d-assets
6.4kHilft deinem Agenten, 3D-Modelle wie glTF-, GLB- und OBJ-Dateien in ein melonJS-Browserspiel zu laden, mit Optionen für Maßstab und Beleuchtung.
melonjs-audio
6.4kHilft deinem Agenten, Soundeffekte und Musik in ein melonJS-Spiel einzubauen, einschließlich Audio-Einrichtung, Hintergrundmusik, Lautstärkeregelung und räumlichem Klang.
melonjs-camera-and-drawing
6.4kHilft deinem Agenten, die Kamera eines melonJS-Spiels zu steuern, etwa um einem Spieler zu folgen, und eigene Formen und Linien im Spiel zu zeichnen.
Ähnliche Skills
diffs
394kLässt deinen Agenten einen echten, teilbaren Diff seiner Änderungen als Viewer-Link oder Bilddatei erstellen, statt einer handgeschriebenen Zusammenfassung.
coding-agent
394kHilft deinem Agenten, eine größere Programmieraufgabe als Hintergrund-Worker an Codex, Claude Code oder OpenCode zu übergeben und danach den Fortschritt zu prüfen.
gh-issues
394kHilft deinem Agenten, GitHub-Issues zu finden, die zu bearbeitenden auszuwählen und Pull Requests mit Korrekturen zu öffnen, einschließlich der Nacharbeit an Review-Kommentaren.