@@ -67,6 +67,8 @@ function vtkLineGlyphRepresentation(publicAPI, model) {
67
67
source : publicAPI ,
68
68
glyph : vtkCylinderSource . newInstance ( {
69
69
direction : [ 1 , 0 , 0 ] ,
70
+ center : [ 0.5 , 0 , 0 ] ,
71
+ capping : false ,
70
72
} ) ,
71
73
mapper : vtkGlyph3DMapper . newInstance ( {
72
74
orientationArray : 'directions' ,
@@ -94,48 +96,47 @@ function vtkLineGlyphRepresentation(publicAPI, model) {
94
96
allocateSize ( internalPolyData , pointCount , model . close && pointCount > 2 ) ;
95
97
96
98
const glyphPositions = internalPolyData . getPoints ( ) . getData ( ) ;
97
- const lines = internalPolyData . getLines ( ) . getData ( ) ;
99
+ // There can be only one line.
100
+ const segments = internalPolyData . getLines ( ) . getData ( ) ;
98
101
99
102
const directions = allocateArray (
100
103
internalPolyData ,
101
104
'directions' ,
102
- lines . length - 1 ,
105
+ segments . length - 1 ,
103
106
undefined ,
104
107
3
105
108
) . getData ( ) ;
106
109
const lengths = allocateArray (
107
110
internalPolyData ,
108
111
'lengths' ,
109
- lines . length - 1 ,
112
+ segments . length - 1 ,
110
113
undefined ,
111
114
3
112
115
) . getData ( ) ;
113
116
114
- const pos = [ ] ; // scratch
115
- for ( let point = 1 ; point < lines . length - 1 ; point ++ ) {
117
+ const tempVector = [ ] ; // scratch
118
+ for ( let point = 1 ; point < segments . length - 1 ; point ++ ) {
119
+ const glyph = ( point - 1 ) * 3 ; // start of glyph's 3 components in the arrays
120
+
121
+ // With cylinder glyph's offset center, position at state origins.
122
+ const origin = points [ segments [ point ] ] ;
123
+ [
124
+ glyphPositions [ glyph ] ,
125
+ glyphPositions [ glyph + 1 ] ,
126
+ glyphPositions [ glyph + 2 ] ,
127
+ ] = origin ;
128
+
116
129
// Orient glyphs to next point.
117
- const eye = points [ lines [ point ] ] ;
118
- const target = points [ lines [ point + 1 ] ] ;
119
- const direction = vtkMath . subtract ( target , eye , pos ) ;
120
- const glyph = ( point - 1 ) * 3 ;
130
+ const target = points [ segments [ point + 1 ] ] ;
131
+ const direction = vtkMath . subtract ( target , origin , tempVector ) ;
121
132
[ directions [ glyph ] , directions [ glyph + 1 ] , directions [ glyph + 2 ] ] =
122
133
direction ;
123
134
124
- // scale to span between points
135
+ // Scale to span between points.
125
136
const distance = vec3 . length ( direction ) ;
126
137
lengths [ glyph ] = distance ;
127
138
lengths [ glyph + 1 ] = 1 ;
128
139
lengths [ glyph + 2 ] = 1 ;
129
-
130
- // Position glyph at center of line segment.
131
- vec3 . normalize ( pos , direction ) ;
132
- vec3 . scale ( pos , pos , distance / 2 ) ;
133
- vec3 . add ( pos , eye , direction ) ;
134
- [
135
- glyphPositions [ glyph ] ,
136
- glyphPositions [ glyph + 1 ] ,
137
- glyphPositions [ glyph + 2 ] ,
138
- ] = pos ;
139
140
}
140
141
141
142
internalPolyData . getPoints ( ) . modified ( ) ;
0 commit comments