create-playcanvas 0.11.0 → 0.12.0

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 (95) hide show
  1. package/README.md +21 -4
  2. package/dist/index.mjs +41 -39
  3. package/package.json +5 -2
  4. package/templates/_common/CLAUDE.md +1 -0
  5. package/templates/_features/physics/assets/public/ammo/SOURCE.md +4 -1
  6. package/templates/{react/interactive-sphere/src/App.css → _shared/interactive-sphere/src/counter.css} +0 -6
  7. package/templates/_shared/web-lens/AGENTS.md +10 -0
  8. package/templates/engine/base/AGENTS.md +37 -0
  9. package/templates/engine/base/README.md +15 -11
  10. package/templates/engine/base/package.json +1 -1
  11. package/templates/engine/base/vite.config.ts +8 -0
  12. package/templates/engine/first-person-controller/src/main.ts +2 -3
  13. package/templates/engine/interactive-sphere/src/App.ts +1 -1
  14. package/templates/engine/interactive-sphere/src/main.ts +3 -5
  15. package/templates/engine/model-viewer/src/main.ts +3 -3
  16. package/templates/engine/physics-playground/src/main.ts +2 -3
  17. package/templates/engine/spinning-cube/src/main.ts +1 -1
  18. package/templates/engine/splat-viewer/src/main.ts +1 -1
  19. package/templates/engine/third-person-controller/src/main.ts +2 -3
  20. package/templates/engine/web-lens/vite.config.ts +4 -1
  21. package/templates/react/base/AGENTS.md +41 -0
  22. package/templates/react/base/README.md +15 -11
  23. package/templates/react/base/package.json +1 -1
  24. package/templates/react/base/vite.config.ts +8 -0
  25. package/templates/react/interactive-sphere/src/App.tsx +5 -6
  26. package/templates/react/interactive-sphere/src/Scene.tsx +1 -1
  27. package/templates/react/model-viewer/src/App.tsx +4 -2
  28. package/templates/react/spinning-cube/src/App.tsx +2 -0
  29. package/templates/react/splat-viewer/src/App.tsx +2 -0
  30. package/templates/react/web-lens/vite.config.ts +4 -1
  31. package/templates/web-components/base/AGENTS.md +39 -0
  32. package/templates/web-components/base/README.md +15 -11
  33. package/templates/web-components/base/package.json +2 -2
  34. package/templates/web-components/base/vite.config.ts +8 -0
  35. package/templates/web-components/first-person-controller/index.html +1 -6
  36. package/templates/web-components/interactive-sphere/src/main.ts +2 -2
  37. package/templates/web-components/model-viewer/index.html +2 -2
  38. package/templates/web-components/model-viewer/src/main.ts +0 -1
  39. package/templates/web-components/physics-playground/index.html +1 -6
  40. package/templates/web-components/spinning-cube/src/main.ts +0 -1
  41. package/templates/web-components/splat-viewer/src/main.ts +0 -1
  42. package/templates/web-components/third-person-controller/index.html +1 -6
  43. package/templates/web-components/web-lens/vite.config.ts +4 -1
  44. package/templates/_features/physics/assets/public/ammo/ammo.js +0 -973
  45. package/templates/engine/interactive-sphere/index.html +0 -13
  46. package/templates/engine/interactive-sphere/src/style.css +0 -28
  47. package/templates/engine/model-viewer/index.html +0 -13
  48. package/templates/engine/model-viewer/src/style.css +0 -8
  49. package/templates/engine/spinning-cube/index.html +0 -13
  50. package/templates/engine/spinning-cube/src/style.css +0 -8
  51. package/templates/engine/splat-viewer/index.html +0 -13
  52. package/templates/engine/splat-viewer/src/style.css +0 -8
  53. package/templates/react/base/.prettierignore +0 -3
  54. package/templates/react/base/_gitignore +0 -24
  55. package/templates/react/base/_npmrc +0 -1
  56. package/templates/react/base/prettier.config.mjs +0 -1
  57. package/templates/react/base/src/assets/playcanvas.png +0 -0
  58. package/templates/react/base/src/inspector.css +0 -33
  59. package/templates/react/base/src/inspector.ts +0 -38
  60. package/templates/react/base/src/starter.css +0 -104
  61. package/templates/react/base/src/vite-env.d.ts +0 -19
  62. package/templates/react/interactive-sphere/index.html +0 -13
  63. package/templates/react/interactive-sphere/src/index.css +0 -4
  64. package/templates/react/interactive-sphere/src/main.tsx +0 -11
  65. package/templates/react/model-viewer/index.html +0 -13
  66. package/templates/react/model-viewer/src/index.css +0 -9
  67. package/templates/react/model-viewer/src/main.tsx +0 -11
  68. package/templates/react/spinning-cube/index.html +0 -13
  69. package/templates/react/spinning-cube/src/index.css +0 -9
  70. package/templates/react/spinning-cube/src/main.tsx +0 -11
  71. package/templates/react/splat-viewer/index.html +0 -13
  72. package/templates/react/splat-viewer/src/index.css +0 -9
  73. package/templates/react/splat-viewer/src/main.tsx +0 -11
  74. package/templates/web-components/base/.prettierignore +0 -3
  75. package/templates/web-components/base/_gitignore +0 -24
  76. package/templates/web-components/base/_npmrc +0 -1
  77. package/templates/web-components/base/prettier.config.mjs +0 -1
  78. package/templates/web-components/base/src/assets/playcanvas.png +0 -0
  79. package/templates/web-components/base/src/inspector.css +0 -33
  80. package/templates/web-components/base/src/inspector.ts +0 -38
  81. package/templates/web-components/base/src/starter.css +0 -104
  82. package/templates/web-components/base/src/vite-env.d.ts +0 -19
  83. package/templates/web-components/interactive-sphere/src/style.css +0 -53
  84. package/templates/web-components/model-viewer/src/style.css +0 -8
  85. package/templates/web-components/spinning-cube/src/style.css +0 -8
  86. package/templates/web-components/splat-viewer/src/style.css +0 -8
  87. /package/templates/{engine/base → _common}/.prettierignore +0 -0
  88. /package/templates/{engine/base → _common}/_gitignore +0 -0
  89. /package/templates/{engine/base → _common}/_npmrc +0 -0
  90. /package/templates/{engine/base → _common}/prettier.config.mjs +0 -0
  91. /package/templates/{engine/base → _common}/src/assets/playcanvas.png +0 -0
  92. /package/templates/{engine/base → _common}/src/inspector.css +0 -0
  93. /package/templates/{engine/base → _common}/src/inspector.ts +0 -0
  94. /package/templates/{engine/base → _common}/src/starter.css +0 -0
  95. /package/templates/{engine/base → _common}/src/vite-env.d.ts +0 -0
