skoch9 / meshplot

Plot 3D triangle meshes
GNU General Public License v3.0
148 stars 37 forks source link

`AttributeError: 'LineSegmentsGeometry' object has no attribute 'attributes'` #36

Closed kbrodt closed 3 years ago

kbrodt commented 3 years ago

Hi,

The following code in OFFLINE mode raises an error AttributeError: 'LineSegmentsGeometry' object has no attribute 'attributes', though in JUPYTER one it renders good but with the same error.

import meshplot as mp
import numpy as np

mp.offline()  # comment in JUPYTER mode

v = np.array([
    [0, 0, 0],
    [1, 0, 0],
    [1, 1, 1],
    [2, 1, 0],
], dtype="float32")

f = np.array([
    [0, 1, 2],
    [1, 3, 2],
])

p = mp.plot(v, f, filename="example_1")
p.add_lines(v, v + 0.1)
p.save("example_2")
kbrodt commented 3 years ago

Quick fix: replace https://github.com/skoch9/meshplot/blob/725e4a7926a5f10888f0edd1762fecf9db751c56/meshplot/Viewer.py#L464 and https://github.com/skoch9/meshplot/blob/725e4a7926a5f10888f0edd1762fecf9db751c56/meshplot/Viewer.py#L498 to

geometry = self.__objects[obj]["geometry"]
if isinstance(geometry, p3s.LineSegmentsGeometry):
    v = geometry.positions
else:
    v = geometry.attributes["position"].array