16
16
from traitlets import (Unicode , CInt , Instance , Enum , List , Tuple , 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
@@ -464,20 +468,13 @@ class Material(Widget):
464
468
465
469
# id = TODO
466
470
name = Unicode (sync = True )
467
- side = Enum ([ 'FrontSide' , 'BackSide' , 'DoubleSide' ] , 'DoubleSide' ).tag (sync = True )
471
+ side = Enum (Side , 'DoubleSide' ).tag (sync = True )
468
472
opacity = CFloat (1.0 ).tag (sync = True )
469
473
transparent = Bool ().tag (sync = True )
470
- blending = Enum (['NoBlending' , 'NormalBlending' , 'AdditiveBlending' ,
471
- 'SubtractiveBlending' , 'MultiplyBlending' ,
472
- 'CustomBlending' ], 'NormalBlending' ).tag (sync = True )
473
- blendSrc = Enum (['ZeroFactor' , 'OneFactor' , 'SrcColorFactor' ,
474
- 'OneMinusSrcColorFactor' , 'SrcAlphaFactor' ,
475
- 'OneMinusSrcAlphaFactor' , 'DstAlphaFactor' ,
476
- 'OneMinusDstAlphaFactor' ], 'SrcAlphaFactor' ).tag (sync = True )
477
- blendDst = Enum (['DstColorFactor' , 'OneMinusDstColorFactor' ,
478
- 'SrcAlphaSaturateFactor' ], 'OneMinusDstColorFactor' ).tag (sync = True )
479
- blendEquation = Enum (['AddEquation' , 'SubtractEquation' ,
480
- 'ReverseSubtractEquation' ], 'AddEquation' ).tag (sync = True )
474
+ blending = Enum (BlendingMode , 'NormalBlending' ).tag (sync = True )
475
+ blendSrc = Enum (DestinationFactors , 'SrcAlphaFactor' ).tag (sync = True )
476
+ blendDst = Enum (SourceFactors , 'OneMinusDstColorFactor' ).tag (sync = True )
477
+ blendEquation = Enum (Equations , 'AddEquation' ).tag (sync = True )
481
478
depthTest = Bool (True ).tag (sync = True )
482
479
depthWrite = Bool (True ).tag (sync = True )
483
480
polygonOffset = Bool (True ).tag (sync = True )
@@ -498,8 +495,8 @@ class BasicMaterial(Material):
498
495
wireframeLinewidth = CFloat (1.0 ).tag (sync = True )
499
496
wireframeLinecap = Unicode ('round' ).tag (sync = True )
500
497
wireframeLinejoin = Unicode ('round' ).tag (sync = True )
501
- shading = Enum ([ 'SmoothShading' , 'FlatShading' , 'NoShading' ] , 'SmoothShading' ).tag (sync = True )
502
- vertexColors = Enum ([ 'NoColors' , 'FaceColors' , 'VertexColors' ] , 'NoColors' ).tag (sync = True )
498
+ shading = Enum (Shading , 'SmoothShading' ).tag (sync = True )
499
+ vertexColors = Enum (Colors , 'NoColors' ).tag (sync = True )
503
500
fog = Bool ().tag (sync = True )
504
501
map = Instance (Texture , allow_none = True ).tag (sync = True , ** widget_serialization )
505
502
lightMap = Instance (Texture , allow_none = True ).tag (sync = True , ** widget_serialization )
@@ -516,8 +513,7 @@ class LambertMaterial(BasicMaterial):
516
513
emissive = Color ('black' ).tag (sync = True )
517
514
reflectivity = CFloat (1.0 ).tag (sync = True )
518
515
refractionRatio = CFloat (0.98 ).tag (sync = True )
519
- combine = Enum (['MultiplyOperation' , 'MixOperation' , 'AddOperation' ],
520
- 'MultiplyOperation' ).tag (sync = True )
516
+ combine = Enum (Operations , 'MultiplyOperation' ).tag (sync = True )
521
517
522
518
523
519
class PhongMaterial (BasicMaterial ):
@@ -529,8 +525,7 @@ class PhongMaterial(BasicMaterial):
529
525
shininess = CFloat (30 ).tag (sync = True )
530
526
reflectivity = CFloat (1.0 ).tag (sync = True )
531
527
refractionRatio = CFloat (0.98 ).tag (sync = True )
532
- combine = Enum (['MultiplyOperation' , 'MixOperation' , 'AddOperation' ],
533
- 'MultiplyOperation' ).tag (sync = True )
528
+ combine = Enum (Operations , 'MultiplyOperation' ).tag (sync = True )
534
529
535
530
536
531
class DepthMaterial (Material ):
@@ -555,7 +550,7 @@ class LineBasicMaterial(_LineMaterial):
555
550
linecap = Unicode ('round' ).tag (sync = True )
556
551
linejoin = Unicode ('round' ).tag (sync = True )
557
552
fog = Bool ().tag (sync = True )
558
- vertexColors = Enum ([ 'NoColors' , 'FaceColors' , 'VertexColors' ] , 'NoColors' ).tag (sync = True )
553
+ vertexColors = Enum (Colors , 'NoColors' ).tag (sync = True )
559
554
560
555
561
556
class LineDashedMaterial (_LineMaterial ):
@@ -567,7 +562,7 @@ class LineDashedMaterial(_LineMaterial):
567
562
scale = CFloat (1.0 ).tag (sync = True )
568
563
dashSize = CFloat (3.0 ).tag (sync = True )
569
564
gapSize = CFloat (1.0 ).tag (sync = True )
570
- vertexColors = Enum ([ 'NoColors' , 'FaceColors' , 'VertexColors' ] , 'NoColors' ).tag (sync = True )
565
+ vertexColors = Enum (Colors , 'NoColors' ).tag (sync = True )
571
566
fog = Bool ().tag (sync = True )
572
567
573
568
@@ -576,7 +571,7 @@ class NormalMaterial(Material):
576
571
_model_name = Unicode ('NormalMaterialModel' ).tag (sync = True )
577
572
578
573
morphTargets = Bool ().tag (sync = True )
579
- shading = Enum ([ 'SmoothShading' , 'FlatShading' , 'NoShading' ] , 'SmoothShading' ).tag (sync = True )
574
+ shading = Enum (Shading , 'SmoothShading' ).tag (sync = True )
580
575
wireframe = Bool ().tag (sync = True )
581
576
wireframeLinewidth = CFloat (1.0 ).tag (sync = True )
582
577
@@ -603,10 +598,10 @@ class ShaderMaterial(Material):
603
598
lights = Bool ().tag (sync = True )
604
599
morphNormals = Bool ().tag (sync = True )
605
600
wireframe = Bool ().tag (sync = True )
606
- vertexColors = Enum ([ 'NoColors' , 'FaceColors' , 'VertexColors' ] , 'NoColors' ).tag (sync = True )
601
+ vertexColors = Enum (Colors , 'NoColors' ).tag (sync = True )
607
602
skinning = Bool ().tag (sync = True )
608
603
fog = Bool ().tag (sync = True )
609
- shading = Enum ([ 'SmoothShading' , 'FlatShading' , 'NoShading' ] , 'SmoothShading' ).tag (sync = True )
604
+ shading = Enum (Shading , 'SmoothShading' ).tag (sync = True )
610
605
linewidth = CFloat (1.0 ).tag (sync = True )
611
606
wireframeLinewidth = CFloat (1.0 ).tag (sync = True )
612
607
@@ -646,7 +641,7 @@ class Line(Mesh):
646
641
_view_name = Unicode ('LineView' ).tag (sync = True )
647
642
_model_name = Unicode ('LineModel' ).tag (sync = True )
648
643
649
- type = Enum ([ 'LineStrip' , 'LinePieces' ] , 'LineStrip' ).tag (sync = True )
644
+ type = Enum (Lines , 'LineStrip' ).tag (sync = True )
650
645
material = Instance (_LineMaterial ).tag (sync = True , ** widget_serialization )
651
646
652
647
@@ -764,7 +759,7 @@ class Renderer(DOMWidget):
764
759
765
760
width = Unicode ('600' ).tag (sync = True ) # TODO: stop relying on deprecated DOMWidget attribute
766
761
height = Unicode ('400' ).tag (sync = True )
767
- renderer_type = Enum ([ 'webgl' , 'canvas' , 'auto' ] , 'auto' ).tag (sync = True )
762
+ renderer_type = Enum (Renderers , 'auto' ).tag (sync = True )
768
763
scene = Instance (Scene ).tag (sync = True , ** widget_serialization )
769
764
camera = Instance (Camera ).tag (sync = True , ** widget_serialization )
770
765
controls = List (Instance (Controls )).tag (sync = True , ** widget_serialization )
0 commit comments