@@ -16,7 +16,7 @@ import {
16
16
  } from 'playcanvas';
17
17
  import { CameraControls } from 'playcanvas/scripts/esm/camera-controls.mjs';
18
18
 
19
- import './style.css';
19
+ import './starter.css';
20
20
 
21
21
  // Hosted so the template stays small. Capture or edit your own splat at https://superspl.at, then
22
22
  // drop the .sog or .ply in public/ and point this at it instead
@@ -42,9 +42,8 @@ const PINE_LAYERS: [number, number, number][] = [
42
42
  ];
43
43
 
44
44
  WasmModule.setConfig('Ammo', {
45
- glueUrl: '/ammo/ammo.wasm.js',
46
- wasmUrl: '/ammo/ammo.wasm.wasm',
47
- fallbackUrl: '/ammo/ammo.js'
45
+ glueUrl: './ammo/ammo.wasm.js',
46
+ wasmUrl: './ammo/ammo.wasm.wasm'
48
47
  });
49
48
  await new Promise<void>((resolve) => {
50
49
  WasmModule.getInstance('Ammo', () => resolve());
@@ -19,7 +19,10 @@ export default defineConfig({
19
19
  // npm run package zips this folder and writes the zip beside it, inside the ignored dist/
20
20
  outDir: 'dist/lens',
21
21
  // source maps only add to the 8 MB upload
22
- sourcemap: false
22
+ sourcemap: false,
23
+ // a PlayCanvas build is 1-2.5 MB minified, nearly all of it engine code the first frame needs,
24
+ // so warn only for chunks well past that rather than at Vite's 500 kB default
25
+ chunkSizeWarningLimit: 3000
23
26
  },
24
27
  preview: {
25
28
  // npm run start serves the build under the Lens rules, so a request for anything outside
@@ -0,0 +1,41 @@
1
+ # AGENTS.md
2
+
3
+ A PlayCanvas app in TypeScript and React, built with Vite. The scene is declared in JSX with `@playcanvas/react`, which drives the PlayCanvas Engine. `README.md` describes the starter this project began from and how to control it.
4
+
5
+ ## Commands
6
+
7
+ - `npm install` installs dependencies.
8
+ - `npm run dev` starts the dev server, usually at <http://localhost:5173>, with hot reload and the PlayCanvas Inspector.
9
+ - `npm run typecheck` checks types.
10
+ - `npm run lint` runs ESLint, and `npm run lint:fix` fixes what it can.
11
+ - `npm run fmt` checks formatting, and `npm run fmt:fix` applies Prettier.
12
+ - `npm run build` builds the production site into `dist/`, and `npm run start` serves it.
13
+
14
+ ## Layout
15
+
16
+ - `index.html` is the page, with the `#root` element React renders into.
17
+ - `src/main.tsx` mounts `<App />` inside `<StrictMode>`.
18
+ - `src/App.tsx` holds the scene: an `<Application>` of `<Entity>` elements, with components such as `<Camera>`, `<Light>` and `<Render>` inside them.
19
+ - `src/starter.css` styles the page and the starter's panels.
20
+ - `src/inspector.ts` loads the Inspector. `vite.config.ts` adds it in the dev server only, so production builds leave it out.
21
+ - `public/` holds files copied into the build as they are, such as models and textures.
22
+
23
+ ## Conventions
24
+
25
+ - Import `<Application>` and `<Entity>` from `@playcanvas/react`, components from `@playcanvas/react/components` and hooks such as `useApp`, `useAppEvent` and `useModel` from `@playcanvas/react/hooks`. Engine classes and types come from `playcanvas`.
26
+ - Reach an entity's engine object through a `ref`, typed with `Entity` from `playcanvas`.
27
+ - Do per-frame work in `useAppEvent('update', (dt) => ...)` on engine objects, not in React state, which would re-render every frame.
28
+ - In development, `<StrictMode>` mounts each component twice, so anything an effect adds to the engine, such as an entity, a script or an event listener, needs a cleanup that removes it.
29
+ - Builds use relative URLs (`base: './'` in `vite.config.ts`), so they run from any folder. Load files in `public/` with relative paths such as `./model.glb`, not `/model.glb`.
30
+ - The engine ships ready-made scripts, such as camera controls and character controllers, under `playcanvas/scripts/esm/`. Use one before writing the same behavior yourself.
31
+ - `node_modules/playcanvas/build/playcanvas.d.ts` documents the installed engine's API.
32
+ - TypeScript is strict, and unused locals and parameters are errors.
33
+
34
+ ## Checking your work
35
+
36
+ - Run `npm run typecheck`, `npm run lint` and `npm run build` before you finish. All three must pass.
37
+ - To see the result, run `npm run dev` and open the page in a browser. The console should show `Powered by PlayCanvas` and no errors. Press the backquote key for the Inspector, which shows the hierarchy, assets, materials, textures, frame graph and physics. <kbd>F9</kbd> pauses and <kbd>F10</kbd> steps a frame.
38
+
39
+ ## Agent skills
40
+
41
+ `.claude/skills/` and `.agents/skills/` hold PlayCanvas skills for coding agents. Use them rather than working from memory: `build-app` when restructuring the app, `find-examples` for a feature the project doesn't use yet, `reuse-scripts` before writing a behavior, `inspect-glb` before placing a model, `inspect-runtime` to read state from the running app, and `verify-pixels` to prove a refactor leaves the image unchanged.
@@ -9,8 +9,6 @@ Node.js 22.23.2 or later.
9
9
  ## Getting started
10
10
 
11
11
  ```bash
12
- npm create playcanvas@latest playcanvas-project -- --format react
13
- cd playcanvas-project
14
12
  npm install
15
13
  npm run dev
16
14
  ```
@@ -23,16 +21,22 @@ Open <http://localhost:5173>. Edit the files under `src/` and save to see the sc
23
21
 
24
22
  ## Scripts
25
23
 
26
- | Command | Description |
27
- | ------------------- | --------------------------------- |
28
- | `npm run dev` | Start the Vite development server |
29
- | `npm run build` | Build for production |
30
- | `npm run start` | Preview the production build |
31
- | `npm run lint` | Run ESLint |
32
- | `npm run fmt` | Check formatting |
33
- | `npm run typecheck` | Run TypeScript checks |
24
+ Run these with `npm run <script>`:
34
25
 
35
- Run `npm run build` to generate a deployable static site in `dist/`.
26
+ | Script | Description |
27
+ | ----------- | --------------------------------- |
28
+ | `dev` | Start the Vite development server |
29
+ | `build` | Build for production |
30
+ | `start` | Preview the production build |
31
+ | `lint` | Run ESLint |
32
+ | `fmt` | Check formatting |
33
+ | `typecheck` | Run TypeScript checks |
34
+
35
+ 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.
36
+
37
+ ## Coding agents
38
+
39
+ `AGENTS.md` gives coding agents such as Claude Code, Codex and Cursor this project's commands, layout, conventions and checks. `CLAUDE.md` imports it for Claude Code.
36
40
 
37
41
  ## Agent skills
38
42
 
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "@playcanvas/eslint-config": "3.0.0-beta.8",
25
- "@playcanvas/inspector": "^0.3.0",
25
+ "@playcanvas/inspector": "^0.4.0",
26
26
  "@types/react": "^19.3.0",
27
27
  "@types/react-dom": "^19.3.0",
28
28
  "@vitejs/plugin-react": "^6.1.2",
@@ -3,6 +3,14 @@ import { defineConfig } from 'vite';
3
3
 
4
4
  // https://vite.dev/config/
5
5
  export default defineConfig({
6
+ // Relative URLs, so the build runs wherever it's served from: a domain root, a subpath such as
7
+ // GitHub Pages or itch.io, or a Snapchat Web Lens
8
+ base: './',
9
+ build: {
10
+ // A PlayCanvas build is 1-2.5 MB minified (300-600 kB gzipped), nearly all of it engine code the
11
+ // first frame needs, so warn only for chunks well past that rather than at Vite's 500 kB default
12
+ chunkSizeWarningLimit: 3000
13
+ },
6
14
  plugins: [
7
15
  react(),
8
16
  {
@@ -1,19 +1,18 @@
1
1
  import { Application } from '@playcanvas/react';
2
2
  import { useState } from 'react';
3
3
 
4
- import './App.css';
4
+ import './counter.css';
5
5
  import Scene from './Scene';
6
+ import './starter.css';
6
7
 
7
8
  function App() {
8
9
  const [count, setCount] = useState(0);
9
10
 
10
11
  return (
11
12
  <>
12
- <div className="full-bleed">
13
- <Application className="playcanvas-app">
14
- <Scene onClick={() => setCount((count) => count + 1)} />
15
- </Application>
16
- </div>
13
+ <Application className="playcanvas-app">
14
+ <Scene onClick={() => setCount((count) => count + 1)} />
15
+ </Application>
17
16
  <p className="counter">Click count: {count}</p>
18
17
  </>
19
18
  );
@@ -18,7 +18,7 @@ function Scene({ onClick }: SceneProps) {
18
18
  const material = useMaterial({ diffuse });
19
19
 
20
20
  // Load the environment map
21
- const { asset: envMap } = useEnvAtlas('/environment-map.png');
21
+ const { asset: envMap } = useEnvAtlas('./environment-map.png');
22
22
 
23
23
  // Change the mouse cursor based on the hover state
24
24
  useEffect(() => {
@@ -5,8 +5,10 @@ import { TONEMAP_ACES2 } from 'playcanvas';
5
5
  import { CameraControls } from 'playcanvas/scripts/esm/camera-controls.mjs';
6
6
  import { ProceduralSky } from 'playcanvas/scripts/esm/sky/procedural-sky.mjs';
7
7
 
8
- // Swap this for your own model - anything you drop in public/ is served from the site root
9
- const MODEL_URL = '/playcanvas-cube.glb';
8
+ import './starter.css';
9
+
10
+ // Swap this for your own model - files in public/ are served next to index.html, so use a ./ path
11
+ const MODEL_URL = './playcanvas-cube.glb';
10
12
 
11
13
  function Model() {
12
14
  const { asset } = useModel(MODEL_URL);
@@ -4,6 +4,8 @@ import { useAppEvent } from '@playcanvas/react/hooks';
4
4
  import type { Entity as PcEntity } from 'playcanvas';
5
5
  import { useRef } from 'react';
6
6
 
7
+ import './starter.css';
8
+
7
9
  function Scene() {
8
10
  const cube = useRef<PcEntity>(null);
9
11
 
@@ -3,6 +3,8 @@ import { Camera, GSplat, Script } from '@playcanvas/react/components';
3
3
  import { useSplat } from '@playcanvas/react/hooks';
4
4
  import { CameraControls } from 'playcanvas/scripts/esm/camera-controls.mjs';
5
5
 
6
+ import './starter.css';
7
+
6
8
  // Hosted so the template stays small. Capture or edit your own splat at https://superspl.at, then
7
9
  // drop the .sog or .ply in public/ and point this at it instead
8
10
  const SPLAT_URL = 'https://developer.playcanvas.com/assets/toy-cat.sog';
@@ -20,7 +20,10 @@ export default defineConfig({
20
20
  // npm run package zips this folder and writes the zip beside it, inside the ignored dist/
21
21
  outDir: 'dist/lens',
22
22
  // source maps only add to the 8 MB upload
23
- sourcemap: false
23
+ sourcemap: false,
24
+ // a PlayCanvas build is 1-2.5 MB minified, nearly all of it engine code the first frame needs,
25
+ // so warn only for chunks well past that rather than at Vite's 500 kB default
26
+ chunkSizeWarningLimit: 3000
24
27
  },
25
28
  preview: {
26
29
  // npm run start serves the build under the Lens rules, so a request for anything outside
@@ -0,0 +1,39 @@
1
+ # AGENTS.md
2
+
3
+ A PlayCanvas app in TypeScript, built with Vite. The scene is declared in HTML with `@playcanvas/web-components`, custom elements that drive the PlayCanvas Engine. `README.md` describes the starter this project began from and how to control it.
4
+
5
+ ## Commands
6
+
7
+ - `npm install` installs dependencies.
8
+ - `npm run dev` starts the dev server, usually at <http://localhost:5173>, with hot reload and the PlayCanvas Inspector.
9
+ - `npm run typecheck` checks types.
10
+ - `npm run lint` runs ESLint, and `npm run lint:fix` fixes what it can.
11
+ - `npm run fmt` checks formatting, and `npm run fmt:fix` applies Prettier.
12
+ - `npm run build` builds the production site into `dist/`, and `npm run start` serves it.
13
+
14
+ ## Layout
15
+
16
+ - `index.html` holds the scene: `<pc-app>` wraps a `<pc-scene>` of `<pc-entity>` elements, with components such as `<pc-camera>`, `<pc-light>` and `<pc-render>` inside them.
17
+ - `src/main.ts` does what HTML can't, such as attaching scripts and handling input.
18
+ - `src/starter.css` styles the page and the starter's panels.
19
+ - `src/inspector.ts` loads the Inspector. `vite.config.ts` adds it in the dev server only, so production builds leave it out.
20
+ - `public/` holds files copied into the build as they are, such as models and textures.
21
+
22
+ ## Conventions
23
+
24
+ - Attribute values are strings, such as `position="0 0 3"` and `clear-color="#8099e6"`. `node_modules/@playcanvas/web-components/dist/custom-elements.json` lists every element and its attributes.
25
+ - Attach a script that's imported through the bundler in `src/main.ts`, not with `<pc-script-instance name="...">`, which only finds scripts that a `<pc-asset>` fetched at runtime. Wait for the element with `whenReady()`, then add the script through its `.entity`.
26
+ - `<pc-app>` dispatches ordinary pointer events, such as `pointerup`, on the `<pc-entity>` under the pointer, so listen for them on the element. Only entities with a listener receive them.
27
+ - Builds use relative URLs (`base: './'` in `vite.config.ts`), so they run from any folder. Load files in `public/` with relative paths such as `./model.glb`, not `/model.glb`.
28
+ - The engine ships ready-made scripts, such as camera controls and character controllers, under `playcanvas/scripts/esm/`. Use one before writing the same behavior yourself.
29
+ - `node_modules/playcanvas/build/playcanvas.d.ts` documents the installed engine's API.
30
+ - TypeScript is strict, and unused locals and parameters are errors.
31
+
32
+ ## Checking your work
33
+
34
+ - Run `npm run typecheck`, `npm run lint` and `npm run build` before you finish. All three must pass.
35
+ - To see the result, run `npm run dev` and open the page in a browser. The console should show `Powered by PlayCanvas` and no errors. Press the backquote key for the Inspector, which shows the hierarchy, assets, materials, textures, frame graph and physics. <kbd>F9</kbd> pauses and <kbd>F10</kbd> steps a frame.
36
+
37
+ ## Agent skills
38
+
39
+ `.claude/skills/` and `.agents/skills/` hold PlayCanvas skills for coding agents. Use them rather than working from memory: `build-app` when restructuring the app, `find-examples` for a feature the project doesn't use yet, `reuse-scripts` before writing a behavior, `inspect-glb` before placing a model, `inspect-runtime` to read state from the running app, and `verify-pixels` to prove a refactor leaves the image unchanged.
@@ -10,8 +10,6 @@ Node.js 22.23.2 or later.
10
10
  ## Getting started
11
11
 
12
12
  ```bash
13
- npm create playcanvas@latest playcanvas-project -- --format web-components
14
- cd playcanvas-project
15
13
  npm install
16
14
  npm run dev
17
15
  ```
@@ -24,16 +22,18 @@ Open <http://localhost:5173>. Edit `index.html` to change the scene.
24
22
 
25
23
  ## Scripts
26
24
 
27
- | Command | Description |
28
- | ------------------- | --------------------------------- |
29
- | `npm run dev` | Start the Vite development server |
30
- | `npm run build` | Build for production |
31
- | `npm run start` | Preview the production build |
32
- | `npm run lint` | Run ESLint |
33
- | `npm run fmt` | Check formatting |
34
- | `npm run typecheck` | Run TypeScript checks |
25
+ Run these with `npm run <script>`:
35
26
 
36
- Run `npm run build` to generate a deployable static site in `dist/`.
27
+ | Script | Description |
28
+ | ----------- | --------------------------------- |
29
+ | `dev` | Start the Vite development server |
30
+ | `build` | Build for production |
31
+ | `start` | Preview the production build |
32
+ | `lint` | Run ESLint |
33
+ | `fmt` | Check formatting |
34
+ | `typecheck` | Run TypeScript checks |
35
+
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
 
@@ -62,6 +62,10 @@ JetBrains IDEs pick it up automatically. For VS Code, add to `.vscode/settings.j
62
62
  }
63
63
  ```
64
64
 
65
+ ## Coding agents
66
+
67
+ `AGENTS.md` gives coding agents such as Claude Code, Codex and Cursor this project's commands, layout, conventions and checks. `CLAUDE.md` imports it for Claude Code.
68
+
65
69
  ## Agent skills
66
70
 
67
71
  This project includes [`@playcanvas/skills`](https://github.com/playcanvas/skills) under `.claude/skills/` and `.agents/skills/`, so Claude Code, Codex and Cursor pick up PlayCanvas-specific workflows automatically.
@@ -15,12 +15,12 @@
15
15
  "typecheck": "tsc --noEmit"
16
16
  },
17
17
  "dependencies": {
18
- "@playcanvas/web-components": "^0.28.0",
18
+ "@playcanvas/web-components": "^0.28.1",
19
19
  "playcanvas": "^2.23.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@playcanvas/eslint-config": "3.0.0-beta.8",
23
- "@playcanvas/inspector": "^0.3.0",
23
+ "@playcanvas/inspector": "^0.4.0",
24
24
  "eslint": "^9.39.5",
25
25
  "prettier": "^3.9.10",
26
26
  "typescript": "~6.0.3",
@@ -2,6 +2,14 @@ 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: './',
8
+ build: {
9
+ // A PlayCanvas build is 1-2.5 MB minified (300-600 kB gzipped), nearly all of it engine code the
10
+ // first frame needs, so warn only for chunks well past that rather than at Vite's 500 kB default
11
+ chunkSizeWarningLimit: 3000
12
+ },
5
13
  plugins: [
6
14
  {
7
15
  // 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"
@@ -19,7 +19,10 @@ export default defineConfig({
19
19
  // npm run package zips this folder and writes the zip beside it, inside the ignored dist/
20
20
  outDir: 'dist/lens',
21
21
  // source maps only add to the 8 MB upload
22
- sourcemap: false
22
+ sourcemap: false,
23
+ // a PlayCanvas build is 1-2.5 MB minified, nearly all of it engine code the first frame needs,
24
+ // so warn only for chunks well past that rather than at Vite's 500 kB default
25
+ chunkSizeWarningLimit: 3000
23
26
  },
24
27
  preview: {
25
28
  // npm run start serves the build under the Lens rules, so a request for anything outside