11
11
]
12
12
13
13
14
- from ... import config
15
14
import itertools as it
16
15
import sys
17
16
import colour
45
44
46
45
47
46
class VMobject (Mobject ):
48
- fill_dtype = [
49
- ("point" , np .float32 , (3 ,)),
50
- ("unit_normal" , np .float32 , (3 ,)),
51
- ("color" , np .float32 , (4 ,)),
52
- ("vert_index" , np .float32 , (1 ,)),
53
- ]
54
-
55
- stroke_dtype = [
56
- ("point" , np .float32 , (3 ,)),
57
- ("prev_point" , np .float32 , (3 ,)),
58
- ("next_point" , np .float32 , (3 ,)),
59
- ("unit_normal" , np .float32 , (3 ,)),
60
- ("stroke_width" , np .float32 , (1 ,)),
61
- ("color" , np .float32 , (4 ,)),
62
- ]
63
-
64
47
def __init__ (
65
48
self ,
66
49
fill_color = None ,
@@ -113,51 +96,8 @@ def __init__(
113
96
self .shade_in_3d = shade_in_3d
114
97
self .tolerance_for_point_equality = tolerance_for_point_equality
115
98
self .n_points_per_cubic_curve = n_points_per_cubic_curve
116
-
117
99
Mobject .__init__ (self , ** kwargs )
118
100
119
- def init_gl_data (self ):
120
- self .needs_new_triangulation = True
121
- self .joint_type = "auto"
122
- self .flat_stroke = True
123
- self .data ["points" ] = np .zeros (0 )
124
- self .data ["unit_normal" ] = np .array ([[0.0 , 0.0 , 1.0 ]])
125
- self .data ["stroke_width" ] = np .array ([[4 ]])
126
-
127
- def init_gl_points (self ):
128
- self .data ["points" ] = np .array (
129
- [
130
- [1.0 , 1.0 , 0.0 ],
131
- [0.5 , 1.0 , 0.0 ],
132
- [0.0 , 1.0 , 0.0 ],
133
- [0.0 , 1.0 , 0.0 ],
134
- [- 0.5 , 1.0 , 0.0 ],
135
- [- 1.0 , 1.0 , 0.0 ],
136
- [- 1.0 , 1.0 , 0.0 ],
137
- [- 1.0 , 0.5 , 0.0 ],
138
- [- 1.0 , 0.0 , 0.0 ],
139
- [- 1.0 , 0.0 , 0.0 ],
140
- [- 1.0 , - 0.5 , 0.0 ],
141
- [- 1.0 , - 1.0 , 0.0 ],
142
- [- 1.0 , - 1.0 , 0.0 ],
143
- [- 0.5 , - 1.0 , 0.0 ],
144
- [0.0 , - 1.0 , 0.0 ],
145
- [0.0 , - 1.0 , 0.0 ],
146
- [0.5 , - 1.0 , 0.0 ],
147
- [1.0 , - 1.0 , 0.0 ],
148
- [1.0 , - 1.0 , 0.0 ],
149
- [1.0 , - 0.5 , 0.0 ],
150
- [1.0 , 0.0 , 0.0 ],
151
- [1.0 , 0.0 , 0.0 ],
152
- [1.0 , 0.5 , 0.0 ],
153
- [1.0 , 1.0 , 0.0 ],
154
- ]
155
- )
156
-
157
- def init_gl_colors (self ):
158
- self .data ["stroke_rgba" ] = np .array ([[1.0 , 1.0 , 1.0 , 1.0 ]])
159
- self .data ["fill_rgba" ] = np .array ([[1.0 , 1.0 , 1.0 , 0.0 ]])
160
-
161
101
def get_group_class (self ):
162
102
return VGroup
163
103
@@ -513,18 +453,8 @@ def set_shade_in_3d(self, value=True, z_index_as_group=False):
513
453
514
454
# Points
515
455
def set_points (self , points ):
516
- if config ["use_opengl_renderer" ]:
517
- if len (points ) == len (self .data ["points" ]):
518
- self .data ["points" ][:] = points
519
- elif isinstance (points , np .ndarray ):
520
- self .data ["points" ] = points .copy ()
521
- else :
522
- self .data ["points" ] = np .array (points )
523
- self .refresh_bounding_box ()
524
- return self
525
- else :
526
- self .points = np .array (points )
527
- return self
456
+ self .points = np .array (points )
457
+ return self
528
458
529
459
def get_points (self ):
530
460
return np .array (self .points )
@@ -545,27 +475,15 @@ def set_anchors_and_handles(
545
475
VMobject
546
476
for chaining.
547
477
"""
548
- if config ["use_opengl_renderer" ]:
549
- handles = handles1
550
- anchors2 = handles2
551
- assert len (anchors1 ) == len (handles ) == len (anchors2 )
552
- nppc = 3
553
- new_points = np .zeros ((nppc * len (anchors1 ), self .dim ))
554
- arrays = [anchors1 , handles , anchors2 ]
555
- for index , array in enumerate (arrays ):
556
- new_points [index ::nppc ] = array
557
- self .set_points (new_points )
558
- return self
559
- else :
560
- assert len (anchors1 ) == len (handles1 ) == len (handles2 ) == len (anchors2 )
561
- nppcc = self .n_points_per_cubic_curve # 4
562
- total_len = nppcc * len (anchors1 )
563
- self .points = np .zeros ((total_len , self .dim ))
564
- # the following will, from the four sets, dispatch them in points such that self.points = [anchors1[0], handles1[0], handles2[0], anchors1[0], anchors1[1], handles1[1], ...]
565
- arrays = [anchors1 , handles1 , handles2 , anchors2 ]
566
- for index , array in enumerate (arrays ):
567
- self .points [index ::nppcc ] = array
568
- return self
478
+ assert len (anchors1 ) == len (handles1 ) == len (handles2 ) == len (anchors2 )
479
+ nppcc = self .n_points_per_cubic_curve # 4
480
+ total_len = nppcc * len (anchors1 )
481
+ self .points = np .zeros ((total_len , self .dim ))
482
+ # the following will, from the four sets, dispatch them in points such that self.points = [anchors1[0], handles1[0], handles2[0], anchors1[0], anchors1[1], handles1[1], ...]
483
+ arrays = [anchors1 , handles1 , handles2 , anchors2 ]
484
+ for index , array in enumerate (arrays ):
485
+ self .points [index ::nppcc ] = array
486
+ return self
569
487
570
488
def clear_points (self ):
571
489
self .points = np .zeros ((0 , self .dim ))
@@ -721,28 +639,17 @@ def set_points_as_corners(self, points: Iterable[float]) -> "VMobject":
721
639
VMobject
722
640
self. For chaining purposes.
723
641
"""
724
- if config ["use_opengl_renderer" ]:
725
- nppc = self .n_points_per_curve
726
- points = np .array (points )
727
- self .set_anchors_and_handles (
728
- * [
729
- interpolate (points [:- 1 ], points [1 :], a )
730
- for a in np .linspace (0 , 1 , nppc )
731
- ]
732
- )
733
- return self
734
- else :
735
- nppcc = self .n_points_per_cubic_curve
736
- points = np .array (points )
737
- # This will set the handles aligned with the anchors.
738
- # Id est, a bezier curve will be the segment from the two anchors such that the handles belongs to this segment.
739
- self .set_anchors_and_handles (
740
- * [
741
- interpolate (points [:- 1 ], points [1 :], a )
742
- for a in np .linspace (0 , 1 , nppcc )
743
- ]
744
- )
745
- return self
642
+ nppcc = self .n_points_per_cubic_curve
643
+ points = np .array (points )
644
+ # This will set the handles aligned with the anchors.
645
+ # Id est, a bezier curve will be the segment from the two anchors such that the handles belongs to this segment.
646
+ self .set_anchors_and_handles (
647
+ * [
648
+ interpolate (points [:- 1 ], points [1 :], a )
649
+ for a in np .linspace (0 , 1 , nppcc )
650
+ ]
651
+ )
652
+ return self
746
653
747
654
def set_points_smoothly (self , points ):
748
655
self .set_points_as_corners (points )
0 commit comments