Skip to content

Commit 8d5a65d

Browse files
committed
Validate index attribute on BufferGeometry
1 parent 1d71471 commit 8d5a65d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

pythreejs/core/BufferAttribute.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import numpy as np
21
from ipywidgets import register
3-
from traitlets import validate, TraitError, Undefined
4-
from ipydatawidgets import NDArrayWidget
52

63
from .BufferAttribute_autogen import BufferAttribute as BaseBufferAttribute
74

pythreejs/geometries/PlainBufferGeometry.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11

2-
from ipywidgets import register
2+
from ipywidgets import register, widget_serialization
3+
from traitlets import validate, TraitError
4+
from ipydatawidgets import NDArrayWidget
5+
36
from .PlainBufferGeometry_autogen import PlainBufferGeometry as PlainBufferGeometryBase
47

58

9+
610
@register
711
class PlainBufferGeometry(PlainBufferGeometryBase):
812

@@ -12,5 +16,17 @@ def from_geometry(cls, geometry):
1216
"""
1317
return cls(_ref_geometry=geometry)
1418

19+
@validate('attributes')
20+
def validate(self, proposal):
21+
value = proposal['value']
1522

23+
if 'index' in value:
24+
# We treat index special, so we might as well do some checking:
25+
idx = value['index']
26+
array = idx.array if isinstance(idx, NDArrayWidget) else idx.array
27+
if array.dtype.kind != 'u':
28+
raise TraitError('Index attribute must have unsigned integer data')
29+
if array.ndim != 1:
30+
raise TraitError('Index attribute must be a flat array. Consider using array.ravel().')
1631

32+
return value

0 commit comments

Comments
 (0)