Exemplo n.º 1
0
def test_resize():
    sf = SchematicFile(shape=(3, 2, 1))
    assert np.all(sf.shape == (3, 2, 1))
    sf.resize((3, 1, 2))
    assert np.all(sf.shape == (3, 1, 2))
    assert np.all(sf.blocks.shape == (3, 1, 2))
    assert np.all(sf.data.shape == (3, 1, 2))
Exemplo n.º 2
0
def test_set_entities():
    sf = SchematicFile()
    sf.entities = [Entity()]
    sf.entities[0]['id'] = 'awe:some'
    sf.entities[0]['Pos'] = [0, 0, 0]
    sf.block_entities = [BlockEntity()]
    sf.block_entities[0]['id'] = 'awe:somer'
    sf.block_entities[0]['x'] = 0
    sf.block_entities[0]['y'] = 0
    sf.block_entities[0]['z'] = 0
Exemplo n.º 3
0
def readBlocksFromSchematicFile(inputFile, outputDirectory):
    if os.path.isfile(inputFile):
        if os.path.exists(outputDirectory) and (
                not os.path.isfile(outputDirectory)):
            schematic = SchematicFile.load(inputFile)

            outputData = {}
            outputData["height"], outputData["length"], outputData[
                "width"] = schematic.blocks.shape
            outputData["blocks"] = []

            for x in range(0, outputData["width"]):
                for y in range(0, outputData["height"]):
                    for z in range(0, outputData["length"]):
                        outputData["blocks"].append(
                            str(int(schematic.blocks[y, z, x])) + ":" +
                            str(int(schematic.data[y, z, x])))

            outputFile = open(
                outputDirectory + "/" +
                os.path.splitext(os.path.basename(inputFile))[0] + ".json",
                "w")
            outputFile.write(json.dumps(outputData))
            outputFile.close()

            return "Success : Blocks file saved to : " + outputDirectory + "/" + os.path.splitext(
                os.path.basename(inputFile))[0] + ".json !"
        else:
            return "Error : Output specified doesn't exist or is not a directory."
    else:
        return "Error : Input file doesn't exist."
Exemplo n.º 4
0
def read_bv_schematic(fn, scene_file):
    fileformat = 'schematic'
    with open(scene_file) as f:
        scene_json = json.load(f)
    scene_obj_list = scene_json['objects']
    print("num objs ", len(scene_obj_list))
    # check if extra object voxels need to be removed from blocks
    remove_extra_objects = True
    orig_block_id = int(scene_obj_list[0]['obj_id'].split('blockid_')[-1])
    if len(scene_obj_list) == 1:
        remove_extra_objects = True
        orig_block_id = int(scene_obj_list[0]['obj_id'].split('blockid_')[-1])
    # load image
    if fileformat == 'schematic':
        voxel_file = fn
        sf = SchematicFile.load(voxel_file)
        blocks = np.frombuffer(sf.blocks, dtype=sf.blocks.dtype)
        voxel_size = int(round(len(blocks)**(1. / 3)))
        blocks = blocks.reshape((voxel_size, voxel_size, voxel_size))
        blocks = blocks.copy()
        if remove_extra_objects:
            blocks[blocks != orig_block_id] = 0
    # st()
    data = np.float32(blocks)
    return data
Exemplo n.º 5
0
def makeBlocks(input, location, Z, Y, X):
    sf = SchematicFile(shape=(Y, Z, X))
    assert sf.blocks.shape == (Y, Z, X)

    for y in range(Y):
        for z in range(Z):
            for x in range(X):
                sf.blocks[y, z, x] = input[z, y, x]

    Y = len(sf.blocks)
    #print("Y: ", Y)
    Z = len(sf.blocks[0])
    #print("Z: ", Z)
    X = len(sf.blocks[0][0])
    #print("X: ", X)

    sf.save('location')
