|
2 | 2 | * @author mrdoob / http://mrdoob.com/
|
3 | 3 | */
|
4 | 4 |
|
5 |
| -THREE.VTKLoader = function () {}; |
| 5 | +THREE.VTKLoader = function () { |
6 | 6 |
|
7 |
| -THREE.VTKLoader.prototype = new THREE.Loader(); |
8 |
| -THREE.VTKLoader.prototype.constructor = THREE.VTKLoader; |
| 7 | + THREE.EventTarget.call( this ); |
9 | 8 |
|
10 |
| -THREE.VTKLoader.prototype.load = function ( url, callback ) { |
| 9 | +}; |
| 10 | + |
| 11 | +THREE.VTKLoader.prototype = { |
| 12 | + |
| 13 | + constructor: THREE.VTKLoader, |
| 14 | + |
| 15 | + load: function ( url ) { |
| 16 | + |
| 17 | + var scope = this; |
| 18 | + var xhr = new XMLHttpRequest(); |
11 | 19 |
|
12 |
| - var that = this; |
13 |
| - var xhr = new XMLHttpRequest(); |
| 20 | + xhr.onreadystatechange = function () { |
14 | 21 |
|
15 |
| - xhr.onreadystatechange = function () { |
| 22 | + if ( xhr.readyState == 4 ) { |
16 | 23 |
|
17 |
| - if ( xhr.readyState == 4 ) { |
| 24 | + if ( xhr.status == 200 || xhr.status == 0 ) { |
18 | 25 |
|
19 |
| - if ( xhr.status == 200 || xhr.status == 0 ) { |
| 26 | + scope.dispatchEvent( { type: 'complete', content: scope.parse( xhr.responseText ) } ); |
20 | 27 |
|
21 |
| - callback( that.parse( xhr.responseText ) ); |
| 28 | + } else { |
22 | 29 |
|
23 |
| - } else { |
| 30 | + scope.dispatchEvent( { type: 'error', status: xhr.status } ); |
24 | 31 |
|
25 |
| - console.error( 'THREE.VTKLoader: Couldn\'t load ' + url + ' (' + xhr.status + ')' ); |
| 32 | + } |
26 | 33 |
|
27 | 34 | }
|
28 | 35 |
|
29 |
| - } |
| 36 | + }; |
30 | 37 |
|
31 |
| - }; |
| 38 | + xhr.open( 'GET', url, true ); |
| 39 | + xhr.send( null ); |
32 | 40 |
|
33 |
| - xhr.open( "GET", url, true ); |
34 |
| - xhr.send( null ); |
| 41 | + }, |
35 | 42 |
|
36 |
| -}; |
| 43 | + parse: function ( data ) { |
37 | 44 |
|
38 |
| -THREE.VTKLoader.prototype.parse = function ( data ) { |
| 45 | + var geometry = new THREE.Geometry(); |
39 | 46 |
|
40 |
| - var geometry = new THREE.Geometry(); |
| 47 | + function vertex( x, y, z ) { |
41 | 48 |
|
42 |
| - function vertex( x, y, z ) { |
| 49 | + geometry.vertices.push( new THREE.Vector3( x, y, z ) ); |
43 | 50 |
|
44 |
| - geometry.vertices.push( new THREE.Vector3( x, y, z ) ); |
| 51 | + } |
45 | 52 |
|
46 |
| - } |
| 53 | + function face3( a, b, c ) { |
47 | 54 |
|
48 |
| - function face3( a, b, c ) { |
| 55 | + geometry.faces.push( new THREE.Face3( a, b, c ) ); |
49 | 56 |
|
50 |
| - geometry.faces.push( new THREE.Face3( a, b, c ) ); |
| 57 | + } |
51 | 58 |
|
52 |
| - } |
| 59 | + function face4( a, b, c, d ) { |
53 | 60 |
|
54 |
| - function face4( a, b, c, d ) { |
| 61 | + geometry.faces.push( new THREE.Face4( a, b, c, d ) ); |
55 | 62 |
|
56 |
| - geometry.faces.push( new THREE.Face4( a, b, c, d ) ); |
| 63 | + } |
57 | 64 |
|
58 |
| - } |
| 65 | + var pattern, result; |
59 | 66 |
|
60 |
| - var pattern, result; |
| 67 | + // float float float |
61 | 68 |
|
62 |
| - // float float float |
| 69 | + pattern = /([\d|\.|\+|\-|e]+)[ ]+([\d|\.|\+|\-|e]+)[ ]+([\d|\.|\+|\-|e]+)/g; |
63 | 70 |
|
64 |
| - pattern = /([\d|\.|\+|\-|e]+)[ ]+([\d|\.|\+|\-|e]+)[ ]+([\d|\.|\+|\-|e]+)/g; |
| 71 | + while ( ( result = pattern.exec( data ) ) != null ) { |
65 | 72 |
|
66 |
| - while ( ( result = pattern.exec( data ) ) != null ) { |
| 73 | + // ["1.0 2.0 3.0", "1.0", "2.0", "3.0"] |
67 | 74 |
|
68 |
| - // ["1.0 2.0 3.0", "1.0", "2.0", "3.0"] |
| 75 | + vertex( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) ); |
69 | 76 |
|
70 |
| - vertex( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) ); |
| 77 | + } |
71 | 78 |
|
72 |
| - } |
| 79 | + // 3 int int int |
73 | 80 |
|
74 |
| - // 3 int int int |
| 81 | + pattern = /3[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g; |
75 | 82 |
|
76 |
| - pattern = /3[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g; |
| 83 | + while ( ( result = pattern.exec( data ) ) != null ) { |
77 | 84 |
|
78 |
| - while ( ( result = pattern.exec( data ) ) != null ) { |
| 85 | + // ["3 1 2 3", "1", "2", "3"] |
79 | 86 |
|
80 |
| - // ["3 1 2 3", "1", "2", "3"] |
| 87 | + face3( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) ); |
81 | 88 |
|
82 |
| - face3( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) ); |
| 89 | + } |
83 | 90 |
|
84 |
| - } |
| 91 | + // 4 int int int int |
85 | 92 |
|
86 |
| - // 4 int int int int |
| 93 | + pattern = /4[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g; |
87 | 94 |
|
88 |
| - pattern = /4[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g; |
| 95 | + while ( ( result = pattern.exec( data ) ) != null ) { |
89 | 96 |
|
90 |
| - while ( ( result = pattern.exec( data ) ) != null ) { |
| 97 | + // ["4 1 2 3 4", "1", "2", "3", "4"] |
91 | 98 |
|
92 |
| - // ["4 1 2 3 4", "1", "2", "3", "4"] |
| 99 | + face4( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ), parseInt( result[ 4 ] ) ); |
93 | 100 |
|
94 |
| - face4( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ), parseInt( result[ 4 ] ) ); |
| 101 | + } |
95 | 102 |
|
96 |
| - } |
| 103 | + geometry.computeCentroids(); |
| 104 | + geometry.computeFaceNormals(); |
| 105 | + geometry.computeVertexNormals(); |
| 106 | + geometry.computeBoundingSphere(); |
97 | 107 |
|
98 |
| - geometry.computeCentroids(); |
99 |
| - geometry.computeFaceNormals(); |
100 |
| - geometry.computeVertexNormals(); |
101 |
| - geometry.computeBoundingSphere(); |
| 108 | + return geometry; |
102 | 109 |
|
103 |
| - return geometry; |
| 110 | + } |
104 | 111 |
|
105 | 112 | }
|
0 commit comments