提交 14304544 编写于 作者: M Mr.doob

Refactored EventDispatcher usage.

上级 e55d50ab
...@@ -27,12 +27,14 @@ function AnimationMixer( root ) { ...@@ -27,12 +27,14 @@ function AnimationMixer( root ) {
} }
Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, { AnimationMixer.prototype = {
constructor: AnimationMixer,
// return an action for a clip optionally using a custom root target // return an action for a clip optionally using a custom root target
// object (this method allocates a lot of dynamic memory in case a // object (this method allocates a lot of dynamic memory in case a
// previously unknown clip/root combination is specified) // previously unknown clip/root combination is specified)
clipAction: function( clip, optionalRoot ) { clipAction: function ( clip, optionalRoot ) {
var root = optionalRoot || this._root, var root = optionalRoot || this._root,
rootUuid = root.uuid, rootUuid = root.uuid,
...@@ -273,13 +275,13 @@ Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, { ...@@ -273,13 +275,13 @@ Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, {
} }
} ); };
// Implementation details: // Implementation details:
Object.assign( AnimationMixer.prototype, { Object.assign( AnimationMixer.prototype, {
_bindAction: function( action, prototypeAction ) { _bindAction: function ( action, prototypeAction ) {
var root = action._localRoot || this._root, var root = action._localRoot || this._root,
tracks = action._clip.tracks, tracks = action._clip.tracks,
...@@ -346,7 +348,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -346,7 +348,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_activateAction: function( action ) { _activateAction: function ( action ) {
if ( ! this._isActiveAction( action ) ) { if ( ! this._isActiveAction( action ) ) {
...@@ -388,7 +390,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -388,7 +390,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_deactivateAction: function( action ) { _deactivateAction: function ( action ) {
if ( this._isActiveAction( action ) ) { if ( this._isActiveAction( action ) ) {
...@@ -416,7 +418,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -416,7 +418,7 @@ Object.assign( AnimationMixer.prototype, {
// Memory manager // Memory manager
_initMemoryManager: function() { _initMemoryManager: function () {
this._actions = []; // 'nActiveActions' followed by inactive ones this._actions = []; // 'nActiveActions' followed by inactive ones
this._nActiveActions = 0; this._nActiveActions = 0;
...@@ -461,14 +463,14 @@ Object.assign( AnimationMixer.prototype, { ...@@ -461,14 +463,14 @@ Object.assign( AnimationMixer.prototype, {
// Memory management for AnimationAction objects // Memory management for AnimationAction objects
_isActiveAction: function( action ) { _isActiveAction: function ( action ) {
var index = action._cacheIndex; var index = action._cacheIndex;
return index !== null && index < this._nActiveActions; return index !== null && index < this._nActiveActions;
}, },
_addInactiveAction: function( action, clipUuid, rootUuid ) { _addInactiveAction: function ( action, clipUuid, rootUuid ) {
var actions = this._actions, var actions = this._actions,
actionsByClip = this._actionsByClip, actionsByClip = this._actionsByClip,
...@@ -503,7 +505,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -503,7 +505,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_removeInactiveAction: function( action ) { _removeInactiveAction: function ( action ) {
var actions = this._actions, var actions = this._actions,
lastInactiveAction = actions[ actions.length - 1 ], lastInactiveAction = actions[ actions.length - 1 ],
...@@ -548,7 +550,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -548,7 +550,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_removeInactiveBindingsForAction: function( action ) { _removeInactiveBindingsForAction: function ( action ) {
var bindings = action._propertyBindings; var bindings = action._propertyBindings;
for ( var i = 0, n = bindings.length; i !== n; ++ i ) { for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
...@@ -565,7 +567,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -565,7 +567,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_lendAction: function( action ) { _lendAction: function ( action ) {
// [ active actions | inactive actions ] // [ active actions | inactive actions ]
// [ active actions >| inactive actions ] // [ active actions >| inactive actions ]
...@@ -588,7 +590,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -588,7 +590,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_takeBackAction: function( action ) { _takeBackAction: function ( action ) {
// [ active actions | inactive actions ] // [ active actions | inactive actions ]
// [ active actions |< inactive actions ] // [ active actions |< inactive actions ]
...@@ -613,7 +615,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -613,7 +615,7 @@ Object.assign( AnimationMixer.prototype, {
// Memory management for PropertyMixer objects // Memory management for PropertyMixer objects
_addInactiveBinding: function( binding, rootUuid, trackName ) { _addInactiveBinding: function ( binding, rootUuid, trackName ) {
var bindingsByRoot = this._bindingsByRootAndName, var bindingsByRoot = this._bindingsByRootAndName,
bindingByName = bindingsByRoot[ rootUuid ], bindingByName = bindingsByRoot[ rootUuid ],
...@@ -634,7 +636,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -634,7 +636,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_removeInactiveBinding: function( binding ) { _removeInactiveBinding: function ( binding ) {
var bindings = this._bindings, var bindings = this._bindings,
propBinding = binding.binding, propBinding = binding.binding,
...@@ -662,7 +664,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -662,7 +664,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_lendBinding: function( binding ) { _lendBinding: function ( binding ) {
var bindings = this._bindings, var bindings = this._bindings,
prevIndex = binding._cacheIndex, prevIndex = binding._cacheIndex,
...@@ -679,7 +681,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -679,7 +681,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_takeBackBinding: function( binding ) { _takeBackBinding: function ( binding ) {
var bindings = this._bindings, var bindings = this._bindings,
prevIndex = binding._cacheIndex, prevIndex = binding._cacheIndex,
...@@ -699,7 +701,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -699,7 +701,7 @@ Object.assign( AnimationMixer.prototype, {
// Memory management of Interpolants for weight and time scale // Memory management of Interpolants for weight and time scale
_lendControlInterpolant: function() { _lendControlInterpolant: function () {
var interpolants = this._controlInterpolants, var interpolants = this._controlInterpolants,
lastActiveIndex = this._nActiveControlInterpolants ++, lastActiveIndex = this._nActiveControlInterpolants ++,
...@@ -720,7 +722,7 @@ Object.assign( AnimationMixer.prototype, { ...@@ -720,7 +722,7 @@ Object.assign( AnimationMixer.prototype, {
}, },
_takeBackControlInterpolant: function( interpolant ) { _takeBackControlInterpolant: function ( interpolant ) {
var interpolants = this._controlInterpolants, var interpolants = this._controlInterpolants,
prevIndex = interpolant.__cacheIndex, prevIndex = interpolant.__cacheIndex,
...@@ -741,5 +743,6 @@ Object.assign( AnimationMixer.prototype, { ...@@ -741,5 +743,6 @@ Object.assign( AnimationMixer.prototype, {
} ); } );
Object.assign( AnimationMixer.prototype, EventDispatcher.prototype );
export { AnimationMixer }; export { AnimationMixer };
...@@ -38,7 +38,9 @@ function BufferGeometry() { ...@@ -38,7 +38,9 @@ function BufferGeometry() {
} }
Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, { BufferGeometry.prototype = {
constructor: BufferGeometry,
isBufferGeometry: true, isBufferGeometry: true,
...@@ -1033,9 +1035,10 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, { ...@@ -1033,9 +1035,10 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
} }
} ); };
BufferGeometry.MaxIndex = 65535; BufferGeometry.MaxIndex = 65535;
Object.assign( BufferGeometry.prototype, EventDispatcher.prototype );
export { BufferGeometry }; export { BufferGeometry };
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
function EventDispatcher() {} function EventDispatcher() {}
Object.assign( EventDispatcher.prototype, { EventDispatcher.prototype = {
addEventListener: function ( type, listener ) { addEventListener: function ( type, listener ) {
...@@ -87,7 +87,7 @@ Object.assign( EventDispatcher.prototype, { ...@@ -87,7 +87,7 @@ Object.assign( EventDispatcher.prototype, {
} }
} ); };
export { EventDispatcher }; export { EventDispatcher };
...@@ -19,6 +19,9 @@ import { _Math } from '../math/Math'; ...@@ -19,6 +19,9 @@ import { _Math } from '../math/Math';
* @author bhouston / http://clara.io * @author bhouston / http://clara.io
*/ */
var count = 0;
function GeometryIdCount() { return count++; };
function Geometry() { function Geometry() {
Object.defineProperty( this, 'id', { value: GeometryIdCount() } ); Object.defineProperty( this, 'id', { value: GeometryIdCount() } );
...@@ -31,7 +34,7 @@ function Geometry() { ...@@ -31,7 +34,7 @@ function Geometry() {
this.vertices = []; this.vertices = [];
this.colors = []; this.colors = [];
this.faces = []; this.faces = [];
this.faceVertexUvs = [ [] ]; this.faceVertexUvs = [[]];
this.morphTargets = []; this.morphTargets = [];
this.morphNormals = []; this.morphNormals = [];
...@@ -56,7 +59,9 @@ function Geometry() { ...@@ -56,7 +59,9 @@ function Geometry() {
} }
Object.assign( Geometry.prototype, EventDispatcher.prototype, { Geometry.prototype = {
constructor: Geometry,
isGeometry: true, isGeometry: true,
...@@ -308,7 +313,7 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, { ...@@ -308,7 +313,7 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, {
for ( var j = start, jl = start + count; j < jl; j += 3 ) { for ( var j = start, jl = start + count; j < jl; j += 3 ) {
addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex ); addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
} }
...@@ -701,7 +706,7 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, { ...@@ -701,7 +706,7 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, {
merge: function ( geometry, matrix, materialIndexOffset ) { merge: function ( geometry, matrix, materialIndexOffset ) {
if ( (geometry && geometry.isGeometry) === false ) { if ( ( geometry && geometry.isGeometry ) === false ) {
console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry ); console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
return; return;
...@@ -821,7 +826,7 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, { ...@@ -821,7 +826,7 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, {
mergeMesh: function ( mesh ) { mergeMesh: function ( mesh ) {
if ( (mesh && mesh.isMesh) === false ) { if ( ( mesh && mesh.isMesh ) === false ) {
console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh ); console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
return; return;
...@@ -886,15 +891,12 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, { ...@@ -886,15 +891,12 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, {
indices = [ face.a, face.b, face.c ]; indices = [ face.a, face.b, face.c ];
var dupIndex = - 1;
// if any duplicate vertices are found in a Face3 // if any duplicate vertices are found in a Face3
// we have to remove the face as nothing can be saved // we have to remove the face as nothing can be saved
for ( var n = 0; n < 3; n ++ ) { for ( var n = 0; n < 3; n ++ ) {
if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) { if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
dupIndex = n;
faceIndicesToRemove.push( i ); faceIndicesToRemove.push( i );
break; break;
...@@ -1265,10 +1267,8 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, { ...@@ -1265,10 +1267,8 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, {
} }
} ); };
var count = 0;
function GeometryIdCount() { return count++; };
Object.assign( Geometry.prototype, EventDispatcher.prototype );
export { GeometryIdCount, Geometry }; export { GeometryIdCount, Geometry };
...@@ -101,7 +101,9 @@ function Object3D() { ...@@ -101,7 +101,9 @@ function Object3D() {
Object3D.DefaultUp = new Vector3( 0, 1, 0 ); Object3D.DefaultUp = new Vector3( 0, 1, 0 );
Object3D.DefaultMatrixAutoUpdate = true; Object3D.DefaultMatrixAutoUpdate = true;
Object.assign( Object3D.prototype, EventDispatcher.prototype, { Object3D.prototype = {
constructor: Object3D,
isObject3D: true, isObject3D: true,
...@@ -728,6 +730,8 @@ Object.assign( Object3D.prototype, EventDispatcher.prototype, { ...@@ -728,6 +730,8 @@ Object.assign( Object3D.prototype, EventDispatcher.prototype, {
} }
} ); };
Object.assign( Object3D.prototype, EventDispatcher.prototype );
export { Object3D }; export { Object3D };
...@@ -110,7 +110,7 @@ Material.prototype = { ...@@ -110,7 +110,7 @@ Material.prototype = {
currentValue.set( newValue ); currentValue.set( newValue );
} else if ( (currentValue && currentValue.isVector3) && (newValue && newValue.isVector3) ) { } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
currentValue.copy( newValue ); currentValue.copy( newValue );
......
...@@ -39,7 +39,9 @@ function WebGLRenderTarget( width, height, options ) { ...@@ -39,7 +39,9 @@ function WebGLRenderTarget( width, height, options ) {
} }
Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, { WebGLRenderTarget.prototype = {
constructor: WebGLRenderTarget,
isWebGLRenderTarget: true, isWebGLRenderTarget: true,
...@@ -88,7 +90,8 @@ Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, { ...@@ -88,7 +90,8 @@ Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, {
} }
} ); };
Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype );
export { WebGLRenderTarget }; export { WebGLRenderTarget };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册