Skip to content
Browse files

Reformated VTKLoader.

  • Loading branch information...
1 parent f3dc454 commit 21a5aa4b6d4ac3bfd0fdf87645a107961d63adf2 @mrdoob committed Apr 18, 2012
Showing with 155 additions and 117 deletions.
  1. +0 −4 examples/js/loaders/OBJLoader.js
  2. +155 −113 examples/js/loaders/VTKLoader.js
View
4 examples/js/loaders/OBJLoader.js
@@ -20,8 +20,6 @@ THREE.OBJLoader.prototype.load = function ( url, callback ) {
callback( that.parse( xhr.responseText ) );
- that.onLoadComplete();
-
} else {
console.error( 'THREE.OBJLoader: Couldn\'t load ' + url + ' (' + xhr.status + ')' );
@@ -35,8 +33,6 @@ THREE.OBJLoader.prototype.load = function ( url, callback ) {
xhr.open( "GET", url, true );
xhr.send( null );
- that.onLoadStart();
-
};
THREE.OBJLoader.prototype.parse = function ( data ) {
View
268 examples/js/loaders/VTKLoader.js
@@ -1,5 +1,5 @@
/**
- * @author mrdoob / http://mrdoob.com/
+ * @author Sebastien Valette sebastien.valette@creatis.insa-lyon.fr
*/
THREE.VTKLoader = function () {};
@@ -37,8 +37,8 @@ THREE.VTKLoader.prototype.load = function ( url, callback ) {
THREE.VTKLoader.prototype.parse = function ( data ) {
- var geometry=new THREE.Geometry();
- var lines=data.split("\n");
+ var geometry = new THREE.Geometry();
+ var lines = data.split("\n");
function v( x, y, z ) {
@@ -52,158 +52,200 @@ THREE.VTKLoader.prototype.parse = function ( data ) {
}
- var lineIndex=0;
-
- var line=lines[0].split(" ");
- var lineLength=line.length;
- var columnIndex=-1;
-
-
- function readNextString ()
- {
- while (1)
- {
- var nextWord=line[columnIndex];
- columnIndex++;
- if (columnIndex==lineLength)
- {
- lineIndex++;
- columnIndex=0;
- if (lineIndex>lines.length)
- return ("");
- line=lines[lineIndex].split(" ");
- lineLength=line.length;
+ var lineIndex = 0;
+
+ var line = lines[ 0 ].split( ' ' );
+ var lineLength = line.length;
+ var columnIndex = -1;
+
+ function readNextString() {
+
+ while ( 1 ) {
+
+ var nextWord = line[ columnIndex ];
+ columnIndex ++;
+
+ if ( columnIndex == lineLength ) {
+
+ lineIndex ++;
+ columnIndex = 0;
+
+ if ( lineIndex > lines.length ) {
+
+ return '';
+
+ }
+
+ line = lines[ lineIndex ].split( ' ' );
+ lineLength = line.length;
+
}
- if (nextWord!=null)
- if (nextWord.length>0)
- return (nextWord);
+
+ if ( nextWord != null ) {
+
+ if ( nextWord.length > 0 ) {
+
+ return nextWord;
+
+ }
+
+ }
+
}
+
}
// read point data
- var found=false;
- while (!found)
- {
- var readString=readNextString();
- switch (readString.toUpperCase())
- {
- case "POINTS":
- found=true;
+ var found = false;
+ while ( !found ) {
+
+ var readString = readNextString();
+
+ switch ( readString.toUpperCase() ) {
+
+ case 'POINTS':
+ found = true;
break;
- case "":
- alert ("error while reading "+url+" : \n");
+
+ case '':
+ alert ( 'error while reading ' + url + ' : \n' );
return;
- default:
+
}
}
var newIndex;
var new2old;
- var numberOfPoints=parseInt(readNextString());
+ var numberOfPoints = parseInt( readNextString() );
+
+ if ( numberOfPoints > 5000000 ) {
- if (numberOfPoints>5000000)
- {
- alert ("mesh is too big : "+numberOfPoints+" vertices");
+ alert ( 'mesh is too big : ' + numberOfPoints + ' vertices' );
return;
+
}
- var coord=[0,0,0];
- var index2=0;
+ var coord = [ 0, 0, 0 ];
+ var index2 = 0;
var number;
var coordIndex;
- for (var j=0;j!=numberOfPoints;j++)
- {
- for (coordIndex=0;coordIndex<3;coordIndex++)
- {
- do
- {
- number=parseFloat(line[columnIndex]);
- columnIndex++;
- if (columnIndex==lineLength)
- {
- lineIndex++;
- columnIndex=0;
- if (lineIndex>lines.length)
- {
- alert ("error while reading "+url+" : \n");
+
+ for ( var j = 0; j != numberOfPoints; j ++ ) {
+
+ for ( coordIndex = 0; coordIndex < 3; coordIndex ++ ) {
+
+ do {
+
+ number = parseFloat( line[ columnIndex ] );
+
+ columnIndex ++;
+
+ if ( columnIndex == lineLength ) {
+
+ lineIndex ++;
+ columnIndex = 0;
+
+ if ( lineIndex > lines.length ) {
+
+ alert ( 'error while reading ' + url + ' : \n' );
return;
}
- line=lines[lineIndex].split(" ");
- lineLength=line.length;
+
+ line = lines[ lineIndex ].split( ' ' );
+ lineLength = line.length;
}
- } while (isNaN(number))
- coord[coordIndex]=number;
+ } while ( isNaN( number ) )
+
+ coord[ coordIndex ] = number;
}
- v(coord[0],coord[1],coord[2]);
+
+ v( coord[ 0 ], coord[ 1 ], coord[ 2 ] );
+
}
- found=false;
- while (!found)
- {
- var readString=readNextString();
- switch (readString)
- {
- case "POLYGONS":
- found=true;
+ found = false;
+
+ while ( !found ) {
+
+ var readString = readNextString();
+
+ switch ( readString ) {
+
+ case 'POLYGONS':
+ found = true;
break;
- case "":
- alert ("error while reading "+url+" : \n");
+
+ case '':
+ alert ( 'error while reading ' + url + ' : \n' );
return;
- default:
+
}
+
}
- var numberOfPolygons=parseInt(readNextString());
- var numberOfpolygonElements=parseInt(readNextString());
-
- index2=0;
- var connectivity=[];
- for (var p=0;p!=numberOfpolygonElements;p++)
- {
- do
- {
- number=parseInt(line[columnIndex]);
- columnIndex++;
- if (columnIndex==lineLength)
- {
- lineIndex++;
- columnIndex=0;
- if (lineIndex>lines.length)
- {
- alert ("error while reading "+url+" : \n");
+ var numberOfPolygons = parseInt( readNextString() );
+ var numberOfpolygonElements = parseInt( readNextString() );
+
+ index2 = 0;
+ var connectivity = [];
+
+ for ( var p = 0; p != numberOfpolygonElements; p ++ ) {
+
+ do {
+
+ number = parseInt( line[ columnIndex ] );
+
+ columnIndex ++;
+
+ if ( columnIndex == lineLength ) {
+
+ lineIndex ++;
+ columnIndex = 0;
+
+ if ( lineIndex > lines.length ) {
+
+ alert ( 'error while reading ' + url + ' : \n' );
return;
+
}
- line=lines[lineIndex].split(" ");
- lineLength=line.length;
+
+ line = lines[ lineIndex ].split( ' ' );
+ lineLength = line.length;
}
- } while (isNaN(number))
-
- connectivity[index2]=number;
- index2++;
-
- if (index2==connectivity[0]+1)
- {
- var triangle=[0,0,0];
- index2=0;
- var numberOfTrianglesInCell=connectivity[0]-2;
- var vertex1=triangle[0]=connectivity[1];
-
- for (var i=0;i<numberOfTrianglesInCell;i++)
- {
- var vertex2=connectivity[i+2];
- var vertex3=triangle[2]=connectivity[i+3];
- f3(vertex1,vertex2,vertex3);
+ } while ( isNaN( number ) )
+
+ connectivity[ index2 ] = number;
+ index2 ++;
+
+ if ( index2 == connectivity[ 0 ] + 1 ) {
+
+ var triangle = [ 0, 0, 0 ];
+ index2 = 0;
+
+ var numberOfTrianglesInCell = connectivity[ 0 ] - 2;
+ var vertex1 = triangle[ 0 ] = connectivity[ 1 ];
+
+ for ( var i = 0; i < numberOfTrianglesInCell; i ++ ) {
+
+ var vertex2 = connectivity[ i + 2 ];
+ var vertex3 = triangle[ 2 ] = connectivity[ i + 3 ];
+
+ f3( vertex1, vertex2, vertex3 );
+
}
+
}
+
}
geometry.computeCentroids();
geometry.computeFaceNormals();
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
- return (geometry);
+
+ return geometry;
}

0 comments on commit 21a5aa4

Please sign in to comment.
Something went wrong with that request. Please try again.