11import macro from 'vtk.js/Sources/macro' ;
22import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray' ;
33import 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
910function 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