Jelajahi Sumber

Objects: Convert to classes. (#21625)

* Objects: Convert to classes.

* Examples: Clean up.
Michael Herzog 4 tahun lalu
induk
melakukan
5aa098f0e1

+ 68 - 46
examples/js/controls/TransformControls.js

@@ -1301,39 +1301,52 @@
 		isTransformControlsGizmo: true
 	} );
 
-	var TransformControlsPlane = function () {
+	const _unitX = new THREE.Vector3( 1, 0, 0 );
 
-		'use strict';
+	const _unitY = new THREE.Vector3( 0, 1, 0 );
 
-		THREE.Mesh.call( this, new THREE.PlaneGeometry( 100000, 100000, 2, 2 ), new THREE.MeshBasicMaterial( {
-			visible: false,
-			wireframe: true,
-			side: THREE.DoubleSide,
-			transparent: true,
-			opacity: 0.1,
-			toneMapped: false
-		} ) );
-		this.type = 'TransformControlsPlane';
-		var unitX = new THREE.Vector3( 1, 0, 0 );
-		var unitY = new THREE.Vector3( 0, 1, 0 );
-		var unitZ = new THREE.Vector3( 0, 0, 1 );
-		var tempVector = new THREE.Vector3();
-		var dirVector = new THREE.Vector3();
-		var alignVector = new THREE.Vector3();
-		var tempMatrix = new THREE.Matrix4();
-		var identityQuaternion = new THREE.Quaternion();
+	const _unitZ = new THREE.Vector3( 0, 0, 1 );
 
-		this.updateMatrixWorld = function () {
+	const _tempVector = new THREE.Vector3();
+
+	const _dirVector = new THREE.Vector3();
+
+	const _alignVector = new THREE.Vector3();
+
+	const _tempMatrix = new THREE.Matrix4();
+
+	const _identityQuaternion = new THREE.Quaternion();
+
+	class TransformControlsPlane extends THREE.Mesh {
+
+		constructor() {
+
+			super( new THREE.PlaneGeometry( 100000, 100000, 2, 2 ), new THREE.MeshBasicMaterial( {
+				visible: false,
+				wireframe: true,
+				side: THREE.DoubleSide,
+				transparent: true,
+				opacity: 0.1,
+				toneMapped: false
+			} ) );
+			this.type = 'TransformControlsPlane';
+
+		}
+
+		updateMatrixWorld( force ) {
 
 			var space = this.space;
 			this.position.copy( this.worldPosition );
 			if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
 
-			unitX.set( 1, 0, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion );
-			unitY.set( 0, 1, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion );
-			unitZ.set( 0, 0, 1 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion ); // Align the plane for current transform mode, axis and space.
+			_unitX.set( 1, 0, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion );
+
+			_unitY.set( 0, 1, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion );
 
-			alignVector.copy( unitY );
+			_unitZ.set( 0, 0, 1 ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion ); // Align the plane for current transform mode, axis and space.
+
+
+			_alignVector.copy( _unitY );
 
 			switch ( this.mode ) {
 
@@ -1342,36 +1355,47 @@
 					switch ( this.axis ) {
 
 						case 'X':
-							alignVector.copy( this.eye ).cross( unitX );
-							dirVector.copy( unitX ).cross( alignVector );
+							_alignVector.copy( this.eye ).cross( _unitX );
+
+							_dirVector.copy( _unitX ).cross( _alignVector );
+
 							break;
 
 						case 'Y':
-							alignVector.copy( this.eye ).cross( unitY );
-							dirVector.copy( unitY ).cross( alignVector );
+							_alignVector.copy( this.eye ).cross( _unitY );
+
+							_dirVector.copy( _unitY ).cross( _alignVector );
+
 							break;
 
 						case 'Z':
-							alignVector.copy( this.eye ).cross( unitZ );
-							dirVector.copy( unitZ ).cross( alignVector );
+							_alignVector.copy( this.eye ).cross( _unitZ );
+
+							_dirVector.copy( _unitZ ).cross( _alignVector );
+
 							break;
 
 						case 'XY':
-							dirVector.copy( unitZ );
+							_dirVector.copy( _unitZ );
+
 							break;
 
 						case 'YZ':
-							dirVector.copy( unitX );
+							_dirVector.copy( _unitX );
+
 							break;
 
 						case 'XZ':
-							alignVector.copy( unitZ );
-							dirVector.copy( unitY );
+							_alignVector.copy( _unitZ );
+
+							_dirVector.copy( _unitY );
+
 							break;
 
 						case 'XYZ':
 						case 'E':
-							dirVector.set( 0, 0, 0 );
+							_dirVector.set( 0, 0, 0 );
+
 							break;
 
 					}
@@ -1381,32 +1405,30 @@
 				case 'rotate':
 				default:
 				// special case for rotate
-					dirVector.set( 0, 0, 0 );
+					_dirVector.set( 0, 0, 0 );
 
 			}
 
-			if ( dirVector.length() === 0 ) {
+			if ( _dirVector.length() === 0 ) {
 
 				// If in rotate mode, make the plane parallel to camera
 				this.quaternion.copy( this.cameraQuaternion );
 
 			} else {
 
-				tempMatrix.lookAt( tempVector.set( 0, 0, 0 ), dirVector, alignVector );
-				this.quaternion.setFromRotationMatrix( tempMatrix );
+				_tempMatrix.lookAt( _tempVector.set( 0, 0, 0 ), _dirVector, _alignVector );
+
+				this.quaternion.setFromRotationMatrix( _tempMatrix );
 
 			}
 
-			THREE.Object3D.prototype.updateMatrixWorld.call( this );
+			super.updateMatrixWorld( force );
 
-		};
+		}
 
-	};
+	}
 
-	TransformControlsPlane.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
-		constructor: TransformControlsPlane,
-		isTransformControlsPlane: true
-	} );
+	TransformControlsPlane.prototype.isTransformControlsPlane = true;
 
 	THREE.TransformControls = TransformControls;
 	THREE.TransformControlsGizmo = TransformControlsGizmo;

