feat(agent): support 3D degree comments, markup annotations, and config3d in read_asset (#473)

* feat(agent): support AI embedding, autofill, and read_asset for 3D assets

* feat(agent): support 3D degree comments, markup annotations, and config3d in read_asset

* fix(agent): resolve 3D session annotations to turntable degree frame time
This commit is contained in:
Yiling-J
2026-10-13 00:03:21 +08:00
committed by GitHub
parent 0f9d213b1d
commit fe8d404a44
26 changed files with 1687 additions and 21 deletions
+90
View File
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest'
import {
calculateTurntableFrameCenterTime,
degreeToSecond,
degreeToTurntableFrame,
isValidTurntableDegree,
secondToDegree,
secondToTurntableFrame,
TOTAL_TURNTABLE_FRAMES,
TURNTABLE_FPS,
} from './model3d'
describe('model3d utils', () => {
describe('secondToTurntableFrame', () => {
it('converts playback seconds to frame indices (0..23)', () => {
expect(secondToTurntableFrame(0)).toBe(0)
expect(secondToTurntableFrame(0.167)).toBe(1)
expect(secondToTurntableFrame(0.5)).toBe(3)
expect(secondToTurntableFrame(2.0)).toBe(12)
expect(secondToTurntableFrame(3.9)).toBe(23)
})
it('clamps out-of-range seconds', () => {
expect(secondToTurntableFrame(-1)).toBe(0)
expect(secondToTurntableFrame(10)).toBe(TOTAL_TURNTABLE_FRAMES - 1)
})
})
describe('secondToDegree', () => {
it('converts seconds to turntable degrees (0, 15, ..., 345)', () => {
expect(secondToDegree(0)).toBe(0)
expect(secondToDegree(1 / TURNTABLE_FPS)).toBe(15)
expect(secondToDegree(0.5)).toBe(45)
expect(secondToDegree(2.0)).toBe(180)
expect(secondToDegree(3.9)).toBe(345)
})
})
describe('degreeToTurntableFrame', () => {
it('converts discrete degrees to frame indices', () => {
expect(degreeToTurntableFrame(0)).toBe(0)
expect(degreeToTurntableFrame(15)).toBe(1)
expect(degreeToTurntableFrame(45)).toBe(3)
expect(degreeToTurntableFrame(90)).toBe(6)
expect(degreeToTurntableFrame(180)).toBe(12)
expect(degreeToTurntableFrame(345)).toBe(23)
})
it('normalizes degrees outside [0, 360)', () => {
expect(degreeToTurntableFrame(360)).toBe(0)
expect(degreeToTurntableFrame(-15)).toBe(23)
expect(degreeToTurntableFrame(720)).toBe(0)
})
})
describe('calculateTurntableFrameCenterTime and degreeToSecond', () => {
it('calculates frame center times within bounds', () => {
const centerTime0 = calculateTurntableFrameCenterTime(0)
expect(centerTime0).toBeCloseTo(0.5 / TURNTABLE_FPS)
const centerTime23 = calculateTurntableFrameCenterTime(23)
expect(centerTime23).toBeLessThan(TOTAL_TURNTABLE_FRAMES / TURNTABLE_FPS)
expect(centerTime23).toBeGreaterThan(23 / TURNTABLE_FPS)
expect(degreeToSecond(0)).toBeCloseTo(centerTime0)
expect(degreeToSecond(45)).toBeCloseTo((3 + 0.5) / TURNTABLE_FPS)
expect(degreeToSecond(345)).toBeCloseTo(centerTime23)
})
})
describe('isValidTurntableDegree', () => {
it('returns true for integer multiples of 15 from 0 to 345', () => {
for (let deg = 0; deg < 360; deg += 15) {
expect(isValidTurntableDegree(deg)).toBe(true)
}
})
it('returns false for non-multiples of 15', () => {
expect(isValidTurntableDegree(10)).toBe(false)
expect(isValidTurntableDegree(44)).toBe(false)
expect(isValidTurntableDegree(45.5)).toBe(false)
})
it('returns false for out of range or negative degrees', () => {
expect(isValidTurntableDegree(-15)).toBe(false)
expect(isValidTurntableDegree(360)).toBe(false)
expect(isValidTurntableDegree(720)).toBe(false)
})
})
})
+58
View File
@@ -0,0 +1,58 @@
export const TOTAL_TURNTABLE_FRAMES = 24
export const TURNTABLE_FPS = 6
export const TURNTABLE_FRAME_DURATION = 1 / TURNTABLE_FPS
/**
* Converts a playback second into a turntable frame index (0..23), clamped.
*/
export function secondToTurntableFrame(second: number): number {
return Math.min(
Math.max(0, Math.floor(second * TURNTABLE_FPS + 1e-4)),
TOTAL_TURNTABLE_FRAMES - 1,
)
}
/**
* Converts a turntable playback second to turntable degree (0, 15, 30, ..., 345).
*/
export function secondToDegree(second: number): number {
const frameIndex = secondToTurntableFrame(second)
return (frameIndex * 15) % 360
}
/**
* Calculates the presentation time within a turntable frame.
* Seeking near frame center avoids PTS boundary inaccuracies in video decoders.
*/
export function calculateTurntableFrameCenterTime(frameIndex: number): number {
const normalizedFrame =
((frameIndex % TOTAL_TURNTABLE_FRAMES) + TOTAL_TURNTABLE_FRAMES) % TOTAL_TURNTABLE_FRAMES
if (normalizedFrame === TOTAL_TURNTABLE_FRAMES - 1) {
return normalizedFrame * TURNTABLE_FRAME_DURATION + TURNTABLE_FRAME_DURATION * 0.25
}
return (normalizedFrame + 0.5) * TURNTABLE_FRAME_DURATION
}
/**
* Converts a rotation degree (0..345) to a turntable frame index (0..23).
*/
export function degreeToTurntableFrame(degree: number): number {
const normalizedDegree = ((Math.round(degree) % 360) + 360) % 360
return Math.round(normalizedDegree / 15) % TOTAL_TURNTABLE_FRAMES
}
/**
* Converts a rotation degree into a turntable video playback second (center time of that frame).
*/
export function degreeToSecond(degree: number): number {
const frameIndex = degreeToTurntableFrame(degree)
return calculateTurntableFrameCenterTime(frameIndex)
}
/**
* Validates whether a degree is a valid discrete turntable angle:
* integer multiple of 15 between 0 and 345 inclusive (0, 15, 30, ..., 345).
*/
export function isValidTurntableDegree(degree: number): boolean {
return Number.isInteger(degree) && degree >= 0 && degree <= 345 && degree % 15 === 0
}