Skip to content

Commit d6f7e10

Browse files
committed
fix(CylinderSource): generate correct normals for directed cylinders
This fixes incorrect normals for capped or directed cylinders
1 parent dfbee4c commit d6f7e10

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • Sources/Filters/Sources/CylinderSource

Sources/Filters/Sources/CylinderSource/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ function vtkCylinderSource(publicAPI, model) {
6565
// y coordinate
6666
xbot[1] = 0.5 * model.height + model.center[1];
6767
xtop[1] = -0.5 * model.height + model.center[1];
68+
nbot[1] = 0.0;
69+
ntop[1] = 0.0;
6870
tcbot[1] = 0.0;
6971
tctop[1] = 1.0;
7072

@@ -100,6 +102,13 @@ function vtkCylinderSource(publicAPI, model) {
100102
if (model.capping) {
101103
// Generate points for top/bottom polygons
102104
for (let i = 0; i < model.resolution; i++) {
105+
nbot[0] = 0.0;
106+
nbot[1] = 1.0;
107+
nbot[2] = 0.0;
108+
ntop[0] = 0.0;
109+
ntop[1] = -1.0;
110+
ntop[2] = 0.0;
111+
103112
// x coordinate
104113
xbot[0] = model.radius * Math.cos(i * angle + model.initAngle);
105114
xtop[0] = xbot[0];
@@ -109,8 +118,6 @@ function vtkCylinderSource(publicAPI, model) {
109118
xtop[0] += model.center[0];
110119

111120
// y coordinate
112-
nbot[1] = 1.0;
113-
ntop[1] = -1.0;
114121
xbot[1] = 0.5 * model.height + model.center[1];
115122
xtop[1] = -0.5 * model.height + model.center[1];
116123

@@ -154,6 +161,11 @@ function vtkCylinderSource(publicAPI, model) {
154161
.translate(...model.center.map((c) => c * -1))
155162
.apply(points);
156163

164+
vtkMatrixBuilder
165+
.buildFromRadian()
166+
.rotateFromDirections([0, 1, 0], model.direction)
167+
.apply(normalsData);
168+
157169
const dataset = outData[0]?.initialize() || vtkPolyData.newInstance();
158170
dataset.getPoints().setData(points, 3);
159171
dataset.getPolys().setData(polys, 1);

0 commit comments

Comments
 (0)