Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
76 changes: 32 additions & 44 deletions src/animation/PropertyBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,39 @@

// Characters [].:/ are reserved for track binding syntax.
var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
var _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );

var _reservedRe;
var _trackRe, _supportedObjectNames;
// Attempts to allow node names from any language. ES5's `\w` regexp matches
// only latin characters, and the unicode \p{L} is not yet supported. So
// instead, we exclude reserved characters and match everything else.
var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';

// Parent directories, delimited by '/' or ':'. Currently unused, but must
// be matched to parse the rest of the track name.
var _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );

// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
var _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );

// Object on target node, and accessor. May not contain reserved
// characters. Accessor may contain any character except closing bracket.
var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );

// Property and accessor. May not contain reserved characters. Accessor may
// contain any non-bracket characters.
var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );

var _trackRe = new RegExp( ''
+ '^'
+ _directoryRe
+ _nodeRe
+ _objectRe
+ _propertyRe
+ '$'
);

var _supportedObjectNames = [ 'material', 'materials', 'bones' ];

function Composite( targetGroup, path, optionalParsedPath ) {

Expand Down Expand Up @@ -114,54 +144,12 @@ Object.assign( PropertyBinding, {
*/
sanitizeNodeName: function ( name ) {

if ( _reservedRe === undefined ) {

_reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );

}

return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );

},

parseTrackName: function ( trackName ) {

if ( _supportedObjectNames === undefined ) {

// Attempts to allow node names from any language. ES5's `\w` regexp matches
// only latin characters, and the unicode \p{L} is not yet supported. So
// instead, we exclude reserved characters and match everything else.
var wordChar = '[^' + _RESERVED_CHARS_RE + ']';
var wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';

// Parent directories, delimited by '/' or ':'. Currently unused, but must
// be matched to parse the rest of the track name.
var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );

// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );

// Object on target node, and accessor. May not contain reserved
// characters. Accessor may contain any character except closing bracket.
var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );

// Property and accessor. May not contain reserved characters. Accessor may
// contain any non-bracket characters.
var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );

_trackRe = new RegExp( ''
+ '^'
+ directoryRe
+ nodeRe
+ objectRe
+ propertyRe
+ '$'
);

_supportedObjectNames = [ 'material', 'materials', 'bones' ];

}

var matches = _trackRe.exec( trackName );

