@@ -122,13 +122,24 @@ def __init__(self, *args, show_points: bool = True, show_lines: bool = True, sho
122122 def buffergeometry (self ) -> BufferGeometry :
123123 return self .item
124124
125+ def _get_num_vertices (self , positions : NDArray ) -> int :
126+ """Get the number of vertices from positions array.
127+
128+ Handles both flat 1D arrays [x1, y1, z1, x2, y2, z2, ...] and
129+ 2D arrays with shape (N, 3).
130+ """
131+ if positions .ndim == 1 :
132+ return positions .shape [0 ] // 3
133+ else :
134+ return positions .shape [0 ]
135+
125136 def _read_points_data (self ):
126137 """Read points data from the object."""
127138 if self .buffergeometry .points is None :
128139 return None
129140 positions = self .buffergeometry .points
130141 colors = self .buffergeometry .pointcolor
131- elements = np .arange (positions . shape [ 0 ] // 3 , dtype = int )
142+ elements = np .arange (self . _get_num_vertices ( positions ) , dtype = int )
132143 return positions , colors , elements
133144
134145 def _read_lines_data (self ):
@@ -137,7 +148,7 @@ def _read_lines_data(self):
137148 return None
138149 positions = self .buffergeometry .lines
139150 colors = self .buffergeometry .linecolor
140- elements = np .arange (positions . shape [ 0 ] // 3 , dtype = int )
151+ elements = np .arange (self . _get_num_vertices ( positions ) , dtype = int )
141152 return positions , colors , elements
142153
143154 def _read_frontfaces_data (self ):
@@ -146,7 +157,7 @@ def _read_frontfaces_data(self):
146157 return None
147158 positions = self .buffergeometry .faces
148159 colors = self .buffergeometry .facecolor
149- elements = np .arange (positions . shape [ 0 ] // 3 , dtype = int )
160+ elements = np .arange (self . _get_num_vertices ( positions ) , dtype = int )
150161 return positions , colors , elements
151162
152163 def _read_backfaces_data (self ):
@@ -155,5 +166,5 @@ def _read_backfaces_data(self):
155166 return None
156167 positions = self .buffergeometry .faces
157168 colors = self .buffergeometry .facecolor
158- elements = np .flip (np .arange (positions . shape [ 0 ] // 3 , dtype = int ))
169+ elements = np .flip (np .arange (self . _get_num_vertices ( positions ) , dtype = int ))
159170 return positions , colors , elements
0 commit comments