@johnmorrisdotca/uchusen-rockets 0.3.0 → 0.4.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.
- package/CHANGELOG.md +16 -5
- package/README.md +241 -4
- package/dist/attrs.d.ts +70 -4
- package/dist/attrs.js +59 -4
- package/dist/build/glb.d.ts +25 -0
- package/dist/build/glb.js +14 -0
- package/dist/build/index.d.ts +89 -4
- package/dist/build/index.js +55 -4
- package/dist/build/lineup.d.ts +56 -2
- package/dist/build/lineup.js +23 -2
- package/dist/builder.d.ts +47 -1
- package/dist/builder.js +14 -1
- package/dist/crossfade.d.ts +44 -2
- package/dist/crossfade.js +44 -2
- package/dist/data/credits.d.ts +44 -1
- package/dist/data/credits.js +22 -1
- package/dist/data/flight-log.d.ts +33 -1
- package/dist/data/flight-log.js +22 -1
- package/dist/data/flights.d.ts +54 -2
- package/dist/data/flights.js +10 -0
- package/dist/data/makers.d.ts +21 -0
- package/dist/data/makers.js +10 -0
- package/dist/data/sources.d.ts +32 -0
- package/dist/data/sources.js +10 -0
- package/dist/data/types.d.ts +81 -1
- package/dist/data/types.js +26 -1
- package/dist/element.d.ts +61 -3
- package/dist/element.js +50 -3
- package/dist/embed.d.ts +110 -5
- package/dist/embed.js +88 -5
- package/dist/engines.d.ts +86 -4
- package/dist/engines.js +75 -4
- package/dist/fit.d.ts +68 -0
- package/dist/fit.js +13 -0
- package/dist/flight.d.ts +134 -9
- package/dist/flight.js +122 -9
- package/dist/flightbar.d.ts +12 -0
- package/dist/flightbar.js +12 -0
- package/dist/framing.d.ts +182 -8
- package/dist/framing.js +127 -6
- package/dist/layout.d.ts +65 -1
- package/dist/layout.js +43 -1
- package/dist/looks.d.ts +64 -1
- package/dist/looks.js +42 -1
- package/dist/model/materials.d.ts +32 -0
- package/dist/model/materials.js +10 -0
- package/dist/model/registry.d.ts +22 -0
- package/dist/model/registry.js +22 -0
- package/dist/parts.d.ts +33 -1
- package/dist/pixels.d.ts +44 -4
- package/dist/pixels.js +44 -4
- package/dist/react.d.ts +24 -0
- package/dist/react.js +13 -0
- package/dist/rockets.d.ts +91 -3
- package/dist/rockets.js +58 -2
- package/dist/spin.d.ts +57 -2
- package/dist/spin.js +35 -2
- package/dist/tilt.d.ts +48 -4
- package/dist/tilt.js +26 -4
- package/package.json +10 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.4.0] - 2026-11-03
|
|
6
|
+
|
|
7
|
+
- Demo: the rocket, variant, parts, look and view (the From row) are kept in the address with the maker, the Earth and the view controls' choices, each at a default that leaves the address clean, so a link or a reload opens what was on the screen.
|
|
8
|
+
- Demo: kazoku-ui 0.12 (Centre came in 0.11). Once the view is zoomed or moved, a Centre button brings the rocket back to the middle at Fit and the default angle (the keys Home and 0 too). A rocket is thin, so the controls are told its size on the screen (`object-size`) and hold a pan so that at least a quarter of it stays in view. There is no `grab-radius`: a rocket is not round, so the default drag is kept. A browser test drags it far off and presses Centre.
|
|
9
|
+
- The drag rule has its browser check: `e2e/direction.demo.ts` runs kazoku-ui's shared `e2e/ground.mjs` on the Space Shuttle's stack (a plain rocket body has nothing to follow up or down), and reads Starship's camera angle. A drag right moves the surface right, a drag up moves it up, the arrow keys agree and Auto-turn takes the near side to the right.
|
|
10
|
+
- Demo: the Earth behind the rocket takes chikyu-earth 0.10: `max-ratio="1"` instead of sizing the element at half and scaling it, the Sun and the view are set on the same tick (one draw, so the every-fourth-draw workaround is gone), and the page's Content-Security-Policy has no style hash: `style-src 'self'` alone, which a test now holds (a refused stylesheet is an error).
|
|
11
|
+
- The release runs the freeze test before anything is published: `release.yml` calls kazoku-ui's shared release workflow at v0.11.0 with `freeze-command: pnpm test:freeze`.
|
|
12
|
+
- Engines: the parts whose data lists engines but whose drawing has no bell stay dark on purpose, and a test names them (Jupiter-C, Dragon 1, Dragon 2, Cargo Dragon 2, Apollo's service module, the lunar module's ascent stage, Dragon on top of Falcon 9). No source read here gives a Draco or SuperDraco thruster's size, the service propulsion engine's or the A-7's, and a bell's size is never estimated.
|
|
13
|
+
- The README opens with the package's thumbnail, and the demo carries it as its link preview (og:image) and publishes the card, a dark card and an icon on Pages at `thumbnail.png`, `thumbnail-dark.png` and `icon.png`.
|
|
14
|
+
- Documentation: a reference site made from the source's doc comments (every export has a summary, its parameters, what it returns and an example that runs), thirteen guides with a Japanese twin of each, a code builder page (`builder.html`), eighteen pictures, a longer README, and every release of this changelog dated. `pnpm docs:check` and `pnpm docs:site` are new, and `pnpm test:readme` now runs the guides too. No behaviour changed.
|
|
15
|
+
|
|
5
16
|
## [0.3.0] - 2026-11-02
|
|
6
17
|
|
|
7
18
|
- Falcon 1, and the Falcon 1e that was announced and never flew, drawn by this package's code. Sizes from SpaceX's 2008 user's guide, with Wikipedia's other figures kept beside them. A part placed rather than stacked can now stand above the ground (`strapOn.y`).
|
|
@@ -41,12 +52,12 @@
|
|
|
41
52
|
- Demo: a Background row, None or Earth, beside Look and From, off by default and kept in the address (`?background=earth`). It is the page's own: the embed page and what is copied carry the rocket, and say so. The rocket floats in front of the Earth from [`@johnmorrisdotca/chikyu-earth`](https://www.npmjs.com/package/@johnmorrisdotca/chikyu-earth), turning once in 12 minutes: a line-drawn globe behind Line drawing and Thick lines, one SVG and no canvas, and the realistic Earth behind Painted, a second WebGL context given back when it is left. A person who does not choose it loads nothing of it and pays nothing. It draws 2 or 4 times a second, not at all out of sight, on a hidden tab or under reduced motion, and stops turning when nobody has touched the page for five minutes. `e2e/freeze.demo.ts` holds its budgets, and `pnpm test:freeze` runs that file alone. None of this is in the published package.
|
|
42
53
|
- Demo: kazoku-ui 0.10 (chikyu-earth needs >=0.9.0), with `controls="advanced"` on the bar, so it keeps tilt, Front and the pan pad on show; its `2×` preset is gone, and a double press on the view still goes to 2 times. The Content-Security-Policy's `style-src` gains one hash, for the realistic Earth's inline `<style>`, until chikyu-earth adopts its styles as kazoku-ui does.
|
|
43
54
|
|
|
44
|
-
## [0.2.2]
|
|
55
|
+
## [0.2.2] - 2026-11-02
|
|
45
56
|
|
|
46
57
|
- Demo: kazoku-ui 0.7 (a dev dependency, used only by the demo). The demo's strict Content-Security-Policy is now plain `style-src 'self'`: the controls adopt their styles as a constructable stylesheet since kazoku-ui 0.3.1, so the build no longer writes the controls' style text's hash into the page (the `%KAZOKU_STYLE%` step of `scripts/site.ts` is gone). The introduction's own pause (a one-minute timer and a scroll observer in `demo/demo.ts`) is replaced by the controls' `autoplay-for="60"` and their idle-out-of-sight, from kazoku-ui 0.7.1; `docs/element.md` says so.
|
|
47
58
|
- Repository: `release.yml` calls kazoku-ui's shared `reusable-release.yml` (pinned to v0.7.3): the same checks, tag, GitHub release with the tarball and npm publish by trusted publishing; the trusted publisher entry stays `release.yml`. The GitHub release's notes are generated by GitHub until the shared workflow reads `scripts/release-notes.ts`. `AGENTS.md` is written from kazoku-ui's template.
|
|
48
59
|
|
|
49
|
-
## [0.2.1]
|
|
60
|
+
## [0.2.1] - 2026-11-02
|
|
50
61
|
|
|
51
62
|
- Fixed: the demo could hang the screen while turning. When the 3D view turned by itself, or glided to a stop after a drag, the controls' change event asked for the next frame while the view's own loop did too, so each frame started two and the number of draws doubled every frame: thousands of draws a second, enough to starve the graphics card (measured in a real browser on a real graphics card: 12,308 draws in 3 seconds, against 181 now at 60 frames a second). One frame is asked for, once.
|
|
52
63
|
- Fixed: every change of variant, look or parts left the old shapes in the graphics card (about 60 buffers each), and a painted model's pictures with them. They are given back now, and the glow's too.
|
|
@@ -58,18 +69,18 @@
|
|
|
58
69
|
- `pixelRatioFor(width, height, deviceRatio)`, with `MAX_PIXELS`, `MAX_SIDE` and `MAX_RATIO`.
|
|
59
70
|
- New browser tests: draws per frame, nothing drawing when still or out of sight, no growth of contexts, buffers, vertex arrays or textures over changes, a lost context, and the canvas within its budget from 1x to 5x on a 5K screen.
|
|
60
71
|
|
|
61
|
-
## [0.2.0]
|
|
72
|
+
## [0.2.0] - 2026-11-01
|
|
62
73
|
|
|
63
74
|
- `element.drive({ yaw, tilt, zoom, panX, panY })`: a page can hand the turn, tip, zoom and move to the family's `<kazoku-view-controls>` ([`@johnmorrisdotca/kazoku-ui`](https://www.npmjs.com/package/@johnmorrisdotca/kazoku-ui)). The element's own drag, wheel, keys and spin stand down, and the 3D view and the drawing both follow, so it works with no WebGL as well. `drive(null)` takes them back. kazoku-ui is not imported by the package: the demo uses it, as a dev dependency.
|
|
64
75
|
- The demo uses the shared view controls: angle, tilt, auto-turn, Front, zoom, Fit and move, with the same drag, pinch and keys as the rest of the family, and the choices kept in the address (`?yaw=40&tilt=10&zoom=2`). Its own slow-spin switch and hint are gone.
|
|
65
76
|
- `turnedBy(base, yaw, tilt)` and the `ViewChoice` type: the camera angle for a view turned and tipped by the controls.
|
|
66
77
|
|
|
67
|
-
## [0.1.1]
|
|
78
|
+
## [0.1.1] - 2026-11-01
|
|
68
79
|
|
|
69
80
|
- The painted Falcon 9 Block 5 second stage shows this package's own engine nozzle when it stands apart or alone, as the model has none, and not when it is nested in the first stage.
|
|
70
81
|
- The Falcon 9's drawn vacuum nozzle is 3.3 m across at the exit, the figure Wikipedia's Merlin infobox gives, in the line looks too (the v1.0 keeps its narrower bell).
|
|
71
82
|
|
|
72
|
-
## [0.1.0]
|
|
83
|
+
## [0.1.0] - 2026-10-31
|
|
73
84
|
|
|
74
85
|
- Starship: Super Heavy and the Ship, in Block 1, Block 1 as it first flew, Block 2, Block 3 and the announced Block 4, each with its own sourced sizes, and an artist's model of the 2019 design.
|
|
75
86
|
- Falcon 9 in v1.0, v1.1, Full Thrust and Block 5, with a fairing or with Dragon 2; Falcon Heavy; Dragon 1 and Dragon 2; Grasshopper, the test vehicle.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<p align="center"><a href="https://johnmorrisdotca.github.io/uchusen-rockets/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/thumbnail-dark.png"><img src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/thumbnail.png" alt="Uchusen Rockets: Saturn V, Starship, the Space Shuttle, Falcon Heavy and SLS, painted in 3D, side by side." width="1200"></picture></a></p>
|
|
2
|
+
|
|
1
3
|
<h1 align="center">Uchusen Rockets <sub>宇宙船</sub></h1>
|
|
2
4
|
|
|
3
5
|
<p align="center"><strong>Rockets drawn from sourced sizes, that you drop into a page, take apart and turn round.</strong><br>
|
|
@@ -10,7 +12,7 @@ Uchūsen means "spaceship". Each rocket comes in every variant a source document
|
|
|
10
12
|
<img alt="TypeScript" src="https://img.shields.io/badge/types-TypeScript-3178c6">
|
|
11
13
|
</p>
|
|
12
14
|
|
|
13
|
-
<p align="center"><a href="https://johnmorrisdotca.github.io/uchusen-rockets/"><strong>Open the demo →</strong></a> · <a href="./docs/variants.md">Variants and sizes</a> · <a href="./docs/parts.md">Build from parts</a> · <a href="./docs/element.md">The element</a> · <a href="./docs/flight.md">Lit engines and flights</a> · <a href="./docs/embed.md">Use one on your site</a> · <a href="./docs/assets.md">Assets</a></p>
|
|
15
|
+
<p align="center"><a href="https://johnmorrisdotca.github.io/uchusen-rockets/"><strong>Open the demo →</strong></a> · <a href="./docs/variants.md">Variants and sizes</a> · <a href="./docs/parts.md">Build from parts</a> · <a href="./docs/element.md">The element</a> · <a href="./docs/flight.md">Lit engines and flights</a> · <a href="./docs/embed.md">Use one on your site</a> · <a href="./docs/assets.md">Assets</a> · <a href="./docs/guides/getting-started.md">Guides</a> · <a href="https://johnmorrisdotca.github.io/uchusen-rockets/builder.html">Code builder</a> · <a href="https://johnmorrisdotca.github.io/uchusen-rockets/docs/">Docs site</a></p>
|
|
14
16
|
|
|
15
17
|
<p align="center"><img alt="Block 3 of the rocket as a painted 3D view, stainless steel with black tiles, beside its controls and its sizes, each with a source." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/main-painted.jpg" width="820"></p>
|
|
16
18
|
|
|
@@ -23,7 +25,7 @@ Uchūsen means "spaceship". Each rocket comes in every variant a source document
|
|
|
23
25
|
|
|
24
26
|
<p align="center"><img alt="Every rocket at one scale: Starship, Falcon 9, Falcon 9 with Dragon 2, Falcon Heavy, Grasshopper and Dragon 2, as line drawings beside a ruler, a building and a person." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/family.jpg" width="820"></p>
|
|
25
27
|
|
|
26
|
-
##
|
|
28
|
+
## In 30 seconds
|
|
27
29
|
|
|
28
30
|
```sh
|
|
29
31
|
npm install @johnmorrisdotca/uchusen-rockets three
|
|
@@ -41,6 +43,54 @@ npm install @johnmorrisdotca/uchusen-rockets three
|
|
|
41
43
|
|
|
42
44
|
That is all a page needs with a bundler. The drawing shows at once; when the element comes on screen and the browser can draw WebGL, the 3D view takes over without a jump. Drag to turn it, use the arrow keys, or leave it to its slow spin. `engines="on"` lights each engine at full thrust, in the painted look and as a drawn flame in the line looks, and a reader who asked for reduced motion has them off. A flame's length and its shock diamonds are a picture, not a measurement. [A flight](docs/flight.md) plays each phase with the engines that burn in it, from published timelines. With no WebGL, under Save-Data, or on any failure, the drawing stays.
|
|
43
45
|
|
|
46
|
+
## Who it is for
|
|
47
|
+
|
|
48
|
+
- **A developer who wants a rocket on a page** with one tag, no build step, and a drawing that is there before any 3D has loaded.
|
|
49
|
+
- **A writer or teacher** who needs a rocket to scale, beside a person and a building, with every size traceable to a source.
|
|
50
|
+
- **A maker of tools** who wants rockets as data: variants, sourced sizes, parts that carry their own joints, and a check that says whether a mix goes together.
|
|
51
|
+
- **Anyone who must credit what they show**: a painted rocket's licence travels with it, in every form it is copied.
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
- Twenty-three kinds of thing, from Starship to the Hubble Space Telescope, each in every variant a source documents, with its own sizes.
|
|
56
|
+
- Three looks (`line`, `thick`, `painted`), five views, together, apart and each part alone, for every one of them.
|
|
57
|
+
- A drawing made by code, and a 3D view that takes over without a jump. With no WebGL, under Save-Data or on any failure, the drawing stays.
|
|
58
|
+
- Lit engines at full thrust, and flights played phase by phase from published timelines.
|
|
59
|
+
- `check` and `build`: a typed part record, a fit check, a `.glb` mesh and an SVG, in Node or a browser, with no three.js.
|
|
60
|
+
- `<uchusen-lineup>`: rockets at one scale with a ruler, a person and a building.
|
|
61
|
+
- Six ways to copy a rocket into your own page, with the credit written in.
|
|
62
|
+
- A strict content security policy is enough. No network request but the painted model you ask for.
|
|
63
|
+
|
|
64
|
+
## Use it in your project
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npm install @johnmorrisdotca/uchusen-rockets three
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```ts no-run
|
|
71
|
+
import "@johnmorrisdotca/uchusen-rockets/element";
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Import the element once, anywhere in your client code, and use the tag. `three` is an optional peer dependency, loaded only for a 3D view. Copy `node_modules/@johnmorrisdotca/uchusen-rockets/dist/assets` to a folder your site serves and call `setAssetBase("/that/folder/")` if you want painted models. [Getting started](docs/guides/getting-started.md) and [React and other frameworks](docs/guides/react-and-frameworks.md) go through it step by step.
|
|
75
|
+
|
|
76
|
+
## Use it anywhere
|
|
77
|
+
|
|
78
|
+
A page with no bundler loads the element from a CDN, with an import map for three.js:
|
|
79
|
+
|
|
80
|
+
```html
|
|
81
|
+
<script type="importmap">
|
|
82
|
+
{ "imports": { "three": "https://cdn.jsdelivr.net/npm/three@0.186.1/build/three.module.js" } }
|
|
83
|
+
</script>
|
|
84
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@johnmorrisdotca/uchusen-rockets@0/dist/element.js"></script>
|
|
85
|
+
<uchusen-rocket rocket="falcon-heavy" look="thick" view="below"></uchusen-rocket>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
A page that cannot run script uses an iframe of the embed page:
|
|
89
|
+
|
|
90
|
+
```html
|
|
91
|
+
<iframe src="https://johnmorrisdotca.github.io/uchusen-rockets/embed.html?rocket=starship&variant=v3&look=line" title="Starship Block 3" style="width:100%;max-width:480px;aspect-ratio:3 / 4;border:0"></iframe>
|
|
92
|
+
```
|
|
93
|
+
|
|
44
94
|
## Put one on your own site
|
|
45
95
|
|
|
46
96
|
The drawings are there to be used. The demo copies the code for the rocket on the screen, in six ways: a CDN script and the element, an iframe of the embed page (for a site that cannot run script), a module, the SVG, a data address, and a link to the picture in the package. It saves an SVG or a PNG too. [docs/embed.md](docs/embed.md) has each one.
|
|
@@ -74,6 +124,10 @@ embedCode({ rocket: "starship", variant: "v3", look: "line" }, "element").includ
|
|
|
74
124
|
|
|
75
125
|
Changing `look` keeps the angle. Changing `show` is an animated move, and a cut under reduced motion. Each part alone fills the frame and has its own listed size. Every look works for every variant and every choice of parts. Front is the windward, tiled side; back is the steel side.
|
|
76
126
|
|
|
127
|
+
<p align="center"><img alt="The code builder: a row of makers, rockets, variants, parts, looks and views beside the rocket, and the code to copy below." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/builder.jpg" width="820"></p>
|
|
128
|
+
|
|
129
|
+
<p align="center"><img alt="The demo on a phone, the rocket on a screen 390 pixels wide." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/phone.jpg" width="320"></p>
|
|
130
|
+
|
|
77
131
|
## The rockets
|
|
78
132
|
|
|
79
133
|
Starship; Falcon 9 in v1.0, v1.1, Full Thrust and Block 5, with a fairing or with Dragon 2; Falcon Heavy; Dragon 1, Dragon 2 and Cargo Dragon 2, and Crew Dragon cut open to see inside; Grasshopper, the test vehicle; and Falcon 1, with the Falcon 1e that was announced and never flew. From other makers, to compare at one scale, each drawn by this package's code from its published sizes: Saturn V; the Space Shuttle, stacked with its tank and boosters, each part alone too, and Discovery, a real scan; the Space Launch System, Block 1 with Orion; New Glenn 7×2; Electron; and Soyuz-2. And where a booster lands: drone ships and landing zones. The Starbase integration tower too, with its mount and arms, a Block 3 stacked on it, or catching its booster. And Starbase, as a scene from the map: `launch-site`, `build-site` and `city`. The Apollo lunar module, painted by NASA's model. Apollo docked to Soyuz, painted by NASA's model, stood on end. The Gemini spacecraft, painted by NASA's model. The Mercury spacecraft, as Friendship 7, painted by NASA's model. Jupiter-C, painted by NASA's model. The International Space Station, painted by NASA's model, of the station as it was when that was made. And the Hubble Space Telescope, painted by NASA's model. <!-- more rockets -->
|
|
@@ -168,7 +222,14 @@ import { UchusenRocket } from "@johnmorrisdotca/uchusen-rockets/react";
|
|
|
168
222
|
|
|
169
223
|
## Licences, credits and a word on trademarks
|
|
170
224
|
|
|
171
|
-
The code, the code-made meshes and the drawings are under the MIT licence. **The painted models are not: they stay under Creative Commons Attribution 4.0, or public domain where the row says so, and using them means crediting them.** `check(description).credits` says which belong to a rocket.
|
|
225
|
+
The code, the code-made meshes and the drawings are under the MIT licence. **The painted models are not: they stay under Creative Commons Attribution 4.0, or public domain where the row says so, and using them means crediting them.** `check(description).credits` says which belong to a rocket.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import { check } from "@johnmorrisdotca/uchusen-rockets";
|
|
229
|
+
|
|
230
|
+
check({ rocket: "starship", variant: "v3" }).credits[0].licence; // "CC BY 4.0"
|
|
231
|
+
```
|
|
232
|
+
**Starbase's coordinates and outlines, its map heights and the tower's 13 m footprint are © OpenStreetMap contributors, under ODbL 1.0, not MIT** (https://www.openstreetmap.org/copyright).
|
|
172
233
|
|
|
173
234
|
| Painted | Title | Creator | Source | Changed |
|
|
174
235
|
| --- | --- | --- | --- | --- |
|
|
@@ -198,10 +259,186 @@ All but Discovery and NASA's are under [CC BY 4.0](https://creativecommons.org/l
|
|
|
198
259
|
|
|
199
260
|
**No mesh or drawing carries a logo, a wordmark or a flag.** Rocket names appear only as plain descriptive words. All trademarks belong to their owners, and this project is not affiliated with or endorsed by SpaceX, NASA or any other maker or agency named here. [NOTICE.md](NOTICE.md) names each source and what was taken from it.
|
|
200
261
|
|
|
201
|
-
##
|
|
262
|
+
## Examples
|
|
263
|
+
|
|
264
|
+
Every `ts` block in this README and in the guides runs against the built package (`pnpm test:readme`).
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import { check, variantOf } from "@johnmorrisdotca/uchusen-rockets";
|
|
268
|
+
|
|
269
|
+
const falcon = variantOf("falcon-9", "block-5");
|
|
270
|
+
falcon.facts.height.value; // 69.8
|
|
271
|
+
check({ rocket: "falcon-9", variant: "block-5" }).ok; // true
|
|
272
|
+
check({ rocket: "falcon-9", variant: "block-5" }).custom; // false
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
import { showsOf, variantOf } from "@johnmorrisdotca/uchusen-rockets";
|
|
277
|
+
|
|
278
|
+
showsOf(variantOf("falcon-9", "block-5").slots).includes("apart"); // true
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
import { lineupSvg } from "@johnmorrisdotca/uchusen-rockets/build";
|
|
283
|
+
|
|
284
|
+
const picture = lineupSvg({ items: ["starship:v3", "falcon-9:block-5", "person"], unit: 4, ruler: true, labels: true });
|
|
285
|
+
picture.items.length; // 3
|
|
286
|
+
picture.svg.startsWith("<svg"); // true
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import { cleanLook, cleanView } from "@johnmorrisdotca/uchusen-rockets";
|
|
291
|
+
|
|
292
|
+
cleanLook("shiny"); // "line"
|
|
293
|
+
cleanView("below"); // "below"
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Anything from outside is treated as text: an attribute that is not in its list falls back to the default and nothing else.
|
|
297
|
+
|
|
298
|
+
## The code builder
|
|
299
|
+
|
|
300
|
+
[The code builder](https://johnmorrisdotca.github.io/uchusen-rockets/builder.html) is one screen: choose the maker, the rocket, the variant, the parts, the look, the view and the engines, see the rocket, and copy the code for any of the six ways. A painted rocket's credit is under the code. It is built from `ROCKETS`, `showsOf`, `embedCode` and `paintedCredit`, so it offers every rocket the package has, as it gains them.
|
|
301
|
+
|
|
302
|
+
## Lit engines and flights
|
|
303
|
+
|
|
304
|
+
```html
|
|
305
|
+
<uchusen-rocket id="rocket" rocket="falcon-9" variant="block-5" look="painted" engines="on"></uchusen-rocket>
|
|
306
|
+
<uchusen-flight for="rocket"></uchusen-flight>
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
<p align="center"><img alt="Falcon 9 painted, seen from below with its engines lit." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/engines.jpg" width="360"></p>
|
|
310
|
+
|
|
311
|
+
<p align="center"><img alt="The flight bar: play, back, a slider and next, what happens at hot staging and a chart of the engines that burn." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/flight.jpg" width="720"></p>
|
|
312
|
+
|
|
313
|
+
`engines="on"` lights each engine that shows, and a flight lights only the engines that burn in each phase, from a published timeline. How the picture moves between phases, and a flame's length, is illustrative; the times and counts are sourced. [The guide](docs/guides/engines-and-flights.md) has the details.
|
|
314
|
+
|
|
315
|
+
## NASA's models
|
|
316
|
+
|
|
317
|
+
The Apollo lunar module, Apollo docked to Soyuz, Gemini, Mercury, Jupiter-C, the Space Shuttle, the International Space Station and the Hubble Space Telescope are painted by NASA's own public-domain models, each with its marks removed and its sizes set from a source.
|
|
318
|
+
|
|
319
|
+
<p align="center">
|
|
320
|
+
<img alt="The Apollo lunar module painted from NASA's model." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/lunar-module.jpg" width="300">
|
|
321
|
+
<img alt="The Space Shuttle stacked for launch, painted from NASA's models." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/shuttle.jpg" width="300">
|
|
322
|
+
</p>
|
|
323
|
+
|
|
324
|
+
## API
|
|
325
|
+
|
|
326
|
+
The reference is a site, made from the source's own doc comments: every export has a summary, its parameters, what it returns, and an example that runs when the site is built. [Open the reference](https://johnmorrisdotca.github.io/uchusen-rockets/docs/).
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
import { ROCKETS, PART_ENTRIES, SOURCES, MODEL_CREDITS } from "@johnmorrisdotca/uchusen-rockets";
|
|
330
|
+
|
|
331
|
+
Object.keys(ROCKETS).length > 20; // true
|
|
332
|
+
PART_ENTRIES.length > 100; // true
|
|
333
|
+
Object.keys(SOURCES).length > 20; // true
|
|
334
|
+
Object.keys(MODEL_CREDITS).length > 10; // true
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
<p align="center"><img alt="The documentation site: a search box, the entry points, the guides in sections, and every export with its example." src="https://raw.githubusercontent.com/johnmorrisdotca/uchusen-rockets/main/docs/images/docs-site.jpg" width="720"></p>
|
|
338
|
+
|
|
339
|
+
## Guides
|
|
340
|
+
|
|
341
|
+
Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja).
|
|
342
|
+
|
|
343
|
+
| Guide | What it is for |
|
|
344
|
+
| --- | --- |
|
|
345
|
+
| [Getting started](docs/guides/getting-started.md) | A rocket on a page in ten minutes |
|
|
346
|
+
| [Looks, views and parts](docs/guides/looks-views-and-parts.md) | The three choices that change what you see |
|
|
347
|
+
| [Build a rocket from parts](docs/guides/build-from-parts.md) | Part records, the fit check, `build`, the builder |
|
|
348
|
+
| [Lit engines and flights](docs/guides/engines-and-flights.md) | Engines at full thrust, flights, what is sourced |
|
|
349
|
+
| [Rockets to scale](docs/guides/scale-lineups.md) | `<uchusen-lineup>` and `lineupSvg` |
|
|
350
|
+
| [Put a rocket on your own site](docs/guides/embed-on-your-site.md) | Six ways, and the credit |
|
|
351
|
+
| [React and other frameworks](docs/guides/react-and-frameworks.md) | React, Vue, Svelte, Angular |
|
|
352
|
+
| [Ready files and 3D models](docs/guides/assets-and-3d-files.md) | The `.glb` and `.svg` files |
|
|
353
|
+
| [Variants and sourced sizes](docs/guides/variants-and-sources.md) | Why a figure names its source |
|
|
354
|
+
| [Licences, credits and trademarks](docs/guides/licences-and-credits.md) | What is MIT, CC BY, public domain, ODbL |
|
|
355
|
+
| [Architecture](docs/guides/architecture.md) | How the layers fit |
|
|
356
|
+
| [Troubleshooting](docs/guides/troubleshooting.md) | Why the 3D view or the model is missing |
|
|
357
|
+
| [Upgrading](docs/guides/upgrading.md) | What to look for between versions |
|
|
358
|
+
|
|
359
|
+
## Limits
|
|
360
|
+
|
|
361
|
+
- A rocket is only as good as its sources. A figure no source gives is blank, never estimated, and a blank is shown as one.
|
|
362
|
+
- A flame's length and its shock diamonds, how parts move between flight phases, smoke and the ground falling away are pictures, not measurements.
|
|
363
|
+
- A part with no licensed model is painted by this package's own code from photographs and sizes. It is a likeness, not a scan.
|
|
364
|
+
- A flight exists only for the variants a published timeline covers. A custom build has none.
|
|
365
|
+
- A painted model is up to 8 MB and is fetched only when asked for. Code-made meshes stay under 600 KB and drawings under 80 KB.
|
|
366
|
+
- There is no logo, wordmark or flag on anything, so a rocket is never "the real livery".
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
import { variantOf } from "@johnmorrisdotca/uchusen-rockets";
|
|
370
|
+
|
|
371
|
+
variantOf("starship", "2019").facts.diameter.value; // null
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## Accessibility
|
|
375
|
+
|
|
376
|
+
- The element has an accessible name from its `label` attribute, or from the fit report's label (such as "Block 3 (V3)") when there is none. The 3D view's canvas says how to turn it.
|
|
377
|
+
- A reader who asked for reduced motion gets no spin, no flames, no played flight and a cut instead of an animated move. The slider and charts still work.
|
|
378
|
+
- Turning works by drag, touch and the keyboard: the arrow keys turn it, `+` and `-` zoom, Home puts it back.
|
|
379
|
+
- The demo's controls are at least 44 pixels tall and work with a keyboard.
|
|
380
|
+
|
|
381
|
+
```html
|
|
382
|
+
<uchusen-rocket rocket="starship" variant="v3" label="Starship Block 3, taken apart" show="apart"></uchusen-rocket>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## Browser and runtime support
|
|
386
|
+
|
|
387
|
+
- Using the package needs Node 22 or later. Working on it needs 22.18 or later.
|
|
388
|
+
- In a browser, any current one. The 3D view needs WebGL; without it the drawing stays.
|
|
389
|
+
- The test suite runs the demo in Chromium and WebKit at a phone's width and a desk's, and the packed package on Linux, macOS and Windows, on Node 22 and 24.
|
|
390
|
+
- `three` `>=0.170.0` and `react` `>=18` are optional peer dependencies.
|
|
391
|
+
|
|
392
|
+
## Languages
|
|
393
|
+
|
|
394
|
+
The documentation is in English and Japanese: each guide in [docs/guides](docs/guides) has a twin in [docs/guides/ja](docs/guides/ja), and the documentation site switches between them. The rockets' own names are plain descriptive words and are the same in both.
|
|
395
|
+
|
|
396
|
+
## Architecture
|
|
397
|
+
|
|
398
|
+
The data is typed once. A part is a table of numbers: its real size in metres and the joints it mates at. A mesh and a drawing come from the same pieces, so they cannot disagree with each other or with the data. The root and `build` entries import neither three.js nor the DOM; the element loads three.js only for a 3D view.
|
|
399
|
+
|
|
400
|
+
```ts
|
|
401
|
+
import { build } from "@johnmorrisdotca/uchusen-rockets/build";
|
|
402
|
+
|
|
403
|
+
const a = build({ rocket: "falcon-9", variant: "block-5" }).glb().bytes;
|
|
404
|
+
const b = build({ rocket: "falcon-9", variant: "block-5" }).glb().bytes;
|
|
405
|
+
a.length === b.length; // true
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
A mesh is a pure function of its description: the same description gives the same bytes. [Architecture](docs/guides/architecture.md) has the layers.
|
|
409
|
+
|
|
410
|
+
## Development
|
|
411
|
+
|
|
412
|
+
```sh
|
|
413
|
+
pnpm install
|
|
414
|
+
pnpm check # lint, types, tests, the build and the packed package
|
|
415
|
+
pnpm test:readme # run every example of the README, the docs and the guides
|
|
416
|
+
pnpm docs:check # the reference site's checks: every export documented, every example run
|
|
417
|
+
pnpm test:demo # the demo in a real browser
|
|
418
|
+
pnpm dev # the demo on http://127.0.0.1:7900/uchusen-rockets/
|
|
419
|
+
pnpm screenshots # the pictures in docs/images
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Contributing
|
|
423
|
+
|
|
424
|
+
Bug reports, ideas and pull requests are welcome: see [CONTRIBUTING.md](CONTRIBUTING.md). The rules that matter most: a figure names its source or is blank, no logos or marks, a mesh is a pure function of its description, and anything from outside is text.
|
|
425
|
+
|
|
426
|
+
## Changes
|
|
427
|
+
|
|
428
|
+
[CHANGELOG.md](CHANGELOG.md) lists every release with its date.
|
|
429
|
+
|
|
430
|
+
## Roadmap
|
|
202
431
|
|
|
203
432
|
`PLANNED_ROCKETS` lists rockets with sourced facts and no shape yet: Vulcan Centaur and Ariane 6.
|
|
204
433
|
|
|
434
|
+
```ts
|
|
435
|
+
import { PLANNED_ROCKETS } from "@johnmorrisdotca/uchusen-rockets";
|
|
436
|
+
|
|
437
|
+
PLANNED_ROCKETS.map((rocket) => rocket.id).length > 0; // true
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
A rocket goes in only when a source documents it.
|
|
441
|
+
|
|
205
442
|
## The rest
|
|
206
443
|
|
|
207
444
|
[CONTRIBUTING.md](CONTRIBUTING.md) · [SECURITY.md](SECURITY.md) · [CHANGELOG.md](CHANGELOG.md) · [NOTICE.md](NOTICE.md) · MIT licence, CC BY 4.0 for the painted models, and ODbL 1.0 for the map data
|
package/dist/attrs.d.ts
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attributes of `<uchusen-rocket>` that choose what is drawn, in the order the demo writes them. The `embed.html` query uses the same words.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { OPTION_ATTRIBUTES } from "@johnmorrisdotca/uchusen-rockets";
|
|
7
|
+
*
|
|
8
|
+
* console.log(OPTION_ATTRIBUTES.join(", "));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
1
11
|
export declare const OPTION_ATTRIBUTES: readonly ["rocket", "variant", "show", "look", "view", "build", "mode", "spin", "way", "label", "assets", "engines", "phase"];
|
|
12
|
+
/**
|
|
13
|
+
* Every choice that draws a rocket, as plain text: the same names and values as the element's attributes. Nothing here is trusted. A value outside its list falls back to a default when it is drawn.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import type { RocketOptions } from "@johnmorrisdotca/uchusen-rockets";
|
|
18
|
+
*
|
|
19
|
+
* const options: RocketOptions = { rocket: "falcon-9", variant: "block-5", look: "thick", view: "below" };
|
|
20
|
+
* console.log(options);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
2
23
|
export interface RocketOptions {
|
|
3
24
|
rocket?: string;
|
|
4
25
|
variant?: string;
|
|
@@ -17,11 +38,56 @@ export interface RocketOptions {
|
|
|
17
38
|
/** A phase of the rocket's flight, by its id: the engines that burn there. */
|
|
18
39
|
phase?: string;
|
|
19
40
|
}
|
|
20
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The attributes that draw these options. Empty values are left out.
|
|
43
|
+
*
|
|
44
|
+
* @param options The choices to turn into attributes.
|
|
45
|
+
* @returns The attributes by name, as text. A choice left out or empty has no entry.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { attributesFromOptions } from "@johnmorrisdotca/uchusen-rockets";
|
|
49
|
+
*
|
|
50
|
+
* console.log(attributesFromOptions({ rocket: "starship", variant: "v3", look: "painted", show: "" }));
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
21
53
|
export declare function attributesFromOptions(options: RocketOptions): Record<string, string>;
|
|
22
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* The options `read` finds. A missing attribute is left out; nothing here is trusted as a real rocket.
|
|
56
|
+
*
|
|
57
|
+
* @param read Reads one attribute by name and gives null when it is missing, as `element.getAttribute` does.
|
|
58
|
+
* @returns The choices found, as written. A missing attribute is left out of the result.
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { optionsFromAttributes } from "@johnmorrisdotca/uchusen-rockets";
|
|
62
|
+
*
|
|
63
|
+
* const attributes: Record<string, string> = { rocket: "starship", look: "thick" };
|
|
64
|
+
* console.log(optionsFromAttributes((name) => attributes[name] ?? null));
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
23
67
|
export declare function optionsFromAttributes(read: (name: string) => string | null): RocketOptions;
|
|
24
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* The options as a query for `embed.html`.
|
|
70
|
+
*
|
|
71
|
+
* @param options The choices to write.
|
|
72
|
+
* @returns A query for `embed.html`, with one entry for each choice made.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { rocketToParams } from "@johnmorrisdotca/uchusen-rockets";
|
|
76
|
+
*
|
|
77
|
+
* console.log(rocketToParams({ rocket: "falcon-9", show: "apart" }).toString());
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
25
80
|
export declare function rocketToParams(options: RocketOptions): URLSearchParams;
|
|
26
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* The options a query names.
|
|
83
|
+
*
|
|
84
|
+
* @param params The query of an `embed.html` address.
|
|
85
|
+
* @returns The choices the query names.
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { rocketFromParams } from "@johnmorrisdotca/uchusen-rockets";
|
|
89
|
+
*
|
|
90
|
+
* console.log(rocketFromParams(new URLSearchParams("rocket=falcon-9&look=thick")));
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
27
93
|
export declare function rocketFromParams(params: URLSearchParams): RocketOptions;
|
package/dist/attrs.js
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
// A rocket's options as text: the attributes of `<uchusen-rocket>` and the query of `embed.html` are the same words, read by one function and written by another.
|
|
2
|
+
/**
|
|
3
|
+
* The attributes of `<uchusen-rocket>` that choose what is drawn, in the order the demo writes them. The `embed.html` query uses the same words.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { OPTION_ATTRIBUTES } from "@johnmorrisdotca/uchusen-rockets";
|
|
8
|
+
*
|
|
9
|
+
* console.log(OPTION_ATTRIBUTES.join(", "));
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
2
12
|
export const OPTION_ATTRIBUTES = ["rocket", "variant", "show", "look", "view", "build", "mode", "spin", "way", "label", "assets", "engines", "phase"];
|
|
3
13
|
const text = (value) => (typeof value === "string" && value !== "" ? value : undefined);
|
|
4
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* The attributes that draw these options. Empty values are left out.
|
|
16
|
+
*
|
|
17
|
+
* @param options The choices to turn into attributes.
|
|
18
|
+
* @returns The attributes by name, as text. A choice left out or empty has no entry.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { attributesFromOptions } from "@johnmorrisdotca/uchusen-rockets";
|
|
22
|
+
*
|
|
23
|
+
* console.log(attributesFromOptions({ rocket: "starship", variant: "v3", look: "painted", show: "" }));
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
5
26
|
export function attributesFromOptions(options) {
|
|
6
27
|
const out = {};
|
|
7
28
|
for (const name of OPTION_ATTRIBUTES) {
|
|
@@ -11,7 +32,19 @@ export function attributesFromOptions(options) {
|
|
|
11
32
|
}
|
|
12
33
|
return out;
|
|
13
34
|
}
|
|
14
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The options `read` finds. A missing attribute is left out; nothing here is trusted as a real rocket.
|
|
37
|
+
*
|
|
38
|
+
* @param read Reads one attribute by name and gives null when it is missing, as `element.getAttribute` does.
|
|
39
|
+
* @returns The choices found, as written. A missing attribute is left out of the result.
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { optionsFromAttributes } from "@johnmorrisdotca/uchusen-rockets";
|
|
43
|
+
*
|
|
44
|
+
* const attributes: Record<string, string> = { rocket: "starship", look: "thick" };
|
|
45
|
+
* console.log(optionsFromAttributes((name) => attributes[name] ?? null));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
15
48
|
export function optionsFromAttributes(read) {
|
|
16
49
|
const options = {};
|
|
17
50
|
for (const name of OPTION_ATTRIBUTES) {
|
|
@@ -21,11 +54,33 @@ export function optionsFromAttributes(read) {
|
|
|
21
54
|
}
|
|
22
55
|
return options;
|
|
23
56
|
}
|
|
24
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The options as a query for `embed.html`.
|
|
59
|
+
*
|
|
60
|
+
* @param options The choices to write.
|
|
61
|
+
* @returns A query for `embed.html`, with one entry for each choice made.
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { rocketToParams } from "@johnmorrisdotca/uchusen-rockets";
|
|
65
|
+
*
|
|
66
|
+
* console.log(rocketToParams({ rocket: "falcon-9", show: "apart" }).toString());
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
25
69
|
export function rocketToParams(options) {
|
|
26
70
|
return new URLSearchParams(attributesFromOptions(options));
|
|
27
71
|
}
|
|
28
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* The options a query names.
|
|
74
|
+
*
|
|
75
|
+
* @param params The query of an `embed.html` address.
|
|
76
|
+
* @returns The choices the query names.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { rocketFromParams } from "@johnmorrisdotca/uchusen-rockets";
|
|
80
|
+
*
|
|
81
|
+
* console.log(rocketFromParams(new URLSearchParams("rocket=falcon-9&look=thick")));
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
29
84
|
export function rocketFromParams(params) {
|
|
30
85
|
return optionsFromAttributes((name) => params.get(name));
|
|
31
86
|
}
|
package/dist/build/glb.d.ts
CHANGED
|
@@ -5,8 +5,33 @@ export interface GlbPart {
|
|
|
5
5
|
mesh: PartMesh;
|
|
6
6
|
at: readonly [number, number, number];
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* A binary glTF file: its bytes and how many triangles it holds. Save the bytes as a `.glb` file or hand them to any glTF viewer.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { build } from "@johnmorrisdotca/uchusen-rockets/build";
|
|
14
|
+
*
|
|
15
|
+
* const glb = build({ rocket: "starship", variant: "v3" }).glb();
|
|
16
|
+
* console.log(glb.bytes.length > 1000, glb.triangles > 0);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
8
19
|
export interface Glb {
|
|
9
20
|
bytes: Uint8Array;
|
|
10
21
|
triangles: number;
|
|
11
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Writes parts into one small binary glTF file, in Node or a browser, with no dependency: one node for each part and one primitive for each material. The same parts always give the same bytes.
|
|
25
|
+
*
|
|
26
|
+
* @param parts The parts to write: each has a node name, its mesh and where it stands in metres.
|
|
27
|
+
* @returns The file's bytes and its triangle count.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { build, toGlb } from "@johnmorrisdotca/uchusen-rockets/build";
|
|
31
|
+
*
|
|
32
|
+
* const rocket = build({ rocket: "falcon-9", variant: "block-5" });
|
|
33
|
+
* const glb = toGlb(rocket.parts.map((part) => ({ name: part.slot, mesh: part.mesh, at: [0, 0, 0] as const })));
|
|
34
|
+
* console.log(glb.bytes.length > 1000, glb.triangles > 0);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
12
37
|
export declare function toGlb(parts: readonly GlbPart[]): Glb;
|
package/dist/build/glb.js
CHANGED
|
@@ -10,6 +10,20 @@ const LINES = 1;
|
|
|
10
10
|
const round6 = (v) => Math.round(v * 1e6) / 1e6;
|
|
11
11
|
const toLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
12
12
|
const linearOf = (hex) => [1, 3, 5].map((i) => round6(toLinear(Number.parseInt(hex.slice(i, i + 2), 16) / 255)));
|
|
13
|
+
/**
|
|
14
|
+
* Writes parts into one small binary glTF file, in Node or a browser, with no dependency: one node for each part and one primitive for each material. The same parts always give the same bytes.
|
|
15
|
+
*
|
|
16
|
+
* @param parts The parts to write: each has a node name, its mesh and where it stands in metres.
|
|
17
|
+
* @returns The file's bytes and its triangle count.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { build, toGlb } from "@johnmorrisdotca/uchusen-rockets/build";
|
|
21
|
+
*
|
|
22
|
+
* const rocket = build({ rocket: "falcon-9", variant: "block-5" });
|
|
23
|
+
* const glb = toGlb(rocket.parts.map((part) => ({ name: part.slot, mesh: part.mesh, at: [0, 0, 0] as const })));
|
|
24
|
+
* console.log(glb.bytes.length > 1000, glb.triangles > 0);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
13
27
|
export function toGlb(parts) {
|
|
14
28
|
const chunks = [];
|
|
15
29
|
let offset = 0;
|