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
|
@@ -345,7 +345,10 @@ module Three
|
|
|
345
345
|
texture[:matrixAutoUpdate] = parameters[:matrix_auto_update] unless parameters[:matrix_auto_update].nil?
|
|
346
346
|
texture[:matrix].call(:fromArray, js_array(parameters[:matrix])) if parameters[:matrix]
|
|
347
347
|
texture.call(:updateMatrix) if parameters[:matrix_auto_update]
|
|
348
|
-
texture
|
|
348
|
+
# A loader texture has no image until its file arrives, and three.js
|
|
349
|
+
# warns on every frame it is flagged before then. The loader flags it
|
|
350
|
+
# once the image is in, and the upload reads the settings above.
|
|
351
|
+
texture[:needsUpdate] = true if js_present?(texture[:image])
|
|
349
352
|
texture
|
|
350
353
|
end
|
|
351
354
|
|
|
@@ -562,7 +565,10 @@ module Three
|
|
|
562
565
|
end
|
|
563
566
|
|
|
564
567
|
def new_mesh_toon_material(parameters)
|
|
565
|
-
|
|
568
|
+
# MeshToonMaterial doesn't declare flatShading, so its constructor
|
|
569
|
+
# warns and drops it. The renderer still reads flatShading on any
|
|
570
|
+
# material, so update_material assigns it directly instead.
|
|
571
|
+
material = @three[:MeshToonMaterial].new(stringify_keys(parameters.except(:flatShading)))
|
|
566
572
|
update_material(material, parameters)
|
|
567
573
|
material
|
|
568
574
|
end
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "fileutils"
|
|
4
|
-
|
|
4
|
+
# Ruby 4.0 keeps only the escape helpers of the cgi library.
|
|
5
|
+
require "cgi/escape"
|
|
5
6
|
require "json"
|
|
6
7
|
require "pathname"
|
|
8
|
+
require "set"
|
|
9
|
+
require "yaml"
|
|
7
10
|
|
|
8
11
|
module Three
|
|
9
12
|
module Generators
|
|
@@ -56,14 +59,95 @@ module Three
|
|
|
56
59
|
end
|
|
57
60
|
|
|
58
61
|
def copy_runtime
|
|
59
|
-
|
|
60
|
-
copy_file(runtime_path("pnpm-lock.yaml"), File.join(@root, "pnpm-lock.yaml"), overwrite: false)
|
|
62
|
+
write_app_package
|
|
61
63
|
copy_tree(runtime_path("lib"), File.join(@root, "lib"), overwrite: false)
|
|
62
64
|
copy_file(
|
|
63
65
|
runtime_path("examples/browser/shared/boot.mjs"),
|
|
64
66
|
File.join(File.dirname(@target), "shared", "boot.mjs"),
|
|
65
67
|
overwrite: @force
|
|
66
68
|
)
|
|
69
|
+
# boot.mjs imports the wasm URL from here. Apps may point it at their
|
|
70
|
+
# own host, so an existing copy is kept even with --force.
|
|
71
|
+
copy_file(
|
|
72
|
+
runtime_path("examples/browser/shared/config.mjs"),
|
|
73
|
+
File.join(File.dirname(@target), "shared", "config.mjs"),
|
|
74
|
+
overwrite: false
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# The gem's own package.json also lists its test and deploy tooling, and
|
|
79
|
+
# pnpm refuses to install that tooling without the gem's
|
|
80
|
+
# pnpm-workspace.yaml. Apps only need the browser runtime packages.
|
|
81
|
+
def write_app_package
|
|
82
|
+
package_path = File.join(@root, "package.json")
|
|
83
|
+
package = app_package_json
|
|
84
|
+
write_runtime_file(package_path, package)
|
|
85
|
+
|
|
86
|
+
# A lockfile written next to someone else's package.json would not
|
|
87
|
+
# match it, and pnpm rejects a mismatched lockfile in CI.
|
|
88
|
+
return unless File.read(package_path) == package
|
|
89
|
+
|
|
90
|
+
lockfile = app_lockfile
|
|
91
|
+
write_runtime_file(File.join(@root, "pnpm-lock.yaml"), lockfile) if lockfile
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def app_package_json
|
|
95
|
+
package = JSON.parse(File.read(runtime_path("package.json")))
|
|
96
|
+
app = {
|
|
97
|
+
"private" => true,
|
|
98
|
+
"packageManager" => package.fetch("packageManager"),
|
|
99
|
+
"dependencies" => package.fetch("dependencies")
|
|
100
|
+
}
|
|
101
|
+
"#{JSON.pretty_generate(app)}\n"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Keeps the entries the runtime dependencies reach, so the app gets the
|
|
105
|
+
# versions and integrity hashes the gem was tested with.
|
|
106
|
+
def app_lockfile
|
|
107
|
+
source = File.read(runtime_path("pnpm-lock.yaml"))
|
|
108
|
+
return unless YAML.parse_stream(source).children.length == 1
|
|
109
|
+
|
|
110
|
+
lockfile = YAML.safe_load(source)
|
|
111
|
+
importer = lockfile.dig("importers", ".")
|
|
112
|
+
return unless importer
|
|
113
|
+
|
|
114
|
+
importer.delete("devDependencies")
|
|
115
|
+
snapshots = lockfile.fetch("snapshots", {})
|
|
116
|
+
reachable = reachable_snapshots(snapshots, importer.fetch("dependencies", {}))
|
|
117
|
+
# Snapshot keys may carry a peer suffix, as in "name@1.0.0(peer@2.0.0)".
|
|
118
|
+
packages = reachable.to_set { |key| key.sub(/\(.*\z/, "") }
|
|
119
|
+
lockfile["packages"] = lockfile.fetch("packages", {}).select { |key, _value| packages.include?(key) }
|
|
120
|
+
lockfile["snapshots"] = snapshots.select { |key, _value| reachable.include?(key) }
|
|
121
|
+
|
|
122
|
+
# pnpm reads a leading document marker as an empty first document and
|
|
123
|
+
# then reports the lockfile as missing.
|
|
124
|
+
YAML.dump(lockfile).delete_prefix("---\n")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def reachable_snapshots(snapshots, dependencies)
|
|
128
|
+
pending = dependencies.map { |name, dependency| "#{name}@#{dependency.fetch("version")}" }
|
|
129
|
+
reachable = Set.new
|
|
130
|
+
until pending.empty?
|
|
131
|
+
key = pending.shift
|
|
132
|
+
next unless reachable.add?(key)
|
|
133
|
+
|
|
134
|
+
snapshot = snapshots.fetch(key, nil) || {}
|
|
135
|
+
%w[dependencies optionalDependencies].each do |field|
|
|
136
|
+
snapshot.fetch(field, {}).each { |name, version| pending << "#{name}@#{version}" }
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
reachable
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def write_runtime_file(path, content)
|
|
143
|
+
if File.exist?(path)
|
|
144
|
+
@skipped << relative_path(path)
|
|
145
|
+
return
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
149
|
+
File.write(path, content)
|
|
150
|
+
@created << relative_path(path)
|
|
67
151
|
end
|
|
68
152
|
|
|
69
153
|
def write_example_files
|
|
@@ -82,7 +166,7 @@ module Three
|
|
|
82
166
|
"index.html" => "index.html",
|
|
83
167
|
"boot.mjs" => "boot.mjs",
|
|
84
168
|
"main.rb" => "main.rb",
|
|
85
|
-
"assets/
|
|
169
|
+
"assets/helvetiker_regular.typeface.json" => "assets/helvetiker_regular.typeface.json"
|
|
86
170
|
}.each do |source_name, destination_name|
|
|
87
171
|
copy_generated_file(
|
|
88
172
|
runtime_path(File.join("examples/browser/ruby", source_name)),
|
|
@@ -167,7 +251,7 @@ module Three
|
|
|
167
251
|
|
|
168
252
|
def example_files
|
|
169
253
|
names = %w[index.html boot.mjs main.rb README.md]
|
|
170
|
-
names << "assets/
|
|
254
|
+
names << "assets/helvetiker_regular.typeface.json" if ruby_example?
|
|
171
255
|
names.map { |name| example_path(name) }
|
|
172
256
|
end
|
|
173
257
|
|
|
@@ -238,9 +322,11 @@ module Three
|
|
|
238
322
|
position: absolute;
|
|
239
323
|
top: 16px;
|
|
240
324
|
left: 16px;
|
|
241
|
-
display:
|
|
325
|
+
display: grid;
|
|
326
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
242
327
|
align-items: center;
|
|
243
328
|
gap: 8px;
|
|
329
|
+
min-width: min(360px, calc(100% - 32px));
|
|
244
330
|
padding: 8px 10px;
|
|
245
331
|
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
246
332
|
border-radius: 6px;
|
|
@@ -257,6 +343,27 @@ module Three
|
|
|
257
343
|
}
|
|
258
344
|
.status-dot[data-state="running"] { background: #4ed08f; }
|
|
259
345
|
.status-dot[data-state="error"] { background: #f15b5b; }
|
|
346
|
+
.status-dot[data-state="loading"] { animation: status-dot-pulse 1.2s ease-in-out infinite; }
|
|
347
|
+
@keyframes status-dot-pulse {
|
|
348
|
+
0%, 100% { opacity: 1; transform: scale(1); }
|
|
349
|
+
50% { opacity: 0.4; transform: scale(0.75); }
|
|
350
|
+
}
|
|
351
|
+
.progress {
|
|
352
|
+
grid-column: 1 / -1;
|
|
353
|
+
width: 100%;
|
|
354
|
+
height: 4px;
|
|
355
|
+
overflow: hidden;
|
|
356
|
+
border-radius: 999px;
|
|
357
|
+
background: rgba(255, 255, 255, 0.16);
|
|
358
|
+
}
|
|
359
|
+
.progress-bar {
|
|
360
|
+
width: 4%;
|
|
361
|
+
height: 100%;
|
|
362
|
+
border-radius: inherit;
|
|
363
|
+
background: linear-gradient(90deg, #55ace0, #4ed08f);
|
|
364
|
+
transition: width 180ms ease;
|
|
365
|
+
}
|
|
366
|
+
.progress[hidden] { display: none; }
|
|
260
367
|
</style>
|
|
261
368
|
<script type="importmap">
|
|
262
369
|
{
|
|
@@ -271,10 +378,22 @@ module Three
|
|
|
271
378
|
<script type="module">
|
|
272
379
|
const status = document.querySelector("#status");
|
|
273
380
|
const statusDot = document.querySelector("#status-dot");
|
|
381
|
+
const progress = document.querySelector("#progress");
|
|
382
|
+
const progressBar = document.querySelector("#progress-bar");
|
|
274
383
|
|
|
275
|
-
globalThis.__threeRbSetStatus = (message, state) => {
|
|
384
|
+
globalThis.__threeRbSetStatus = (message, state, percent) => {
|
|
276
385
|
if (status) status.textContent = message;
|
|
277
386
|
if (statusDot) statusDot.dataset.state = state;
|
|
387
|
+
if (progress && progressBar) {
|
|
388
|
+
if (state === "running" || state === "error") {
|
|
389
|
+
progress.hidden = true;
|
|
390
|
+
} else {
|
|
391
|
+
progress.hidden = false;
|
|
392
|
+
if (Number.isFinite(percent)) {
|
|
393
|
+
progressBar.style.width = `${Math.max(4, Math.min(100, percent))}%`;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
278
397
|
};
|
|
279
398
|
globalThis.__threeRbBootFailed = (message) => globalThis.__threeRbSetStatus(message, "error");
|
|
280
399
|
globalThis.addEventListener("error", (event) => globalThis.__threeRbBootFailed(event.message || "Browser error"));
|
|
@@ -282,7 +401,12 @@ module Three
|
|
|
282
401
|
const reason = event.reason;
|
|
283
402
|
globalThis.__threeRbBootFailed(reason && reason.message ? reason.message : "Ruby boot failed");
|
|
284
403
|
});
|
|
285
|
-
globalThis.
|
|
404
|
+
globalThis.setTimeout(() => {
|
|
405
|
+
if (status && statusDot && statusDot.dataset.state === "loading") {
|
|
406
|
+
status.textContent = "Still loading after 15 seconds. Try reloading the page.";
|
|
407
|
+
}
|
|
408
|
+
}, 15000);
|
|
409
|
+
globalThis.__threeRbSetStatus("Loading ruby.wasm", "loading", 4);
|
|
286
410
|
</script>
|
|
287
411
|
<script type="module" src="./boot.mjs"></script>
|
|
288
412
|
</head>
|
|
@@ -290,8 +414,11 @@ module Three
|
|
|
290
414
|
<main id="viewport">
|
|
291
415
|
<canvas id="scene" data-testid="scene-canvas"></canvas>
|
|
292
416
|
<div class="hud" aria-live="polite">
|
|
293
|
-
<span class="status-dot" id="status-dot"></span>
|
|
417
|
+
<span class="status-dot" id="status-dot" data-state="loading"></span>
|
|
294
418
|
<span id="status" data-testid="status">Loading ruby.wasm</span>
|
|
419
|
+
<div class="progress" id="progress" aria-hidden="true">
|
|
420
|
+
<div class="progress-bar" id="progress-bar"></div>
|
|
421
|
+
</div>
|
|
295
422
|
</div>
|
|
296
423
|
</main>
|
|
297
424
|
</body>
|
data/lib/three/version.rb
CHANGED
data/package.json
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"packageManager": "pnpm@11.1.1",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"build:pages:ruby": "sh scripts/build-pages-ruby.sh",
|
|
8
|
+
"test:browser": "pnpm test:browser:ruby && pnpm test:browser:cube && pnpm test:browser:dango && pnpm test:browser:composition && pnpm test:browser:textures && pnpm test:browser:cubemap && pnpm test:browser:gltf && pnpm test:browser:serialization && pnpm test:browser:picking && pnpm test:browser:primitives && pnpm test:browser:postprocessing && pnpm test:browser:generated",
|
|
8
9
|
"test:browser:ruby": "node examples/browser/ruby/smoke_test.mjs",
|
|
9
10
|
"test:browser:cube": "node examples/browser/cube/smoke_test.mjs",
|
|
11
|
+
"test:browser:dango": "node examples/browser/dango/smoke_test.mjs",
|
|
10
12
|
"test:browser:composition": "node examples/browser/composition/smoke_test.mjs",
|
|
11
13
|
"test:browser:textures": "node examples/browser/textures/smoke_test.mjs",
|
|
12
14
|
"test:browser:cubemap": "node examples/browser/cubemap/smoke_test.mjs",
|
|
@@ -15,17 +17,19 @@
|
|
|
15
17
|
"test:browser:picking": "node examples/browser/picking/smoke_test.mjs",
|
|
16
18
|
"test:browser:primitives": "node examples/browser/primitives/smoke_test.mjs",
|
|
17
19
|
"test:browser:postprocessing": "node examples/browser/postprocessing/smoke_test.mjs",
|
|
20
|
+
"test:browser:generated": "node test/browser/generated_apps_smoke_test.mjs",
|
|
18
21
|
"benchmark:browser": "pnpm benchmark:browser:mesh-sync && pnpm benchmark:browser:instanced-mesh-sync",
|
|
19
22
|
"benchmark:browser:mesh-sync": "node benchmarks/browser/mesh_sync/run.mjs",
|
|
20
23
|
"benchmark:browser:instanced-mesh-sync": "node benchmarks/browser/instanced_mesh_sync/run.mjs"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
23
26
|
"@bjorn3/browser_wasi_shim": "0.4.2",
|
|
24
|
-
"@ruby/3.4-wasm-wasi": "2.
|
|
25
|
-
"@ruby/wasm-wasi": "2.
|
|
26
|
-
"three": "0.
|
|
27
|
+
"@ruby/3.4-wasm-wasi": "2.10.1",
|
|
28
|
+
"@ruby/wasm-wasi": "2.10.1",
|
|
29
|
+
"three": "0.187.0"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
|
-
"playwright": "^1.
|
|
32
|
+
"playwright": "^1.65.1",
|
|
33
|
+
"wrangler": "^4.165.0"
|
|
30
34
|
}
|
|
31
35
|
}
|