Skip to content

Commit

Permalink
[orx-obj-loader] skip padding when saving obj
Browse files Browse the repository at this point in the history
  • Loading branch information
hamoid committed Jan 30, 2025
1 parent 79e4df3 commit 6fa851e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions orx-obj-loader/src/jvmMain/kotlin/OBJSaver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ fun VertexBuffer.saveOBJ(filePath: String) {
// Process the ByteBuffer and populate data structures
while (bb.position() < bb.capacity()) {
vertexFormat.items.forEach { vertexElement ->
val floats = List(vertexElement.type.componentCount) {
val componentCount = vertexElement.type.componentCount
val floats = List(componentCount) {
bb.getFloat()
}.joinToString(" ")
val token = tokens[vertexElement.attribute]
if (token != null) {
lastIndices[token] = indexMap[token]!!.add(floats)
}
// Skip padding
repeat(4 - componentCount) {
bb.getFloat()
}
}
vertexIndices.add("${lastIndices["v"]}/${lastIndices["vt"]}/${lastIndices["vn"]}")
}
Expand All @@ -84,8 +89,8 @@ fun VertexBuffer.saveOBJ(filePath: String) {
// Write v, vt, vn blocks
indexMap.forEach { (token, verts) ->
appendLine(verts.toObjBlock(token))

}

// Write faces processing three vertices at a time
vertexIndices.chunked(3) {
appendLine("f ${it[0]} ${it[1]} ${it[2]}")
Expand Down

0 comments on commit 6fa851e

Please sign in to comment.