Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Covert to es6 class. #20008

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 120 additions & 118 deletions src/core/BufferAttribute.js

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions src/core/EventDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
* https://github.com/mrdoob/eventdispatcher.js/
*/

function EventDispatcher() {}
class EventDispatcher {

Object.assign( EventDispatcher.prototype, {

addEventListener: function ( type, listener ) {
addEventListener( type, listener ) {

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

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

}

},
}

hasEventListener: function ( type, listener ) {
hasEventListener( type, listener ) {

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

const listeners = this._listeners;

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

},
}

removeEventListener: function ( type, listener ) {
removeEventListener( type, listener ) {

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

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

}

},
}

dispatchEvent: function ( event ) {
dispatchEvent( event ) {

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

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

}

} );

}

export { EventDispatcher };
34 changes: 15 additions & 19 deletions src/core/InstancedBufferAttribute.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import { BufferAttribute } from './BufferAttribute.js';

function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
class InstancedBufferAttribute extends BufferAttribute {

if ( typeof ( normalized ) === 'number' ) {
constructor( array, itemSize, normalized, meshPerAttribute ) {

meshPerAttribute = normalized;
super( array, itemSize, normalized );

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

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

}

BufferAttribute.call( this, array, itemSize, normalized );
meshPerAttribute = normalized;

this.meshPerAttribute = meshPerAttribute || 1;
normalized = false;

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

InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
}

constructor: InstancedBufferAttribute,
this.meshPerAttribute = meshPerAttribute || 1;
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved

isInstancedBufferAttribute: true,
}

copy: function ( source ) {
copy( source ) {

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

this.meshPerAttribute = source.meshPerAttribute;

return this;

},
}

toJSON: function () {
toJSON() {

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

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

}

} );


}

export { InstancedBufferAttribute };
28 changes: 13 additions & 15 deletions src/core/InstancedBufferGeometry.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import { BufferGeometry } from './BufferGeometry.js';

function InstancedBufferGeometry() {
class InstancedBufferGeometry extends BufferGeometry {

BufferGeometry.call( this );
constructor() {

this.type = 'InstancedBufferGeometry';
this.instanceCount = Infinity;
super();

}

InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
Object.defineProperty( this, 'isInstancedBufferGeometry', { value: true } );

constructor: InstancedBufferGeometry,
this.type = 'InstancedBufferGeometry';
this.instanceCount = Infinity;

isInstancedBufferGeometry: true,
}

copy: function ( source ) {
copy( source ) {

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

this.instanceCount = source.instanceCount;

return this;

},
}

clone: function () {
clone() {

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

},
}

toJSON: function () {
toJSON() {

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

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

}

} );
}

export { InstancedBufferGeometry };
26 changes: 12 additions & 14 deletions src/core/InstancedInterleavedBuffer.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import { InterleavedBuffer } from './InterleavedBuffer.js';

function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
class InstancedInterleavedBuffer extends InterleavedBuffer {

InterleavedBuffer.call( this, array, stride );
constructor( array, stride, meshPerAttribute ) {

this.meshPerAttribute = meshPerAttribute || 1;
super( array, stride );

}

InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
Object.defineProperty( this, 'isInstancedInterleavedBuffer', { value: true } );

constructor: InstancedInterleavedBuffer,
this.meshPerAttribute = meshPerAttribute || 1;
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved

isInstancedInterleavedBuffer: true,
}

copy: function ( source ) {
copy( source ) {

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

this.meshPerAttribute = source.meshPerAttribute;

return this;

},
}

clone: function ( data ) {
clone( data ) {

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

ib.meshPerAttribute = this.meshPerAttribute;

return ib;

},
}

toJSON: function ( data ) {
toJSON( data ) {

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

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

}

} );
}

export { InstancedInterleavedBuffer };
60 changes: 28 additions & 32 deletions src/core/InterleavedBuffer.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
import { MathUtils } from '../math/MathUtils.js';
import { StaticDrawUsage } from '../constants.js';

function InterleavedBuffer( array, stride ) {
class InterleavedBuffer {

this.array = array;
this.stride = stride;
this.count = array !== undefined ? array.length / stride : 0;
constructor( array, stride ) {

this.usage = StaticDrawUsage;
this.updateRange = { offset: 0, count: - 1 };
this.array = array;
this.stride = stride;
this.count = array !== undefined ? array.length / stride : 0;

this.version = 0;
this.isInterleavedBuffer = true;

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

}

Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
this.version = 0;

set: function ( value ) {

if ( value === true ) this.version ++;
this.uuid = MathUtils.generateUUID();

}

} );
set needsUpdate( value ) {

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

isInterleavedBuffer: true,
}

onUploadCallback: function () {},
onUploadCallback() {}

setUsage: function ( value ) {
setUsage( value ) {

this.usage = value;

return this;

},
}

copy: function ( source ) {
copy( source ) {

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

return this;

},
}

copyAt: function ( index1, attribute, index2 ) {
copyAt( index1, attribute, index2 ) {

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

return this;

},
}

set: function ( value, offset = 0 ) {
set( value, offset = 0 ) {

this.array.set( value, offset );

return this;

},
}

clone: function ( data ) {
clone( data ) {

if ( data.arrayBuffers === undefined ) {

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

return ib;

},
}

onUpload: function ( callback ) {
onUpload( callback ) {

this.onUploadCallback = callback;

return this;

},
}

toJSON: function ( data ) {
toJSON( data ) {

if ( data.arrayBuffers === undefined ) {

Expand Down Expand Up @@ -144,6 +140,6 @@ Object.assign( InterleavedBuffer.prototype, {

}

} );
}

export { InterleavedBuffer };
Loading