提交 5c3aab83 编写于 作者: A ALEXANDER PLETZER

fix for vertices that are integer numbers

上级 d6384d20
......@@ -31,45 +31,69 @@ THREE.VTKLoader.prototype = {
var indices = [];
var positions = [];
var pattern, result;
var result;
// float float float
pattern = /([\+|\-]?[\d]+[\.][\d|\-|e]+)[ ]+([\+|\-]?[\d]+[\.][\d|\-|e]+)[ ]+([\+|\-]?[\d]+[\.][\d|\-|e]+)/g;
var pat3Floats = /([\-]?[\d]+[\.]?[\d|\-|e]*)[ ]+([\-]?[\d]+[\.]?[\d|\-|e]*)[ ]+([\-]?[\d]+[\.]?[\d|\-|e]*)/g;
var patTriangle = /^3[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/;
var patQuad = /^4[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/;
var patPOINTS = /^POINTS /;
var patPOLYGONS = /^POLYGONS /;
var inPointsSection = false;
var inPolygonsSection = false;
while ( ( result = pattern.exec( data ) ) !== null ) {
var lines = data.split('\n');
for ( var i = 0; i < lines.length; ++i ) {
// ["1.0 2.0 3.0", "1.0", "2.0", "3.0"]
line = lines[i];
positions.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
if ( inPointsSection ) {
}
// get the vertices
// 3 int int int
while ( ( result = pat3Floats.exec( line ) ) !== null ) {
positions.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
}
}
else if ( inPolygonsSection ) {
pattern = /3[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g;
result = patTriangle.exec(line);
while ( ( result = pattern.exec( data ) ) !== null ) {
if ( result !== null ) {
// ["3 1 2 3", "1", "2", "3"]
// 3 int int int
// triangle
indices.push( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) );
}
else {
// 4 int int int int
pattern = /4[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g;
result = patQuad.exec(line);
while ( ( result = pattern.exec( data ) ) !== null ) {
if ( result !== null ) {
// ["4 1 2 3 4", "1", "2", "3", "4"]
// 4 int int int int
// break quad into two triangles
indices.push( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 4 ] ) );
indices.push( parseInt( result[ 2 ] ), parseInt( result[ 3 ] ), parseInt( result[ 4 ] ) );
}
}
}
if ( patPOLYGONS.exec(line) !== null ) {
inPointsSection = false;
inPolygonsSection = true;
}
if ( patPOINTS.exec(line) !== null ) {
inPolygonsSection = false;
inPointsSection = true;
}
}
var geometry = new THREE.BufferGeometry();
geometry.addAttribute( 'index', new THREE.BufferAttribute( new ( indices.length > 65535 ? Uint32Array : Uint16Array )( indices ), 1 ) );
geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( positions ), 3 ) );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册