File tree 2 files changed +10
-5
lines changed
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export class Three extends Vue {
20
20
21
21
private _app ! : Application ;
22
22
private _animationFrame ?: number ;
23
+ private _lastUpdate ?: number ;
23
24
24
25
public app ( ) {
25
26
return this . _app ;
@@ -67,13 +68,17 @@ export class Three extends Vue {
67
68
public onActivate ( ) {
68
69
console . log ( "activate render loop" ) ;
69
70
if ( ! this . _animationFrame ) {
71
+ this . _lastUpdate = Date . now ( ) ;
70
72
this . onRender ( ) ;
71
73
}
72
74
}
73
75
74
76
public onRender ( ) {
77
+ const now = Date . now ( ) ;
78
+ const deltaTime = ( now - this . _lastUpdate ! ) * 0.001 ;
75
79
this . _animationFrame = requestAnimationFrame ( this . onRender ) ;
76
- this . _app . update ( 0 ) ;
80
+ this . _app . update ( deltaTime ) ;
81
+ this . _lastUpdate = now ;
77
82
}
78
83
79
84
private onResize ( ) {
Original file line number Diff line number Diff line change @@ -64,12 +64,12 @@ export class Application {
64
64
public update ( deltaTime : number ) {
65
65
const scene = this . sceneManager . active ;
66
66
const camera = this . cameraManager . main ;
67
- if ( this . renderer ) {
68
- this . renderer . clearColor ( ) ;
69
- this . inputs . update ( ) ;
70
67
71
- this . _hooks . emit ( "update" , deltaTime ) ;
68
+ this . inputs . update ( ) ;
69
+ this . _hooks . emit ( "update" , deltaTime ) ;
72
70
71
+ if ( this . renderer ) {
72
+ this . renderer . clearColor ( ) ;
73
73
if ( scene && camera ) {
74
74
this . renderer . render ( scene , camera ) ;
75
75
}
You can’t perform that action at this time.
0 commit comments