@@ -250,77 +250,51 @@ Object.assign( THREE.VTKLoader.prototype, THREE.EventDispatcher.prototype, {
250250
251251 }
252252
253- var geometry ;
254- var stagger = 'point' ;
253+ var geometry = new THREE . BufferGeometry ( ) ;
254+ geometry . setIndex ( indices ) ;
255+ geometry . addAttribute ( 'position' , new THREE . Float32BufferAttribute ( positions , 3 ) ) ;
255256
256- if ( colors . length === indices . length ) {
257+ if ( normals . length === positions . length ) {
257258
258- stagger = 'cell' ;
259+ geometry . addAttribute ( 'normal' , new THREE . Float32BufferAttribute ( normals , 3 ) ) ;
259260
260261 }
261262
262- if ( stagger === 'point' ) {
263+ if ( colors . length !== indices . length ) {
263264
264- // Nodal. Use BufferGeometry
265- geometry = new THREE . BufferGeometry ( ) ;
266- geometry . setIndex ( new THREE . BufferAttribute ( new Uint32Array ( indices ) , 1 ) ) ;
267- geometry . addAttribute ( 'position' , new THREE . BufferAttribute ( new Float32Array ( positions ) , 3 ) ) ;
265+ // stagger
268266
269267 if ( colors . length === positions . length ) {
270268
271- geometry . addAttribute ( 'color' , new THREE . BufferAttribute ( new Float32Array ( colors ) , 3 ) ) ;
272-
273- }
274-
275- if ( normals . length === positions . length ) {
276-
277- geometry . addAttribute ( 'normal' , new THREE . BufferAttribute ( new Float32Array ( normals ) , 3 ) ) ;
269+ geometry . addAttribute ( 'color' , new THREE . Float32BufferAttribute ( colors , 3 ) ) ;
278270
279271 }
280272
281273 } else {
282274
283- // Cell centered colors. The only way to attach a solid color to each triangle
284- // is to use Geometry, which is less efficient than BufferGeometry
285- geometry = new THREE . Geometry ( ) ;
286-
287- var numTriangles = indices . length / 3 ;
288- var numPoints = positions . length / 3 ;
289- var face ;
290- var ia , ib , ic ;
291- var x , y , z ;
292- var r , g , b ;
275+ // cell
293276
294- for ( var j = 0 ; j < numPoints ; ++ j ) {
277+ geometry = geometry . toNonIndexed ( ) ;
278+ var numTriangles = geometry . attributes . position . count / 3 ;
295279
296- x = positions [ 3 * j + 0 ] ;
297- y = positions [ 3 * j + 1 ] ;
298- z = positions [ 3 * j + 2 ] ;
299- geometry . vertices . push ( new THREE . Vector3 ( x , y , z ) ) ;
280+ if ( colors . length === ( numTriangles * 3 ) ) {
300281
301- }
302-
303- for ( var i = 0 ; i < numTriangles ; ++ i ) {
304-
305- ia = indices [ 3 * i + 0 ] ;
306- ib = indices [ 3 * i + 1 ] ;
307- ic = indices [ 3 * i + 2 ] ;
308- geometry . faces . push ( new THREE . Face3 ( ia , ib , ic ) ) ;
282+ var newColors = [ ] ;
309283
310- }
311-
312- if ( colors . length === numTriangles * 3 ) {
284+ for ( var i = 0 ; i < numTriangles ; i ++ ) {
313285
314- for ( var i = 0 ; i < numTriangles ; ++ i ) {
286+ var r = colors [ 3 * i + 0 ] ;
287+ var g = colors [ 3 * i + 1 ] ;
288+ var b = colors [ 3 * i + 2 ] ;
315289
316- face = geometry . faces [ i ] ;
317- r = colors [ 3 * i + 0 ] ;
318- g = colors [ 3 * i + 1 ] ;
319- b = colors [ 3 * i + 2 ] ;
320- face . color = new THREE . Color ( ) . setRGB ( r , g , b ) ;
290+ newColors . push ( r , g , b ) ;
291+ newColors . push ( r , g , b ) ;
292+ newColors . push ( r , g , b ) ;
321293
322294 }
323295
296+ geometry . addAttribute ( 'color' , new THREE . Float32BufferAttribute ( newColors , 3 ) ) ;
297+
324298 }
325299
326300 }
0 commit comments