2016-11-22 10:27:42 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2016-11-22 14:23:53 +00:00
|
|
|
from .obj import is_obj, OBJParser, OBJExporter
|
|
|
|
from .ply import is_ply, PLYParser, PLYExporter
|
2016-11-30 13:57:58 +00:00
|
|
|
from .stl import is_stl, STLParser, STLExporter
|
2016-11-25 13:56:37 +00:00
|
|
|
from .basemodel import ModelParser, Exporter
|
2016-11-22 10:27:42 +00:00
|
|
|
|
2016-11-30 14:37:58 +00:00
|
|
|
def load_model(path, up_conversion = None):
|
2016-11-22 10:27:42 +00:00
|
|
|
parser = None
|
|
|
|
|
|
|
|
if is_obj(path):
|
2016-11-30 14:37:58 +00:00
|
|
|
parser = OBJParser(up_conversion)
|
2016-11-22 10:27:42 +00:00
|
|
|
elif is_ply(path):
|
2016-11-30 14:37:58 +00:00
|
|
|
parser = PLYParser(up_conversion)
|
2016-11-30 13:57:58 +00:00
|
|
|
elif is_stl(path):
|
2016-11-30 14:37:58 +00:00
|
|
|
parser = STLParser(up_conversion)
|
2016-11-22 10:27:42 +00:00
|
|
|
else:
|
|
|
|
raise Exception("File format not supported")
|
|
|
|
|
|
|
|
parser.parse_file(path)
|
|
|
|
|
|
|
|
return parser
|
2016-11-22 14:23:53 +00:00
|
|
|
|
|
|
|
def export_model(model, path):
|
|
|
|
exporter = None
|
|
|
|
|
|
|
|
if is_obj(path):
|
|
|
|
exporter = OBJExporter(model)
|
|
|
|
elif is_ply(path):
|
|
|
|
exporter = PLYExporter(model)
|
2016-11-30 13:57:58 +00:00
|
|
|
elif is_stl(path):
|
|
|
|
exporter = STLExporter(model)
|
2016-11-22 14:23:53 +00:00
|
|
|
else:
|
|
|
|
raise Exception("File format not supported")
|
|
|
|
|
|
|
|
return exporter
|
|
|
|
|
2016-11-30 14:37:58 +00:00
|
|
|
def convert(input, output, up_conversion = None):
|
|
|
|
model = load_model(input, up_conversion)
|
2016-11-22 14:23:53 +00:00
|
|
|
exporter = export_model(model, output)
|
|
|
|
return str(exporter)
|
|
|
|
|