1
1
import macro from 'vtk.js/Sources/macros' ;
2
2
import { MouseButton } from 'vtk.js/Sources/Rendering/Core/RenderWindowInteractor/Constants' ;
3
3
import vtkInteractorStyle from 'vtk.js/Sources/Rendering/Core/InteractorStyle' ;
4
- import { mat4 , vec3 } from 'gl-matrix' ;
5
4
6
5
const { vtkDebugMacro } = macro ;
7
6
const { States } = vtkInteractorStyle ;
@@ -135,77 +134,6 @@ function dollyByFactor(interactor, renderer, factor) {
135
134
}
136
135
}
137
136
138
- function getCameraMatrix ( renderer , tempMatrix ) {
139
- const cam = renderer . getActiveCamera ( ) ;
140
- if ( cam ) {
141
- mat4 . copy ( tempMatrix , cam . getViewMatrix ( ) ) ;
142
- return tempMatrix ;
143
- }
144
- return null ;
145
- }
146
-
147
- /**
148
- * Transforms a vector by the transformation delta between two matrices.
149
- *
150
- * @param {Object } tempObjects - Temporary matrices/vectors for computation
151
- * @param {mat4 } beforeMatrix - Matrix before transformation
152
- * @param {mat4 } afterMatrix - Matrix after transformation
153
- * @param {Array } vector - Vector to transform [x, y, z]
154
- * @returns {Array } Transformed vector [x, y, z]
155
- */
156
- function transformVectorByTransformation (
157
- tempObjects ,
158
- beforeMatrix ,
159
- afterMatrix ,
160
- vector
161
- ) {
162
- const { matrixA, matrixB, newCenter } = tempObjects ;
163
-
164
- // The view matrix from vtk.js is row-major, but gl-matrix expects column-major.
165
- // We need to transpose them before use.
166
- mat4 . transpose ( matrixA , beforeMatrix ) ;
167
-
168
- mat4 . transpose ( matrixB , afterMatrix ) ;
169
- mat4 . invert ( matrixB , matrixB ) ;
170
-
171
- // Compute delta transformation matrix
172
- mat4 . multiply ( matrixA , matrixB , matrixA ) ;
173
-
174
- vec3 . transformMat4 ( newCenter , vector , matrixA ) ;
175
- return newCenter ;
176
- }
177
-
178
- /**
179
- * Computes the new center of rotation based on camera movement.
180
- * When the camera moves (pan), the center of rotation should move
181
- * by the same transformation to maintain consistent rotation behavior.
182
- *
183
- * @param {Object } tempObjects - Temporary matrices/vectors for computation
184
- * @param {Object } renderer - VTK renderer
185
- * @param {mat4 } beforeCameraMatrix - Camera view matrix before movement
186
- * @param {Array } oldCenterOfRotation - Previous center of rotation [x, y, z]
187
- * @returns {Array } New center of rotation [x, y, z]
188
- */
189
- function computeNewCenterOfRotation (
190
- tempObjects ,
191
- renderer ,
192
- beforeCameraMatrix ,
193
- oldCenterOfRotation
194
- ) {
195
- const cam = renderer . getActiveCamera ( ) ;
196
- if ( ! cam || ! beforeCameraMatrix ) {
197
- return oldCenterOfRotation ;
198
- }
199
- const afterMatrixRowMajor = cam . getViewMatrix ( ) ;
200
-
201
- return transformVectorByTransformation (
202
- tempObjects ,
203
- beforeCameraMatrix ,
204
- afterMatrixRowMajor ,
205
- oldCenterOfRotation
206
- ) ;
207
- }
208
-
209
137
// ----------------------------------------------------------------------------
210
138
// Static API
211
139
// ----------------------------------------------------------------------------
@@ -224,14 +152,6 @@ function vtkInteractorStyleManipulator(publicAPI, model) {
224
152
// Set our className
225
153
model . classHierarchy . push ( 'vtkInteractorStyleManipulator' ) ;
226
154
227
- // Initialize temporary objects to reduce garbage collection
228
- const tempCameraMatrix = mat4 . create ( ) ;
229
- const tempComputeObjects = {
230
- matrixA : mat4 . create ( ) ,
231
- matrixB : mat4 . create ( ) ,
232
- newCenter : vec3 . create ( ) ,
233
- } ;
234
-
235
155
model . currentVRManipulators = new Map ( ) ;
236
156
model . mouseManipulators = [ ] ;
237
157
model . keyboardManipulators = [ ] ;
@@ -584,23 +504,11 @@ function vtkInteractorStyleManipulator(publicAPI, model) {
584
504
publicAPI . handleMouseMove = ( callData ) => {
585
505
model . cachedMousePosition = callData . position ;
586
506
if ( model . currentManipulator && model . currentManipulator . onMouseMove ) {
587
- const renderer = model . getRenderer ( callData ) ;
588
- const beforeCameraMatrix = getCameraMatrix ( renderer , tempCameraMatrix ) ;
589
-
590
507
model . currentManipulator . onMouseMove (
591
508
model . _interactor ,
592
- renderer ,
509
+ model . getRenderer ( callData ) ,
593
510
callData . position
594
511
) ;
595
-
596
- const newCenter = computeNewCenterOfRotation (
597
- tempComputeObjects ,
598
- renderer ,
599
- beforeCameraMatrix ,
600
- model . centerOfRotation
601
- ) ;
602
- publicAPI . setCenterOfRotation ( newCenter ) ;
603
-
604
512
publicAPI . invokeInteractionEvent ( INTERACTION_EVENT ) ;
605
513
}
606
514
} ;
@@ -765,7 +673,6 @@ function vtkInteractorStyleManipulator(publicAPI, model) {
765
673
//----------------------------------------------------------------------------
766
674
publicAPI . handlePan = ( callData ) => {
767
675
const renderer = model . getRenderer ( callData ) ;
768
- const beforeCameraMatrix = getCameraMatrix ( renderer , tempCameraMatrix ) ;
769
676
770
677
let count = model . gestureManipulators . length ;
771
678
let actionCount = 0 ;
@@ -776,15 +683,8 @@ function vtkInteractorStyleManipulator(publicAPI, model) {
776
683
actionCount ++ ;
777
684
}
778
685
}
779
- if ( actionCount ) {
780
- const newCenter = computeNewCenterOfRotation (
781
- tempComputeObjects ,
782
- renderer ,
783
- beforeCameraMatrix ,
784
- model . centerOfRotation
785
- ) ;
786
- publicAPI . setCenterOfRotation ( newCenter ) ;
787
686
687
+ if ( actionCount ) {
788
688
publicAPI . invokeInteractionEvent ( INTERACTION_EVENT ) ;
789
689
}
790
690
} ;
0 commit comments