Sat, 08 Jun 2019 11:17:17 +0300
cleanup
65 | 1 | #!/usr/bin/env python3 |
2 | ''' | |
3 | Routines for parsing LDraw code. | |
4 | ''' | |
2 | 5 | import linetypes |
6 | import re | |
7 | from geometry import * | |
8 | 8 | from colours import Colour |
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
9 | import header |
2 | 10 | |
11 | class BadLdrawLine(Exception): | |
12 | pass | |
13 | ||
54
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
14 | class Model: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
15 | def __init__(self, header, body, *, ldraw_directories, header_size = 0): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
16 | self.header = header |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
17 | self.body = body |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
18 | self.header_size = header_size |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
19 | self.ldraw_directories = ldraw_directories |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
20 | def filter_by_type(self, type): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
21 | yield from [ |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
22 | element |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
23 | for element in self.body |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
24 | if isinstance(element, type) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
25 | ] |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
26 | @property |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
27 | def subfile_references(self): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
28 | yield from self.filter_by_type(linetypes.SubfileReference) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
29 | @property |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
30 | def line_segments(self): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
31 | yield from self.filter_by_type(linetypes.LineSegment) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
32 | @property |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
33 | def triangles(self): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
34 | yield from self.filter_by_type(linetypes.Triangle) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
35 | @property |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
36 | def quadrilaterals(self): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
37 | yield from self.filter_by_type(linetypes.Quadrilateral) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
38 | @property |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
39 | def has_header(self): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
40 | return self.header and not isinstance(self.header, header.BadHeader) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
41 | |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
42 | def model_vertices( |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
43 | model, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
44 | transformation_matrix = None, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
45 | file_cache = None, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
46 | ): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
47 | if transformation_matrix is None: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
48 | transformation_matrix = complete_matrix(Matrix3x3(), Vertex(0, 0, 0)) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
49 | if file_cache is None: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
50 | import filecache |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
51 | file_cache = filecache.SubfileCache(model.ldraw_directories) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
52 | for element in model.body: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
53 | if isinstance(element, linetypes.BasePolygon): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
54 | for point in element.geometry.vertices: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
55 | yield point @ transformation_matrix |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
56 | if isinstance(element, linetypes.ConditionalLine): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
57 | for point in element.control_points: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
58 | yield point @ transformation_matrix |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
59 | if isinstance(element, linetypes.SubfileReference): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
60 | subfile = file_cache.prepare_file(element.subfile_path) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
61 | for point in subfile.vertices: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
62 | matrix_4x4 = complete_matrix(element.matrix, element.anchor) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
63 | point @= matrix_4x4 |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
64 | yield point @ transformation_matrix |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
65 | |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
66 | def read_ldraw(file, *, ldraw_directories, name = ''): |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
67 | model_body = [ |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
68 | parse_ldraw_code(line) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
69 | for line in file |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
70 | ] |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
71 | headerparser = header.HeaderParser() |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
72 | try: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
73 | header_parse_result = headerparser.parse(model_body) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
74 | header_object = header_parse_result['header'] |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
75 | end = header_parse_result['end-index'] |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
76 | except header.HeaderError as error: |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
77 | header_object = header.BadHeader(error.index, error.reason) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
78 | end = 0 |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
79 | model = Model( |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
80 | header = header_object, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
81 | body = model_body, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
82 | header_size = end, |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
83 | ldraw_directories = ldraw_directories) |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
84 | model.name = name |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
85 | return model |
0c686d10eb49
added tests for moved-to files and scaling in flat dimensions
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
86 | |
2 | 87 | def parse_ldraw_code(line): |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
88 | try: |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
89 | if isinstance(line, bytes): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
90 | line = line.decode() |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
91 | line = line.strip() |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
92 | if not line: |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
93 | return linetypes.EmptyLine() |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
94 | elif line == '0': |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
95 | return linetypes.MetaCommand('') |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
96 | elif line.startswith('0 '): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
97 | return parse_ldraw_meta_line(line) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
98 | elif line.startswith('1 '): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
99 | return parse_ldraw_subfile_reference(line) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
100 | elif line.startswith('2 '): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
101 | return parse_ldraw_line(line) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
102 | elif line.startswith('3 '): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
103 | return parse_ldraw_triangle(line) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
104 | elif line.startswith('4 '): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
105 | return parse_ldraw_quadrilateral(line) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
106 | elif line.startswith('5 '): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
107 | return parse_ldraw_conditional_line(line) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
108 | else: |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
109 | raise BadLdrawLine('unknown line type') |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
110 | except BadLdrawLine as error: |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
111 | return linetypes.Error(line, str(error)) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
112 | |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
113 | def parse_ldraw_meta_line(line): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
114 | if line.startswith('0 //'): |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
115 | return linetypes.Comment(line[4:]) |
2 | 116 | else: |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
117 | return linetypes.MetaCommand(line[2:]) |
2 | 118 | |
119 | def parse_ldraw_subfile_reference(line): | |
3
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
2
diff
changeset
|
120 | pattern = r'^1\s+([^ ]+)' + r'\s+([^ ]+)' * (3 + 9 + 1) + r'\s*$' |
2 | 121 | match = re.search(pattern, line) |
122 | if not match: | |
123 | raise BadLdrawLine('unable to parse') | |
124 | groups = list(match.groups()) | |
125 | indices = { | |
4 | 126 | 'colour_index': 0, |
2 | 127 | 'anchor': slice(1, 4), |
128 | 'matrix': slice(4, 13), | |
129 | 'subfile_path': 13 | |
130 | } | |
131 | try: | |
4 | 132 | colour = Colour(groups[indices['colour_index']]) |
2 | 133 | vertex_values = [float(x) for x in groups[indices['anchor']]] |
134 | matrix_values = [float(x) for x in groups[indices['matrix']]] | |
135 | except ValueError: | |
136 | raise BadLdrawLine('bad numeric values') | |
137 | return linetypes.SubfileReference( | |
4 | 138 | colour = colour, |
2 | 139 | anchor = Vertex(*vertex_values), |
6
6da1e81c5652
Added code to compute areas of triangles and quadrilaterals
Santeri Piippo
parents:
4
diff
changeset
|
140 | matrix = Matrix3x3(matrix_values), |
2 | 141 | subfile_path = groups[indices['subfile_path']] |
142 | ) | |
143 | ||
144 | def generic_parse_polygon(line, *, type_code, vertex_count): | |
35 | 145 | pattern = r'^' # matches the start of line |
146 | pattern += str(type_code) # matches the type code | |
147 | pattern += '\s+([^ ]+)' # matches the colour | |
148 | pattern += r'\s+([^ ]+)' * (vertex_count * 3) # matches the vertices | |
149 | pattern += r'\s*$' # matches any trailing space | |
2 | 150 | match = re.search(pattern, line) |
151 | if not match: | |
152 | raise BadLdrawLine(str.format('cannot parse type-{} line', type_code)) | |
153 | vertices = [] | |
154 | for vertex_index in range(vertex_count): | |
155 | slice_begin = 1 + vertex_index * 3 | |
156 | slice_end = 1 + (vertex_index + 1) * 3 | |
157 | coordinates = match.groups()[slice_begin:slice_end] | |
158 | assert(len(coordinates) == 3) | |
159 | try: | |
160 | coordinates = [float(x) for x in coordinates] | |
161 | except ValueError: | |
162 | raise BadLdrawLine('bad numeric values') | |
163 | vertices.append(Vertex(*coordinates)) | |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
164 | try: |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
165 | colour = int(match.group(1), 0) |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
166 | except ValueError: |
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
167 | raise BadLdrawLine('invalid syntax for colour: ' + repr(match.group(1))) |
2 | 168 | return { |
38
66c9591b733d
added proper handling of syntax errors
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
169 | 'colour': Colour(colour), |
2 | 170 | 'vertices': vertices, |
171 | } | |
172 | ||
173 | def parse_ldraw_line(line): | |
174 | parse_result = generic_parse_polygon(line, type_code = 2, vertex_count = 2) | |
175 | return linetypes.LineSegment( | |
4 | 176 | colour = parse_result['colour'], |
2 | 177 | geometry = LineSegment(*parse_result['vertices']), |
178 | ) | |
179 | ||
180 | def parse_ldraw_triangle(line): | |
181 | parse_result = generic_parse_polygon(line, type_code = 3, vertex_count = 3) | |
182 | return linetypes.Triangle( | |
4 | 183 | colour = parse_result['colour'], |
2 | 184 | geometry = Polygon(parse_result['vertices']), |
185 | ) | |
186 | ||
187 | def parse_ldraw_quadrilateral(line): | |
188 | parse_result = generic_parse_polygon(line, type_code = 4, vertex_count = 4) | |
189 | return linetypes.Quadrilateral( | |
4 | 190 | colour = parse_result['colour'], |
2 | 191 | geometry = Polygon(parse_result['vertices']), |
192 | ) | |
193 | ||
35 | 194 | def parse_ldraw_conditional_line(line): |
2 | 195 | parse_result = generic_parse_polygon(line, type_code = 5, vertex_count = 4) |
35 | 196 | return linetypes.ConditionalLine( |
4 | 197 | colour = parse_result['colour'], |
2 | 198 | geometry = LineSegment(*parse_result['vertices'][0:2]), |
199 | control_points = parse_result['vertices'][2:], | |
200 | ) |