use of org.terasology.engine.world.block.shapes.BlockShape in project Terasology by MovingBlocks.
the class BlockManagerImpl method loadFamily.
private Optional<BlockFamily> loadFamily(BlockUri uri) {
Optional<BlockFamilyDefinition> familyDef = assetManager.getAsset(uri.getBlockFamilyDefinitionUrn(), BlockFamilyDefinition.class);
if (familyDef.isPresent() && familyDef.get().isLoadable()) {
if (familyDef.get().isFreeform()) {
ResourceUrn shapeUrn;
if (uri.getShapeUrn().isPresent()) {
shapeUrn = uri.getShapeUrn().get();
} else {
shapeUrn = CUBE_SHAPE_URN;
}
Optional<BlockShape> shape = assetManager.getAsset(shapeUrn, BlockShape.class);
if (shape.isPresent()) {
return Optional.of(familyDef.get().createFamily(shape.get(), blockBuilder));
}
} else if (!familyDef.get().isFreeform()) {
return Optional.of(familyDef.get().createFamily(blockBuilder));
}
} else {
logger.error("Family not available: {}", uri);
}
return Optional.empty();
}
use of org.terasology.engine.world.block.shapes.BlockShape in project Terasology by MovingBlocks.
the class BlockFamilyLibrary method createFamily.
/**
* Create a family based on the type and instantiate from the the family definition of the block and builder
*
* @param blockFamily
* @param blockFamilyDefinition
* @param blockBuilderHelper
* @param shape
* @return new BlockFamily
*/
public static BlockFamily createFamily(Class<? extends AbstractBlockFamily> blockFamily, BlockFamilyDefinition blockFamilyDefinition, BlockShape shape, BlockBuilderHelper blockBuilderHelper) {
try {
SimpleClassFactory simpleClassFactory = new SimpleClassFactory(new ParameterProvider() {
@Override
public <T> Optional<T> get(Class<T> type) {
if (type.isAssignableFrom(BlockBuilderHelper.class)) {
return Optional.ofNullable((T) blockBuilderHelper);
} else if (type.isAssignableFrom(BlockFamilyDefinition.class)) {
return Optional.ofNullable((T) blockFamilyDefinition);
} else if (type.isAssignableFrom(BlockShape.class)) {
return Optional.ofNullable((T) shape);
}
return Optional.empty();
}
});
BlockFamily result = simpleClassFactory.instantiateClass(blockFamily).get();
InjectionHelper.inject(result);
if (result.getURI() == null) {
throw new Exception("Family Is missng a BlockUri");
}
return result;
} catch (Exception e) {
logger.error("Failed to load blockFamily {}", blockFamily, e);
}
return null;
}
use of org.terasology.engine.world.block.shapes.BlockShape in project Terasology by MovingBlocks.
the class BlockShapeTest method testConvexHull.
@Test
public void testConvexHull() {
BlockShape blockShape = assetManager.getAsset("engine:halfSlope", BlockShape.class).get();
CollisionShape shape = blockShape.getCollisionShape(Rotation.rotate(Yaw.CLOCKWISE_90));
assertTrue(shape instanceof ConvexHullShape);
Vector3f[] test = new Vector3f[] { new Vector3f(0.49999997f, 0.0f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, 0.0f, 0.49999997f) };
BulletConvexHullShape bulletConvexHullShape = (BulletConvexHullShape) shape;
// TODO: Test fails because native library is not loaded
for (int x = 0; x < ((btConvexHullShape) bulletConvexHullShape.underlyingShape).getNumPoints(); x++) {
fuzzVectorTest(test[x], ((btConvexHullShape) bulletConvexHullShape.underlyingShape).getScaledPoint(x));
}
}
Aggregations