16
16
from traitlets import (Unicode , Int , CInt , Instance , Enum , List , Dict , Float ,
17
17
CFloat , Bool )
18
18
from ._package import npm_pkg_name
19
+ from .enums import (
20
+ Equations , DestinationFactors , SourceFactors , Side , Shading , Colors ,
21
+ BlendingMode , Operations , MappingModes , WrappingModes , Filters ,
22
+ DataTypes , PixelTypes , PixelFormats , CompressedTextureFormats ,
23
+ Lines , Renderers )
24
+
19
25
from math import pi , sqrt
20
26
27
+
21
28
def vector3 (trait_type = CFloat , default = None , ** kwargs ):
22
29
if default is None :
23
30
default = [0 , 0 , 0 ]
@@ -56,25 +63,22 @@ class DataTexture(Texture):
56
63
_model_name = Unicode ('DataTextureModel' ).tag (sync = True )
57
64
58
65
data = List (CInt ).tag (sync = True )
59
- format = Enum (['RGBAFormat' , 'AlphaFormat' , 'RGBFormat' , 'LuminanceFormat' ,
60
- 'LuminanceAlphaFormat' ], 'RGBAFormat' ).tag (sync = True )
66
+ format = Enum (PixelFormats , 'RGBAFormat' ).tag (sync = True )
61
67
width = CInt (256 ).tag (sync = True )
62
68
height = CInt (256 ).tag (sync = True )
63
- type = Enum (['UnsignedByteType' , 'ByteType' , 'ShortType' ,
64
- 'UnsignedShortType' , 'IntType' , 'UnsignedIntType' ,
65
- 'FloatType' , 'UnsignedShort4444Type' , 'UnsignedShort5551Type' ,
66
- 'UnsignedShort565Type' ], 'UnsignedByteType' ).tag (sync = True )
67
- mapping = Enum (['UVMapping' , 'CubeReflectionMapping' ,
68
- 'CubeRefractionMapping' , 'SphericalReflectionMapping' ,
69
- 'SphericalRefractionMapping' ], 'UVMapping' ).tag (sync = True )
70
- wrapS = Enum (['ClampToEdgeWrapping' , 'RepeatWrapping' , 'MirroredRepeatWrapping' ],
71
- 'ClampToEdgeWrapping' ).tag (sync = True )
72
- wrapT = Enum (['ClampToEdgeWrapping' , 'RepeatWrapping' , 'MirroredRepeatWrapping' ],
73
- 'ClampToEdgeWrapping' ).tag (sync = True )
74
- magFilter = Enum (['LinearFilter' , 'NearestFilter' ], 'LinearFilter' ).tag (sync = True )
75
- minFilter = Enum (['NearestFilter' , 'NearestMipMapNearestFilter' ,
76
- 'NearestMipMapLinearFilter' , 'LinearFilter' ,
77
- 'LinearMipMapNearestFilter' ], 'NearestFilter' ).tag (sync = True )
69
+ type = Enum (DataTypes , 'UnsignedByteType' ).tag (sync = True )
70
+
71
+ # TODO: this enum includes both DataTypes and PixelTypes?
72
+ # type = Enum(['UnsignedByteType', 'ByteType', 'ShortType',
73
+ # 'UnsignedShortType', 'IntType', 'UnsignedIntType',
74
+ # 'FloatType', 'UnsignedShort4444Type', 'UnsignedShort5551Type',
75
+ # 'UnsignedShort565Type'], 'UnsignedByteType').tag(sync=True)
76
+
77
+ mapping = Enum (MappingModes , 'UVMapping' ).tag (sync = True )
78
+ wrapS = Enum (WrappingModes , 'ClampToEdgeWrapping' ).tag (sync = True )
79
+ wrapT = Enum (WrappingModes , 'ClampToEdgeWrapping' ).tag (sync = True )
80
+ magFilter = Enum (Filters , 'LinearFilter' ).tag (sync = True )
81
+ minFilter = Enum (Filters , 'NearestFilter' ).tag (sync = True )
78
82
anisotropy = CInt (1 ).tag (sync = True )
79
83
80
84
@@ -460,20 +464,13 @@ class Material(Widget):
460
464
461
465
# id = TODO
462
466
name = Unicode (sync = True )
463
- side = Enum ([ 'FrontSide' , 'BackSide' , 'DoubleSide' ] , 'DoubleSide' ).tag (sync = True )
467
+ side = Enum (Side , 'DoubleSide' ).tag (sync = True )
464
468
opacity = CFloat (1.0 ).tag (sync = True )
465
469
transparent = Bool ().tag (sync = True )
466
- blending = Enum (['NoBlending' , 'NormalBlending' , 'AdditiveBlending' ,
467
- 'SubtractiveBlending' , 'MultiplyBlending' ,
468
- 'CustomBlending' ], 'NormalBlending' ).tag (sync = True )
469
- blendSrc = Enum (['ZeroFactor' , 'OneFactor' , 'SrcColorFactor' ,
470
- 'OneMinusSrcColorFactor' , 'SrcAlphaFactor' ,
471
- 'OneMinusSrcAlphaFactor' , 'DstAlphaFactor' ,
472
- 'OneMinusDstAlphaFactor' ], 'SrcAlphaFactor' ).tag (sync = True )
473
- blendDst = Enum (['DstColorFactor' , 'OneMinusDstColorFactor' ,
474
- 'SrcAlphaSaturateFactor' ], 'OneMinusDstColorFactor' ).tag (sync = True )
475
- blendEquation = Enum (['AddEquation' , 'SubtractEquation' ,
476
- 'ReverseSubtractEquation' ], 'AddEquation' ).tag (sync = True )
470
+ blending = Enum (BlendingMode , 'NormalBlending' ).tag (sync = True )
471
+ blendSrc = Enum (DestinationFactors , 'SrcAlphaFactor' ).tag (sync = True )
472
+ blendDst = Enum (SourceFactors , 'OneMinusDstColorFactor' ).tag (sync = True )
473
+ blendEquation = Enum (Equations , 'AddEquation' ).tag (sync = True )
477
474
depthTest = Bool (True ).tag (sync = True )
478
475
depthWrite = Bool (True ).tag (sync = True )
479
476
polygonOffset = Bool (True ).tag (sync = True )
@@ -494,8 +491,8 @@ class BasicMaterial(Material):
494
491
wireframeLinewidth = CFloat (1.0 ).tag (sync = True )
495
492
wireframeLinecap = Unicode ('round' ).tag (sync = True )
496
493
wireframeLinejoin = Unicode ('round' ).tag (sync = True )
497
- shading = Enum ([ 'SmoothShading' , 'FlatShading' , 'NoShading' ] , 'SmoothShading' ).tag (sync = True )
498
- vertexColors = Enum ([ 'NoColors' , 'FaceColors' , 'VertexColors' ] , 'NoColors' ).tag (sync = True )
494
+ shading = Enum (Shading , 'SmoothShading' ).tag (sync = True )
495
+ vertexColors = Enum (Colors , 'NoColors' ).tag (sync = True )
499
496
fog = Bool ().tag (sync = True )
500
497
map = Instance (Texture , allow_none = True ).tag (sync = True , ** widget_serialization )
501
498
lightMap = Instance (Texture , allow_none = True ).tag (sync = True , ** widget_serialization )
@@ -512,8 +509,7 @@ class LambertMaterial(BasicMaterial):
512
509
emissive = Color ('black' ).tag (sync = True )
513
510
reflectivity = CFloat (1.0 ).tag (sync = True )
514
511
refractionRatio = CFloat (0.98 ).tag (sync = True )
515
- combine = Enum (['MultiplyOperation' , 'MixOperation' , 'AddOperation' ],
516
- 'MultiplyOperation' ).tag (sync = True )
512
+ combine = Enum (Operations , 'MultiplyOperation' ).tag (sync = True )
517
513
518
514
519
515
class PhongMaterial (BasicMaterial ):
@@ -525,8 +521,7 @@ class PhongMaterial(BasicMaterial):
525
521
shininess = CFloat (30 ).tag (sync = True )
526
522
reflectivity = CFloat (1.0 ).tag (sync = True )
527
523
refractionRatio = CFloat (0.98 ).tag (sync = True )
528
- combine = Enum (['MultiplyOperation' , 'MixOperation' , 'AddOperation' ],
529
- 'MultiplyOperation' ).tag (sync = True )
524
+ combine = Enum (Operations , 'MultiplyOperation' ).tag (sync = True )
530
525
531
526
532
527
class DepthMaterial (Material ):
@@ -551,7 +546,7 @@ class LineBasicMaterial(_LineMaterial):
551
546
linecap = Unicode ('round' ).tag (sync = True )
552
547
linejoin = Unicode ('round' ).tag (sync = True )
553
548
fog = Bool ().tag (sync = True )
554
- vertexColors = Enum ([ 'NoColors' , 'FaceColors' , 'VertexColors' ] , 'NoColors' ).tag (sync = True )
549
+ vertexColors = Enum (Colors , 'NoColors' ).tag (sync = True )
555
550
556
551
557
552
class LineDashedMaterial (_LineMaterial ):
@@ -563,7 +558,7 @@ class LineDashedMaterial(_LineMaterial):
563
558
scale = CFloat (1.0 ).tag (sync = True )
564
559
dashSize = CFloat (3.0 ).tag (sync = True )
565
560
gapSize = CFloat (1.0 ).tag (sync = True )
566
- vertexColors = Enum ([ 'NoColors' , 'FaceColors' , 'VertexColors' ] , 'NoColors' ).tag (sync = True )
561
+ vertexColors = Enum (Colors , 'NoColors' ).tag (sync = True )
567
562
fog = Bool ().tag (sync = True )
568
563
569
564
@@ -572,7 +567,7 @@ class NormalMaterial(Material):
572
567
_model_name = Unicode ('NormalMaterialModel' ).tag (sync = True )
573
568
574
569
morphTargets = Bool ().tag (sync = True )
575
- shading = Enum ([ 'SmoothShading' , 'FlatShading' , 'NoShading' ] , 'SmoothShading' ).tag (sync = True )
570
+ shading = Enum (Shading , 'SmoothShading' ).tag (sync = True )
576
571
wireframe = Bool ().tag (sync = True )
577
572
wireframeLinewidth = CFloat (1.0 ).tag (sync = True )
578
573
@@ -599,10 +594,10 @@ class ShaderMaterial(Material):
599
594
lights = Bool ().tag (sync = True )
600
595
morphNormals = Bool ().tag (sync = True )
601
596
wireframe = Bool ().tag (sync = True )
602
- vertexColors = Enum ([ 'NoColors' , 'FaceColors' , 'VertexColors' ] , 'NoColors' ).tag (sync = True )
597
+ vertexColors = Enum (Colors , 'NoColors' ).tag (sync = True )
603
598
skinning = Bool ().tag (sync = True )
604
599
fog = Bool ().tag (sync = True )
605
- shading = Enum ([ 'SmoothShading' , 'FlatShading' , 'NoShading' ] , 'SmoothShading' ).tag (sync = True )
600
+ shading = Enum (Shading , 'SmoothShading' ).tag (sync = True )
606
601
linewidth = CFloat (1.0 ).tag (sync = True )
607
602
wireframeLinewidth = CFloat (1.0 ).tag (sync = True )
608
603
@@ -642,7 +637,7 @@ class Line(Mesh):
642
637
_view_name = Unicode ('LineView' ).tag (sync = True )
643
638
_model_name = Unicode ('LineModel' ).tag (sync = True )
644
639
645
- type = Enum ([ 'LineStrip' , 'LinePieces' ] , 'LineStrip' ).tag (sync = True )
640
+ type = Enum (Lines , 'LineStrip' ).tag (sync = True )
646
641
material = Instance (_LineMaterial ).tag (sync = True , ** widget_serialization )
647
642
648
643
@@ -760,7 +755,7 @@ class Renderer(DOMWidget):
760
755
761
756
width = Unicode ('600' ).tag (sync = True ) # TODO: stop relying on deprecated DOMWidget attribute
762
757
height = Unicode ('400' ).tag (sync = True )
763
- renderer_type = Enum ([ 'webgl' , 'canvas' , 'auto' ] , 'auto' ).tag (sync = True )
758
+ renderer_type = Enum (Renderers , 'auto' ).tag (sync = True )
764
759
scene = Instance (Scene ).tag (sync = True , ** widget_serialization )
765
760
camera = Instance (Camera ).tag (sync = True , ** widget_serialization )
766
761
controls = List (Instance (Controls )).tag (sync = True , ** widget_serialization )
0 commit comments