create-playcanvas 0.10.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +26 -3
  2. package/dist/index.mjs +41 -38
  3. package/package.json +6 -3
  4. package/templates/_features/physics/assets/public/ammo/SOURCE.md +4 -1
  5. package/templates/{react/interactive-sphere/src/App.css → _shared/interactive-sphere/src/counter.css} +0 -6
  6. package/templates/_shared/web-lens/README.md +42 -0
  7. package/templates/_shared/web-lens/package.json +9 -0
  8. package/templates/_shared/web-lens/scripts/package-lens.mjs +231 -0
  9. package/templates/_shared/web-lens/src/dodge-game.ts +271 -0
  10. package/templates/_shared/web-lens/src/lens.css +155 -0
  11. package/templates/_shared/web-lens/src/lens.ts +91 -0
  12. package/templates/engine/base/README.md +1 -1
  13. package/templates/engine/base/package.json +4 -4
  14. package/templates/engine/base/vite.config.ts +3 -0
  15. package/templates/engine/first-person-controller/src/main.ts +2 -3
  16. package/templates/engine/interactive-sphere/src/App.ts +1 -1
  17. package/templates/engine/interactive-sphere/src/main.ts +3 -5
  18. package/templates/engine/model-viewer/src/main.ts +3 -3
  19. package/templates/engine/physics-playground/src/main.ts +2 -3
  20. package/templates/engine/spinning-cube/src/main.ts +1 -1
  21. package/templates/engine/splat-viewer/src/main.ts +1 -1
  22. package/templates/engine/third-person-controller/src/main.ts +2 -3
  23. package/templates/engine/web-lens/index.html +26 -0
  24. package/templates/engine/web-lens/src/main.ts +89 -0
  25. package/templates/engine/web-lens/vite.config.ts +44 -0
  26. package/templates/index.ts +6 -0
  27. package/templates/react/base/README.md +1 -1
  28. package/templates/react/base/package.json +6 -6
  29. package/templates/react/base/vite.config.ts +3 -0
  30. package/templates/react/interactive-sphere/src/App.tsx +5 -6
  31. package/templates/react/interactive-sphere/src/Scene.tsx +1 -1
  32. package/templates/react/model-viewer/src/App.tsx +4 -2
  33. package/templates/react/spinning-cube/src/App.tsx +2 -0
  34. package/templates/react/splat-viewer/src/App.tsx +2 -0
  35. package/templates/react/{splat-viewer → web-lens}/index.html +2 -3
  36. package/templates/react/web-lens/src/App.tsx +85 -0
  37. package/templates/react/web-lens/vite.config.ts +46 -0
  38. package/templates/web-components/base/README.md +1 -1
  39. package/templates/web-components/base/package.json +4 -4
  40. package/templates/web-components/base/vite.config.ts +3 -0
  41. package/templates/web-components/first-person-controller/index.html +1 -6
  42. package/templates/web-components/interactive-sphere/src/main.ts +2 -2
  43. package/templates/web-components/model-viewer/index.html +2 -2
  44. package/templates/web-components/model-viewer/src/main.ts +0 -1
  45. package/templates/web-components/physics-playground/index.html +1 -6
  46. package/templates/web-components/spinning-cube/src/main.ts +0 -1
  47. package/templates/web-components/splat-viewer/src/main.ts +0 -1
  48. package/templates/web-components/third-person-controller/index.html +1 -6
  49. package/templates/web-components/web-lens/index.html +36 -0
  50. package/templates/web-components/web-lens/src/main.ts +47 -0
  51. package/templates/web-components/web-lens/vite.config.ts +44 -0
  52. package/templates/_features/physics/assets/public/ammo/ammo.js +0 -973
  53. package/templates/engine/interactive-sphere/index.html +0 -13
  54. package/templates/engine/interactive-sphere/src/style.css +0 -28
  55. package/templates/engine/model-viewer/index.html +0 -13
  56. package/templates/engine/model-viewer/src/style.css +0 -8
  57. package/templates/engine/spinning-cube/index.html +0 -13
  58. package/templates/engine/spinning-cube/src/style.css +0 -8
  59. package/templates/engine/splat-viewer/index.html +0 -13
  60. package/templates/engine/splat-viewer/src/style.css +0 -8
  61. package/templates/react/base/.prettierignore +0 -3
  62. package/templates/react/base/_gitignore +0 -24
  63. package/templates/react/base/_npmrc +0 -1
  64. package/templates/react/base/prettier.config.mjs +0 -1
  65. package/templates/react/base/src/assets/playcanvas.png +0 -0
  66. package/templates/react/base/src/inspector.css +0 -33
  67. package/templates/react/base/src/inspector.ts +0 -38
  68. package/templates/react/base/src/starter.css +0 -104
  69. package/templates/react/base/src/vite-env.d.ts +0 -19
  70. package/templates/react/interactive-sphere/index.html +0 -13
  71. package/templates/react/interactive-sphere/src/index.css +0 -4
  72. package/templates/react/interactive-sphere/src/main.tsx +0 -11
  73. package/templates/react/model-viewer/index.html +0 -13
  74. package/templates/react/model-viewer/src/index.css +0 -9
  75. package/templates/react/model-viewer/src/main.tsx +0 -11
  76. package/templates/react/spinning-cube/index.html +0 -13
  77. package/templates/react/spinning-cube/src/index.css +0 -9
  78. package/templates/react/spinning-cube/src/main.tsx +0 -11
  79. package/templates/react/splat-viewer/src/index.css +0 -9
  80. package/templates/react/splat-viewer/src/main.tsx +0 -11
  81. package/templates/web-components/base/.prettierignore +0 -3
  82. package/templates/web-components/base/_gitignore +0 -24
  83. package/templates/web-components/base/_npmrc +0 -1
  84. package/templates/web-components/base/prettier.config.mjs +0 -1
  85. package/templates/web-components/base/src/assets/playcanvas.png +0 -0
  86. package/templates/web-components/base/src/inspector.css +0 -33
  87. package/templates/web-components/base/src/inspector.ts +0 -38
  88. package/templates/web-components/base/src/starter.css +0 -104
  89. package/templates/web-components/base/src/vite-env.d.ts +0 -19
  90. package/templates/web-components/interactive-sphere/src/style.css +0 -53
  91. package/templates/web-components/model-viewer/src/style.css +0 -8
  92. package/templates/web-components/spinning-cube/src/style.css +0 -8
  93. package/templates/web-components/splat-viewer/src/style.css +0 -8
  94. /package/templates/{engine/base → _common}/.prettierignore +0 -0
  95. /package/templates/{engine/base → _common}/_gitignore +0 -0
  96. /package/templates/{engine/base → _common}/_npmrc +0 -0
  97. /package/templates/{engine/base → _common}/prettier.config.mjs +0 -0
  98. /package/templates/{engine/base → _common}/src/assets/playcanvas.png +0 -0
  99. /package/templates/{engine/base → _common}/src/inspector.css +0 -0
  100. /package/templates/{engine/base → _common}/src/inspector.ts +0 -0
  101. /package/templates/{engine/base → _common}/src/starter.css +0 -0
  102. /package/templates/{engine/base → _common}/src/vite-env.d.ts +0 -0
