From e195a8b389799377441a43bae83c1739c0a311d7 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Sat, 18 May 2019 01:25:12 +0200 Subject: [PATCH] bump to 0.0.26 add support for quad faces in orx-obj-loader --- build.gradle | 2 +- orx-obj-loader/src/main/kotlin/OBJLoader.kt | 24 ++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index a4771488..a86db5b2 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { allprojects { group 'org.openrndr.extra' - version '0.0.25' + version '0.0.26' } repositories { diff --git a/orx-obj-loader/src/main/kotlin/OBJLoader.kt b/orx-obj-loader/src/main/kotlin/OBJLoader.kt index 53e70e89..b1373168 100644 --- a/orx-obj-loader/src/main/kotlin/OBJLoader.kt +++ b/orx-obj-loader/src/main/kotlin/OBJLoader.kt @@ -145,29 +145,31 @@ fun loadOBJ(lines: List): Map> { it.map { it.toIntOrNull() } } - if (indices.size == 3) { + for (i in 0 until indices.size-2) { val attributes = indices[0].size + val o = i*2 + val s = indices.size val ps = if (attributes >= 1) arrayOf( - indices[0][0]?.let { positions[it - 1] } ?: Vector3.ZERO, - indices[1][0]?.let { positions[it - 1] } ?: Vector3.ZERO, - indices[2][0]?.let { positions[it - 1] } ?: Vector3.ZERO) + indices[(0+o)%s][0]?.let { positions[it - 1] } ?: Vector3.ZERO, + indices[(1+o)%s][0]?.let { positions[it - 1] } ?: Vector3.ZERO, + indices[(2+o)%s][0]?.let { positions[it - 1] } ?: Vector3.ZERO) else emptyArray() val tcs = if (attributes >= 2) arrayOf( - indices[0][1]?.let { textureCoords[it - 1] } ?: Vector2.ZERO, - indices[1][1]?.let { textureCoords[it - 1] } ?: Vector2.ZERO, - indices[2][1]?.let { textureCoords[it - 1] } ?: Vector2.ZERO) + indices[(0+o)%s][1]?.let { textureCoords[it - 1] } ?: Vector2.ZERO, + indices[(1+o)%s][1]?.let { textureCoords[it - 1] } ?: Vector2.ZERO, + indices[(2+o)%s][1]?.let { textureCoords[it - 1] } ?: Vector2.ZERO) else emptyArray() val ns = if (attributes >= 3) arrayOf( - indices[0][2]?.let { normals[it - 1] } ?: Vector3.ZERO, - indices[1][2]?.let { normals[it - 1] } ?: Vector3.ZERO, - indices[2][2]?.let { normals[it - 1] } ?: Vector3.ZERO) + indices[(0+o)%s][2]?.let { normals[it - 1] } ?: Vector3.ZERO, + indices[(1+o)%s][2]?.let { normals[it - 1] } ?: Vector3.ZERO, + indices[(2+o)%s][2]?.let { normals[it - 1] } ?: Vector3.ZERO) else emptyArray() @@ -175,8 +177,6 @@ fun loadOBJ(lines: List): Map> { if(meshes.isEmpty()) { meshes["no-name"] = activeMesh } - } else { - TODO("implement non triangular surfaces ${indices.size}") } } }