Add gltf animation support to orx-dnk3
This commit is contained in:
@@ -65,4 +65,5 @@ class KeyframerChannel {
|
||||
leftKey.value * (1.0 - e0) + rightKey.value * (e0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
64
orx-keyframer/src/main/kotlin/KeyQuaternion.kt
Normal file
64
orx-keyframer/src/main/kotlin/KeyQuaternion.kt
Normal file
@@ -0,0 +1,64 @@
|
||||
package org.openrndr.extra.keyframer
|
||||
|
||||
import org.openrndr.extras.easing.Easing
|
||||
import org.openrndr.extras.easing.EasingFunction
|
||||
import org.openrndr.math.Quaternion
|
||||
import org.openrndr.math.slerp
|
||||
|
||||
class KeyQuaternion(val time: Double, val value: Quaternion, val easing: EasingFunction)
|
||||
|
||||
class KeyframerChannelQuaternion {
|
||||
val keys = mutableListOf<KeyQuaternion>()
|
||||
|
||||
operator fun invoke() : Double {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
fun add(time: Double, value: Quaternion?, easing: EasingFunction = Easing.Linear.function, jump: Hold = Hold.HoldNone) {
|
||||
if (jump == Hold.HoldAll || (jump == Hold.HoldSet && value != null)) {
|
||||
lastValue()?.let {
|
||||
keys.add(KeyQuaternion(time, it, Easing.Linear.function))
|
||||
}
|
||||
}
|
||||
value?.let {
|
||||
keys.add(KeyQuaternion(time, it, easing))
|
||||
}
|
||||
}
|
||||
|
||||
fun lastValue(): Quaternion? {
|
||||
return keys.lastOrNull()?.value
|
||||
}
|
||||
|
||||
fun duration(): Double {
|
||||
return keys.last().time
|
||||
}
|
||||
|
||||
fun value(time: Double): Quaternion? {
|
||||
if (keys.size == 0) {
|
||||
return null
|
||||
}
|
||||
if (keys.size == 1) {
|
||||
return if (time < keys.first().time) {
|
||||
keys[0].value.normalized
|
||||
} else {
|
||||
keys[0].value.normalized
|
||||
}
|
||||
}
|
||||
|
||||
if (time < keys.first().time) {
|
||||
return null
|
||||
}
|
||||
|
||||
val rightIndex = keys.indexOfFirst { it.time > time }
|
||||
return if (rightIndex == -1) {
|
||||
keys.last().value.normalized
|
||||
} else {
|
||||
val leftIndex = (rightIndex - 1).coerceAtLeast(0)
|
||||
val rightKey = keys[rightIndex]
|
||||
val leftKey = keys[leftIndex]
|
||||
val t0 = (time - leftKey.time) / (rightKey.time - leftKey.time)
|
||||
val e0 = rightKey.easing(t0, 0.0, 1.0, 1.0)
|
||||
slerp(leftKey.value, rightKey.value, e0).normalized
|
||||
}
|
||||
}
|
||||
}
|
||||
63
orx-keyframer/src/main/kotlin/KeyVector3.kt
Normal file
63
orx-keyframer/src/main/kotlin/KeyVector3.kt
Normal file
@@ -0,0 +1,63 @@
|
||||
package org.openrndr.extra.keyframer
|
||||
|
||||
import org.openrndr.extras.easing.Easing
|
||||
import org.openrndr.extras.easing.EasingFunction
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
class KeyVector3(val time: Double, val value: Vector3, val easing: EasingFunction)
|
||||
|
||||
class KeyframerChannelVector3 {
|
||||
val keys = mutableListOf<KeyVector3>()
|
||||
|
||||
operator fun invoke() : Double {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
fun add(time: Double, value: Vector3?, easing: EasingFunction = Easing.Linear.function, jump: Hold = Hold.HoldNone) {
|
||||
if (jump == Hold.HoldAll || (jump == Hold.HoldSet && value != null)) {
|
||||
lastValue()?.let {
|
||||
keys.add(KeyVector3(time, it, Easing.Linear.function))
|
||||
}
|
||||
}
|
||||
value?.let {
|
||||
keys.add(KeyVector3(time, it, easing))
|
||||
}
|
||||
}
|
||||
|
||||
fun lastValue(): Vector3? {
|
||||
return keys.lastOrNull()?.value
|
||||
}
|
||||
|
||||
fun duration(): Double {
|
||||
return keys.last().time
|
||||
}
|
||||
|
||||
fun value(time: Double): Vector3? {
|
||||
if (keys.size == 0) {
|
||||
return null
|
||||
}
|
||||
if (keys.size == 1) {
|
||||
return if (time < keys.first().time) {
|
||||
null
|
||||
} else {
|
||||
keys[0].value
|
||||
}
|
||||
}
|
||||
|
||||
if (time < keys.first().time) {
|
||||
return null
|
||||
}
|
||||
|
||||
val rightIndex = keys.indexOfFirst { it.time > time }
|
||||
return if (rightIndex == -1) {
|
||||
keys.last().value
|
||||
} else {
|
||||
val leftIndex = (rightIndex - 1).coerceAtLeast(0)
|
||||
val rightKey = keys[rightIndex]
|
||||
val leftKey = keys[leftIndex]
|
||||
val t0 = (time - leftKey.time) / (rightKey.time - leftKey.time)
|
||||
val e0 = rightKey.easing(t0, 0.0, 1.0, 1.0)
|
||||
leftKey.value * (1.0 - e0) + rightKey.value * (e0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,6 @@ enum class KeyframerFormat {
|
||||
FULL
|
||||
}
|
||||
|
||||
|
||||
|
||||
open class Keyframer {
|
||||
private var currentTime = 0.0
|
||||
operator fun invoke(time: Double) {
|
||||
|
||||
Reference in New Issue
Block a user