提交 518d2463 编写于 作者: M Mugen87

Remove remaining IIFEs from core.

上级 a1936ac1
......@@ -594,17 +594,10 @@ Object.assign( Matrix4.prototype, {
},
getPosition: function () {
var v1;
console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
return new Vector3().setFromMatrixColumn( this, 3 );
return function getPosition() {
if ( v1 === undefined ) v1 = new Vector3();
console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
return v1.setFromMatrixColumn( this, 3 );
};
}(),
},
setRotationFromQuaternion: function ( q ) {
console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
......
......@@ -9,7 +9,10 @@
*/
// Characters [].:/ are reserved for track binding syntax.
var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
var _reservedRe;
var _trackRe, _supportedObjectNames;
function Composite( targetGroup, path, optionalParsedPath ) {
......@@ -109,101 +112,101 @@ Object.assign( PropertyBinding, {
* @param {string} name Node name to be sanitized.
* @return {string}
*/
sanitizeNodeName: ( function () {
sanitizeNodeName: function ( name ) {
var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
if ( _reservedRe === undefined ) {
return function sanitizeNodeName( name ) {
_reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
}
};
return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
}() ),
},
parseTrackName: function () {
parseTrackName: function ( trackName ) {
// 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( '\\.', '' ) + ']';
if ( _supportedObjectNames === undefined ) {
// 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 );
// 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( '\\.', '' ) + ']';
// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
// 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 );
// 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 );
// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
// Property and accessor. May not contain reserved characters. Accessor may
// contain any non-bracket characters.
var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
// 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 );
var trackRe = new RegExp( ''
+ '^'
+ directoryRe
+ nodeRe
+ objectRe
+ propertyRe
+ '$'
);
// Property and accessor. May not contain reserved characters. Accessor may
// contain any non-bracket characters.
var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
var supportedObjectNames = [ 'material', 'materials', 'bones' ];
_trackRe = new RegExp( ''
+ '^'
+ directoryRe
+ nodeRe
+ objectRe
+ propertyRe
+ '$'
);
return function parseTrackName( trackName ) {
_supportedObjectNames = [ 'material', 'materials', 'bones' ];
var matches = trackRe.exec( trackName );
}
if ( ! matches ) {
var matches = _trackRe.exec( trackName );
throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
if ( ! matches ) {
}
throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
var results = {
// directoryName: matches[ 1 ], // (tschw) currently unused
nodeName: matches[ 2 ],
objectName: matches[ 3 ],
objectIndex: matches[ 4 ],
propertyName: matches[ 5 ], // required
propertyIndex: matches[ 6 ]
};
}
var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
var results = {
// directoryName: matches[ 1 ], // (tschw) currently unused
nodeName: matches[ 2 ],
objectName: matches[ 3 ],
objectIndex: matches[ 4 ],
propertyName: matches[ 5 ], // required
propertyIndex: matches[ 6 ]
};
if ( lastDot !== undefined && lastDot !== - 1 ) {
var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
var objectName = results.nodeName.substring( lastDot + 1 );
if ( lastDot !== undefined && lastDot !== - 1 ) {
// Object names must be checked against a whitelist. Otherwise, there
// is no way to parse 'foo.bar.baz': 'baz' must be a property, but
// 'bar' could be the objectName, or part of a nodeName (which can
// include '.' characters).
if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
var objectName = results.nodeName.substring( lastDot + 1 );
results.nodeName = results.nodeName.substring( 0, lastDot );
results.objectName = objectName;
// Object names must be checked against a whitelist. Otherwise, there
// is no way to parse 'foo.bar.baz': 'baz' must be a property, but
// 'bar' could be the objectName, or part of a nodeName (which can
// include '.' characters).
if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
}
results.nodeName = results.nodeName.substring( 0, lastDot );
results.objectName = objectName;
}
if ( results.propertyName === null || results.propertyName.length === 0 ) {
}
throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
if ( results.propertyName === null || results.propertyName.length === 0 ) {
}
throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
return results;
}
};
return results;
}(),
},
findNode: function ( root, nodeName ) {
......
......@@ -15,11 +15,14 @@ import { arrayMax } from '../utils.js';
* @author mrdoob / http://mrdoob.com/
*/
var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
var _m1, _obj, _offset;
var _box, _boxMorphTargets;
var _vector;
function BufferGeometry() {
Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } );
this.uuid = _Math.generateUUID();
......@@ -182,129 +185,103 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
},
rotateX: function () {
rotateX: function ( angle ) {
// rotate geometry around world x-axis
var m1 = new Matrix4();
if ( _m1 === undefined ) _m1 = new Matrix4();
return function rotateX( angle ) {
_m1.makeRotationX( angle );
m1.makeRotationX( angle );
this.applyMatrix( _m1 );
this.applyMatrix( m1 );
return this;
};
return this;
}(),
},
rotateY: function () {
rotateY: function ( angle ) {
// rotate geometry around world y-axis
var m1 = new Matrix4();
return function rotateY( angle ) {
if ( _m1 === undefined ) _m1 = new Matrix4();
m1.makeRotationY( angle );
_m1.makeRotationY( angle );
this.applyMatrix( m1 );
this.applyMatrix( _m1 );
return this;
};
return this;
}(),
},
rotateZ: function () {
rotateZ: function ( angle ) {
// rotate geometry around world z-axis
var m1 = new Matrix4();
return function rotateZ( angle ) {
if ( _m1 === undefined ) _m1 = new Matrix4();
m1.makeRotationZ( angle );
_m1.makeRotationZ( angle );
this.applyMatrix( m1 );
return this;
this.applyMatrix( _m1 );
};
return this;
}(),
},
translate: function () {
translate: function ( x, y, z ) {
// translate geometry
var m1 = new Matrix4();
return function translate( x, y, z ) {
if ( _m1 === undefined ) _m1 = new Matrix4();
m1.makeTranslation( x, y, z );
_m1.makeTranslation( x, y, z );
this.applyMatrix( m1 );
this.applyMatrix( _m1 );
return this;
};
return this;
}(),
},
scale: function () {
scale: function ( x, y, z ) {
// scale geometry
var m1 = new Matrix4();
if ( _m1 === undefined ) _m1 = new Matrix4();
return function scale( x, y, z ) {
_m1.makeScale( x, y, z );
m1.makeScale( x, y, z );
this.applyMatrix( m1 );
return this;
};
this.applyMatrix( _m1 );
}(),
return this;
lookAt: function () {
},
var obj = new Object3D();
lookAt: function ( vector ) {
return function lookAt( vector ) {
if ( _obj === undefined ) _obj = new Object3D();
obj.lookAt( vector );
_obj.lookAt( vector );
obj.updateMatrix();
_obj.updateMatrix();
this.applyMatrix( obj.matrix );
this.applyMatrix( _obj.matrix );
};
return this;
}(),
},
center: function () {
var offset = new Vector3();
if ( _offset === undefined ) _offset = new Vector3();
return function center() {
this.computeBoundingBox();
this.computeBoundingBox();
this.boundingBox.getCenter( offset ).negate();
this.boundingBox.getCenter( _offset ).negate();
this.translate( offset.x, offset.y, offset.z );
return this;
this.translate( _offset.x, _offset.y, _offset.z );
};
return this;
}(),
},
setFromObject: function ( object ) {
......@@ -601,144 +578,144 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
computeBoundingBox: function () {
var box = new Box3();
if ( _box === undefined ) {
return function computeBoundingBox() {
_box = new Box3();
if ( this.boundingBox === null ) {
}
this.boundingBox = new Box3();
if ( this.boundingBox === null ) {
}
this.boundingBox = new Box3();
var position = this.attributes.position;
var morphAttributesPosition = this.morphAttributes.position;
}
if ( position !== undefined ) {
var position = this.attributes.position;
var morphAttributesPosition = this.morphAttributes.position;
this.boundingBox.setFromBufferAttribute( position );
if ( position !== undefined ) {
// process morph attributes if present
this.boundingBox.setFromBufferAttribute( position );
if ( morphAttributesPosition ) {
// process morph attributes if present
for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
if ( morphAttributesPosition ) {
var morphAttribute = morphAttributesPosition[ i ];
box.setFromBufferAttribute( morphAttribute );
for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
this.boundingBox.expandByPoint( box.min );
this.boundingBox.expandByPoint( box.max );
var morphAttribute = morphAttributesPosition[ i ];
_box.setFromBufferAttribute( morphAttribute );
}
this.boundingBox.expandByPoint( _box.min );
this.boundingBox.expandByPoint( _box.max );
}
} else {
}
this.boundingBox.makeEmpty();
} else {
}
this.boundingBox.makeEmpty();
if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
}
console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
}
console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
};
}
}(),
},
computeBoundingSphere: function () {
var box = new Box3();
var boxMorphTargets = new Box3();
var vector = new Vector3();
if ( _boxMorphTargets === undefined ) {
return function computeBoundingSphere() {
_box = new Box3();
_vector = new Vector3();
_boxMorphTargets = new Box3();
if ( this.boundingSphere === null ) {
}
this.boundingSphere = new Sphere();
if ( this.boundingSphere === null ) {
}
this.boundingSphere = new Sphere();
var position = this.attributes.position;
var morphAttributesPosition = this.morphAttributes.position;
}
if ( position ) {
var position = this.attributes.position;
var morphAttributesPosition = this.morphAttributes.position;
// first, find the center of the bounding sphere
if ( position ) {
var center = this.boundingSphere.center;
// first, find the center of the bounding sphere
box.setFromBufferAttribute( position );
var center = this.boundingSphere.center;
// process morph attributes if present
_box.setFromBufferAttribute( position );
if ( morphAttributesPosition ) {
// process morph attributes if present
for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
if ( morphAttributesPosition ) {
var morphAttribute = morphAttributesPosition[ i ];
boxMorphTargets.setFromBufferAttribute( morphAttribute );
for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
box.expandByPoint( boxMorphTargets.min );
box.expandByPoint( boxMorphTargets.max );
var morphAttribute = morphAttributesPosition[ i ];
_boxMorphTargets.setFromBufferAttribute( morphAttribute );
}
_box.expandByPoint( _boxMorphTargets.min );
_box.expandByPoint( _boxMorphTargets.max );
}
box.getCenter( center );
}
// second, try to find a boundingSphere with a radius smaller than the
// boundingSphere of the boundingBox: sqrt(3) smaller in the best case
_box.getCenter( center );
var maxRadiusSq = 0;
// second, try to find a boundingSphere with a radius smaller than the
// boundingSphere of the boundingBox: sqrt(3) smaller in the best case
for ( var i = 0, il = position.count; i < il; i ++ ) {
var maxRadiusSq = 0;
vector.fromBufferAttribute( position, i );
for ( var i = 0, il = position.count; i < il; i ++ ) {
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
_vector.fromBufferAttribute( position, i );
}
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
// process morph attributes if present
}
if ( morphAttributesPosition ) {
// process morph attributes if present
for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
if ( morphAttributesPosition ) {
var morphAttribute = morphAttributesPosition[ i ];
for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
var morphAttribute = morphAttributesPosition[ i ];
vector.fromBufferAttribute( morphAttribute, j );
for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
_vector.fromBufferAttribute( morphAttribute, j );
}
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
}
}
this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
}
if ( isNaN( this.boundingSphere.radius ) ) {
this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
if ( isNaN( this.boundingSphere.radius ) ) {
}
console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
}
};
}
}(),
},
computeFaceNormals: function () {
......@@ -900,27 +877,23 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
normalizeNormals: function () {
var vector = new Vector3();
if ( _vector === undefined ) _vector = new Vector3();
return function normalizeNormals() {
var normals = this.attributes.normal;
var normals = this.attributes.normal;
for ( var i = 0, il = normals.count; i < il; i ++ ) {
for ( var i = 0, il = normals.count; i < il; i ++ ) {
_vector.x = normals.getX( i );
_vector.y = normals.getY( i );
_vector.z = normals.getZ( i );
vector.x = normals.getX( i );
vector.y = normals.getY( i );
vector.z = normals.getZ( i );
_vector.normalize();
vector.normalize();
normals.setXYZ( i, _vector.x, _vector.y, _vector.z );
normals.setXYZ( i, vector.x, vector.y, vector.z );
}
};
}
}(),
},
toNonIndexed: function () {
......
......@@ -19,11 +19,12 @@ import { _Math } from '../math/Math.js';
* @author bhouston / http://clara.io
*/
var geometryId = 0; // Geometry uses even numbers as Id
var _geometryId = 0; // Geometry uses even numbers as Id
var _m1, _obj, _offset;
function Geometry() {
Object.defineProperty( this, 'id', { value: geometryId += 2 } );
Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
this.uuid = _Math.generateUUID();
......@@ -107,111 +108,89 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
},
rotateX: function () {
rotateX: function ( angle ) {
// rotate geometry around world x-axis
var m1 = new Matrix4();
if ( _m1 === undefined ) _m1 = new Matrix4();
return function rotateX( angle ) {
_m1.makeRotationX( angle );
m1.makeRotationX( angle );
this.applyMatrix( _m1 );
this.applyMatrix( m1 );
return this;
};
return this;
}(),
},
rotateY: function () {
rotateY: function ( angle ) {
// rotate geometry around world y-axis
var m1 = new Matrix4();
if ( _m1 === undefined ) _m1 = new Matrix4();
return function rotateY( angle ) {
_m1.makeRotationY( angle );
m1.makeRotationY( angle );
this.applyMatrix( _m1 );
this.applyMatrix( m1 );
return this;
};
return this;
}(),
},
rotateZ: function () {
rotateZ: function ( angle ) {
// rotate geometry around world z-axis
var m1 = new Matrix4();
return function rotateZ( angle ) {
m1.makeRotationZ( angle );
if ( _m1 === undefined ) _m1 = new Matrix4();
this.applyMatrix( m1 );
_m1.makeRotationZ( angle );
return this;
this.applyMatrix( _m1 );
};
return this;
}(),
},
translate: function () {
translate: function ( x, y, z ) {
// translate geometry
var m1 = new Matrix4();
return function translate( x, y, z ) {
if ( _m1 === undefined ) _m1 = new Matrix4();
m1.makeTranslation( x, y, z );
_m1.makeTranslation( x, y, z );
this.applyMatrix( m1 );
this.applyMatrix( _m1 );
return this;
};
return this;
}(),
},
scale: function () {
scale: function ( x, y, z ) {
// scale geometry
var m1 = new Matrix4();
return function scale( x, y, z ) {
if ( _m1 === undefined ) _m1 = new Matrix4();
m1.makeScale( x, y, z );
_m1.makeScale( x, y, z );
this.applyMatrix( m1 );
this.applyMatrix( _m1 );
return this;
};
}(),
return this;
lookAt: function () {
},
var obj = new Object3D();
lookAt: function ( vector ) {
return function lookAt( vector ) {
if ( _obj === undefined ) _obj = new Object3D();
obj.lookAt( vector );
_obj.lookAt( vector );
obj.updateMatrix();
_obj.updateMatrix();
this.applyMatrix( obj.matrix );
this.applyMatrix( _obj.matrix );
};
return this;
}(),
},
fromBufferGeometry: function ( geometry ) {
......@@ -348,21 +327,17 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
center: function () {
var offset = new Vector3();
return function center() {
this.computeBoundingBox();
if ( _offset === undefined ) _offset = new Vector3();
this.boundingBox.getCenter( offset ).negate();
this.computeBoundingBox();
this.translate( offset.x, offset.y, offset.z );
this.boundingBox.getCenter( _offset ).negate();
return this;
this.translate( _offset.x, _offset.y, _offset.z );
};
return this;
}(),
},
normalize: function () {
......
......@@ -16,11 +16,14 @@ import { TrianglesDrawMode } from '../constants.js';
* @author elephantatwork / www.elephantatwork.ch
*/
var object3DId = 0;
var _object3DId = 0;
var _m1, _q1, _v1;
var _xAxis, _yAxis, _zAxis;
var _target, _position, _scale, _quaternion;
function Object3D() {
Object.defineProperty( this, 'id', { value: object3DId ++ } );
Object.defineProperty( this, 'id', { value: _object3DId ++ } );
this.uuid = _Math.generateUUID();
......@@ -160,135 +163,99 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
},
rotateOnAxis: function () {
rotateOnAxis: function ( axis, angle ) {
// rotate object on axis in object space
// axis is assumed to be normalized
var q1 = new Quaternion();
if ( _q1 === undefined ) _q1 = new Quaternion();
return function rotateOnAxis( axis, angle ) {
_q1.setFromAxisAngle( axis, angle );
q1.setFromAxisAngle( axis, angle );
this.quaternion.multiply( _q1 );
this.quaternion.multiply( q1 );
return this;
};
return this;
}(),
},
rotateOnWorldAxis: function () {
rotateOnWorldAxis: function ( axis, angle ) {
// rotate object on axis in world space
// axis is assumed to be normalized
// method assumes no rotated parent
var q1 = new Quaternion();
return function rotateOnWorldAxis( axis, angle ) {
q1.setFromAxisAngle( axis, angle );
this.quaternion.premultiply( q1 );
return this;
};
}(),
rotateX: function () {
var v1 = new Vector3( 1, 0, 0 );
if ( _q1 === undefined ) _q1 = new Quaternion();
return function rotateX( angle ) {
_q1.setFromAxisAngle( axis, angle );
return this.rotateOnAxis( v1, angle );
this.quaternion.premultiply( _q1 );
};
return this;
}(),
},
rotateY: function () {
rotateX: function ( angle ) {
var v1 = new Vector3( 0, 1, 0 );
if ( _xAxis === undefined ) _xAxis = new Vector3( 1, 0, 0 );
return function rotateY( angle ) {
return this.rotateOnAxis( _xAxis, angle );
return this.rotateOnAxis( v1, angle );
},
};
rotateY: function ( angle ) {
}(),
if ( _yAxis === undefined ) _yAxis = new Vector3( 0, 1, 0 );
rotateZ: function () {
return this.rotateOnAxis( _yAxis, angle );
var v1 = new Vector3( 0, 0, 1 );
},
return function rotateZ( angle ) {
rotateZ: function ( angle ) {
return this.rotateOnAxis( v1, angle );
if ( _zAxis === undefined ) _zAxis = new Vector3( 0, 0, 1 );
};
return this.rotateOnAxis( _zAxis, angle );
}(),
},
translateOnAxis: function () {
translateOnAxis: function ( axis, distance ) {
// translate object by distance along axis in object space
// axis is assumed to be normalized
var v1 = new Vector3();
return function translateOnAxis( axis, distance ) {
v1.copy( axis ).applyQuaternion( this.quaternion );
this.position.add( v1.multiplyScalar( distance ) );
return this;
};
}(),
translateX: function () {
if ( _v1 === undefined ) _v1 = new Vector3();
var v1 = new Vector3( 1, 0, 0 );
_v1.copy( axis ).applyQuaternion( this.quaternion );
return function translateX( distance ) {
this.position.add( _v1.multiplyScalar( distance ) );
return this.translateOnAxis( v1, distance );
};
return this;
}(),
},
translateY: function () {
translateX: function ( distance ) {
var v1 = new Vector3( 0, 1, 0 );
if ( _xAxis === undefined ) _xAxis = new Vector3( 1, 0, 0 );
return function translateY( distance ) {
return this.translateOnAxis( _xAxis, distance );
return this.translateOnAxis( v1, distance );
},
};
translateY: function ( distance ) {
}(),
if ( _yAxis === undefined ) _yAxis = new Vector3( 0, 1, 0 );
translateZ: function () {
return this.translateOnAxis( _yAxis, distance );
var v1 = new Vector3( 0, 0, 1 );
},
return function translateZ( distance ) {
translateZ: function ( distance ) {
return this.translateOnAxis( v1, distance );
if ( _zAxis === undefined ) _zAxis = new Vector3( 0, 0, 1 );
};
return this.translateOnAxis( _zAxis, distance );
}(),
},
localToWorld: function ( vector ) {
......@@ -296,68 +263,64 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
},
worldToLocal: function () {
var m1 = new Matrix4();
return function worldToLocal( vector ) {
worldToLocal: function ( vector ) {
return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
if ( _m1 === undefined ) _m1 = new Matrix4();
};
return vector.applyMatrix4( _m1.getInverse( this.matrixWorld ) );
}(),
},
lookAt: function () {
lookAt: function ( x, y, z ) {
// This method does not support objects having non-uniformly-scaled parent(s)
var q1 = new Quaternion();
var m1 = new Matrix4();
var target = new Vector3();
var position = new Vector3();
if ( _position === undefined ) {
return function lookAt( x, y, z ) {
_q1 = new Quaternion();
_m1 = new Matrix4();
_target = new Vector3();
_position = new Vector3();
if ( x.isVector3 ) {
}
target.copy( x );
if ( x.isVector3 ) {
} else {
_target.copy( x );
target.set( x, y, z );
} else {
}
_target.set( x, y, z );
var parent = this.parent;
}
this.updateWorldMatrix( true, false );
var parent = this.parent;
position.setFromMatrixPosition( this.matrixWorld );
this.updateWorldMatrix( true, false );
if ( this.isCamera || this.isLight ) {
_position.setFromMatrixPosition( this.matrixWorld );
m1.lookAt( position, target, this.up );
if ( this.isCamera || this.isLight ) {
} else {
_m1.lookAt( _position, _target, this.up );
m1.lookAt( target, position, this.up );
} else {
}
_m1.lookAt( _target, _position, this.up );
this.quaternion.setFromRotationMatrix( m1 );
}
if ( parent ) {
this.quaternion.setFromRotationMatrix( _m1 );
m1.extractRotation( parent.matrixWorld );
q1.setFromRotationMatrix( m1 );
this.quaternion.premultiply( q1.inverse() );
if ( parent ) {
}
_m1.extractRotation( parent.matrixWorld );
_q1.setFromRotationMatrix( _m1 );
this.quaternion.premultiply( _q1.inverse() );
};
}
}(),
},
add: function ( object ) {
......@@ -432,37 +395,33 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
},
attach: function () {
attach: function ( object ) {
// adds object as a child of this, while maintaining the object's world transform
var m = new Matrix4();
if ( _m1 === undefined ) _m1 = new Matrix4();
return function attach( object ) {
this.updateWorldMatrix( true, false );
this.updateWorldMatrix( true, false );
_m1.getInverse( this.matrixWorld );
m.getInverse( this.matrixWorld );
if ( object.parent !== null ) {
if ( object.parent !== null ) {
object.parent.updateWorldMatrix( true, false );
object.parent.updateWorldMatrix( true, false );
m.multiply( object.parent.matrixWorld );
}
_m1.multiply( object.parent.matrixWorld );
object.applyMatrix( m );
}
object.updateWorldMatrix( false, false );
object.applyMatrix( _m1 );
this.add( object );
object.updateWorldMatrix( false, false );
return this;
this.add( object );
};
return this;
}(),
},
getObjectById: function ( id ) {
......@@ -512,53 +471,53 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
},
getWorldQuaternion: function () {
getWorldQuaternion: function ( target ) {
var position = new Vector3();
var scale = new Vector3();
if ( _scale === undefined ) {
return function getWorldQuaternion( target ) {
_position = new Vector3();
_scale = new Vector3();
if ( target === undefined ) {
}
console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
target = new Quaternion();
if ( target === undefined ) {
}
console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
target = new Quaternion();
this.updateMatrixWorld( true );
}
this.matrixWorld.decompose( position, target, scale );
this.updateMatrixWorld( true );
return target;
this.matrixWorld.decompose( _position, target, _scale );
};
return target;
}(),
},
getWorldScale: function () {
getWorldScale: function ( target ) {
var position = new Vector3();
var quaternion = new Quaternion();
if ( _quaternion === undefined ) {
return function getWorldScale( target ) {
_position = new Vector3();
_quaternion = new Quaternion();
if ( target === undefined ) {
}
console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
target = new Vector3();
if ( target === undefined ) {
}
console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
target = new Vector3();
this.updateMatrixWorld( true );
}
this.matrixWorld.decompose( position, quaternion, target );
this.updateMatrixWorld( true );
return target;
this.matrixWorld.decompose( _position, _quaternion, target );
};
return target;
}(),
},
getWorldDirection: function ( target ) {
......
......@@ -24,6 +24,8 @@ import { Color } from '../math/Color.js';
* @author alteredq / http://alteredqualia.com/
*/
var _BlendingMode, _color, _textureLoader, _materialLoader;
function Loader() {}
Loader.Handlers = {
......@@ -83,260 +85,260 @@ Object.assign( Loader.prototype, {
},
createMaterial: ( function () {
createMaterial: function ( m, texturePath, crossOrigin ) {
var BlendingMode = {
NoBlending: NoBlending,
NormalBlending: NormalBlending,
AdditiveBlending: AdditiveBlending,
SubtractiveBlending: SubtractiveBlending,
MultiplyBlending: MultiplyBlending,
CustomBlending: CustomBlending
};
if ( _materialLoader === undefined ) {
var color = new Color();
var textureLoader = new TextureLoader();
var materialLoader = new MaterialLoader();
_BlendingMode = {
NoBlending: NoBlending,
NormalBlending: NormalBlending,
AdditiveBlending: AdditiveBlending,
SubtractiveBlending: SubtractiveBlending,
MultiplyBlending: MultiplyBlending,
CustomBlending: CustomBlending
};
return function createMaterial( m, texturePath, crossOrigin ) {
_color = new Color();
_textureLoader = new TextureLoader();
_materialLoader = new MaterialLoader();
}
// convert from old material format
// convert from old material format
var textures = {};
var textures = {};
function loadTexture( path, repeat, offset, wrap, anisotropy ) {
//
var fullPath = texturePath + path;
var loader = Loader.Handlers.get( fullPath );
var json = {
uuid: _Math.generateUUID(),
type: 'MeshLambertMaterial'
};
var texture;
for ( var name in m ) {
var value = m[ name ];
switch ( name ) {
case 'DbgColor':
case 'DbgIndex':
case 'opticalDensity':
case 'illumination':
break;
case 'DbgName':
json.name = value;
break;
case 'blending':
json.blending = _BlendingMode[ value ];
break;
case 'colorAmbient':
case 'mapAmbient':
console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
break;
case 'colorDiffuse':
json.color = _color.fromArray( value ).getHex();
break;
case 'colorSpecular':
json.specular = _color.fromArray( value ).getHex();
break;
case 'colorEmissive':
json.emissive = _color.fromArray( value ).getHex();
break;
case 'specularCoef':
json.shininess = value;
break;
case 'shading':
if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
break;
case 'mapDiffuse':
json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapDiffuseRepeat':
case 'mapDiffuseOffset':
case 'mapDiffuseWrap':
case 'mapDiffuseAnisotropy':
break;
case 'mapEmissive':
json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapEmissiveRepeat':
case 'mapEmissiveOffset':
case 'mapEmissiveWrap':
case 'mapEmissiveAnisotropy':
break;
case 'mapLight':
json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapLightRepeat':
case 'mapLightOffset':
case 'mapLightWrap':
case 'mapLightAnisotropy':
break;
case 'mapAO':
json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapAORepeat':
case 'mapAOOffset':
case 'mapAOWrap':
case 'mapAOAnisotropy':
break;
case 'mapBump':
json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapBumpScale':
json.bumpScale = value;
break;
case 'mapBumpRepeat':
case 'mapBumpOffset':
case 'mapBumpWrap':
case 'mapBumpAnisotropy':
break;
case 'mapNormal':
json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapNormalFactor':
json.normalScale = value;
break;
case 'mapNormalRepeat':
case 'mapNormalOffset':
case 'mapNormalWrap':
case 'mapNormalAnisotropy':
break;
case 'mapSpecular':
json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapSpecularRepeat':
case 'mapSpecularOffset':
case 'mapSpecularWrap':
case 'mapSpecularAnisotropy':
break;
case 'mapMetalness':
json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapMetalnessRepeat':
case 'mapMetalnessOffset':
case 'mapMetalnessWrap':
case 'mapMetalnessAnisotropy':
break;
case 'mapRoughness':
json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapRoughnessRepeat':
case 'mapRoughnessOffset':
case 'mapRoughnessWrap':
case 'mapRoughnessAnisotropy':
break;
case 'mapAlpha':
json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy, textures, texturePath, crossOrigin );
break;
case 'mapAlphaRepeat':
case 'mapAlphaOffset':
case 'mapAlphaWrap':
case 'mapAlphaAnisotropy':
break;
case 'flipSided':
json.side = BackSide;
break;
case 'doubleSided':
json.side = DoubleSide;
break;
case 'transparency':
console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
json.opacity = value;
break;
case 'depthTest':
case 'depthWrite':
case 'colorWrite':
case 'opacity':
case 'reflectivity':
case 'transparent':
case 'visible':
case 'wireframe':
json[ name ] = value;
break;
case 'vertexColors':
if ( value === true ) json.vertexColors = VertexColors;
if ( value === 'face' ) json.vertexColors = FaceColors;
break;
default:
console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
break;
if ( loader !== null ) {
}
texture = loader.load( fullPath );
}
} else {
if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
textureLoader.setCrossOrigin( crossOrigin );
texture = textureLoader.load( fullPath );
if ( json.opacity < 1 ) json.transparent = true;
}
_materialLoader.setTextures( textures );
if ( repeat !== undefined ) {
return _materialLoader.parse( json );
texture.repeat.fromArray( repeat );
}
if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
} );
}
function loadTexture( path, repeat, offset, wrap, anisotropy, textures, texturePath, crossOrigin ) {
if ( offset !== undefined ) {
var fullPath = texturePath + path;
var loader = Loader.Handlers.get( fullPath );
texture.offset.fromArray( offset );
var texture;
}
if ( loader !== null ) {
if ( wrap !== undefined ) {
texture = loader.load( fullPath );
if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
} else {
if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
_textureLoader.setCrossOrigin( crossOrigin );
texture = _textureLoader.load( fullPath );
}
}
if ( anisotropy !== undefined ) {
if ( repeat !== undefined ) {
texture.anisotropy = anisotropy;
texture.repeat.fromArray( repeat );
}
if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
var uuid = _Math.generateUUID();
}
textures[ uuid ] = texture;
if ( offset !== undefined ) {
return uuid;
texture.offset.fromArray( offset );
}
}
//
if ( wrap !== undefined ) {
var json = {
uuid: _Math.generateUUID(),
type: 'MeshLambertMaterial'
};
if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
for ( var name in m ) {
var value = m[ name ];
switch ( name ) {
case 'DbgColor':
case 'DbgIndex':
case 'opticalDensity':
case 'illumination':
break;
case 'DbgName':
json.name = value;
break;
case 'blending':
json.blending = BlendingMode[ value ];
break;
case 'colorAmbient':
case 'mapAmbient':
console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
break;
case 'colorDiffuse':
json.color = color.fromArray( value ).getHex();
break;
case 'colorSpecular':
json.specular = color.fromArray( value ).getHex();
break;
case 'colorEmissive':
json.emissive = color.fromArray( value ).getHex();
break;
case 'specularCoef':
json.shininess = value;
break;
case 'shading':
if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
break;
case 'mapDiffuse':
json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
break;
case 'mapDiffuseRepeat':
case 'mapDiffuseOffset':
case 'mapDiffuseWrap':
case 'mapDiffuseAnisotropy':
break;
case 'mapEmissive':
json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
break;
case 'mapEmissiveRepeat':
case 'mapEmissiveOffset':
case 'mapEmissiveWrap':
case 'mapEmissiveAnisotropy':
break;
case 'mapLight':
json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
break;
case 'mapLightRepeat':
case 'mapLightOffset':
case 'mapLightWrap':
case 'mapLightAnisotropy':
break;
case 'mapAO':
json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
break;
case 'mapAORepeat':
case 'mapAOOffset':
case 'mapAOWrap':
case 'mapAOAnisotropy':
break;
case 'mapBump':
json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
break;
case 'mapBumpScale':
json.bumpScale = value;
break;
case 'mapBumpRepeat':
case 'mapBumpOffset':
case 'mapBumpWrap':
case 'mapBumpAnisotropy':
break;
case 'mapNormal':
json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
break;
case 'mapNormalFactor':
json.normalScale = value;
break;
case 'mapNormalRepeat':
case 'mapNormalOffset':
case 'mapNormalWrap':
case 'mapNormalAnisotropy':
break;
case 'mapSpecular':
json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
break;
case 'mapSpecularRepeat':
case 'mapSpecularOffset':
case 'mapSpecularWrap':
case 'mapSpecularAnisotropy':
break;
case 'mapMetalness':
json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
break;
case 'mapMetalnessRepeat':
case 'mapMetalnessOffset':
case 'mapMetalnessWrap':
case 'mapMetalnessAnisotropy':
break;
case 'mapRoughness':
json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
break;
case 'mapRoughnessRepeat':
case 'mapRoughnessOffset':
case 'mapRoughnessWrap':
case 'mapRoughnessAnisotropy':
break;
case 'mapAlpha':
json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
break;
case 'mapAlphaRepeat':
case 'mapAlphaOffset':
case 'mapAlphaWrap':
case 'mapAlphaAnisotropy':
break;
case 'flipSided':
json.side = BackSide;
break;
case 'doubleSided':
json.side = DoubleSide;
break;
case 'transparency':
console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
json.opacity = value;
break;
case 'depthTest':
case 'depthWrite':
case 'colorWrite':
case 'opacity':
case 'reflectivity':
case 'transparent':
case 'visible':
case 'wireframe':
json[ name ] = value;
break;
case 'vertexColors':
if ( value === true ) json.vertexColors = VertexColors;
if ( value === 'face' ) json.vertexColors = FaceColors;
break;
default:
console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
break;
}
if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
}
}
if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
if ( anisotropy !== undefined ) {
if ( json.opacity < 1 ) json.transparent = true;
texture.anisotropy = anisotropy;
materialLoader.setTextures( textures );
}
return materialLoader.parse( json );
var uuid = _Math.generateUUID();
};
textures[ uuid ] = texture;
} )()
return uuid;
} );
}
export { Loader };
......@@ -55,33 +55,29 @@ if ( Object.assign === undefined ) {
// Missing in IE
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
( function () {
Object.assign = function ( target ) {
Object.assign = function ( target ) {
'use strict';
'use strict';
if ( target === undefined || target === null ) {
if ( target === undefined || target === null ) {
throw new TypeError( 'Cannot convert undefined or null to object' );
throw new TypeError( 'Cannot convert undefined or null to object' );
}
var output = Object( target );
}
for ( var index = 1; index < arguments.length; index ++ ) {
var output = Object( target );
var source = arguments[ index ];
for ( var index = 1; index < arguments.length; index ++ ) {
if ( source !== undefined && source !== null ) {
var source = arguments[ index ];
for ( var nextKey in source ) {
if ( source !== undefined && source !== null ) {
if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
for ( var nextKey in source ) {
output[ nextKey ] = source[ nextKey ];
if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
}
output[ nextKey ] = source[ nextKey ];
}
......@@ -89,10 +85,10 @@ if ( Object.assign === undefined ) {
}
return output;
}
};
return output;
} )();
};
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册