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);
}
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);
}
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;
}
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);
}
}
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);
}
Aggregations