Example #1
0
    def test_find_vertices(self):
        a = Vec3(10, 20, 30)
        b = Vec3(0, -10, 50)

        result = CoordinateUtils._find_vertices(a, b)

        self.assertEquals(result[0].x, 0)
        self.assertEquals(result[0].y, -10)
        self.assertEquals(result[0].z, 30)
        self.assertEquals(result[1].x, 10)
        self.assertEquals(result[1].y, 20)
        self.assertEquals(result[1].z, 50)
def main():
    coord_to_save = []


    ## build explorer ships
    x = -130
    y = 40
    Zs = [200, 250]
    gap_x = 30
    for i in range(0, 8):
        for z in Zs:
            v = Vec3(x, y, z)
            explorer_data = CoordinateUtils.shift_coordinates(DATA['explorer'], v)
            scanner.print_3d(explorer_data)
            coord_to_save.append(explorer_data)
            explorer_data['name'] = 'explorer'
        x += gap_x


    ## build comand ship 1
    x = -140
    y = 40
    z = 50
    v = Vec3(x, y, z)
    command_data = CoordinateUtils.shift_coordinates(DATA['command'], v)
    scanner.print_3d(command_data)
    command_data['name'] = 'command'
    coord_to_save.append(command_data)


    ## build comand ship 2
    x = 60
    y = 40
    z = 50
    v = Vec3(x, y, z)
    command_data = CoordinateUtils.shift_coordinates(DATA['command'], v)
    scanner.print_3d(command_data)
    command_data['name'] = 'command'
    coord_to_save.append(command_data)


    ## build mother
    x = -40
    y = 40
    z = 50
    v = Vec3(x, y, z)
    mother_data = CoordinateUtils.shift_coordinates(DATA['mother'], v)
    scanner.print_3d(mother_data)
    mother_data['name'] = 'mother'
    coord_to_save.append(mother_data)


    CoordinateUtils.save_data_to_file(coord_to_save, SPACESHIP_FLEET)
Example #3
0
    def grow_forest(cls,
                    Xo=None,
                    Xe=None,
                    Y=None,
                    Zo=None,
                    Ze=None,
                    exclude=None):
        for i in range(Xo, Xe, cls.TREE_GAP):
            for j in range(Zo, Ze, cls.TREE_GAP):
                tree = random.choice(cls.TREES)
                tree_data = cls.TREE_DATA[tree]

                x = i + random.choice(cls.TREE_RANDOM_GAP)
                z = j + random.choice(cls.TREE_RANDOM_GAP)
                v = Vec3(x, Y, z)

                if not cls.is_within_excluded(v, exclude):
                    data = CoordinateUtils.shift_coordinates(tree_data, v)
                    scanner.print_3d(data)
Example #4
0
class Forest(object):
    BASE_PATH = os.path.dirname(__file__)
    RESOURCES_PATH = os.path.join(BASE_PATH, '..', '..', 'resources')

    EXCLUDE_DISTANCE = 10
    TREE_GAP = 15
    TREE_RANDOM_GAP = range(-3, 3)
    TREE_DATA = {}
    TREE_PATH = os.path.join(RESOURCES_PATH, 'scans', 'trees')
    TREES = ['tree001.json', 'tree001.json', 'tree002_fixed.json']
    for t in TREES:
        TREE_DATA[t] = CoordinateUtils.read_data_from_file(
            (os.path.join(TREE_PATH, t)))

    @classmethod
    def grow_forest(cls,
                    Xo=None,
                    Xe=None,
                    Y=None,
                    Zo=None,
                    Ze=None,
                    exclude=None):
        for i in range(Xo, Xe, cls.TREE_GAP):
            for j in range(Zo, Ze, cls.TREE_GAP):
                tree = random.choice(cls.TREES)
                tree_data = cls.TREE_DATA[tree]

                x = i + random.choice(cls.TREE_RANDOM_GAP)
                z = j + random.choice(cls.TREE_RANDOM_GAP)
                v = Vec3(x, Y, z)

                if not cls.is_within_excluded(v, exclude):
                    data = CoordinateUtils.shift_coordinates(tree_data, v)
                    scanner.print_3d(data)

    @classmethod
    def is_within_excluded(cls, v=None, exclude=None):
        for ex in exclude:
            if ex['min']['x'] - cls.EXCLUDE_DISTANCE <= v.x <= ex['max']['x'] + cls.EXCLUDE_DISTANCE \
                    and ex['min']['z'] - cls.EXCLUDE_DISTANCE <= v.z <= ex['max']['z'] + cls.EXCLUDE_DISTANCE:
                return True
        return False
    #gap_z = 208 - 197
    #v = Vec3(Xo, Yo, Zo)
    #data_file = HOUSE_DATA
    #data = CoordinateUtils.read_data_from_file(data_file)
    #for i in range(0, 2):
    #    print("Printing ...")
    #    house_data = CoordinateUtils.shift_coordinates(data, v)
    #    scanner.print_3d(house_data)
    #    v = Vec3(v.x, v.y, v.z + gap_z)

    ##### scan mansion
    print("Scanning ...")
    v1 = Vec3(Xo, Yo, Zo)
    v2 = Vec3(45, 19, 121)
    data_file = MANSION_DATA
    data = scanner.scan_3d(v1, v2)
    data = CoordinateUtils.calculate_relative_coordinates(data)
    CoordinateUtils.save_data_to_file(data, data_file)

    #### build mansion
    x = 65
    y = 0
    z = 197
    v = Vec3(x, y, z)
    print("Printing ...")
    data_file = MANSION_DATA
    data = CoordinateUtils.read_data_from_file(data_file)
    data = CoordinateUtils.shift_coordinates(data, v)
    scanner.print_3d(data)
