Skip to content

Commit

Permalink
Fix loading of maya animations for composite models
Browse files Browse the repository at this point in the history
  • Loading branch information
dosier committed May 1, 2024
1 parent 0ab23ea commit 23ba8b0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
jcenter()
}

version = "0.2.9"
version = "0.3.0"

allprojects {
group = "stan.qodat"
Expand Down
8 changes: 4 additions & 4 deletions qodat-api/src/main/kotlin/qodat/cache/models/RS2Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,19 +583,19 @@ public void setTexturePrimaryColors(short[] texturePrimaryColors) {
this.texturePrimaryColors = texturePrimaryColors;
}

public void setAnimayaGroups(int[][] animayaGroups) {
public void setMayaGroups(int[][] animayaGroups) {
this.animayaGroups = animayaGroups;
}

public void setAnimayaScales(int[][] animayaScales) {
public void setMayaScales(int[][] animayaScales) {
this.animayaScales = animayaScales;
}

public int[][] getAnimayaGroups() {
public int[][] getMayaGroups() {
return animayaGroups;
}

public int[][] getAnimayaScales() {
public int[][] getMayaScales() {
return animayaScales;
}

Expand Down
20 changes: 19 additions & 1 deletion qodat-api/src/main/kotlin/qodat/cache/models/RS2ModelBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class RS2ModelBuilder(vararg modelDefinitions: ModelDefinition) {
private var copyFaceSkins = false
private var copyFaceColors = true
private var copyFaceTextures = false
private var copyMayaGroups = false

private var vertexPositionsX : IntArray
private var vertexPositionsY : IntArray
Expand All @@ -37,6 +38,8 @@ class RS2ModelBuilder(vararg modelDefinitions: ModelDefinition) {
private val faceRenderPriorities: ByteArray?
private val faceRenderTypes: ByteArray?
private val faceSkins: IntArray?
private val mayaGroups: Array<IntArray?>?
private val mayaScales: Array<IntArray?>?

init {
for(definition in modelDefinitions){
Expand All @@ -50,6 +53,8 @@ class RS2ModelBuilder(vararg modelDefinitions: ModelDefinition) {
globalPriority = definition.getPriority()
copyFaceSkins = copyFaceSkins or (definition.getFaceSkins() != null)
copyFaceTextures = copyFaceTextures or (definition.getFaceTextures() != null)
if (definition is RS2Model)
copyMayaGroups = copyMayaGroups or (definition.mayaGroups != null)
}

vertexPositionsX = IntArray(vertexCount)
Expand All @@ -67,6 +72,13 @@ class RS2ModelBuilder(vararg modelDefinitions: ModelDefinition) {
faceColors = if(copyFaceColors) ShortArray(faceCount) else null
faceSkins = if(copyFaceSkins) IntArray(faceCount) else null
faceTextures = if(copyFaceTextures) ShortArray(faceCount) {(-1).toShort()} else null
if(copyMayaGroups) {
mayaGroups = arrayOfNulls(vertexCount)
mayaScales = arrayOfNulls(vertexCount)
} else {
mayaGroups = null
mayaScales = null
}

for(definition in modelDefinitions){
for(srcFaceIdx in 0 until definition.getFaceCount()){
Expand Down Expand Up @@ -101,6 +113,10 @@ class RS2ModelBuilder(vararg modelDefinitions: ModelDefinition) {
val skins = model.getVertexSkins()
if (skins != null)
vertexSkins[vertexIdx] = skins[localVertexIdx]
if (model is RS2Model) {
model.mayaGroups?.get(localVertexIdx)?.let { mayaGroups?.set(vertexIdx, it) }
model.mayaScales?.get(localVertexIdx)?.let { mayaScales?.set(vertexIdx, it) }
}
return vertexIdx++
}

Expand All @@ -121,6 +137,8 @@ class RS2ModelBuilder(vararg modelDefinitions: ModelDefinition) {
setFaceSkins(faceSkins)
setFaceTextures(faceTextures)
setPriority(globalPriority)
mayaGroups = this@RS2ModelBuilder.mayaGroups
mayaScales = this@RS2ModelBuilder.mayaScales
}

private fun ByteArray.tryCopy(srcIdx: Int, byteArray: ByteArray?) {
Expand All @@ -135,4 +153,4 @@ class RS2ModelBuilder(vararg modelDefinitions: ModelDefinition) {
if (shortArray != null)
this[faceIdx] = shortArray[srcIdx]
}
}
}
4 changes: 2 additions & 2 deletions qodat-api/src/main/kotlin/qodat/cache/models/RSModelLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class RSModelLoader {
setFaceTextureConfigs(it.textureCoords)
faceRenderPriorities = it.faceRenderPriorities
faceRenderTypes = it.faceRenderTypes
setAnimayaGroups(it.animayaGroups)
setAnimayaScales(it.animayaScales)
setMayaGroups(it.animayaGroups)
setMayaScales(it.animayaScales)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ open class ModelSkeleton(internal val modelDefinition: ModelDefinition)

val duration = anim.duration
for (vertex in 0 until getVertexCount()) {
val boneIndices = modelDefinition.animayaGroups[vertex]
val boneIndices = modelDefinition.mayaGroups[vertex]
if (boneIndices != null && boneIndices.isNotEmpty()) {
val scales = modelDefinition.animayaScales[vertex]
val scales = modelDefinition.mayaScales[vertex]
field2703.zeroMatrix()
for ((index, boneIndex) in boneIndices.withIndex()) {
val bone = animSkeleton.getBone(boneIndex)
Expand Down

0 comments on commit 23ba8b0

Please sign in to comment.