提交 8292d318 编写于 作者: T tpmccauley

OBJExporter: export lines

* When an object child is a THREE.Line parse and output to obj file.

* Handles separate cases of type Line and type LineSegment

remove nbVertex; it is not needed
上级 e39520a6
......@@ -123,11 +123,11 @@ THREE.OBJExporter.prototype = {
var face = faces[ i ];
for ( var m = 0; m < 3; m ++ ) {
indices[ m ] = ( indexVertex + face[ faceVertexKeys[ m ] ] + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + m + 1 ) : '' ) + '/' + ( indexNormals + j + m + 1 );
}
output += 'f ' + indices.join( ' ' ) + "\n";
}
......@@ -145,9 +145,71 @@ THREE.OBJExporter.prototype = {
};
var parseLine = function( line ) {
var geometry = line.geometry;
var type = line.type;
if ( geometry instanceof THREE.BufferGeometry ) {
geometry = new THREE.Geometry().fromBufferGeometry( geometry );
}
if ( geometry instanceof THREE.Geometry ) {
output += 'o ' + line.name + '\n';
var vertices = geometry.vertices;
for ( var i = 0, l = vertices.length; i < l; i++ ) {
var vertex = vertices[ i ].clone();
vertex.applyMatrix4( line.matrixWorld );
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
}
if ( type === 'Line' ) {
output += 'l ';
for ( var j = 1, m = vertices.length; j <= m; j++ ) {
output += j + ' ';
}
output += '\n';
}
if ( type === 'LineSegments' ) {
for ( var j = 1, k = j + 1, m = vertices.length; j < m; j += 2, k = j + 1 ) {
output += 'l ' + j + ' ' + k + '\n';
}
}
} else {
console.warn('THREE.OBJExporter.parseLine(): geometry type unsupported', line);
}
};
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) parseMesh( child );
if ( child instanceof THREE.Mesh ) {
parseMesh( child );
}
if ( child instanceof THREE.Line ) {
parseLine( child );
}
} );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册