mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 16:28:42 +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
173 lines
4.6 KiB
TypeScript
173 lines
4.6 KiB
TypeScript
import type { WorkflowTask } from '@shumai/db'
|
|
import '@shumai/db/src/prisma-json-types'
|
|
import { executeActivity, getActivities } from '@shumai/workflow-core'
|
|
import {
|
|
getWorkerQueueAndStartTask,
|
|
fetchAssetWithKey,
|
|
completeTask,
|
|
failTask,
|
|
cleanupTmpDir,
|
|
} from './common'
|
|
|
|
export async function transcode3dWorkflow(task: WorkflowTask): Promise<void> {
|
|
let tmpDir: string | undefined
|
|
let workerQueue = ''
|
|
let mediaProcessed = false
|
|
|
|
try {
|
|
workerQueue = await getWorkerQueueAndStartTask(task)
|
|
|
|
const {
|
|
updateAssetStatusActivity,
|
|
downloadMediaToTmpActivity,
|
|
start3dRenderActivity,
|
|
waitFor3dVideoRenderActivity,
|
|
generate3dSpriteActivity,
|
|
updateAssetMediaActivity,
|
|
createEmbeddingTaskIfEnabledActivity,
|
|
createAutofillTaskIfEnabledActivity,
|
|
} = getActivities()
|
|
|
|
await executeActivity(workerQueue, updateAssetStatusActivity, {
|
|
assetId: task.assetId,
|
|
status: 'processing',
|
|
})
|
|
|
|
const { asset, key } = await fetchAssetWithKey(workerQueue, task.assetId)
|
|
|
|
const download = await executeActivity(workerQueue, downloadMediaToTmpActivity, {
|
|
assetKey: key,
|
|
})
|
|
const currentFilePath = download.filePath
|
|
tmpDir = download.tmpDir
|
|
|
|
const lastSlashIndex = key.lastIndexOf('/')
|
|
const assetDir = lastSlashIndex === -1 ? '' : key.substring(0, lastSlashIndex)
|
|
const videoKey = assetDir ? `${assetDir}/turntable.mp4` : 'turntable.mp4'
|
|
const posterKey = assetDir ? `${assetDir}/poster.webp` : 'poster.webp'
|
|
const spriteKey = assetDir ? `${assetDir}/sprite.webp` : 'sprite.webp'
|
|
|
|
const renderStart = await executeActivity(workerQueue, start3dRenderActivity, {
|
|
taskId: task.id,
|
|
teamId: task.teamId,
|
|
assetId: asset.id,
|
|
assetKey: key,
|
|
filePath: currentFilePath,
|
|
filename: asset.name || 'model.glb',
|
|
targetPosterKey: posterKey,
|
|
})
|
|
|
|
const posterWidth = renderStart.posterWidth || 1080
|
|
const posterHeight = renderStart.posterHeight || 1080
|
|
|
|
const mediaInfo: PrismaJson.MediaInfo = {
|
|
duration: 4,
|
|
filesize: 0,
|
|
frames: 24,
|
|
proxyType: '3d',
|
|
imageTranscodes: [],
|
|
videoTranscodes: [],
|
|
poster: {
|
|
key: posterKey,
|
|
},
|
|
finishedAt: new Date().toISOString(),
|
|
metadata: {
|
|
originalHeight: posterHeight,
|
|
originalWidth: posterWidth,
|
|
hasAudio: false,
|
|
duration: 4,
|
|
bitRate: 0,
|
|
frameRate: 6,
|
|
totalFrames: 24,
|
|
startTimecode: '00:00:00:00',
|
|
format: renderStart.modelMetadata ?? {},
|
|
},
|
|
original: {
|
|
key,
|
|
filesizeInBytes: Number(asset.sizeByte || 0),
|
|
codec: '',
|
|
},
|
|
}
|
|
|
|
await executeActivity(workerQueue, updateAssetMediaActivity, {
|
|
assetId: asset.id,
|
|
mediaInfo,
|
|
})
|
|
|
|
const renderVideo = await executeActivity(workerQueue, waitFor3dVideoRenderActivity, {
|
|
taskId: task.id,
|
|
teamId: task.teamId,
|
|
assetKey: key,
|
|
renderTaskId: renderStart.renderTaskId,
|
|
targetVideoKey: videoKey,
|
|
tmpDir,
|
|
})
|
|
|
|
await executeActivity(workerQueue, generate3dSpriteActivity, {
|
|
taskId: task.id,
|
|
assetKey: key,
|
|
videoFilePath: renderVideo.videoFilePath,
|
|
spriteKey,
|
|
})
|
|
|
|
mediaInfo.sprite = {
|
|
key: spriteKey,
|
|
frames: 100,
|
|
tileX: 10,
|
|
tileY: 10,
|
|
}
|
|
|
|
await executeActivity(workerQueue, updateAssetMediaActivity, {
|
|
assetId: asset.id,
|
|
mediaInfo,
|
|
})
|
|
|
|
mediaInfo.videoTranscodes = [
|
|
{
|
|
key: videoKey,
|
|
width: 1080,
|
|
height: 1080,
|
|
resolution: '1080p',
|
|
},
|
|
]
|
|
mediaInfo.videoPreview = {
|
|
key: videoKey,
|
|
width: 1080,
|
|
height: 1080,
|
|
resolution: '1080p',
|
|
}
|
|
mediaInfo.finishedAt = new Date().toISOString()
|
|
|
|
await executeActivity(workerQueue, updateAssetMediaActivity, {
|
|
assetId: asset.id,
|
|
mediaInfo,
|
|
})
|
|
|
|
await executeActivity(workerQueue, updateAssetStatusActivity, {
|
|
assetId: asset.id,
|
|
status: 'processed',
|
|
})
|
|
mediaProcessed = true
|
|
|
|
await executeActivity(workerQueue, createEmbeddingTaskIfEnabledActivity, {
|
|
assetId: asset.id,
|
|
teamId: task.teamId,
|
|
projectId: task.projectId,
|
|
})
|
|
|
|
await executeActivity(workerQueue, createAutofillTaskIfEnabledActivity, {
|
|
assetId: asset.id,
|
|
teamId: task.teamId,
|
|
projectId: task.projectId,
|
|
})
|
|
|
|
await completeTask(workerQueue, task.id)
|
|
} catch (err) {
|
|
console.error(`transcode3dWorkflow failed for task ${task.id}:`, err)
|
|
await failTask(workerQueue, task.id, err, mediaProcessed ? undefined : task.assetId)
|
|
throw err
|
|
} finally {
|
|
await cleanupTmpDir(workerQueue, tmpDir)
|
|
}
|
|
}
|