@@ -0,0 +1,46 @@
1
+ import react from '@vitejs/plugin-react';
2
+ import { defineConfig } from 'vite';
3
+
4
+ // Approximates the Web Lens sandbox, which allows resources from the Lens itself and nothing else
5
+ const LENS_SANDBOX = [
6
+ "default-src 'self' data: blob:",
7
+ "script-src 'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' blob:",
8
+ "style-src 'self' 'unsafe-inline'",
9
+ "frame-src 'none'",
10
+ "object-src 'none'",
11
+ "base-uri 'none'",
12
+ "form-action 'none'"
13
+ ].join('; ');
14
+
15
+ // https://vite.dev/config/
16
+ export default defineConfig({
17
+ // Snapchat serves a Lens from its own origin, so every URL in the build must be relative
18
+ base: './',
19
+ build: {
20
+ // npm run package zips this folder and writes the zip beside it, inside the ignored dist/
21
+ outDir: 'dist/lens',
22
+ // source maps only add to the 8 MB upload
23
+ sourcemap: false
24
+ },
25
+ preview: {
26
+ // npm run start serves the build under the Lens rules, so a request for anything outside
27
+ // the zip fails in the browser console as it would in Snapchat
28
+ headers: {
29
+ 'Content-Security-Policy': LENS_SANDBOX,
30
+ 'Cross-Origin-Opener-Policy': 'same-origin',
31
+ 'Cross-Origin-Embedder-Policy': 'require-corp'
32
+ }
33
+ },
34
+ plugins: [
35
+ react(),
36
+ {
37
+ // Dev only: install the PlayCanvas Inspector before the app starts (press ` to toggle)
38
+ name: 'playcanvas-inspector',
39
+ apply: 'serve',
40
+ config: () => ({ optimizeDeps: { include: ['@playcanvas/inspector'] } }),
41
+ transformIndexHtml: () => [
42
+ { tag: 'script', attrs: { type: 'module', src: '/src/inspector.ts' }, injectTo: 'head-prepend' }
43
+ ]
44
+ }
45
+ ]
46
+ });
@@ -33,7 +33,7 @@ Open <http://localhost:5173>. Edit `index.html` to change the scene.
33
33
  | `npm run fmt` | Check formatting |
