Search in sources :

Example 1 with AABBf

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

the class AABBTypeHandlerTest method testSerializeAABBf.

@Test
public void testSerializeAABBf() {
    AABB2Test aabb1 = new AABB2Test();
    aabb1.a1 = new AABBf(0, 2.0f, 1.5f, 10.0f, 5.0f, 10);
    JsonElement tree = gson.toJsonTree(aabb1);
    JsonObject obj = tree.getAsJsonObject();
    assertTrue(obj.has("a1"));
    assertAABBf(obj.get("a1"), 0, 2.0f, 1.5f, 10.0f, 5.0f, 10);
}
Also used : AABBf(org.terasology.joml.geom.AABBf) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test)

Example 2 with AABBf

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

the class SkeletalMeshDataBuilder method build.

public SkeletalMeshData build() {
    int rootBones = 0;
    for (Bone bone : bones) {
        if (bone.getParent() == null) {
            rootBones++;
        }
    }
    Vector3f minOfAABB = new Vector3f(vertices.get(0));
    Vector3f maxOfAABB = new Vector3f(vertices.get(0));
    for (Vector3f vert : vertices) {
        minOfAABB.min(vert);
        maxOfAABB.max(vert);
    }
    if (rootBones == 0) {
        throw new IllegalStateException("Cannot create a skeleton with no root bones");
    } else if (rootBones > 1) {
        throw new IllegalStateException("Cannot create a skeleton with multiple root bones");
    }
    AABBf staticAabb = new AABBf(minOfAABB, maxOfAABB);
    return new SkeletalMeshData(bones, vertices, normals, weights, uvs, indices, staticAabb);
}
Also used : AABBf(org.terasology.joml.geom.AABBf) Vector3f(org.joml.Vector3f)

Example 3 with AABBf

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

the class ChunkMeshComponent method copyFrom.

@Override
public void copyFrom(ChunkMeshComponent other) {
    // TODO deep or shallow copy?
    this.mesh = other.mesh;
    this.aabb = new AABBf(other.aabb);
    this.animated = other.animated;
}
Also used : AABBf(org.terasology.joml.geom.AABBf)

Example 4 with AABBf

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

the class BoundingBoxRenderer method renderOverlay.

@Override
public void renderOverlay() {
    if (config.getRendering().getDebug().isRenderEntityBoundingBoxes()) {
        GL33.glDepthFunc(GL33.GL_ALWAYS);
        Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition();
        Vector3f worldPos = new Vector3f();
        Vector3f worldPositionCameraSpace = new Vector3f();
        worldPos.sub(cameraPosition, worldPositionCameraSpace);
        Matrix4f matrixCameraSpace = new Matrix4f().translationRotateScale(worldPositionCameraSpace, new Quaternionf(), 1.0f);
        Matrix4f modelViewMatrix = new Matrix4f(worldRenderer.getActiveCamera().getViewMatrix()).mul(matrixCameraSpace);
        material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix());
        material.setMatrix4("modelViewMatrix", modelViewMatrix, true);
        int index = 0;
        meshData.reallocate(0, 0);
        meshData.indices.rewind();
        meshData.position.rewind();
        meshData.color0.rewind();
        Vector3f worldPosition = new Vector3f();
        Quaternionf worldRot = new Quaternionf();
        Matrix4f transform = new Matrix4f();
        AABBf bounds = new AABBf(0, 0, 0, 0, 0, 0);
        for (EntityRef entity : entityManager.getEntitiesWith(LocationComponent.class)) {
            LocationComponent location = entity.getComponent(LocationComponent.class);
            location.getWorldPosition(worldPosition);
            location.getWorldRotation(worldRot);
            BoxShapeComponent boxShapeComponent = entity.getComponent(BoxShapeComponent.class);
            if (boxShapeComponent != null) {
                bounds.set(0, 0, 0, 0, 0, 0);
                bounds.expand(new Vector3f(boxShapeComponent.extents).div(2.0f));
                transform.translationRotateScale(worldPosition, worldRot, location.getWorldScale());
                bounds.transform(transform);
                index = addRenderBound(meshData, bounds, index);
            }
            CapsuleShapeComponent capsuleComponent = entity.getComponent(CapsuleShapeComponent.class);
            if (capsuleComponent != null) {
                bounds.set(0, 0, 0, 0, 0, 0);
                bounds.expand(new Vector3f(capsuleComponent.radius, capsuleComponent.height / 2.0f, capsuleComponent.radius).div(2.0f));
                transform.translationRotateScale(worldPosition, worldRot, location.getWorldScale());
                bounds.transform(transform);
                index = addRenderBound(meshData, bounds, index);
            }
            CylinderShapeComponent cylinderShapeComponent = entity.getComponent(CylinderShapeComponent.class);
            if (cylinderShapeComponent != null) {
                bounds.set(0, 0, 0, 0, 0, 0);
                bounds.expand(new Vector3f(cylinderShapeComponent.radius, cylinderShapeComponent.height / 2.0f, cylinderShapeComponent.radius).div(2.0f));
                transform.translationRotateScale(worldPosition, worldRot, location.getWorldScale());
                bounds.transform(transform);
                index = addRenderBound(meshData, bounds, index);
            }
            SphereShapeComponent sphereShapeComponent = entity.getComponent(SphereShapeComponent.class);
            if (sphereShapeComponent != null) {
                bounds.set(0, 0, 0, 0, 0, 0);
                bounds.expand(new Vector3f(sphereShapeComponent.radius).div(2.0f));
                transform.translationRotateScale(worldPosition, worldRot, location.getWorldScale());
                bounds.transform(transform);
                index = addRenderBound(meshData, bounds, index);
            }
        }
        material.enable();
        mesh.reload(meshData);
        mesh.render();
        GL33.glDepthFunc(GL33.GL_LEQUAL);
    }
}
Also used : Matrix4f(org.joml.Matrix4f) AABBf(org.terasology.joml.geom.AABBf) SphereShapeComponent(org.terasology.engine.physics.components.shapes.SphereShapeComponent) Vector3f(org.joml.Vector3f) BoxShapeComponent(org.terasology.engine.physics.components.shapes.BoxShapeComponent) Quaternionf(org.joml.Quaternionf) CylinderShapeComponent(org.terasology.engine.physics.components.shapes.CylinderShapeComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) CapsuleShapeComponent(org.terasology.engine.physics.components.shapes.CapsuleShapeComponent)

