Search in sources :

Example 11 with AABBf

use of org.terasology.joml.geom.AABBf in project Terasology by MovingBlocks.

the class BulletCollisionShape method getAABB.

@Override
public AABBf getAABB(Vector3fc origin, Quaternionfc rotation, float scale) {
    Vector3f min = new Vector3f();
    Vector3f max = new Vector3f();
    Matrix4f m = new Matrix4f();
    underlyingShape.getAabb(m, min, max);
    return new AABBf(min, max).translate(origin);
}
Also used : Matrix4f(org.joml.Matrix4f) AABBf(org.terasology.joml.geom.AABBf) Vector3f(org.joml.Vector3f)

Example 12 with AABBf

use of org.terasology.joml.geom.AABBf in project Terasology by MovingBlocks.

the class GLTFAnimationFormat method loadAnimation.

private MeshAnimationData loadAnimation(GLTF gltf, GLTFAnimation animation, List<byte[]> loadedBuffers, TIntIntMap boneIndexMapping, List<String> boneNames, TIntList boneParents, List<Bone> bones) throws IOException {
    List<ChannelReader> channelReaders = new ArrayList<>();
    for (GLTFChannel channel : animation.getChannels()) {
        GLTFAnimationSampler sampler = animation.getSamplers().get(channel.getSampler());
        TFloatList times = getFloats(gltf, loadedBuffers, sampler.getInput());
        int bone = boneIndexMapping.get(channel.getTarget().getNode());
        switch(channel.getTarget().getPath()) {
            case TRANSLATION:
                {
                    List<Vector3f> data = getVector3fs(gltf, loadedBuffers, sampler.getOutput());
                    channelReaders.add(new BufferChannelReader<>(times, data, sampler.getInterpolation()::interpolate, x -> x.getPosition(bone)));
                    break;
                }
            case ROTATION:
                {
                    List<Quaternionf> data = getQuat4fs(gltf, loadedBuffers, sampler.getOutput());
                    channelReaders.add(new BufferChannelReader<>(times, data, sampler.getInterpolation()::interpolate, x -> x.getRotation(bone)));
                    break;
                }
            case SCALE:
                {
                    List<Vector3f> data = getVector3fs(gltf, loadedBuffers, sampler.getOutput());
                    channelReaders.add(new BufferChannelReader<>(times, data, sampler.getInterpolation()::interpolate, x -> x.getBoneScale(bone)));
                    break;
                }
            default:
                break;
        }
    }
    int frameCount = (int) (channelReaders.stream().map(ChannelReader::endTime).reduce(Float::max).orElse(0f) / TIME_PER_FRAME) + 1;
    List<MeshAnimationFrame> frames = new ArrayList<>(frameCount);
    for (int i = 0; i < frameCount; i++) {
        float time = i * TIME_PER_FRAME;
        List<Vector3f> boneLocations = new ArrayList<>();
        List<Quaternionf> boneRotations = new ArrayList<>();
        List<Vector3f> boneScales = new ArrayList<>();
        for (Bone bone : bones) {
            boneLocations.add(new Vector3f(bone.getLocalPosition()));
            boneRotations.add(new Quaternionf(bone.getLocalRotation()));
            boneScales.add(new Vector3f(bone.getLocalScale()));
        }
        MeshAnimationFrame frame = new MeshAnimationFrame(boneLocations, boneRotations, boneScales);
        channelReaders.forEach(x -> x.updateFrame(time, frame));
        frames.add(frame);
    }
    return new MeshAnimationData(boneNames, boneParents, frames, TIME_PER_FRAME, new AABBf(0, 0, 0));
}
Also used : GLTFAnimationSampler(org.terasology.engine.rendering.gltf.model.GLTFAnimationSampler) MeshAnimationFrame(org.terasology.engine.rendering.assets.animation.MeshAnimationFrame) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TFloatArrayList(gnu.trove.list.array.TFloatArrayList) TFloatList(gnu.trove.list.TFloatList) GLTFChannel(org.terasology.engine.rendering.gltf.model.GLTFChannel) Quaternionf(org.joml.Quaternionf) AABBf(org.terasology.joml.geom.AABBf) Vector3f(org.joml.Vector3f) MeshAnimationData(org.terasology.engine.rendering.assets.animation.MeshAnimationData) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TFloatList(gnu.trove.list.TFloatList) TIntList(gnu.trove.list.TIntList) TFloatArrayList(gnu.trove.list.array.TFloatArrayList) List(java.util.List) Bone(org.terasology.engine.rendering.assets.skeletalmesh.Bone)

