Skip to content

feat(gltf): glTF/GLB scene loader with lighting, materials & 3D bounds#1502

Merged
obiot merged 1 commit into
masterfrom
feat/gltf-loader
Jun 19, 2026
Merged

feat(gltf): glTF/GLB scene loader with lighting, materials & 3D bounds#1502
obiot merged 1 commit into
masterfrom
feat/gltf-loader

Conversation

@obiot

@obiot obiot commented Jun 19, 2026

Copy link
Copy Markdown
Member

What

Adds a glTF / GLB scene loader to melonJS. Author a 3D scene in Blender (or any DCC tool), export a .glb, and load the whole thing with one call — exactly like a Tiled map:

me.loader.preload([{ name: "level", type: "glb", src: "models/level.glb" }], () => {
  me.level.load("level", { scale: 32 });   // meshes instantiated, lit by the authored sun
});

This is part 1 of the 19.8 glTF work; node/TRS animation lands in a focused follow-up PR before the 19.8 tag.

Highlights

  • Loader.glb/.gltf auto-registers with the level director; each mesh node → a Mesh under Camera3d. Parses the node graph, POSITION/NORMAL/TEXCOORD_0/COLOR_0/indices, baseColorTexture + baseColorFactor, perspective cameras, scene bounds, and KHR_lights_punctual lights. loader.getGLTF(name) exposes the raw descriptor. Uint32 index buffers preserved (>65535-vertex meshes).
  • 3D mesh lightingLight3d + LightingEnvironment (directional, half-Lambert + ambient), auto-loaded from the scene's authored sun. Opt-in mesh.lit routes to a dedicated LitMeshBatcher, so standalone unlit meshes stay on the lean path.
  • Material colorbaseColorFactor → tint (solid-color untextured materials no longer render white); vertex colors (COLOR_0). Compose factor × vertexColor × texel, under lighting.
  • 3D boundsMesh.getBounds3d(), Camera3d.worldToScreen(), AABB3d exported (+ fromVertices), vertex.ts transformedBounds/boundingRadius.
  • Render fix — world-space meshes no longer leak the anchor-point offset into the mesh view matrix (Renderable.applyAnchorTransform); props were rendering at the wrong position under Camera3d, sinking into the surfaces they rested on.
  • @melonjs/debug-plugin 16.1.0 — 3D bounding-box wireframe overlay for meshes (requires melonJS ≥ 19.8).
  • New "glTF Scene" example (Kenney Platformer Kit, CC0).

Tests

~50 new tests (parser, lighting, materials/vertex colors, bounds, worldToScreen, the anchor fix). Full suite green (4140 passed). Verified end-to-end via Playwright/ANGLE.

Docs

Wiki updated (Loading glTF / GLB scenes, Working in 3D) + README + CHANGELOG.

🤖 Generated with Claude Code

@obiot obiot force-pushed the feat/gltf-loader branch from 0ce2c13 to c131236 Compare June 19, 2026 04:38
…unds

Load a Blender-authored 3D scene via `me.level.load(...)` like a Tiled map:
the GLB auto-registers with the level director and each mesh node becomes a
`Mesh` viewed under `Camera3d`.

- Parser (loader/parsers/gltf.js): node graph; POSITION / NORMAL / TEXCOORD_0
  / COLOR_0 / indices; baseColorTexture + baseColorFactor; perspective cameras;
  scene bounds; KHR_lights_punctual lights. Uint32 index buffers preserved.
- GLTFScene + level-director dispatch (gltf/glb); loader.getGLTF descriptor.
- 3D mesh lighting: Light3d + LightingEnvironment (directional, half-Lambert +
  ambient), auto-loaded from the scene's authored sun; LitMeshBatcher with an
  opt-in `mesh.lit` so unlit meshes keep the lean path.
- Material color: baseColorFactor -> mesh tint; vertex colors (COLOR_0).
- Mesh.getBounds3d() + Camera3d.worldToScreen() + AABB3d export/fromVertices +
  vertex.ts transformedBounds/boundingRadius.
- Fix: world-space meshes no longer leak the anchor-point offset into the mesh
  view matrix (Renderable.applyAnchorTransform) -- props rendered at the wrong
  position under Camera3d, sinking into the surfaces they rested on.
- @melonjs/debug-plugin 16.1.0: 3D bounding-box wireframe overlay for meshes.
- New glTF Scene example (Kenney Platformer Kit, CC0). ~50 new tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@obiot obiot force-pushed the feat/gltf-loader branch from c131236 to 51c6d6d Compare June 19, 2026 04:41
@obiot obiot merged commit 14e2f10 into master Jun 19, 2026
6 checks passed
@obiot obiot deleted the feat/gltf-loader branch June 19, 2026 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant