Skip to content

Examples: the 3D examples await their level load - #1651

Merged
obiot merged 1 commit into
masterfrom
feat/examples-async-level-load
Sep 6, 2026
Merged

Examples: the 3D examples await their level load#1651
obiot merged 1 commit into
masterfrom
feat/examples-async-level-load

Conversation

@obiot

@obiot obiot commented Sep 6, 2026

Copy link
Copy Markdown
Member

The three 3D examples that go through the level director — forest, glTF scene and glTF character — now use the async option from #1647 instead of the onLoaded callback, so the setup that follows the load reads as ordinary sequential code:

await level.load("character", { scale: SCALE, async: true });
setupScene();

The other Camera3d examples (afterBurner, billboard, camera3d, materialTextures, nightcity) build their scenes in code and never call level.load, so there was nothing to convert. The remaining non-async call sites are all 2D and were left alone.

loader.preload deliberately keeps its callback form. Awaiting it would delay returning the teardown function, and the forest example needs that cleanup to exist while its 3 MB glb is still loading.

Also: a JSDoc default that shipped in the published types

LevelLoadOptions.castGroundShadow was documented as defaulting to false, but the option is tri-state — omitting it means "inherit the application setting", which is true in defaultApplicationSettings. The three sibling declarations (Mesh, GLTFScene, GLTFModel) already said "omit to inherit"; this was the odd one out.

The emitted type is unchanged (castGroundShadow?: boolean either way) — only the prose was wrong, in the direction that makes someone set the flag to true believing it is off.

Verification

  • tsc on the examples package: exit 0
  • eslint 0 errors, biome clean
  • full engine suite: 276 files, 6733 passed, exit 0
  • all three examples rendered in a real browser with zero console errors, and screenshots compared against the pre-change build: forest and glTF scene byte-identical (182100 B, 91528 B), the character differing by 316 B — the animation at a slightly different frame

No CHANGELOG entry: examples do not go in the engine changelog, and the JSDoc correction is below the bar for something a reader would act on.

🤖 Generated with Claude Code

https://claude.ai/code/session_012Aa37KGXZcnVrbn1yG4j1N

The three 3D examples that go through the level director — forest, glTF
scene and glTF character — now use the `async` option from #1647 instead
of the `onLoaded` callback, so the setup that follows the load reads as
ordinary sequential code.

`loader.preload` deliberately keeps its callback form. Awaiting it would
delay returning the teardown function, and the forest example needs that
cleanup to exist while its 3 MB glb is still loading.

Also corrects a JSDoc default that shipped in the published types:
`LevelLoadOptions.castGroundShadow` was documented as defaulting to
`false`, but the option is tri-state — omitting it means "inherit the
application setting", which is on by default. The three sibling
declarations (Mesh, GLTFScene, GLTFModel) already said so. The emitted
type is unchanged; only the prose was wrong, in the direction that makes
someone set the flag to `true` believing it is off.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Aa37KGXZcnVrbn1yG4j1N
Copilot AI lite review requested due to automatic review settings September 6, 2026 23:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The examples now pass async callbacks to loader.preload, but the loader does not await them, so errors after the first await can surface as unhandled promise rejections unless explicitly handled.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates the 3D level-director examples to use the async: true level.load form (so post-load setup can be written sequentially), and corrects a misleading JSDoc default for LevelLoadOptions.castGroundShadow.

Changes:

  • Converted the forest + glTF scene + glTF character examples from onLoaded to await level.load(..., { async: true }) followed by explicit setup calls.
  • Corrected LevelLoadOptions.castGroundShadow documentation to reflect tri-state “omit to inherit app setting” behavior.
File summaries
File Description
packages/melonjs/src/level/level.js Fixes castGroundShadow option prose to match tri-state/inheritance behavior.
packages/examples/src/examples/gltf/ExampleGltfCharacter.tsx Switches level load flow to async: true + sequential setup.
packages/examples/src/examples/gltf/ExampleGltf.tsx Switches level load flow to async: true + sequential setup.
packages/examples/src/examples/forest/ExampleForest.tsx Switches level load flow to async: true + sequential setup.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +249 to +253
await level.load("forest", {
scale: SCALE,
castGroundShadow: true,
shadowGroundY: GROUND_Y,
onLoaded: setupScene,
async: true,
Comment on lines +335 to 339
await level.load("diorama", {
scale: SCALE,
castGroundShadow: true,
onLoaded: setupScene,
async: true,
});
Comment on lines +271 to 275
// actually in the world, so the setup below reads as ordinary
// sequential code rather than a callback
await level.load("character", { scale: SCALE, async: true });
setupScene();
},
@obiot
obiot merged commit 398c40f into master Sep 6, 2026
7 checks passed
@obiot
obiot deleted the feat/examples-async-level-load branch September 6, 2026 23:54
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.

2 participants