Skip to content

Commit e11d41b

Browse files
committed
fix(Glyph3DMapper): shift+scale for large coords
1 parent 06b05f9 commit e11d41b

File tree

1 file changed

+43
-2
lines changed
  • Sources/Rendering/OpenGL/Glyph3DMapper

1 file changed

+43
-2
lines changed

Sources/Rendering/OpenGL/Glyph3DMapper/index.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import vtkHardwareSelector from 'vtk.js/Sources/Rendering/OpenGL/HardwareSelecto
77
import vtkProperty from 'vtk.js/Sources/Rendering/Core/Property';
88
import vtkOpenGLPolyDataMapper from 'vtk.js/Sources/Rendering/OpenGL/PolyDataMapper';
99
import vtkShaderProgram from 'vtk.js/Sources/Rendering/OpenGL/ShaderProgram';
10+
import { computeCoordShiftAndScale } from 'vtk.js/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers';
1011

1112
import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactory';
13+
import { primTypes } from '../Helper';
1214

1315
const { vtkErrorMacro } = macro;
1416
const { Representation } = vtkProperty;
@@ -18,6 +20,16 @@ const { PassTypes } = vtkHardwareSelector;
1820
const StartEvent = { type: 'StartEvent' };
1921
const EndEvent = { type: 'EndEvent' };
2022

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+
2133
// ----------------------------------------------------------------------------
2234
// vtkOpenGLSphereMapper methods
2335
// ----------------------------------------------------------------------------
@@ -630,9 +642,14 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
630642
};
631643

632644
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+
633651
if (model.hardwareSupport) {
634652
// update the buffer objects if needed
635-
const garray = model.renderable.getMatrixArray();
636653
const narray = model.renderable.getNormalArray();
637654
const carray = model.renderable.getColorArray();
638655
if (!model.matrixBuffer) {
@@ -645,6 +662,19 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
645662
model.pickBuffer = vtkBufferObject.newInstance();
646663
model.pickBuffer.setOpenGLRenderWindow(model._openGLRenderWindow);
647664
}
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+
648678
if (
649679
model.renderable.getBuildTime().getMTime() >
650680
model.glyphBOBuildTime.getMTime()
@@ -674,7 +704,18 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
674704
model.glyphBOBuildTime.modified();
675705
}
676706
}
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+
}
678719
};
679720
}
680721

0 commit comments

Comments
 (0)