[orx-obj-loader] skip padding when saving obj (#353)
This commit is contained in:
@@ -62,13 +62,18 @@ fun VertexBuffer.saveOBJ(filePath: String) {
|
|||||||
// Process the ByteBuffer and populate data structures
|
// Process the ByteBuffer and populate data structures
|
||||||
while (bb.position() < bb.capacity()) {
|
while (bb.position() < bb.capacity()) {
|
||||||
vertexFormat.items.forEach { vertexElement ->
|
vertexFormat.items.forEach { vertexElement ->
|
||||||
val floats = List(vertexElement.type.componentCount) {
|
val componentCount = vertexElement.type.componentCount
|
||||||
|
val floats = List(componentCount) {
|
||||||
bb.getFloat()
|
bb.getFloat()
|
||||||
}.joinToString(" ")
|
}.joinToString(" ")
|
||||||
val token = tokens[vertexElement.attribute]
|
val token = tokens[vertexElement.attribute]
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
lastIndices[token] = indexMap[token]!!.add(floats)
|
lastIndices[token] = indexMap[token]!!.add(floats)
|
||||||
}
|
}
|
||||||
|
// Skip padding
|
||||||
|
repeat(4 - componentCount) {
|
||||||
|
bb.getFloat()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vertexIndices.add("${lastIndices["v"]}/${lastIndices["vt"]}/${lastIndices["vn"]}")
|
vertexIndices.add("${lastIndices["v"]}/${lastIndices["vt"]}/${lastIndices["vn"]}")
|
||||||
}
|
}
|
||||||
@@ -84,8 +89,8 @@ fun VertexBuffer.saveOBJ(filePath: String) {
|
|||||||
// Write v, vt, vn blocks
|
// Write v, vt, vn blocks
|
||||||
indexMap.forEach { (token, verts) ->
|
indexMap.forEach { (token, verts) ->
|
||||||
appendLine(verts.toObjBlock(token))
|
appendLine(verts.toObjBlock(token))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write faces processing three vertices at a time
|
// Write faces processing three vertices at a time
|
||||||
vertexIndices.chunked(3) {
|
vertexIndices.chunked(3) {
|
||||||
appendLine("f ${it[0]} ${it[1]} ${it[2]}")
|
appendLine("f ${it[0]} ${it[1]} ${it[2]}")
|
||||||
|
|||||||
Reference in New Issue
Block a user