@@ -546,15 +546,15 @@ function extrusion(args) {
546546 args . axis = ( args . axis === undefined ) ? null : args . axis
547547 args . up = ( args . up === undefined ) ? vec ( 0 , 1 , 0 ) : args . up . norm ( )
548548 let first_segment = ( args . path [ 1 ] . sub ( args . path [ 0 ] ) ) . norm ( )
549- if ( first_segment . cross ( args . up ) . mag < 0.1 ) { // construct args.up to be perpendicular to first_segment
550- if ( args . up . cross ( vec ( 0 , 1 , 0 ) ) . mag > 0.2 ) { // try making args.up be vec(0,1,0)
551- args . up = vec ( 0 , 1 , 0 )
552- } else if ( args . up . cross ( vec ( 1 , 0 , 0 ) ) . mag > 0.2 ) { // try making args.up be vec(1,0,0)
553- args . up = vec ( 1 , 0 , 0 )
554- } else if ( args . up . cross ( vec ( 0 , 0 , 1 ) ) . mag > 0.2 ) { // try making args.up be vec(0,0,1)
555- args . up = vec ( 0 , 0 , 1 )
556- }
557- }
549+ // if (first_segment.cross(args.up).mag < 0.1) { // construct args.up to be perpendicular to first_segment
550+ // if (args.up.cross(vec(0,1,0)).mag > 0.2) { // try making args.up be vec(0,1,0)
551+ // args.up = vec(0,1,0)
552+ // } else if (args.up.cross(vec(1,0,0)).mag > 0.2) { // try making args.up be vec(1,0,0)
553+ // args.up = vec(1,0,0)
554+ // } else if (args.up.cross(vec(0,0,1)).mag > 0.2) { // try making args.up be vec(0,0,1)
555+ // args.up = vec(0,0,1)
556+ // }
557+ // }
558558
559559 args . color = ( args . color === undefined ) ? color . white : args . color
560560 args . twist = ( args . twist === undefined ) ? 0 : args . twist
@@ -693,11 +693,23 @@ function extrusion(args) {
693693 if ( L < 2 ) throw new Error ( 'An extrusion path must contain more than one distinct point.' )
694694 let start_normal , end_normal , theta , A , extraA , axis , x , y , z
695695
696- // Deal with normals to the end caps:
697696 if ( ! path_closed ) {
697+ // Adjust x, y, and z (z goes from one point to the next point)
698+ // x, y, z are the vectors in a left-handed xyz set; x and y are unit vectors.
698699 z = p [ 1 ] . sub ( p [ 0 ] ) // points inward
699- y = norm ( args . up )
700- x = norm ( z . cross ( y ) )
700+ let da = diff_angle ( z , args . up )
701+ if ( da == 0 ) {
702+ x = vec ( 1 , 0 , 0 )
703+ y = vec ( 0 , 0 , 1 )
704+ } else if ( da == pi ) {
705+ x = vec ( - 1 , 0 , 0 )
706+ y = vec ( 0 , 0 , 1 )
707+ } else {
708+ x = norm ( z . cross ( args . up ) )
709+ y = norm ( x . cross ( z ) )
710+ }
711+
712+ // Deal with normals to the end caps:
701713 start_normal = z
702714 if ( args . start_normal !== null ) start_normal = args . start_normal . multiply ( - 1 ) // points inward
703715 if ( ! norm ( start_normal ) . equals ( norm ( z ) ) ) {
@@ -719,8 +731,8 @@ function extrusion(args) {
719731 }
720732 } else {
721733 z = p [ 0 ] . sub ( p [ L - 1 ] )
722- y = norm ( args . up )
723- x = norm ( z . cross ( y ) )
734+ x = norm ( z . cross ( args . up ) )
735+ y = norm ( x . cross ( z ) )
724736 }
725737
726738 // Analyze the whole path before creating quads.
0 commit comments