@@ -188,7 +188,8 @@ class baseObj(object):
188
188
updates = {'cmds' :[], 'methods' :[], 'attrs' :{}}
189
189
object_registry = {} ## idx -> instance
190
190
attach_arrows = []
191
- attach_trails = [] ## needed only for functions
191
+ attach_trails = [] # needed only for functions
192
+ follow_objects = [] # entries are [invisible object to follow, function to call for pos, prevous pos]
192
193
attrs = set () # each element is (idx, attr name)
193
194
194
195
@classmethod
@@ -232,6 +233,15 @@ def handle_attach(cls): # called when about to send data to the browser
232
233
continue
233
234
aa ._last_val = fval
234
235
236
+ ## update every scene.camera.follow(function)
237
+ for aa in cls .follow_objects :
238
+ obj = aa [0 ]
239
+ val = aa [1 ]()
240
+ lastpos = aa [2 ]
241
+ if val != lastpos :
242
+ aa [2 ] = val
243
+ obj .pos = val
244
+
235
245
def __init__ (self , ** kwargs ):
236
246
if not (baseObj ._view_constructed or
237
247
baseObj ._canvas_constructing ):
@@ -1338,7 +1348,7 @@ def round(self):
1338
1348
return self ._round
1339
1349
@round .setter
1340
1350
def round (self ,value ):
1341
- raise AttributeError ('Cannot change the "round" attribute of an attach_arrow .' )
1351
+ raise AttributeError ('Cannot change the "round" attribute of an arrow .' )
1342
1352
1343
1353
@property
1344
1354
def scale (self ):
@@ -2770,7 +2780,6 @@ def project(self, **args):
2770
2780
class Camera (object ):
2771
2781
def __init__ (self , canvas ):
2772
2782
self ._canvas = canvas
2773
- self ._followthis = None
2774
2783
self ._pos = None
2775
2784
2776
2785
@property
@@ -2933,9 +2942,13 @@ def __init__(self, **args):
2933
2942
distant_light (direction = vector (- 0.88 , - 0.22 , - 0.44 ), color = color .gray (0.3 ))
2934
2943
baseObj ._canvas_constructing = False
2935
2944
2936
- def follow (self , obj ): ## should allow a function also
2945
+ def follow (self , obj ):
2937
2946
if obj is None :
2938
2947
self .addmethod ('follow' , 'None' )
2948
+ elif callable (obj ):
2949
+ b = box (visible = False )
2950
+ baseObj .follow_objects .append ([b , obj , vector (1.2e15 ,3.4e14 ,- 5.6e13 )])
2951
+ self .addmethod ('follow' , b .idx )
2939
2952
else :
2940
2953
self .addmethod ('follow' , obj .idx )
2941
2954
0 commit comments