12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- THREE.VTKLoader = function () {};
- THREE.VTKLoader.prototype = {
- constructor: THREE.VTKLoader,
- load: function ( url, onLoad, onProgress, onError ) {
- var scope = this;
- var loader = new THREE.XHRLoader( scope.manager );
- loader.setCrossOrigin( this.crossOrigin );
- loader.load( url, function ( text ) {
- onLoad( scope.parse( text ) );
- } );
- },
- parse: function ( data ) {
- var indices = [];
- var positions = [];
- var pattern, result;
-
- pattern = /([\+|\-]?[\d]+[\.][\d|\-|e]+)[ ]+([\+|\-]?[\d]+[\.][\d|\-|e]+)[ ]+([\+|\-]?[\d]+[\.][\d|\-|e]+)/g;
- while ( ( result = pattern.exec( data ) ) !== null ) {
-
- positions.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
- }
-
- pattern = /3[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g;
- while ( ( result = pattern.exec( data ) ) !== null ) {
-
- indices.push( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) );
- }
-
- pattern = /4[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g;
- while ( ( result = pattern.exec( data ) ) !== null ) {
-
- indices.push( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 4 ] ) );
- indices.push( parseInt( result[ 2 ] ), parseInt( result[ 3 ] ), parseInt( result[ 4 ] ) );
- }
- 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 ) );
- return geometry;
- }
- };
- THREE.EventDispatcher.prototype.apply( THREE.VTKLoader.prototype );
|