three-rb 0.2.0 → 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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -2
  3. data/README.md +14 -6
  4. data/docs/browser-runtime.md +10 -6
  5. data/docs/cloudflare-pages.md +205 -0
  6. data/docs/implementation-plan.md +6 -4
  7. data/docs/loaded-assets-design.md +1 -1
  8. data/docs/next-work.md +26 -25
  9. data/docs/publishing.md +4 -1
  10. data/docs/release-readiness.md +11 -11
  11. data/docs/standalone-browser-app.md +8 -2
  12. data/examples/browser/README.md +5 -1
  13. data/examples/browser/composition/index.html +65 -4
  14. data/examples/browser/composition/main.rb +2 -2
  15. data/examples/browser/cube/README.md +3 -3
  16. data/examples/browser/cube/index.html +61 -6
  17. data/examples/browser/cubemap/assets/checker.svg +11 -0
  18. data/examples/browser/cubemap/index.html +60 -5
  19. data/examples/browser/cubemap/main.rb +1 -1
  20. data/examples/browser/dango/README.md +26 -0
  21. data/examples/browser/dango/boot.mjs +6 -0
  22. data/examples/browser/dango/index.html +197 -0
  23. data/examples/browser/dango/main.rb +278 -0
  24. data/examples/browser/dango/smoke_test.mjs +232 -0
  25. data/examples/browser/gltf/index.html +60 -5
  26. data/examples/browser/gltf/main.rb +2 -2
  27. data/examples/browser/picking/index.html +61 -6
  28. data/examples/browser/postprocessing/index.html +61 -6
  29. data/examples/browser/primitives/assets/checker.svg +11 -0
  30. data/examples/browser/primitives/index.html +61 -6
  31. data/examples/browser/primitives/main.rb +1 -1
  32. data/examples/browser/ruby/README.md +2 -0
  33. data/examples/browser/ruby/assets/helvetiker_regular.typeface.json +1 -0
  34. data/examples/browser/ruby/index.html +112 -8
  35. data/examples/browser/ruby/main.rb +2 -6
  36. data/examples/browser/serialization/assets/checker.svg +11 -0
  37. data/examples/browser/serialization/index.html +61 -6
  38. data/examples/browser/serialization/main.rb +1 -1
  39. data/examples/browser/shared/boot.mjs +116 -14
  40. data/examples/browser/shared/config.mjs +3 -0
  41. data/examples/browser/shared/smoke_test_helpers.mjs +13 -8
  42. data/examples/browser/textures/assets/checker.svg +11 -0
  43. data/examples/browser/textures/index.html +61 -6
  44. data/examples/browser/textures/main.rb +2 -2
  45. data/exe/three-rb +1 -0
  46. data/lib/three/backends/threejs/parameters.rb +4 -1
  47. data/lib/three/backends/threejs/ruby_wasm_adapter.rb +8 -2
  48. data/lib/three/generators/browser_example.rb +220 -12
  49. data/lib/three/version.rb +1 -1
  50. data/package.json +9 -5
  51. data/pnpm-lock.yaml +1235 -31
  52. metadata +19 -7
  53. /data/examples/browser/{assets → composition/assets}/checker.svg +0 -0
  54. /data/examples/browser/{assets → gltf/assets}/animated_triangle.gltf +0 -0
  55. /data/examples/browser/{assets → gltf/assets}/compressed_triangle.gltf +0 -0
  56. /data/examples/browser/{assets → gltf/assets}/triangle.gltf +0 -0
  57. /data/examples/browser/{assets → textures/assets}/studio.hdr +0 -0
@@ -54,10 +54,12 @@
54
54
  position: absolute;
55
55
  top: 16px;
56
56
  left: 16px;
57
- display: flex;
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 && status.textContent === "Loading ruby.wasm") {
125
- status.textContent = "Still loading ruby.wasm";
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>
@@ -21,7 +21,7 @@ Three::Browser.run(starting: "Starting Ruby scene") do |app|
21
21
  )