#
    #data = CoordinateUtils.read_data_from_file(data_file)
    #data = CoordinateUtils.shift_coordinates(data, v)
    #scanner.print_3d(data)


    ###### scan mansion
    #print("Scanning ...")
    #v1 = Vec3(Xo, Yo, Zo)
    #v2 = Vec3(-129, 24, 67)
    #data_file = MANSION_DATA
    #data = scanner.scan_3d(v1, v2)
    #data = CoordinateUtils.calculate_relative_coordinates(data)
    #CoordinateUtils.save_data_to_file(data, data_file)



    #### build mansion
    x = 140
    y = 0
    z  = 0
    v = Vec3(x, y, z)
    print("Printing ...")
    data_file = MANSION_DATA
    data = CoordinateUtils.read_data_from_file(data_file)
    data = CoordinateUtils.shift_coordinates(data, v)
    scanner.print_3d(data)




mc = minecraft.Minecraft.create()
scanner = ScanPrint3D(mc)


SPACESHIP_FLEET = 'spaceship_fleet_002.json'

BASE_PATH = os.path.dirname(__file__)
RESOURCES_PATH = os.path.join(BASE_PATH, '..', '..', 'resources', 'scans', 'spaceships')
DATA_FILES = {
    'command':  os.path.join(RESOURCES_PATH, 'command_ship_002.json'),
    'explorer': os.path.join(RESOURCES_PATH, 'explorer_ship_002.json'),
    'mother':   os.path.join(RESOURCES_PATH, 'mother_ship_002.json'),
}
DATA = {}
for d in DATA_FILES:
    DATA[d] = CoordinateUtils.read_data_from_file(DATA_FILES[d])



def main():
    coord_to_save = []


    ## build explorer ships
    x = -130
    y = 40
    Zs = [200, 250]
    gap_x = 30
    for i in range(0, 8):
        for z in Zs:
            v = Vec3(x, y, z)
Example #8
0
import mcpi.block as block
import time
from mcpi.vec3 import Vec3
import os
import random

from jljc.printer_3d.coordinate_utils import CoordinateUtils
from jljc.printer_3d.scan_print_3d import ScanPrint3D

TREE_GAP = 15
TREE_RANDOM_GAP = range(-3, 3)
TREE_DATA = {}
TREE_PATH = '../resources/scans/trees'
TREES = ['tree001.json', 'tree002.json']
for t in TREES:
    TREE_DATA[t] = CoordinateUtils.read_data_from_file(
        (os.path.join(TREE_PATH, t)))

mc = minecraft.Minecraft.create()
scanner = ScanPrint3D(mc)

time.sleep(2)
pos = mc.player.getTilePos()
mc.postToChat("x: {0} y: {1} z: {2}".format(str(pos.x), str(pos.y),
                                            str(pos.z)))

## starting coordinates
Y = 0

Xo = -200
Zo = 0
Example #9
0
    #v1 = Vec3(120, 0, -217)
    #v2 = Vec3(128, 4, -208)

    ### scan house
    #data = scanner.scan_3d(v1, v2)
    #data = CoordinateUtils.calculate_relative_coordinates(data)
    #CoordinateUtils.save_data_to_file(data, DATA_FILE)

    ## point to house
    v = Vec3(112, 0, -234)

    ### build house
    #data = CoordinateUtils.read_data_from_file(DATA_FILE)
    #data = CoordinateUtils.shift_coordinates(data, v)
    #scanner.print_3d(data)

    ## build street
    gap_z = -10
    orig_data = CoordinateUtils.read_data_from_file(DATA_FILE)

    #import pprint
    #pprint.pprint(orig_data)

    gap_z += -1 * (orig_data['box']['max']['z'] - orig_data['box']['min']['z'])
    for i in range(0, 10):
        print(v)
        data = CoordinateUtils.shift_coordinates(orig_data, v)
        scanner.print_3d(data)
        v.z += gap_z
        time.sleep(3)
