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}") } } }