melonjs-3d
하는 일
melonJS에서 3D와 2.5D가 어떻게 동작하는지 설명하며, 일반적인 OpenGL 방식과 반대인 좌표 규칙도 포함합니다. melonJS 게임에 깊이를 더하려는 게임 개발자를 위한 스킬입니다.
사용하는 경우
- ✓개발자가 melonJS 게임에 원근 카메라나 3D 오브젝트를 넣고 싶을 때.
- ✓개발자의 3D 오브젝트가 뒤집혀 보이거나 카메라 뒤에 있을 때.
- ✓개발자가 melonJS 3D 장면에 조명이나 바닥 그림자를 추가하려 할 때.
스킬 링크
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-3d/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“melonJS에서 제 3D 오브젝트가 뒤집혀 보입니다. 좌표는 어떻게 동작하나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 수직 축이 아래를 향하고 깊이는 앞쪽으로 커진다고 설명한 뒤, 카메라 설정과 시점을 올바르게 기울이거나 회전시키는 방법을 설명합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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
자주 묻는 질문
오브젝트가 왜 뒤집혀 보이나요?
melonJS는 일반적인 OpenGL 방식과 반대로, 수직 축이 아래를 향합니다.
카메라를 어떻게 롤(roll)하나요?
roll 값을 설정하라고 스킬은 안내합니다. 카메라 회전 호출은 3D 뷰에 영향을 주지 않기 때문입니다.
모든 기기에서 3D가 작동하나요?
Canvas 대체 방식에서는 일부 기능이 작동하지 않으며, 이 기능들은 GPU 백엔드가 필요하다고 스킬은 설명합니다.
상세 정보
작성자의 원본 설명
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
인기도
- GitHub 스타
- 6.4k
- 순위
- #14196
- 라이선스
- MIT
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
melonjs-20-migration
6.4k에이전트가 melonJS 20 버전에 맞는 게임 코드를 작성하고, 필수 비동기 시작 방식 등 이전 버전의 오래된 메서드를 피하도록 돕습니다.
melonjs-3d-assets
6.4k에이전트가 glTF, GLB, OBJ 같은 3D 모델 파일을 melonJS 브라우저 게임에 불러오고, 크기와 조명 옵션을 설정하도록 돕습니다.
melonjs-audio
6.4k에이전트가 melonJS 게임에 효과음과 배경 음악을 추가하고, 오디오 설정, 음량 조절, 공간 음향까지 다루도록 돕습니다.
melonjs-camera-and-drawing
6.4k에이전트가 플레이어를 따라가는 등 melonJS 게임 카메라를 제어하고, 게임 안에 사용자 정의 도형과 선을 그리도록 돕습니다.