Added TextModelParser for text files
This commit is contained in:
parent
23a3b4535d
commit
41a13e6014
|
@ -134,23 +134,9 @@ class ModelParser:
|
|||
|
||||
self.current_part.add_face(face)
|
||||
|
||||
def parse_line(self, string):
|
||||
"""Parses a line of a text model
|
||||
|
||||
This method needs to be implemented by each subclass of ModelParser.
|
||||
"""
|
||||
def parse_bytes(self, bytes):
|
||||
pass
|
||||
|
||||
def parse_file(self, path):
|
||||
"""Sets the path of the model and parse each line
|
||||
"""
|
||||
self.path = path
|
||||
with open(path) as f:
|
||||
for line in f.readlines():
|
||||
line = line.rstrip()
|
||||
if line != '':
|
||||
self.parse_line(line)
|
||||
|
||||
def draw(self):
|
||||
"""Draws each part of the model with OpenGL
|
||||
"""
|
||||
|
@ -221,6 +207,17 @@ class ModelParser:
|
|||
face.b.normal = index
|
||||
face.c.normal = index
|
||||
|
||||
class TextModelParser(ModelParser):
|
||||
def parse_file(self, path):
|
||||
"""Sets the path of the model and parse each line
|
||||
"""
|
||||
self.path = path
|
||||
with open(path) as f:
|
||||
for line in f.readlines():
|
||||
line = line.rstrip()
|
||||
if line != '':
|
||||
self.parse_line(line)
|
||||
|
||||
|
||||
class BoundingBox:
|
||||
"""Represents a bounding box of a 3D model
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from ..basemodel import ModelParser, Exporter, Vertex, TexCoord, Normal, FaceVertex, Face
|
||||
from ..basemodel import TextModelParser, Exporter, Vertex, TexCoord, Normal, FaceVertex, Face
|
||||
from ..mesh import Material, MeshPart
|
||||
from functools import reduce
|
||||
import os.path
|
||||
|
@ -8,7 +8,7 @@ import sys
|
|||
def is_obj(filename):
|
||||
return filename[-4:] == '.obj'
|
||||
|
||||
class OBJParser(ModelParser):
|
||||
class OBJParser(TextModelParser):
|
||||
|
||||
def __init__(self, up_conversion = None):
|
||||
super().__init__(up_conversion)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from ..basemodel import ModelParser, Exporter, Vertex, TexCoord, Normal, FaceVertex, Face
|
||||
from ..basemodel import TextModelParser, Exporter, Vertex, TexCoord, Normal, FaceVertex, Face
|
||||
from ..mesh import Material, MeshPart
|
||||
|
||||
def is_off(filename):
|
||||
return filename[-4:] == '.off'
|
||||
|
||||
class OFFParser(ModelParser):
|
||||
class OFFParser(TextModelParser):
|
||||
def __init__(self, up_conversion = None):
|
||||
super().__init__(up_conversion)
|
||||
self.vertex_number = None
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import os
|
||||
import PIL
|
||||
from ..basemodel import ModelParser, Exporter, Vertex, Face, FaceVertex, TexCoord, Material
|
||||
from ..basemodel import ModelParser, TextModelParser, Exporter, Vertex, Face, FaceVertex, TexCoord, Material
|
||||
|
||||
def is_ply(filename):
|
||||
return filename[-4:] == '.ply'
|
||||
|
||||
class PLYParser(ModelParser):
|
||||
class PLYParser(TextModelParser):
|
||||
|
||||
def __init__(self, up_conversion = None):
|
||||
super().__init__(up_conversion)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from ..basemodel import ModelParser, Exporter, Vertex, FaceVertex, Face
|
||||
from ..basemodel import TextModelParser, Exporter, Vertex, FaceVertex, Face
|
||||
from ..mesh import MeshPart
|
||||
|
||||
import os.path
|
||||
|
@ -6,7 +6,7 @@ import os.path
|
|||
def is_stl(filename):
|
||||
return filename[-4:] == '.stl'
|
||||
|
||||
class STLParser(ModelParser):
|
||||
class STLParser(TextModelParser):
|
||||
|
||||
def __init__(self, up_conversion = None):
|
||||
super().__init__(up_conversion)
|
||||
|
|
Loading…
Reference in New Issue