11import  {  Quaternion  }  from  '../math/Quaternion.js' ; 
22
3- function  PropertyMixer (  binding ,  typeName ,  valueSize  )  { 
4- 
5- 	this . binding  =  binding ; 
6- 	this . valueSize  =  valueSize ; 
7- 
8- 	let  mixFunction , 
9- 		mixFunctionAdditive , 
10- 		setIdentity ; 
11- 
12- 	// buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ] 
13- 	// 
14- 	// interpolators can use .buffer as their .result 
15- 	// the data then goes to 'incoming' 
16- 	// 
17- 	// 'accu0' and 'accu1' are used frame-interleaved for 
18- 	// the cumulative result and are compared to detect 
19- 	// changes 
20- 	// 
21- 	// 'orig' stores the original state of the property 
22- 	// 
23- 	// 'add' is used for additive cumulative results 
24- 	// 
25- 	// 'work' is optional and is only present for quaternion types. It is used 
26- 	// to store intermediate quaternion multiplication results 
27- 
28- 	switch  (  typeName  )  { 
29- 
30- 		case  'quaternion' :
31- 			mixFunction  =  this . _slerp ; 
32- 			mixFunctionAdditive  =  this . _slerpAdditive ; 
33- 			setIdentity  =  this . _setAdditiveIdentityQuaternion ; 
34- 
35- 			this . buffer  =  new  Float64Array (  valueSize  *  6  ) ; 
36- 			this . _workIndex  =  5 ; 
37- 			break ; 
38- 
39- 		case  'string' :
40- 		case  'bool' :
41- 			mixFunction  =  this . _select ; 
42- 
43- 			// Use the regular mix function and for additive on these types, 
44- 			// additive is not relevant for non-numeric types 
45- 			mixFunctionAdditive  =  this . _select ; 
46- 
47- 			setIdentity  =  this . _setAdditiveIdentityOther ; 
48- 
49- 			this . buffer  =  new  Array (  valueSize  *  5  ) ; 
50- 			break ; 
51- 
52- 		default :
53- 			mixFunction  =  this . _lerp ; 
54- 			mixFunctionAdditive  =  this . _lerpAdditive ; 
55- 			setIdentity  =  this . _setAdditiveIdentityNumeric ; 
56- 
57- 			this . buffer  =  new  Float64Array (  valueSize  *  5  ) ; 
3+ class  PropertyMixer  { 
4+ 
5+ 	constructor (  binding ,  typeName ,  valueSize  )  { 
6+ 
7+ 		this . binding  =  binding ; 
8+ 		this . valueSize  =  valueSize ; 
9+ 
10+ 		let  mixFunction , 
11+ 			mixFunctionAdditive , 
12+ 			setIdentity ; 
13+ 
14+ 		// buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ] 
15+ 		// 
16+ 		// interpolators can use .buffer as their .result 
17+ 		// the data then goes to 'incoming' 
18+ 		// 
19+ 		// 'accu0' and 'accu1' are used frame-interleaved for 
20+ 		// the cumulative result and are compared to detect 
21+ 		// changes 
22+ 		// 
23+ 		// 'orig' stores the original state of the property 
24+ 		// 
25+ 		// 'add' is used for additive cumulative results 
26+ 		// 
27+ 		// 'work' is optional and is only present for quaternion types. It is used 
28+ 		// to store intermediate quaternion multiplication results 
29+ 
30+ 		switch  (  typeName  )  { 
31+ 
32+ 			case  'quaternion' :
33+ 				mixFunction  =  this . _slerp ; 
34+ 				mixFunctionAdditive  =  this . _slerpAdditive ; 
35+ 				setIdentity  =  this . _setAdditiveIdentityQuaternion ; 
36+ 
37+ 				this . buffer  =  new  Float64Array (  valueSize  *  6  ) ; 
38+ 				this . _workIndex  =  5 ; 
39+ 				break ; 
5840
59- 	} 
41+ 			case  'string' :
42+ 			case  'bool' :
43+ 				mixFunction  =  this . _select ; 
6044
61- 	this . _mixBufferRegion  =  mixFunction ; 
62- 	this . _mixBufferRegionAdditive  =  mixFunctionAdditive ; 
63- 	this . _setIdentity  =  setIdentity ; 
64- 	this . _origIndex  =  3 ; 
65- 	this . _addIndex  =  4 ; 
45+ 				// Use the regular mix function and for additive on these types, 
46+ 				// additive is not relevant for non-numeric types 
47+ 				mixFunctionAdditive  =  this . _select ; 
6648
67- 	this . cumulativeWeight  =  0 ; 
68- 	this . cumulativeWeightAdditive  =  0 ; 
49+ 				setIdentity  =  this . _setAdditiveIdentityOther ; 
6950
70- 	this . useCount  =  0 ; 
71- 	this . referenceCount   =   0 ; 
51+ 				 this . buffer  =  new   Array (   valueSize   *   5   ) ; 
52+ 				 break ; 
7253
73- } 
54+ 			default :
55+ 				mixFunction  =  this . _lerp ; 
56+ 				mixFunctionAdditive  =  this . _lerpAdditive ; 
57+ 				setIdentity  =  this . _setAdditiveIdentityNumeric ; 
58+ 
59+ 				this . buffer  =  new  Float64Array (  valueSize  *  5  ) ; 
60+ 
61+ 		} 
7462
75- Object . assign (  PropertyMixer . prototype ,  { 
63+ 		this . _mixBufferRegion  =  mixFunction ; 
64+ 		this . _mixBufferRegionAdditive  =  mixFunctionAdditive ; 
65+ 		this . _setIdentity  =  setIdentity ; 
66+ 		this . _origIndex  =  3 ; 
67+ 		this . _addIndex  =  4 ; 
68+ 
69+ 		this . cumulativeWeight  =  0 ; 
70+ 		this . cumulativeWeightAdditive  =  0 ; 
71+ 
72+ 		this . useCount  =  0 ; 
73+ 		this . referenceCount  =  0 ; 
74+ 
75+ 	} 
7676
7777	// accumulate data in the 'incoming' region into 'accu<i>' 
78- 	accumulate :  function   (  accuIndex ,  weight  )  { 
78+ 	accumulate (  accuIndex ,  weight  )  { 
7979
8080		// note: happily accumulating nothing when weight = 0, the caller knows 
8181		// the weight and shouldn't have made the call in the first place 
@@ -110,10 +110,10 @@ Object.assign( PropertyMixer.prototype, {
110110
111111		this . cumulativeWeight  =  currentWeight ; 
112112
113- 	} , 
113+ 	} 
114114
115115	// accumulate data in the 'incoming' region into 'add' 
116- 	accumulateAdditive :  function   (  weight  )  { 
116+ 	accumulateAdditive (  weight  )  { 
117117
118118		const  buffer  =  this . buffer , 
119119			stride  =  this . valueSize , 
@@ -132,10 +132,10 @@ Object.assign( PropertyMixer.prototype, {
132132		this . _mixBufferRegionAdditive (  buffer ,  offset ,  0 ,  weight ,  stride  ) ; 
133133		this . cumulativeWeightAdditive  +=  weight ; 
134134
135- 	} , 
135+ 	} 
136136
137137	// apply the state of 'accu<i>' to the binding when accus differ 
138- 	apply :  function   (  accuIndex  )  { 
138+ 	apply (  accuIndex  )  { 
139139
140140		const  stride  =  this . valueSize , 
141141			buffer  =  this . buffer , 
@@ -181,10 +181,10 @@ Object.assign( PropertyMixer.prototype, {
181181
182182		} 
183183
184- 	} , 
184+ 	} 
185185
186186	// remember the state of the bound property and copy it to both accus 
187- 	saveOriginalState :  function   ( )  { 
187+ 	saveOriginalState ( )  { 
188188
189189		const  binding  =  this . binding ; 
190190
@@ -208,17 +208,17 @@ Object.assign( PropertyMixer.prototype, {
208208		this . cumulativeWeight  =  0 ; 
209209		this . cumulativeWeightAdditive  =  0 ; 
210210
211- 	} , 
211+ 	} 
212212
213213	// apply the state previously taken via 'saveOriginalState' to the binding 
214- 	restoreOriginalState :  function   ( )  { 
214+ 	restoreOriginalState ( )  { 
215215
216216		const  originalValueOffset  =  this . valueSize  *  3 ; 
217217		this . binding . setValue (  this . buffer ,  originalValueOffset  ) ; 
218218
219- 	} , 
219+ 	} 
220220
221- 	_setAdditiveIdentityNumeric :  function   ( )  { 
221+ 	_setAdditiveIdentityNumeric ( )  { 
222222
223223		const  startIndex  =  this . _addIndex  *  this . valueSize ; 
224224		const  endIndex  =  startIndex  +  this . valueSize ; 
@@ -229,16 +229,16 @@ Object.assign( PropertyMixer.prototype, {
229229
230230		} 
231231
232- 	} , 
232+ 	} 
233233
234- 	_setAdditiveIdentityQuaternion :  function   ( )  { 
234+ 	_setAdditiveIdentityQuaternion ( )  { 
235235
236236		this . _setAdditiveIdentityNumeric ( ) ; 
237237		this . buffer [  this . _addIndex  *  this . valueSize  +  3  ]  =  1 ; 
238238
239- 	} , 
239+ 	} 
240240
241- 	_setAdditiveIdentityOther :  function   ( )  { 
241+ 	_setAdditiveIdentityOther ( )  { 
242242
243243		const  startIndex  =  this . _origIndex  *  this . valueSize ; 
244244		const  targetIndex  =  this . _addIndex  *  this . valueSize ; 
@@ -249,12 +249,12 @@ Object.assign( PropertyMixer.prototype, {
249249
250250		} 
251251
252- 	} , 
252+ 	} 
253253
254254
255255	// mix functions 
256256
257- 	_select :  function   (  buffer ,  dstOffset ,  srcOffset ,  t ,  stride  )  { 
257+ 	_select (  buffer ,  dstOffset ,  srcOffset ,  t ,  stride  )  { 
258258
259259		if  (  t  >=  0.5  )  { 
260260
@@ -266,15 +266,15 @@ Object.assign( PropertyMixer.prototype, {
266266
267267		} 
268268
269- 	} , 
269+ 	} 
270270
271- 	_slerp :  function   (  buffer ,  dstOffset ,  srcOffset ,  t  )  { 
271+ 	_slerp (  buffer ,  dstOffset ,  srcOffset ,  t  )  { 
272272
273273		Quaternion . slerpFlat (  buffer ,  dstOffset ,  buffer ,  dstOffset ,  buffer ,  srcOffset ,  t  ) ; 
274274
275- 	} , 
275+ 	} 
276276
277- 	_slerpAdditive :  function   (  buffer ,  dstOffset ,  srcOffset ,  t ,  stride  )  { 
277+ 	_slerpAdditive (  buffer ,  dstOffset ,  srcOffset ,  t ,  stride  )  { 
278278
279279		const  workOffset  =  this . _workIndex  *  stride ; 
280280
@@ -284,9 +284,9 @@ Object.assign( PropertyMixer.prototype, {
284284		// Slerp to the intermediate result 
285285		Quaternion . slerpFlat (  buffer ,  dstOffset ,  buffer ,  dstOffset ,  buffer ,  workOffset ,  t  ) ; 
286286
287- 	} , 
287+ 	} 
288288
289- 	_lerp :  function   (  buffer ,  dstOffset ,  srcOffset ,  t ,  stride  )  { 
289+ 	_lerp (  buffer ,  dstOffset ,  srcOffset ,  t ,  stride  )  { 
290290
291291		const  s  =  1  -  t ; 
292292
@@ -298,9 +298,9 @@ Object.assign( PropertyMixer.prototype, {
298298
299299		} 
300300
301- 	} , 
301+ 	} 
302302
303- 	_lerpAdditive :  function   (  buffer ,  dstOffset ,  srcOffset ,  t ,  stride  )  { 
303+ 	_lerpAdditive (  buffer ,  dstOffset ,  srcOffset ,  t ,  stride  )  { 
304304
305305		for  (  let  i  =  0 ;  i  !==  stride ;  ++  i  )  { 
306306
@@ -312,7 +312,7 @@ Object.assign( PropertyMixer.prototype, {
312312
313313	} 
314314
315- }   ) ; 
315+ } 
316316
317317
318318export  {  PropertyMixer  } ; 
0 commit comments