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
|
@@ -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(84, 105, 130, 0.18);
|
|
63
65
|
border-radius: 6px;
|
|
@@ -79,14 +81,95 @@
|
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
.status-dot[data-state="running"] {
|
|
82
|
-
background: #
|
|
83
|
-
box-shadow: 0 0 14px rgba(
|
|
84
|
+
background: #2fae66;
|
|
85
|
+
box-shadow: 0 0 14px rgba(47, 174, 102, 0.72);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
.status-dot[data-state="error"] {
|
|
87
89
|
background: #d64040;
|
|
88
90
|
box-shadow: 0 0 14px rgba(214, 64, 64, 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(84, 105, 130, 0.16);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.progress-bar {
|
|
120
|
+
width: 4%;
|
|
121
|
+
height: 100%;
|
|
122
|
+
border-radius: inherit;
|
|
123
|
+
background: linear-gradient(90deg, #55ace0, #2fae66);
|
|
124
|
+
transition: width 180ms ease;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.progress[hidden] {
|
|
128
|
+
display: none;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.repo-link {
|
|
132
|
+
position: absolute;
|
|
133
|
+
top: 16px;
|
|
134
|
+
right: 16px;
|
|
135
|
+
display: inline-flex;
|
|
136
|
+
align-items: center;
|
|
137
|
+
gap: 7px;
|
|
138
|
+
min-height: 36px;
|
|
139
|
+
padding: 8px 10px;
|
|
140
|
+
border: 1px solid rgba(84, 105, 130, 0.18);
|
|
141
|
+
border-radius: 6px;
|
|
142
|
+
background: rgba(255, 255, 255, 0.82);
|
|
143
|
+
box-shadow: 0 14px 34px rgba(53, 72, 94, 0.16);
|
|
144
|
+
color: #243142;
|
|
145
|
+
font-size: 13px;
|
|
146
|
+
font-weight: 600;
|
|
147
|
+
line-height: 1;
|
|
148
|
+
text-decoration: none;
|
|
149
|
+
backdrop-filter: blur(10px);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.repo-link:hover,
|
|
153
|
+
.repo-link:focus-visible {
|
|
154
|
+
border-color: rgba(207, 23, 72, 0.38);
|
|
155
|
+
color: #cf1748;
|
|
156
|
+
outline: none;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.repo-link svg {
|
|
160
|
+
width: 18px;
|
|
161
|
+
height: 18px;
|
|
162
|
+
flex: 0 0 auto;
|
|
163
|
+
fill: currentColor;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@media (max-width: 560px) {
|
|
167
|
+
.repo-link {
|
|
168
|
+
top: auto;
|
|
169
|
+
right: 16px;
|
|
170
|
+
bottom: 16px;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
90
173
|
</style>
|
|
91
174
|
<script type="importmap">
|
|
92
175
|
{
|
|
@@ -101,10 +184,22 @@
|
|
|
101
184
|
<script type="module">
|
|
102
185
|
const status = document.querySelector("#status");
|
|
103
186
|
const statusDot = document.querySelector("#status-dot");
|
|
187
|
+
const progress = document.querySelector("#progress");
|
|
188
|
+
const progressBar = document.querySelector("#progress-bar");
|
|
104
189
|
|
|
105
|
-
globalThis.__threeRbSetStatus = (message, state) => {
|
|
190
|
+
globalThis.__threeRbSetStatus = (message, state, percent) => {
|
|
106
191
|
if (status) status.textContent = message;
|
|
107
192
|
if (statusDot) statusDot.dataset.state = state;
|
|
193
|
+
if (progress && progressBar) {
|
|
194
|
+
if (state === "running" || state === "error") {
|
|
195
|
+
progress.hidden = true;
|
|
196
|
+
} else {
|
|
197
|
+
progress.hidden = false;
|
|
198
|
+
if (Number.isFinite(percent)) {
|
|
199
|
+
progressBar.style.width = `${Math.max(4, Math.min(100, percent))}%`;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
108
203
|
};
|
|
109
204
|
|
|
110
205
|
globalThis.__threeRbBootFailed = (message) => {
|
|
@@ -121,12 +216,12 @@
|
|
|
121
216
|
});
|
|
122
217
|
|
|
123
218
|
globalThis.setTimeout(() => {
|
|
124
|
-
if (status &&
|
|
125
|
-
status.textContent = "Still loading
|
|
219
|
+
if (status && statusDot && statusDot.dataset.state === "loading") {
|
|
220
|
+
status.textContent = "Still loading after 15 seconds. Try reloading the page.";
|
|
126
221
|
}
|
|
127
222
|
}, 15000);
|
|
128
223
|
|
|
129
|
-
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading");
|
|
224
|
+
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading", 4);
|
|
130
225
|
</script>
|
|
131
226
|
<script type="module" src="./boot.mjs"></script>
|
|
132
227
|
</head>
|
|
@@ -134,9 +229,18 @@
|
|
|
134
229
|
<main class="viewport" id="viewport">
|
|
135
230
|
<canvas id="scene" data-testid="scene-canvas"></canvas>
|
|
136
231
|
<div class="hud" aria-live="polite">
|
|
137
|
-
<span class="status-dot" id="status-dot"></span>
|
|
232
|
+
<span class="status-dot" id="status-dot" data-state="loading"></span>
|
|
138
233
|
<span id="status" data-testid="status">Loading ruby.wasm</span>
|
|
234
|
+
<div class="progress" id="progress" aria-hidden="true">
|
|
235
|
+
<div class="progress-bar" id="progress-bar"></div>
|
|
236
|
+
</div>
|
|
139
237
|
</div>
|
|
238
|
+
<a class="repo-link" href="https://github.com/lef237/three.rb" target="_blank" rel="noopener noreferrer" aria-label="Open GitHub repository">
|
|
239
|
+
<svg viewBox="0 0 16 16" aria-hidden="true">
|
|
240
|
+
<path d="M8 0C3.58 0 0 3.67 0 8.2c0 3.62 2.29 6.69 5.47 7.78.4.08.55-.18.55-.4 0-.2-.01-.85-.01-1.54-2.01.38-2.53-.5-2.69-.96-.09-.24-.48-.98-.82-1.18-.28-.15-.68-.53-.01-.54.63-.01 1.08.59 1.23.84.72 1.24 1.87.89 2.33.68.07-.53.28-.89.51-1.09-1.78-.21-3.64-.91-3.64-4.04 0-.89.31-1.63.82-2.2-.08-.21-.36-1.04.08-2.17 0 0 .67-.22 2.2.84A7.43 7.43 0 0 1 8 3.94c.68 0 1.36.09 2 .28 1.53-1.06 2.2-.84 2.2-.84.44 1.13.16 1.96.08 2.17.51.57.82 1.3.82 2.2 0 3.14-1.87 3.83-3.65 4.04.29.26.54.75.54 1.52 0 1.09-.01 1.97-.01 2.24 0 .22.15.48.55.4A8.17 8.17 0 0 0 16 8.2C16 3.67 12.42 0 8 0Z"></path>
|
|
241
|
+
</svg>
|
|
242
|
+
GitHub
|
|
243
|
+
</a>
|
|
140
244
|
</main>
|
|
141
245
|
</body>
|
|
142
246
|
</html>
|
|
@@ -106,9 +106,6 @@ Three::Browser.run(starting: "Starting Ruby scene") do |app|
|
|
|
106
106
|
camera = Three::PerspectiveCamera.new(42, aspect: 1.0, near: 0.1, far: 100)
|
|
107
107
|
camera.position.set(0, 0.42, 6.9)
|
|
108
108
|
|
|
109
|
-
environment_texture = Three::Loaders::RGBELoader.new.load("/examples/browser/ruby/assets/studio.hdr")
|
|
110
|
-
scene.environment = environment_texture
|
|
111
|
-
|
|
112
109
|
scene.add(Three::AmbientLight.new(0xffffff, 0.82))
|
|
113
110
|
scene.add(Three::HemisphereLight.new(0xffffff, 0xffedf2, 1.0))
|
|
114
111
|
|
|
@@ -198,7 +195,7 @@ Three::Browser.run(starting: "Starting Ruby scene") do |app|
|
|
|
198
195
|
[sparkle, phase, size]
|
|
199
196
|
end
|
|
200
197
|
|
|
201
|
-
title_font = Three::Loaders::FontLoader.new.load("/
|
|
198
|
+
title_font = Three::Loaders::FontLoader.new.load("/examples/browser/ruby/assets/helvetiker_regular.typeface.json")
|
|
202
199
|
title_geometry = Three::TextGeometry.new(
|
|
203
200
|
"three-rb",
|
|
204
201
|
font: title_font,
|
|
@@ -238,7 +235,7 @@ Three::Browser.run(starting: "Starting Ruby scene") do |app|
|
|
|
238
235
|
alpha: false,
|
|
239
236
|
preserveDrawingBuffer: true,
|
|
240
237
|
shadow_map_enabled: true,
|
|
241
|
-
shadow_map_type: Three::
|
|
238
|
+
shadow_map_type: Three::PCFShadowMap
|
|
242
239
|
)
|
|
243
240
|
renderer.set_clear_color(0xffffff, 1)
|
|
244
241
|
renderer.tone_mapping = Three::ACESFilmicToneMapping
|
|
@@ -273,7 +270,6 @@ Three::Browser.run(starting: "Starting Ruby scene") do |app|
|
|
|
273
270
|
ruby_title_geometry: title_geometry,
|
|
274
271
|
ruby_title_material: title_material,
|
|
275
272
|
ruby_sparkles: sparkles.map(&:first),
|
|
276
|
-
ruby_environment: environment_texture,
|
|
277
273
|
ruby_font_loaded: true,
|
|
278
274
|
ruby_frame: 0
|
|
279
275
|
},
|
|
@@ -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>
|
|
@@ -11,13 +11,17 @@ import { RenderPass } from "three/addons/postprocessing/RenderPass.js";
|
|
|
11
11
|
import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js";
|
|
12
12
|
import { DotScreenPass } from "three/addons/postprocessing/DotScreenPass.js";
|
|
13
13
|
import { OutputPass } from "three/addons/postprocessing/OutputPass.js";
|
|
14
|
+
import { rubyWasmUrl } from "./config.mjs";
|
|
15
|
+
|
|
16
|
+
const WASM_DOWNLOAD_ATTEMPTS = 3;
|
|
17
|
+
const WASM_STALL_TIMEOUT_MS = 20000;
|
|
14
18
|
|
|
15
19
|
export async function bootRubyExample({ main, clearColor }) {
|
|
16
20
|
const setStatus = globalThis.__threeRbSetStatus || (() => {});
|
|
17
21
|
const bootFailed = globalThis.__threeRbBootFailed || ((message) => console.error(message));
|
|
18
22
|
|
|
19
23
|
try {
|
|
20
|
-
setStatus("
|
|
24
|
+
setStatus("Preparing browser runtime", "loading", 4);
|
|
21
25
|
globalThis.THREE = THREE;
|
|
22
26
|
globalThis.THREE_GLTF_LOADER = GLTFLoader;
|
|
23
27
|
globalThis.THREE_DRACO_LOADER = DRACOLoader;
|
|
@@ -49,11 +53,16 @@ export async function bootRubyExample({ main, clearColor }) {
|
|
|
49
53
|
composer.render();
|
|
50
54
|
};
|
|
51
55
|
|
|
52
|
-
const rubyModule = await compileWasm(
|
|
56
|
+
const rubyModule = await compileWasm(rubyWasmUrl, {
|
|
57
|
+
onProgress: (percent) => setStatus(`Loading ruby.wasm ${percent}%`, "loading", percent),
|
|
58
|
+
onRetry: (attempt, attempts) =>
|
|
59
|
+
setStatus(`Retrying ruby.wasm download (${attempt}/${attempts})`, "loading", 4)
|
|
60
|
+
});
|
|
61
|
+
setStatus("Compiling ruby.wasm", "loading", 82);
|
|
53
62
|
const { vm } = await DefaultRubyVM(rubyModule);
|
|
54
63
|
globalThis.rubyVM = vm;
|
|
55
64
|
|
|
56
|
-
setStatus("Starting Ruby VM", "loading");
|
|
65
|
+
setStatus("Starting Ruby VM", "loading", 88);
|
|
57
66
|
await withNoStoreRubySourceFetch(async () => {
|
|
58
67
|
await vm.evalAsync(`
|
|
59
68
|
require "js/require_remote/relative_shim"
|
|
@@ -93,19 +102,112 @@ function shouldBypassCache(input) {
|
|
|
93
102
|
return !pathname.includes("/assets/");
|
|
94
103
|
}
|
|
95
104
|
|
|
96
|
-
async function compileWasm(url) {
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
async function compileWasm(url, { onProgress = () => {}, onRetry = () => {} } = {}) {
|
|
106
|
+
let lastError;
|
|
107
|
+
|
|
108
|
+
for (let attempt = 1; attempt <= WASM_DOWNLOAD_ATTEMPTS; attempt += 1) {
|
|
109
|
+
if (attempt > 1) onRetry(attempt, WASM_DOWNLOAD_ATTEMPTS);
|
|
110
|
+
|
|
99
111
|
try {
|
|
100
|
-
return await
|
|
101
|
-
} catch (
|
|
102
|
-
|
|
112
|
+
return await compileWasmOnce(url, onProgress);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
lastError = error;
|
|
103
115
|
}
|
|
104
116
|
}
|
|
105
117
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
const reason = lastError && lastError.message ? lastError.message : "Failed to load ruby.wasm";
|
|
119
|
+
|
|
120
|
+
throw new Error(`${reason}. Try reloading the page.`, { cause: lastError });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function compileWasmOnce(url, onProgress) {
|
|
124
|
+
const controller = new AbortController();
|
|
125
|
+
const stall = watchForStall(controller, WASM_STALL_TIMEOUT_MS);
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
throw new Error(`Failed to load ruby.wasm: ${response.status} ${response.statusText}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Decide before reading the body. Falling back after the download has
|
|
134
|
+
// started would fetch the whole file a second time.
|
|
135
|
+
const canStream =
|
|
136
|
+
typeof WebAssembly.compileStreaming === "function" &&
|
|
137
|
+
(response.headers.get("content-type") || "").includes("application/wasm");
|
|
138
|
+
const tracked = trackDownload(response, {
|
|
139
|
+
onProgress: (percent) => {
|
|
140
|
+
stall.reset();
|
|
141
|
+
if (percent !== null) onProgress(percent);
|
|
142
|
+
},
|
|
143
|
+
onSettled: () => stall.cancel()
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (canStream) return await WebAssembly.compileStreaming(tracked);
|
|
147
|
+
|
|
148
|
+
return await WebAssembly.compile(await tracked.arrayBuffer());
|
|
149
|
+
} finally {
|
|
150
|
+
stall.cancel();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// A download that stops mid-stream never rejects on its own, which left the
|
|
155
|
+
// status line stuck on "Loading ruby.wasm" with nothing to retry it.
|
|
156
|
+
function watchForStall(controller, timeout) {
|
|
157
|
+
let cancelled = false;
|
|
158
|
+
let timer = globalThis.setTimeout(abort, timeout);
|
|
159
|
+
|
|
160
|
+
function abort() {
|
|
161
|
+
controller.abort(new Error(`ruby.wasm stopped downloading for ${Math.round(timeout / 1000)} seconds`));
|
|
109
162
|
}
|
|
110
|
-
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
reset() {
|
|
166
|
+
if (cancelled) return;
|
|
167
|
+
|
|
168
|
+
globalThis.clearTimeout(timer);
|
|
169
|
+
timer = globalThis.setTimeout(abort, timeout);
|
|
170
|
+
},
|
|
171
|
+
cancel() {
|
|
172
|
+
cancelled = true;
|
|
173
|
+
globalThis.clearTimeout(timer);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function trackDownload(response, { onProgress, onSettled }) {
|
|
179
|
+
if (!response.body) {
|
|
180
|
+
onSettled();
|
|
181
|
+
return response;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const total = Number(response.headers.get("content-length"));
|
|
185
|
+
const measurable = Number.isFinite(total) && total > 0;
|
|
186
|
+
let loaded = 0;
|
|
187
|
+
const stream = new ReadableStream({
|
|
188
|
+
async start(controller) {
|
|
189
|
+
const reader = response.body.getReader();
|
|
190
|
+
try {
|
|
191
|
+
while (true) {
|
|
192
|
+
const { done, value } = await reader.read();
|
|
193
|
+
if (done) break;
|
|
194
|
+
|
|
195
|
+
loaded += value.byteLength;
|
|
196
|
+
onProgress(measurable ? Math.min(80, Math.round((loaded / total) * 80)) : null);
|
|
197
|
+
controller.enqueue(value);
|
|
198
|
+
}
|
|
199
|
+
controller.close();
|
|
200
|
+
} catch (error) {
|
|
201
|
+
controller.error(error);
|
|
202
|
+
} finally {
|
|
203
|
+
onSettled();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
return new Response(stream, {
|
|
209
|
+
headers: response.headers,
|
|
210
|
+
status: response.status,
|
|
211
|
+
statusText: response.statusText
|
|
212
|
+
});
|
|
111
213
|
}
|
|
@@ -17,7 +17,7 @@ const mimeTypes = new Map([
|
|
|
17
17
|
]);
|
|
18
18
|
|
|
19
19
|
export function createDiagnostics() {
|
|
20
|
-
return { errors: [], requests: [] };
|
|
20
|
+
return { errors: [], warnings: [], requests: [] };
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export async function loadPlaywright() {
|
|
@@ -35,6 +35,10 @@ export async function createSmokePage(browser, diagnostics, options = {}) {
|
|
|
35
35
|
const page = await browser.newPage({ viewport: options.viewport || { width: 960, height: 540 } });
|
|
36
36
|
page.on("console", (message) => {
|
|
37
37
|
if (message.type() === "error") diagnostics.errors.push(message.text());
|
|
38
|
+
// three.js prefixes its warnings, which flag API misuse such as unknown
|
|
39
|
+
// material properties. Chromium's GPU driver messages are left out: they
|
|
40
|
+
// vary by machine and the canvas readback in these tests triggers them.
|
|
41
|
+
if (message.type() === "warning" && message.text().startsWith("THREE.")) diagnostics.warnings.push(message.text());
|
|
38
42
|
});
|
|
39
43
|
page.on("pageerror", (error) => diagnostics.errors.push(error.message));
|
|
40
44
|
page.on("requestfailed", (request) => {
|
|
@@ -105,7 +109,7 @@ export function assertNonBlankCanvas(canvas) {
|
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
export function assertNoDiagnostics(diagnostics) {
|
|
108
|
-
if (diagnostics.errors.length > 0 || diagnostics.requests.length > 0) {
|
|
112
|
+
if (diagnostics.errors.length > 0 || diagnostics.warnings.length > 0 || diagnostics.requests.length > 0) {
|
|
109
113
|
throw new Error(diagnosticMessage("browser diagnostics", diagnostics));
|
|
110
114
|
}
|
|
111
115
|
}
|
|
@@ -113,15 +117,16 @@ export function assertNoDiagnostics(diagnostics) {
|
|
|
113
117
|
export function diagnosticMessage(message, diagnostics) {
|
|
114
118
|
const sections = [message];
|
|
115
119
|
if (diagnostics.errors.length > 0) sections.push(`console/page errors:\n${diagnostics.errors.join("\n")}`);
|
|
120
|
+
if (diagnostics.warnings.length > 0) sections.push(`three.js warnings:\n${diagnostics.warnings.join("\n")}`);
|
|
116
121
|
if (diagnostics.requests.length > 0) sections.push(`network diagnostics:\n${diagnostics.requests.join("\n")}`);
|
|
117
122
|
return sections.join("\n\n");
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
export function startServer() {
|
|
125
|
+
export function startServer(serverRoot = root) {
|
|
121
126
|
const server = createServer(async (request, response) => {
|
|
122
127
|
try {
|
|
123
128
|
const pathname = decodeURIComponent(new URL(request.url, "http://127.0.0.1").pathname);
|
|
124
|
-
const filePath = await resolveFile(pathname);
|
|
129
|
+
const filePath = await resolveFile(pathname, serverRoot);
|
|
125
130
|
response.setHeader("Content-Type", mimeTypes.get(extname(filePath)) || "application/octet-stream");
|
|
126
131
|
response.end(await readFile(filePath));
|
|
127
132
|
} catch (error) {
|
|
@@ -139,11 +144,11 @@ export function startServer() {
|
|
|
139
144
|
});
|
|
140
145
|
}
|
|
141
146
|
|
|
142
|
-
async function resolveFile(pathname) {
|
|
147
|
+
async function resolveFile(pathname, serverRoot) {
|
|
143
148
|
const requested = pathname.endsWith("/") ? `${pathname}index.html` : pathname;
|
|
144
|
-
const filePath = normalize(join(
|
|
145
|
-
const rel = relative(
|
|
146
|
-
if (rel.startsWith("..")) throw new Error("request escaped
|
|
149
|
+
const filePath = normalize(join(serverRoot, requested));
|
|
150
|
+
const rel = relative(serverRoot, filePath);
|
|
151
|
+
if (rel.startsWith("..")) throw new Error("request escaped server root");
|
|
147
152
|
|
|
148
153
|
const info = await stat(filePath);
|
|
149
154
|
if (info.isDirectory()) return join(filePath, "index.html");
|
|
@@ -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
|
<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>
|
|
@@ -31,7 +31,10 @@ module Three
|
|
|
31
31
|
parameters[:iridescence] = material.iridescence if material.respond_to?(:iridescence)
|
|
32
32
|
parameters[:iridescenceIOR] = material.iridescence_ior if material.respond_to?(:iridescence_ior)
|
|
33
33
|
if material.respond_to?(:iridescence_thickness_range) && material.iridescence_thickness_range
|
|
34
|
-
|
|
34
|
+
# three.js r187 replaced iridescenceThicknessRange with these two properties.
|
|
35
|
+
minimum, maximum = material.iridescence_thickness_range
|
|
36
|
+
parameters[:iridescenceThicknessMinimum] = minimum
|
|
37
|
+
parameters[:iridescenceThicknessMaximum] = maximum
|
|
35
38
|
end
|
|
36
39
|
parameters[:sheen] = material.sheen if material.respond_to?(:sheen)
|
|
37
40
|
parameters[:sheenColor] = material.sheen_color.hex if material.respond_to?(:sheen_color)
|