mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 20:59:25 +00:00
* feat(transcode): add 3D asset support and turntable viewer * perf(turntable): stream file via Bun.file and increase upload timeout * feat(turntable): increase upload timeout to 15m to support 5GB uploads * fix(webui): align 3D model viewer layout and full-width control bar with video viewer * feat(webui): unify 3D viewer bottom bar and redesign cyclic ruler slider - Place RulerSlider in single row with playback and zoom controls, centered with max 320px width - Flank RulerSlider with minus and plus buttons to step angle by 15° - Redesign RulerSlider with fixed center indicator and moving cyclic track with continuous 360° wrapping - Render major ticks longer at 60° intervals without numeric text labels on track - Display floating degree tooltip above center indicator only during dragging * fix(webui): prevent RulerSlider from collapsing to 0px width in control bar - Use flex layout with flex-1 on left and right clusters to preserve center cluster width - Enforce min-w-[140px] and w-full on RulerSlider - Fix tooltip positioning and remove outer overflow-hidden * feat(webui): snap RulerSlider track directly to discrete 15° ticks during drag * fix(webui): prevent ruler snap-back caused by floating point second truncation - Use Math.round instead of Math.floor in secondToDegree to avoid 0.999996 dropping to previous frame - Ensure final dragDegree is committed on pointer up * fix(webui): fix arrow key frame rounding and duplicate event bubbling - Use Math.round instead of Math.floor for keyboard arrow frame navigation in ModelViewer - Add e.stopPropagation() to RulerSlider keyboard events to prevent duplicate bubbling to window listener * feat(webui): redesign RulerSlider with encapsulated step buttons and capsule pill track * feat(webui): make RulerSlider responsive on mobile and remove bottom bar reset button * fix(webui): load 3d video directly without poster and invert drag rotation to counterclockwise * fix(webui): fix 3d asset viewer frame seeking and drag jitter * feat(transcode): show 3D asset poster preview immediately after render start * fix(viewer): synchronize 3D turntable playback via frame callback to prevent skipped degrees * fix(viewer): handle touchpad zoom gestures and prevent page zoom in 3D viewer * fix(viewer): eliminate 3D model rotation jitter at 345 degrees * fix(share): watermark 3D asset turntable video on share links * fix(share): preserve video transcode resolution on watermarked share links * fix(viewer): download original 3D model file instead of rendered turntable MP4
141 lines
4.5 KiB
TypeScript
141 lines
4.5 KiB
TypeScript
import type { Locator, Page } from '@playwright/test'
|
|
|
|
const MODEL_VIDEO_SELECTOR = '[data-testid="model-viewer-surface"] video'
|
|
|
|
export interface ModelViewerSnapshot {
|
|
degree: number
|
|
currentTime: number
|
|
frameHash: string
|
|
}
|
|
|
|
export class ModelViewerPage {
|
|
readonly page: Page
|
|
readonly stage: Locator
|
|
readonly container: Locator
|
|
readonly surface: Locator
|
|
readonly video: Locator
|
|
readonly playToggle: Locator
|
|
readonly degreeReadout: Locator
|
|
readonly rulerSlider: Locator
|
|
readonly rulerStepMinus: Locator
|
|
readonly rulerStepPlus: Locator
|
|
readonly rulerTooltip: Locator
|
|
|
|
constructor(page: Page) {
|
|
this.page = page
|
|
this.stage = page.getByTestId('harness-stage')
|
|
this.container = page.getByTestId('model-viewer-container')
|
|
this.surface = page.getByTestId('model-viewer-surface')
|
|
this.video = page.locator(MODEL_VIDEO_SELECTOR).first()
|
|
this.playToggle = page.getByTestId('play-toggle')
|
|
this.degreeReadout = page.getByTestId('degree-readout')
|
|
this.rulerSlider = page.locator('[role="slider"]')
|
|
this.rulerStepMinus = page.getByTestId('ruler-step-minus')
|
|
this.rulerStepPlus = page.getByTestId('ruler-step-plus')
|
|
this.rulerTooltip = page.getByTestId('ruler-slider-tooltip')
|
|
}
|
|
|
|
async goto(): Promise<void> {
|
|
await this.page.goto('/?variant=3d')
|
|
await this.waitUntilReady()
|
|
}
|
|
|
|
async waitUntilReady(): Promise<void> {
|
|
await this.video.waitFor({ state: 'attached' })
|
|
await this.page.waitForFunction(
|
|
(selector) => {
|
|
const el = document.querySelector(selector) as HTMLVideoElement | null
|
|
return !!el && el.readyState >= 1 && Number.isFinite(el.duration)
|
|
},
|
|
MODEL_VIDEO_SELECTOR,
|
|
{ timeout: 15_000 },
|
|
)
|
|
await this.page.waitForFunction(
|
|
() => {
|
|
const readout = document.querySelector('[data-testid="degree-readout"]')
|
|
return !!readout && /\d+°\s*\/\s*360°/.test(readout.textContent ?? '')
|
|
},
|
|
undefined,
|
|
{ timeout: 15_000 },
|
|
)
|
|
}
|
|
|
|
async getDegree(): Promise<number> {
|
|
const text = (await this.degreeReadout.textContent()) ?? ''
|
|
const match = text.match(/(\d+)°\s*\/\s*360°/)
|
|
return match ? Number.parseInt(match[1], 10) : Number.NaN
|
|
}
|
|
|
|
async getCurrentTime(): Promise<number> {
|
|
return this.video.evaluate((el: HTMLVideoElement) => el.currentTime)
|
|
}
|
|
|
|
/**
|
|
* Captures a perceptual pixel hash of the video's current rendered frame.
|
|
* Two frames displaying identical visuals yield the identical hash.
|
|
*/
|
|
async captureFrameHash(): Promise<string> {
|
|
return this.video.evaluate((el: HTMLVideoElement) => {
|
|
const canvas = document.createElement('canvas')
|
|
canvas.width = 64
|
|
canvas.height = 64
|
|
const ctx = canvas.getContext('2d')
|
|
if (!ctx) return ''
|
|
ctx.drawImage(el, 0, 0, 64, 64)
|
|
const data = ctx.getImageData(0, 0, 64, 64).data
|
|
let hash = 0
|
|
for (let i = 0; i < data.length; i++) {
|
|
hash = ((hash << 5) - hash + data[i]) | 0
|
|
}
|
|
return `${hash}_${data[0]}_${data[100]}_${data[500]}_${data[1000]}`
|
|
})
|
|
}
|
|
|
|
async snapshot(): Promise<ModelViewerSnapshot> {
|
|
const [degree, currentTime, frameHash] = await Promise.all([
|
|
this.getDegree(),
|
|
this.getCurrentTime(),
|
|
this.captureFrameHash(),
|
|
])
|
|
return { degree, currentTime, frameHash }
|
|
}
|
|
|
|
async stepPlus(): Promise<void> {
|
|
await this.rulerStepPlus.click()
|
|
}
|
|
|
|
async stepMinus(): Promise<void> {
|
|
await this.rulerStepMinus.click()
|
|
}
|
|
|
|
async pressArrowRight(): Promise<void> {
|
|
await this.page.keyboard.press('ArrowRight')
|
|
}
|
|
|
|
async pressArrowLeft(): Promise<void> {
|
|
await this.page.keyboard.press('ArrowLeft')
|
|
}
|
|
|
|
async dragSurface(deltaX: number, steps = 5): Promise<void> {
|
|
const box = await this.surface.boundingBox()
|
|
if (!box) throw new Error('Surface bounding box not found')
|
|
const startX = box.x + box.width / 2
|
|
const startY = box.y + box.height / 2
|
|
await this.page.mouse.move(startX, startY)
|
|
await this.page.mouse.down()
|
|
await this.page.mouse.move(startX + deltaX, startY, { steps })
|
|
await this.page.mouse.up()
|
|
}
|
|
|
|
async dragSlider(deltaX: number, steps = 5): Promise<void> {
|
|
const box = await this.rulerSlider.boundingBox()
|
|
if (!box) throw new Error('Slider bounding box not found')
|
|
const startX = box.x + box.width / 2
|
|
const startY = box.y + box.height / 2
|
|
await this.page.mouse.move(startX, startY)
|
|
await this.page.mouse.down()
|
|
await this.page.mouse.move(startX + deltaX, startY, { steps })
|
|
await this.page.mouse.up()
|
|
}
|
|
}
|