@@ -11,6 +11,7 @@ var FlyControlsModel = FlyControlsAutogen.FlyControlsModel.extend({
11
11
this . clock = new THREE . Clock ( ) ;
12
12
var controlling = this . get ( 'controlling' ) ;
13
13
this . renderer = null ;
14
+ this . syncAtWill = true ;
14
15
15
16
obj = new FlyControls ( controlling . obj ) ;
16
17
obj . dispose ( ) ; // Disconnect events, we need to (dis-)connect on freeze/thaw
@@ -21,7 +22,12 @@ var FlyControlsModel = FlyControlsAutogen.FlyControlsModel.extend({
21
22
FlyControlsAutogen . FlyControlsModel . prototype . setupListeners . call ( this ) ;
22
23
var that = this ;
23
24
this . obj . addEventListener ( 'change' , function ( ) {
24
- that . update_controlled ( ) ;
25
+ // Throttle syncs:
26
+ if ( that . syncAtWill ) {
27
+ that . syncAtWill = false ;
28
+ that . update_controlled ( ) ;
29
+ setTimeout ( that . allowSync . bind ( that ) , 1000 * that . get ( 'syncRate' ) ) ;
30
+ }
25
31
} ) ;
26
32
this . on ( 'enableControl' , this . onEnable , this ) ;
27
33
this . on ( 'disableControl' , this . onDisable , this ) ;
@@ -38,9 +44,13 @@ var FlyControlsModel = FlyControlsAutogen.FlyControlsModel.extend({
38
44
this . renderer = null ;
39
45
} ,
40
46
47
+ allowSync : function ( ) {
48
+ this . syncAtWill = true ;
49
+ } ,
50
+
41
51
_update : function ( ) {
42
- this . obj . update ( this . clock . getDelta ( ) ) ;
43
52
if ( this . renderer !== null ) {
53
+ this . obj . update ( this . clock . getDelta ( ) ) ;
44
54
requestAnimationFrame ( this . _update . bind ( this ) ) ;
45
55
}
46
56
} ,
0 commit comments