未验证 提交 8c6d24b0 编写于 作者: M Mr.doob 提交者: GitHub

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

Add onDone to PLYExporter
......@@ -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>
......
......@@ -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;
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册