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
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
+1
View File
@@ -74,3 +74,4 @@ class Exporter:
def __init__(self, model):
self.model = model
+4 -1
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'
+3 -1
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