Exemplo n.º 6
0
def test_init_writeread(datadir):
    sf = SchematicFile(shape=(3, 3, 3), blocks=COUNTING_C, data=COUNTING_C)
    assert np.all(np.asarray(sf.blocks) == COUNTING_C)
    assert np.all(np.asarray(sf.data) == COUNTING_C)
    outbuf = io.BytesIO()
    outbuf.name = 'none'
    sf.write(outbuf)
    outbuf.seek(0, 0)

    # Can we read it from bytes?
    sf2 = SchematicFile.from_fileobj(outbuf)
    assert np.all(np.asarray(sf2.shape) == (3, 3, 3))
    assert np.all(np.asarray(sf2.blocks) == COUNTING_C)
    assert np.all(np.asarray(sf2.data) == COUNTING_C)

    # Does it match our existing schematic file?
    test_file = os.path.join(datadir, 'counting.schematic')
    with gzip.open(test_file, 'rb') as fd:
        in_bytes = fd.read()
    assert np.all(in_bytes == outbuf.getvalue())
Exemplo n.º 7
0
def test_rewrite_identical(datadir):
    test_file = os.path.join(datadir, 'simple.schematic')
    with gzip.open(test_file, 'rb') as fd:
        in_bytes = fd.read()

    outbuf = io.BytesIO()
    sf = SchematicFile.load(test_file)
    sf.write(outbuf)
    out_bytes = outbuf.getvalue()

    assert np.all(in_bytes == out_bytes)
Exemplo n.º 8
0
def generateSchematicFromBlocksFile(inputFile, outputDirectory):
    if os.path.isfile(inputFile):
        if os.path.exists(outputDirectory) and (
                not os.path.isfile(outputDirectory)):
            inputData = json.loads(open(inputFile, "r").read())

            schematic = SchematicFile(shape=(inputData["height"],
                                             inputData["length"],
                                             inputData["width"]))
            assert schematic.blocks.shape == (inputData["height"],
                                              inputData["length"],
                                              inputData["width"])

            currentBlock = 0
            for x in range(0, inputData["width"]):
                for y in range(0, inputData["height"]):
                    for z in range(0, inputData["length"]):
                        schematic.blocks[y, z, x] = int(
                            (inputData["blocks"][currentBlock]).split(":")[0])
                        schematic.data[y, z, x] = int(
                            (inputData["blocks"][currentBlock]).split(":")[1])
                        currentBlock += 1

            schematic.save(outputDirectory + "/" +
                           os.path.splitext(os.path.basename(inputFile))[0] +
                           ".schematic")

            return "Success : Schematic file saved to : " + outputDirectory + "/" + os.path.splitext(
                os.path.basename(inputFile))[0] + ".schematic !"
        else:
            return "Error : Output specified doesn't exist or is not a directory."
    else:
        return "Error : Input file doesn't exist."
Exemplo n.º 9
0
def makeArray(location):
    sf = SchematicFile.load(location)

    Y = len(sf.blocks)
    #print("Y: ", Y)
    Z = len(sf.blocks[0])
    #print("Z: ", Z)
    X = len(sf.blocks[0][0])
    #print("X: ", X)

    breakpoint
    array = np.zeros(Z * Y * X).reshape(Z, Y, X)

    for y in range(Y):
        for z in range(Z):
            for x in range(X):
                array[z, y, x] = sf.blocks[y, z, x]
    return array
Exemplo n.º 10
0
def test_shape_mismatch():
    sf = SchematicFile(shape=(3, 2, 1))
    sf.blocks = np.zeros((3, 2, 1))
    sf.data = np.zeros((3, 2, 1))
    try:
        sf.blocks = np.zeros((3, 1, 2))
        assert False
    except ValueError:
        assert True
    try:
        sf.data = np.zeros((3, 1, 2))
        assert False
    except ValueError:
        assert True