34
34
  | `npm run typecheck` | Run TypeScript checks |
35
35
 
36
- Run `npm run build` to generate a deployable static site in `dist/`.
36
+ Run `npm run build` to generate a deployable static site in `dist/`. Its paths are relative, so it runs from any folder, such as a GitHub Pages project site or an itch.io upload.
37
37
 
38
38
  ## How it fits together
39
39
 
@@ -16,15 +16,15 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@playcanvas/web-components": "^0.28.0",
19
- "playcanvas": "^2.23.1"
19
+ "playcanvas": "^2.23.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@playcanvas/eslint-config": "3.0.0-beta.8",
23
- "@playcanvas/inspector": "^0.2.0",
23
+ "@playcanvas/inspector": "^0.3.0",
24
24
  "eslint": "^9.39.5",
25
- "prettier": "^3.9.9",
25
+ "prettier": "^3.9.10",
26
26
  "typescript": "~6.0.3",
27
- "vite": "^8.3.4"
27
+ "vite": "^8.3.5"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=22.23.2"
@@ -2,6 +2,9 @@ import { defineConfig } from 'vite';
2
2
 
3
3
  // https://vite.dev/config/
4
4
  export default defineConfig({
5
+ // Relative URLs, so the build runs wherever it's served from: a domain root, a subpath such as
6
+ // GitHub Pages or itch.io, or a Snapchat Web Lens
7
+ base: './',
5
8
  plugins: [
6
9
  {
7
10
  // Dev only: install the PlayCanvas Inspector before the app starts (press ` to toggle)
@@ -14,12 +14,7 @@
14
14
  <pc-material id="green-material" diffuse="#2e6638" emissive="#09140b" gloss="0.2"></pc-material>
15
15
  <pc-material id="wood-material" diffuse="#7a451a" emissive="#180e05" gloss="0.2"></pc-material>
16
16
  <pc-material id="metal-material" diffuse="#475461" emissive="#0e1113" gloss="0.5"></pc-material>
17
- <pc-wasm
18
- name="Ammo"
19
- glue="/ammo/ammo.wasm.js"
20
- wasm="/ammo/ammo.wasm.wasm"
21
- fallback="/ammo/ammo.js"
22
- ></pc-wasm>
17
+ <pc-wasm name="Ammo" glue="./ammo/ammo.wasm.js" wasm="./ammo/ammo.wasm.wasm"></pc-wasm>
23
18
  <pc-scene>
24
19
  <pc-entity name="light" rotation="50 30 0"
25
20
  ><pc-light
@@ -4,8 +4,8 @@ import { Asset, TEXTURETYPE_RGBP } from 'playcanvas';
4
4
  import { CameraControls } from 'playcanvas/scripts/esm/camera-controls.mjs';
5
5
  import { Grid } from 'playcanvas/scripts/esm/grid.mjs';
6
6
 
7
+ import './counter.css';
7
8
  import './starter.css';
8
- import './style.css';
9
9
 
10
10
  const HOVER_COLOR = '#40ccff';
11
11
  const DEFAULT_COLOR = '#e6edf9';
@@ -25,7 +25,7 @@ const app = appElement.app!;
25
25
  const envAtlas = new Asset(
26
26
  'env-atlas',
27
27
  'texture',
28
- { url: '/environment-map.png' },
28
+ { url: './environment-map.png' },
29
29
  {
30
30
  type: TEXTURETYPE_RGBP,
31
31
  mipmaps: false
@@ -8,8 +8,8 @@
8
8
  </head>
9
9
  <body>
10
10
  <pc-app>
11
- <!-- Swap this for your own model - anything you drop in public/ is served from the site root -->
12
- <pc-asset id="model" src="/playcanvas-cube.glb"></pc-asset>
11
+ <!-- Swap this for your own model - files in public/ are served next to index.html, so use a ./ path -->
12
+ <pc-asset id="model" src="./playcanvas-cube.glb"></pc-asset>
13
13
 
14
14
  <pc-scene>
15
15
  <!-- Camera. Orbit controls are attached in src/main.ts. The sky is HDR, so it needs
@@ -4,7 +4,6 @@ import { CameraControls } from 'playcanvas/scripts/esm/camera-controls.mjs';
4
4
  import { ProceduralSky } from 'playcanvas/scripts/esm/sky/procedural-sky.mjs';
5
5
 
6
6
  import './starter.css';
7
- import './style.css';
8
7
 
9
8
  // The camera is awaited as <pc-camera> rather than the <pc-entity> holding it - an entity becomes
10
9
  // ready before its component children do, and CameraControls needs the camera component to exist
@@ -8,12 +8,7 @@
8
8
  </head>
9
9
  <body>
10
10
  <pc-app>
11
- <pc-wasm
12
- name="Ammo"
13
- glue="/ammo/ammo.wasm.js"
14
- wasm="/ammo/ammo.wasm.wasm"
15
- fallback="/ammo/ammo.js"
16
- ></pc-wasm>
11
+ <pc-wasm name="Ammo" glue="./ammo/ammo.wasm.js" wasm="./ammo/ammo.wasm.wasm"></pc-wasm>
17
12
  <pc-material id="floor-material" diffuse="#2e333d" gloss="0.2"></pc-material>
18
13
  <pc-material id="cyan-material" diffuse="#29ade6" gloss="0.45"></pc-material>
19
14
  <pc-material id="coral-material" diffuse="#f25738" gloss="0.45"></pc-material>
@@ -3,7 +3,6 @@ import { whenReady } from '@playcanvas/web-components';
3
3
  import { Script } from 'playcanvas';
4
4
 
5
5
  import './starter.css';
6
- import './style.css';
7
6
 
8
7
  class Rotate extends Script {
9
8
  static scriptName = 'rotate';
@@ -2,7 +2,6 @@ import { whenReady } from '@playcanvas/web-components';
2
2
  import { CameraControls } from 'playcanvas/scripts/esm/camera-controls.mjs';
3
3
 
4
4
  import './starter.css';
5
- import './style.css';
6
5
 
7
6
  // The camera is awaited as <pc-camera> rather than the <pc-entity> holding it - an entity becomes
8
7
  // ready before its component children do, and CameraControls needs the camera component to exist
@@ -16,12 +16,7 @@
16
16
  <pc-material id="shirt-material" diffuse="#268bd2"></pc-material>
17
17
  <pc-material id="skin-material" diffuse="#c78759"></pc-material>
18
18
  <pc-material id="pants-material" diffuse="#2e4a85"></pc-material>
19
- <pc-wasm
20
- name="Ammo"
21
- glue="/ammo/ammo.wasm.js"
22
- wasm="/ammo/ammo.wasm.wasm"
23
- fallback="/ammo/ammo.js"
24
- ></pc-wasm>
19
+ <pc-wasm name="Ammo" glue="./ammo/ammo.wasm.js" wasm="./ammo/ammo.wasm.wasm"></pc-wasm>
25
20
  <pc-scene>
26
21
  <pc-entity name="camera" position="0 3 6"><pc-camera clear-color="#7ab8e6"></pc-camera></pc-entity>
27
22
  <pc-entity name="light" rotation="45 30 0"
@@ -0,0 +1,36 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
+ <title>Dodge</title>
7
+ </head>
8
+ <body>
9
+ <main class="lens">
10
+ <pc-app max-pixel-ratio="2">
11
+ <pc-scene>
12
+ <pc-entity name="camera" position="0 0 7">
13
+ <pc-camera clear-color="#0b1020" fov="45" horizontal-fov></pc-camera>
14
+ </pc-entity>
15
+ <pc-entity name="light" rotation="40 30 0">
16
+ <pc-light type="directional" intensity="1.5"></pc-light>
17
+ </pc-entity>
18
+ <pc-entity name="game"></pc-entity>
19
+ </pc-scene>
20
+ </pc-app>
21
+ <div class="lens-hud">
22
+ <header class="lens-bar">
23
+ <img class="lens-avatar" alt="Your Bitmoji" hidden />
24
+ <span class="lens-score">0</span>
25
+ <span class="lens-best">Best 0</span>
26
+ </header>
27
+ <section class="lens-card">
28
+ <h1 class="lens-title">Dodge</h1>
29
+ <button class="lens-leaderboard" hidden>Leaderboard</button>
30
+ <p class="lens-hint">Drag to steer. Tap to play</p>
31
+ </section>
32
+ </div>
33
+ </main>
34
+ <script type="module" src="/src/main.ts"></script>
35
+ </body>
36
+ </html>
@@ -0,0 +1,47 @@
1
+ import type { EntityElement } from '@playcanvas/web-components';
2
+ import { whenReady } from '@playcanvas/web-components';
3
+
4
+ import { CARDS, DodgeGame } from './dodge-game';
5
+ import type { GameState } from './dodge-game';
6
+ import { hasLeaderboard, loadAvatar, loadBest, recordScore, showLeaderboard } from './lens';
7
+ import './lens.css';
8
+
9
+ // the HUD follows the game's state, and the Lens records each finished run
10
+ const hud = {
11
+ avatar: document.querySelector<HTMLImageElement>('.lens-avatar')!,
12
+ score: document.querySelector('.lens-score')!,
13
+ best: document.querySelector('.lens-best')!,
14
+ card: document.querySelector<HTMLElement>('.lens-card')!,
15
+ title: document.querySelector('.lens-title')!,
16
+ hint: document.querySelector('.lens-hint')!,
17
+ leaderboard: document.querySelector<HTMLButtonElement>('.lens-leaderboard')!
18
+ };
19
+ const showBest = (best: number) => {
20
+ hud.best.textContent = `Best ${best}`;
21
+ };
22
+
23
+ const { app } = await whenReady('pc-app');
24
+ app!.on('game:state', (state: GameState, score: number) => {
25
+ const card = CARDS[state];
26
+ hud.score.textContent = String(score);
27
+ hud.card.hidden = !card;
28
+ if (card) {
29
+ hud.title.textContent = card.title;
30
+ hud.hint.textContent = card.hint;
31
+ }
32
+ hud.leaderboard.hidden = state !== 'over' || !hasLeaderboard();
33
+ if (state === 'over') recordScore(score).then(showBest);
34
+ });
35
+ hud.leaderboard.addEventListener('click', showLeaderboard);
36
+
37
+ loadBest().then(showBest);
38
+ loadAvatar().then((url) => {
39
+ if (!url) return;
40
+ hud.avatar.src = url;
41
+ hud.avatar.hidden = false;
42
+ });
43
+
44
+ // the game is an engine script imported through the bundler, so it attaches through the entity
45
+ const game = await whenReady<EntityElement>('pc-entity[name="game"]');
46
+ game.entity!.addComponent('script');
47
+ game.entity!.script!.create(DodgeGame);
@@ -0,0 +1,44 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ // Approximates the Web Lens sandbox, which allows resources from the Lens itself and nothing else
4
+ const LENS_SANDBOX = [
5
+ "default-src 'self' data: blob:",
6
+ "script-src 'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' blob:",
7
+ "style-src 'self' 'unsafe-inline'",
8
+ "frame-src 'none'",
9
+ "object-src 'none'",
10
+ "base-uri 'none'",
11
+ "form-action 'none'"
12
+ ].join('; ');
13
+
14
+ // https://vite.dev/config/
15
+ export default defineConfig({
16
+ // Snapchat serves a Lens from its own origin, so every URL in the build must be relative
17
+ base: './',
18
+ build: {
19
+ // npm run package zips this folder and writes the zip beside it, inside the ignored dist/
20
+ outDir: 'dist/lens',
21
+ // source maps only add to the 8 MB upload
22
+ sourcemap: false
23
+ },
24
+ preview: {
25
+ // npm run start serves the build under the Lens rules, so a request for anything outside
26
+ // the zip fails in the browser console as it would in Snapchat
27
+ headers: {
28
+ 'Content-Security-Policy': LENS_SANDBOX,
29
+ 'Cross-Origin-Opener-Policy': 'same-origin',
30
+ 'Cross-Origin-Embedder-Policy': 'require-corp'
31
+ }
32
+ },
33
+ plugins: [
34
+ {
35
+ // Dev only: install the PlayCanvas Inspector before the app starts (press ` to toggle)
36
+ name: 'playcanvas-inspector',
37
+ apply: 'serve',
38
+ config: () => ({ optimizeDeps: { include: ['@playcanvas/inspector'] } }),
39
+ transformIndexHtml: () => [
40
+ { tag: 'script', attrs: { type: 'module', src: '/src/inspector.ts' }, injectTo: 'head-prepend' }
41
+ ]
42
+ }
43
+ ]
44
+ });