fix: Defer initial WebGL render until DOM layout completes for auto-loaded STL

This commit is contained in:
2026-08-26 00:52:26 +02:00
parent 1abd4f74ac
commit 340cd182e7
+16 -7
View File
@@ -349,6 +349,11 @@
frame = 0;
if (!vertexCount) return;
const rect = canvas.getBoundingClientRect();
if (rect.width < 10 || rect.height < 10) {
// Container layout is not ready yet; retry on next frame
requestDraw();
return;
}
const width = Math.max(1, Math.round(rect.width * renderScale));
const height = Math.max(1, Math.round(rect.height * renderScale));
if (canvas.width !== width || canvas.height !== height) {
@@ -503,14 +508,18 @@
yawVelocity = 0;
pitchVelocity = 0;
setTimeout(() => {
introAnimating = true;
introStartTime = performance.now();
startYaw = yaw;
startPitch = pitch;
startZoom = zoom;
// Defer rendering to post-reflow rAF so canvas dimensions are ready
requestAnimationFrame(() => {
requestDraw();
}, 150);
setTimeout(() => {
introAnimating = true;
introStartTime = performance.now();
startYaw = yaw;
startPitch = pitch;
startZoom = zoom;
requestDraw();
}, 150);
});
requestDraw();
return { name, triangles: vertexCount / 3 };