+ 107 - 106
examples/js/loaders/LDrawLoader.js

@@ -713,19 +713,19 @@
 		parseColourMetaDirective( lineParser ) {
 
 			// Parses a colour definition and returns a THREE.Material or null if error
-			var code = null; // Triangle and line colours
+			let code = null; // Triangle and line colours
 
-			var colour = 0xFF00FF;
-			var edgeColour = 0xFF00FF; // Transparency
+			let colour = 0xFF00FF;
+			let edgeColour = 0xFF00FF; // Transparency
 
-			var alpha = 1;
-			var isTransparent = false; // Self-illumination:
+			let alpha = 1;
+			let isTransparent = false; // Self-illumination:
 
-			var luminance = 0;
-			var finishType = FINISH_TYPE_DEFAULT;
-			var canHaveEnvMap = true;
-			var edgeMaterial = null;
-			var name = lineParser.getToken();
+			let luminance = 0;
+			let finishType = FINISH_TYPE_DEFAULT;
+			let canHaveEnvMap = true;
+			let edgeMaterial = null;
+			const name = lineParser.getToken();
 
 			if ( ! name ) {
 
@@ -734,7 +734,7 @@
 			} // Parse tag tokens and their parameters
 
 
-			var token = null;
+			let token = null;
 
 			while ( true ) {
 
@@ -856,7 +856,7 @@
 
 			}
 
-			var material = null;
+			let material = null;
 
 			switch ( finishType ) {
 
@@ -871,8 +871,8 @@
 
 				case FINISH_TYPE_PEARLESCENT:
 				// Try to imitate pearlescency by setting the specular to the complementary of the color, and low shininess
-					var specular = new THREE.Color( colour );
-					var hsl = specular.getHSL( {
+					const specular = new THREE.Color( colour );
+					const hsl = specular.getHSL( {
 						h: 0,
 						s: 0,
 						l: 0
@@ -988,18 +988,18 @@
 		objectParse( text ) {
 
 			// Retrieve data from the parent parse scope
-			var parentParseScope = this.getParentParseScope(); // Main colour codes passed to this subobject (or default codes 16 and 24 if it is the root object)
+			const parentParseScope = this.getParentParseScope(); // Main colour codes passed to this subobject (or default codes 16 and 24 if it is the root object)
 
-			var mainColourCode = parentParseScope.mainColourCode;
-			var mainEdgeColourCode = parentParseScope.mainEdgeColourCode;
-			var currentParseScope = this.getCurrentParseScope(); // Parse result variables
+			const mainColourCode = parentParseScope.mainColourCode;
+			const mainEdgeColourCode = parentParseScope.mainEdgeColourCode;
+			const currentParseScope = this.getCurrentParseScope(); // Parse result variables
 
-			var triangles;
-			var lineSegments;
-			var conditionalSegments;
-			var subobjects = [];
-			var category = null;
-			var keywords = null;
+			let triangles;
+			let lineSegments;
+			let conditionalSegments;
+			const subobjects = [];
+			let category = null;
+			let keywords = null;
 
 			if ( text.indexOf( '\r\n' ) !== - 1 ) {
 
@@ -1008,24 +1008,23 @@
 
 			}
 
-			var lines = text.split( '\n' );
-			var numLines = lines.length;
-			var lineIndex = 0;
-			var parsingEmbeddedFiles = false;
-			var currentEmbeddedFileName = null;
-			var currentEmbeddedText = null;
-			var bfcCertified = false;
-			var bfcCCW = true;
-			var bfcInverted = false;
-			var bfcCull = true;
-			var type = '';
-			var startingConstructionStep = false;
-			var scope = this;
+			const lines = text.split( '\n' );
+			const numLines = lines.length;
+			let parsingEmbeddedFiles = false;
+			let currentEmbeddedFileName = null;
+			let currentEmbeddedText = null;
+			let bfcCertified = false;
+			let bfcCCW = true;
+			let bfcInverted = false;
+			let bfcCull = true;
+			let type = '';
+			let startingConstructionStep = false;
+			const scope = this;
 
 			function parseColourCode( lineParser, forEdge ) {
 
 				// Parses next colour code and returns a THREE.Material
-				var colourCode = lineParser.getToken();
+				let colourCode = lineParser.getToken();
 
 				if ( ! forEdge && colourCode === '16' ) {
 
@@ -1039,7 +1038,7 @@
 
 				}
 
-				var material = scope.getMaterial( colourCode );
+				const material = scope.getMaterial( colourCode );
 
 				if ( ! material ) {
 
@@ -1053,7 +1052,7 @@
 
 			function parseVector( lp ) {
 
-				var v = new THREE.Vector3( parseFloat( lp.getToken() ), parseFloat( lp.getToken() ), parseFloat( lp.getToken() ) );
+				const v = new THREE.Vector3( parseFloat( lp.getToken() ), parseFloat( lp.getToken() ), parseFloat( lp.getToken() ) );
 
 				if ( ! scope.separateObjects ) {
 
@@ -1066,9 +1065,9 @@
 			} // Parse all line commands
 
 
-			for ( lineIndex = 0; lineIndex < numLines; lineIndex ++ ) {
+			for ( let lineIndex = 0; lineIndex < numLines; lineIndex ++ ) {
 
-				var line = lines[ lineIndex ];
+				const line = lines[ lineIndex ];
 				if ( line.length === 0 ) continue;
 
 				if ( parsingEmbeddedFiles ) {
@@ -1091,7 +1090,7 @@
 
 				}
 
-				var lp = new LineParser( line, lineIndex + 1 );
+				const lp = new LineParser( line, lineIndex + 1 );
 				lp.seekNonSpace();
 
 				if ( lp.isAtTheEnd() ) {
@@ -1102,14 +1101,20 @@
 				} // Parse the line type
 
 
-				var lineType = lp.getToken();
+				const lineType = lp.getToken();
+				let material;
+				let segment;
+				let inverted;
+				let ccw;
+				let doubleSided;
+				let v0, v1, v2, v3, faceNormal;
 
 				switch ( lineType ) {
 
 					// Line type 0: Comment or META
 					case '0':
 					// Parse meta directive
-						var meta = lp.getToken();
+						const meta = lp.getToken();
 
 						if ( meta ) {
 
@@ -1121,7 +1126,7 @@
 									currentParseScope.lineSegments = [];
 									currentParseScope.conditionalSegments = [];
 									currentParseScope.type = type;
-									var isRoot = ! parentParseScope.isFromParse;
+									const isRoot = ! parentParseScope.isFromParse;
 
 									if ( isRoot || scope.separateObjects && ! isPrimitiveType( type ) ) {
 
@@ -1132,9 +1137,7 @@
 									// needs to be flipped.
 
 
-									var matrix = currentParseScope.matrix;
-
-									if ( matrix.determinant() < 0 && ( scope.separateObjects && isPrimitiveType( type ) || ! scope.separateObjects ) ) {
+									if ( currentParseScope.matrix.determinant() < 0 && ( scope.separateObjects && isPrimitiveType( type ) || ! scope.separateObjects ) ) {
 
 										currentParseScope.inverted = ! currentParseScope.inverted;
 
@@ -1146,7 +1149,7 @@
 									break;
 
 								case '!COLOUR':
-									var material = this.parseColourMetaDirective( lp );
+									material = this.parseColourMetaDirective( lp );
 
 									if ( material ) {
 
@@ -1165,7 +1168,7 @@
 									break;
 
 								case '!KEYWORDS':
-									var newKeywords = lp.getRemainingString().split( ',' );
+									const newKeywords = lp.getRemainingString().split( ',' );
 
 									if ( newKeywords.length > 0 ) {
 
@@ -1203,7 +1206,7 @@
 								// Changes to the backface culling state
 									while ( ! lp.isAtTheEnd() ) {
 
-										var token = lp.getToken();
+										const token = lp.getToken();
 
 										switch ( token ) {
 
@@ -1253,21 +1256,21 @@
 						// Line type 1: Sub-object file
 
 					case '1':
-						var material = parseColourCode( lp );
-						var posX = parseFloat( lp.getToken() );
-						var posY = parseFloat( lp.getToken() );
-						var posZ = parseFloat( lp.getToken() );
-						var m0 = parseFloat( lp.getToken() );
-						var m1 = parseFloat( lp.getToken() );
-						var m2 = parseFloat( lp.getToken() );
-						var m3 = parseFloat( lp.getToken() );
-						var m4 = parseFloat( lp.getToken() );
-						var m5 = parseFloat( lp.getToken() );
-						var m6 = parseFloat( lp.getToken() );
-						var m7 = parseFloat( lp.getToken() );
-						var m8 = parseFloat( lp.getToken() );
-						var matrix = new THREE.Matrix4().set( m0, m1, m2, posX, m3, m4, m5, posY, m6, m7, m8, posZ, 0, 0, 0, 1 );
-						var fileName = lp.getRemainingString().trim().replace( /\\/g, '/' );
+						material = parseColourCode( lp );
+						const posX = parseFloat( lp.getToken() );
+						const posY = parseFloat( lp.getToken() );
+						const posZ = parseFloat( lp.getToken() );
+						const m0 = parseFloat( lp.getToken() );
+						const m1 = parseFloat( lp.getToken() );
+						const m2 = parseFloat( lp.getToken() );
+						const m3 = parseFloat( lp.getToken() );
+						const m4 = parseFloat( lp.getToken() );
+						const m5 = parseFloat( lp.getToken() );
+						const m6 = parseFloat( lp.getToken() );
+						const m7 = parseFloat( lp.getToken() );
+						const m8 = parseFloat( lp.getToken() );
+						const matrix = new THREE.Matrix4().set( m0, m1, m2, posX, m3, m4, m5, posY, m6, m7, m8, posZ, 0, 0, 0, 1 );
+						const fileName = lp.getRemainingString().trim().replace( /\\/g, '/' );
 
 						if ( scope.fileMap[ fileName ] ) {
 
@@ -1305,8 +1308,8 @@
 						// Line type 2: Line segment
 
 					case '2':
-						var material = parseColourCode( lp, true );
-						var segment = {
+						material = parseColourCode( lp, true );
+						segment = {
 							material: material.userData.edgeMaterial,
 							colourCode: material.userData.code,
 							v0: parseVector( lp ),
@@ -1317,8 +1320,8 @@
 						// Line type 5: Conditional Line segment
 
 					case '5':
-						var material = parseColourCode( lp, true );
-						var segment = {
+						material = parseColourCode( lp, true );
+						segment = {
 							material: material.userData.edgeMaterial.userData.conditionalEdgeMaterial,
 							colourCode: material.userData.code,
 							v0: parseVector( lp ),
@@ -1331,11 +1334,10 @@
 						// Line type 3: Triangle
 
 					case '3':
-						var material = parseColourCode( lp );
-						var inverted = currentParseScope.inverted;
-						var ccw = bfcCCW !== inverted;
-						var doubleSided = ! bfcCertified || ! bfcCull;
-						var v0, v1, v2, faceNormal;
+						material = parseColourCode( lp );
+						inverted = currentParseScope.inverted;
+						ccw = bfcCCW !== inverted;
+						doubleSided = ! bfcCertified || ! bfcCull;
 
 						if ( ccw === true ) {
 
@@ -1388,11 +1390,10 @@
 						// Line type 4: Quadrilateral
 
 					case '4':
-						var material = parseColourCode( lp );
-						var inverted = currentParseScope.inverted;
-						var ccw = bfcCCW !== inverted;
-						var doubleSided = ! bfcCertified || ! bfcCull;
-						var v0, v1, v2, v3, faceNormal;
+						material = parseColourCode( lp );
+						inverted = currentParseScope.inverted;
+						ccw = bfcCCW !== inverted;
+						doubleSided = ! bfcCertified || ! bfcCull;
 
 						if ( ccw === true ) {
 
@@ -1492,7 +1493,7 @@
 		computeConstructionSteps( model ) {
 
 			// Sets userdata.constructionStep number in THREE.Group objects and userData.numConstructionSteps number in the root THREE.Group object.
-			var stepNumber = 0;
+			let stepNumber = 0;
 			model.traverse( c => {
 
 				if ( c.isGroup ) {
@@ -1514,10 +1515,10 @@
 
 		processObject( text, onProcessed, subobject, url ) {
 
-			var scope = this;
-			var parseScope = scope.newParseScopeLevel();
+			const scope = this;
+			const parseScope = scope.newParseScopeLevel();
 			parseScope.url = url;
-			var parentParseScope = scope.getParentParseScope(); // Set current matrix
+			const parentParseScope = scope.getParentParseScope(); // Set current matrix
 
 			if ( subobject ) {
 
@@ -1529,7 +1530,7 @@
 			} // Add to cache
 
 
-			var currentFileName = parentParseScope.currentFileName;
+			let currentFileName = parentParseScope.currentFileName;
 
 			if ( currentFileName !== null ) {
 
@@ -1545,7 +1546,7 @@
 
 
 			scope.objectParse( text );
-			var finishedCount = 0;
+			let finishedCount = 0;
 			onSubobjectFinish();
 
 			function onSubobjectFinish() {
@@ -1564,7 +1565,7 @@
 					// Promise.resolve is used as an approach to asynchronously schedule a task _before_ this frame ends to
 					// avoid stack overflow exceptions when loading many subobjects from the cache. RequestAnimationFrame
 					// will work but causes the load to happen after the next frame which causes the load to take significantly longer.
-					var subobject = parseScope.subobjects[ parseScope.subobjectIndex ];
+					const subobject = parseScope.subobjects[ parseScope.subobjectIndex ];
 					Promise.resolve().then( function () {
 
 						loadSubobject( subobject );
@@ -1584,7 +1585,7 @@
 
 				}
 
-				var isRoot = ! parentParseScope.isFromParse;
+				const isRoot = ! parentParseScope.isFromParse;
 
 				if ( scope.separateObjects && ! isPrimitiveType( parseScope.type ) || isRoot ) {
 
@@ -1620,17 +1621,17 @@
 
 				} else {
 
-					var separateObjects = scope.separateObjects;
-					var parentLineSegments = parentParseScope.lineSegments;
-					var parentConditionalSegments = parentParseScope.conditionalSegments;
-					var parentTriangles = parentParseScope.triangles;
-					var lineSegments = parseScope.lineSegments;
-					var conditionalSegments = parseScope.conditionalSegments;
-					var triangles = parseScope.triangles;
+					const separateObjects = scope.separateObjects;
+					const parentLineSegments = parentParseScope.lineSegments;
+					const parentConditionalSegments = parentParseScope.conditionalSegments;
+					const parentTriangles = parentParseScope.triangles;
+					const lineSegments = parseScope.lineSegments;
+					const conditionalSegments = parseScope.conditionalSegments;
+					const triangles = parseScope.triangles;
 
-					for ( var i = 0, l = lineSegments.length; i < l; i ++ ) {
+					for ( let i = 0, l = lineSegments.length; i < l; i ++ ) {
 
-						var ls = lineSegments[ i ];
+						const ls = lineSegments[ i ];
 
 						if ( separateObjects ) {
 
@@ -1643,9 +1644,9 @@
 
 					}
 
-					for ( var i = 0, l = conditionalSegments.length; i < l; i ++ ) {
+					for ( let i = 0, l = conditionalSegments.length; i < l; i ++ ) {
 
-						var os = conditionalSegments[ i ];
+						const os = conditionalSegments[ i ];
 
 						if ( separateObjects ) {
 
@@ -1660,9 +1661,9 @@
 
 					}
 
-					for ( var i = 0, l = triangles.length; i < l; i ++ ) {
+					for ( let i = 0, l = triangles.length; i < l; i ++ ) {
 
-						var tri = triangles[ i ];
+						const tri = triangles[ i ];
 
 						if ( separateObjects ) {
 
@@ -1706,7 +1707,7 @@
 				parseScope.mainEdgeColourCode = subobject.material.userData.edgeMaterial.userData.code;
 				parseScope.currentFileName = subobject.originalFileName; // If subobject was cached previously, use the cached one
 
-				var cached = scope.subobjectCache[ subobject.originalFileName.toLowerCase() ];
+				const cached = scope.subobjectCache[ subobject.originalFileName.toLowerCase() ];
 
 				if ( cached ) {
 
@@ -1722,8 +1723,8 @@
 				// Update also subobject.locationState for the next try if this load fails.
 
 
-				var subobjectURL = subobject.fileName;
-				var newLocationState = FILE_LOCATION_NOT_FOUND;
+				let subobjectURL = subobject.fileName;
+				let newLocationState = FILE_LOCATION_NOT_FOUND;
 
 				switch ( subobject.locationState ) {
 
@@ -1781,7 +1782,7 @@
 				// Use another file loader here so we can keep track of the subobject information
 				// and use it when processing the next model.
 
-				var fileLoader = new THREE.FileLoader( scope.manager );
+				const fileLoader = new THREE.FileLoader( scope.manager );
 				fileLoader.setPath( scope.path );
 				fileLoader.setRequestHeader( scope.requestHeader );
 				fileLoader.setWithCredentials( scope.withCredentials );

+ 40 - 45
examples/jsm/controls/TransformControls.js

@@ -1577,29 +1577,30 @@ TransformControlsGizmo.prototype = Object.assign( Object.create( Object3D.protot
 
 } );
 
+const _unitX = new Vector3( 1, 0, 0 );
+const _unitY = new Vector3( 0, 1, 0 );
+const _unitZ = new Vector3( 0, 0, 1 );
 
-var TransformControlsPlane = function () {
+const _tempVector = new Vector3();
+const _dirVector = new Vector3();
+const _alignVector = new Vector3();
+const _tempMatrix = new Matrix4();
+const _identityQuaternion = new Quaternion();
 
-	'use strict';
+class TransformControlsPlane extends Mesh {
 
-	Mesh.call( this,
-		new PlaneGeometry( 100000, 100000, 2, 2 ),
-		new MeshBasicMaterial( { visible: false, wireframe: true, side: DoubleSide, transparent: true, opacity: 0.1, toneMapped: false } )
-	);
+	constructor() {
 
-	this.type = 'TransformControlsPlane';
+		super(
+			new PlaneGeometry( 100000, 100000, 2, 2 ),
+			new MeshBasicMaterial( { visible: false, wireframe: true, side: DoubleSide, transparent: true, opacity: 0.1, toneMapped: false } )
+		);
 
-	var unitX = new Vector3( 1, 0, 0 );
-	var unitY = new Vector3( 0, 1, 0 );
-	var unitZ = new Vector3( 0, 0, 1 );
+		this.type = 'TransformControlsPlane';
 
-	var tempVector = new Vector3();
-	var dirVector = new Vector3();
-	var alignVector = new Vector3();
-	var tempMatrix = new Matrix4();
-	var identityQuaternion = new Quaternion();
+	}
 
-	this.updateMatrixWorld = function () {
+	updateMatrixWorld( force ) {
 
 		var space = this.space;
 
@@ -1607,13 +1608,13 @@ var TransformControlsPlane = function () {
 
 		if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
 
-		unitX.set( 1, 0, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion );
-		unitY.set( 0, 1, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion );
-		unitZ.set( 0, 0, 1 ).applyQuaternion( space === 'local' ? this.worldQuaternion : identityQuaternion );
+		_unitX.set( 1, 0, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion );
+		_unitY.set( 0, 1, 0 ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion );
+		_unitZ.set( 0, 0, 1 ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion );
 
 		// Align the plane for current transform mode, axis and space.
 
-		alignVector.copy( unitY );
+		_alignVector.copy( _unitY );
 
 		switch ( this.mode ) {
 
@@ -1622,30 +1623,30 @@ var TransformControlsPlane = function () {
 				switch ( this.axis ) {
 
 					case 'X':
-						alignVector.copy( this.eye ).cross( unitX );
-						dirVector.copy( unitX ).cross( alignVector );
+						_alignVector.copy( this.eye ).cross( _unitX );
+						_dirVector.copy( _unitX ).cross( _alignVector );
 						break;
 					case 'Y':
-						alignVector.copy( this.eye ).cross( unitY );
-						dirVector.copy( unitY ).cross( alignVector );
+						_alignVector.copy( this.eye ).cross( _unitY );
+						_dirVector.copy( _unitY ).cross( _alignVector );
 						break;
 					case 'Z':
-						alignVector.copy( this.eye ).cross( unitZ );
-						dirVector.copy( unitZ ).cross( alignVector );
+						_alignVector.copy( this.eye ).cross( _unitZ );
+						_dirVector.copy( _unitZ ).cross( _alignVector );
 						break;
 					case 'XY':
-						dirVector.copy( unitZ );
+						_dirVector.copy( _unitZ );
 						break;
 					case 'YZ':
-						dirVector.copy( unitX );
+						_dirVector.copy( _unitX );
 						break;
 					case 'XZ':
-						alignVector.copy( unitZ );
-						dirVector.copy( unitY );
+						_alignVector.copy( _unitZ );
+						_dirVector.copy( _unitY );
 						break;
 					case 'XYZ':
 					case 'E':
-						dirVector.set( 0, 0, 0 );
+						_dirVector.set( 0, 0, 0 );
 						break;
 
 				}
@@ -1654,35 +1655,29 @@ var TransformControlsPlane = function () {
 			case 'rotate':
 			default:
 				// special case for rotate
-				dirVector.set( 0, 0, 0 );
+				_dirVector.set( 0, 0, 0 );
 
 		}
 
-		if ( dirVector.length() === 0 ) {
+		if ( _dirVector.length() === 0 ) {
 
 			// If in rotate mode, make the plane parallel to camera
 			this.quaternion.copy( this.cameraQuaternion );
 
 		} else {
 
-			tempMatrix.lookAt( tempVector.set( 0, 0, 0 ), dirVector, alignVector );
+			_tempMatrix.lookAt( _tempVector.set( 0, 0, 0 ), _dirVector, _alignVector );
 
-			this.quaternion.setFromRotationMatrix( tempMatrix );
+			this.quaternion.setFromRotationMatrix( _tempMatrix );
 
 		}
 
-		Object3D.prototype.updateMatrixWorld.call( this );
+		super.updateMatrixWorld( force );
 
-	};
-
-};
-
-TransformControlsPlane.prototype = Object.assign( Object.create( Mesh.prototype ), {
-
-	constructor: TransformControlsPlane,
+	}
 
-	isTransformControlsPlane: true
+}
 
-} );
+TransformControlsPlane.prototype.isTransformControlsPlane = true;
 
 export { TransformControls, TransformControlsGizmo, TransformControlsPlane };

+ 30 - 32
src/objects/InstancedMesh.js

@@ -2,35 +2,31 @@ import { BufferAttribute } from '../core/BufferAttribute.js';
 import { Mesh } from './Mesh.js';
 import { Matrix4 } from '../math/Matrix4.js';
 
-const _instanceLocalMatrix = new Matrix4();
-const _instanceWorldMatrix = new Matrix4();
+const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
+const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
 
 const _instanceIntersects = [];
 
-const _mesh = new Mesh();
+const _mesh = /*@__PURE__*/ new Mesh();
 
-function InstancedMesh( geometry, material, count ) {
+class InstancedMesh extends Mesh {
 
-	Mesh.call( this, geometry, material );
+	constructor( geometry, material, count ) {
 
-	this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
-	this.instanceColor = null;
+		super( geometry, material );
 
-	this.count = count;
+		this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
+		this.instanceColor = null;
 
-	this.frustumCulled = false;
+		this.count = count;
 
-}
-
-InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
+		this.frustumCulled = false;
 
-	constructor: InstancedMesh,
-
-	isInstancedMesh: true,
+	}
 
-	copy: function ( source ) {
+	copy( source ) {
 
-		Mesh.prototype.copy.call( this, source );
+		super.copy( source );
 
 		this.instanceMatrix.copy( source.instanceMatrix );
 
@@ -40,21 +36,21 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 		return this;
 
-	},
+	}
 
-	getColorAt: function ( index, color ) {
+	getColorAt( index, color ) {
 
 		color.fromArray( this.instanceColor.array, index * 3 );
 
-	},
+	}
 
-	getMatrixAt: function ( index, matrix ) {
+	getMatrixAt( index, matrix ) {
 
 		matrix.fromArray( this.instanceMatrix.array, index * 16 );
 
-	},
+	}
 
-	raycast: function ( raycaster, intersects ) {
+	raycast( raycaster, intersects ) {
 
 		const matrixWorld = this.matrixWorld;
 		const raycastTimes = this.count;
@@ -93,9 +89,9 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 		}
 
-	},
+	}
 
-	setColorAt: function ( index, color ) {
+	setColorAt( index, color ) {
 
 		if ( this.instanceColor === null ) {
 
@@ -105,24 +101,26 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 		color.toArray( this.instanceColor.array, index * 3 );
 
-	},
+	}
 
-	setMatrixAt: function ( index, matrix ) {
+	setMatrixAt( index, matrix ) {
 
 		matrix.toArray( this.instanceMatrix.array, index * 16 );
 
-	},
+	}
 
-	updateMorphTargets: function () {
+	updateMorphTargets() {
 
-	},
+	}
 
-	dispose: function () {
+	dispose() {
 
 		this.dispatchEvent( { type: 'dispose' } );
 
 	}
 
-} );
+}
+
+InstancedMesh.prototype.isInstancedMesh = true;
 
 export { InstancedMesh };

+ 24 - 26
src/objects/Line.js

@@ -7,43 +7,39 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 
-const _start = new Vector3();
-const _end = new Vector3();
-const _inverseMatrix = new Matrix4();
-const _ray = new Ray();
-const _sphere = new Sphere();
+const _start = /*@__PURE__*/ new Vector3();
+const _end = /*@__PURE__*/ new Vector3();
+const _inverseMatrix = /*@__PURE__*/ new Matrix4();
+const _ray = /*@__PURE__*/ new Ray();
+const _sphere = /*@__PURE__*/ new Sphere();
 
-function Line( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
+class Line extends Object3D {
 
-	Object3D.call( this );
+	constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
 
-	this.type = 'Line';
+		super();
 
-	this.geometry = geometry;
-	this.material = material;
+		this.type = 'Line';
 
-	this.updateMorphTargets();
+		this.geometry = geometry;
+		this.material = material;
 
-}
-
-Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
-
-	constructor: Line,
+		this.updateMorphTargets();
 
-	isLine: true,
+	}
 
-	copy: function ( source ) {
+	copy( source ) {
 
-		Object3D.prototype.copy.call( this, source );
+		super.copy( source );
 
 		this.material = source.material;
 		this.geometry = source.geometry;
 
 		return this;
 
-	},
+	}
 
-	computeLineDistances: function () {
+	computeLineDistances() {
 
 		const geometry = this.geometry;
 
@@ -82,9 +78,9 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 		return this;
 
-	},
+	}
 
-	raycast: function ( raycaster, intersects ) {
+	raycast( raycaster, intersects ) {
 
 		const geometry = this.geometry;
 		const matrixWorld = this.matrixWorld;
@@ -202,9 +198,9 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 		}
 
-	},
+	}
 
-	updateMorphTargets: function () {
+	updateMorphTargets() {
 
 		const geometry = this.geometry;
 
@@ -249,7 +245,9 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 	}
 
-} );
+}
+
+Line.prototype.isLine = true;
 
 
 export { Line };

+ 10 - 13
src/objects/LineSegments.js

@@ -2,24 +2,20 @@ import { Line } from './Line.js';
 import { Vector3 } from '../math/Vector3.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 
-const _start = new Vector3();
-const _end = new Vector3();
+const _start = /*@__PURE__*/ new Vector3();
+const _end = /*@__PURE__*/ new Vector3();
 
-function LineSegments( geometry, material ) {
+class LineSegments extends Line {
 
-	Line.call( this, geometry, material );
+	constructor( geometry, material ) {
 
-	this.type = 'LineSegments';
+		super( geometry, material );
 
-}
-
-LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
-
-	constructor: LineSegments,
+		this.type = 'LineSegments';
 
-	isLineSegments: true,
+	}
 
-	computeLineDistances: function () {
+	computeLineDistances() {
 
 		const geometry = this.geometry;
 
@@ -60,7 +56,8 @@ LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
 
 	}
 
-} );
+}
 
+LineSegments.prototype.isLineSegments = true;
 
 export { LineSegments };

+ 34 - 36
src/objects/Mesh.js

@@ -9,51 +9,47 @@ import { DoubleSide, BackSide } from '../constants.js';
 import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 
-const _inverseMatrix = new Matrix4();
-const _ray = new Ray();
-const _sphere = new Sphere();
+const _inverseMatrix = /*@__PURE__*/ new Matrix4();
+const _ray = /*@__PURE__*/ new Ray();
+const _sphere = /*@__PURE__*/ new Sphere();
 
-const _vA = new Vector3();
-const _vB = new Vector3();
-const _vC = new Vector3();
+const _vA = /*@__PURE__*/ new Vector3();
+const _vB = /*@__PURE__*/ new Vector3();
+const _vC = /*@__PURE__*/ new Vector3();
 
-const _tempA = new Vector3();
-const _tempB = new Vector3();
-const _tempC = new Vector3();
+const _tempA = /*@__PURE__*/ new Vector3();
+const _tempB = /*@__PURE__*/ new Vector3();
+const _tempC = /*@__PURE__*/ new Vector3();
 
-const _morphA = new Vector3();
-const _morphB = new Vector3();
-const _morphC = new Vector3();
+const _morphA = /*@__PURE__*/ new Vector3();
+const _morphB = /*@__PURE__*/ new Vector3();
+const _morphC = /*@__PURE__*/ new Vector3();
 
-const _uvA = new Vector2();
-const _uvB = new Vector2();
-const _uvC = new Vector2();
+const _uvA = /*@__PURE__*/ new Vector2();
+const _uvB = /*@__PURE__*/ new Vector2();
+const _uvC = /*@__PURE__*/ new Vector2();
 
-const _intersectionPoint = new Vector3();
-const _intersectionPointWorld = new Vector3();
+const _intersectionPoint = /*@__PURE__*/ new Vector3();
+const _intersectionPointWorld = /*@__PURE__*/ new Vector3();
 
-function Mesh( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
+class Mesh extends Object3D {
 
-	Object3D.call( this );
+	constructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
 
-	this.type = 'Mesh';
+		super();
 
-	this.geometry = geometry;
-	this.material = material;
+		this.type = 'Mesh';
 
-	this.updateMorphTargets();
+		this.geometry = geometry;
+		this.material = material;
 
-}
-
-Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
+		this.updateMorphTargets();
 
-	constructor: Mesh,
-
-	isMesh: true,
+	}
 
-	copy: function ( source ) {
+	copy( source ) {
 
-		Object3D.prototype.copy.call( this, source );
+		super.copy( source );
 
 		if ( source.morphTargetInfluences !== undefined ) {
 
@@ -72,9 +68,9 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 		return this;
 
-	},
+	}
 
-	updateMorphTargets: function () {
+	updateMorphTargets() {
 
 		const geometry = this.geometry;
 
@@ -117,9 +113,9 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 		}
 
-	},
+	}
 
-	raycast: function ( raycaster, intersects ) {
+	raycast( raycaster, intersects ) {
 
 		const geometry = this.geometry;
 		const material = this.material;
@@ -288,7 +284,9 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 	}
 
-} );
+}
+
+Mesh.prototype.isMesh = true;
 
 function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
 

+ 21 - 23
src/objects/Points.js

@@ -6,42 +6,38 @@ import { Vector3 } from '../math/Vector3.js';
 import { PointsMaterial } from '../materials/PointsMaterial.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 
-const _inverseMatrix = new Matrix4();
-const _ray = new Ray();
-const _sphere = new Sphere();
-const _position = new Vector3();
+const _inverseMatrix = /*@__PURE__*/ new Matrix4();
+const _ray = /*@__PURE__*/ new Ray();
+const _sphere = /*@__PURE__*/ new Sphere();
+const _position = /*@__PURE__*/ new Vector3();
 
-function Points( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
+class Points extends Object3D {
 
-	Object3D.call( this );
+	constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
 
-	this.type = 'Points';
+		super();
 
-	this.geometry = geometry;
-	this.material = material;
+		this.type = 'Points';
 
-	this.updateMorphTargets();
+		this.geometry = geometry;
+		this.material = material;
 
-}
-
-Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
+		this.updateMorphTargets();
 
-	constructor: Points,
-
-	isPoints: true,
+	}
 
-	copy: function ( source ) {
+	copy( source ) {
 
-		Object3D.prototype.copy.call( this, source );
+		super.copy( source );
 
 		this.material = source.material;
 		this.geometry = source.geometry;
 
 		return this;
 
-	},
+	}
 
-	raycast: function ( raycaster, intersects ) {
+	raycast( raycaster, intersects ) {
 
 		const geometry = this.geometry;
 		const matrixWorld = this.matrixWorld;
@@ -108,9 +104,9 @@ Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 		}
 
-	},
+	}
 
-	updateMorphTargets: function () {
+	updateMorphTargets() {
 
 		const geometry = this.geometry;
 
@@ -155,7 +151,9 @@ Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 	}
 
-} );
+}
+
+Points.prototype.isPoints = true;
 
 function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
 

+ 28 - 31
src/objects/SkinnedMesh.js

@@ -3,35 +3,31 @@ import { Matrix4 } from '../math/Matrix4.js';
 import { Vector3 } from '../math/Vector3.js';
 import { Vector4 } from '../math/Vector4.js';
 
-const _basePosition = new Vector3();
+const _basePosition = /*@__PURE__*/ new Vector3();
 
-const _skinIndex = new Vector4();
-const _skinWeight = new Vector4();
+const _skinIndex = /*@__PURE__*/ new Vector4();
+const _skinWeight = /*@__PURE__*/ new Vector4();
 
-const _vector = new Vector3();
-const _matrix = new Matrix4();
+const _vector = /*@__PURE__*/ new Vector3();
+const _matrix = /*@__PURE__*/ new Matrix4();
 
-function SkinnedMesh( geometry, material ) {
+class SkinnedMesh extends Mesh {
 
-	Mesh.call( this, geometry, material );
+	constructor( geometry, material ) {
 
-	this.type = 'SkinnedMesh';
+		super( geometry, material );
 
-	this.bindMode = 'attached';
-	this.bindMatrix = new Matrix4();
-	this.bindMatrixInverse = new Matrix4();
+		this.type = 'SkinnedMesh';
 
-}
-
-SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
-
-	constructor: SkinnedMesh,
+		this.bindMode = 'attached';
+		this.bindMatrix = new Matrix4();
+		this.bindMatrixInverse = new Matrix4();
 
-	isSkinnedMesh: true,
+	}
 
-	copy: function ( source ) {
+	copy( source ) {
 
-		Mesh.prototype.copy.call( this, source );
+		super.copy( source );
 
 		this.bindMode = source.bindMode;
 		this.bindMatrix.copy( source.bindMatrix );
@@ -41,9 +37,9 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 		return this;
 
-	},
+	}
 
-	bind: function ( skeleton, bindMatrix ) {
+	bind( skeleton, bindMatrix ) {
 
 		this.skeleton = skeleton;
 
@@ -60,15 +56,15 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 		this.bindMatrix.copy( bindMatrix );
 		this.bindMatrixInverse.copy( bindMatrix ).invert();
 
-	},
+	}
 
-	pose: function () {
+	pose() {
 
 		this.skeleton.pose();
 
-	},
+	}
 
-	normalizeSkinWeights: function () {
+	normalizeSkinWeights() {
 
 		const vector = new Vector4();
 
@@ -97,11 +93,11 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 		}
 
-	},
+	}
 
-	updateMatrixWorld: function ( force ) {
+	updateMatrixWorld( force ) {
 
-		Mesh.prototype.updateMatrixWorld.call( this, force );
+		super.updateMatrixWorld( force );
 
 		if ( this.bindMode === 'attached' ) {
 
@@ -117,9 +113,9 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 		}
 
-	},
+	}
 
-	boneTransform: function ( index, target ) {
+	boneTransform( index, target ) {
 
 		const skeleton = this.skeleton;
 		const geometry = this.geometry;
@@ -151,7 +147,8 @@ SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 	}
 
-} );
+}
 
+SkinnedMesh.prototype.isSkinnedMesh = true;
 
 export { SkinnedMesh };