Exemplo n.º 11
0
def test_load_verify(datadir):
    sf = SchematicFile.load(os.path.join(datadir, 'simple.schematic'))
    assert (sf.material == Material.Alpha)
    assert (np.all(sf.shape == (4, 4, 4)))

    # all blocks are air, except on main diagonal
    expect_blocks = np.zeros((4, 4, 4), dtype=np.uint8)
    expect_blocks[0, 0, 0] = 1
    expect_blocks[1, 1, 1] = 4
    expect_blocks[2, 2, 2] = 24
    expect_blocks[3, 3, 3] = 54
    assert np.all(np.asarray(sf.blocks) == expect_blocks)
    assert sf.data[3, 3, 3] == 2

    # chicken entity
    assert len(sf.entities) == 1
    assert sf.entities[0]['id'] == 'minecraft:chicken'

    # chest tile entity, one occupied slot
    assert len(sf.blockentities) == 1
    assert sf.blockentities[0]['id'] == 'minecraft:chest'
    assert len(sf.blockentities[0]['Items']) == 1
Exemplo n.º 12
0
def test_blocks_from_numpy():
    sf = SchematicFile(shape=(3, 3, 3))
    sf.blocks = COUNTING_C
    sf.data = np.transpose(COUNTING_C)
    assert np.all(np.asarray(sf.blocks) == COUNTING_C)
    assert np.all(np.asarray(sf.root['Blocks']) == range(0, 27))
    assert np.all(np.asarray(sf.data) == np.transpose(COUNTING_C))
    assert np.all(np.asarray(sf.root['Data']) ==
                  np.transpose(COUNTING_C).flatten())

    sf.blocks = COUNTING_F
    sf.data = np.transpose(COUNTING_F)
    assert np.all(np.asarray(sf.blocks) == COUNTING_F)
    assert np.all(np.asarray(sf.root['Blocks']) == COUNTING_F.reshape(-1))
    assert np.all(np.asarray(sf.data) == np.transpose(COUNTING_F))
    assert np.all(np.asarray(sf.root['Data']) ==
                  np.transpose(COUNTING_F).reshape(-1))
Exemplo n.º 13
0
import time
from mcipc.rcon import Client
from nbtschematic import SchematicFile

sf = SchematicFile.load('eiffel-tower-e1260.schematic')

with Client('localhost', 25575) as client:
    client.login('hurra')

    shape = sf.blocks.shape

    x_offset, y_offset, z_offset = 5033, 69, 4970
    for y in range(shape[0]):
        for z in range(shape[1]):
            for x in range(shape[2]):
                block = sf.blocks[y, z, x]
                if not block == 0:
                    r = client.run(
                        'setblock',
                        f'{x_offset + x} {y_offset + y} {z_offset + z} air')
                    # time.sleep(0.03)
Exemplo n.º 14
0
            else:
                #We have a new block. Print out how many of the previous block we had.
                instruction_string += (str(block_count) + " " + current_block +
                                       " || ")
                current_block = best_block
                block_count = 1
            #At the end of the row, print off the current block run that is truncated by the edge.
            if (pixel == width - 1):
                instruction_string += (str(block_count) + " " + current_block)

    with open("out_list.txt", "w") as f:
        f.write(instruction_string)
