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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -2
- data/README.md +14 -6
- data/docs/browser-runtime.md +10 -6
- data/docs/cloudflare-pages.md +205 -0
- data/docs/implementation-plan.md +6 -4
- data/docs/loaded-assets-design.md +1 -1
- data/docs/next-work.md +26 -25
- data/docs/publishing.md +4 -1
- data/docs/release-readiness.md +11 -11
- data/docs/standalone-browser-app.md +8 -2
- data/examples/browser/README.md +5 -1
- data/examples/browser/composition/index.html +65 -4
- data/examples/browser/composition/main.rb +2 -2
- data/examples/browser/cube/README.md +3 -3
- data/examples/browser/cube/index.html +61 -6
- data/examples/browser/cubemap/assets/checker.svg +11 -0
- data/examples/browser/cubemap/index.html +60 -5
- data/examples/browser/cubemap/main.rb +1 -1
- 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/gltf/main.rb +2 -2
- data/examples/browser/picking/index.html +61 -6
- data/examples/browser/postprocessing/index.html +61 -6
- data/examples/browser/primitives/assets/checker.svg +11 -0
- data/examples/browser/primitives/index.html +61 -6
- data/examples/browser/primitives/main.rb +1 -1
- data/examples/browser/ruby/README.md +2 -0
- 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/assets/checker.svg +11 -0
- data/examples/browser/serialization/index.html +61 -6
- data/examples/browser/serialization/main.rb +1 -1
- data/examples/browser/shared/boot.mjs +116 -14
- data/examples/browser/shared/config.mjs +3 -0
- data/examples/browser/shared/smoke_test_helpers.mjs +13 -8
- data/examples/browser/textures/assets/checker.svg +11 -0
- data/examples/browser/textures/index.html +61 -6
- data/examples/browser/textures/main.rb +2 -2
- data/exe/three-rb +1 -0
- 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 +220 -12
- data/lib/three/version.rb +1 -1
- data/package.json +9 -5
- data/pnpm-lock.yaml +1235 -31
- metadata +19 -7
- /data/examples/browser/{assets → composition/assets}/checker.svg +0 -0
- /data/examples/browser/{assets → gltf/assets}/animated_triangle.gltf +0 -0
- /data/examples/browser/{assets → gltf/assets}/compressed_triangle.gltf +0 -0
- /data/examples/browser/{assets → gltf/assets}/triangle.gltf +0 -0
- /data/examples/browser/{assets → textures/assets}/studio.hdr +0 -0
|
@@ -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>
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../lib/three"
|
|
4
|
+
|
|
5
|
+
def dango_ring_points(radial_segments)
|
|
6
|
+
(0..radial_segments).map do |index|
|
|
7
|
+
angle = (Math::PI * 2 * index) / radial_segments
|
|
8
|
+
[Math.cos(angle), Math.sin(angle), index.to_f / radial_segments]
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def append_dango_skewer_body(vertices, normals, uvs, indices, half_length, radius, ring_points)
|
|
13
|
+
ring_points.each do |cosine, sine, u|
|
|
14
|
+
y = cosine * radius
|
|
15
|
+
z = sine * radius
|
|
16
|
+
|
|
17
|
+
vertices.push(-half_length, y, z, half_length, y, z)
|
|
18
|
+
normals.push(0, cosine, sine, 0, cosine, sine)
|
|
19
|
+
uvs.push(u, 0, u, 1)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
(ring_points.length - 1).times do |index|
|
|
23
|
+
left = index * 2
|
|
24
|
+
right = left + 1
|
|
25
|
+
next_left = left + 2
|
|
26
|
+
next_right = left + 3
|
|
27
|
+
indices.push(left, next_left, right, right, next_left, next_right)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def append_dango_skewer_cap(vertices, normals, uvs, indices, x, radius, ring_points, normal_x:, reverse: false)
|
|
32
|
+
center = vertices.length / 3
|
|
33
|
+
vertices.push(x, 0, 0)
|
|
34
|
+
normals.push(normal_x, 0, 0)
|
|
35
|
+
uvs.push(0.5, 0.5)
|
|
36
|
+
|
|
37
|
+
ring_points.each do |cosine, sine, _u|
|
|
38
|
+
vertices.push(x, cosine * radius, sine * radius)
|
|
39
|
+
normals.push(normal_x, 0, 0)
|
|
40
|
+
uvs.push((cosine + 1) / 2.0, (sine + 1) / 2.0)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
(ring_points.length - 1).times do |index|
|
|
44
|
+
first = center + index + 1
|
|
45
|
+
second = center + index + 2
|
|
46
|
+
reverse ? indices.push(center, second, first) : indices.push(center, first, second)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def dango_skewer_geometry(length, radius, radial_segments: 18)
|
|
51
|
+
geometry = Three::BufferGeometry.new
|
|
52
|
+
half_length = length / 2.0
|
|
53
|
+
ring_points = dango_ring_points(radial_segments)
|
|
54
|
+
vertices = []
|
|
55
|
+
normals = []
|
|
56
|
+
uvs = []
|
|
57
|
+
indices = []
|
|
58
|
+
|
|
59
|
+
append_dango_skewer_body(vertices, normals, uvs, indices, half_length, radius, ring_points)
|
|
60
|
+
append_dango_skewer_cap(vertices, normals, uvs, indices, -half_length, radius, ring_points, normal_x: -1, reverse: true)
|
|
61
|
+
append_dango_skewer_cap(vertices, normals, uvs, indices, half_length, radius, ring_points, normal_x: 1)
|
|
62
|
+
|
|
63
|
+
geometry.set_index(indices)
|
|
64
|
+
geometry.set_attribute(:position, Three::Float32BufferAttribute.new(vertices, 3))
|
|
65
|
+
geometry.set_attribute(:normal, Three::Float32BufferAttribute.new(normals, 3))
|
|
66
|
+
geometry.set_attribute(:uv, Three::Float32BufferAttribute.new(uvs, 2))
|
|
67
|
+
geometry
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def dango_plate_part(size, material, position: nil, cast_shadow: true)
|
|
71
|
+
mesh = Three::Mesh.new(Three::BoxGeometry.new(*size), material)
|
|
72
|
+
mesh.position.set(*position) if position
|
|
73
|
+
mesh.cast_shadow = cast_shadow
|
|
74
|
+
mesh.receive_shadow = true
|
|
75
|
+
mesh
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def dango_lights
|
|
79
|
+
hemisphere_light = Three::HemisphereLight.new(0xfffbf2, 0xd7ddb8, 0.68)
|
|
80
|
+
|
|
81
|
+
key_light = Three::DirectionalLight.new(0xffffff, 1.05)
|
|
82
|
+
key_light.position.set(-2.4, 3.0, 5.2)
|
|
83
|
+
key_light.cast_shadow = true
|
|
84
|
+
key_light.shadow_map_size = [1024, 1024]
|
|
85
|
+
key_light.shadow_bias = -0.00008
|
|
86
|
+
key_light.set_shadow_camera(left: -3.6, right: 3.6, top: 2.4, bottom: -2.4, near: 0.5, far: 12)
|
|
87
|
+
|
|
88
|
+
fill_light = Three::PointLight.new(0xffe6d0, 0.52, 7, 2)
|
|
89
|
+
fill_light.position.set(2.6, -1.2, 3.0)
|
|
90
|
+
|
|
91
|
+
{ hemisphere: hemisphere_light, key: key_light, fill: fill_light }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def dango_shadow_catcher
|
|
95
|
+
material = Three::ShadowMaterial.new(color: 0x8c806d, opacity: 0.12)
|
|
96
|
+
mesh = Three::Mesh.new(Three::PlaneGeometry.new(6.0, 3.6), material)
|
|
97
|
+
mesh.position.z = -0.72
|
|
98
|
+
mesh.receive_shadow = true
|
|
99
|
+
mesh
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def dango_plate
|
|
103
|
+
plate = Three::Group.new
|
|
104
|
+
plate.name = "dango-plate"
|
|
105
|
+
plate.position.set(0, -1.15, 0.04)
|
|
106
|
+
plate.rotation.x = -0.52
|
|
107
|
+
|
|
108
|
+
floor_material = Three::MeshLambertMaterial.new(color: 0xfff7ea)
|
|
109
|
+
rim_material = Three::MeshLambertMaterial.new(color: 0xf1d8ad)
|
|
110
|
+
foot_material = Three::MeshLambertMaterial.new(color: 0xd3b680)
|
|
111
|
+
parts = {
|
|
112
|
+
floor: dango_plate_part([3.72, 0.08, 0.82], floor_material, cast_shadow: false),
|
|
113
|
+
front_rim: dango_plate_part([4.08, 0.14, 0.12], rim_material, position: [0, 0.055, -0.48]),
|
|
114
|
+
back_rim: dango_plate_part([4.08, 0.14, 0.12], rim_material, position: [0, 0.055, 0.48]),
|
|
115
|
+
left_rim: dango_plate_part([0.14, 0.14, 0.82], rim_material, position: [-1.98, 0.055, 0]),
|
|
116
|
+
right_rim: dango_plate_part([0.14, 0.14, 0.82], rim_material, position: [1.98, 0.055, 0]),
|
|
117
|
+
foot: dango_plate_part([2.72, 0.08, 0.34], foot_material, position: [0, -0.12, -0.04])
|
|
118
|
+
}
|
|
119
|
+
parts.each_value { |part| plate.add(part) }
|
|
120
|
+
|
|
121
|
+
[plate, parts]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def dango_skewer_mesh(length, material, position)
|
|
125
|
+
mesh = Three::Mesh.new(dango_skewer_geometry(length, 0.034), material)
|
|
126
|
+
mesh.position.set(*position)
|
|
127
|
+
mesh.cast_shadow = true
|
|
128
|
+
mesh
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def dango_skewer
|
|
132
|
+
material = Three::MeshLambertMaterial.new(color: 0xcbb281)
|
|
133
|
+
skewer = Three::Group.new
|
|
134
|
+
skewer.name = "dango-skewer-rod"
|
|
135
|
+
|
|
136
|
+
core = dango_skewer_mesh(2.58, material, [0, 0, 0.04])
|
|
137
|
+
tip = dango_skewer_mesh(0.72, material, [1.82, 0, 0.04])
|
|
138
|
+
skewer.add(core, tip)
|
|
139
|
+
|
|
140
|
+
[skewer, core, tip]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def dango_mochi
|
|
144
|
+
geometry = Three::SphereGeometry.new(0.56, width_segments: 96, height_segments: 48)
|
|
145
|
+
[
|
|
146
|
+
["sakura", -0.98, 0xf8cfd7, 0xf4dce1],
|
|
147
|
+
["plain", 0.0, 0xfffaed, 0xe8dfc8],
|
|
148
|
+
["matcha", 0.98, 0xc0dca4, 0xddebd0]
|
|
149
|
+
].map do |name, x, color, specular|
|
|
150
|
+
material = Three::MeshPhongMaterial.new(color: color, specular: specular, shininess: 14)
|
|
151
|
+
mesh = Three::Mesh.new(geometry, material)
|
|
152
|
+
mesh.name = "#{name}-dango"
|
|
153
|
+
mesh.position.set(x, 0, 0.04)
|
|
154
|
+
mesh.cast_shadow = true
|
|
155
|
+
mesh.receive_shadow = true
|
|
156
|
+
mesh
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def dango_skewer_group
|
|
161
|
+
group = Three::Group.new
|
|
162
|
+
group.name = "dango-skewer"
|
|
163
|
+
group.rotation.z = -0.22
|
|
164
|
+
group.position.set(0, 0.18, -0.75)
|
|
165
|
+
group
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def dango_renderer
|
|
169
|
+
renderer = Three::Renderers::ThreeJSRenderer.new(
|
|
170
|
+
canvas: "#scene",
|
|
171
|
+
antialias: true,
|
|
172
|
+
alpha: false,
|
|
173
|
+
preserveDrawingBuffer: true,
|
|
174
|
+
shadow_map_enabled: true,
|
|
175
|
+
shadow_map_type: Three::PCFShadowMap
|
|
176
|
+
)
|
|
177
|
+
renderer.set_clear_color(0xfaf5ec, 1)
|
|
178
|
+
renderer
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def dango_controls(camera, renderer)
|
|
182
|
+
controls = Three::Controls::OrbitControls.new(
|
|
183
|
+
camera,
|
|
184
|
+
renderer: renderer,
|
|
185
|
+
enable_damping: true,
|
|
186
|
+
damping_factor: 0.08,
|
|
187
|
+
enable_pan: false,
|
|
188
|
+
auto_rotate: false,
|
|
189
|
+
min_zoom: 0.82,
|
|
190
|
+
max_zoom: 1.65
|
|
191
|
+
)
|
|
192
|
+
controls.target.set(0, -0.18, 0)
|
|
193
|
+
controls
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
Three::Browser.run(starting: "Starting dango scene") do |app|
|
|
197
|
+
scene = Three::Scene.new
|
|
198
|
+
camera = Three::OrthographicCamera.new(-3.2, 3.2, 2.0, -2.0, near: 0.1, far: 100)
|
|
199
|
+
camera.position.z = 6
|
|
200
|
+
|
|
201
|
+
lights = dango_lights
|
|
202
|
+
hemisphere_light = lights[:hemisphere]
|
|
203
|
+
key_light = lights[:key]
|
|
204
|
+
fill_light = lights[:fill]
|
|
205
|
+
scene.add(hemisphere_light, key_light, fill_light)
|
|
206
|
+
|
|
207
|
+
shadow_catcher = dango_shadow_catcher
|
|
208
|
+
scene.add(shadow_catcher)
|
|
209
|
+
|
|
210
|
+
plate, plate_parts = dango_plate
|
|
211
|
+
scene.add(plate)
|
|
212
|
+
|
|
213
|
+
dango_group = dango_skewer_group
|
|
214
|
+
scene.add(dango_group)
|
|
215
|
+
|
|
216
|
+
skewer, skewer_core, skewer_tip = dango_skewer
|
|
217
|
+
dango_group.add(skewer)
|
|
218
|
+
|
|
219
|
+
mochi = dango_mochi
|
|
220
|
+
mochi.each { |mesh| dango_group.add(mesh) }
|
|
221
|
+
|
|
222
|
+
renderer = dango_renderer
|
|
223
|
+
controls = dango_controls(camera, renderer)
|
|
224
|
+
|
|
225
|
+
app.resize_renderer(renderer, camera) do |width, height, _aspect|
|
|
226
|
+
view_height = 4.05
|
|
227
|
+
view_width = view_height * width.to_f / height
|
|
228
|
+
if view_width < 4.6
|
|
229
|
+
view_width = 4.6
|
|
230
|
+
view_height = view_width * height.to_f / width
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
camera.left = -view_width / 2
|
|
234
|
+
camera.right = view_width / 2
|
|
235
|
+
camera.top = view_height / 2
|
|
236
|
+
camera.bottom = -view_height / 2
|
|
237
|
+
camera.update_projection_matrix
|
|
238
|
+
end
|
|
239
|
+
renderer.render(scene, camera)
|
|
240
|
+
|
|
241
|
+
app.expose(
|
|
242
|
+
{
|
|
243
|
+
renderer: renderer,
|
|
244
|
+
controls: controls,
|
|
245
|
+
scene: scene,
|
|
246
|
+
camera: camera,
|
|
247
|
+
dango_group: dango_group,
|
|
248
|
+
dango_skewer: skewer,
|
|
249
|
+
dango_skewer_core: skewer_core,
|
|
250
|
+
dango_skewer_tip: skewer_tip,
|
|
251
|
+
dango_mochi: mochi,
|
|
252
|
+
dango_plate: plate,
|
|
253
|
+
dango_plate_floor: plate_parts[:floor],
|
|
254
|
+
dango_plate_front_rim: plate_parts[:front_rim],
|
|
255
|
+
dango_plate_back_rim: plate_parts[:back_rim],
|
|
256
|
+
dango_plate_left_rim: plate_parts[:left_rim],
|
|
257
|
+
dango_plate_right_rim: plate_parts[:right_rim],
|
|
258
|
+
dango_plate_foot: plate_parts[:foot],
|
|
259
|
+
dango_shadow: shadow_catcher,
|
|
260
|
+
dango_key_light: key_light,
|
|
261
|
+
dango_hemisphere_light: hemisphere_light,
|
|
262
|
+
dango_fill_light: fill_light,
|
|
263
|
+
dango_frame: 0
|
|
264
|
+
},
|
|
265
|
+
renderer: renderer
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
renderer.animation_loop do
|
|
269
|
+
frame = app.increment(:dango_frame)
|
|
270
|
+
dango_group.rotation.y = 0
|
|
271
|
+
dango_group.rotation.x = -0.05 + (Math.sin(frame * 0.017) * 0.035)
|
|
272
|
+
dango_group.position.y = 0.18 + (Math.sin(frame * 0.03) * 0.02)
|
|
273
|
+
plate.rotation.z = Math.sin(frame * 0.012) * 0.018
|
|
274
|
+
|
|
275
|
+
controls.update
|
|
276
|
+
renderer.render(scene, camera)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertNoDiagnostics,
|
|
3
|
+
assertNonBlankCanvas,
|
|
4
|
+
createDiagnostics,
|
|
5
|
+
createSmokePage,
|
|
6
|
+
loadPlaywright,
|
|
7
|
+
sampleCanvas,
|
|
8
|
+
startServer,
|
|
9
|
+
waitForRunning
|
|
10
|
+
} from "../shared/smoke_test_helpers.mjs";
|
|
11
|
+
|
|
12
|
+
async function main() {
|
|
13
|
+
const { chromium } = await loadPlaywright();
|
|
14
|
+
const server = await startServer();
|
|
15
|
+
const browser = await chromium.launch({ headless: process.env.HEADLESS !== "0" });
|
|
16
|
+
const diagnostics = createDiagnostics();
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const page = await createSmokePage(browser, diagnostics);
|
|
20
|
+
|
|
21
|
+
await page.goto(`${server.url}/examples/browser/dango/`, { waitUntil: "load" });
|
|
22
|
+
await waitForRunning(page, diagnostics);
|
|
23
|
+
await page.waitForTimeout(1_000);
|
|
24
|
+
|
|
25
|
+
assertNonBlankCanvas(await sampleCanvas(page));
|
|
26
|
+
|
|
27
|
+
const state = await page.evaluate(() => ({
|
|
28
|
+
frame: globalThis.__threeRbDangoFrame,
|
|
29
|
+
group: {
|
|
30
|
+
type: globalThis.__threeRbDangoGroup?.type,
|
|
31
|
+
name: globalThis.__threeRbDangoGroup?.name,
|
|
32
|
+
children: globalThis.__threeRbDangoGroup?.children?.length,
|
|
33
|
+
rotation: globalThis.__threeRbDangoGroup?.rotation?.toArray?.(),
|
|
34
|
+
position: globalThis.__threeRbDangoGroup?.position?.toArray?.()
|
|
35
|
+
},
|
|
36
|
+
mochi: globalThis.__threeRbDangoMochi?.map((mesh) => ({
|
|
37
|
+
type: mesh?.type,
|
|
38
|
+
name: mesh?.name,
|
|
39
|
+
geometryType: mesh?.geometry?.type,
|
|
40
|
+
geometryRadius: mesh?.geometry?.parameters?.radius,
|
|
41
|
+
geometryWidthSegments: mesh?.geometry?.parameters?.widthSegments,
|
|
42
|
+
geometryHeightSegments: mesh?.geometry?.parameters?.heightSegments,
|
|
43
|
+
materialType: mesh?.material?.type,
|
|
44
|
+
color: mesh?.material?.color?.getHex?.(),
|
|
45
|
+
shininess: mesh?.material?.shininess,
|
|
46
|
+
castShadow: mesh?.castShadow,
|
|
47
|
+
receiveShadow: mesh?.receiveShadow,
|
|
48
|
+
position: mesh?.position?.toArray?.(),
|
|
49
|
+
scale: mesh?.scale?.toArray?.()
|
|
50
|
+
})),
|
|
51
|
+
skewer: {
|
|
52
|
+
type: globalThis.__threeRbDangoSkewer?.type,
|
|
53
|
+
name: globalThis.__threeRbDangoSkewer?.name,
|
|
54
|
+
children: globalThis.__threeRbDangoSkewer?.children?.length,
|
|
55
|
+
position: globalThis.__threeRbDangoSkewer?.position?.toArray?.(),
|
|
56
|
+
coreType: globalThis.__threeRbDangoSkewerCore?.type,
|
|
57
|
+
coreGeometryType: globalThis.__threeRbDangoSkewerCore?.geometry?.type,
|
|
58
|
+
corePositionCount: globalThis.__threeRbDangoSkewerCore?.geometry?.attributes?.position?.count,
|
|
59
|
+
corePosition: globalThis.__threeRbDangoSkewerCore?.position?.toArray?.(),
|
|
60
|
+
coreColor: globalThis.__threeRbDangoSkewerCore?.material?.color?.getHex?.(),
|
|
61
|
+
coreCastShadow: globalThis.__threeRbDangoSkewerCore?.castShadow,
|
|
62
|
+
tipType: globalThis.__threeRbDangoSkewerTip?.type,
|
|
63
|
+
tipGeometryType: globalThis.__threeRbDangoSkewerTip?.geometry?.type,
|
|
64
|
+
tipPositionCount: globalThis.__threeRbDangoSkewerTip?.geometry?.attributes?.position?.count,
|
|
65
|
+
tipPosition: globalThis.__threeRbDangoSkewerTip?.position?.toArray?.(),
|
|
66
|
+
tipColor: globalThis.__threeRbDangoSkewerTip?.material?.color?.getHex?.(),
|
|
67
|
+
tipCastShadow: globalThis.__threeRbDangoSkewerTip?.castShadow
|
|
68
|
+
},
|
|
69
|
+
plate: {
|
|
70
|
+
type: globalThis.__threeRbDangoPlate?.type,
|
|
71
|
+
name: globalThis.__threeRbDangoPlate?.name,
|
|
72
|
+
children: globalThis.__threeRbDangoPlate?.children?.length,
|
|
73
|
+
position: globalThis.__threeRbDangoPlate?.position?.toArray?.(),
|
|
74
|
+
rotation: globalThis.__threeRbDangoPlate?.rotation?.toArray?.(),
|
|
75
|
+
floorType: globalThis.__threeRbDangoPlateFloor?.type,
|
|
76
|
+
floorGeometryType: globalThis.__threeRbDangoPlateFloor?.geometry?.type,
|
|
77
|
+
frontRimType: globalThis.__threeRbDangoPlateFrontRim?.type,
|
|
78
|
+
frontRimGeometryType: globalThis.__threeRbDangoPlateFrontRim?.geometry?.type,
|
|
79
|
+
backRimType: globalThis.__threeRbDangoPlateBackRim?.type,
|
|
80
|
+
backRimGeometryType: globalThis.__threeRbDangoPlateBackRim?.geometry?.type,
|
|
81
|
+
leftRimType: globalThis.__threeRbDangoPlateLeftRim?.type,
|
|
82
|
+
leftRimGeometryType: globalThis.__threeRbDangoPlateLeftRim?.geometry?.type,
|
|
83
|
+
rightRimType: globalThis.__threeRbDangoPlateRightRim?.type,
|
|
84
|
+
rightRimGeometryType: globalThis.__threeRbDangoPlateRightRim?.geometry?.type,
|
|
85
|
+
footType: globalThis.__threeRbDangoPlateFoot?.type,
|
|
86
|
+
footGeometryType: globalThis.__threeRbDangoPlateFoot?.geometry?.type,
|
|
87
|
+
floorReceiveShadow: globalThis.__threeRbDangoPlateFloor?.receiveShadow,
|
|
88
|
+
frontRimReceiveShadow: globalThis.__threeRbDangoPlateFrontRim?.receiveShadow,
|
|
89
|
+
backRimReceiveShadow: globalThis.__threeRbDangoPlateBackRim?.receiveShadow,
|
|
90
|
+
leftRimReceiveShadow: globalThis.__threeRbDangoPlateLeftRim?.receiveShadow,
|
|
91
|
+
rightRimReceiveShadow: globalThis.__threeRbDangoPlateRightRim?.receiveShadow,
|
|
92
|
+
footReceiveShadow: globalThis.__threeRbDangoPlateFoot?.receiveShadow
|
|
93
|
+
},
|
|
94
|
+
lights: {
|
|
95
|
+
keyType: globalThis.__threeRbDangoKeyLight?.type,
|
|
96
|
+
keyCastShadow: globalThis.__threeRbDangoKeyLight?.castShadow,
|
|
97
|
+
hemisphereType: globalThis.__threeRbDangoHemisphereLight?.type,
|
|
98
|
+
fillType: globalThis.__threeRbDangoFillLight?.type
|
|
99
|
+
},
|
|
100
|
+
controls: {
|
|
101
|
+
autoRotate: globalThis.__threeRbControls?.autoRotate,
|
|
102
|
+
enableDamping: globalThis.__threeRbControls?.enableDamping
|
|
103
|
+
},
|
|
104
|
+
renderInfo: globalThis.__threeRbRenderer?.info?.render
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
if (state.group.type !== "Group" || state.group.name !== "dango-skewer" || state.group.children !== 4) {
|
|
108
|
+
throw new Error(`dango group did not materialize correctly: ${JSON.stringify(state)}`);
|
|
109
|
+
}
|
|
110
|
+
if (!Array.isArray(state.group.rotation) || Math.abs(state.group.rotation[2] + 0.22) > 1e-12) {
|
|
111
|
+
throw new Error(`dango group did not keep the expected skewer angle: ${JSON.stringify(state)}`);
|
|
112
|
+
}
|
|
113
|
+
if (
|
|
114
|
+
!Array.isArray(state.group.position) ||
|
|
115
|
+
Math.abs(state.group.position[1] - 0.18) > 0.05 ||
|
|
116
|
+
Math.abs(state.group.position[2] + 0.75) > 1e-12
|
|
117
|
+
) {
|
|
118
|
+
throw new Error(`dango group is not centered over the plate depth: ${JSON.stringify(state)}`);
|
|
119
|
+
}
|
|
120
|
+
if (!Array.isArray(state.mochi) || state.mochi.length !== 3) {
|
|
121
|
+
throw new Error(`expected three mochi meshes: ${JSON.stringify(state)}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const expectedColors = [0xf8cfd7, 0xfffaed, 0xc0dca4];
|
|
125
|
+
state.mochi.forEach((mesh, index) => {
|
|
126
|
+
if (
|
|
127
|
+
mesh.type !== "Mesh" ||
|
|
128
|
+
mesh.geometryType !== "SphereGeometry" ||
|
|
129
|
+
mesh.geometryRadius !== 0.56 ||
|
|
130
|
+
mesh.geometryWidthSegments !== 96 ||
|
|
131
|
+
mesh.geometryHeightSegments !== 48 ||
|
|
132
|
+
mesh.materialType !== "MeshPhongMaterial" ||
|
|
133
|
+
mesh.color !== expectedColors[index] ||
|
|
134
|
+
mesh.shininess !== 14 ||
|
|
135
|
+
mesh.castShadow !== true ||
|
|
136
|
+
mesh.receiveShadow !== true
|
|
137
|
+
) {
|
|
138
|
+
throw new Error(`mochi mesh ${index} did not materialize correctly: ${JSON.stringify(state)}`);
|
|
139
|
+
}
|
|
140
|
+
if (!Array.isArray(mesh.scale) || mesh.scale[0] !== 1 || mesh.scale[1] !== 1 || mesh.scale[2] !== 1) {
|
|
141
|
+
throw new Error(`mochi mesh ${index} is not spherical: ${JSON.stringify(state)}`);
|
|
142
|
+
}
|
|
143
|
+
if (!Array.isArray(mesh.position) || mesh.position[1] !== 0 || mesh.position[2] !== 0.04) {
|
|
144
|
+
throw new Error(`mochi mesh ${index} position did not sync: ${JSON.stringify(state)}`);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
if (
|
|
149
|
+
state.skewer.type !== "Group" ||
|
|
150
|
+
state.skewer.name !== "dango-skewer-rod" ||
|
|
151
|
+
state.skewer.children !== 2 ||
|
|
152
|
+
!Array.isArray(state.skewer.position) ||
|
|
153
|
+
state.skewer.position[0] !== 0 ||
|
|
154
|
+
state.skewer.coreType !== "Mesh" ||
|
|
155
|
+
state.skewer.coreGeometryType !== "BufferGeometry" ||
|
|
156
|
+
state.skewer.coreColor !== 0xcbb281 ||
|
|
157
|
+
state.skewer.coreCastShadow !== true ||
|
|
158
|
+
state.skewer.corePositionCount < 70 ||
|
|
159
|
+
!Array.isArray(state.skewer.corePosition) ||
|
|
160
|
+
state.skewer.corePosition[0] !== 0 ||
|
|
161
|
+
state.skewer.corePosition[1] !== 0 ||
|
|
162
|
+
state.skewer.corePosition[2] !== 0.04 ||
|
|
163
|
+
state.skewer.tipType !== "Mesh" ||
|
|
164
|
+
state.skewer.tipGeometryType !== "BufferGeometry" ||
|
|
165
|
+
state.skewer.tipColor !== 0xcbb281 ||
|
|
166
|
+
state.skewer.tipCastShadow !== true ||
|
|
167
|
+
state.skewer.tipPositionCount < 70 ||
|
|
168
|
+
!Array.isArray(state.skewer.tipPosition) ||
|
|
169
|
+
state.skewer.tipPosition[0] <= 1.6 ||
|
|
170
|
+
state.skewer.tipPosition[1] !== 0 ||
|
|
171
|
+
state.skewer.tipPosition[2] !== 0.04
|
|
172
|
+
) {
|
|
173
|
+
throw new Error(`skewer did not materialize correctly: ${JSON.stringify(state)}`);
|
|
174
|
+
}
|
|
175
|
+
if (
|
|
176
|
+
state.plate.type !== "Group" ||
|
|
177
|
+
state.plate.name !== "dango-plate" ||
|
|
178
|
+
state.plate.children !== 6 ||
|
|
179
|
+
!Array.isArray(state.plate.position) ||
|
|
180
|
+
state.plate.position[0] !== 0 ||
|
|
181
|
+
state.plate.position[2] !== 0.04 ||
|
|
182
|
+
!Array.isArray(state.plate.rotation) ||
|
|
183
|
+
state.plate.rotation[0] >= -0.4 ||
|
|
184
|
+
state.plate.floorType !== "Mesh" ||
|
|
185
|
+
state.plate.floorGeometryType !== "BoxGeometry" ||
|
|
186
|
+
state.plate.frontRimType !== "Mesh" ||
|
|
187
|
+
state.plate.frontRimGeometryType !== "BoxGeometry" ||
|
|
188
|
+
state.plate.backRimType !== "Mesh" ||
|
|
189
|
+
state.plate.backRimGeometryType !== "BoxGeometry" ||
|
|
190
|
+
state.plate.leftRimType !== "Mesh" ||
|
|
191
|
+
state.plate.leftRimGeometryType !== "BoxGeometry" ||
|
|
192
|
+
state.plate.rightRimType !== "Mesh" ||
|
|
193
|
+
state.plate.rightRimGeometryType !== "BoxGeometry" ||
|
|
194
|
+
state.plate.footType !== "Mesh" ||
|
|
195
|
+
state.plate.footGeometryType !== "BoxGeometry" ||
|
|
196
|
+
state.plate.floorReceiveShadow !== true ||
|
|
197
|
+
state.plate.frontRimReceiveShadow !== true ||
|
|
198
|
+
state.plate.backRimReceiveShadow !== true ||
|
|
199
|
+
state.plate.leftRimReceiveShadow !== true ||
|
|
200
|
+
state.plate.rightRimReceiveShadow !== true ||
|
|
201
|
+
state.plate.footReceiveShadow !== true
|
|
202
|
+
) {
|
|
203
|
+
throw new Error(`plate did not materialize correctly: ${JSON.stringify(state)}`);
|
|
204
|
+
}
|
|
205
|
+
if (
|
|
206
|
+
state.lights.keyType !== "DirectionalLight" ||
|
|
207
|
+
state.lights.keyCastShadow !== true ||
|
|
208
|
+
state.lights.hemisphereType !== "HemisphereLight" ||
|
|
209
|
+
state.lights.fillType !== "PointLight"
|
|
210
|
+
) {
|
|
211
|
+
throw new Error(`dango lights did not materialize correctly: ${JSON.stringify(state)}`);
|
|
212
|
+
}
|
|
213
|
+
if (state.controls.autoRotate !== false || state.controls.enableDamping !== true) {
|
|
214
|
+
throw new Error(`orbit controls did not expose expected settings: ${JSON.stringify(state)}`);
|
|
215
|
+
}
|
|
216
|
+
if (!state.renderInfo || state.renderInfo.triangles < 2_000 || !state.frame) {
|
|
217
|
+
throw new Error(`dango scene did not render or animate: ${JSON.stringify(state)}`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
assertNoDiagnostics(diagnostics);
|
|
221
|
+
|
|
222
|
+
console.log(`dango smoke test passed at ${server.url}/examples/browser/dango/`);
|
|
223
|
+
} finally {
|
|
224
|
+
await browser.close();
|
|
225
|
+
await new Promise((resolve) => server.instance.close(resolve));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
main().catch((error) => {
|
|
230
|
+
console.error(error);
|
|
231
|
+
process.exitCode = 1;
|
|
232
|
+
});
|