Переглянути джерело

Exporters: Clean up ES modules, update script.

Don McCurdy 6 роки тому
батько
коміт
6488f7a1c5

+ 6 - 6
examples/jsm/exporters/ColladaExporter.js

@@ -211,7 +211,7 @@ ColladaExporter.prototype = {
 
 				// convert the geometry to bufferGeometry if it isn't already
 				var bufferGeometry = g;
-				if ( bufferGeometry.isGeometry ) {
+				if ( bufferGeometry instanceof Geometry ) {
 
 					bufferGeometry = ( new BufferGeometry() ).fromGeometry( bufferGeometry );
 
@@ -362,11 +362,11 @@ ColladaExporter.prototype = {
 
 				var type = 'phong';
 
-				if ( m.isMeshLambertMaterial ) {
+				if ( m instanceof MeshLambertMaterial ) {
 
 					type = 'lambert';
 
-				} else if ( m.isMeshBasicMaterial ) {
+				} else if ( m instanceof MeshBasicMaterial ) {
 
 					type = 'constant';
 
@@ -388,7 +388,7 @@ ColladaExporter.prototype = {
 				var reflectivity = m.reflectivity || 0;
 
 				// Do not export and alpha map for the reasons mentioned in issue (#13792)
-				// in js alpha maps are black and white, but collada expects the alpha
+				// in THREE.js alpha maps are black and white, but collada expects the alpha
 				// channel to specify the transparency
 				var transparencyNode = '';
 				if ( m.transparent === true ) {
@@ -519,7 +519,7 @@ ColladaExporter.prototype = {
 
 			node += getTransform( o );
 
-			if ( o.isMesh && o.geometry != null ) {
+			if ( o instanceof Mesh && o.geometry != null ) {
 
 				// function returns the id associated with the mesh and a "BufferGeometry" version
 				// of the geometry in case it's not a geometry.
@@ -592,7 +592,7 @@ ColladaExporter.prototype = {
 			'<asset>' +
 			(
 				'<contributor>' +
-				'<authoring_tool>js Collada Exporter</authoring_tool>' +
+				'<authoring_tool>THREE.js Collada Exporter</authoring_tool>' +
 				( options.author !== null ? `<author>${ options.author }</author>` : '' ) +
 				'</contributor>' +
 				`<created>${ ( new Date() ).toISOString() }</created>` +

+ 1 - 1
examples/jsm/exporters/GLTFExporter.js

@@ -1930,7 +1930,7 @@ GLTFExporter.prototype = {
 
 			for ( var i = 0; i < input.length; i ++ ) {
 
-				if ( input[ i ].isScene ) {
+				if ( input[ i ] instanceof Scene ) {
 
 					processScene( input[ i ] );
 

+ 1 - 1
examples/jsm/exporters/MMDExporter.js

@@ -99,7 +99,7 @@ var MMDExporter = function () {
 
 		if ( skin.isSkinnedMesh !== true ) {
 
-			console.warn( 'THREE.MMDExporter: parseVpd() requires SkinnedMesh instance.' );
+			console.warn( 'MMDExporter: parseVpd() requires SkinnedMesh instance.' );
 			return null;
 
 		}

+ 6 - 6
examples/jsm/exporters/OBJExporter.js

@@ -42,13 +42,13 @@ OBJExporter.prototype = {
 
 			var normalMatrixWorld = new Matrix3();
 
-			if ( geometry.isGeometry ) {
+			if ( geometry instanceof Geometry ) {
 
 				geometry = new BufferGeometry().setFromObject( mesh );
 
 			}
 
-			if ( geometry.isBufferGeometry ) {
+			if ( geometry instanceof BufferGeometry ) {
 
 				// shortcuts
 				var vertices = geometry.getAttribute( 'position' );
@@ -182,13 +182,13 @@ OBJExporter.prototype = {
 			var geometry = line.geometry;
 			var type = line.type;
 
-			if ( geometry.isGeometry ) {
+			if ( geometry instanceof Geometry ) {
 
 				geometry = new BufferGeometry().setFromObject( line );
 
 			}
 
-			if ( geometry.isBufferGeometry ) {
+			if ( geometry instanceof BufferGeometry ) {
 
 				// shortcuts
 				var vertices = geometry.getAttribute( 'position' );
@@ -251,13 +251,13 @@ OBJExporter.prototype = {
 
 		object.traverse( function ( child ) {
 
-			if ( child.isMesh ) {
+			if ( child instanceof Mesh ) {
 
 				parseMesh( child );
 
 			}
 
-			if ( child.isLine ) {
+			if ( child instanceof Line ) {
 
 				parseLine( child );
 

+ 1 - 1
examples/jsm/exporters/PLYExporter.js

@@ -28,7 +28,7 @@ PLYExporter.prototype = {
 
 		if ( onDone && typeof onDone === 'object' ) {
 
-			console.warn( 'THREE.PLYExporter: The options parameter is now the third argument to the "parse" function. See the documentation for the new API.' );
+			console.warn( 'PLYExporter: The options parameter is now the third argument to the "parse" function. See the documentation for the new API.' );
 			options = onDone;
 			onDone = undefined;
 

+ 2 - 0
examples/jsm/exporters/TypedGeometryExporter.js

@@ -2,6 +2,8 @@
  * @author mrdoob / http://mrdoob.com/
  */
 
+
+
 var TypedGeometryExporter = function () {};
 
 TypedGeometryExporter.prototype = {

+ 30 - 4
utils/modularize.js

@@ -12,7 +12,12 @@ var files = [
 	{ path: 'controls/MapControls.js', ignoreList: [] },
 	{ path: 'controls/TrackballControls.js', ignoreList: [] },
 	// { path: 'controls/TransformControls.js', ignoreList: [] },
-	{ path: 'exporters/GLTFExporter.js', ignoreList: [] },
+	{ path: 'exporters/GLTFExporter.js', ignoreList: ['AnimationClip', 'Camera', 'Material', 'Mesh', 'Object3D', 'RGBFormat', 'Scenes', 'ShaderMaterial', 'VertexColors' ] },
+	{ path: 'exporters/MMDExporter.js', ignoreList: [] },
+	{ path: 'exporters/OBJExporter.js', ignoreList: [] },
+	{ path: 'exporters/PLYExporter.js', ignoreList: [] },
+	{ path: 'exporters/STLExporter.js', ignoreList: [] },
+	{ path: 'exporters/TypedGeometryExporter.js', ignoreList: [] },
 	{ path: 'loaders/GLTFLoader.js', ignoreList: [ 'NoSide', 'Matrix2', 'DDSLoader' ] },
 	{ path: 'loaders/OBJLoader.js', ignoreList: [] },
 	{ path: 'loaders/MTLLoader.js', ignoreList: [] }
@@ -51,6 +56,14 @@ function convert( path, ignoreList ) {
 		if ( p1 === '\'' ) return match; // Inside a string
 		if ( p2 === className ) return `${p2}${p3}`;
 
+		if ( p1 === 'Math' ) {
+
+			dependencies[ '_Math' ] = true;
+
+			return '_Math.';
+
+		}
+
 		return match;
 
 	} );
@@ -72,7 +85,15 @@ function convert( path, ignoreList ) {
 	contents = contents.replace( /THREE\.([a-zA-Z0-9]+)/g, function ( match, p1 ) {
 
 		if ( ignoreList.includes( p1 ) ) return match;
-		if ( p1 === className ) return match;
+		if ( p1 === className ) return p1;
+
+		if ( p1 === 'Math' || p1 === '_Math' ) {
+
+			dependencies[ '_Math' ] = true;
+
+			return '_Math';
+
+		}
 
 		dependencies[ p1 ] = true;
 
@@ -84,11 +105,16 @@ function convert( path, ignoreList ) {
 
 	//
 
-	var keys = Object.keys( dependencies ).sort().map( value => '\n\t' + value ).toString();
+	var keys = Object.keys( dependencies )
+		.filter( value => value !== className )
+		.map( value => value === '_Math' ? 'Math as _Math' : value )
+		.map( value => '\n\t' + value )
+		.sort()
+		.toString();
 	var imports = `import {${keys}\n} from "../../../build/three.module.js";`;
 	var exports = `export { ${className} };\n`;
 
-	var output = contents.replace( '_IMPORTS_', imports ) + '\n' + exports;
+	var output = contents.replace( '_IMPORTS_', keys ? imports : '' ) + '\n' + exports;
 
 	// console.log( output );