[orx-mesh, orx-mesh-generator, orx-obj-loader] Add decal and tangent tools

This commit is contained in:
Edwin Jakobs
2024-09-25 09:51:46 +02:00
parent fb3bb6f7a6
commit e016891b1d
28 changed files with 1072 additions and 82 deletions

View File

@@ -0,0 +1,33 @@
package org.openrndr.extra.mesh
import org.openrndr.math.LinearType
import org.openrndr.math.Vector3
internal fun <T : LinearType<T>> bc(barycentric: Vector3, items: List<T>): T {
return (items[0] * barycentric.x) + (items[1] * barycentric.y) + (items[2] * barycentric.z)
}
/**
* Evaluate a point in triangle
* @param vertexData the vertex data to use
* @param barycentric the barycentric coordinates of the point to evaluate
*/
fun IIndexedPolygon.point(vertexData: VertexData, barycentric: Vector3): Point {
require(positions.size == 3)
val positions = vertexData.positions.slice(positions)
val colors = vertexData.colors.slice(colors)
val normals = vertexData.normals.slice(normals)
val tangents = vertexData.tangents.slice(tangents)
val bitangents = vertexData.bitangents.slice(bitangents)
val textureCoords = vertexData.textureCoords.slice(textureCoords)
return Point(
(if (positions.isNotEmpty()) bc(barycentric, positions) else null)!!,
if (textureCoords.isNotEmpty()) bc(barycentric, textureCoords) else null,
if (colors.isNotEmpty()) bc(barycentric, colors) else null,
if (normals.isNotEmpty()) bc(barycentric, normals) else null,
if (tangents.isNotEmpty()) bc(barycentric, tangents) else null,
if (bitangents.isNotEmpty()) bc(barycentric, bitangents) else null
)
}