Fix formatting of OBJLoader
This commit is contained in:
@@ -9,6 +9,8 @@ import org.openrndr.math.Vector3
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.MalformedURLException
|
import java.net.MalformedURLException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class Triangle(val positions: Array<Vector3> = emptyArray(),
|
class Triangle(val positions: Array<Vector3> = emptyArray(),
|
||||||
val normals: Array<Vector3> = emptyArray(),
|
val normals: Array<Vector3> = emptyArray(),
|
||||||
@@ -31,13 +33,13 @@ fun bounds(triangles: List<Triangle>): Box {
|
|||||||
|
|
||||||
triangles.forEach {
|
triangles.forEach {
|
||||||
it.positions.forEach {
|
it.positions.forEach {
|
||||||
minX = Math.min(minX, it.x)
|
minX = min(minX, it.x)
|
||||||
minY = Math.min(minY, it.y)
|
minY = min(minY, it.y)
|
||||||
minZ = Math.min(minZ, it.z)
|
minZ = min(minZ, it.z)
|
||||||
|
|
||||||
maxX = Math.max(maxX, it.x)
|
maxX = max(maxX, it.x)
|
||||||
maxY = Math.max(maxY, it.y)
|
maxY = max(maxY, it.y)
|
||||||
maxZ = Math.max(maxZ, it.z)
|
maxZ = max(maxZ, it.z)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Box(Vector3(minX, minY, minZ), maxX - minX, maxY - minY, maxZ - minZ)
|
return Box(Vector3(minX, minY, minZ), maxX - minX, maxY - minY, maxZ - minZ)
|
||||||
@@ -47,7 +49,7 @@ fun List<Triangle>.vertexBuffer():VertexBuffer {
|
|||||||
val vertexBuffer = vertexBuffer(objVertexFormat, size * 3)
|
val vertexBuffer = vertexBuffer(objVertexFormat, size * 3)
|
||||||
vertexBuffer.put {
|
vertexBuffer.put {
|
||||||
this@vertexBuffer.forEach {
|
this@vertexBuffer.forEach {
|
||||||
for (i in 0 until it.positions.size) {
|
for (i in it.positions.indices) {
|
||||||
write(it.positions[i])
|
write(it.positions[i])
|
||||||
write(it.normals[i])
|
write(it.normals[i])
|
||||||
write(Vector2.ZERO)
|
write(Vector2.ZERO)
|
||||||
@@ -92,16 +94,16 @@ fun loadOBJasVertexBuffer(lines: List<String>): VertexBuffer {
|
|||||||
vertexBuffer.put {
|
vertexBuffer.put {
|
||||||
objects.entries.forEach {
|
objects.entries.forEach {
|
||||||
it.value.forEach {
|
it.value.forEach {
|
||||||
for (i in 0 until it.positions.size) {
|
for (i in it.positions.indices) {
|
||||||
write(it.positions[i])
|
write(it.positions[i])
|
||||||
if (it.normals.size > 0) {
|
if (it.normals.isNotEmpty()) {
|
||||||
write(it.normals[i])
|
write(it.normals[i])
|
||||||
} else {
|
} else {
|
||||||
val d0 = it.positions[2] - it.positions[0]
|
val d0 = it.positions[2] - it.positions[0]
|
||||||
val d1 = it.positions[1] - it.positions[0]
|
val d1 = it.positions[1] - it.positions[0]
|
||||||
write(d0.normalized.cross(d1.normalized).normalized)
|
write(d0.normalized.cross(d1.normalized).normalized)
|
||||||
}
|
}
|
||||||
if (it.textureCoords.size > 0) {
|
if (it.textureCoords.isNotEmpty()) {
|
||||||
write(it.textureCoords[i])
|
write(it.textureCoords[i])
|
||||||
} else {
|
} else {
|
||||||
write(Vector2.ZERO)
|
write(Vector2.ZERO)
|
||||||
|
|||||||
Reference in New Issue
Block a user