feat: validate per-body mouth timelines and reviewed conversation routes

This commit is contained in:
zenord
2026-10-13 01:23:43 +08:00
parent 4358fc9cae
commit 4ead34a944
17 changed files with 646 additions and 61 deletions
@@ -4,12 +4,34 @@ data class MouthPatchLevel(val levelIndex: Int,val aperture: Float,val path: Str
data class RegisteredMouthPatch(val frameIndex: Int,val ptsUs: Long,val path: String,val sha256: String,
val x: Float,val y: Float,val width: Int,val height: Int,val levels: List<MouthPatchLevel> = emptyList())
data class ContinuousBodyAsset(val path: String,val sha256: String,val width: Int,val height: Int,
val frameCount: Int,val durationUs: Long)
val frameCount: Int,val durationUs: Long,
val ptsUs: List<Long> = List(frameCount) { it*1_000_000L/24 },
val fpsNumerator: Int = 24,val fpsDenominator: Int = 1)
data class ContinuousAvatarPack(val body: ContinuousBodyAsset,val patches: List<RegisteredMouthPatch>,
val curves: Map<String,MouthCurve>,val root: String,val manifestSha: String,val apertureMode: Boolean=false) {
val textureImages: List<MouthPatchLevel> = patches.flatMap { p ->
if(apertureMode) p.levels else listOf(MouthPatchLevel(0,1f,p.path,p.sha256))
}
val rgbaBytes: Long get() = patches.sumOf { it.width*it.height*4L*(if(apertureMode) 5 else 1) }
}
/** Metadata validation only; importer must additionally verify decoded frame PTS. */
object BodyTimeline {
const val MAX_TALK_FRAMES = 720
const val MAX_RGBA_BYTES = 8_000_000L
const val MAX_PACK_CACHE_BYTES = 32_000_000L
fun valid(pts: List<Long>,count: Int,durationUs: Long,fpsNumerator: Int,fpsDenominator: Int,
maxFrames: Int = MAX_TALK_FRAMES,maxDurationUs: Long = 30_000_000): Boolean {
if(count !in 2..maxFrames || pts.size!=count || durationUs !in 100_000..maxDurationUs ||
fpsNumerator !in 1..120_000 || fpsDenominator !in 1..10_000) return false
val fps=fpsNumerator.toDouble()/fpsDenominator
if(fps !in 1.0..60.0 || pts.first()!=0L || pts.last()>=durationUs ||
pts.zipWithNext().any { (a,b)->a<0 || b<=a }) return false
val period=1_000_000.0/fps
return kotlin.math.abs(durationUs-count*period)<=period+2 &&
durationUs-pts.last()<=period*2+2 &&
pts.zipWithNext().all { (a,b)->b-a<=period*2+2 }
}
}
/** This parser admits only coordinator-selected debug runtime data; no production graph. */
@@ -23,34 +45,40 @@ object ContinuousAvatarManifest {
fun smallInt(v: Any?): Int { val n=integer(v);require(n in 0..1_000_000);return n.toInt() }
fun finite(v: Any?): Float { val f=(v as Number).toFloat(); require(f.isFinite()); return f }
fun hash(v: Any?)=(v as String).also { require(it.matches(Regex("[0-9a-f]{64}"))) }
val apertureMode=root["packId"]=="a01-neutral-graph-v1-runtime-04" ||
(root["packId"] as? String)?.matches(Regex("a01-expression-action-v1-[a-z0-9_-]+-runtime-04"))==true
require(integer(root["schemaVersion"])==1L && root["identityId"]=="a01" &&
val dynamic=(root["packId"] as? String)?.matches(Regex("a01-expression-action-v1-[a-z0-9_-]+-runtime-04"))==true
val apertureMode=root["packId"]=="a01-neutral-graph-v1-runtime-04" || dynamic
require(integer(root["schemaVersion"])==(if(dynamic) 2L else 1L) && root["identityId"]=="a01" &&
(apertureMode || root["packId"]=="a01-neutral-graph-v1-runtime-03"))
require(root["publishApproval"]==false && root["runtimeReady"]==true)
val b=obj(root["body"])
val count=smallInt(b["frameCount"]);require(count in 2..BodyTimeline.MAX_TALK_FRAMES)
val fpsN=smallInt(b["fpsNumerator"]);val fpsD=smallInt(b["fpsDenominator"])
val pts=if(dynamic) (b["ptsUs"] as List<*>).also { require(it.size==count) }.map(::integer) else List(count) { it*1_000_000L/24 }
val body=ContinuousBodyAsset(b["path"] as String,hash(b["sha256"]),smallInt(b["width"]),smallInt(b["height"]),
smallInt(b["frameCount"]),integer(b["durationUs"]))
count,integer(b["durationUs"]),pts,fpsN,fpsD)
require(body.path.matches(Regex("body/[a-zA-Z0-9_.-]+\\.mp4")))
require(body.width==480 && body.height==848 && body.frameCount==97 && kotlin.math.abs(body.durationUs-4_041_667)<=2)
require(integer(b["fpsNumerator"])==24L && integer(b["fpsDenominator"])==1L && b["hasAudio"]==false)
require(integer(b["frameDurationUsNumerator"])==1_000_000L && integer(b["frameDurationUsDenominator"])==24L)
require(body.width==480 && body.height==848 && b["hasAudio"]==false)
if(dynamic) require(BodyTimeline.valid(pts,count,body.durationUs,fpsN,fpsD)) else {
require(count==97 && kotlin.math.abs(body.durationUs-4_041_667)<=2 && fpsN==24 && fpsD==1)
require(integer(b["frameDurationUsNumerator"])==1_000_000L && integer(b["frameDurationUsDenominator"])==24L)
}
val patchFormat=obj(root["patchFormat"])
require(patchFormat["alphaEncoding"]=="straight_unassociated" && patchFormat["format"]=="PNG RGBA 8bit")
if(dynamic) require(hash(patchFormat["bodySha256"])==body.sha256)
if(apertureMode) {
require((patchFormat["apertureLevels"] as List<*>).map(::finite)==listOf(0f,.25f,.5f,.75f,1f))
require(patchFormat["requiresRendererExtension"]==true)
}
val rows=root["patches"] as List<Map<String,Any?>>; require(rows.size==97)
val rows=root["patches"] as List<Map<String,Any?>>; require(rows.size==count)
val patches=rows.mapIndexed { index,p ->
val patch=RegisteredMouthPatch(smallInt(p["frameIndex"]),integer(p["ptsUs"]),p["path"] as String,hash(p["sha256"]),
finite(p["x"]),finite(p["y"]),smallInt(p["width"]),smallInt(p["height"]))
require(patch.frameIndex==index && kotlin.math.abs(patch.ptsUs-index*1_000_000L/24)<=2)
require(patch.frameIndex==index && if(dynamic) patch.ptsUs==pts[index] else kotlin.math.abs(patch.ptsUs-pts[index])<=2)
require(patch.path.matches(Regex("patches/[a-zA-Z0-9_.-]+\\.png")))
require(patch.width in 1..128 && patch.height in 1..128 && patch.x>=0 && patch.y>=0 &&
patch.x+patch.width<=480 && patch.y+patch.height<=848)
if(apertureMode) {
val levels=(p["levels"] as List<Map<String,Any?>>).mapIndexed { level,row ->
val levels=(p["levels"] as List<Map<String,Any?>>).also { require(it.size==5) }.mapIndexed { level,row ->
require(level in 0..4 && smallInt(row["levelIndex"])==level && finite(row["aperture"])==level/4f)
MouthPatchLevel(level,level/4f,row["path"] as String,hash(row["sha256"])).also {
require(it.path.matches(Regex("patches/[a-zA-Z0-9_.-]+\\.png")))
@@ -64,19 +92,26 @@ object ContinuousAvatarManifest {
}
}
val paths=patches.flatMap { if(apertureMode) it.levels.map { l -> l.path } else listOf(it.path) }
require(paths.distinct().size==if(apertureMode) 485 else 97)
require(patches.sumOf { it.width*it.height*4L*(if(apertureMode) 5 else 1) }<=8_000_000)
require(paths.distinct().size==count*(if(apertureMode) 5 else 1))
require(patches.sumOf { it.width*it.height*4L*(if(apertureMode) 5 else 1) }<=BodyTimeline.MAX_RGBA_BYTES)
val states=root["mouthStates"] as List<Map<String,Any?>>
require(states.size==5)
val c=states.associateBy { it["id"] as String }
require(c.keys==setOf("idle","opening","talk1","talk2","end-talk"))
val curves=c.mapValues { (id,v) ->
val row=obj(v); val duration=integer(row["durationMs"])
val alpha=(row["globalAlphaByFrame"] as List<*>).map(::finite)
val alpha=(row["globalAlphaByFrame"] as List<*>).also { require(it.size in 2..60) }.map(::finite)
val bridge=id in setOf("opening","end-talk")
require(duration==if(bridge) 250L else 500L)
require(alpha.size==if(bridge) 6 else 12)
require(integer(row["frameCount"])==alpha.size.toLong() && integer(row["fpsNumerator"])==24L && integer(row["fpsDenominator"])==1L)
require(integer(row["frameCount"])==alpha.size.toLong())
val curvePts=if(dynamic) (row["ptsUs"] as List<*>).also { require(it.size==alpha.size) }.map(::integer) else alpha.indices.map { it*1_000_000L/24 }
if(dynamic) {
require(duration in 100..1_000 && BodyTimeline.valid(curvePts,alpha.size,duration*1000,
smallInt(row["fpsNumerator"]),smallInt(row["fpsDenominator"]),60,1_000_000))
} else {
require(duration==if(bridge) 250L else 500L)
require(alpha.size==if(bridge) 6 else 12)
require(integer(row["fpsNumerator"])==24L && integer(row["fpsDenominator"])==1L)
}
require(alpha.all { it in 0f..1f })
require(row["entryMouthAnchor"]==if(id in setOf("idle","opening")) "A" else "B")
require(row["exitMouthAnchor"]==if(id in setOf("idle","end-talk")) "A" else "B")
@@ -86,7 +121,7 @@ object ContinuousAvatarManifest {
"end-talk" -> require(alpha.first()==1f && alpha.last()==0f)
else -> require(alpha.first()==1f && alpha.last()==1f && alpha.min()<.5f)
}
MouthCurve(id,duration,alpha)
MouthCurve(id,duration,alpha,curvePts)
}
val routing=obj(root["stateRouting"])
val required=mapOf("idle" to setOf("idle","opening"),"opening" to setOf("talk1","talk2","end-talk"),
@@ -63,6 +63,7 @@ class ContinuousBodyRenderer(private val context: Context,private val pack: Cont
fun intent(talk: Boolean,generation: Long,revision: Long) { worker.post { if(alive.get()) gate.intent(talk,generation,revision,SystemClock.elapsedRealtime()) } }
fun resize(w: Int,h: Int) { worker.post { if(alive.get()) { width=w; height=h } } }
private fun initialize() {
check(pack.rgbaBytes<=BodyTimeline.MAX_RGBA_BYTES && pack.patches.size==pack.body.frameCount)
display=EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);check(display!=EGL14.EGL_NO_DISPLAY)
val version=IntArray(2);check(EGL14.eglInitialize(display,version,0,version,1))
val configs=arrayOfNulls<EGLConfig>(1);val count=IntArray(1)
@@ -149,7 +150,9 @@ class ContinuousBodyRenderer(private val context: Context,private val pack: Cont
check(!(info.size==0 && info.flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM!=0)) { "early_eos" }
val key=gate.decoded(info.presentationTimeUs)
waiting=true;lastIndex=key.index
val step=if(key.index==0) 41L else key.index*1000L/24-(key.index-1)*1000L/24
val pts=pack.body.ptsUs
val step=if(key.index==0) (pack.body.durationUs-pts.last())/1000 else
pts[key.index]/1000-pts[key.index-1]/1000
val delay=if(first) 0L else (lastPresentedMs+step-SystemClock.elapsedRealtime()).coerceAtLeast(0)
worker.postDelayed({ guarded {
worker.postDelayed(timeout,2_000)
@@ -13,7 +13,7 @@ data class ComposedBodyFrame(val key: BodyFrameKey,val patch: RegisteredMouthPat
/** The real EGL renderer uses this gate immediately around updateTexImage + draw/swap.
* No other thread can choose a patch or change body phase. close() fences stale output. */
class ContinuousFramePresenter(private val pack: ContinuousAvatarPack,choose: (Int)->Int = { kotlin.random.Random.nextInt(it) }) {
private val clock=ContinuousFrameClock(pack.body.frameCount)
private val clock=ContinuousFrameClock(pack.body.frameCount,pack.body.ptsUs)
private val mouth=ContinuousMouth(pack.curves,choose)
private var active=true
fun intent(talk: Boolean,generation: Long,revision: Long,nowMs: Long?=null): Boolean = active && mouth.request(talk,generation,revision,nowMs)
@@ -1,6 +1,7 @@
package com.gorios.lanvoice.avatar
data class MouthCurve(val id: String, val durationMs: Long, val alpha: List<Float>)
data class MouthCurve(val id: String, val durationMs: Long, val alpha: List<Float>,
val ptsUs: List<Long> = alpha.indices.map { it*1_000_000L/24 })
data class MouthLayerSample(val phase: String, val alpha: Float, val generation: Long, val revision: Long,
val phaseWaitMs: Long=0)
@@ -43,11 +44,13 @@ class ContinuousMouth(private val curves: Map<String,MouthCurve>, private val ch
val wait=if(satisfied) 0 else (nowMs-checkNotNull(requestedAt)).coerceAtLeast(0)
if (phase=="idle") return MouthLayerSample(phase,0f,generation,revision,wait)
val c=curves.getValue(phase)
// Authored endpoints are at (n-1)/24. Hold their value only for the last
// natural display interval; do not manufacture a body freeze or reverse.
val index=((nowMs-startedAt)*24.0/1000).coerceIn(0.0,(c.alpha.size-1).toDouble())
val lower=index.toInt(); val upper=minOf(lower+1,c.alpha.lastIndex)
val alpha=c.alpha[lower]+(c.alpha[upper]-c.alpha[lower])*(index-lower).toFloat()
val elapsedUs=(nowMs-startedAt)*1000
val found=c.ptsUs.binarySearch(elapsedUs)
val lower=if(found>=0) found else (-found-2).coerceAtLeast(0)
val upper=minOf(lower+1,c.alpha.lastIndex)
val fraction=if(lower==upper) 0f else ((elapsedUs-c.ptsUs[lower]).toDouble()/
(c.ptsUs[upper]-c.ptsUs[lower])).coerceIn(0.0,1.0).toFloat()
val alpha=c.alpha[lower]+(c.alpha[upper]-c.alpha[lower])*fraction
return MouthLayerSample(phase,alpha,generation,revision,wait)
}
private fun nextTalk(): String {
@@ -59,14 +62,16 @@ class ContinuousMouth(private val curves: Map<String,MouthCurve>, private val ch
data class BodyFrameKey(val index: Int, val loopOrdinal: Long, val ptsUs: Long)
/** Decoder order and SurfaceTexture consumption are separately checked. */
class ContinuousFrameClock(private val frames: Int=97) {
class ContinuousFrameClock(private val frames: Int=97,
private val pts: List<Long> = List(frames) { it*1_000_000L/24 }) {
init { require(pts.size==frames && frames>0) }
private var expected=0
private var loop=0L
private var pending: BodyFrameKey?=null
fun decoded(ptsUs: Long): BodyFrameKey {
check(pending==null)
val index=((ptsUs*24+500_000)/1_000_000).toInt()
check(index==expected && kotlin.math.abs(ptsUs-index*1_000_000L/24)<=2_000)
val index=expected
check(index in pts.indices && kotlin.math.abs(ptsUs-pts[index])<=2)
return BodyFrameKey(index,loop,ptsUs).also { pending=it }
}
fun latched(timestampNs: Long): BodyFrameKey {
@@ -0,0 +1,52 @@
package com.gorios.lanvoice.avatar
import com.gorios.lanvoice.dialogue.RoleEmotion
data class PreparedExpression(val turn: Long,val seq: Long,val emotion: RoleEmotion,val intensity: Int)
data class ConversationBridge(val serial: Long,val turn: Long,val edge: ConversationEdge)
/** Preparation never changes selected/visible packages. A final reply authorizes
* routing; a driver must present every reviewed bridge before acknowledging it. */
class ConversationPackagePlanner(private val index: EmotionActionIndex) {
var visiblePackage = index.fallbackId
private set
var selected: RoleVisualSelection? = null
private set
var prepared: PreparedExpression? = null
private set
private var turn = -1L
private var finalSeq = -1L
private var target = visiblePackage
private var inFlight: ConversationBridge? = null
private var bridgeSerial = 0L
private fun valid(value: PreparedExpression) = value.seq>=0 && value.intensity in
if(value.emotion==RoleEmotion.NEUTRAL) 0..0 else 1..2
fun newTurn(id: Long) {
require(id>=0);turn=id;finalSeq=-1;prepared=null;selected=null;target=visiblePackage
inFlight=null
}
fun prepare(value: PreparedExpression): Boolean {
if(!valid(value) || value.turn!=turn || value.seq<=finalSeq || value.seq<=(prepared?.seq ?: -1)) return false
prepared=value;return true
}
fun cancelPrepare(id: Long) { if(id==turn) prepared=null }
fun commit(value: PreparedExpression): Boolean {
if(!valid(value) || value.turn!=turn || value.seq<=finalSeq) return false
finalSeq=value.seq;prepared=null
selected=RoleVisualSelector.select(value.emotion,value.intensity,index.visuals,index.fallbackId)
target=checkNotNull(selected).packageId
return true
}
fun nextEdge(frame: Int): ConversationBridge? {
if(inFlight!=null || visiblePackage==target) return null
val candidates=index.edges.filter { it.from==visiblePackage && it.fromFrame==frame }
val edge=candidates.firstOrNull { it.to==target } ?: candidates.firstOrNull {
visiblePackage!=index.fallbackId && it.to==index.fallbackId
} ?: return null
return ConversationBridge(++bridgeSerial,turn,edge).also { inFlight=it }
}
fun presented(bridge: ConversationBridge,targetFrame: Int): Boolean {
if(bridge!=inFlight || bridge.turn!=turn || bridge.edge.toFrame!=targetFrame) return false
visiblePackage=bridge.edge.to;inFlight=null;return true
}
}
@@ -3,7 +3,9 @@ package com.gorios.lanvoice.avatar
import com.gorios.lanvoice.dialogue.RoleEmotion
data class EmotionActionIndex(val fallbackId: String, val packages: Map<String,ContinuousAvatarPack>,
val visuals: List<TalkPackage>, val actionPack: ReviewedActionPack?)
val visuals: List<TalkPackage>, val actionPack: ReviewedActionPack?, val edges: List<ConversationEdge> = emptyList())
data class ConversationEdge(val id: String,val from: String,val to: String,val fromFrame: Int,val toFrame: Int,
val clip: ContinuousBodyAsset)
/** Exact external manifest pin admits the whole graph. Self-approval fields have no effect.
* loadRuntime must hash-check exact bytes and all body/patch files before returning a pack.
@@ -21,6 +23,7 @@ object EmotionActionManifest {
}
fun hash(value: Any?)=(value as String).also { require(it.matches(Regex("[0-9a-f]{64}"))) }
fun integer(value: Any?): Long { val n=value as Number;require(n.toDouble()==n.toLong().toDouble());return n.toLong() }
fun boundedInt(value: Any?, maximum: Int): Int = integer(value).also { require(it in 1..maximum.toLong()) }.toInt()
val fallback=root["fallbackPackageId"] as String
val rows=root["conversationPackages"] as List<Map<String,Any?>>
require(rows.isNotEmpty() && rows.size<=12 && rows.map { it["id"] }.distinct().size==rows.size)
@@ -28,28 +31,43 @@ object EmotionActionManifest {
val visuals=rows.map { row ->
val id=row["id"] as String;require(id.matches(Regex("[a-z0-9_-]{1,48}")))
val emotion=RoleEmotion.entries.single { it.wire==row["emotion"] }
require(emotion!=RoleEmotion.ANGRY && integer(row["visualIntensity"])==if(emotion==RoleEmotion.NEUTRAL) 0L else 1L)
require(emotion in setOf(RoleEmotion.NEUTRAL,RoleEmotion.HAPPY,RoleEmotion.SAD) &&
integer(row["visualIntensity"])==if(emotion==RoleEmotion.NEUTRAL) 0L else 1L)
val reference=obj(row["runtimeManifest"])
val runtime=checkNotNull(loadRuntime(path(reference["path"]),hash(reference["sha256"])))
require(runtime.apertureMode && runtime.body.sha256==hash(row["mouthBodySha256"]))
require(runtime.patches.size==runtime.body.frameCount && runtime.patches.all { it.levels.size==5 })
require(runtime.body.ptsUs==runtime.patches.map { it.ptsUs } &&
BodyTimeline.valid(runtime.body.ptsUs,runtime.body.frameCount,runtime.body.durationUs,
runtime.body.fpsNumerator,runtime.body.fpsDenominator))
packages[id]=runtime
val pts=runtime.patches.map { it.ptsUs }
TalkPackage(id,emotion,runtime.body.sha256,hash(row["mouthBodySha256"]),pts,pts,false)
TalkPackage(id,emotion,runtime.body.sha256,hash(row["mouthBodySha256"]),runtime.body.ptsUs,pts,false)
}
require(packages.values.sumOf { it.rgbaBytes }<=BodyTimeline.MAX_PACK_CACHE_BYTES)
require(visuals.single { it.id==fallback }.emotion==RoleEmotion.NEUTRAL)
val edges=root["edges"] as List<Map<String,Any?>>
require(edges.size<=100 && edges.map { it["id"] }.distinct().size==edges.size)
edges.forEach { edge ->
val admittedEdges=edges.map { edge ->
require(edge["from"] in packages && edge["to"] in packages)
val from=checkNotNull(packages[edge["from"]]);val to=checkNotNull(packages[edge["to"]])
require(integer(edge["fromFrame"]) in 0 until from.body.frameCount.toLong())
require(integer(edge["toFrame"]) in 0 until to.body.frameCount.toLong())
require(edge["fromAnchor"]=="A" && edge["toAnchor"]=="A")
val clip=obj(edge["clip"]);path(clip["path"]);hash(clip["sha256"])
require(clip["hasAudio"]==false && integer(clip["frameCount"])>0 && integer(clip["durationUs"])>0)
val pts=(clip["ptsUs"] as List<*>).map(::integer)
require(pts.size==integer(clip["frameCount"]).toInt() && pts.first()==0L && pts.zipWithNext().all { (a,b)->a<b })
require(clip["hasAudio"]==false && integer(clip["width"])==480L && integer(clip["height"])==848L)
val count=boundedInt(clip["frameCount"],BodyTimeline.MAX_TALK_FRAMES)
val pts=(clip["ptsUs"] as List<*>).also { require(it.size==count) }.map(::integer)
require(BodyTimeline.valid(pts,count,integer(clip["durationUs"]),
boundedInt(clip["fpsNumerator"],120_000),boundedInt(clip["fpsDenominator"],10_000)))
val source=rows.single { it["id"]==edge["from"] }
require(integer(edge["fromFrame"]) in (source["legalExitFrames"] as List<*>).map(::integer))
require(integer(edge["fromPtsUs"])==from.body.ptsUs[integer(edge["fromFrame"]).toInt()])
require(integer(edge["toPtsUs"])==to.body.ptsUs[integer(edge["toFrame"]).toInt()])
ConversationEdge(edge["id"] as String,edge["from"] as String,edge["to"] as String,
integer(edge["fromFrame"]).toInt(),integer(edge["toFrame"]).toInt(),
ContinuousBodyAsset(path(clip["path"]),hash(clip["sha256"]),480,848,pts.size,
integer(clip["durationUs"]),pts,boundedInt(clip["fpsNumerator"],120_000),boundedInt(clip["fpsDenominator"],10_000)))
}
val admitted=visuals.map { visual ->
val row=rows.single { it["id"]==visual.id }
@@ -73,13 +91,16 @@ object EmotionActionManifest {
val clip=obj(action["clip"]);path(clip["path"]);hash(clip["sha256"])
val duration=integer(clip["durationUs"])
require(clip["hasAudio"]==true && integer(action["audioEndUs"]) in 1..duration)
val pts=(clip["ptsUs"] as List<*>).map(::integer)
require(pts.isNotEmpty() && pts.size==integer(clip["frameCount"]).toInt() && pts.zipWithNext().all { (a,b)->a<b })
val count=boundedInt(clip["frameCount"],5400)
val pts=(clip["ptsUs"] as List<*>).also { require(it.size==count) }.map(::integer)
require(integer(clip["width"])==480L && integer(clip["height"])==848L)
require(BodyTimeline.valid(pts,count,duration,
boundedInt(clip["fpsNumerator"],120_000),boundedInt(clip["fpsDenominator"],10_000),5400,90_000_000))
require(duration in 1_000_000..90_000_000)
ActionAsset(action["id"] as String,(duration+999)/1000)
}
ReviewedActionPack(actualSha,assets)
}
EmotionActionIndex(fallback,packages,admitted,actionPack)
EmotionActionIndex(fallback,packages,admitted,actionPack,admittedEdges)
} catch(_: Exception) { null }
}
@@ -13,7 +13,8 @@ data class TalkPackage(val id: String, val emotion: RoleEmotion, val bodySha: St
object RoleVisualSelector {
fun select(emotion: RoleEmotion, intensity: Int, packages: List<TalkPackage>, fallbackId: String): RoleVisualSelection {
fun valid(p: TalkPackage) = p.bodySha.matches(Regex("[0-9a-f]{64}")) &&
p.mouthBodySha == p.bodySha && p.framePtsUs.size == 97 &&
p.mouthBodySha == p.bodySha && p.framePtsUs.size in 2..BodyTimeline.MAX_TALK_FRAMES &&
p.framePtsUs.first()==0L &&
p.framePtsUs == p.mouthPtsUs && p.framePtsUs.zipWithNext().all { (a,b) -> a < b } && p.approvedEdges
val usable = packages.filter(::valid)
val same = usable.firstOrNull { it.emotion == emotion && emotion != RoleEmotion.ANGRY }