if ( ! matches ) {
Expand Down
15 changes: 4 additions & 11 deletions src/audio/AudioListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { Clock } from '../core/Clock.js';
import { Object3D } from '../core/Object3D.js';
import { AudioContext } from './AudioContext.js';

var _position, _quaternion, _scale;
var _orientation;
var _position = new Vector3();
var _quaternion = new Quaternion();
var _scale = new Vector3();
var _orientation = new Vector3();

function AudioListener() {

Expand Down Expand Up @@ -102,15 +104,6 @@ AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {

Object3D.prototype.updateMatrixWorld.call( this, force );

if ( _position === undefined ) {

_position = new Vector3();
_quaternion = new Quaternion();
_scale = new Vector3();
_orientation = new Vector3();

}

var listener = this.context.listener;
var up = this.up;

Expand Down
15 changes: 4 additions & 11 deletions src/audio/PositionalAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { Quaternion } from '../math/Quaternion.js';
import { Audio } from './Audio.js';
import { Object3D } from '../core/Object3D.js';

var _position, _quaternion, _scale;
var _orientation;
var _position = new Vector3();
var _quaternion = new Quaternion();
var _scale = new Vector3();
var _orientation = new Vector3();

function PositionalAudio( listener ) {

Expand Down Expand Up @@ -100,15 +102,6 @@ PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {

Object3D.prototype.updateMatrixWorld.call( this, force );

if ( _position === undefined ) {

_position = new Vector3();
_quaternion = new Quaternion();
_scale = new Vector3();
_orientation = new Vector3();

}

if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;

this.matrixWorld.decompose( _position, _quaternion, _scale );
Expand Down
10 changes: 2 additions & 8 deletions src/cameras/StereoCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Matrix4 } from '../math/Matrix4.js';
import { _Math } from '../math/Math.js';
import { PerspectiveCamera } from './PerspectiveCamera.js';

var _eyeRight, _eyeLeft;
var _eyeRight = new Matrix4();
var _eyeLeft = new Matrix4();

/**
* @author mrdoob / http://mrdoob.com/
Expand Down Expand Up @@ -40,13 +41,6 @@ Object.assign( StereoCamera.prototype, {

update: function ( camera ) {

if ( _eyeRight === undefined ) {

_eyeRight = new Matrix4();
_eyeLeft = new Matrix4();

}

var cache = this._cache;

var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
Expand Down
40 changes: 7 additions & 33 deletions src/core/BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import { arrayMax } from '../utils.js';
*/

var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
var _m1, _obj, _offset;
var _box, _boxMorphTargets;
var _vector;

var _m1 = new Matrix4();
var _obj = new Object3D();
var _offset = new Vector3();
var _box = new Box3();
var _boxMorphTargets = new Box3();
var _vector = new Vector3();

function BufferGeometry() {

Expand Down Expand Up @@ -189,8 +193,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

// rotate geometry around world x-axis

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeRotationX( angle );

this.applyMatrix( _m1 );
Expand All @@ -203,8 +205,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

// rotate geometry around world y-axis

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeRotationY( angle );

this.applyMatrix( _m1 );
Expand All @@ -217,8 +217,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

// rotate geometry around world z-axis

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeRotationZ( angle );

this.applyMatrix( _m1 );
Expand All @@ -231,8 +229,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

// translate geometry

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeTranslation( x, y, z );

this.applyMatrix( _m1 );
Expand All @@ -245,8 +241,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

// scale geometry

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeScale( x, y, z );

this.applyMatrix( _m1 );
Expand All @@ -257,8 +251,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

lookAt: function ( vector ) {

if ( _obj === undefined ) _obj = new Object3D();

_obj.lookAt( vector );

_obj.updateMatrix();
Expand All @@ -271,8 +263,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

center: function () {

if ( _offset === undefined ) _offset = new Vector3();

this.computeBoundingBox();

this.boundingBox.getCenter( _offset ).negate();
Expand Down Expand Up @@ -578,12 +568,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

computeBoundingBox: function () {

if ( _box === undefined ) {

_box = new Box3();

}

if ( this.boundingBox === null ) {

this.boundingBox = new Box3();
Expand Down Expand Up @@ -629,14 +613,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

computeBoundingSphere: function () {

if ( _boxMorphTargets === undefined ) {

_box = new Box3();
_vector = new Vector3();
_boxMorphTargets = new Box3();

}

if ( this.boundingSphere === null ) {

this.boundingSphere = new Sphere();
Expand Down Expand Up @@ -877,8 +853,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy

normalizeNormals: function () {

if ( _vector === undefined ) _vector = new Vector3();

var normals = this.attributes.normal;

for ( var i = 0, il = normals.count; i < il; i ++ ) {
Expand Down
18 changes: 3 additions & 15 deletions src/core/Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { _Math } from '../math/Math.js';
*/

var _geometryId = 0; // Geometry uses even numbers as Id
var _m1, _obj, _offset;
var _m1 = new Matrix4();
var _obj = new Object3D();
var _offset = new Vector3();

function Geometry() {

Expand Down Expand Up @@ -112,8 +114,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

// rotate geometry around world x-axis

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeRotationX( angle );

this.applyMatrix( _m1 );
Expand All @@ -126,8 +126,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

// rotate geometry around world y-axis

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeRotationY( angle );

this.applyMatrix( _m1 );
Expand All @@ -140,8 +138,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

// rotate geometry around world z-axis

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeRotationZ( angle );

this.applyMatrix( _m1 );
Expand All @@ -154,8 +150,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

// translate geometry

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeTranslation( x, y, z );

this.applyMatrix( _m1 );
Expand All @@ -168,8 +162,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

// scale geometry

if ( _m1 === undefined ) _m1 = new Matrix4();

_m1.makeScale( x, y, z );

this.applyMatrix( _m1 );
Expand All @@ -180,8 +172,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

lookAt: function ( vector ) {

if ( _obj === undefined ) _obj = new Object3D();

_obj.lookAt( vector );

_obj.updateMatrix();
Expand Down Expand Up @@ -327,8 +317,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

center: function () {

if ( _offset === undefined ) _offset = new Vector3();

this.computeBoundingBox();

this.boundingBox.getCenter( _offset ).negate();
Expand Down
Loading