Add timeline owner for WebGL book playback

This commit is contained in:
2026-06-10 02:00:57 +02:00
parent b41340151d
commit 10bf23b10b
6 changed files with 447 additions and 74 deletions
+22 -2
View File
@@ -4,7 +4,7 @@ import { RenderPass } from 'https://esm.sh/three@0.165.0/examples/jsm/postproces
import { SSAOPass } from 'https://esm.sh/three@0.165.0/examples/jsm/postprocessing/SSAOPass.js';
import { SMAAPass } from 'https://esm.sh/three@0.165.0/examples/jsm/postprocessing/SMAAPass.js';
import { OutputPass } from 'https://esm.sh/three@0.165.0/examples/jsm/postprocessing/OutputPass.js';
import { PROCEDURAL_BOOK, createProceduralBookModel, snapProceduralPageCount } from './procedural-book-model.js?v=20260608-webgl-mask-timing-c';
import { PROCEDURAL_BOOK, createProceduralBookModel, snapProceduralPageCount } from './procedural-book-model.js?v=20260610-book-timeline-a';
const canvas = document.getElementById('scene');
canvas.style.cursor = 'grab';
@@ -275,6 +275,7 @@ const pageRevealState = {
left: null,
right: null
};
let pageRevealFreezeAt = null;
const pageRevealClearLog = [];
await reportLabStep(52, 'Generating leather texture set');
const leatherTextures = createLeatherTextures();
@@ -2573,7 +2574,25 @@ function fastForwardPageReveals(blockIds = []) {
}
function updatePageRevealAnimations(now) {
if (activeFlips.length > 0) return;
if (activeFlips.length > 0) {
if (pageRevealFreezeAt === null) pageRevealFreezeAt = now;
return;
}
if (pageRevealFreezeAt !== null) {
const frozenMs = Math.max(0, now - pageRevealFreezeAt);
['left', 'right'].forEach((side) => {
const state = pageRevealState[side];
if (!state || state.startedAt == null) return;
state.startedAt += frozenMs;
state.lastRevealFrameAt = now;
});
activeRevealBlockStarts.forEach((value, blockId) => {
if (Number.isFinite(Number(value))) {
activeRevealBlockStarts.set(blockId, Number(value) + frozenMs);
}
});
pageRevealFreezeAt = null;
}
['left', 'right'].forEach((side) => {
const state = pageRevealState[side];
if (!state) return;
@@ -2942,6 +2961,7 @@ function canPageFlip(direction) {
}
function handleRevealCommittedForPageFlip(detail = {}) {
if (window.BookPlaybackTimeline?.ownsPageFlipCommit === true) return;
if (detail.side !== 'right' || detail.pageFlipAfterReveal !== true) return;
if (activeFlips.length > 0 || pendingRightPageFlip) return;
if (isChoiceAwaitingPlayer()) return;