Example #10
0
def main():

    exclude = []
    coord_to_save = []

    ## build Talia's mansion
    x = -140
    y = 0
    z = 120
    v = Vec3(x, y, z)
    hill_data = CoordinateUtils.shift_coordinates(DATA['mansion_hill'], v)
    scanner.print_3d(hill_data)
    v = Vec3(x + 4, -5, z + 8)
    talia_mansion = CoordinateUtils.shift_coordinates(DATA['talia_mansion'], v)
    scanner.print_3d(talia_mansion)
    exclude.append(hill_data['box'])
    coord_to_save.append({
        'box': talia_mansion['box'],
        'levels': 5,
        'name': 'talia_mansion'
    })

    ## build pond
    Xo = -38
    Zo = 150
    Xi = Xo + 50
    Zi = Zo + 70
    exclude.append(
        Pond.build_pond(Y=-1,
                        Xo=Xo,
                        Xi=Xi,
                        Zo=Zo,
                        Zi=Zi,
                        factor_z=6,
                        factor_x=4))

    ## build Talia's mansion
    x = -140
    y = 0
    z = 220
    v = Vec3(x, y, z)
    hill_data = CoordinateUtils.shift_coordinates(DATA['mansion_hill'], v)
    scanner.print_3d(hill_data)
    v = Vec3(x + 4, -5, z + 8)
    selina_mansion = CoordinateUtils.shift_coordinates(DATA['selina_mansion'],
                                                       v)
    scanner.print_3d(selina_mansion)
    exclude.append(hill_data['box'])
    coord_to_save.append({
        'box': selina_mansion['box'],
        'levels': 5,
        'name': 'selina_mansion'
    })

    ## build houses
    x = 40
    y = -9
    z = 120
    for i in range(0, 4):
        v = Vec3(x, y, z)
        house_data = CoordinateUtils.shift_coordinates(DATA['house'], v)
        scanner.print_3d(house_data)
        z += 50
        exclude.append(house_data['box'])
        coord_to_save.append({
            'box': house_data['box'],
            'levels': 3,
            'name': 'houses'
        })

    ## village
    Xo = -43
    Zo = 4
    Xe = 30
    Ze = 88
    village = {
        'box': {
            'min': {
                'x': Xo,
                'y': 0,
                'z': Zo
            },
            'max': {
                'x': Xe,
                'y': 0,
                'z': Ze
            }
        },
        'levels': 1,
        'name': 'village'
    }
    exclude.append(village['box'])
    coord_to_save.append(village)

    ## save city coordinates
    CoordinateUtils.save_data_to_file(coord_to_save, CITY_WORLD)

    ## grow forest within world limits
    Xo = -150
    Xe = 80
    Zo = -4
    Ze = 320
    Forest.grow_forest(Xo, Xe, 0, Zo, Ze, exclude)
Example #11
0
    def test_shift_coordinates(self):
        datain = {
            'box': {
                'min': {
                    'x': 0,
                    'y': 0,
                    'z': 0
                },
                'max': {
                    'x': 10,
                    'y': 10,
                    'z': 10
                }
            },
            'data': [{
                'coord': {
                    'x': 0,
                    'y': 0,
                    'z': 0
                },
                'block': {
                    'id': 1,
                    'data': 0
                }
            }, {
                'coord': {
                    'x': 10,
                    'y': 10,
                    'z': 10
                },
                'block': {
                    'id': 1,
                    'data': 0
                }
            }]
        }
        expected = {
            'box': {
                'min': {
                    'x': 10,
                    'y': 15,
                    'z': 20
                },
                'max': {
                    'x': 20,
                    'y': 25,
                    'z': 30
                }
            },
            'data': [{
                'coord': {
                    'x': 10,
                    'y': 15,
                    'z': 20
                },
                'block': {
                    'id': 1,
                    'data': 0
                }
            }, {
                'coord': {
                    'x': 20,
                    'y': 25,
                    'z': 30
                },
                'block': {
                    'id': 1,
                    'data': 0
                }
            }]
        }
        saved = copy.deepcopy(datain)

        result = CoordinateUtils.shift_coordinates(datain, Vec3(10, 15, 20))

        self.assertDictEqual(result, expected)
        self.assertDictEqual(saved, datain)