Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/examples/src/examples/forest/ExampleForest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const createGame = async () => {

loader.preload(
[{ name: "forest", type: "glb", src: `${base}forest.glb` }],
() => {
async () => {
state.change(state.DEFAULT, true);
// one call — the instanced node becomes an InstancedMesh, the
// ground stays an ordinary Mesh, and the authored sun lights both
Expand All @@ -243,12 +243,16 @@ const createGame = async () => {
// read from the same instance buffer the trees draw from. The
// scene's ground plane is skipped automatically — it has no height
// to cast, and shadowing it with itself would smear the floor.
level.load("forest", {
// `async: true` hands back a promise that settles once the scene is
// actually in the world, so the setup below reads as ordinary
// sequential code rather than a callback
await level.load("forest", {
scale: SCALE,
castGroundShadow: true,
shadowGroundY: GROUND_Y,
onLoaded: setupScene,
async: true,
Comment on lines +249 to +253
});
setupScene();
},
);

Expand Down
10 changes: 7 additions & 3 deletions packages/examples/src/examples/gltf/ExampleGltf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const createGame = async () => {

loader.preload(
[{ name: "diorama", type: "glb", src: `${base}platformer-diorama.glb` }],
() => {
async () => {
state.change(state.DEFAULT, true);
// load the whole glTF scene into the world in one call — the glb
// auto-registered with the level director on preload, exactly like
Expand All @@ -329,11 +329,15 @@ const createGame = async () => {
// heights rather than on one floor. The scene's ground/platform
// meshes are skipped automatically: they have no height to cast
// from, and shadowing them with themselves would smear the terrain.
level.load("diorama", {
// `async: true` hands back a promise that settles once the scene is
// actually in the world, so the setup below reads as ordinary
// sequential code rather than a callback
await level.load("diorama", {
scale: SCALE,
castGroundShadow: true,
onLoaded: setupScene,
async: true,
});
Comment on lines +335 to 339
setupScene();
},
);

Expand Down
8 changes: 6 additions & 2 deletions packages/examples/src/examples/gltf/ExampleGltfCharacter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,13 @@ const createGame = async () => {
// the GLB references an external texture (Textures/texture-a.png),
// resolved relative to the asset URL by the loader — no repackaging.
[{ name: "character", type: "glb", src: `${base}character.glb` }],
() => {
async () => {
state.change(state.DEFAULT, true);
level.load("character", { scale: SCALE, onLoaded: setupScene });
// `async: true` hands back a promise that settles once the scene is
// 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();
},
Comment on lines +271 to 275
);

Expand Down
2 changes: 1 addition & 1 deletion packages/melonjs/src/level/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function levelIdAt(offset) {
* @property {boolean} [rightHanded=true] - (glTF/GLB only) convert the right-handed (Y-up) source to the engine's Y-down via a rotation rather than a mirror
* @property {boolean} [lights=true] - (glTF/GLB only) add the scene's authored `KHR_lights_punctual` lights (plus a soft ambient fill) as {@link Light3d} world children
* @property {number} [lightIntensityScale] - (glTF/GLB only) multiply each light's authored physical intensity by this factor instead of normalizing it to 1
* @property {boolean} [castGroundShadow=false] - (glTF/GLB only) give every mesh in the scene a ground shadow
* @property {boolean} [castGroundShadow] - (glTF/GLB only) give every mesh in the scene a ground shadow; omit to inherit the application's `castGroundShadow` setting (on by default)
* @property {number} [shadowGroundY] - (glTF/GLB only) world Y the ground shadows land on
*/

Expand Down
Loading