Browse Source

Merge pull request #14573 from gkjohnson/ply-exporter-onDone

Add onDone to PLYExporter
Mr.doob 7 years ago
parent
commit
8c6d24b087
2 changed files with 21 additions and 7 deletions
  1. 4 2
      docs/examples/exporters/PLYExporter.html
  2. 17 5
      examples/js/exporters/PLYExporter.js

+ 4 - 2
docs/examples/exporters/PLYExporter.html

@@ -41,9 +41,10 @@
 
 		<h2>Methods</h2>
 
-		<h3>[method:null parse]( [param:Object3D input], [param:Object options] )</h3>
+		<h3>[method:null parse]( [param:Object3D input], [param:Function onCompleted], [param:Object options] )</h3>
 		<p>
 		[page:Object input] — Object3D<br />
+		[page:Function onCompleted] — Will be called when the export completes. The argument will be the generated ply ascii or binary ArrayBuffer.<br />
 		[page:Options options] — Export options<br />
 		<ul>
 			<li>excludeAttributes - array. Which properties to explicitly exclude from the exported PLY file. Valid values are 'color', 'normal', 'uv', and 'index'. If triangle indices are excluded, then a point cloud is exported. Default is an empty array.</li>
@@ -51,7 +52,8 @@
 		</ul>
 		</p>
 		<p>
-		Generates ply file data as string or ArrayBuffer (ascii or binary) output from the input object.
+		Generates ply file data as string or ArrayBuffer (ascii or binary) output from the input object. The data that is returned is the same
+		that is passed into the "onCompleted" function.
 		If the object is composed of multiple children and geometry, they are merged into a single mesh in the file.
 		</p>
 

+ 17 - 5
examples/js/exporters/PLYExporter.js

@@ -6,10 +6,10 @@
  *  var exporter = new THREE.PLYExporter();
  *
  *  // second argument is a list of options
- *  var data = exporter.parse( mesh, { binary: true, excludeAttributes: [ 'color' ] } );
+ *  exporter.parse(mesh, data => console.log(data), { binary: true, excludeAttributes: [ 'color' ] });
  *
  * Format Definition:
- *  http://paulbourke.net/dataformats/ply/
+ * http://paulbourke.net/dataformats/ply/
  */
 
 THREE.PLYExporter = function () {};
@@ -18,7 +18,15 @@ THREE.PLYExporter.prototype = {
 
 	constructor: THREE.PLYExporter,
 
-	parse: function ( object, options ) {
+	parse: function ( object, onDone, options ) {
+
+		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.' );
+			options = onDone;
+			onDone = undefined;
+
+		}
 
 		// Iterate over the valid meshes in the object
 		function traverseMeshes( cb ) {
@@ -208,6 +216,7 @@ THREE.PLYExporter.prototype = {
 		// Generate attribute data
 		var vertex = new THREE.Vector3();
 		var normalMatrixWorld = new THREE.Matrix3();
+		var result = null;
 
 		if ( options.binary === true ) {
 
@@ -399,7 +408,7 @@ THREE.PLYExporter.prototype = {
 
 			} );
 
-			return output;
+			result = output.buffer;
 
 		} else {
 
@@ -529,10 +538,13 @@ THREE.PLYExporter.prototype = {
 
 			} );
 
-			return `${ header }${vertexList}\n${ includeIndices ? `${faceList}\n` : '' }`;
+			result = `${ header }${vertexList}\n${ includeIndices ? `${faceList}\n` : '' }`;
 
 		}
 
+		if ( typeof onDone === 'function' ) requestAnimationFrame( () => onDone( result ) );
+		return result;
+
 	}
 
 };