예제 #1
0
def convert_qmo(data, path):
    qmo_file = QubicleFile()
    qmo_model = QubicleModel()
    x_size, y_size, z_size = 256, 256, 256
    qmo_model.x_size = x_size
    qmo_model.y_size = y_size
    qmo_model.z_size = z_size
    qmo_model.x_offset = -x_size / 2
    qmo_model.y_offset = 0
    qmo_model.z_offset = -z_size / 2

    blocks = data.get_dict()

    min_z = max_z = None
    for pos in blocks.keys():
        x, y, z = pos
        if min_z is None:
            min_z = max_z = z
        min_z = min(min_z, z)
        max_z = max(max_z, z)

    qmo_model.y_size = max_z - min_z + 1

    for pos, color in blocks.items():
        x, y, z = switch_axes(*pos)
        y -= min_z
        qmo_model.blocks[(x, y, z)] = color

    qmo_file.models.append(qmo_model)
    writer = ByteWriter()
    qmo_file.write(writer)
    open(path, 'wb').write(writer.get())
예제 #2
0
파일: genchunk.py 프로젝트: matpow2/cuwo
def convert_qmo(data, path):
    qmo_file = QubicleFile()
    qmo_model = QubicleModel()
    x_size, y_size, z_size = 256, 256, 256
    qmo_model.x_size = x_size
    qmo_model.y_size = y_size
    qmo_model.z_size = z_size
    qmo_model.x_offset = -x_size / 2
    qmo_model.y_offset = 0
    qmo_model.z_offset = -z_size / 2

    blocks = data.get_dict()

    min_z = max_z = None
    for pos in blocks.keys():
        x, y, z = pos
        if min_z is None:
            min_z = max_z = z
        min_z = min(min_z, z)
        max_z = max(max_z, z)

    qmo_model.y_size = max_z - min_z + 1

    for pos, color in blocks.items():
        x, y, z = switch_axes(*pos)
        y -= min_z
        qmo_model.blocks[(x, y, z)] = color

    qmo_file.models.append(qmo_model)
    writer = ByteWriter()
    qmo_file.write(writer)
    open(path, 'wb').write(writer.get())
예제 #3
0
파일: convertchunk.py 프로젝트: waoler/cuwo
def convert_qmo(path):
    data = ByteReader(open(path, 'rb').read())

    qmo_file = QubicleFile()
    qmo_model = QubicleModel()
    x_size, y_size, z_size = 256, 256, 256
    qmo_model.x_size = x_size
    qmo_model.y_size = y_size
    qmo_model.z_size = z_size
    qmo_model.x_offset = -x_size / 2
    qmo_model.y_offset = 0
    qmo_model.z_offset = -z_size / 2

    min_z = None
    max_z = None

    for i in xrange(256*256):
        something = data.read_float()
        something2 = data.read_float()
        something3 = data.read_float()
        something4 = data.read_uint32()
        something5 = data.read_uint32()
        size = data.read_uint32()*4
        chunk_data = data.read(size)

        x = i % 256
        y = i / 256

        z = something4

        if min_z is None or max_z is None:
            min_z = z
            max_z = z + len(chunk_data) / 4
        else:
            min_z = min(z, min_z)
            max_z = max(max_z, len(chunk_data) / 4)

        for i in xrange(len(chunk_data) / 4):
            r = ord(chunk_data[i*4])
            g = ord(chunk_data[i*4+1])
            b = ord(chunk_data[i*4+2])
            a = ord(chunk_data[i*4+3])
            if a == 0:
                z += 1
                continue
            qmo_model.blocks[switch_axes(x, y, z)] = (r, g, b)
            z += 1

    qmo_model.y_offset

    qmo_file.models.append(qmo_model)
    writer = ByteWriter()
    qmo_file.write(writer)
    name = os.path.splitext(os.path.basename(path))[0]
    out_path = os.path.join('genqmo', name + '.qmo')
    open(out_path, 'wb').write(writer.get())

    print 'Converted', path
예제 #4
0
def to_qmo(in_file, out_file):
    cub = CubModel(ByteReader(open(in_file, 'rb').read()))
    qmo_file = QubicleFile()
    qmo_model = QubicleModel()
    x_size, y_size, z_size = switch_axes(cub.x_size, cub.y_size, cub.z_size)
    qmo_model.x_size = x_size
    qmo_model.y_size = y_size
    qmo_model.z_size = z_size
    qmo_model.x_offset = -x_size / 2
    qmo_model.y_offset = 0
    qmo_model.z_offset = -z_size / 2
    for k, v in cub.blocks.iteritems():
        x, y, z = k
        x2, y2, z2 = switch_axes(x, y, z)
        qmo_model.blocks[x2, y2, z2] = v
    qmo_file.models.append(qmo_model)
    qmo_file.write(ByteWriter(fp=open(out_file, 'wb')))
예제 #5
0
파일: convertqmo.py 프로젝트: BangL/cuwo
def to_qmo(in_file, out_file):
    cub = CubModel(ByteReader(open(in_file, 'rb').read()))
    qmo_file = QubicleFile()
    qmo_model = QubicleModel()
    x_size, y_size, z_size = switch_axes(cub.x_size, cub.y_size, cub.z_size)
    qmo_model.x_size = x_size
    qmo_model.y_size = y_size
    qmo_model.z_size = z_size
    qmo_model.x_offset = -x_size / 2
    qmo_model.y_offset = 0
    qmo_model.z_offset = -z_size / 2
    for k, v in cub.blocks.iteritems():
        x, y, z = k
        x2, y2, z2 = switch_axes(x, y, z)
        qmo_model.blocks[x2, y2, z2] = v
    qmo_file.models.append(qmo_model)
    qmo_file.write(ByteWriter(fp=open(out_file, 'wb')))