Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[orx-obj-loader] skip padding when saving obj #353

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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