refactor: inline example runtime urls#8746
Merged
Merged
Conversation
Contributor
|
Much nicer! |
Contributor
Author
Yep all works exactly the same |
efd6d09 to
68e342a
Compare
68e342a to
d86fdf4
Compare
32506f2 to
e65d0b8
Compare
bd399c5 to
38fa4a2
Compare
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.
Description
This updates how examples are authored and cleaned up in the examples browser. The goal is for new examples to look like normal ESM modules: use static imports for code/text sidecars, use simple runtime URL strings for files loaded by the engine, and let the iframe loader clean up PlayCanvas apps automatically. It also consolidates the author-facing examples browser context into examples/context, so examples import data and deviceType from one place. It also migrates example config metadata to multiline
// @configblocks with// @flagentries.Example config format:
Files Moved
examples/src/lib/examples/assets/wasm/./assets/wasm/draco/draco.wasm.jsand./assets/wasm/twgsl/twgsl.jsexamples/src/lib/ammo/*examples/assets/wasm/ammo/*./assets/wasm/ammo/...examples/src/lib/basis/*examples/assets/wasm/basis/*./assets/wasm/basis/...examples/src/lib/draco/*examples/assets/wasm/draco/*./assets/wasm/draco/...examples/src/lib/glslang/*examples/assets/wasm/glslang/*./assets/wasm/glslang/glslang.jsexamples/src/lib/twgsl/*examples/assets/wasm/twgsl/*./assets/wasm/twgsl/twgsl.jsImporting And Runtime URLs
import * as pc from 'playcanvas';import { data } from 'examples/observer';plusimport { deviceType } from 'examples/utils';import { data, deviceType } from 'examples/context';fileImport(...)or helper-generated URLsimport ... from 'examples/assets/...';import ... from 'playcanvas/scripts/...';loadES5fromexamples/utilslocalImport('module.mjs')import { helper } from './module.mjs';./shader.frag?rawimport shader from './shader.frag';import data from './data.json';*Urlimports orrootPath + 'assets/...'./assets/models/statue.glb*Urlimports orrootPath + 'scripts/...'./scripts/camera/orbit-camera.jsrootPath + 'static/lib/...'/examples/src/lib/..../assets/wasm/...Runtime URL rule of thumb:
./assets/...for files served fromexamples/assets/../scripts/...for shared engine scripts when they are loaded as script assets.examples/contextfor examples browser-provided state:dataand the selecteddeviceType.Cleanup And Destroy Conditions
appwithexport { app };so the loader could destroy itapp; no export is neededmodule.appfrom the imported example modulepc.AppBase.getApplication('application-canvas')#appInnermulti-appdestroycode had to remove additional apps/canvasesapplication-canvasis preservedexport { destroy };AppBase.destroy()Public API
No engine API changes. This only changes examples browser authoring conventions and loader cleanup behavior. The author-facing examples modules are now consolidated under
examples/context;examples/observerandexamples/utilsare no longer part of the examples import map.Manual Testing
misc_multi-app.htmluses<base href="../static/">./static/assets/wasm/twgsl/twgsl.jsand/static/assets/wasm/glslang/glslang.jsreturn 200.dataanddeviceTypefromexamples/context, andexamples/contextexposes only those two values.misc/hello-world, hot reloaded, and confirmedwindow.ready === truewith the app and canvas registered.misc/multi-app, added and removed an app, hot reloaded, and confirmed old extra canvases/apps were gone and new apps were registered.gaussian-splatting/benchmark, hot reloaded, and confirmed its benchmark UI was not duplicated.Checklist