retiam 1.0.1 → 1.0.3

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 (28) hide show
  1. package/bin/render-config.js +0 -1
  2. package/dist/{UTIF-CuM_xgsi.js → UTIF-Ds1s3mlY.js} +1 -1
  3. package/dist/{index-C7UzgTiw.js → index-B0d0AebJ.js} +15763 -15093
  4. package/dist/{main-CCBHkqdA.js → main-D6re07P2.js} +1 -1
  5. package/dist/retiam.es.js +810 -798
  6. package/dist/src/engine/_core/Material.d.ts +13 -18
  7. package/dist/src/engine/_core/Scene.d.ts +3 -0
  8. package/dist/src/engine/_core/SnapshotManager.d.ts +3 -0
  9. package/dist/src/engine/_core/VectorEntity.d.ts +14 -0
  10. package/dist/src/engine/animation/transform/TransformMatchingShapes.d.ts +14 -0
  11. package/dist/src/engine/animation/transform/TransformMatchingTex.d.ts +15 -0
  12. package/dist/src/engine/animation/transform/TransformMatchingText.d.ts +14 -0
  13. package/dist/src/engine/components/fragment/ModelFragment.d.ts +1 -6
  14. package/dist/src/engine/entities/composites/coordinates/Axes.d.ts +20 -0
  15. package/dist/src/engine/entities/composites/geometry/Arrow.d.ts +35 -0
  16. package/dist/src/engine/entities/composites/geometry/Arrow3D.d.ts +31 -0
  17. package/dist/src/engine/material/shading/CelShading.d.ts +16 -0
  18. package/dist/src/engine/material/shading/ClayShading.d.ts +6 -0
  19. package/dist/src/engine/material/shading/GoochShading.d.ts +14 -0
  20. package/dist/src/engine/material/shading/PBRShading.d.ts +6 -0
  21. package/dist/src/engine/material/shading/Shading.d.ts +17 -0
  22. package/dist/src/engine/material/shading/index.d.ts +5 -0
  23. package/dist/src/engine/render/RenderConfig.d.ts +1 -23
  24. package/dist/src/engine/utils/IndexInspector.d.ts +44 -0
  25. package/dist/src/engine/utils/PathEqualizer.d.ts +15 -0
  26. package/dist/src/index.d.ts +2 -0
  27. package/package.json +3 -2
  28. package/readme.md +298 -16
package/readme.md CHANGED
@@ -12,20 +12,60 @@ Retiam is a TypeScript animation engine built on WebGPU. Write scenes for mathem
12
12
  - **Rendering:** combine 2D paths, 3D meshes, lighting, shadows, compute effects, and post-processing.
13
13
  - **Specialized libraries:** add charts, graphs, physics, procedural shapes, sketch styling, and emphasis animations through separate imports.
14
14
  - **Audio and output:** work with audio, narration, and subtitles; inspect snapshots, render video, or share scenes as web components.
15
+ - **Retiam Studio:** edit scenes alongside a live preview, tune supported values with inspectors, and control playback from your generated project.
15
16
 
16
17
  ## Getting started
17
18
 
