Search in sources :

Example 1 with BlockMeshPart

use of org.terasology.world.block.shapes.BlockMeshPart in project Terasology by MovingBlocks.

the class BlockMeshGeneratorSingleShape method generateMesh.

private void generateMesh() {
    Tessellator tessellator = new Tessellator();
    for (BlockPart dir : BlockPart.values()) {
        BlockMeshPart part = block.getPrimaryAppearance().getPart(dir);
        if (part != null) {
            if (block.isDoubleSided()) {
                tessellator.addMeshPartDoubleSided(part);
            } else {
                tessellator.addMeshPart(part);
            }
        }
    }
    mesh = tessellator.generateMesh(new ResourceUrn("engine", "blockmesh", block.getURI().toString()));
}
Also used : BlockPart(org.terasology.world.block.BlockPart) ResourceUrn(org.terasology.assets.ResourceUrn) BlockMeshPart(org.terasology.world.block.shapes.BlockMeshPart)

Example 2 with BlockMeshPart

use of org.terasology.world.block.shapes.BlockMeshPart in project Terasology by MovingBlocks.

the class BlockBuilder method createAppearance.

private BlockAppearance createAppearance(BlockShape shape, Map<BlockPart, BlockTile> tiles, Rotation rot) {
    Map<BlockPart, BlockMeshPart> meshParts = Maps.newEnumMap(BlockPart.class);
    Map<BlockPart, Vector2f> textureAtlasPositions = Maps.newEnumMap(BlockPart.class);
    for (BlockPart part : BlockPart.values()) {
        // TODO: Need to be more sensible with the texture atlas. Because things like block particles read from a part that may not exist, we're being fairly lenient
        Vector2f atlasPos;
        if (tiles.get(part) == null) {
            atlasPos = new Vector2f();
        } else {
            atlasPos = worldAtlas.getTexCoords(tiles.get(part), shape.getMeshPart(part) != null);
        }
        BlockPart targetPart = part.rotate(rot);
        textureAtlasPositions.put(targetPart, atlasPos);
        if (shape.getMeshPart(part) != null) {
            meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.getQuat4f()).mapTexCoords(atlasPos, worldAtlas.getRelativeTileSize()));
        }
    }
    return new BlockAppearance(meshParts, textureAtlasPositions);
}
Also used : BlockPart(org.terasology.world.block.BlockPart) BlockAppearance(org.terasology.world.block.BlockAppearance) Vector2f(org.terasology.math.geom.Vector2f) BlockMeshPart(org.terasology.world.block.shapes.BlockMeshPart)

Example 3 with BlockMeshPart

use of org.terasology.world.block.shapes.BlockMeshPart in project Terasology by MovingBlocks.

the class BlockBuilder method applyLoweredShape.

private void applyLoweredShape(Block block, BlockShape shape, Map<BlockPart, BlockTile> tiles) {
    for (Side side : Side.values()) {
        BlockPart part = BlockPart.fromSide(side);
        BlockTile blockTile = tiles.get(part);
        if (blockTile != null) {
            BlockMeshPart meshPart = shape.getMeshPart(part).rotate(Rotation.none().getQuat4f()).mapTexCoords(worldAtlas.getTexCoords(blockTile, true), worldAtlas.getRelativeTileSize());
            block.setLoweredLiquidMesh(part.getSide(), meshPart);
        }
    }
}
Also used : Side(org.terasology.math.Side) BlockPart(org.terasology.world.block.BlockPart) BlockTile(org.terasology.world.block.tiles.BlockTile) BlockMeshPart(org.terasology.world.block.shapes.BlockMeshPart)

Aggregations

BlockPart (org.terasology.world.block.BlockPart)3 BlockMeshPart (org.terasology.world.block.shapes.BlockMeshPart)3 ResourceUrn (org.terasology.assets.ResourceUrn)1 Side (org.terasology.math.Side)1 Vector2f (org.terasology.math.geom.Vector2f)1 BlockAppearance (org.terasology.world.block.BlockAppearance)1 BlockTile (org.terasology.world.block.tiles.BlockTile)1