Skip to content

Commit 378955e

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

File tree

1 file changed

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

1 file changed

+35
-2
lines changed

Sources/Rendering/OpenGL/Glyph3DMapper/index.js

Lines changed: 35 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,12 @@ const { PassTypes } = vtkHardwareSelector;
1820
const StartEvent = { type: 'StartEvent' };
1921
const EndEvent = { type: 'EndEvent' };
2022

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+
2129
// ----------------------------------------------------------------------------
2230
// vtkOpenGLSphereMapper methods
2331
// ----------------------------------------------------------------------------
@@ -630,9 +638,14 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
630638
};
631639

632640
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+
633647
if (model.hardwareSupport) {
634648
// update the buffer objects if needed
635-
const garray = model.renderable.getMatrixArray();
636649
const narray = model.renderable.getNormalArray();
637650
const carray = model.renderable.getColorArray();
638651
if (!model.matrixBuffer) {
@@ -645,6 +658,15 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
645658
model.pickBuffer = vtkBufferObject.newInstance();
646659
model.pickBuffer.setOpenGLRenderWindow(model._openGLRenderWindow);
647660
}
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+
648670
if (
649671
model.renderable.getBuildTime().getMTime() >
650672
model.glyphBOBuildTime.getMTime()
@@ -674,7 +696,18 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
674696
model.glyphBOBuildTime.modified();
675697
}
676698
}
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+
}
678711
};
679712
}
680713

0 commit comments

Comments
 (0)