mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-21 09:31:20 -08:00
More cleanup. move ressouces in the right folder. Simplified override
This commit is contained in:
1 parent
3ee7f00e8d
commit
d49877668d
98 files changed
+340
-152
No files matched your search
@@ -37,7 +37,7 @@ import dev.slimevr.networkprofile.NetworkProfileManager
|
||||
import dev.slimevr.provisioning.ProvisioningManager
|
||||
import dev.slimevr.resets.ResetsManager
|
||||
import dev.slimevr.resourcepacks.ResourcePackManager
|
||||
import dev.slimevr.resourcepacks.compileResourcePacks
|
||||
import dev.slimevr.resourcepacks.compiler.compileResourcePacks
|
||||
import dev.slimevr.routing.BoneRoutingManager
|
||||
import dev.slimevr.skeleton.Skeleton
|
||||
import dev.slimevr.solarxr.rpc.ServerInfos
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
package dev.slimevr.resourcepacks.bones
|
||||
|
||||
import dev.slimevr.bones.BoneId
|
||||
import dev.slimevr.bones.BoneRegistry
|
||||
@@ -6,8 +6,16 @@ import dev.slimevr.bones.Constraint
|
||||
import dev.slimevr.bones.HingeConstraint
|
||||
import dev.slimevr.bones.LooseHingeConstraint
|
||||
import dev.slimevr.bones.TwistSwingConstraint
|
||||
import dev.slimevr.resourcepacks.bones.CompiledOffset
|
||||
import dev.slimevr.resourcepacks.bones.CompiledOffsetTerm
|
||||
import dev.slimevr.resourcepacks.Offset
|
||||
import dev.slimevr.resourcepacks.ParsedResourcePack
|
||||
import dev.slimevr.resourcepacks.ResourceTypes
|
||||
import dev.slimevr.resourcepacks.compiler.BoneContribution
|
||||
import dev.slimevr.resourcepacks.compiler.BoneField
|
||||
import dev.slimevr.resourcepacks.compiler.ProportionContribution
|
||||
import dev.slimevr.resourcepacks.compiler.ResourceOrigin
|
||||
import dev.slimevr.resourcepacks.compiler.ResourcePackCompilationDiagnostic
|
||||
import dev.slimevr.resourcepacks.compiler.diagnostic
|
||||
import dev.slimevr.resourcepacks.compiler.reportCycles
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import com.jme3.math.FastMath.DEG_TO_RAD as degToRad
|
||||
import dev.slimevr.resourcepacks.Constraint as PackConstraint
|
||||
@@ -85,7 +93,7 @@ internal fun compileOffset(
|
||||
}
|
||||
CompiledOffsetTerm(
|
||||
term.proportion,
|
||||
Vector3(term.direction.x, term.direction.y, term.direction.z)
|
||||
Vector3(term.direction.x, term.direction.y, term.direction.z),
|
||||
)
|
||||
}
|
||||
return CompiledOffset(base, terms)
|
||||
@@ -119,7 +127,7 @@ internal fun <T> orderFallbackDependencies(
|
||||
return result
|
||||
}
|
||||
|
||||
private const val DEFAULT_LANGUAGE_PATH = "assets/lang/en.json"
|
||||
private const val DEFAULT_LANGUAGE_PATH = "assets/slimevr/lang/en.json"
|
||||
|
||||
/**
|
||||
* The bone's compiled-in display name: its English translation if the pack ships one, else its
|
||||
@@ -140,15 +148,25 @@ internal fun validateHierarchy(
|
||||
if (roots.isEmpty()) {
|
||||
val overrideOrigin = bonesByKey.values.mapNotNull { it.originOrNull(BoneField.Parent) }.lastOrNull()
|
||||
diagnostics += overrideOrigin?.diagnostic("A resource-pack registry must have exactly one root; found none")
|
||||
?: ResourcePackCompilationDiagnostic(core.manifest.value.id, core.manifest.path, "A resource-pack registry must have exactly one root; found none")
|
||||
?: ResourcePackCompilationDiagnostic(
|
||||
core.manifest.value.id,
|
||||
core.manifest.path,
|
||||
"A resource-pack registry must have exactly one root; found none",
|
||||
)
|
||||
} else if (roots.size > 1) {
|
||||
for (contribution in roots) {
|
||||
diagnostics += contribution.origin(BoneField.Parent).diagnostic("A resource-pack registry must have exactly one root; found ${roots.size}")
|
||||
}
|
||||
}
|
||||
|
||||
reportCycles(bonesByKey.keys, { bonesByKey.getValue(it).resource.value.parent }) { start, _, cycle ->
|
||||
val overrideOrigin = cycle.mapNotNull { bonesByKey.getValue(it).originOrNull(BoneField.Parent) }.lastOrNull()
|
||||
diagnostics += bonesByKey.getValue(start).origin(overrideOrigin).diagnostic("Bone hierarchy contains a cycle: ${cycle.joinToString(" -> ")}")
|
||||
reportCycles(
|
||||
bonesByKey.keys,
|
||||
{ bonesByKey.getValue(it).resource.value.parent },
|
||||
) { start, _, cycle ->
|
||||
val overrideOrigin =
|
||||
cycle.mapNotNull { bonesByKey.getValue(it).originOrNull(BoneField.Parent) }
|
||||
.lastOrNull()
|
||||
diagnostics += bonesByKey.getValue(start).origin(overrideOrigin)
|
||||
.diagnostic("Bone hierarchy contains a cycle: ${cycle.joinToString(" -> ")}")
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ data class CompiledEmitEntry(
|
||||
data class CompiledVrchatOutput(val required: Boolean, val emit: Map<String, CompiledEmitEntry>)
|
||||
|
||||
/**
|
||||
* Everything [dev.slimevr.resourcepacks.compileResourcePacks] resolves for one bone: its offsets, constraint, routing
|
||||
* Everything [dev.slimevr.resourcepacks.compiler.compileResourcePacks] resolves for one bone: its offsets, constraint, routing
|
||||
* facts, and output/input declarations. A plain bone with none of these has every field null.
|
||||
*/
|
||||
data class CompiledBone(
|
||||
@@ -89,7 +89,7 @@ data class CompiledBone(
|
||||
|
||||
/**
|
||||
* The compiled bone registry, proportion catalog, and per-bone data produced by
|
||||
* [dev.slimevr.resourcepacks.compileResourcePacks].
|
||||
* [dev.slimevr.resourcepacks.compiler.compileResourcePacks].
|
||||
*/
|
||||
class CompiledSkeleton(
|
||||
val registry: BoneRegistry,
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
package dev.slimevr.resourcepacks.bones.outputs
|
||||
|
||||
import dev.slimevr.bones.BodyPart
|
||||
import dev.slimevr.bones.BoneId
|
||||
import dev.slimevr.bones.BoneMap
|
||||
import dev.slimevr.bones.BoneRegistry
|
||||
import dev.slimevr.bones.key
|
||||
import dev.slimevr.resourcepacks.VmcInputParent
|
||||
import dev.slimevr.resourcepacks.VmcOutput
|
||||
import dev.slimevr.resourcepacks.bones.CompiledVmcOutput
|
||||
import dev.slimevr.resourcepacks.bones.origin
|
||||
import dev.slimevr.resourcepacks.bones.resolveBoneKey
|
||||
import dev.slimevr.resourcepacks.compiler.BoneContribution
|
||||
import dev.slimevr.resourcepacks.compiler.BoneField
|
||||
import dev.slimevr.resourcepacks.compiler.ResourcePackCompilationDiagnostic
|
||||
import dev.slimevr.resourcepacks.compiler.diagnostic
|
||||
import dev.slimevr.resourcepacks.compiler.reportCycles
|
||||
import dev.slimevr.resourcepacks.compiler.reportDuplicateBoneKey
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlin.collections.iterator
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
import com.jme3.math.FastMath.DEG_TO_RAD as degToRad
|
||||
@@ -46,22 +57,41 @@ internal fun compileVmcOutputs(
|
||||
for ((boneId, pair) in contributions) {
|
||||
val (contribution, vmc) = pair
|
||||
val origin = contribution.origin(BoneField.OutputsVmc)
|
||||
val outputParent = vmc.outputParent?.let { resolveBoneKey(it, origin, "outputs.vmc.outputParent", registry, diagnostics) } ?: namedAncestor(boneId)
|
||||
val outputParent = vmc.outputParent?.let {
|
||||
resolveBoneKey(
|
||||
it,
|
||||
origin,
|
||||
"outputs.vmc.outputParent",
|
||||
registry,
|
||||
diagnostics,
|
||||
)
|
||||
} ?: namedAncestor(boneId)
|
||||
val inputParent = when (val parent = vmc.inputParent) {
|
||||
VmcInputParent.Omitted -> outputParent
|
||||
|
||||
VmcInputParent.ExplicitNull -> null
|
||||
is VmcInputParent.Bone -> resolveBoneKey(parent.key, origin, "outputs.vmc.inputParent", registry, diagnostics)
|
||||
|
||||
is VmcInputParent.Bone -> resolveBoneKey(
|
||||
parent.key,
|
||||
origin,
|
||||
"outputs.vmc.inputParent",
|
||||
registry,
|
||||
diagnostics,
|
||||
)
|
||||
}
|
||||
result[boneId] = CompiledVmcOutput(
|
||||
names = vmc.name.values,
|
||||
outputParent = outputParent,
|
||||
inputParent = inputParent,
|
||||
restRotation = (vmc.restRotation
|
||||
?: emptyList()).fold(Quaternion.IDENTITY) { acc, step ->
|
||||
restRotation = (
|
||||
vmc.restRotation
|
||||
?: emptyList()
|
||||
).fold(Quaternion.IDENTITY) { acc, step ->
|
||||
axisAngleQuaternion(
|
||||
Vector3(step.axis.x, step.axis.y, step.axis.z),
|
||||
step.degrees * degToRad
|
||||
) * acc
|
||||
step.degrees * degToRad,
|
||||
) *
|
||||
acc
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -79,7 +109,17 @@ private fun validateVmcOutputs(
|
||||
for ((boneId, output) in outputs) {
|
||||
val contribution = contributions.getValue(boneId).first
|
||||
val origin = contribution.origin(BoneField.OutputsVmc)
|
||||
for (name in output.names) reportDuplicateBoneKey(names, name, boneId, "VMC name", registry, origin, diagnostics)
|
||||
for (name in output.names) {
|
||||
reportDuplicateBoneKey(
|
||||
names,
|
||||
name,
|
||||
boneId,
|
||||
"VMC name",
|
||||
registry,
|
||||
origin,
|
||||
diagnostics,
|
||||
)
|
||||
}
|
||||
for ((field, parent) in listOf("outputParent" to output.outputParent, "inputParent" to output.inputParent)) {
|
||||
if (parent != null && parent !in outputs) {
|
||||
val parentKey = registry.keyOf(parent) ?: parent.toString()
|
||||
@@ -89,10 +129,20 @@ private fun validateVmcOutputs(
|
||||
}
|
||||
|
||||
fun validateParentGraph(field: String, parentOf: (CompiledVmcOutput) -> BoneId?) {
|
||||
reportCycles(outputs.keys, { outputs[it]?.let(parentOf) }) { _, lastVisited, cycle ->
|
||||
val origin = contributions.getValue(lastVisited).first.origin(BoneField.OutputsVmc)
|
||||
reportCycles(
|
||||
outputs.keys,
|
||||
{ outputs[it]?.let(parentOf) },
|
||||
) { _, lastVisited, cycle ->
|
||||
val origin =
|
||||
contributions.getValue(lastVisited).first.origin(BoneField.OutputsVmc)
|
||||
val keys = cycle.map { registry.keyOf(it) ?: it.toString() }
|
||||
diagnostics += origin.diagnostic("VMC $field graph contains a cycle: ${keys.joinToString(" -> ")}")
|
||||
diagnostics += origin.diagnostic(
|
||||
"VMC $field graph contains a cycle: ${
|
||||
keys.joinToString(
|
||||
" -> ",
|
||||
)
|
||||
}",
|
||||
)
|
||||
}
|
||||
}
|
||||
validateParentGraph("outputParent", CompiledVmcOutput::outputParent)
|
||||
|
||||
+24
-3
@@ -1,9 +1,22 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
package dev.slimevr.resourcepacks.bones.outputs
|
||||
|
||||
import dev.slimevr.bones.BoneId
|
||||
import dev.slimevr.bones.BoneMap
|
||||
import dev.slimevr.bones.BoneRegistry
|
||||
import dev.slimevr.resourcepacks.EmitEntry
|
||||
import dev.slimevr.resourcepacks.EmitSource
|
||||
import dev.slimevr.resourcepacks.PipelineStep
|
||||
import dev.slimevr.resourcepacks.ScalarOrVector
|
||||
import dev.slimevr.resourcepacks.bones.CompiledEmitEntry
|
||||
import dev.slimevr.resourcepacks.bones.origin
|
||||
import dev.slimevr.resourcepacks.bones.resolveBoneKey
|
||||
import dev.slimevr.resourcepacks.compiler.BoneContribution
|
||||
import dev.slimevr.resourcepacks.compiler.BoneField
|
||||
import dev.slimevr.resourcepacks.compiler.ResourceOrigin
|
||||
import dev.slimevr.resourcepacks.compiler.ResourcePackCompilationDiagnostic
|
||||
import dev.slimevr.resourcepacks.compiler.diagnostic
|
||||
import dev.slimevr.resourcepacks.compiler.reportDuplicateBoneKey
|
||||
import kotlin.collections.iterator
|
||||
|
||||
internal fun compileEmitEntries(
|
||||
registry: BoneRegistry,
|
||||
@@ -16,7 +29,15 @@ internal fun compileEmitEntries(
|
||||
val (contribution, entries) = pair
|
||||
result[boneId] = entries.mapValues { (address, entry) ->
|
||||
val origin = contribution.origin(BoneField.OutputsVrchatEmit(address))
|
||||
reportDuplicateBoneKey(addresses, address, boneId, "VRChat emit address", registry, origin, diagnostics)
|
||||
reportDuplicateBoneKey(
|
||||
addresses,
|
||||
address,
|
||||
boneId,
|
||||
"VRChat emit address",
|
||||
registry,
|
||||
origin,
|
||||
diagnostics,
|
||||
)
|
||||
validateEmitPipeline(address, entry, origin, diagnostics)
|
||||
CompiledEmitEntry(
|
||||
from = entry.from,
|
||||
@@ -26,7 +47,7 @@ internal fun compileEmitEntries(
|
||||
origin,
|
||||
"outputs.vrchat.emit.relativeTo",
|
||||
registry,
|
||||
diagnostics
|
||||
diagnostics,
|
||||
)
|
||||
},
|
||||
steps = entry.value ?: emptyList(),
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
|
||||
data class SourcedResource<T>(val path: String, val value: T, val raw: JsonObject)
|
||||
|
||||
|
||||
class ParsedResourcePack(
|
||||
val source: String,
|
||||
val manifest: SourcedResource<PackManifest>,
|
||||
val objects: Map<ResourceType<*>, List<Pair<String, JsonObject>>>,
|
||||
val patches: Map<ResourceType<*>, List<Pair<String, JsonArray>>>,
|
||||
|
||||
) {
|
||||
fun <T : Any> getDecoded(type: JsonResourceType<T>): List<SourcedResource<T>> {
|
||||
val result = mutableListOf<SourcedResource<T>>()
|
||||
val objs = objects[type] ?: return emptyList()
|
||||
for ((path, obj) in objs) {
|
||||
val decoded = type.validateAndDecode(path, obj, mutableListOf())
|
||||
if (decoded != null) result.add(decoded)
|
||||
}
|
||||
return result
|
||||
}
|
||||
fun <T : Any> getDecoded(type: JsonResourceType<T>): List<SourcedResource<T>> {
|
||||
val result = mutableListOf<SourcedResource<T>>()
|
||||
val objs = objects[type] ?: return emptyList()
|
||||
for ((path, obj) in objs) {
|
||||
val decoded = type.validateAndDecode(path, obj, mutableListOf())
|
||||
if (decoded != null) result.add(decoded)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
data class ResourcePackDiagnostic(val path: String, val pointer: String = "", val message: String)
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
package dev.slimevr.resourcepacks.compiler
|
||||
|
||||
import dev.slimevr.resourcepacks.ParsedResourcePack
|
||||
import dev.slimevr.resourcepacks.SourcedResource
|
||||
import dev.slimevr.resourcepacks.bones.BoneDefinition
|
||||
import dev.slimevr.resourcepacks.proportions.ProportionDefinition
|
||||
|
||||
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
package dev.slimevr.resourcepacks.compiler
|
||||
|
||||
import dev.slimevr.bones.BoneId
|
||||
import dev.slimevr.bones.BoneRegistry
|
||||
import dev.slimevr.resourcepacks.ParsedResourcePack
|
||||
|
||||
data class ResourcePackCompilationDiagnostic(val packId: String, val path: String, val message: String)
|
||||
|
||||
|
||||
+169
-42
@@ -1,11 +1,41 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
package dev.slimevr.resourcepacks.compiler
|
||||
|
||||
import dev.slimevr.bones.BodyPart
|
||||
import dev.slimevr.bones.BoneId
|
||||
import dev.slimevr.bones.BoneMap
|
||||
import dev.slimevr.bones.BoneRegistry
|
||||
import dev.slimevr.bones.key
|
||||
import dev.slimevr.resourcepacks.bones.*
|
||||
import dev.slimevr.resourcepacks.CopyRotationFallback
|
||||
import dev.slimevr.resourcepacks.EmitEntry
|
||||
import dev.slimevr.resourcepacks.FirstActiveRotationFallback
|
||||
import dev.slimevr.resourcepacks.JsonResourceType
|
||||
import dev.slimevr.resourcepacks.NoRotationFallback
|
||||
import dev.slimevr.resourcepacks.ParsedResourcePack
|
||||
import dev.slimevr.resourcepacks.ResourcePackCatalog
|
||||
import dev.slimevr.resourcepacks.ResourceTypes
|
||||
import dev.slimevr.resourcepacks.SourcedResource
|
||||
import dev.slimevr.resourcepacks.VmcOutput
|
||||
import dev.slimevr.resourcepacks.bones.CompiledBone
|
||||
import dev.slimevr.resourcepacks.bones.CompiledProportion
|
||||
import dev.slimevr.resourcepacks.bones.CompiledSkeleton
|
||||
import dev.slimevr.resourcepacks.bones.CompiledVrchatOutput
|
||||
import dev.slimevr.resourcepacks.bones.compileConstraint
|
||||
import dev.slimevr.resourcepacks.bones.compileOffset
|
||||
import dev.slimevr.resourcepacks.bones.displayName
|
||||
import dev.slimevr.resourcepacks.bones.orderFallbackDependencies
|
||||
import dev.slimevr.resourcepacks.bones.origin
|
||||
import dev.slimevr.resourcepacks.bones.outputs.compileEmitEntries
|
||||
import dev.slimevr.resourcepacks.bones.outputs.compileVmcInputOrder
|
||||
import dev.slimevr.resourcepacks.bones.outputs.compileVmcOutputs
|
||||
import dev.slimevr.resourcepacks.bones.resolveBoneKey
|
||||
import dev.slimevr.resourcepacks.bones.resolveFallbackBone
|
||||
import dev.slimevr.resourcepacks.bones.validateHierarchy
|
||||
import dev.slimevr.resourcepacks.deepMerge
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import kotlin.collections.iterator
|
||||
import kotlin.collections.plusAssign
|
||||
import kotlin.collections.set
|
||||
import solarxr_protocol.connection.BoneDefinition as WireBoneDefinition
|
||||
import solarxr_protocol.connection.BoneRegistry as WireBoneRegistry
|
||||
|
||||
@@ -17,11 +47,19 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton {
|
||||
for (pack in packs) {
|
||||
val id = pack.manifest.value.id
|
||||
if (packIds.put(id, pack) != null) {
|
||||
diagnostics += ResourcePackCompilationDiagnostic(id, pack.manifest.path, "Duplicate pack ID '$id'")
|
||||
diagnostics += ResourcePackCompilationDiagnostic(
|
||||
id,
|
||||
pack.manifest.path,
|
||||
"Duplicate pack ID '$id'",
|
||||
)
|
||||
}
|
||||
}
|
||||
if (catalog.core.manifest.value.id != "slimevr:core") {
|
||||
diagnostics += ResourcePackCompilationDiagnostic(catalog.core.manifest.value.id, catalog.core.manifest.path, "Expected bundled core pack ID 'slimevr:core'")
|
||||
diagnostics += ResourcePackCompilationDiagnostic(
|
||||
catalog.core.manifest.value.id,
|
||||
catalog.core.manifest.path,
|
||||
"Expected bundled core pack ID 'slimevr:core'",
|
||||
)
|
||||
}
|
||||
|
||||
val bonesByKey = compileResourceMap(packs, ResourceTypes.BONE, "bone key", diagnostics) { it.key }
|
||||
@@ -31,17 +69,30 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton {
|
||||
val standardPartsByKey = standardParts.associateBy(BodyPart::key)
|
||||
for (part in standardParts) {
|
||||
if (part.key !in bonesByKey) {
|
||||
diagnostics += ResourcePackCompilationDiagnostic(catalog.core.manifest.value.id, catalog.core.manifest.path, "Missing standard bone '${part.key}'")
|
||||
diagnostics += ResourcePackCompilationDiagnostic(
|
||||
catalog.core.manifest.value.id,
|
||||
catalog.core.manifest.path,
|
||||
"Missing standard bone '${part.key}'",
|
||||
)
|
||||
}
|
||||
}
|
||||
for ((key, contribution) in bonesByKey) {
|
||||
val part = standardPartsByKey[key]
|
||||
if (part != null && contribution.pack !== catalog.core) {
|
||||
diagnostics += ResourcePackCompilationDiagnostic(contribution.pack.manifest.value.id, contribution.resource.path, "Standard bone '$key' belongs to the core pack")
|
||||
diagnostics += ResourcePackCompilationDiagnostic(
|
||||
contribution.pack.manifest.value.id,
|
||||
contribution.resource.path,
|
||||
"Standard bone '$key' belongs to the core pack",
|
||||
)
|
||||
}
|
||||
if (part == null && contribution.pack === catalog.core) {
|
||||
diagnostics += ResourcePackCompilationDiagnostic(catalog.core.manifest.value.id, contribution.resource.path, "Core pack defines non-standard bone '$key'")
|
||||
diagnostics += ResourcePackCompilationDiagnostic(
|
||||
catalog.core.manifest.value.id,
|
||||
contribution.resource.path,
|
||||
"Core pack defines non-standard bone '$key'",
|
||||
)
|
||||
}
|
||||
|
||||
contribution.resource.value.parent?.let { parent ->
|
||||
if (parent !in bonesByKey) diagnostics += contribution.origin(BoneField.Parent).diagnostic("Unknown parent bone '$parent'")
|
||||
}
|
||||
@@ -62,7 +113,9 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton {
|
||||
WireBoneDefinition(
|
||||
id = (index + 1).toUShort(),
|
||||
key = definition.key,
|
||||
displayName = standardPart?.name?.replace('_', ' ')?.lowercase() ?: displayName(contribution),
|
||||
displayName = standardPart?.name?.replace('_', ' ')?.lowercase() ?: displayName(
|
||||
contribution,
|
||||
),
|
||||
parent = definition.parent?.let(idByKey::getValue) ?: 0.toUShort(),
|
||||
)
|
||||
},
|
||||
@@ -103,15 +156,61 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton {
|
||||
emitContributions[boneId] = contribution to it.emit
|
||||
}
|
||||
definition.inputs?.vrchat?.let { input ->
|
||||
reportDuplicateBoneKey(vrchatInputAddresses, input.address, boneId, "VRChat input address", registry, contribution.origin(BoneField.InputsVrchat), diagnostics)
|
||||
reportDuplicateBoneKey(
|
||||
vrchatInputAddresses,
|
||||
input.address,
|
||||
boneId,
|
||||
"VRChat input address",
|
||||
registry,
|
||||
contribution.origin(BoneField.InputsVrchat),
|
||||
diagnostics,
|
||||
)
|
||||
}
|
||||
bones[boneId] = CompiledBone(
|
||||
tailOffset = definition.tailOffset?.let { compileOffset(it, contribution.origin(BoneField.TailOffset), proportionsByKey, diagnostics) },
|
||||
headOffset = definition.headOffset?.let { compileOffset(it, contribution.origin(BoneField.HeadOffset), proportionsByKey, diagnostics) },
|
||||
tailOffset = definition.tailOffset?.let {
|
||||
compileOffset(
|
||||
it,
|
||||
contribution.origin(BoneField.TailOffset),
|
||||
proportionsByKey,
|
||||
diagnostics,
|
||||
)
|
||||
},
|
||||
headOffset = definition.headOffset?.let {
|
||||
compileOffset(
|
||||
it,
|
||||
contribution.origin(BoneField.HeadOffset),
|
||||
proportionsByKey,
|
||||
diagnostics,
|
||||
)
|
||||
},
|
||||
constraint = definition.constraint?.let { compileConstraint(it) },
|
||||
mirror = definition.mirror?.let { resolveBoneKey(it, contribution.origin(BoneField.Mirror), "mirror", registry, diagnostics) },
|
||||
candidateSources = definition.candidateSources?.map { resolveBoneKey(it, contribution.origin(BoneField.CandidateSources), "candidateSources", registry, diagnostics) },
|
||||
batterySources = definition.batterySources?.map { resolveBoneKey(it, contribution.origin(BoneField.BatterySources), "batterySources", registry, diagnostics) },
|
||||
mirror = definition.mirror?.let {
|
||||
resolveBoneKey(
|
||||
it,
|
||||
contribution.origin(BoneField.Mirror),
|
||||
"mirror",
|
||||
registry,
|
||||
diagnostics,
|
||||
)
|
||||
},
|
||||
candidateSources = definition.candidateSources?.map {
|
||||
resolveBoneKey(
|
||||
it,
|
||||
contribution.origin(BoneField.CandidateSources),
|
||||
"candidateSources",
|
||||
registry,
|
||||
diagnostics,
|
||||
)
|
||||
},
|
||||
batterySources = definition.batterySources?.map {
|
||||
resolveBoneKey(
|
||||
it,
|
||||
contribution.origin(BoneField.BatterySources),
|
||||
"batterySources",
|
||||
registry,
|
||||
diagnostics,
|
||||
)
|
||||
},
|
||||
overridable = definition.overridable == true,
|
||||
driverOutput = definition.outputs?.driver != null,
|
||||
vrchatInput = definition.inputs?.vrchat?.address,
|
||||
@@ -120,11 +219,25 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton {
|
||||
|
||||
val hierarchyOrder = registry.hierarchyFrom(registry.root).map { it.second }
|
||||
val resolvedCopyRotationFallbacks = hierarchyOrder.mapNotNull { boneId ->
|
||||
copyFallbacksByBoneId[boneId]?.let { (contribution, fallback) -> boneId to resolveFallbackBone(fallback.source, contribution, registry, diagnostics) }
|
||||
copyFallbacksByBoneId[boneId]?.let { (contribution, fallback) ->
|
||||
boneId to resolveFallbackBone(
|
||||
fallback.source,
|
||||
contribution,
|
||||
registry,
|
||||
diagnostics,
|
||||
)
|
||||
}
|
||||
}
|
||||
val resolvedFirstActiveRotationFallbacks = hierarchyOrder.mapNotNull { boneId ->
|
||||
firstActiveFallbacksByBoneId[boneId]?.let { (contribution, fallback) ->
|
||||
boneId to fallback.sources.map { resolveFallbackBone(it, contribution, registry, diagnostics) }
|
||||
boneId to fallback.sources.map {
|
||||
resolveFallbackBone(
|
||||
it,
|
||||
contribution,
|
||||
registry,
|
||||
diagnostics,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
val firstActiveBones = resolvedFirstActiveRotationFallbacks.mapTo(mutableSetOf()) { it.first }
|
||||
@@ -136,8 +249,10 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton {
|
||||
"A copy rotationFallback cannot use firstActive bone '$sourceKey' as its source because copy fallbacks run first",
|
||||
)
|
||||
}
|
||||
val copyRotationFallbacks = orderFallbackDependencies(resolvedCopyRotationFallbacks) { it }
|
||||
val firstActiveRotationFallbacks = orderFallbackDependencies(resolvedFirstActiveRotationFallbacks) { it.lastOrNull() }
|
||||
val copyRotationFallbacks =
|
||||
orderFallbackDependencies(resolvedCopyRotationFallbacks) { it }
|
||||
val firstActiveRotationFallbacks =
|
||||
orderFallbackDependencies(resolvedFirstActiveRotationFallbacks) { it.lastOrNull() }
|
||||
val vmcOutputMetadata = compileVmcOutputs(registry, vmcContributions, diagnostics)
|
||||
val emitEntries = compileEmitEntries(registry, emitContributions, diagnostics)
|
||||
val vmcInputOrder = compileVmcInputOrder(vmcOutputMetadata)
|
||||
@@ -161,42 +276,55 @@ private fun <T : Any> compileResourceMap(
|
||||
diagnostics: MutableList<ResourcePackCompilationDiagnostic>,
|
||||
keyExtractor: (T) -> String,
|
||||
): Map<String, Contribution<T>> {
|
||||
val latestDefs = mutableMapOf<String, Contribution<T>>()
|
||||
class RawContribution(
|
||||
val pack: ParsedResourcePack,
|
||||
val path: String,
|
||||
val raw: kotlinx.serialization.json.JsonObject,
|
||||
val latestOverride: ResourceOrigin? = null,
|
||||
)
|
||||
val latestDefs = mutableMapOf<String, RawContribution>()
|
||||
|
||||
for (pack in packs) {
|
||||
val objects = pack.objects[type] ?: emptyList()
|
||||
for ((path, jsonObject) in objects) {
|
||||
val origin = ResourceOrigin(pack, path)
|
||||
latestDefs[path] = Contribution(pack, SourcedResource(path, null as T, jsonObject), mapOf(), origin)
|
||||
val existing = latestDefs[path]
|
||||
if (existing != null) {
|
||||
latestDefs[path] = RawContribution(existing.pack, path, jsonObject, origin)
|
||||
} else {
|
||||
latestDefs[path] = RawContribution(pack, path, jsonObject, origin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (pack in packs) {
|
||||
val patches = pack.patches[type] ?: emptyList()
|
||||
for ((path, patchArray) in patches) {
|
||||
val base = latestDefs[path]
|
||||
if (base == null) {
|
||||
diagnostics += ResourcePackCompilationDiagnostic(pack.manifest.value.id, path, "Patch targets non-existent resource path: $path")
|
||||
continue
|
||||
}
|
||||
try {
|
||||
val patched = applyJsonPatch(base.resource.raw, patchArray)
|
||||
val origin = ResourceOrigin(pack, path)
|
||||
latestDefs[path] = base.copy(
|
||||
resource = SourcedResource(path, null as T, patched),
|
||||
latestOverride = origin
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
diagnostics += ResourcePackCompilationDiagnostic(pack.manifest.value.id, path, "Failed to apply JSON patch: ${e.message}")
|
||||
}
|
||||
|
||||
fun resolveExtend(path: String, visited: Set<String>): JsonObject {
|
||||
val base = latestDefs[path]?.raw ?: return JsonObject(emptyMap())
|
||||
val extendPath = base["\$extend"]?.jsonPrimitive?.content ?: return base
|
||||
if (extendPath in visited) {
|
||||
diagnostics += ResourcePackCompilationDiagnostic(latestDefs[path]!!.pack.manifest.value.id, path, "Cyclic \$extend detected: $extendPath")
|
||||
return base
|
||||
}
|
||||
val parent = resolveExtend(extendPath, visited + path)
|
||||
return deepMerge(parent, base)
|
||||
}
|
||||
|
||||
val byKey = mutableMapOf<String, Contribution<T>>()
|
||||
for ((path, contribution) in latestDefs) {
|
||||
val decoded = type.validateAndDecode(path, contribution.resource.raw, diagnostics as MutableList<ResourcePackDiagnostic>)
|
||||
for ((path, rawCont) in latestDefs) {
|
||||
val resolvedRaw = resolveExtend(path, emptySet())
|
||||
val localDiags = mutableListOf<dev.slimevr.resourcepacks.ResourcePackDiagnostic>()
|
||||
val decoded = type.validateAndDecode(path, resolvedRaw, localDiags)
|
||||
for (diag in localDiags) {
|
||||
val msg = if (diag.pointer.isNotEmpty()) "${diag.pointer}: ${diag.message}" else diag.message
|
||||
diagnostics += ResourcePackCompilationDiagnostic(rawCont.pack.manifest.value.id, diag.path, msg)
|
||||
}
|
||||
if (decoded != null) {
|
||||
val fullContribution = contribution.copy(resource = decoded)
|
||||
val fullContribution = Contribution(
|
||||
rawCont.pack,
|
||||
SourcedResource(path, decoded.value, resolvedRaw),
|
||||
emptyMap(),
|
||||
rawCont.latestOverride
|
||||
)
|
||||
val key = keyExtractor(decoded.value)
|
||||
if (key in byKey) {
|
||||
val existing = byKey.getValue(key)
|
||||
@@ -209,4 +337,3 @@ private fun <T : Any> compileResourceMap(
|
||||
}
|
||||
return byKey
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
fun deepMerge(target: JsonObject, source: JsonObject): JsonObject {
|
||||
val result = target.toMutableMap()
|
||||
for ((k, v) in source) {
|
||||
if (k == "\$extend") continue
|
||||
val existing = result[k]
|
||||
if (existing is JsonObject && v is JsonObject) {
|
||||
result[k] = deepMerge(existing, v)
|
||||
} else {
|
||||
result[k] = v
|
||||
}
|
||||
}
|
||||
return JsonObject(result)
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
fun applyJsonPatch(target: JsonObject, patch: JsonArray): JsonObject {
|
||||
var current = target
|
||||
for (op in patch) {
|
||||
val obj = op.jsonObject
|
||||
val path = obj["path"]?.jsonPrimitive?.content ?: continue
|
||||
val keys = path.trim('/').split('/')
|
||||
when (obj["op"]?.jsonPrimitive?.content) {
|
||||
"replace" -> current = setPath(current, keys, obj["value"]!!)
|
||||
"add" -> current = setPath(current, keys, obj["value"]!!)
|
||||
"remove" -> current = removePath(current, keys)
|
||||
}
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
private fun setPath(target: JsonObject, keys: List<String>, value: JsonElement): JsonObject {
|
||||
if (keys.isEmpty()) return target
|
||||
val key = keys.first()
|
||||
if (keys.size == 1) {
|
||||
val mut = target.toMutableMap()
|
||||
mut[key] = value
|
||||
return JsonObject(mut)
|
||||
}
|
||||
val child = target[key]?.jsonObject ?: JsonObject(emptyMap())
|
||||
val mut = target.toMutableMap()
|
||||
mut[key] = setPath(child, keys.drop(1), value)
|
||||
return JsonObject(mut)
|
||||
}
|
||||
|
||||
private fun removePath(target: JsonObject, keys: List<String>): JsonObject {
|
||||
if (keys.isEmpty()) return target
|
||||
val key = keys.first()
|
||||
if (keys.size == 1) {
|
||||
val mut = target.toMutableMap()
|
||||
mut.remove(key)
|
||||
return JsonObject(mut)
|
||||
}
|
||||
val child = target[key]?.jsonObject ?: return target
|
||||
val mut = target.toMutableMap()
|
||||
mut[key] = removePath(child, keys.drop(1))
|
||||
return JsonObject(mut)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.slimevr.resourcepacks
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
|
||||
internal val ResourcePackJson = Json {
|
||||
@@ -50,7 +50,7 @@ object ResourcePackParser {
|
||||
}
|
||||
|
||||
val objects = mutableMapOf<ResourceType<*>, MutableList<Pair<String, JsonObject>>>()
|
||||
val patches = mutableMapOf<ResourceType<*>, MutableList<Pair<String, JsonArray>>>()
|
||||
|
||||
|
||||
for (entry in entries) {
|
||||
if (entry.path == "manifest.json") continue
|
||||
@@ -58,13 +58,11 @@ object ResourcePackParser {
|
||||
if (type != null) {
|
||||
try {
|
||||
val element = ResourcePackJson.parseToJsonElement(entry.contents)
|
||||
if (element is JsonArray) {
|
||||
patches.getOrPut(type) { mutableListOf() }.add(entry.path to element)
|
||||
} else if (element is JsonObject) {
|
||||
val migrated = (type as JsonResourceType<*>).migrateJson(element, formatVersion)
|
||||
if (element is JsonObject) {
|
||||
val migrated = (type as JsonResourceType<*>).migrateJson(element, formatVersion)
|
||||
objects.getOrPut(type) { mutableListOf() }.add(entry.path to migrated)
|
||||
} else {
|
||||
diagnostics += ResourcePackDiagnostic(entry.path, message = "Expected JSON object or array")
|
||||
diagnostics += ResourcePackDiagnostic(entry.path, message = "Expected JSON object")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
diagnostics += ResourcePackDiagnostic(entry.path, message = "Malformed JSON: ${e.message}")
|
||||
@@ -72,6 +70,6 @@ object ResourcePackParser {
|
||||
}
|
||||
}
|
||||
if (diagnostics.isNotEmpty()) throw ResourcePackParseException(diagnostics.sortedWith(compareBy<ResourcePackDiagnostic> { it.path }.thenBy { it.pointer }))
|
||||
return ParsedResourcePack(source.description, parsedManifest, objects, patches)
|
||||
return ParsedResourcePack(source.description, parsedManifest, objects)
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,11 @@ abstract class JsonResourceType<T : Any>(
|
||||
}
|
||||
|
||||
override fun validateAndDecode(path: String, document: JsonObject, diagnostics: MutableList<in ResourcePackDiagnostic>): SourcedResource<T>? {
|
||||
val instance = try { JsonParser(document.toString()).parse() } catch (e: Exception) { return null }
|
||||
val instance = try {
|
||||
JsonParser(document.toString()).parse()
|
||||
} catch (e: Exception) {
|
||||
return null
|
||||
}
|
||||
val failure = Validator.forSchema(schema).validate(instance)
|
||||
if (failure != null) {
|
||||
diagnostics += ResourcePackDiagnostic(path, message = "$id schema: $failure")
|
||||
@@ -51,7 +55,6 @@ abstract class JsonResourceType<T : Any>(
|
||||
abstract fun decode(document: JsonObject): T
|
||||
}
|
||||
|
||||
|
||||
object ResourceTypes {
|
||||
val MANIFEST: JsonResourceType<PackManifest> = object : JsonResourceType<PackManifest>("manifest", "manifest.schema.json") {
|
||||
override fun matches(path: String) = path == "manifest.json"
|
||||
@@ -71,14 +74,15 @@ object ResourceTypes {
|
||||
}
|
||||
|
||||
val ALL = listOf(MANIFEST, BONE, PROPORTION, LANGUAGE)
|
||||
|
||||
}
|
||||
|
||||
internal object PackSchemas {
|
||||
const val ROOT = ClasspathResourcePackSource.CORE_ROOT + "/schemas/v1"
|
||||
val documents = ResourceTypes.ALL.associate { type ->
|
||||
type.schemaName to (PackSchemas::class.java.classLoader.getResourceAsStream("$ROOT/${type.schemaName}")?.bufferedReader(StandardCharsets.UTF_8)?.use { it.readText() }
|
||||
?: error("Bundled resource-pack schema is missing: $ROOT/${type.schemaName}"))
|
||||
type.schemaName to (
|
||||
PackSchemas::class.java.classLoader.getResourceAsStream("$ROOT/${type.schemaName}")?.bufferedReader(StandardCharsets.UTF_8)?.use { it.readText() }
|
||||
?: error("Bundled resource-pack schema is missing: $ROOT/${type.schemaName}")
|
||||
)
|
||||
}
|
||||
val config = SchemaLoaderConfig.createDefaultConfig(documents.mapKeys { (name, _) -> URI("classpath:/$ROOT/").resolve(name) })
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ interface ResourcePackSource {
|
||||
suspend fun entries(): List<ResourcePackEntry>
|
||||
}
|
||||
|
||||
|
||||
class StorageResourcePackSource(
|
||||
private val storage: ConfigStorage,
|
||||
private val root: String,
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -28,11 +28,11 @@ import dev.slimevr.resets.ResetsManager
|
||||
import dev.slimevr.resets.ResetsMountingTimeoutBehaviour
|
||||
import dev.slimevr.resets.ResetsState
|
||||
import dev.slimevr.resourcepacks.ClasspathResourcePackSource
|
||||
import dev.slimevr.resourcepacks.bones.CompiledSkeleton
|
||||
import dev.slimevr.resourcepacks.ParsedResourcePack
|
||||
import dev.slimevr.resourcepacks.ResourcePackCatalog
|
||||
import dev.slimevr.resourcepacks.ResourcePackParser
|
||||
import dev.slimevr.resourcepacks.compileResourcePacks
|
||||
import dev.slimevr.resourcepacks.bones.CompiledSkeleton
|
||||
import dev.slimevr.resourcepacks.compiler.compileResourcePacks
|
||||
import dev.slimevr.routing.BoneRoutingManager
|
||||
import dev.slimevr.serial.FlashingHandler
|
||||
import dev.slimevr.serial.SerialPortHandle
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package dev.slimevr.bones
|
||||
|
||||
import dev.slimevr.resourcepacks.bones.CompiledSkeleton
|
||||
import dev.slimevr.resourcepacks.InMemoryResourcePackSource
|
||||
import dev.slimevr.resourcepacks.ParsedResourcePack
|
||||
import dev.slimevr.resourcepacks.bones.REFERENCE_HEIGHT
|
||||
import dev.slimevr.resourcepacks.ResourcePackCatalog
|
||||
import dev.slimevr.resourcepacks.ResourcePackCompilationDiagnostic
|
||||
import dev.slimevr.resourcepacks.ResourcePackCompilationException
|
||||
import dev.slimevr.resourcepacks.ResourcePackParser
|
||||
import dev.slimevr.resourcepacks.ResourceTypes
|
||||
import dev.slimevr.resourcepacks.compileResourcePacks
|
||||
import dev.slimevr.resourcepacks.bones.CompiledSkeleton
|
||||
import dev.slimevr.resourcepacks.bones.REFERENCE_HEIGHT
|
||||
import dev.slimevr.resourcepacks.compiler.ResourcePackCompilationDiagnostic
|
||||
import dev.slimevr.resourcepacks.compiler.ResourcePackCompilationException
|
||||
import dev.slimevr.resourcepacks.compiler.compileResourcePacks
|
||||
import dev.slimevr.testCoreResourcePack
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
||||
@@ -94,7 +94,7 @@ class PipelineEvaluatorTest {
|
||||
listOf(
|
||||
PipelineStep.Euler(EulerSpec(axis = Axis.X)),
|
||||
PipelineStep.Divide(ScalarOrVector.Scalar(90f)),
|
||||
PipelineStep.Clamp(listOf(-1f, 1f))
|
||||
PipelineStep.Clamp(listOf(-1f, 1f)),
|
||||
),
|
||||
),
|
||||
bone(rotation = Quaternion.rotationAroundXAxis(100f * PI.toFloat() / 180f)),
|
||||
|
||||
@@ -39,7 +39,7 @@ import dev.slimevr.provisioning.ProvisioningManager
|
||||
import dev.slimevr.resets.ResetsManager
|
||||
import dev.slimevr.resolveConfigDirectory
|
||||
import dev.slimevr.resourcepacks.ResourcePackManager
|
||||
import dev.slimevr.resourcepacks.compileResourcePacks
|
||||
import dev.slimevr.resourcepacks.compiler.compileResourcePacks
|
||||
import dev.slimevr.routing.BoneRoutingManager
|
||||
import dev.slimevr.skeleton.Skeleton
|
||||
import dev.slimevr.solarxr.rpc.ServerInfos
|
||||
|
||||
Reference in new issue
Block a user