Example 5 with AABBf

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

the class RegionOutlineRenderer method renderOverlay.

@Override
public void renderOverlay() {
    if (entityToRegionOutlineMap.isEmpty()) {
        // skip everything if there is nothing to do to avoid possibly costly draw mode changes
        return;
    }
    GL33.glDepthFunc(GL33.GL_ALWAYS);
    Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition();
    Vector3f worldPos = new Vector3f();
    Vector3f worldPositionCameraSpace = new Vector3f();
    worldPos.sub(cameraPosition, worldPositionCameraSpace);
    Matrix4f matrixCameraSpace = new Matrix4f().translationRotateScale(worldPositionCameraSpace, new Quaternionf(), 1.0f);
    Matrix4f modelViewMatrix = new Matrix4f(worldRenderer.getActiveCamera().getViewMatrix()).mul(matrixCameraSpace);
    material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix());
    material.setMatrix4("modelViewMatrix", modelViewMatrix, true);
    meshData.reallocate(0, 0);
    meshData.indices.rewind();
    meshData.position.rewind();
    meshData.color0.rewind();
    int index = 0;
    Vector3f pos = new Vector3f();
    for (RegionOutlineComponent regionOutline : entityToRegionOutlineMap.values()) {
        if (regionOutline.corner1 == null || regionOutline.corner2 == null) {
            continue;
        }
        BlockRegion region = new BlockRegion(regionOutline.corner1).union(regionOutline.corner2);
        AABBf bounds = region.getBounds(new AABBf());
        meshData.position.put(pos.set(bounds.minX, bounds.minY, bounds.minZ));
        meshData.position.put(pos.set(bounds.maxX, bounds.minY, bounds.minZ));
        meshData.position.put(pos.set(bounds.maxX, bounds.minY, bounds.maxZ));
        meshData.position.put(pos.set(bounds.minX, bounds.minY, bounds.maxZ));
        meshData.position.put(pos.set(bounds.minX, bounds.maxY, bounds.minZ));
        meshData.position.put(pos.set(bounds.maxX, bounds.maxY, bounds.minZ));
        meshData.position.put(pos.set(bounds.maxX, bounds.maxY, bounds.maxZ));
        meshData.position.put(pos.set(bounds.minX, bounds.maxY, bounds.maxZ));
        meshData.color0.put(regionOutline.color);
        meshData.color0.put(regionOutline.color);
        meshData.color0.put(regionOutline.color);
        meshData.color0.put(regionOutline.color);
        meshData.color0.put(regionOutline.color);
        meshData.color0.put(regionOutline.color);
        meshData.color0.put(regionOutline.color);
        meshData.color0.put(regionOutline.color);
        meshData.indices.putAll(new int[] { // top loop
        index, index + 1, index + 1, index + 2, index + 2, index + 3, index + 3, index, // connecting edges between top and bottom
        index, index + 4, index + 1, index + 5, index + 2, index + 6, index + 3, index + 7, // bottom loop
        index + 4, index + 5, index + 5, index + 6, index + 6, index + 7, index + 7, index + 4 });
        index += 8;
    }
    material.enable();
    mesh.reload(meshData);
    mesh.render();
    GL33.glDepthFunc(GL33.GL_LEQUAL);
}
Also used : Matrix4f(org.joml.Matrix4f) AABBf(org.terasology.joml.geom.AABBf) Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) BlockRegion(org.terasology.engine.world.block.BlockRegion)

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