Search in sources :

Example 1 with Matrix4fc

use of org.joml.Matrix4fc in project chunkstories-api by Hugobros3.

the class CompoundAnimationHelper method getBoneHierarchyTransformationMatrixInternal.

private final Matrix4fc getBoneHierarchyTransformationMatrixInternal(String boneName, double animationTime) {
    SkeletalAnimation animation = getAnimationPlayingForBone(boneName, animationTime);
    SkeletonBone bone = animation.getBone(boneName);
    // Out if null
    if (bone == null) {
        System.out.println("null bone");
        return new Matrix4f();
    }
    // Get this very bone transformation matrix
    Matrix4fc thisBoneMatrix = getBoneTransformationMatrix(boneName, animationTime);
    // Transform by parent if existant
    SkeletonBone parent = animation.getBone(boneName).getParent();
    if (parent != null) {
        Matrix4f thisBoneMatrix2 = new Matrix4f();
        getBoneHierarchyTransformationMatrixInternal(parent.getName(), animationTime).mul(thisBoneMatrix, thisBoneMatrix2);
        return thisBoneMatrix2;
    }
    return thisBoneMatrix;
}
Also used : Matrix4fc(org.joml.Matrix4fc) Matrix4f(org.joml.Matrix4f) SkeletonBone(io.xol.chunkstories.api.animation.SkeletalAnimation.SkeletonBone)

Example 2 with Matrix4fc

use of org.joml.Matrix4fc in project chunkstories by Hugobros3.

the class BonedRenderer method internalRenderer.

private void internalRenderer(RenderingInterface renderingContext, SkeletonAnimator skeleton, double animationTime) {
    prepareDraw(renderingContext);
    Shader shader = renderingContext.currentShader();
    if (skeleton != null) {
        for (int i = 0; i < boneName.length; i++) {
            if (skeleton.shouldHideBone(renderingContext, boneName[i])) {
                Matrix4f boneMatrix = new Matrix4f();
                boneMatrix.translate(50000, 50000, 50000);
                shader.setUniformMatrix4f("bones[" + i + "]", boneMatrix);
            } else {
                Matrix4fc boneMatrix = skeleton.getBoneHierarchyTransformationMatrixWithOffset(boneName[i], animationTime < 0 ? 0 : animationTime);
                shader.setUniformMatrix4f("bones[" + i + "]", boneMatrix);
            }
        }
    }
    renderingContext.draw(Primitive.TRIANGLE, 0, verticesCount);
}
Also used : Matrix4fc(org.joml.Matrix4fc) Matrix4f(org.joml.Matrix4f) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 3 with Matrix4fc

use of org.joml.Matrix4fc in project chunkstories-core by Hugobros3.

the class CachedLodSkeletonAnimator method getBoneHierarchyTransformationMatrixWithOffset.

@Override
public Matrix4fc getBoneHierarchyTransformationMatrixWithOffset(String nameOfEndBone, double animationTime) {
    // Don't mess with the player animation, it should NEVER be cached
    if (entity.getWorld() instanceof WorldClient && ((WorldClient) entity.getWorld()).getClient() != null && ((WorldClient) entity.getWorld()).getClient().getPlayer().getControlledEntity() == entity)
        return dataSource.getBoneHierarchyTransformationMatrixWithOffset(nameOfEndBone, animationTime);
    CachedData cachedData = cachedBones.get(nameOfEndBone);
    // If the matrix exists and doesn't need an update
    if (cachedData != null && !cachedData.needsUpdate) {
        cachedData.needsUpdate = false;
        return cachedData.matrix;
    }
    // Obtains the matrix and caches it
    Matrix4fc matrix = dataSource.getBoneHierarchyTransformationMatrixWithOffset(nameOfEndBone, animationTime);
    cachedBones.put(nameOfEndBone, new CachedData(matrix, System.currentTimeMillis()));
    return matrix;
}
Also used : Matrix4fc(org.joml.Matrix4fc) WorldClient(io.xol.chunkstories.api.world.WorldClient)

Aggregations

Matrix4fc (org.joml.Matrix4fc)3 Matrix4f (org.joml.Matrix4f)2 SkeletonBone (io.xol.chunkstories.api.animation.SkeletalAnimation.SkeletonBone)1 Shader (io.xol.chunkstories.api.rendering.shader.Shader)1 WorldClient (io.xol.chunkstories.api.world.WorldClient)1