feat(gltf): glTF/GLB scene loader with lighting, materials & 3D bounds#1502
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: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
.glb/.gltfauto-registers with theleveldirector; each mesh node → aMeshunderCamera3d. Parses the node graph,POSITION/NORMAL/TEXCOORD_0/COLOR_0/indices,baseColorTexture+baseColorFactor, perspective cameras, scene bounds, andKHR_lights_punctuallights.loader.getGLTF(name)exposes the raw descriptor.Uint32index buffers preserved (>65535-vertex meshes).Light3d+LightingEnvironment(directional, half-Lambert + ambient), auto-loaded from the scene's authored sun. Opt-inmesh.litroutes to a dedicatedLitMeshBatcher, so standalone unlit meshes stay on the lean path.baseColorFactor→ tint (solid-color untextured materials no longer render white); vertex colors (COLOR_0). Composefactor × vertexColor × texel, under lighting.Mesh.getBounds3d(),Camera3d.worldToScreen(),AABB3dexported (+fromVertices),vertex.tstransformedBounds/boundingRadius.Renderable.applyAnchorTransform); props were rendering at the wrong position underCamera3d, sinking into the surfaces they rested on.@melonjs/debug-plugin16.1.0 — 3D bounding-box wireframe overlay for meshes (requires melonJS ≥ 19.8).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