@@ -588,23 +588,58 @@ define(["jupyter-js-widgets", "underscore", "three"],
588588 } ,
589589 } ) ;
590590
591+
591592
592593 var PlainGeometryView = ThreeView . extend ( {
593594 update : function ( ) {
594595 var geometry = new THREE . Geometry ( ) ;
595596 var vertices = this . model . get ( 'vertices' ) ;
596597 var faces = this . model . get ( 'faces' ) ;
597598 var colors = this . model . get ( 'colors' ) ;
599+ var faceColors = this . model . get ( 'faceColors' ) ;
600+ var faceNormals = this . model . get ( 'faceNormals' ) ;
598601 var faceVertexUvs = this . model . get ( 'faceVertexUvs' )
599602
603+ if ( faceNormals . length === 0 ) {
604+ faceNormals = void 0 ;
605+ }
606+ if ( faceColors . length === 0 ) {
607+ faceColors = void 0 ;
608+ }
609+
610+ var toVec = function ( a ) {
611+ return new THREE . Vector3 ( a [ 0 ] , a [ 1 ] , a [ 2 ] ) ;
612+ }
613+ var toColor = function ( a ) {
614+ return new THREE . Color ( a ) ;
615+ }
616+
600617 var i , len ;
601618 var f ;
619+ var face ;
602620 for ( i = 0 , len = vertices . length ; i < len ; i += 1 ) {
603- geometry . vertices . push ( ( new THREE . Vector3 ( ) ) . fromArray ( vertices [ i ] ) ) ;
621+ geometry . vertices . push ( toVec ( vertices [ i ] ) ) ;
604622 }
605623 for ( i = 0 , len = faces . length ; i < len ; i += 1 ) {
606624 f = faces [ i ] ;
607- geometry . faces . push ( new THREE . Face3 ( f [ 0 ] , f [ 1 ] , f [ 2 ] ) ) ;
625+ normal = faceNormals && faceNormals [ i ] ;
626+ color = faceColors && faceColors [ i ] ;
627+ if ( normal ) {
628+ if ( Array . isArray ( normal [ 0 ] ) ) {
629+ normal = normal . map ( toVec ) ;
630+ } else {
631+ normal = toVec ( normal ) ;
632+ }
633+ }
634+ if ( color ) {
635+ if ( Array . isArray ( color ) ) {
636+ color = color . map ( toColor ) ;
637+ } else {
638+ color = toColor ( color ) ;
639+ }
640+ }
641+ face = new THREE . Face3 ( f [ 0 ] , f [ 1 ] , f [ 2 ] , normal , color ) ;
642+ geometry . faces . push ( face ) ;
608643 }
609644 for ( i = 0 , len = colors . length ; i < len ; i += 1 ) {
610645 geometry . colors . push ( new THREE . Color ( colors [ i ] ) ) ;
@@ -1629,7 +1664,9 @@ define(["jupyter-js-widgets", "underscore", "three"],
16291664
16301665 vertices : [ ] ,
16311666 colors : [ ] ,
1632- faces : [ ]
1667+ faces : [ ] ,
1668+ faceColors : [ ] ,
1669+ faceNormals : [ ]
16331670 // todo: faceVertexUvs
16341671 } )
16351672 } ) ;
0 commit comments