@@ -7,8 +7,10 @@ import vtkHardwareSelector from 'vtk.js/Sources/Rendering/OpenGL/HardwareSelecto
7
7
import vtkProperty from 'vtk.js/Sources/Rendering/Core/Property' ;
8
8
import vtkOpenGLPolyDataMapper from 'vtk.js/Sources/Rendering/OpenGL/PolyDataMapper' ;
9
9
import vtkShaderProgram from 'vtk.js/Sources/Rendering/OpenGL/ShaderProgram' ;
10
+ import { computeCoordShiftAndScale } from 'vtk.js/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers' ;
10
11
11
12
import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactory' ;
13
+ import { primTypes } from '../Helper' ;
12
14
13
15
const { vtkErrorMacro } = macro ;
14
16
const { Representation } = vtkProperty ;
@@ -18,6 +20,16 @@ const { PassTypes } = vtkHardwareSelector;
18
20
const StartEvent = { type : 'StartEvent' } ;
19
21
const EndEvent = { type : 'EndEvent' } ;
20
22
23
+ const MAT4_BYTE_SIZE = 64 ;
24
+ const MAT4_ELEMENT_COUNT = 16 ;
25
+
26
+ function applyShiftScaleToMat ( mat , shift , scale ) {
27
+ // the translation component of a 4x4 column-major matrix
28
+ mat [ 12 ] = ( mat [ 12 ] - shift [ 0 ] ) * scale [ 0 ] ;
29
+ mat [ 13 ] = ( mat [ 13 ] - shift [ 1 ] ) * scale [ 1 ] ;
30
+ mat [ 14 ] = ( mat [ 14 ] - shift [ 2 ] ) * scale [ 2 ] ;
31
+ }
32
+
21
33
// ----------------------------------------------------------------------------
22
34
// vtkOpenGLSphereMapper methods
23
35
// ----------------------------------------------------------------------------
@@ -630,9 +642,14 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
630
642
} ;
631
643
632
644
publicAPI . buildBufferObjects = ( ren , actor ) => {
645
+ const garray = model . renderable . getMatrixArray ( ) ;
646
+
647
+ const pts = model . renderable . getInputData ( 0 ) . getPoints ( ) ;
648
+ const { useShiftAndScale, coordShift, coordScale } =
649
+ computeCoordShiftAndScale ( pts ) ;
650
+
633
651
if ( model . hardwareSupport ) {
634
652
// update the buffer objects if needed
635
- const garray = model . renderable . getMatrixArray ( ) ;
636
653
const narray = model . renderable . getNormalArray ( ) ;
637
654
const carray = model . renderable . getColorArray ( ) ;
638
655
if ( ! model . matrixBuffer ) {
@@ -645,6 +662,19 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
645
662
model . pickBuffer = vtkBufferObject . newInstance ( ) ;
646
663
model . pickBuffer . setOpenGLRenderWindow ( model . _openGLRenderWindow ) ;
647
664
}
665
+
666
+ if ( useShiftAndScale ) {
667
+ const buf = garray . buffer ;
668
+ for (
669
+ let ptIdx = 0 ;
670
+ ptIdx < garray . byteLength ;
671
+ ptIdx += MAT4_BYTE_SIZE
672
+ ) {
673
+ const mat = new Float32Array ( buf , ptIdx , MAT4_ELEMENT_COUNT ) ;
674
+ applyShiftScaleToMat ( mat , coordShift , coordScale ) ;
675
+ }
676
+ }
677
+
648
678
if (
649
679
model . renderable . getBuildTime ( ) . getMTime ( ) >
650
680
model . glyphBOBuildTime . getMTime ( )
@@ -674,7 +704,18 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
674
704
model . glyphBOBuildTime . modified ( ) ;
675
705
}
676
706
}
677
- return superClass . buildBufferObjects ( ren , actor ) ;
707
+
708
+ superClass . buildBufferObjects ( ren , actor ) ;
709
+
710
+ // apply shift + scale to primitives AFTER vtkOpenGLPolyDataMapper.buildBufferObjects
711
+ // so that the Glyph3DMapper gets the last say in the shift + scale
712
+ if ( useShiftAndScale ) {
713
+ for ( let i = primTypes . Start ; i < primTypes . End ; i ++ ) {
714
+ model . primitives [ i ]
715
+ . getCABO ( )
716
+ . setCoordShiftAndScale ( coordShift , coordScale ) ;
717
+ }
718
+ }
678
719
} ;
679
720
}
680
721
0 commit comments