22
22
  renderer.set_clear_color(0x11151a, 1)
23
23
 
24
- gltf = Three::Loaders::GLTFLoader.new(backend: renderer.backend).load("/examples/browser/assets/animated_triangle.gltf")
24
+ gltf = Three::Loaders::GLTFLoader.new(backend: renderer.backend).load("/examples/browser/gltf/assets/animated_triangle.gltf")
25
25
  model = gltf.scene
26
26
  model.position.x = -0.75
27
27
  model.scale.set(1.2, 1.2, 1.2)
@@ -31,7 +31,7 @@ Three::Browser.run(starting: "Starting Ruby scene") do |app|
31
31
  compressed_gltf = Three::Loaders::GLTFLoader.new(
32
32
  backend: renderer.backend,
33
33
  draco_decoder_path: draco_decoder_path
34
- ).load("/examples/browser/assets/compressed_triangle.gltf")
34
+ ).load("/examples/browser/gltf/assets/compressed_triangle.gltf")
35
35
  compressed_model = compressed_gltf.scene
36
36
  compressed_model.position.x = 1.05
37
37
  compressed_model.scale.set(0.82, 0.82, 0.82)
@@ -54,10 +54,12 @@
54
54
  position: absolute;
55
55
  top: 16px;
56
56
  left: 16px;
57
- display: flex;
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 && status.textContent === "Loading ruby.wasm") {
125
- status.textContent = "Still loading ruby.wasm";
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: flex;
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 && status.textContent === "Loading ruby.wasm") {
125
- status.textContent = "Still loading ruby.wasm";
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>
@@ -0,0 +1,11 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128">
2
+ <rect width="128" height="128" fill="#eef3f7"/>
3
+ <rect width="32" height="32" fill="#22313f"/>
4
+ <rect x="64" width="32" height="32" fill="#22313f"/>
5
+ <rect x="32" y="32" width="32" height="32" fill="#6ed69a"/>
6
+ <rect x="96" y="32" width="32" height="32" fill="#6ed69a"/>
7
+ <rect y="64" width="32" height="32" fill="#22313f"/>
8
+ <rect x="64" y="64" width="32" height="32" fill="#22313f"/>
9
+ <rect x="32" y="96" width="32" height="32" fill="#6ed69a"/>
10
+ <rect x="96" y="96" width="32" height="32" fill="#6ed69a"/>
11
+ </svg>
@@ -54,10 +54,12 @@
54
54
  position: absolute;
55
55
  top: 16px;
56
56
  left: 16px;
57
- display: flex;
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 && status.textContent === "Loading ruby.wasm") {
125
- status.textContent = "Still loading ruby.wasm";
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>
@@ -43,7 +43,7 @@ Three::Browser.run(starting: "Starting primitives scene") do |app|
43
43
  Three::PointsMaterial.new(color: 0xffcc4d, size: 12, size_attenuation: false)
44
44
  )
45
45
 
46
- sprite_texture = Three::Loaders::TextureLoader.new.load("/examples/browser/assets/checker.svg")
46
+ sprite_texture = Three::Loaders::TextureLoader.new.load("/examples/browser/primitives/assets/checker.svg")
47
47
  sprite_material = Three::SpriteMaterial.new(
48
48
  color: 0xffffff,
49
49
  map: sprite_texture,
@@ -2,6 +2,8 @@
2
2
 
3
3
  This browser example is the first visual sample for three-rb. It builds a faceted red gemstone in Ruby with `BufferGeometry`, renders it with `MeshPhysicalMaterial`, and adds an extruded `three-rb` title through the three.js `TextGeometry` addon.
4
4
 
5
+ Its title font lives under `examples/browser/ruby/assets/` with the sample.
6
+
5
7
  Run it from the repository root:
6
8
 
7
9
  ```sh