@@ -28,12 +28,15 @@ function SurfaceTrace(scene, surface, uid) {
2828 this . surface = surface ;
2929 this . data = null ;
3030 this . showContour = [ false , false , false ] ;
31+ this . contourStart = [ null , null , null ] ;
32+ this . contourEnd = [ null , null , null ] ;
33+ this . contourSize = [ 0 , 0 , 0 ] ;
3134 this . minValues = [ Infinity , Infinity , Infinity ] ;
3235 this . maxValues = [ - Infinity , - Infinity , - Infinity ] ;
3336 this . dataScaleX = 1.0 ;
3437 this . dataScaleY = 1.0 ;
3538 this . refineData = true ;
36- this . _interpolatedZ = false ;
39+ this . objectOffset = [ 0 , 0 , 0 ] ;
3740}
3841
3942var proto = SurfaceTrace . prototype ;
@@ -346,19 +349,54 @@ proto.refineCoords = function(coords) {
346349 }
347350} ;
348351
352+ function insertIfNewLevel ( arr , newValue ) {
353+ var found = false ;
354+ for ( var k = 0 ; k < arr . length ; k ++ ) {
355+ if ( newValue === arr [ k ] ) {
356+ found = true ;
357+ break ;
358+ }
359+ }
360+ if ( found === false ) arr . push ( newValue ) ;
361+ }
362+
349363proto . setContourLevels = function ( ) {
350- var nlevels = [ [ ] , [ ] , [ ] ] ;
364+ var newLevels = [ [ ] , [ ] , [ ] ] ;
365+ var useNewLevels = [ false , false , false ] ;
351366 var needsUpdate = false ;
352367
353- for ( var i = 0 ; i < 3 ; ++ i ) {
368+ var i , j , value ;
369+
370+ for ( i = 0 ; i < 3 ; ++ i ) {
354371 if ( this . showContour [ i ] ) {
355372 needsUpdate = true ;
356- nlevels [ i ] = this . scene . contourLevels [ i ] ;
373+
374+ if (
375+ this . contourSize [ i ] > 0 &&
376+ this . contourStart [ i ] !== null &&
377+ this . contourEnd [ i ] !== null &&
378+ this . contourEnd [ i ] > this . contourStart [ i ]
379+ ) {
380+ useNewLevels [ i ] = true ;
381+
382+ for ( j = this . contourStart [ i ] ; j < this . contourEnd [ i ] ; j += this . contourSize [ i ] ) {
383+ value = j * this . scene . dataScale [ i ] ;
384+
385+ insertIfNewLevel ( newLevels [ i ] , value ) ;
386+ }
387+ }
388+
357389 }
358390 }
359391
360392 if ( needsUpdate ) {
361- this . surface . update ( { levels : nlevels } ) ;
393+ var allLevels = [ [ ] , [ ] , [ ] ] ;
394+ for ( i = 0 ; i < 3 ; ++ i ) {
395+ if ( this . showContour [ i ] ) {
396+ allLevels [ i ] = useNewLevels [ i ] ? newLevels [ i ] : this . scene . contourLevels [ i ] ;
397+ }
398+ }
399+ this . surface . update ( { levels : allLevels } ) ;
362400 }
363401} ;
364402
@@ -453,15 +491,15 @@ proto.update = function(data) {
453491 }
454492
455493 for ( i = 0 ; i < 3 ; i ++ ) {
456- data . _objectOffset [ i ] = 0.5 * ( this . minValues [ i ] + this . maxValues [ i ] ) ;
494+ this . objectOffset [ i ] = 0.5 * ( this . minValues [ i ] + this . maxValues [ i ] ) ;
457495 }
458496
459497 for ( i = 0 ; i < 3 ; i ++ ) {
460498 for ( j = 0 ; j < xlen ; j ++ ) {
461499 for ( k = 0 ; k < ylen ; k ++ ) {
462500 v = rawCoords [ i ] [ j ] [ k ] ;
463501 if ( v !== null && v !== undefined ) {
464- rawCoords [ i ] [ j ] [ k ] -= data . _objectOffset [ i ] ;
502+ rawCoords [ i ] [ j ] [ k ] -= this . objectOffset [ i ] ;
465503 }
466504 }
467505 }
@@ -561,8 +599,16 @@ proto.update = function(data) {
561599 surface . highlightTint [ i ] = params . contourTint [ i ] = 1 ;
562600 }
563601 params . contourWidth [ i ] = contourParams . width ;
602+
603+ this . contourStart [ i ] = contourParams . start ;
604+ this . contourEnd [ i ] = contourParams . end ;
605+ this . contourSize [ i ] = contourParams . size ;
564606 } else {
565607 this . showContour [ i ] = false ;
608+
609+ this . contourStart [ i ] = null ;
610+ this . contourEnd [ i ] = null ;
611+ this . contourSize [ i ] = 0 ;
566612 }
567613
568614 if ( contourParams . highlight ) {
@@ -576,11 +622,7 @@ proto.update = function(data) {
576622 params . vertexColor = true ;
577623 }
578624
579- params . objectOffset = [
580- data . _objectOffset [ 0 ] ,
581- data . _objectOffset [ 1 ] ,
582- data . _objectOffset [ 2 ]
583- ] ;
625+ params . objectOffset = this . objectOffset ;
584626
585627 params . coords = coords ;
586628 surface . update ( params ) ;
0 commit comments