@@ -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,12 @@ const { PassTypes } = vtkHardwareSelector;
18
20
const StartEvent = { type : 'StartEvent' } ;
19
21
const EndEvent = { type : 'EndEvent' } ;
20
22
23
+ function applyShiftScaleToMat ( mat , shift , scale ) {
24
+ mat [ 12 ] = ( mat [ 12 ] - shift [ 0 ] ) * scale [ 0 ] ;
25
+ mat [ 13 ] = ( mat [ 13 ] - shift [ 1 ] ) * scale [ 1 ] ;
26
+ mat [ 14 ] = ( mat [ 14 ] - shift [ 2 ] ) * scale [ 2 ] ;
27
+ }
28
+
21
29
// ----------------------------------------------------------------------------
22
30
// vtkOpenGLSphereMapper methods
23
31
// ----------------------------------------------------------------------------
@@ -630,9 +638,14 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
630
638
} ;
631
639
632
640
publicAPI . buildBufferObjects = ( ren , actor ) => {
641
+ const garray = model . renderable . getMatrixArray ( ) ;
642
+
643
+ const pts = model . renderable . getInputData ( 0 ) . getPoints ( ) ;
644
+ const { useShiftAndScale, coordShift, coordScale } =
645
+ computeCoordShiftAndScale ( pts ) ;
646
+
633
647
if ( model . hardwareSupport ) {
634
648
// update the buffer objects if needed
635
- const garray = model . renderable . getMatrixArray ( ) ;
636
649
const narray = model . renderable . getNormalArray ( ) ;
637
650
const carray = model . renderable . getColorArray ( ) ;
638
651
if ( ! model . matrixBuffer ) {
@@ -645,6 +658,15 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
645
658
model . pickBuffer = vtkBufferObject . newInstance ( ) ;
646
659
model . pickBuffer . setOpenGLRenderWindow ( model . _openGLRenderWindow ) ;
647
660
}
661
+
662
+ if ( useShiftAndScale ) {
663
+ const buf = garray . buffer ;
664
+ for ( let ptIdx = 0 ; ptIdx < garray . byteLength ; ptIdx += 64 ) {
665
+ const mat = new Float32Array ( buf , ptIdx , 16 ) ;
666
+ applyShiftScaleToMat ( mat , coordShift , coordScale ) ;
667
+ }
668
+ }
669
+
648
670
if (
649
671
model . renderable . getBuildTime ( ) . getMTime ( ) >
650
672
model . glyphBOBuildTime . getMTime ( )
@@ -674,7 +696,18 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
674
696
model . glyphBOBuildTime . modified ( ) ;
675
697
}
676
698
}
677
- return superClass . buildBufferObjects ( ren , actor ) ;
699
+
700
+ superClass . buildBufferObjects ( ren , actor ) ;
701
+
702
+ // apply shift + scale to primitives AFTER vtkOpenGLPolyDataMapper.buildBufferObjects
703
+ // so that the Glyph3DMapper gets the last say in the shift + scale
704
+ if ( useShiftAndScale ) {
705
+ for ( let i = primTypes . Start ; i < primTypes . End ; i ++ ) {
706
+ model . primitives [ i ]
707
+ . getCABO ( )
708
+ . setCoordShiftAndScale ( coordShift , coordScale ) ;
709
+ }
710
+ }
678
711
} ;
679
712
}
680
713
0 commit comments