Skip to content

Commit 12681ad

Browse files
committed
fix(CubeSource): Added rotations to the CubeSource
1 parent 24d832e commit 12681ad

File tree

1 file changed

+19
-2
lines changed
  • Sources/Filters/Sources/CubeSource

1 file changed

+19
-2
lines changed

Sources/Filters/Sources/CubeSource/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import macro from 'vtk.js/Sources/macro';
22
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
33
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
4+
import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder';
45

56
// ----------------------------------------------------------------------------
6-
// vtkConeSource methods
7+
// vtkCubeSource methods
78
// ----------------------------------------------------------------------------
89

910
function vtkCubeSource(publicAPI, model) {
@@ -172,6 +173,21 @@ function vtkCubeSource(publicAPI, model) {
172173
n[2] += 2.0;
173174
}
174175

176+
// Apply rotation to the points coordinates and normals
177+
vtkMatrixBuilder
178+
.buildFromRadian()
179+
.rotateX(model.rotations[0])
180+
.rotateY(model.rotations[1])
181+
.rotateZ(model.rotations[2])
182+
.apply(points)
183+
.apply(normals);
184+
185+
// Apply transformation to the points coordinates
186+
vtkMatrixBuilder
187+
.buildFromRadian()
188+
.translate(...model.center)
189+
.apply(points);
190+
175191
// Define quads
176192
const polys = new window[model.pointType](numberOfPolys * 5);
177193
polyData.getPolys().setData(polys, 1);
@@ -253,6 +269,7 @@ const DEFAULT_VALUES = {
253269
yLength: 1.0,
254270
zLength: 1.0,
255271
center: [0.0, 0.0, 0.0],
272+
rotations: [0.0, 0.0, 0.0],
256273
pointType: 'Float32Array',
257274
generate3DTextureCoordinates: false,
258275
};
@@ -270,7 +287,7 @@ export function extend(publicAPI, model, initialValues = {}) {
270287
'zLength',
271288
'generate3DTextureCoordinates',
272289
]);
273-
macro.setGetArray(publicAPI, model, ['center'], 3);
290+
macro.setGetArray(publicAPI, model, ['center', 'rotations'], 3);
274291

275292
macro.algo(publicAPI, model, 0, 1);
276293
vtkCubeSource(publicAPI, model);

0 commit comments

Comments
 (0)