Added up vector management
This commit is contained in:
@@ -70,9 +70,11 @@ class Face:
|
||||
class ModelParser:
|
||||
"""Represents a 3D model
|
||||
"""
|
||||
def __init__(self):
|
||||
def __init__(self, up_conversion = None):
|
||||
"""Initializes the model
|
||||
"""
|
||||
self.up_conversion = up_conversion
|
||||
print(up_conversion)
|
||||
self.vertices = []
|
||||
self.normals = []
|
||||
self.tex_coords = []
|
||||
@@ -98,8 +100,16 @@ class ModelParser:
|
||||
|
||||
Will also update its bounding box
|
||||
"""
|
||||
self.vertices.append(vertex)
|
||||
self.bounding_box.add(vertex)
|
||||
# Apply up_conversion to the vertex
|
||||
new_vertex = vertex
|
||||
if self.up_conversion is not None:
|
||||
if self.up_conversion[0] == 'y' and self.up_conversion[1] == 'z':
|
||||
new_vertex = Vector(vertex.y, vertex.z, vertex.x)
|
||||
elif self.up_conversion[0] == 'z' and self.up_conversion[1] == 'y':
|
||||
new_vertex = Vector(vertex.z, vertex.x, vertex.y)
|
||||
|
||||
self.vertices.append(new_vertex)
|
||||
self.bounding_box.add(new_vertex)
|
||||
|
||||
def add_tex_coord(self, tex_coord):
|
||||
"""Adds a texture coordinate element to the current model
|
||||
|
||||
@@ -13,8 +13,8 @@ def is_obj(filename):
|
||||
|
||||
class OBJParser(ModelParser):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def __init__(self, up_conversion = None):
|
||||
super().__init__(up_conversion)
|
||||
self.current_material = None
|
||||
self.mtl = None
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ def is_ply(filename):
|
||||
|
||||
class PLYParser(ModelParser):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def __init__(self, up_conversion = None):
|
||||
super().__init__(up_conversion)
|
||||
self.counter = 0
|
||||
self.elements = []
|
||||
self.inner_parser = PLYHeaderParser(self)
|
||||
|
||||
@@ -10,8 +10,8 @@ def is_stl(filename):
|
||||
|
||||
class STLParser(ModelParser):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def __init__(self, up_conversion = None):
|
||||
super().__init__(up_conversion)
|
||||
self.parsing_solid = False
|
||||
self.parsing_face = False
|
||||
self.parsing_loop = False
|
||||
|
||||
@@ -5,15 +5,15 @@ from .ply import is_ply, PLYParser, PLYExporter
|
||||
from .stl import is_stl, STLParser, STLExporter
|
||||
from .basemodel import ModelParser, Exporter
|
||||
|
||||
def load_model(path):
|
||||
def load_model(path, up_conversion = None):
|
||||
parser = None
|
||||
|
||||
if is_obj(path):
|
||||
parser = OBJParser()
|
||||
parser = OBJParser(up_conversion)
|
||||
elif is_ply(path):
|
||||
parser = PLYParser()
|
||||
parser = PLYParser(up_conversion)
|
||||
elif is_stl(path):
|
||||
parser = STLParser()
|
||||
parser = STLParser(up_conversion)
|
||||
else:
|
||||
raise Exception("File format not supported")
|
||||
|
||||
@@ -35,8 +35,8 @@ def export_model(model, path):
|
||||
|
||||
return exporter
|
||||
|
||||
def convert(input, output):
|
||||
model = load_model(input)
|
||||
def convert(input, output, up_conversion = None):
|
||||
model = load_model(input, up_conversion)
|
||||
exporter = export_model(model, output)
|
||||
return str(exporter)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user