Skip to content

Commit 531d75c

Browse files
committed
allow async loading.
1 parent 5bfd808 commit 531d75c

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

examples/webgpu_tsl_wood.html

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
renderer.setSize(window.innerWidth, window.innerHeight);
5858
renderer.toneMapping = THREE.NeutralToneMapping;
5959
renderer.toneMappingExposure = 1.0;
60+
renderer.setAnimationLoop(render);
6061
document.body.appendChild(renderer.domElement);
6162

6263
canvas = document.querySelector("canvas");
@@ -73,20 +74,8 @@
7374

7475
base = new THREE.Group();
7576
base.rotation.set(0, -Math.PI/2, 0);
77+
scene.add(base);
7678

77-
new HDRLoader().load("./textures/equirectangular/royal_esplanade_1k.hdr", async (env_map) =>
78-
{
79-
env_map.mapping = THREE.EquirectangularReflectionMapping;
80-
81-
scene.background = env_map;
82-
scene.environment = env_map;
83-
scene.environmentIntensity = 6;
84-
85-
for (let x = 0; x < WoodGenuses.length; x++)
86-
{
87-
await add_wood(x, text_mat);
88-
}
89-
});
9079

9180

9281
for (let y = 0; y < Finishes.length; y++) {
@@ -110,11 +99,23 @@
11099
base.add(txt);
111100
}
112101

113-
scene.add(base);
114102

103+
new HDRLoader().load("./textures/equirectangular/royal_esplanade_1k.hdr", async (env_map) =>
104+
{
105+
env_map.mapping = THREE.EquirectangularReflectionMapping;
106+
107+
scene.background = env_map;
108+
scene.environment = env_map;
109+
scene.environmentIntensity = 6;
115110

116-
renderer.setAnimationLoop(render);
117-
}
111+
for (let x = 0; x < WoodGenuses.length; x++)
112+
{
113+
await add_wood(x, text_mat);
114+
}
115+
});
116+
117+
118+
}
118119

119120
function render() {
120121
controls.update();
@@ -172,7 +173,10 @@
172173
const cube = new THREE.Mesh(geometry, GenerateWoodMaterial(GetWoodPreset(WoodGenuses[x], Finishes[y])));
173174
cube.position.set(position.x, position.y, position.z);
174175
base.add(cube);
176+
177+
// sleep
175178
}
179+
await new Promise(resolve => setTimeout(resolve, 0));
176180
}
177181
</script>
178182
</body>

0 commit comments

Comments
 (0)