Skip to content

Commit

Permalink
use vector coord if present, update comment about updating colors
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Sep 18, 2024
1 parent 958dbbd commit 4338854
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
30 changes: 17 additions & 13 deletions src/plopp/backends/pythreejs/mesh3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ def __init__(
.astype('uint32', copy=False)
)

pos = (
self._data.coords["vertices"].values.astype('float32')
if 'vertices' in self._data.coords
else np.array(
[
self._data.coords["x"].values.astype('float32', copy=False),
self._data.coords["y"].values.astype('float32', copy=False),
self._data.coords["z"].values.astype('float32', copy=False),
]
).T
)
attributes = {
'position': p3.BufferAttribute(
array=np.array(
[
self._data.coords["x"].values.astype('float32', copy=False),
self._data.coords["y"].values.astype('float32', copy=False),
self._data.coords["z"].values.astype('float32', copy=False),
]
).T
),
'position': p3.BufferAttribute(array=pos),
'color': p3.BufferAttribute(
array=np.broadcast_to(
np.array(to_rgb(f'C{artist_number}' if color is None else color)),
Expand Down Expand Up @@ -129,10 +132,11 @@ def update(self, new_values):
New data to update the mesh values from.
"""
self._data = new_values
# TODO: for now we only update the colors of the mesh. Updating the positions
# of the vertices is doable but is made more complicated by the edges geometry,
# whose positions cannot just be updated. A new geometry and edge lines would
# have to be created, the old one removed from the scene and the new one added.
# TODO: for now we only update the data values of the artist.
# Updating the positions of the vertices is doable but is made more complicated
# by the edges geometry, whose positions cannot just be updated.
# A new geometry and edge lines would have to be created, the old one removed
# from the scene and the new one added.

def bbox(
self,
Expand Down
3 changes: 2 additions & 1 deletion src/plopp/plotting/mesh3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def _preprocess_mesh(
'x': vertices.fields.x,
'y': vertices.fields.y,
'z': vertices.fields.z,
'vertices': vertices,
'faces': sc.scalar(faces),
},
)
Expand All @@ -54,7 +55,7 @@ def mesh3d(
"""
Create a 3D mesh plot.
.. versionadded:: 24.06.0
.. versionadded:: 24.10.0
Parameters
----------
Expand Down

0 comments on commit 4338854

Please sign in to comment.