Skip to content

Commit d08729a

Browse files
committed
core: Covert to es6 class.
1 parent 8000053 commit d08729a

File tree

8 files changed

+286
-312
lines changed

8 files changed

+286
-312
lines changed

src/core/BufferAttribute.js

Lines changed: 120 additions & 118 deletions
Large diffs are not rendered by default.

src/core/EventDispatcher.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
* https://github.com/mrdoob/eventdispatcher.js/
33
*/
44

5-
function EventDispatcher() {}
5+
class EventDispatcher {
66

7-
Object.assign( EventDispatcher.prototype, {
8-
9-
addEventListener: function ( type, listener ) {
7+
addEventListener( type, listener ) {
108

119
if ( this._listeners === undefined ) this._listeners = {};
1210

@@ -24,19 +22,19 @@ Object.assign( EventDispatcher.prototype, {
2422

2523
}
2624

27-
},
25+
}
2826

29-
hasEventListener: function ( type, listener ) {
27+
hasEventListener( type, listener ) {
3028

3129
if ( this._listeners === undefined ) return false;
3230

3331
const listeners = this._listeners;
3432

3533
return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
3634

37-
},
35+
}
3836

39-
removeEventListener: function ( type, listener ) {
37+
removeEventListener( type, listener ) {
4038

4139
if ( this._listeners === undefined ) return;
4240

@@ -55,9 +53,9 @@ Object.assign( EventDispatcher.prototype, {
5553

5654
}
5755

58-
},
56+
}
5957

60-
dispatchEvent: function ( event ) {
58+
dispatchEvent( event ) {
6159

6260
if ( this._listeners === undefined ) return;
6361

@@ -81,7 +79,6 @@ Object.assign( EventDispatcher.prototype, {
8179

8280
}
8381

84-
} );
85-
82+
}
8683

8784
export { EventDispatcher };
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
import { BufferAttribute } from './BufferAttribute.js';
22

3-
function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
3+
class InstancedBufferAttribute extends BufferAttribute {
44

5-
if ( typeof ( normalized ) === 'number' ) {
5+
constructor( array, itemSize, normalized, meshPerAttribute ) {
66

7-
meshPerAttribute = normalized;
7+
super( array, itemSize, normalized );
88

9-
normalized = false;
9+
Object.defineProperty( this, 'isInstancedBufferAttribute', { value: true } );
1010

11-
console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
11+
if ( typeof ( normalized ) === 'number' ) {
1212

13-
}
14-
15-
BufferAttribute.call( this, array, itemSize, normalized );
13+
meshPerAttribute = normalized;
1614

17-
this.meshPerAttribute = meshPerAttribute || 1;
15+
normalized = false;
1816

19-
}
17+
console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
2018

21-
InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
19+
}
2220

23-
constructor: InstancedBufferAttribute,
21+
this.meshPerAttribute = meshPerAttribute || 1;
2422

25-
isInstancedBufferAttribute: true,
23+
}
2624

27-
copy: function ( source ) {
25+
copy( source ) {
2826

2927
BufferAttribute.prototype.copy.call( this, source );
3028

3129
this.meshPerAttribute = source.meshPerAttribute;
3230

3331
return this;
3432

35-
},
33+
}
3634

37-
toJSON: function () {
35+
toJSON() {
3836

3937
const data = BufferAttribute.prototype.toJSON.call( this );
4038

@@ -46,8 +44,6 @@ InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribu
4644

4745
}
4846

49-
} );
50-
51-
47+
}
5248

5349
export { InstancedBufferAttribute };
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
import { BufferGeometry } from './BufferGeometry.js';
22

3-
function InstancedBufferGeometry() {
3+
class InstancedBufferGeometry extends BufferGeometry {
44

5-
BufferGeometry.call( this );
5+
constructor() {
66

7-
this.type = 'InstancedBufferGeometry';
8-
this.instanceCount = Infinity;
7+
super();
98

10-
}
11-
12-
InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
9+
Object.defineProperty( this, 'isInstancedBufferGeometry', { value: true } );
1310

14-
constructor: InstancedBufferGeometry,
11+
this.type = 'InstancedBufferGeometry';
12+
this.instanceCount = Infinity;
1513

16-
isInstancedBufferGeometry: true,
14+
}
1715

18-
copy: function ( source ) {
16+
copy( source ) {
1917

2018
BufferGeometry.prototype.copy.call( this, source );
2119

2220
this.instanceCount = source.instanceCount;
2321

2422
return this;
2523

26-
},
24+
}
2725

28-
clone: function () {
26+
clone() {
2927

3028
return new this.constructor().copy( this );
3129

32-
},
30+
}
3331

34-
toJSON: function () {
32+
toJSON() {
3533

3634
const data = BufferGeometry.prototype.toJSON.call( this );
3735

@@ -43,6 +41,6 @@ InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry
4341

4442
}
4543

46-
} );
44+
}
4745

4846
export { InstancedBufferGeometry };
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
import { InterleavedBuffer } from './InterleavedBuffer.js';
22

3-
function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
3+
class InstancedInterleavedBuffer extends InterleavedBuffer {
44

5-
InterleavedBuffer.call( this, array, stride );
5+
constructor( array, stride, meshPerAttribute ) {
66

7-
this.meshPerAttribute = meshPerAttribute || 1;
7+
super( array, stride );
88

9-
}
10-
11-
InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
9+
Object.defineProperty( this, 'isInstancedInterleavedBuffer', { value: true } );
1210

13-
constructor: InstancedInterleavedBuffer,
11+
this.meshPerAttribute = meshPerAttribute || 1;
1412

15-
isInstancedInterleavedBuffer: true,
13+
}
1614

17-
copy: function ( source ) {
15+
copy( source ) {
1816

1917
InterleavedBuffer.prototype.copy.call( this, source );
2018

2119
this.meshPerAttribute = source.meshPerAttribute;
2220

2321
return this;
2422

25-
},
23+
}
2624

27-
clone: function ( data ) {
25+
clone( data ) {
2826

2927
const ib = InterleavedBuffer.prototype.clone.call( this, data );
3028

3129
ib.meshPerAttribute = this.meshPerAttribute;
3230

3331
return ib;
3432

35-
},
33+
}
3634

37-
toJSON: function ( data ) {
35+
toJSON( data ) {
3836

3937
const json = InterleavedBuffer.prototype.toJSON.call( this, data );
4038

@@ -45,6 +43,6 @@ InstancedInterleavedBuffer.prototype = Object.assign( Object.create( Interleaved
4543

4644
}
4745

48-
} );
46+
}
4947

5048
export { InstancedInterleavedBuffer };

src/core/InterleavedBuffer.js

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
11
import { MathUtils } from '../math/MathUtils.js';
22
import { StaticDrawUsage } from '../constants.js';
33

4-
function InterleavedBuffer( array, stride ) {
4+
class InterleavedBuffer {
55

6-
this.array = array;
7-
this.stride = stride;
8-
this.count = array !== undefined ? array.length / stride : 0;
6+
constructor( array, stride ) {
97

10-
this.usage = StaticDrawUsage;
11-
this.updateRange = { offset: 0, count: - 1 };
8+
this.array = array;
9+
this.stride = stride;
10+
this.count = array !== undefined ? array.length / stride : 0;
1211

13-
this.version = 0;
12+
this.isInterleavedBuffer = true;
1413

15-
this.uuid = MathUtils.generateUUID();
14+
this.usage = StaticDrawUsage;
15+
this.updateRange = { offset: 0, count: - 1 };
1616

17-
}
18-
19-
Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
17+
this.version = 0;
2018

21-
set: function ( value ) {
22-
23-
if ( value === true ) this.version ++;
19+
this.uuid = MathUtils.generateUUID();
2420

2521
}
2622

27-
} );
23+
set needsUpdate( value ) {
2824

29-
Object.assign( InterleavedBuffer.prototype, {
25+
if ( value === true ) this.version ++;
3026

31-
isInterleavedBuffer: true,
27+
}
3228

33-
onUploadCallback: function () {},
29+
onUploadCallback() {}
3430

35-
setUsage: function ( value ) {
31+
setUsage( value ) {
3632

3733
this.usage = value;
3834

3935
return this;
4036

41-
},
37+
}
4238

43-
copy: function ( source ) {
39+
copy( source ) {
4440

4541
this.array = new source.array.constructor( source.array );
4642
this.count = source.count;
@@ -49,9 +45,9 @@ Object.assign( InterleavedBuffer.prototype, {
4945

5046
return this;
5147

52-
},
48+
}
5349

54-
copyAt: function ( index1, attribute, index2 ) {
50+
copyAt( index1, attribute, index2 ) {
5551

5652
index1 *= this.stride;
5753
index2 *= attribute.stride;
@@ -64,17 +60,17 @@ Object.assign( InterleavedBuffer.prototype, {
6460

6561
return this;
6662

67-
},
63+
}
6864

69-
set: function ( value, offset = 0 ) {
65+
set( value, offset = 0 ) {
7066

7167
this.array.set( value, offset );
7268

7369
return this;
7470

75-
},
71+
}
7672

77-
clone: function ( data ) {
73+
clone( data ) {
7874

7975
if ( data.arrayBuffers === undefined ) {
8076

@@ -101,17 +97,17 @@ Object.assign( InterleavedBuffer.prototype, {
10197

10298
return ib;
10399

104-
},
100+
}
105101

106-
onUpload: function ( callback ) {
102+
onUpload( callback ) {
107103

108104
this.onUploadCallback = callback;
109105

110106
return this;
111107

112-
},
108+
}
113109

114-
toJSON: function ( data ) {
110+
toJSON( data ) {
115111

116112
if ( data.arrayBuffers === undefined ) {
117113

@@ -144,6 +140,6 @@ Object.assign( InterleavedBuffer.prototype, {
144140

145141
}
146142

147-
} );
143+
}
148144

149145
export { InterleavedBuffer };

0 commit comments

Comments
 (0)