@@ -8,6 +8,9 @@ import { Clock } from '../core/Clock.js';
88import { Object3D } from '../core/Object3D.js' ;
99import { AudioContext } from './AudioContext.js' ;
1010
11+ var _position , _quaternion , _scale ;
12+ var _orientation ;
13+
1114function AudioListener ( ) {
1215
1316 Object3D . call ( this ) ;
@@ -23,6 +26,10 @@ function AudioListener() {
2326
2427 this . timeDelta = 0 ;
2528
29+ // private
30+
31+ this . _clock = new Clock ( ) ;
32+
2633}
2734
2835AudioListener . prototype = Object . assign ( Object . create ( Object3D . prototype ) , {
@@ -91,54 +98,52 @@ AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
9198
9299 } ,
93100
94- updateMatrixWorld : ( function ( ) {
95-
96- var position = new Vector3 ( ) ;
97- var quaternion = new Quaternion ( ) ;
98- var scale = new Vector3 ( ) ;
101+ updateMatrixWorld : function ( force ) {
99102
100- var orientation = new Vector3 ( ) ;
101- var clock = new Clock ( ) ;
103+ Object3D . prototype . updateMatrixWorld . call ( this , force ) ;
102104
103- return function updateMatrixWorld ( force ) {
105+ if ( _position === undefined ) {
104106
105- Object3D . prototype . updateMatrixWorld . call ( this , force ) ;
107+ _position = new Vector3 ( ) ;
108+ _quaternion = new Quaternion ( ) ;
109+ _scale = new Vector3 ( ) ;
110+ _orientation = new Vector3 ( ) ;
106111
107- var listener = this . context . listener ;
108- var up = this . up ;
112+ }
109113
110- this . timeDelta = clock . getDelta ( ) ;
114+ var listener = this . context . listener ;
115+ var up = this . up ;
111116
112- this . matrixWorld . decompose ( position , quaternion , scale ) ;
117+ this . timeDelta = this . _clock . getDelta ( ) ;
113118
114- orientation . set ( 0 , 0 , - 1 ) . applyQuaternion ( quaternion ) ;
119+ this . matrixWorld . decompose ( _position , _quaternion , _scale ) ;
115120
116- if ( listener . positionX ) {
121+ _orientation . set ( 0 , 0 , - 1 ) . applyQuaternion ( _quaternion ) ;
117122
118- // code path for Chrome (see #14393)
123+ if ( listener . positionX ) {
119124
120- var endTime = this . context . currentTime + this . timeDelta ;
125+ // code path for Chrome (see #14393)
121126
122- listener . positionX . linearRampToValueAtTime ( position . x , endTime ) ;
123- listener . positionY . linearRampToValueAtTime ( position . y , endTime ) ;
124- listener . positionZ . linearRampToValueAtTime ( position . z , endTime ) ;
125- listener . forwardX . linearRampToValueAtTime ( orientation . x , endTime ) ;
126- listener . forwardY . linearRampToValueAtTime ( orientation . y , endTime ) ;
127- listener . forwardZ . linearRampToValueAtTime ( orientation . z , endTime ) ;
128- listener . upX . linearRampToValueAtTime ( up . x , endTime ) ;
129- listener . upY . linearRampToValueAtTime ( up . y , endTime ) ;
130- listener . upZ . linearRampToValueAtTime ( up . z , endTime ) ;
127+ var endTime = this . context . currentTime + this . timeDelta ;
131128
132- } else {
129+ listener . positionX . linearRampToValueAtTime ( _position . x , endTime ) ;
130+ listener . positionY . linearRampToValueAtTime ( _position . y , endTime ) ;
131+ listener . positionZ . linearRampToValueAtTime ( _position . z , endTime ) ;
132+ listener . forwardX . linearRampToValueAtTime ( _orientation . x , endTime ) ;
133+ listener . forwardY . linearRampToValueAtTime ( _orientation . y , endTime ) ;
134+ listener . forwardZ . linearRampToValueAtTime ( _orientation . z , endTime ) ;
135+ listener . upX . linearRampToValueAtTime ( up . x , endTime ) ;
136+ listener . upY . linearRampToValueAtTime ( up . y , endTime ) ;
137+ listener . upZ . linearRampToValueAtTime ( up . z , endTime ) ;
133138
134- listener . setPosition ( position . x , position . y , position . z ) ;
135- listener . setOrientation ( orientation . x , orientation . y , orientation . z , up . x , up . y , up . z ) ;
139+ } else {
136140
137- }
141+ listener . setPosition ( _position . x , _position . y , _position . z ) ;
142+ listener . setOrientation ( _orientation . x , _orientation . y , _orientation . z , up . x , up . y , up . z ) ;
138143
139- } ;
144+ }
140145
141- } ) ( )
146+ }
142147
143148} ) ;
144149
0 commit comments