if (make_schematic):
    #Parse the image into a Minecraft Schematic file for easy pasting into world
    from nbtschematic import SchematicFile
    sf = SchematicFile(shape=(1, width, height))
    assert sf.blocks.shape == (1, width, height)
    #This dictionary takes a name for a block in the palette, and converts to an in-game block which
    #has that color on the map. Schematics use minecraft block ID's so these are the numbers.
    #First number is block ID, second is data value for things like color.
    name_to_id = {
        "GRASS": (2, 0),
        "SAND": (5, 2),
        "WOOL": (99, 15),
        "FIRE": (152, 0),
        "ICE": (174, 0),
        "METAL": (42, 0),
        "PLANT": (18, 0),
        "SNOW": (80, 0),
        "CLAY": (82, 0),
        "DIRT": (3, 1),
Exemplo n.º 15
0
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm
from nbtschematic import SchematicFile
from mpl_toolkits.mplot3d import Axes3D

res = 64

# vpath = 'output/blendfiles/train/CLEVR_new_000001.schematic'
vpath = 'CLEVR_' + str(res) + '_OBJ_FULL/voxels/train/CLEVR_new_00000%d.schematic'

for img in range(10):
	sf = SchematicFile.load(vpath%img)
	blocks = np.frombuffer(sf.blocks, dtype=sf.blocks.dtype)
	data = np.frombuffer(sf.data, dtype=sf.data.dtype)
	blocks = blocks.reshape((res,res,res))
	# np.save('voxel.npy',blocks)
	vals = np.unique(blocks)
	print(vals)
	colors = np.empty(blocks.shape, dtype=object)
	colorname = ['red','blue','green','black','yellow','cyan','magenta']
	for i,c in zip(vals, colorname):
		colors[blocks == i] = c

	# from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
	# box = [108,  93,   0,  19,  20,  19]
	# Z = np.array([[108,93,0],[108,93,19],[108,113,0],[127,93,0],[108,113,19],[127,113,0],[127,93,19],[127,113,19]])
	# verts = [[Z[0],Z[1],Z[2],Z[3]],
	#  [Z[4],Z[5],Z[6],Z[7]], 
	#  [Z[0],Z[1],Z[5],Z[4]], 
	#  [Z[2],Z[3],Z[7],Z[6]], 
Exemplo n.º 16
0
import sys
import numpy as np
from nbtschematic import SchematicFile

voxel_file = sys.argv[1]
voxel_size = int(sys.argv[2])
sf = SchematicFile.load(voxel_file)
blocks = np.frombuffer(sf.blocks, dtype=sf.blocks.dtype)
blocks = blocks.reshape((voxel_size, voxel_size, voxel_size))
blocks = np.moveaxis(blocks, [0, 1, 2], [1, 0, 2])
temp_np_file = voxel_file.split('.schematic')[0] + '.npy'
np.save(temp_np_file, blocks)
Exemplo n.º 17
0
def wóda(x, y, color):
    j = x * 3
    k = y * 3
    col = color
    # TODO color based on rgb values
    sf.blocks[j, k, 0] = col
    sf.blocks[j + 1, k, 0] = col
    sf.blocks[j, k + 1, 0] = col
    sf.blocks[j + 1, k + 1, 0] = col


X = 26
Y = 38
Z = 1
sf = SchematicFile(shape=(X, Y, Z))
assert sf.blocks.shape == (X, Y, Z)
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            sf.blocks[x, y, z] = 80

for x in range(0, X, 3):
    for y in range(0, Y, 3):
        for z in range(Z):
            sf.blocks[x, y, z] = 95
            sf.blocks[x + 1, y, z] = 95
            sf.blocks[x, y + 1, z] = 95
            sf.blocks[x + 1, y + 1, z] = 95
sf.blocks[0, 0, 0] = 41
wóda(2, 3, 4)
Exemplo n.º 18
0
def test_set_materials():
    sf = SchematicFile()
    sf.material = Material.Classic
    assert (sf.material == Material.Classic)
@author: coren
"""

import mcpi.minecraft as minecraft
import mcpi.block as block
import time
from nbtschematic import SchematicFile
import numpy as np

mc = minecraft.Minecraft.create()
Nombre_pixel_art = 22  #Nombre de pixel art qu'on veut faire à la suite

for t in range(1, Nombre_pixel_art + 1):

    sf = SchematicFile.load(
        str(t) + '.schematic'
    )  #Fichier schematic. Pour la conversion d'une image en schematic utiliser le logiciel Spritecraft
    #Nommer les fichiers schematic de "1" à Nombre_pixel_art
    largeur = int(sf['Schematic']['Width'])
    longueur = int(sf['Schematic']['Length'])

    #mc.player.setPos(largeur/2,longueur/2,-125)
    L = []
    for i in range(longueur):
        for j in range(largeur):
            L.append([i, j])

    np.random.seed(30)
    L = np.random.permutation(L)

    time.sleep(20)