Skip to content

Commit 2b9ef90

Browse files
committed
mesh -> save node properties in json
1 parent 53434a4 commit 2b9ef90

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

openglider/mesh/mesh.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@
1212
class Vertex(object):
1313
dmin = 10**-10
1414

15-
def __init__(self, x, y, z):
15+
def __init__(self, x, y, z, attributes=None):
1616
self.set_values(x, y, z)
17-
self.attributes = {}
17+
self.attributes = attributes or {}
1818

1919
def __iter__(self):
2020
yield self.x
2121
yield self.y
2222
yield self.z
2323

24+
def __json__(self):
25+
data = list(self)
26+
if self.attributes:
27+
data.append(self.attributes)
28+
29+
return data
30+
2431
def set_values(self, x, y, z):
2532
self.x = x
2633
self.y = y
@@ -235,7 +242,7 @@ def triangularize(self):
235242

236243
def __json__(self):
237244
vertices, polygons, boundaries = self.get_indexed()
238-
vertices_new = [list(v) for v in vertices]
245+
vertices_new = [v.__json__() for v in vertices]
239246

240247
return {
241248
"vertices": vertices_new,

0 commit comments

Comments
 (0)