three-rb 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -2
- data/README.md +12 -6
- data/docs/browser-runtime.md +9 -7
- data/docs/cloudflare-pages.md +205 -0
- data/docs/implementation-plan.md +6 -4
- data/docs/next-work.md +26 -25
- data/docs/publishing.md +1 -1
- data/docs/release-readiness.md +11 -11
- data/docs/standalone-browser-app.md +5 -3
- data/examples/browser/README.md +3 -1
- data/examples/browser/composition/index.html +65 -4
- data/examples/browser/cube/README.md +3 -3
- data/examples/browser/cube/index.html +61 -6
- data/examples/browser/cubemap/index.html +60 -5
- data/examples/browser/dango/README.md +26 -0
- data/examples/browser/dango/boot.mjs +6 -0
- data/examples/browser/dango/index.html +197 -0
- data/examples/browser/dango/main.rb +278 -0
- data/examples/browser/dango/smoke_test.mjs +232 -0
- data/examples/browser/gltf/index.html +60 -5
- data/examples/browser/picking/index.html +61 -6
- data/examples/browser/postprocessing/index.html +61 -6
- data/examples/browser/primitives/index.html +61 -6
- data/examples/browser/ruby/README.md +1 -1
- data/examples/browser/ruby/assets/helvetiker_regular.typeface.json +1 -0
- data/examples/browser/ruby/index.html +112 -8
- data/examples/browser/ruby/main.rb +2 -6
- data/examples/browser/serialization/index.html +61 -6
- data/examples/browser/shared/boot.mjs +115 -13
- data/examples/browser/shared/config.mjs +3 -0
- data/examples/browser/shared/smoke_test_helpers.mjs +13 -8
- data/examples/browser/textures/index.html +61 -6
- data/lib/three/backends/threejs/parameters.rb +4 -1
- data/lib/three/backends/threejs/ruby_wasm_adapter.rb +8 -2
- data/lib/three/generators/browser_example.rb +136 -9
- data/lib/three/version.rb +1 -1
- data/package.json +9 -5
- data/pnpm-lock.yaml +1235 -31
- metadata +10 -3
- data/examples/browser/ruby/assets/studio.hdr +0 -5
|
@@ -22,13 +22,13 @@ If you installed through Bundler, run:
|
|
|
22
22
|
bundle exec three-rb browser examples/browser/quickstart
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
Use `three-rb browser examples/browser/ruby` instead when you want the richer Ruby gemstone sample. It generates the same browser runtime shape and keeps its
|
|
25
|
+
Use `three-rb browser examples/browser/ruby` instead when you want the richer Ruby gemstone sample. It generates the same browser runtime shape and keeps its title font under `examples/browser/ruby/assets/`.
|
|
26
26
|
|
|
27
27
|
The generator creates:
|
|
28
28
|
|
|
29
|
-
- `package.json
|
|
29
|
+
- `package.json`, listing only the browser runtime packages (three.js and ruby.wasm), and a matching `pnpm-lock.yaml`
|
|
30
30
|
- `lib/`, copied from the installed gem
|
|
31
|
-
- `examples/browser/shared/boot.mjs`
|
|
31
|
+
- `examples/browser/shared/boot.mjs` and `examples/browser/shared/config.mjs`
|
|
32
32
|
- `examples/browser/quickstart/index.html`
|
|
33
33
|
- `examples/browser/quickstart/boot.mjs`
|
|
34
34
|
- `examples/browser/quickstart/main.rb`
|
|
@@ -36,6 +36,8 @@ The generator creates:
|
|
|
36
36
|
|
|
37
37
|
For templates that need assets, the generator also creates an `assets/` directory inside the example.
|
|
38
38
|
|
|
39
|
+
If the project already has a `package.json`, the generator leaves it alone and doesn't write a lockfile. Add the `dependencies` from the gem's `package.json` to it yourself.
|
|
40
|
+
|
|
39
41
|
Copying `lib/` puts the installed gem's Ruby source in the served app directory. The browser Ruby VM loads Ruby files over HTTP, so this is the current standalone workflow.
|
|
40
42
|
|
|
41
43
|
Pass `--force` only when you want to overwrite generated example files:
|
data/examples/browser/README.md
CHANGED
|
@@ -20,6 +20,7 @@ Open an example URL:
|
|
|
20
20
|
```text
|
|
21
21
|
http://localhost:8000/examples/browser/ruby/
|
|
22
22
|
http://localhost:8000/examples/browser/cube/
|
|
23
|
+
http://localhost:8000/examples/browser/dango/
|
|
23
24
|
http://localhost:8000/examples/browser/composition/
|
|
24
25
|
http://localhost:8000/examples/browser/textures/
|
|
25
26
|
http://localhost:8000/examples/browser/cubemap/
|
|
@@ -44,8 +45,9 @@ Run one smoke test by using the command listed in the table below.
|
|
|
44
45
|
|
|
45
46
|
| Example | Primary APIs covered | Smoke command | Why it exists |
|
|
46
47
|
| --- | --- | --- | --- |
|
|
47
|
-
| `examples/browser/ruby/` | `BufferGeometry`, `Float32BufferAttribute`, `MeshPhysicalMaterial`, `
|
|
48
|
+
| `examples/browser/ruby/` | `BufferGeometry`, `Float32BufferAttribute`, `MeshPhysicalMaterial`, `FontLoader`, `TextGeometry`, `OrbitControls`, shadows | `pnpm test:browser:ruby` | Provides the first visual sample: a Ruby-authored faceted red gemstone with a three-dimensional `three-rb` title. |
|
|
48
49
|
| `examples/browser/cube/` | `Scene`, `PerspectiveCamera`, `BoxGeometry`, `Mesh`, `MeshBasicMaterial`, `ThreeJSRenderer`, animation loop | `pnpm test:browser:cube` | Verifies the smallest Ruby-authored scene can boot through ruby.wasm and draw nonblank WebGL pixels through the three.js renderer path. |
|
|
50
|
+
| `examples/browser/dango/` | `OrthographicCamera`, `SphereGeometry`, `BoxGeometry`, `Group`, `MeshPhongMaterial`, `MeshLambertMaterial`, directional/hemisphere/point lights, shadows, `OrbitControls` | `pnpm test:browser:dango` | Adds a recognizable Ruby-authored 3D graphics example by composing a three-color dango from primitive meshes with lighting, shadows, and camera controls. |
|
|
49
51
|
| `examples/browser/composition/` | `OrthographicCamera`, ambient/directional/point/hemisphere lights, shadows, `ShadowMaterial`, `Group`, `InstancedMesh`, `TextureLoader`, `OrbitControls`, material/texture disposal | `pnpm test:browser:composition` | Exercises the broad scene-composition path used by richer browser scenes, including dynamic material updates and camera controls. |
|
|
50
52
|
| `examples/browser/textures/` | `TextureLoader`, `RGBELoader`, repeat/wrap/filter/UV-transform settings, `MeshPhysicalMaterial`, `MeshMatcapMaterial`, `MeshToonMaterial`, physical, matcap, and toon texture slots, scene environment | `pnpm test:browser:textures` | Verifies browser texture loading, HDR environment synchronization, and the current material texture bridge. |
|
|
51
53
|
| `examples/browser/cubemap/` | `CubeTextureLoader`, `CubeTexture`, scene `background`, scene `environment`, reflective `MeshStandardMaterial` | `pnpm test:browser:cubemap` | Keeps cubemap background/environment behavior covered separately from ordinary 2D texture loading. |
|
|
@@ -54,10 +54,12 @@
|
|
|
54
54
|
position: absolute;
|
|
55
55
|
top: 16px;
|
|
56
56
|
left: 16px;
|
|
57
|
-
display:
|
|
57
|
+
display: grid;
|
|
58
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
58
59
|
align-items: center;
|
|
59
60
|
gap: 8px;
|
|
60
61
|
max-width: calc(100% - 32px);
|
|
62
|
+
min-width: min(360px, calc(100% - 32px));
|
|
61
63
|
padding: 8px 10px;
|
|
62
64
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
63
65
|
border-radius: 6px;
|
|
@@ -87,6 +89,44 @@
|
|
|
87
89
|
background: #f15b5b;
|
|
88
90
|
box-shadow: 0 0 14px rgba(241, 91, 91, 0.72);
|
|
89
91
|
}
|
|
92
|
+
|
|
93
|
+
.status-dot[data-state="loading"] {
|
|
94
|
+
animation: status-dot-pulse 1.2s ease-in-out infinite;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@keyframes status-dot-pulse {
|
|
98
|
+
0%,
|
|
99
|
+
100% {
|
|
100
|
+
opacity: 1;
|
|
101
|
+
transform: scale(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
50% {
|
|
105
|
+
opacity: 0.4;
|
|
106
|
+
transform: scale(0.75);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.progress {
|
|
111
|
+
grid-column: 1 / -1;
|
|
112
|
+
width: 100%;
|
|
113
|
+
height: 4px;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
border-radius: 999px;
|
|
116
|
+
background: rgba(255, 255, 255, 0.16);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.progress-bar {
|
|
120
|
+
width: 4%;
|
|
121
|
+
height: 100%;
|
|
122
|
+
border-radius: inherit;
|
|
123
|
+
background: linear-gradient(90deg, #55ace0, #60d394);
|
|
124
|
+
transition: width 180ms ease;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.progress[hidden] {
|
|
128
|
+
display: none;
|
|
129
|
+
}
|
|
90
130
|
</style>
|
|
91
131
|
<script type="importmap">
|
|
92
132
|
{
|
|
@@ -101,10 +141,22 @@
|
|
|
101
141
|
<script type="module">
|
|
102
142
|
const status = document.querySelector("#status");
|
|
103
143
|
const statusDot = document.querySelector("#status-dot");
|
|
144
|
+
const progress = document.querySelector("#progress");
|
|
145
|
+
const progressBar = document.querySelector("#progress-bar");
|
|
104
146
|
|
|
105
|
-
globalThis.__threeRbSetStatus = (message, state) => {
|
|
147
|
+
globalThis.__threeRbSetStatus = (message, state, percent) => {
|
|
106
148
|
if (status) status.textContent = message;
|
|
107
149
|
if (statusDot) statusDot.dataset.state = state;
|
|
150
|
+
if (progress && progressBar) {
|
|
151
|
+
if (state === "running" || state === "error") {
|
|
152
|
+
progress.hidden = true;
|
|
153
|
+
} else {
|
|
154
|
+
progress.hidden = false;
|
|
155
|
+
if (Number.isFinite(percent)) {
|
|
156
|
+
progressBar.style.width = `${Math.max(4, Math.min(100, percent))}%`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
108
160
|
};
|
|
109
161
|
|
|
110
162
|
globalThis.__threeRbBootFailed = (message) => {
|
|
@@ -120,7 +172,13 @@
|
|
|
120
172
|
globalThis.__threeRbBootFailed(reason && reason.message ? reason.message : "Ruby boot failed");
|
|
121
173
|
});
|
|
122
174
|
|
|
123
|
-
globalThis.
|
|
175
|
+
globalThis.setTimeout(() => {
|
|
176
|
+
if (status && statusDot && statusDot.dataset.state === "loading") {
|
|
177
|
+
status.textContent = "Still loading after 15 seconds. Try reloading the page.";
|
|
178
|
+
}
|
|
179
|
+
}, 15000);
|
|
180
|
+
|
|
181
|
+
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading", 4);
|
|
124
182
|
</script>
|
|
125
183
|
<script type="module" src="./boot.mjs"></script>
|
|
126
184
|
</head>
|
|
@@ -128,8 +186,11 @@
|
|
|
128
186
|
<main class="viewport" id="viewport">
|
|
129
187
|
<canvas id="scene" data-testid="scene-canvas"></canvas>
|
|
130
188
|
<div class="hud" aria-live="polite">
|
|
131
|
-
<span class="status-dot" id="status-dot"></span>
|
|
189
|
+
<span class="status-dot" id="status-dot" data-state="loading"></span>
|
|
132
190
|
<span id="status" data-testid="status">Loading ruby.wasm</span>
|
|
191
|
+
<div class="progress" id="progress" aria-hidden="true">
|
|
192
|
+
<div class="progress-bar" id="progress-bar"></div>
|
|
193
|
+
</div>
|
|
133
194
|
</div>
|
|
134
195
|
</main>
|
|
135
196
|
</body>
|
|
@@ -17,9 +17,9 @@ http://localhost:8000/examples/browser/cube/
|
|
|
17
17
|
|
|
18
18
|
The page uses these pnpm-managed browser dependencies:
|
|
19
19
|
|
|
20
|
-
- `@ruby/3.4-wasm-wasi@2.
|
|
21
|
-
- `@ruby/wasm-wasi@2.
|
|
22
|
-
- `three@0.
|
|
20
|
+
- `@ruby/3.4-wasm-wasi@2.10.1`
|
|
21
|
+
- `@ruby/wasm-wasi@2.10.1`
|
|
22
|
+
- `three@0.187.0`
|
|
23
23
|
|
|
24
24
|
The repository root must be served, not only this directory, because `boot.mjs` loads browser packages from `node_modules/` and `main.rb` loads the library source from `lib/`.
|
|
25
25
|
|
|
@@ -54,10 +54,12 @@
|
|
|
54
54
|
position: absolute;
|
|
55
55
|
top: 16px;
|
|
56
56
|
left: 16px;
|
|
57
|
-
display:
|
|
57
|
+
display: grid;
|
|
58
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
58
59
|
align-items: center;
|
|
59
60
|
gap: 8px;
|
|
60
61
|
max-width: calc(100% - 32px);
|
|
62
|
+
min-width: min(360px, calc(100% - 32px));
|
|
61
63
|
padding: 8px 10px;
|
|
62
64
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
63
65
|
border-radius: 6px;
|
|
@@ -87,6 +89,44 @@
|
|
|
87
89
|
background: #f15b5b;
|
|
88
90
|
box-shadow: 0 0 14px rgba(241, 91, 91, 0.72);
|
|
89
91
|
}
|
|
92
|
+
|
|
93
|
+
.status-dot[data-state="loading"] {
|
|
94
|
+
animation: status-dot-pulse 1.2s ease-in-out infinite;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@keyframes status-dot-pulse {
|
|
98
|
+
0%,
|
|
99
|
+
100% {
|
|
100
|
+
opacity: 1;
|
|
101
|
+
transform: scale(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
50% {
|
|
105
|
+
opacity: 0.4;
|
|
106
|
+
transform: scale(0.75);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.progress {
|
|
111
|
+
grid-column: 1 / -1;
|
|
112
|
+
width: 100%;
|
|
113
|
+
height: 4px;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
border-radius: 999px;
|
|
116
|
+
background: rgba(255, 255, 255, 0.16);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.progress-bar {
|
|
120
|
+
width: 4%;
|
|
121
|
+
height: 100%;
|
|
122
|
+
border-radius: inherit;
|
|
123
|
+
background: linear-gradient(90deg, #55ace0, #4ed08f);
|
|
124
|
+
transition: width 180ms ease;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.progress[hidden] {
|
|
128
|
+
display: none;
|
|
129
|
+
}
|
|
90
130
|
</style>
|
|
91
131
|
<script type="importmap">
|
|
92
132
|
{
|
|
@@ -101,10 +141,22 @@
|
|
|
101
141
|
<script type="module">
|
|
102
142
|
const status = document.querySelector("#status");
|
|
103
143
|
const statusDot = document.querySelector("#status-dot");
|
|
144
|
+
const progress = document.querySelector("#progress");
|
|
145
|
+
const progressBar = document.querySelector("#progress-bar");
|
|
104
146
|
|
|
105
|
-
globalThis.__threeRbSetStatus = (message, state) => {
|
|
147
|
+
globalThis.__threeRbSetStatus = (message, state, percent) => {
|
|
106
148
|
if (status) status.textContent = message;
|
|
107
149
|
if (statusDot) statusDot.dataset.state = state;
|
|
150
|
+
if (progress && progressBar) {
|
|
151
|
+
if (state === "running" || state === "error") {
|
|
152
|
+
progress.hidden = true;
|
|
153
|
+
} else {
|
|
154
|
+
progress.hidden = false;
|
|
155
|
+
if (Number.isFinite(percent)) {
|
|
156
|
+
progressBar.style.width = `${Math.max(4, Math.min(100, percent))}%`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
108
160
|
};
|
|
109
161
|
|
|
110
162
|
globalThis.__threeRbBootFailed = (message) => {
|
|
@@ -121,12 +173,12 @@
|
|
|
121
173
|
});
|
|
122
174
|
|
|
123
175
|
globalThis.setTimeout(() => {
|
|
124
|
-
if (status &&
|
|
125
|
-
status.textContent = "Still loading
|
|
176
|
+
if (status && statusDot && statusDot.dataset.state === "loading") {
|
|
177
|
+
status.textContent = "Still loading after 15 seconds. Try reloading the page.";
|
|
126
178
|
}
|
|
127
179
|
}, 15000);
|
|
128
180
|
|
|
129
|
-
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading");
|
|
181
|
+
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading", 4);
|
|
130
182
|
</script>
|
|
131
183
|
<script type="module" src="./boot.mjs"></script>
|
|
132
184
|
</head>
|
|
@@ -134,8 +186,11 @@
|
|
|
134
186
|
<main class="viewport" id="viewport">
|
|
135
187
|
<canvas id="scene" data-testid="scene-canvas"></canvas>
|
|
136
188
|
<div class="hud" aria-live="polite">
|
|
137
|
-
<span class="status-dot" id="status-dot"></span>
|
|
189
|
+
<span class="status-dot" id="status-dot" data-state="loading"></span>
|
|
138
190
|
<span id="status" data-testid="status">Loading ruby.wasm</span>
|
|
191
|
+
<div class="progress" id="progress" aria-hidden="true">
|
|
192
|
+
<div class="progress-bar" id="progress-bar"></div>
|
|
193
|
+
</div>
|
|
139
194
|
</div>
|
|
140
195
|
</main>
|
|
141
196
|
</body>
|
|
@@ -54,10 +54,12 @@
|
|
|
54
54
|
position: absolute;
|
|
55
55
|
top: 16px;
|
|
56
56
|
left: 16px;
|
|
57
|
-
display:
|
|
57
|
+
display: grid;
|
|
58
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
58
59
|
align-items: center;
|
|
59
60
|
gap: 8px;
|
|
60
61
|
max-width: calc(100% - 32px);
|
|
62
|
+
min-width: min(360px, calc(100% - 32px));
|
|
61
63
|
padding: 8px 10px;
|
|
62
64
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
63
65
|
border-radius: 6px;
|
|
@@ -87,6 +89,44 @@
|
|
|
87
89
|
background: #f15b5b;
|
|
88
90
|
box-shadow: 0 0 14px rgba(241, 91, 91, 0.72);
|
|
89
91
|
}
|
|
92
|
+
|
|
93
|
+
.status-dot[data-state="loading"] {
|
|
94
|
+
animation: status-dot-pulse 1.2s ease-in-out infinite;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@keyframes status-dot-pulse {
|
|
98
|
+
0%,
|
|
99
|
+
100% {
|
|
100
|
+
opacity: 1;
|
|
101
|
+
transform: scale(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
50% {
|
|
105
|
+
opacity: 0.4;
|
|
106
|
+
transform: scale(0.75);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.progress {
|
|
111
|
+
grid-column: 1 / -1;
|
|
112
|
+
width: 100%;
|
|
113
|
+
height: 4px;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
border-radius: 999px;
|
|
116
|
+
background: rgba(255, 255, 255, 0.16);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.progress-bar {
|
|
120
|
+
width: 4%;
|
|
121
|
+
height: 100%;
|
|
122
|
+
border-radius: inherit;
|
|
123
|
+
background: linear-gradient(90deg, #55ace0, #60d394);
|
|
124
|
+
transition: width 180ms ease;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.progress[hidden] {
|
|
128
|
+
display: none;
|
|
129
|
+
}
|
|
90
130
|
</style>
|
|
91
131
|
<script type="importmap">
|
|
92
132
|
{
|
|
@@ -101,10 +141,22 @@
|
|
|
101
141
|
<script type="module">
|
|
102
142
|
const status = document.querySelector("#status");
|
|
103
143
|
const statusDot = document.querySelector("#status-dot");
|
|
144
|
+
const progress = document.querySelector("#progress");
|
|
145
|
+
const progressBar = document.querySelector("#progress-bar");
|
|
104
146
|
|
|
105
|
-
globalThis.__threeRbSetStatus = (message, state) => {
|
|
147
|
+
globalThis.__threeRbSetStatus = (message, state, percent) => {
|
|
106
148
|
if (status) status.textContent = message;
|
|
107
149
|
if (statusDot) statusDot.dataset.state = state;
|
|
150
|
+
if (progress && progressBar) {
|
|
151
|
+
if (state === "running" || state === "error") {
|
|
152
|
+
progress.hidden = true;
|
|
153
|
+
} else {
|
|
154
|
+
progress.hidden = false;
|
|
155
|
+
if (Number.isFinite(percent)) {
|
|
156
|
+
progressBar.style.width = `${Math.max(4, Math.min(100, percent))}%`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
108
160
|
};
|
|
109
161
|
|
|
110
162
|
globalThis.__threeRbBootFailed = (message) => {
|
|
@@ -121,12 +173,12 @@
|
|
|
121
173
|
});
|
|
122
174
|
|
|
123
175
|
globalThis.setTimeout(() => {
|
|
124
|
-
if (status &&
|
|
125
|
-
status.textContent = "Still loading
|
|
176
|
+
if (status && statusDot && statusDot.dataset.state === "loading") {
|
|
177
|
+
status.textContent = "Still loading after 15 seconds. Try reloading the page.";
|
|
126
178
|
}
|
|
127
179
|
}, 15000);
|
|
128
180
|
|
|
129
|
-
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading");
|
|
181
|
+
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading", 4);
|
|
130
182
|
</script>
|
|
131
183
|
</head>
|
|
132
184
|
<body>
|
|
@@ -135,6 +187,9 @@
|
|
|
135
187
|
<div class="hud" aria-live="polite">
|
|
136
188
|
<span id="status-dot" class="status-dot" data-state="loading"></span>
|
|
137
189
|
<span id="status" data-testid="status">Loading ruby.wasm</span>
|
|
190
|
+
<div class="progress" id="progress" aria-hidden="true">
|
|
191
|
+
<div class="progress-bar" id="progress-bar"></div>
|
|
192
|
+
</div>
|
|
138
193
|
</div>
|
|
139
194
|
</main>
|
|
140
195
|
<script type="module" src="./boot.mjs"></script>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# three-rb dango browser example
|
|
2
|
+
|
|
3
|
+
This example renders a Ruby-authored three-color dango scene through ruby.wasm and three.js. It focuses on composing a recognizable 3D object from `SphereGeometry`, `BoxGeometry`, grouped meshes, glossy `MeshPhongMaterial`, lambertian supporting objects, shadows, and `OrbitControls`.
|
|
4
|
+
|
|
5
|
+
## Run
|
|
6
|
+
|
|
7
|
+
From the repository root:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm install
|
|
11
|
+
ruby -run -e httpd . -p 8000
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Open:
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
http://localhost:8000/examples/browser/dango/
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Smoke Test
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pnpm test:browser:dango
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The smoke test serves the repository root, waits for the Ruby scene to reach `Running`, samples the WebGL canvas for nonblank pixels, verifies the three mochi meshes and skewer materialize with the expected geometry and colors, and confirms animation frames are rendered.
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>three-rb dango</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: light;
|
|
10
|
+
font-family:
|
|
11
|
+
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
|
|
12
|
+
"Segoe UI", sans-serif;
|
|
13
|
+
background: #faf5ec;
|
|
14
|
+
color: #263126;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
* {
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
html,
|
|
22
|
+
body {
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 100%;
|
|
25
|
+
margin: 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
body {
|
|
29
|
+
display: grid;
|
|
30
|
+
place-items: stretch;
|
|
31
|
+
overflow: hidden;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.viewport {
|
|
35
|
+
position: relative;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
min-width: 320px;
|
|
39
|
+
min-height: 320px;
|
|
40
|
+
background:
|
|
41
|
+
linear-gradient(rgba(150, 122, 82, 0.045) 1px, transparent 1px),
|
|
42
|
+
linear-gradient(90deg, rgba(150, 122, 82, 0.045) 1px, transparent 1px),
|
|
43
|
+
linear-gradient(135deg, #fff9f1 0%, #f3f6e5 48%, #f4eadb 100%);
|
|
44
|
+
background-size: 34px 34px, 34px 34px, auto;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
canvas {
|
|
48
|
+
display: block;
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: 100%;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.hud {
|
|
54
|
+
position: absolute;
|
|
55
|
+
top: 16px;
|
|
56
|
+
left: 16px;
|
|
57
|
+
display: grid;
|
|
58
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
59
|
+
align-items: center;
|
|
60
|
+
gap: 8px;
|
|
61
|
+
max-width: calc(100% - 32px);
|
|
62
|
+
min-width: min(360px, calc(100% - 32px));
|
|
63
|
+
padding: 8px 10px;
|
|
64
|
+
border: 1px solid rgba(38, 49, 38, 0.12);
|
|
65
|
+
border-radius: 6px;
|
|
66
|
+
background: rgba(255, 252, 245, 0.82);
|
|
67
|
+
box-shadow: 0 12px 30px rgba(83, 64, 39, 0.18);
|
|
68
|
+
color: #263126;
|
|
69
|
+
font-size: 13px;
|
|
70
|
+
line-height: 1.3;
|
|
71
|
+
backdrop-filter: blur(10px);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.status-dot {
|
|
75
|
+
width: 8px;
|
|
76
|
+
height: 8px;
|
|
77
|
+
flex: 0 0 auto;
|
|
78
|
+
border-radius: 999px;
|
|
79
|
+
background: #c08d3d;
|
|
80
|
+
box-shadow: 0 0 14px rgba(192, 141, 61, 0.72);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.status-dot[data-state="running"] {
|
|
84
|
+
background: #6fa35c;
|
|
85
|
+
box-shadow: 0 0 14px rgba(111, 163, 92, 0.72);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.status-dot[data-state="error"] {
|
|
89
|
+
background: #cf554d;
|
|
90
|
+
box-shadow: 0 0 14px rgba(207, 85, 77, 0.72);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.status-dot[data-state="loading"] {
|
|
94
|
+
animation: status-dot-pulse 1.2s ease-in-out infinite;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@keyframes status-dot-pulse {
|
|
98
|
+
0%,
|
|
99
|
+
100% {
|
|
100
|
+
opacity: 1;
|
|
101
|
+
transform: scale(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
50% {
|
|
105
|
+
opacity: 0.4;
|
|
106
|
+
transform: scale(0.75);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.progress {
|
|
111
|
+
grid-column: 1 / -1;
|
|
112
|
+
width: 100%;
|
|
113
|
+
height: 4px;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
border-radius: 999px;
|
|
116
|
+
background: rgba(38, 49, 38, 0.14);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.progress-bar {
|
|
120
|
+
width: 4%;
|
|
121
|
+
height: 100%;
|
|
122
|
+
border-radius: inherit;
|
|
123
|
+
background: linear-gradient(90deg, #55ace0, #6fa35c);
|
|
124
|
+
transition: width 180ms ease;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.progress[hidden] {
|
|
128
|
+
display: none;
|
|
129
|
+
}
|
|
130
|
+
</style>
|
|
131
|
+
<script type="importmap">
|
|
132
|
+
{
|
|
133
|
+
"imports": {
|
|
134
|
+
"@bjorn3/browser_wasi_shim": "/node_modules/@bjorn3/browser_wasi_shim/dist/index.js",
|
|
135
|
+
"@ruby/wasm-wasi/browser": "/node_modules/@ruby/wasm-wasi/dist/esm/browser.js",
|
|
136
|
+
"three": "/node_modules/three/build/three.module.js",
|
|
137
|
+
"three/addons/": "/node_modules/three/examples/jsm/"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
</script>
|
|
141
|
+
<script type="module">
|
|
142
|
+
const status = document.querySelector("#status");
|
|
143
|
+
const statusDot = document.querySelector("#status-dot");
|
|
144
|
+
const progress = document.querySelector("#progress");
|
|
145
|
+
const progressBar = document.querySelector("#progress-bar");
|
|
146
|
+
|
|
147
|
+
globalThis.__threeRbSetStatus = (message, state, percent) => {
|
|
148
|
+
if (status) status.textContent = message;
|
|
149
|
+
if (statusDot) statusDot.dataset.state = state;
|
|
150
|
+
if (progress && progressBar) {
|
|
151
|
+
if (state === "running" || state === "error") {
|
|
152
|
+
progress.hidden = true;
|
|
153
|
+
} else {
|
|
154
|
+
progress.hidden = false;
|
|
155
|
+
if (Number.isFinite(percent)) {
|
|
156
|
+
progressBar.style.width = `${Math.max(4, Math.min(100, percent))}%`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
globalThis.__threeRbBootFailed = (message) => {
|
|
163
|
+
globalThis.__threeRbSetStatus(message, "error");
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
globalThis.addEventListener("error", (event) => {
|
|
167
|
+
globalThis.__threeRbBootFailed(event.message || "Browser error");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
globalThis.addEventListener("unhandledrejection", (event) => {
|
|
171
|
+
const reason = event.reason;
|
|
172
|
+
globalThis.__threeRbBootFailed(reason && reason.message ? reason.message : "Ruby boot failed");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
globalThis.setTimeout(() => {
|
|
176
|
+
if (status && statusDot && statusDot.dataset.state === "loading") {
|
|
177
|
+
status.textContent = "Still loading after 15 seconds. Try reloading the page.";
|
|
178
|
+
}
|
|
179
|
+
}, 15000);
|
|
180
|
+
|
|
181
|
+
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading", 4);
|
|
182
|
+
</script>
|
|
183
|
+
<script type="module" src="./boot.mjs"></script>
|
|
184
|
+
</head>
|
|
185
|
+
<body>
|
|
186
|
+
<main class="viewport" id="viewport">
|
|
187
|
+
<canvas id="scene" data-testid="scene-canvas"></canvas>
|
|
188
|
+
<div class="hud" aria-live="polite">
|
|
189
|
+
<span class="status-dot" id="status-dot" data-state="loading"></span>
|
|
190
|
+
<span id="status" data-testid="status">Loading ruby.wasm</span>
|
|
191
|
+
<div class="progress" id="progress" aria-hidden="true">
|
|
192
|
+
<div class="progress-bar" id="progress-bar"></div>
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
</main>
|
|
196
|
+
</body>
|
|
197
|
+
</html>
|