@@ -726,56 +726,62 @@ impl ActiveTrail {
726
726
// scale it trail scale
727
727
let horizontal_offset = horizontal_offset * attrs. get_trail_scale ( ) . copied ( ) . unwrap_or ( 1.0 ) ;
728
728
let height = horizontal_offset * 2.0 ;
729
- let mut y_offset = 1.0 ;
729
+
730
730
let mut vertices = vec ! [ ] ;
731
- for two_positions in positions. windows ( 2 ) {
732
- let first = two_positions[ 0 ] ;
733
- let second = two_positions[ 1 ] ;
734
- // right side of the vector from first to second
735
- let right_side = ( second - first) . normalize ( ) . cross ( Vec3 :: Y ) . normalize ( ) ;
731
+ // trail mesh is split by separating different parts with a [0, 0, 0]
732
+ // we will call each separate trail mesh as a "strip" of trail.
733
+ // each strip should *almost* act as an independent trail, but they all are drawn at the same time with the same parameters.
734
+ for strip in positions. split ( |& v| v == Vec3 :: ZERO ) {
735
+ let mut y_offset = 1.0 ;
736
+ for two_positions in strip. windows ( 2 ) {
737
+ let first = two_positions[ 0 ] ;
738
+ let second = two_positions[ 1 ] ;
739
+ // right side of the vector from first to second
740
+ let right_side = ( second - first) . normalize ( ) . cross ( Vec3 :: Y ) . normalize ( ) ;
736
741
737
- let new_offset = ( -1.0 * ( first. distance ( second) / height) ) + y_offset;
738
- let first_left = MarkerVertex {
739
- position : first - ( right_side * horizontal_offset) ,
740
- texture_coordinates : vec2 ( 0.0 , y_offset) ,
741
- alpha,
742
- color,
743
- fade_near_far,
744
- } ;
745
- let first_right = MarkerVertex {
746
- position : first + ( right_side * horizontal_offset) ,
747
- texture_coordinates : vec2 ( 1.0 , y_offset) ,
748
- alpha,
749
- color,
750
- fade_near_far,
751
- } ;
752
- let second_left = MarkerVertex {
753
- position : second - ( right_side * horizontal_offset) ,
754
- texture_coordinates : vec2 ( 0.0 , new_offset) ,
755
- alpha,
756
- color,
757
- fade_near_far,
758
- } ;
759
- let second_right = MarkerVertex {
760
- position : second + ( right_side * horizontal_offset) ,
761
- texture_coordinates : vec2 ( 1.0 , new_offset) ,
762
- alpha,
763
- color,
764
- fade_near_far,
765
- } ;
766
- y_offset = if new_offset. is_sign_positive ( ) {
767
- new_offset
768
- } else {
769
- 1.0 - new_offset. fract ( ) . abs ( )
770
- } ;
771
- vertices. extend ( [
772
- second_left,
773
- first_left,
774
- first_right,
775
- first_right,
776
- second_right,
777
- second_left,
778
- ] ) ;
742
+ let new_offset = ( -1.0 * ( first. distance ( second) / height) ) + y_offset;
743
+ let first_left = MarkerVertex {
744
+ position : first - ( right_side * horizontal_offset) ,
745
+ texture_coordinates : vec2 ( 0.0 , y_offset) ,
746
+ alpha,
747
+ color,
748
+ fade_near_far,
749
+ } ;
750
+ let first_right = MarkerVertex {
751
+ position : first + ( right_side * horizontal_offset) ,
752
+ texture_coordinates : vec2 ( 1.0 , y_offset) ,
753
+ alpha,
754
+ color,
755
+ fade_near_far,
756
+ } ;
757
+ let second_left = MarkerVertex {
758
+ position : second - ( right_side * horizontal_offset) ,
759
+ texture_coordinates : vec2 ( 0.0 , new_offset) ,
760
+ alpha,
761
+ color,
762
+ fade_near_far,
763
+ } ;
764
+ let second_right = MarkerVertex {
765
+ position : second + ( right_side * horizontal_offset) ,
766
+ texture_coordinates : vec2 ( 1.0 , new_offset) ,
767
+ alpha,
768
+ color,
769
+ fade_near_far,
770
+ } ;
771
+ y_offset = if new_offset. is_sign_positive ( ) {
772
+ new_offset
773
+ } else {
774
+ 1.0 - new_offset. fract ( ) . abs ( )
775
+ } ;
776
+ vertices. extend ( [
777
+ second_left,
778
+ first_left,
779
+ first_right,
780
+ first_right,
781
+ second_right,
782
+ second_left,
783
+ ] ) ;
784
+ }
779
785
}
780
786
781
787
Some ( ActiveTrail {
0 commit comments