From 6fa851ec4b9bd9a0114a47516c2051b2118241b2 Mon Sep 17 00:00:00 2001 From: Abe Pazos Date: Thu, 30 Jan 2025 21:27:56 +0100 Subject: [PATCH] [orx-obj-loader] skip padding when saving obj --- orx-obj-loader/src/jvmMain/kotlin/OBJSaver.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/orx-obj-loader/src/jvmMain/kotlin/OBJSaver.kt b/orx-obj-loader/src/jvmMain/kotlin/OBJSaver.kt index 4597b6429..3a374138c 100644 --- a/orx-obj-loader/src/jvmMain/kotlin/OBJSaver.kt +++ b/orx-obj-loader/src/jvmMain/kotlin/OBJSaver.kt @@ -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"]}") } @@ -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]}")