All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.ru.casperix.spine.TransformConstraint.kt Maven / Gradle / Ivy

The newest version!
package ru.casperix.spine

import ru.casperix.math.Transform

class TransformConstraint(val skeleton: Skeleton, val data: TransformConstraintData) {
    private val bones = data.bones.map {
        skeleton.bones[it.index]
    }
    private var target = skeleton.bones[data.target.index]
    private var mix = data.mix

    /** Applies the constraint to the constrained bones.  */
    fun update() {
        if (mix == Transform.ZERO) return
        applyBones()
    }

    private fun applyBones() {
        val target = target

        bones.forEach { bone ->
            val transform = TransformMixer.mix(bone.local, target.local, data.offset, data.mix, data.local, data.relative).toABCD()
            bone.updateTransform(transform.toMatrix())
        }
    }

    fun setToSetupPose() {
        target = skeleton.bones[data.target.index]
        mix = data.mix
    }


}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy