[orx-obj-loader] Add obj saver, demos (#348)

This commit is contained in:
Abe Pazos
2024-07-18 10:23:32 +02:00
committed by GitHub
parent 411f7ffc54
commit 556794b634
11 changed files with 2312 additions and 14 deletions

View File

@@ -1,16 +1,23 @@
package org.openrndr.extra.objloader
import org.openrndr.draw.VertexBuffer
import org.openrndr.draw.VertexFormat
import org.openrndr.draw.vertexBuffer
import org.openrndr.draw.vertexFormat
import org.openrndr.math.Vector2
/**
* The [VertexFormat] for a [VertexBuffer] with positions, normals and texture coordinates.
*/
private val objVertexFormat = vertexFormat {
position(3)
normal(3)
textureCoordinate(2)
}
/**
* Converts a [MeshData] instance into a [VertexBuffer]
*/
fun MeshData.toVertexBuffer() : VertexBuffer {
val objects = triangulate().flattenPolygons()
val triangleCount = objects.values.sumOf { it.size }