Added function load_model

This commit is contained in:
Thomas FORGIONE 2016-11-22 11:27:42 +01:00
parent 65467fbb0a
commit e5da208ae7
6 changed files with 30 additions and 8 deletions

18
conv3d/loadmodel.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
from .obj import is_obj, OBJParser
from .ply import is_ply, PLYParser
def load_model(path):
parser = None
if is_obj(path):
parser = OBJParser()
elif is_ply(path):
parser = PLYParser()
else:
raise Exception("File format not supported")
parser.parse_file(path)
return parser

View File

@ -74,3 +74,4 @@ class Exporter:
def __init__(self, model):
self.model = model

View File

@ -3,6 +3,9 @@
from .model import ModelParser, Exporter, Vertex, TexCoord, Normal, FaceVertex, Face
from functools import reduce
def is_obj(filename):
return filename[-4:] == '.obj'
class OBJParser(ModelParser):
def __init__(self):
@ -69,7 +72,7 @@ class OBJExporter(Exporter):
elif v.texture is not None:
sub_arr.append(str(int(v.texture) + 1))
if v.normal is not None:
sub_arr.append(str(int(v.normal + 1)))
sub_arr.append(str(int(v.normal) + 1))
arr.append('/'.join(sub_arr))
string += ' '.join(arr) + '\n'

View File

@ -2,6 +2,9 @@
from .model import ModelParser, Exporter, Vertex, Face, FaceVertex
def is_ply(filename):
return filename[-4:] == '.ply'
class PLYParser(ModelParser):
def __init__(self):
@ -102,4 +105,3 @@ class PLYExporter(Exporter):
return string

View File

@ -3,8 +3,8 @@
import argparse
import os
from conv3d.obj import OBJParser
from conv3d.ply import PLYExporter
from conv3d.loadmodel import load_model
from functools import partial
def check_path(path, should_exist):
@ -17,8 +17,7 @@ def check_path(path, should_exist):
return path
def main(args):
parser = OBJParser()
parser.parse_file(args.input)
parser = load_model(args.input)
exporter = PLYExporter(parser)
result = str(exporter)

View File

@ -4,7 +4,7 @@ import argparse
import os
from conv3d.obj import OBJExporter
from conv3d.ply import PLYParser
from conv3d.loadmodel import load_model
from functools import partial
def check_path(path, should_exist):
@ -17,8 +17,7 @@ def check_path(path, should_exist):
return path
def main(args):
parser = PLYParser()
parser.parse_file(args.input)
parser = load_model(args.input)
exporter = OBJExporter(parser)
result = str(exporter)