Skip to content
This repository was archived by the owner on Mar 22, 2026. It is now read-only.

Commit 6e31a6d

Browse files
committed
使用 BDEF2 和 BDEF4 来读取 PMX 的 SDEF 和 QDEF
1 parent 699e0dd commit 6e31a6d

File tree

1 file changed

+27
-4
lines changed
  • model/model-pmx/src/main/kotlin/top/fifthlight/renderer/model/pmx

1 file changed

+27
-4
lines changed

model/model-pmx/src/main/kotlin/top/fifthlight/renderer/model/pmx/PmxLoader.kt

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ object PmxLoader : ModelFileLoader {
246246
}
247247

248248
fun readWeight(): Float = buffer.getFloat(inputPosition).also { inputPosition += 4 }
249+
fun readVector3f(): Vector3f = Vector3f().also {
250+
it.set(
251+
buffer.getFloat(inputPosition),
252+
buffer.getFloat(inputPosition + 4),
253+
buffer.getFloat(inputPosition + 8)
254+
)
255+
inputPosition += 12
256+
}
249257

250258
// TODO: keep track of vertices without bone, to exclude non-skinned vertices out
251259
when (weightDeformType) {
@@ -271,8 +279,8 @@ object PmxLoader : ModelFileLoader {
271279
outputBuffer.putFloat(outputPosition + 20, 1f - weight1)
272280
}
273281
}
274-
// BDEF4
275-
2 -> {
282+
// BDEF4, or not really supported QDEF
283+
2, 4 -> {
276284
val index1 = readBoneIndex()
277285
val index2 = readBoneIndex()
278286
val index3 = readBoneIndex()
@@ -299,8 +307,23 @@ object PmxLoader : ModelFileLoader {
299307
}
300308
}
301309

302-
3 -> throw PmxLoadException("SDEF is not supported!")
303-
4 -> throw PmxLoadException("QDEF is not supported!")
310+
3 -> {
311+
// SDEF, not really supported, just treat as BDEF2
312+
val index1 = readBoneIndex()
313+
val index2 = readBoneIndex()
314+
val weight1 = readWeight()
315+
val c = readVector3f()
316+
val r0 = readVector3f()
317+
val r1 = readVector3f()
318+
outputBuffer.putInt(outputPosition, index1)
319+
outputBuffer.putInt(outputPosition + 4, index2)
320+
if (index1 != -1) {
321+
outputBuffer.putFloat(outputPosition + 16, weight1)
322+
}
323+
if (index2 != -1) {
324+
outputBuffer.putFloat(outputPosition + 20, 1f - weight1)
325+
}
326+
}
304327
}
305328
outputPosition += SKIN_VERTEX_ATTRIBUTE_SIZE
306329

0 commit comments

Comments
 (0)