Example 13 with AABBf

use of org.terasology.joml.geom.AABBf in project Terasology by MovingBlocks.

the class BlockItemSystem method canPlaceBlock.

private boolean canPlaceBlock(Block block, Vector3i targetBlock, Vector3i blockPos) {
    if (block == null) {
        return false;
    }
    Block centerBlock = worldProvider.getBlock(targetBlock.x, targetBlock.y, targetBlock.z);
    if (!centerBlock.isAttachmentAllowed()) {
        return false;
    }
    Block adjBlock = worldProvider.getBlock(blockPos.x, blockPos.y, blockPos.z);
    if (!adjBlock.isReplacementAllowed() || adjBlock.isTargetable()) {
        return false;
    }
    if (block.getBlockFamily().equals(adjBlock.getBlockFamily())) {
        return false;
    }
    // Prevent players from placing blocks inside their bounding boxes
    if (!block.isPenetrable()) {
        Physics physics = CoreRegistry.get(Physics.class);
        AABBf blockBounds = block.getBounds(blockPos);
        /**
         * Characters can enter other solid objects/blocks for certain amount. This is does to detect collsion
         * start and end without noise. So if the user walked as close to a block as possible it is only natural
         * to let it place a block exactly above it even if that technically would mean a collision start.
         */
        blockBounds.minX += KinematicCharacterMover.HORIZONTAL_PENETRATION;
        blockBounds.maxX -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
        blockBounds.minY += KinematicCharacterMover.VERTICAL_PENETRATION;
        blockBounds.maxY -= KinematicCharacterMover.VERTICAL_PENETRATION;
        blockBounds.minZ += KinematicCharacterMover.HORIZONTAL_PENETRATION;
        blockBounds.maxZ -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
        /*
             * Calculations aren't exact and in the corner cases it is better to let the user place the block.
             */
        blockBounds.minX += ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.minY += ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.minZ += ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.maxX -= ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.maxY -= ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.maxZ -= ADDITIONAL_ALLOWED_PENETRATION;
        return physics.scanArea(blockBounds, StandardCollisionGroup.DEFAULT, StandardCollisionGroup.CHARACTER).isEmpty();
    }
    return true;
}
Also used : AABBf(org.terasology.joml.geom.AABBf) Block(org.terasology.engine.world.block.Block) Physics(org.terasology.engine.physics.Physics)

Aggregations

AABBf (org.terasology.joml.geom.AABBf)13 Vector3f (org.joml.Vector3f)7 Matrix4f (org.joml.Matrix4f)5 Quaternionf (org.joml.Quaternionf)5 JsonElement (com.google.gson.JsonElement)3 JsonObject (com.google.gson.JsonObject)3 Test (org.junit.jupiter.api.Test)3 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)3 LocationComponent (org.terasology.engine.logic.location.LocationComponent)3 TFloatList (gnu.trove.list.TFloatList)2 FloatBuffer (java.nio.FloatBuffer)2 Matrix3f (org.joml.Matrix3f)2 Bone (org.terasology.engine.rendering.assets.skeletalmesh.Bone)2 TIntList (gnu.trove.list.TIntList)1 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Vector3fc (org.joml.Vector3fc)1 Physics (org.terasology.engine.physics.Physics)1