Example #1
0
import math
import sys
import coloredlogs
from pyvox.parser import VoxParser

coloredlogs.install(level='DEBUG')

m = VoxParser(sys.argv[1]).parse()

img = m.to_dense()

import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
import numpy as np

cm = ListedColormap(np.array(m.palette, dtype='f') / 256)

s = math.ceil(math.sqrt(img.shape[0]))
print('size', img.shape, s)
f, arr = plt.subplots(s, s)
for i, slc in enumerate(img):
    arr[i // s, i % s].imshow(img[i], cmap=cm)
for a in range(i + 1, s * s):
    arr[a // s, a % s].imshow(np.zeros(img.shape[1:3]))

plt.show()
Example #2
0
import math
import sys
import coloredlogs
from pyvox.parser import VoxParser

coloredlogs.install(level='DEBUG')

m = VoxParser(sys.argv[1]).parse()

img = m.to_dense()

import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
import numpy as np

cm = ListedColormap(np.array(m.palette, dtype='f')/256)

s = math.ceil(math.sqrt(img.shape[0]))
print('size', img.shape, s)
f, arr = plt.subplots(s,s)
for i, slc in enumerate(img):
    arr[i//s, i%s].imshow(img[i], cmap=cm)
for a in range(i+1, s*s):
    arr[a//s, a%s].imshow(np.zeros(img.shape[1:3]))

plt.show()
Example #3
0
def load_voxel_sample(path):
    vox_parser = VoxParser(path).parse()
    sample = vox_parser.to_dense()
    sample = np.expand_dims(sample, axis=3)
    return sample
Example #4
0
from matplotlib import cm
from matplotlib.colors import ListedColormap
from pyvox.parser import VoxParser
import matplotlib.pyplot as plt
import numpy as np
import math

map = VoxParser(
    "C:/Users/itmm/Documents/Ap Principals Mpas/Stress Test.vox").parse()
array = map.to_dense()
print(array.shape)
voxelList = array.tolist()
newList = []
outputString = ""
for z in range(len(voxelList)):
    newZ = []
    for x in range(len(voxelList[z])):
        newX = voxelList[z][x]
        if sum(voxelList[z][x]) == 0:
            newX = []
            newZ.append(newX)
            continue
        indexItem = 0
        for item in voxelList[z][x]:
            newItem = item
            outputString = ""
            if item != 0:

                # 1.2
                if z != len(voxelList) - 1 and voxelList[z +
                                                         1][x][indexItem] != 0:
Example #5
0
sys.path.append('/Users/huntingt/Documents/6.111/py-vox-io')

from pyvox.parser import VoxParser
from octree import Octree
from argparse import ArgumentParser

if __name__ == '__main__':
    parser = ArgumentParser("Parse a magica voxel file into an octree format")
    parser.add_argument('input', help="input octree filename")
    parser.add_argument('size', type=int, help="cells per octree side")
    parser.add_argument('-oc', help="output .oc file representing the tree")
    parser.add_argument('-mat',
                        help="output .mat file representing the materials")
    args = parser.parse_args()

    m = VoxParser(args.input).parse()
    oc = Octree(args.size)

    for model in m.models:
        for voxel in model.voxels:
            oc.set(voxel.x, voxel.y, voxel.z, voxel.c)

    if args.oc:
        with open(args.oc, 'w') as f:
            f.write(oc.toOC())

    if args.mat:
        output = "0x000000\n"
        for color in m.palette:
            output += f"0x{color.b:0{2}x}{color.g:0{2}x}{color.r:0{2}x}\n"
Example #6
0
import logging
import coloredlogs
from pyvox.parser import VoxParser
from pyvox.writer import VoxWriter

log = logging.getLogger(__name__)

coloredlogs.install(level='DEBUG')

parser = argparse.ArgumentParser(
    description='Testing roundtrip for vox saving and parsing')
parser.add_argument("voxfilename", help="VOX model filename")
args = parser.parse_args()

log.info("Reading vox file: " + args.voxfilename)

m1 = VoxParser(args.voxfilename).parse()

log.info("File read; writing to test.vox")

VoxWriter('test.vox', m1).write()

log.info("Reading vox file: test.vox")

m2 = VoxParser('test.vox').parse()

if (m1.models == m2.models):
    log.info("Round trip: SUCCESS")
else:
    log.error("Round trip: FAILURE, models do not match")
Example #7
0
import sys
import coloredlogs
from pyvox.parser import VoxParser
from pyvox.writer import VoxWriter

coloredlogs.install(level='DEBUG')

m1 = VoxParser(sys.argv[1]).parse()

print(m1)

VoxWriter('test.vox', m1).write()

m2 = VoxParser('test.vox').parse()

print(m2)

assert m1.models == m2.models
Example #8
0
File: io.py Project: msraig/mp_gan
def load_vox(filename):
    _voxel_data = VoxParser(filename).parse().to_dense()
    _voxel_data = _voxel_data[:,::-1,:]

    return _voxel_data
Example #9
0
import math
import sys
import coloredlogs
from pyvox.parser import VoxParser

coloredlogs.install(level='DEBUG')

m = VoxParser(sys.argv[1]).parse()

print(m.palette)

img = m.to_dense_rgba()

import matplotlib.pyplot as plt
import numpy as np

s = math.ceil(math.sqrt(img.shape[0]))
print('size', img.shape, s)
f, arr = plt.subplots(s,s)
for i, slc in enumerate(img):
    arr[i//s, i%s].imshow(img[i])
for a in range(i+1, s*s):
    arr[a//s, a%s].imshow(np.zeros(img.shape[1:3]))

plt.show()