18
- The project generator creates a TypeScript application, installs its dependencies,
19
- and opens Retiam Studio with a **Write** animation of “Retiam”:
19
+ | Method | Use it for | Result |
20
+ | --- | --- | --- |
21
+ | [npm project and Studio](#create-a-project-with-studio) | Author and preview TypeScript scenes, then render video | Source project, MP4 and snapshots |
22
+ | [CDN modules](#use-retiam-from-a-cdn) | Add a live scene directly to a browser page | Interactive WebGPU canvas |
23
+ | [Embedded export](#export-an-independent-web-embed) | Share a finished animation on another website | Hosted web component and bundled assets |
24
+
25
+ ### Create a project with Studio
26
+
27
+ Use Node.js 20.19 or newer and a WebGPU-capable browser. The project generator
28
+ creates a TypeScript application, installs its dependencies, and opens Retiam
29
+ Studio with a **Write** animation of “Retiam”:
20
30
 
21
31
  ```bash
22
- npx create-retiam my-animation
32
+ npx create-retiam@latest my-animation
33
+ ```
34
+
35
+ The generated project declares
36
+ `"retiam": "latest"`. Its initial install uses npm's `latest` engine release;
37
+ the package manager's lockfile records the resolved version for later installs.
38
+
39
+ The editor opens below the preview. Drag the divider to resize it, or use the
40
+ layout control to dock it on the left or right. Studio remembers your choice.
41
+ Single-scene projects show the preview and editor; scene navigation and search
42
+ appear when more scenes are added and the page reloads.
43
+
44
+ Press Ctrl+C to stop the server. To reopen Studio:
45
+
46
+ ```bash
47
+ cd my-animation
48
+ npm run dev
23
49
  ```
24
50
 
25
- Run `npm run dev` inside the generated project to reopen Studio. Use `--no-start`
26
- to install without launching or `--no-install` to generate files only. The
27
- [`create-retiam` package](packages/create-retiam/README.md) is released separately
28
- from the engine; see its maintainer instructions for packaging and publication.
51
+ Edit `src/scenes/Retiam.ts` in your editor or Studio. The generated project also
52
+ includes `config.js` for CLI rendering, `studio/` for the local editor, and the
53
+ Vite and TypeScript configuration. In Studio, **Run** or **Ctrl/Command+Enter**
54
+ applies and saves edits. Add default-exported Scene classes under `src/scenes/`
55
+ to make them available in the scene browser after reloading.
56
+
57
+ | Generator option | Behavior |
58
+ | --- | --- |
59
+ | `--no-start` | Install dependencies without starting Studio |
60
+ | `--no-install` | Generate files without installing or starting |
61
+ | `--no-open` | Start the server without opening a browser |
62
+ | `--title "Hello"` | Change the starter animation text |
63
+ | `--pm npm\|pnpm\|yarn\|bun` | Choose the package manager |
64
+
65
+ The [`create-retiam` package](packages/create-retiam/README.md)
66
+ is released separately from the engine. Publish the engine version required by
67
+ its starter before publishing the generator. Generator updates apply to new
68
+ projects; existing projects keep their own Studio and configuration files.
29
69
 
30
70
  ### Manual setup
31
71
 
@@ -33,7 +73,7 @@ Install Retiam in your own TypeScript application:
33
73
 
34
74
  ```bash
35
75
  npm install retiam
36
- npm install --save-dev typescript vite @webgpu/types
76
+ npm install --save-dev typescript "vite@^6.1.1" @webgpu/types
37
77
  ```
38
78
 
39
79
  Follow the [installation guide](https://abhilasbiswas.github.io/retiam-docs/installation/) for the complete project structure, TypeScript configuration, and browser entry point. To use an unpublished checkout, run `npm pack` in this repository and install the generated `.tgz` file in your application.
@@ -93,21 +133,259 @@ window.addEventListener("pagehide", () => scene.destroy(), { once: true });
93
133
 
94
134
  The host page needs a `<canvas id="canvas"></canvas>` with an explicit CSS display size. Continue with [your first scene](https://abhilasbiswas.github.io/retiam-docs/first-scene/) for animation, camera, and lifecycle guidance.
95
135
 
136
+ ## Use Retiam from a CDN
137
+
138
+ Import Retiam directly in a browser page. The published module is available at
139
+ **[jsDelivr](https://cdn.jsdelivr.net/npm/retiam@latest/dist/retiam.es.min.js)**.
140
+ This example loads the core and charts entries through the latest release tag:
141
+
142
+ ```html
143
+ <!doctype html>
144
+ <html lang="en">
145
+ <head>
146
+ <meta charset="utf-8" />
147
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
148
+ <title>Retiam CDN animation</title>
149
+ <style>
150
+ html, body { margin: 0; width: 100%; height: 100%; }
151
+ canvas { display: block; width: 100%; height: 100%; }
152
+ </style>
153
+ <script type="importmap">
154
+ {
155
+ "imports": {
156
+ "retiam": "https://cdn.jsdelivr.net/npm/retiam@latest/dist/retiam.es.min.js",
157
+ "retiam/charts": "https://cdn.jsdelivr.net/npm/retiam@latest/dist/libs/charts/index.js"
158
+ }
159
+ }
160
+ </script>
161
+ </head>
162
+ <body>
163
+ <canvas id="canvas"></canvas>
164
+ <script type="module">
165
+ import { Scene, Circle, Create, CameraModel, hex } from 'retiam';
166
+
167
+ class BrowserScene extends Scene {
168
+ async run() {
169
+ this.clearColor(hex('#080C14'));
170
+ this.camera.model = CameraModel.ORTHOGRAPHIC;
171
+ this.camera.orthoScale = 12;
172
+ this.camera.position.set([0, 0, 20]);
173
+ this.camera.lookAt([0, 0, 0]);
174
+ const circle = new Circle(1, { fill: hex('#38BDF8') });
175
+ this.add(circle);
176
+ await this.play(new Create(circle, { duration: 1200 }));
177
+ await this.wait(1000);
178
+ }
179
+ }
180
+
181
+ const scene = new BrowserScene();
182
+ scene.start(document.querySelector('#canvas')).catch(console.error);
183
+ window.addEventListener('pagehide', () => scene.destroy(), { once: true });
184
+ </script>
185
+ </body>
186
+ </html>
187
+ ```
188
+
189
+ Serve the page over HTTPS or localhost, with a WebGPU-capable browser. No Retiam
190
+ npm installation is needed for this page. Add import-map entries for any other
191
+ sublibraries you use, such as `retiam/shapes`, with the same release tag. jsDelivr
192
+ serves the module's related chunks, fonts, workers and WASM assets. A CDN page
193
+ runs the animation live; the [npm CLI workflow](#cli-and-video-rendering) produces
194
+ video and snapshots.
195
+
196
+ ## Export an independent web embed
197
+
198
+ Bundle a finished scene into a custom element for a blog, documentation page or
199
+ another application. The exported files include the engine code and emitted
200
+ assets needed by that scene. The receiving site needs WebGPU and those files.
201
+
202
+ This recipe uses Vite 6, matching the generated project's toolchain. For a
203
+ generated npm project, save the following as `src/embed.ts`. Each element
204
+ owns its canvas and Scene, handles resizing, and cleans up when removed.
205
+
206
+ <details>
207
+ <summary>src/embed.ts</summary>
208
+
209
+ ```typescript
210
+ import MyScene from './scenes/Retiam';
211
+
212
+ // A separate name lets this bundle coexist with other scene components.
213
+ class MyRetiamSceneElement extends HTMLElement {
214
+ private cleanup?: () => void;
215
+
216
+ connectedCallback() {
217
+ this.cleanup?.();
218
+ const canvas = document.createElement('canvas');
219
+ canvas.style.cssText = 'display:block;width:100%;height:100%';
220
+ this.replaceChildren(canvas);
221
+ const scene = new MyScene();
222
+ let cancelled = false, started = false, resizeFrame = 0;
223
+ let observer: ResizeObserver | undefined;
224
+
225
+ this.cleanup = () => {
226
+ cancelled = true;
227
+ observer?.disconnect();
228
+ cancelAnimationFrame(resizeFrame);
229
+ if (started) scene.destroy();
230
+ // A pending initialization cleans up in its continuation below.
231
+ };
232
+ void scene.start(canvas).then(() => {
233
+ started = true;
234
+ if (cancelled) { scene.destroy(); return; }
235
+ observer = new ResizeObserver(() => {
236
+ cancelAnimationFrame(resizeFrame);
237
+ resizeFrame = requestAnimationFrame(() => {
238
+ // Current composer resizing listens to the window resize event.
239
+ window.dispatchEvent(new Event('resize'));
240
+ });
241
+ });
242
+ observer.observe(this);
243
+ this.dispatchEvent(new CustomEvent('scene-ready', { bubbles: true }));
244
+ }).catch(error => {
245
+ scene.destroy();
246
+ if (!cancelled) {
247
+ const message = document.createElement('p');
248
+ message.setAttribute('role', 'alert');
249
+ message.textContent = String(error);
250
+ this.replaceChildren(message);
251
+ }
252
+ });
253
+ }
254
+
255
+ disconnectedCallback() {
256
+ this.cleanup?.();
257
+ this.cleanup = undefined;
258
+ }
259
+ }
260
+
261
+ if (!customElements.get('my-retiam-scene')) {
262
+ customElements.define('my-retiam-scene', MyRetiamSceneElement);
263
+ }
264
+ ```
265
+
266
+ </details>
267
+
268
+ For a manual project, change the scene import to your scene module. The
269
+ [npm embed recipe](https://abhilasbiswas.github.io/retiam-docs/export/#embed-from-npm)
270
+ explains lifecycle handling, multiple instances and hosting.
271
+
272
+ Save this as `vite.embed.config.ts`:
273
+
274
+ ```typescript
275
+ import { defineConfig } from 'vite';
276
+
277
+ export default defineConfig({
278
+ base: './',
279
+ build: {
280
+ target: 'es2022',
281
+ outDir: 'outputs/embed',
282
+ lib: {
283
+ entry: 'src/embed.ts',
284
+ formats: ['es'],
285
+ fileName: 'my-scene',
286
+ },
287
+ },
288
+ });
289
+ ```
290
+
291
+ Build the component:
292
+
293
+ ```bash
294
+ npx vite build --config vite.embed.config.ts
295
+ ```
296
+
297
+ Copy the **whole** `outputs/embed` folder to your website, for example under
298
+ `/embeds/my-scene/`, then mount the custom element:
299
+
300
+ ```html
301
+ <script type="module" src="/embeds/my-scene/my-scene.js"></script>
302
+ <my-retiam-scene style="display:block;width:100%;height:540px"></my-retiam-scene>
303
+ ```
304
+
305
+ The receiving site needs no npm installation or separate Retiam CDN import.
306
+ Preserve emitted files and their relative paths. Assets or services explicitly
307
+ referenced by remote URLs still need hosting. Use a distinct custom-element name
308
+ for each different scene bundle. An MP4 is the alternative when the receiving
309
+ page only needs video playback.
310
+
311
+ The engine repository also provides an export CLI:
312
+
313
+ ```bash
314
+ npx retiam export scenes/MyScene.ts outputs/embed
315
+ ```
316
+
317
+ Its current implementation expects the engine repository's `src/engine` layout.
318
+ Use the package-based Vite recipe above for generated and other external npm
319
+ projects. See [repository export](https://abhilasbiswas.github.io/retiam-docs/export/#standalone-embeds)
320
+ for the CLI's script and `<retiam-scene>` usage.
321
+
96
322
  ## CLI and video rendering
97
323
 
98
- Use the CLI to analyze scenes, capture PNG snapshots, and render video:
324
+ Run these commands from the generated project folder containing `package.json`
325
+ and `config.js`:
99
326
 
100
327
  ```bash
101
- npx retiam lint scenes/FirstScene.ts --json
102
- npx retiam snapshot scenes/FirstScene.ts --times 1.0,2.5,4.0 --json
103
- npx retiam render scenes/FirstScene.ts -w 1920 -h 1080 -f 60 -d 4000 -o outputs/video
328
+ npx retiam lint src/scenes/Retiam.ts --json
329
+ npx retiam snapshot src/scenes/Retiam.ts --times 1.0,2.5,4.0 --json
330
+ npx retiam render src/scenes/Retiam.ts
104
331
  ```
105
332
 
106
- Puppeteer is a required production dependency of Retiam starting with version 1.0.1 and is installed automatically with the package. Render and snapshot commands need a working Chrome/WebGPU setup. Video rendering also requires FFmpeg on your `PATH`.
333
+ Puppeteer is a required production dependency of Retiam and is installed automatically with the package. Render and snapshot commands need a working Chrome/WebGPU setup. Video rendering also requires FFmpeg on your `PATH`.
107
334
 
108
- Projects made with `create-retiam` include a commented `config.js` containing all CLI and engine render defaults. `npx retiam render` reads it from the calling project; `retiam.config.js` takes priority when present, and CLI flags override file settings. Settings include video output, anti-aliasing, transparency, shadows, shading, raytracing, and denoising.
335
+ ### Render configuration
109
336
 
110
- For rendering and snapshots, your project must include an `index.html` host that loads the scene selected by the CLI's `file` query parameter. Use the host from the [installation guide](https://abhilasbiswas.github.io/retiam-docs/installation/#create-a-consumer-application). Render duration (`-d`) is in milliseconds; output (`-o`) is a directory.
337
+ The generated [config.js](packages/create-retiam/starter/config.js) contains CLI
338
+ output and renderer quality settings with their defaults and comments. The default output
339
+ is 1920×1080 at 60 fps, MP4 at `20M`, in `outputs/video`. `maxDuration: 0` renders
340
+ until the scene finishes; set a limit for scenes that loop indefinitely.
341
+
342
+ For a smaller draft, edit the output fields in `config.js`:
343
+
344
+ ```javascript
345
+ export default {
346
+ width: 1280,
347
+ height: 720,
348
+ fps: 30,
349
+ videoBitrate: '8M',
350
+ outputFormat: 'mp4',
351
+ outputDir: './outputs/video',
352
+ maxDuration: 4000, // milliseconds
353
+ };
354
+ ```
355
+
356
+ The renderer starts with built-in defaults, loads `config.js` from the calling
357
+ project, then applies CLI flags. If `retiam.config.js` exists, it is used instead
358
+ of `config.js`. For example, this renders at 60 fps while retaining the other
359
+ file settings:
360
+
361
+ ```bash
362
+ npx retiam render src/scenes/Retiam.ts -f 60
363
+ ```
364
+
365
+ The complete file also covers anti-aliasing, transparency layers, shadows,
366
+ culling, raytracing, denoising, local server ports, and input replay.
367
+ See the [configuration reference](https://abhilasbiswas.github.io/retiam-docs/export/#render-configuration).
368
+
369
+ Choose surface appearance in scene code and materials:
370
+
371
+ ```typescript
372
+ import { CelShading, GoochShading } from 'retiam';
373
+
374
+ this.shading = new CelShading({ bands: 3 }); // Scene default
375
+ sphere.material.shading = new GoochShading({ warm: 0.6, cool: 0.4 });
376
+ ```
377
+
378
+ Each shading model supplies its own WGSL. Numeric parameters update through the
379
+ material buffer without recompiling shaders. These styles apply to rasterized
380
+ 3D models; raytracing uses its own physically based lighting.
381
+
382
+ For the manual setup above, use `scenes/FirstScene.ts` as the scene path. Rendering
383
+ and snapshots serve the project's `index.html`; a host that supports selecting
384
+ different scenes must load the CLI's `file` query parameter. The
385
+ [manual installation guide](https://abhilasbiswas.github.io/retiam-docs/installation/#create-a-consumer-application)
386
+ includes that bootstrap. Render duration (`-d`) is in milliseconds, snapshot
387
+ times are in seconds, and output (`-o`) is a directory. Render filenames include
388
+ a timestamp.
111
389
 
112
390
  See [rendering and export](https://abhilasbiswas.github.io/retiam-docs/export/) for project setup and encoding options, or follow [package-based embeds](https://abhilasbiswas.github.io/retiam-docs/export/#embed-from-npm) to bundle a scene for another website. Run `npx retiam help` for the command reference.
113
391
 
@@ -126,10 +404,14 @@ Import shared scene primitives from `retiam` and specialized functionality from
126
404
  | `retiam/rough` | RoughJS styling integration |
127
405
  | `retiam/tts` | Microsoft Edge speech synthesis, narration, and subtitles |
128
406
 
129
- See the [library guide](https://abhilasbiswas.github.io/retiam-docs/libraries/) for import boundaries and examples. Starting with Retiam 1.0.1, `roughjs` is a required production dependency and is installed automatically.
407
+ See the [library guide](https://abhilasbiswas.github.io/retiam-docs/libraries/) for import boundaries and examples. `roughjs` is a required production dependency and is installed automatically.
130
408
 
131
409
  Built-in fonts and imported engine assets are included in the library package. Application media is managed separately. Edge speech synthesis in the browser requires a compatible service. See [asset workflows](https://abhilasbiswas.github.io/retiam-docs/asset-workflows/) and [speech and subtitles](https://abhilasbiswas.github.io/retiam-docs/speech-subtitles/) for setup.
132
410
 
411
+ MSDF font generation runs in a browser worker using the WASM supplied by
412
+ `@zappar/msdf-generator`, a production dependency. The repository's font-baking
413
+ tools, including `msdf-bmfont-xml` and `msdf-atlas-gen`, remain development tools.
414
+
133
415
  ## Repository development
134
416
 
135
417
  Use Node.js 24, matching the documentation CI configuration.