mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 18:17:57 +00:00
fix(webui): fix 3d asset viewer frame seeking and drag jitter
This commit is contained in:
@@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
### Fixed
|
||||
|
||||
- **viewer**: Fix an issue where certain angles in the 3D asset viewer appeared stuck on the previous frame, and eliminate view jitter when rotating at 345°
|
||||
|
||||
### Changed
|
||||
|
||||
- **viewer**: Redesign the 3D turntable ruler slider with an enclosed capsule track, encapsulated ±15° step buttons, vertically centered ticks, a center red indicator, and a responsive mobile layout with the bottom bar reset button removed
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { FileTypeDefinition } from '../types'
|
||||
import ModelViewer from './model-viewer'
|
||||
|
||||
export function secondToDegree(second: number): number {
|
||||
const frameIndex = Math.min(Math.max(0, Math.round(second * 6)), 23)
|
||||
return (frameIndex * 15) % 360
|
||||
}
|
||||
import { secondToDegree } from './utils'
|
||||
export { secondToDegree } from './utils'
|
||||
|
||||
export const modelTypeDefinition: FileTypeDefinition = {
|
||||
id: '3d',
|
||||
|
||||
@@ -6,11 +6,13 @@ import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
import type { FileViewerProps, MediaController } from '../types'
|
||||
import { centeredPan, fitScale, zoomAtPoint } from '../pan-zoom'
|
||||
import { ModelControlBar } from './model-control-bar'
|
||||
import { secondToDegree } from './index'
|
||||
|
||||
const TOTAL_FRAMES = 24
|
||||
const FPS = 6
|
||||
const FRAME_DURATION = 1 / FPS
|
||||
import {
|
||||
secondToDegree,
|
||||
secondToFrame,
|
||||
calculateFrameCenterTime,
|
||||
TOTAL_FRAMES,
|
||||
FRAME_DURATION,
|
||||
} from './utils'
|
||||
|
||||
export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
(
|
||||
@@ -101,7 +103,7 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
const normalizedFrame = ((frameIndex % TOTAL_FRAMES) + TOTAL_FRAMES) % TOTAL_FRAMES
|
||||
const targetSec = normalizedFrame * FRAME_DURATION
|
||||
if (videoRef.current) {
|
||||
videoRef.current.currentTime = targetSec
|
||||
videoRef.current.currentTime = calculateFrameCenterTime(normalizedFrame)
|
||||
}
|
||||
setCurrentTime(targetSec)
|
||||
onTimeUpdate?.(targetSec)
|
||||
@@ -111,6 +113,7 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
|
||||
const seekToDegree = useCallback(
|
||||
(degree: number) => {
|
||||
videoRef.current?.pause()
|
||||
const frame = Math.round((((degree % 360) + 360) % 360) / 15) % TOTAL_FRAMES
|
||||
seekToFrame(frame)
|
||||
},
|
||||
@@ -139,7 +142,7 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
videoRef.current?.pause()
|
||||
},
|
||||
seekTo: (second: number) => {
|
||||
seekToFrame(Math.floor(second * FPS))
|
||||
seekToFrame(secondToFrame(second))
|
||||
},
|
||||
getCurrentTime: () => videoRef.current?.currentTime || 0,
|
||||
getDuration: () => 4,
|
||||
@@ -165,11 +168,11 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
togglePlay()
|
||||
} else if (e.key === 'ArrowLeft') {
|
||||
e.preventDefault()
|
||||
const currentFrame = Math.round(currentTime * FPS)
|
||||
const currentFrame = secondToFrame(currentTime)
|
||||
seekToFrame(currentFrame - 1)
|
||||
} else if (e.key === 'ArrowRight') {
|
||||
e.preventDefault()
|
||||
const currentFrame = Math.round(currentTime * FPS)
|
||||
const currentFrame = secondToFrame(currentTime)
|
||||
seekToFrame(currentFrame + 1)
|
||||
}
|
||||
}
|
||||
@@ -185,7 +188,7 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
target.setPointerCapture(e.pointerId)
|
||||
videoRef.current?.pause()
|
||||
|
||||
const currentFrame = Math.floor(currentTime * FPS)
|
||||
const currentFrame = Math.round(currentDegree / 15) % TOTAL_FRAMES
|
||||
dragStartRef.current = {
|
||||
clientX: e.clientX,
|
||||
frame: currentFrame,
|
||||
@@ -308,7 +311,7 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
onLoadedData={() => {
|
||||
setIsLoading(false)
|
||||
if (startTime && startTime > 0) {
|
||||
seekToFrame(Math.floor(startTime * FPS))
|
||||
seekToFrame(secondToFrame(startTime))
|
||||
}
|
||||
}}
|
||||
onPlay={() => {
|
||||
@@ -320,7 +323,7 @@ export const ModelViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
onPause?.()
|
||||
}}
|
||||
onTimeUpdate={() => {
|
||||
if (videoRef.current && !isDraggingRotation) {
|
||||
if (videoRef.current && !isDraggingRotation && isPlaying) {
|
||||
setCurrentTime(videoRef.current.currentTime)
|
||||
onTimeUpdate?.(videoRef.current.currentTime)
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ export const RulerSlider: React.FC<RulerSliderProps> = ({
|
||||
// Dragging left (deltaX < 0) rotates turntable forward (angle increases)
|
||||
const nextRawDegree = dragStartRef.current.startDegree - deltaX / PX_PER_DEGREE
|
||||
const snapped = (((Math.round(nextRawDegree / STEP) * STEP) % 360) + 360) % 360
|
||||
setDragDegree(snapped)
|
||||
setDragDegree(nextRawDegree)
|
||||
onChange(snapped)
|
||||
},
|
||||
[isDragging, disabled, onChange],
|
||||
@@ -79,7 +79,8 @@ export const RulerSlider: React.FC<RulerSliderProps> = ({
|
||||
if (!isDragging) return
|
||||
setIsDragging(false)
|
||||
if (dragDegree !== null) {
|
||||
onChange(dragDegree)
|
||||
const snapped = (((Math.round(dragDegree / STEP) * STEP) % 360) + 360) % 360
|
||||
onChange(snapped)
|
||||
}
|
||||
setDragDegree(null)
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
calculateFrameCenterTime,
|
||||
secondToFrame,
|
||||
secondToDegree,
|
||||
TOTAL_FRAMES,
|
||||
FPS,
|
||||
FRAME_DURATION,
|
||||
} from './utils'
|
||||
|
||||
describe('model viewer utils', () => {
|
||||
describe('calculateFrameCenterTime', () => {
|
||||
it('calculates the center time for frame 0', () => {
|
||||
expect(calculateFrameCenterTime(0)).toBeCloseTo(0.5 / FPS)
|
||||
})
|
||||
|
||||
it('calculates the center time for all frames 0 to 23', () => {
|
||||
for (let i = 0; i < TOTAL_FRAMES; i++) {
|
||||
const center = calculateFrameCenterTime(i)
|
||||
expect(center).toBeCloseTo((i + 0.5) * FRAME_DURATION)
|
||||
}
|
||||
})
|
||||
|
||||
it('handles negative and wrapping frames properly', () => {
|
||||
expect(calculateFrameCenterTime(-1)).toBeCloseTo(calculateFrameCenterTime(23))
|
||||
expect(calculateFrameCenterTime(24)).toBeCloseTo(calculateFrameCenterTime(0))
|
||||
})
|
||||
})
|
||||
|
||||
describe('secondToFrame', () => {
|
||||
it('correctly maps frame start times to frame index without float truncation', () => {
|
||||
for (let i = 0; i < TOTAL_FRAMES; i++) {
|
||||
const startSec = i * FRAME_DURATION
|
||||
expect(secondToFrame(startSec)).toBe(i)
|
||||
}
|
||||
})
|
||||
|
||||
it('correctly maps frame center times to frame index', () => {
|
||||
for (let i = 0; i < TOTAL_FRAMES; i++) {
|
||||
const centerSec = calculateFrameCenterTime(i)
|
||||
expect(secondToFrame(centerSec)).toBe(i)
|
||||
}
|
||||
})
|
||||
|
||||
it('clamps values below 0 and above total duration', () => {
|
||||
expect(secondToFrame(-1)).toBe(0)
|
||||
expect(secondToFrame(100)).toBe(TOTAL_FRAMES - 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('secondToDegree', () => {
|
||||
it('returns 0 for 0s', () => {
|
||||
expect(secondToDegree(0)).toBe(0)
|
||||
})
|
||||
|
||||
it('returns exact degrees (0..345) for every frame center', () => {
|
||||
for (let i = 0; i < TOTAL_FRAMES; i++) {
|
||||
const center = calculateFrameCenterTime(i)
|
||||
expect(secondToDegree(center)).toBe((i * 15) % 360)
|
||||
}
|
||||
})
|
||||
|
||||
it('returns exact degrees for frame start times', () => {
|
||||
for (let i = 0; i < TOTAL_FRAMES; i++) {
|
||||
const start = i * FRAME_DURATION
|
||||
expect(secondToDegree(start)).toBe((i * 15) % 360)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
export const TOTAL_FRAMES = 24
|
||||
export const FPS = 6
|
||||
export const FRAME_DURATION = 1 / FPS
|
||||
|
||||
/**
|
||||
* Calculates the presentation time at the center of a frame.
|
||||
* Seeking to the frame center avoids PTS boundary inaccuracies in browser video decoders.
|
||||
*/
|
||||
export function calculateFrameCenterTime(frameIndex: number): number {
|
||||
const normalizedFrame = ((frameIndex % TOTAL_FRAMES) + TOTAL_FRAMES) % TOTAL_FRAMES
|
||||
return (normalizedFrame + 0.5) * FRAME_DURATION
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a playback second into a frame index (0..23), clamped.
|
||||
* Works with frame start times, frame center times, or continuous playback seconds.
|
||||
*/
|
||||
export function secondToFrame(second: number): number {
|
||||
return Math.min(Math.max(0, Math.floor(second * FPS + 1e-4)), TOTAL_FRAMES - 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a second to turntable degree (0, 15, 30, ..., 345).
|
||||
*/
|
||||
export function secondToDegree(second: number): number {
|
||||
const frameIndex = secondToFrame(second)
|
||||
return (frameIndex * 15) % 360
|
||||
}
|
||||
Binary file not shown.
@@ -192,3 +192,38 @@ export const sampleAudioAsset: AssetInfo = {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const TURNTABLE_VIDEO_URL = '/turntable.mp4'
|
||||
export const TURNTABLE_FRAME_RATE = 6
|
||||
export const TURNTABLE_TOTAL_FRAMES = 24
|
||||
export const TURNTABLE_DURATION = 4.0
|
||||
export const TURNTABLE_WIDTH = 1080
|
||||
export const TURNTABLE_HEIGHT = 1080
|
||||
|
||||
export const sampleTurntableAsset: AssetInfo = {
|
||||
id: 'e2e-turntable-asset',
|
||||
name: 'turntable.glb',
|
||||
proxyType: '3d',
|
||||
type: 'file',
|
||||
status: 'ready',
|
||||
sizeByte: 314488,
|
||||
fileCount: 1,
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
updatedAt: '2026-01-01T00:00:00.000Z',
|
||||
media: {
|
||||
proxyType: '3d',
|
||||
videoPreview: {
|
||||
url: TURNTABLE_VIDEO_URL,
|
||||
},
|
||||
original: {
|
||||
key: 'turntable.glb',
|
||||
},
|
||||
metadata: {
|
||||
duration: TURNTABLE_DURATION,
|
||||
originalWidth: TURNTABLE_WIDTH,
|
||||
originalHeight: TURNTABLE_HEIGHT,
|
||||
frameRate: TURNTABLE_FRAME_RATE,
|
||||
totalFrames: TURNTABLE_TOTAL_FRAMES,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { type ReactElement, useCallback, useRef, useState } from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import type { MediaController } from '@/ui/components/viewers/types'
|
||||
import VideoPlayer from '@/ui/components/viewers/video/video-viewer'
|
||||
import ModelViewer from '@/ui/components/viewers/model/model-viewer'
|
||||
import { calculateFrameCenterTime } from '@/ui/components/viewers/video/utils'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import {
|
||||
@@ -10,6 +11,7 @@ import {
|
||||
containerLongerVideoAsset,
|
||||
longAudioVideoAsset,
|
||||
sampleAudioAsset,
|
||||
sampleTurntableAsset,
|
||||
} from './fixture'
|
||||
|
||||
/**
|
||||
@@ -60,6 +62,7 @@ function resolveAsset() {
|
||||
if (variant === 'container-longer') return containerLongerVideoAsset
|
||||
if (variant === 'long-audio') return longAudioVideoAsset
|
||||
if (variant === 'audio') return sampleAudioAsset
|
||||
if (variant === '3d' || variant === 'turntable') return sampleTurntableAsset
|
||||
return sampleVideoAsset
|
||||
}
|
||||
|
||||
@@ -132,12 +135,21 @@ function Harness(): ReactElement {
|
||||
style={{ width: '800px', height: '600px', display: 'flex', overflow: 'hidden' }}
|
||||
>
|
||||
<div className="flex flex-col flex-1 h-full overflow-hidden relative">
|
||||
<VideoPlayer
|
||||
key={playerKey}
|
||||
file={harnessAsset}
|
||||
ref={playerRef}
|
||||
onTimeUpdate={handleTimeUpdate}
|
||||
/>
|
||||
{harnessAsset.proxyType === '3d' ? (
|
||||
<ModelViewer
|
||||
key={playerKey}
|
||||
file={harnessAsset}
|
||||
ref={playerRef}
|
||||
onTimeUpdate={handleTimeUpdate}
|
||||
/>
|
||||
) : (
|
||||
<VideoPlayer
|
||||
key={playerKey}
|
||||
file={harnessAsset}
|
||||
ref={playerRef}
|
||||
onTimeUpdate={handleTimeUpdate}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ const server = Bun.serve({
|
||||
new Response(Bun.file(join(fixturesDir, 'sample-audio.mp4')), {
|
||||
headers: { 'Content-Type': 'video/mp4' },
|
||||
}),
|
||||
'/turntable.mp4': () =>
|
||||
new Response(Bun.file(join(fixturesDir, 'turntable.mp4')), {
|
||||
headers: { 'Content-Type': 'video/mp4' },
|
||||
}),
|
||||
'/': index,
|
||||
'/*': index,
|
||||
},
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { ModelViewerPage } from '../pages/model-viewer.page'
|
||||
|
||||
test.describe('3D Asset Viewer E2E Tests', () => {
|
||||
/**
|
||||
* ISSUE 1 VERIFICATION:
|
||||
* Asserts that all 24 frames across 0° to 345° have completely unique visual scenes.
|
||||
* Specifically, verifies that pairs like [0°, 15°], [45°, 60°], [90°, 105°], etc.
|
||||
* decode distinct frames instead of showing the same scene.
|
||||
*/
|
||||
test('Issue 1: verifies all 24 degree angles render unique visual frames', async ({ page }) => {
|
||||
const viewer = new ModelViewerPage(page)
|
||||
await viewer.goto()
|
||||
|
||||
// Step through each of the 24 angles: 0°, 15°, 30°, 45°, ..., 345°
|
||||
const snapshots: Array<{ degree: number; currentTime: number; frameHash: string }> = []
|
||||
|
||||
for (let i = 0; i < 24; i++) {
|
||||
// Allow video element decoding and frame presentation to settle
|
||||
await page.waitForTimeout(100)
|
||||
const snap = await viewer.snapshot()
|
||||
snapshots.push(snap)
|
||||
|
||||
if (i < 23) {
|
||||
await viewer.stepPlus()
|
||||
}
|
||||
}
|
||||
|
||||
console.log('--- SNAPSHOTS ACROSS ALL 24 STEPS ---')
|
||||
for (const snap of snapshots) {
|
||||
console.log(
|
||||
`Degree: ${snap.degree}°, currentTime: ${snap.currentTime.toFixed(6)}, frameHash: ${snap.frameHash}`,
|
||||
)
|
||||
}
|
||||
|
||||
// Verify all 24 frames have unique hashes
|
||||
const uniqueHashes = new Set(snapshots.map((s) => s.frameHash))
|
||||
expect(uniqueHashes.size).toBe(24)
|
||||
|
||||
// Verify all adjacent pairs have distinct scenes
|
||||
for (let i = 0; i < 23; i++) {
|
||||
const snapA = snapshots[i]
|
||||
const snapB = snapshots[i + 1]
|
||||
expect(snapA.frameHash).not.toBe(snapB.frameHash)
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* ISSUE 2 VERIFICATION (Surface):
|
||||
* Asserts that at 345°, starting a drag or making small drag movements
|
||||
* maintains the 345° position rather than snapping backwards to 330°.
|
||||
*/
|
||||
test('Issue 2: verifies drag-to-rotate on viewer surface at 345 degrees does not jitter', async ({
|
||||
page,
|
||||
}) => {
|
||||
const viewer = new ModelViewerPage(page)
|
||||
await viewer.goto()
|
||||
|
||||
// Step backward from 0° -> wraps to 345°
|
||||
await viewer.stepMinus()
|
||||
await page.waitForTimeout(100)
|
||||
|
||||
const initialSnap = await viewer.snapshot()
|
||||
expect(initialSnap.degree).toBe(345)
|
||||
|
||||
const box = await viewer.surface.boundingBox()
|
||||
if (!box) throw new Error('Surface box not found')
|
||||
const startX = box.x + box.width / 2
|
||||
const startY = box.y + box.height / 2
|
||||
|
||||
// Mouse down at 345°
|
||||
await page.mouse.move(startX, startY)
|
||||
await page.mouse.down()
|
||||
|
||||
// Small drag of -4px (less than 12px / 2 = 6px threshold for 1 frame)
|
||||
await page.mouse.move(startX - 4, startY, { steps: 2 })
|
||||
await page.waitForTimeout(50)
|
||||
const degreeSmallDrag = await viewer.getDegree()
|
||||
// Must remain at 345° (no jitter back to 330°)
|
||||
expect(degreeSmallDrag).toBe(345)
|
||||
|
||||
// Drag left by -12px (rotates counterclockwise by 1 frame: 345° -> 0°)
|
||||
await page.mouse.move(startX - 12, startY, { steps: 2 })
|
||||
await page.waitForTimeout(50)
|
||||
const degreeCcw = await viewer.getDegree()
|
||||
expect(degreeCcw).toBe(0)
|
||||
|
||||
// Drag back to start position (0px delta relative to start)
|
||||
await page.mouse.move(startX, startY, { steps: 2 })
|
||||
await page.waitForTimeout(50)
|
||||
const degreeBack = await viewer.getDegree()
|
||||
expect(degreeBack).toBe(345)
|
||||
|
||||
// Drag right by +12px (rotates clockwise by 1 frame: 345° -> 330°)
|
||||
await page.mouse.move(startX + 12, startY, { steps: 2 })
|
||||
await page.waitForTimeout(50)
|
||||
const degreeCw = await viewer.getDegree()
|
||||
expect(degreeCw).toBe(330)
|
||||
|
||||
await page.mouse.up()
|
||||
})
|
||||
|
||||
/**
|
||||
* ISSUE 2 VERIFICATION (Slider):
|
||||
* Asserts that dragging the ruler slider across 345° and 0° scrolls smoothly
|
||||
* and transitions between angles cleanly.
|
||||
*/
|
||||
test('Issue 2 (slider): verifies dragging ruler slider across 345° and 0° transitions smoothly', async ({
|
||||
page,
|
||||
}) => {
|
||||
const viewer = new ModelViewerPage(page)
|
||||
await viewer.goto()
|
||||
|
||||
// Navigate to 345°
|
||||
await viewer.stepMinus()
|
||||
await page.waitForTimeout(100)
|
||||
expect(await viewer.getDegree()).toBe(345)
|
||||
|
||||
const sliderBox = await viewer.rulerSlider.boundingBox()
|
||||
if (!sliderBox) throw new Error('Slider box not found')
|
||||
const startX = sliderBox.x + sliderBox.width / 2
|
||||
const startY = sliderBox.y + sliderBox.height / 2
|
||||
|
||||
await page.mouse.move(startX, startY)
|
||||
await page.mouse.down()
|
||||
|
||||
// Drag slightly left (-12px) across 345° towards 0°
|
||||
await page.mouse.move(startX - 12, startY, { steps: 2 })
|
||||
await page.waitForTimeout(50)
|
||||
const degCross = await viewer.getDegree()
|
||||
expect(degCross).toBe(0)
|
||||
|
||||
// Drag further left (-32px) to 15°
|
||||
await page.mouse.move(startX - 32, startY, { steps: 2 })
|
||||
await page.waitForTimeout(50)
|
||||
const degFurther = await viewer.getDegree()
|
||||
expect(degFurther).toBe(15)
|
||||
|
||||
// Drag back to 0px
|
||||
await page.mouse.move(startX, startY, { steps: 2 })
|
||||
await page.waitForTimeout(50)
|
||||
const degBack = await viewer.getDegree()
|
||||
expect(degBack).toBe(345)
|
||||
|
||||
await page.mouse.up()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user