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