@kitware/vtk.js 24.0.1 → 24.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Rendering/OpenGL/Glyph3DMapper.js +11 -2
- package/Rendering/OpenGL/HardwareSelector.js +11 -9
- package/Rendering/OpenGL/Helper.js +145 -3
- package/Rendering/OpenGL/OrderIndependentTranslucentPass.js +10 -14
- package/Rendering/OpenGL/PolyDataMapper.js +16 -77
- package/Rendering/OpenGL/PolyDataMapper2D.js +14 -98
- package/Rendering/OpenGL/RenderWindow.js +6 -0
- package/Rendering/OpenGL/Renderer.js +4 -3
- package/Widgets/SVG/SVGLandmarkRepresentation.js +9 -2
- package/Widgets/Widgets3D/AngleWidget/behavior.js +11 -7
- package/Widgets/Widgets3D/DistanceWidget/behavior.js +9 -5
- package/Widgets/Widgets3D/ImageCroppingWidget/behavior.js +5 -5
- package/Widgets/Widgets3D/ImplicitPlaneWidget.js +11 -7
- package/Widgets/Widgets3D/LabelWidget/behavior.js +25 -12
- package/Widgets/Widgets3D/LineWidget/behavior.js +14 -10
- package/Widgets/Widgets3D/PaintWidget/behavior.js +6 -4
- package/Widgets/Widgets3D/PolyLineWidget/behavior.js +11 -7
- package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +11 -7
- package/Widgets/Widgets3D/ShapeWidget/behavior.js +23 -15
- package/Widgets/Widgets3D/SphereWidget/behavior.js +15 -7
- package/Widgets/Widgets3D/SplineWidget/behavior.js +11 -8
- package/package.json +2 -2
|
@@ -331,9 +331,10 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
|
|
|
331
331
|
if (cabo.getElementCount()) {
|
|
332
332
|
// are we drawing edges
|
|
333
333
|
model.drawingEdges = drawSurfaceWithEdges && (i === model.primTypes.TrisEdges || i === model.primTypes.TriStripsEdges);
|
|
334
|
-
|
|
334
|
+
model.lastBoundBO = model.primitives[i];
|
|
335
|
+
model.primitives[i].updateShaders(ren, actor, publicAPI);
|
|
335
336
|
var program = model.primitives[i].getProgram();
|
|
336
|
-
var mode =
|
|
337
|
+
var mode = model.primitives[i].getOpenGLMode(representation);
|
|
337
338
|
var normalMatrixUsed = program.isUniformUsed('normalMatrix');
|
|
338
339
|
var mcvcMatrixUsed = program.isUniformUsed('MCVCMatrix');
|
|
339
340
|
|
|
@@ -413,6 +414,14 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
|
|
|
413
414
|
return superClass.getNeedToRebuildBufferObjects(ren, actor);
|
|
414
415
|
};
|
|
415
416
|
|
|
417
|
+
publicAPI.getNeedToRebuildShaders = function (cellBO, ren, actor) {
|
|
418
|
+
if (superClass.getNeedToRebuildShaders(cellBO, ren, actor) || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime()) {
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return false;
|
|
423
|
+
};
|
|
424
|
+
|
|
416
425
|
publicAPI.buildBufferObjects = function (ren, actor) {
|
|
417
426
|
if (model.hardwareSupport) {
|
|
418
427
|
// update the buffer objects if needed
|
|
@@ -239,7 +239,7 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
|
|
|
239
239
|
|
|
240
240
|
|
|
241
241
|
publicAPI.beginSelection = function () {
|
|
242
|
-
model._openGLRenderer = model._openGLRenderWindow.getViewNodeFor(model.
|
|
242
|
+
model._openGLRenderer = model._openGLRenderWindow.getViewNodeFor(model._renderer);
|
|
243
243
|
model.maxAttributeId = 0;
|
|
244
244
|
|
|
245
245
|
var size = model._openGLRenderWindow.getSize();
|
|
@@ -307,7 +307,7 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
|
|
|
307
307
|
switch (_context.prev = _context.next) {
|
|
308
308
|
case 0:
|
|
309
309
|
// assign the renderer
|
|
310
|
-
model.
|
|
310
|
+
model._renderer = renderer; // set area to all if no arguments provided
|
|
311
311
|
|
|
312
312
|
if (fx1 === undefined) {
|
|
313
313
|
size = model._openGLRenderWindow.getSize();
|
|
@@ -361,12 +361,12 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
|
|
|
361
361
|
|
|
362
362
|
|
|
363
363
|
publicAPI.captureBuffers = function () {
|
|
364
|
-
if (!model.
|
|
364
|
+
if (!model._renderer || !model._openGLRenderWindow) {
|
|
365
365
|
vtkErrorMacro('Renderer and view must be set before calling Select.');
|
|
366
366
|
return false;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
model._openGLRenderer = model._openGLRenderWindow.getViewNodeFor(model.
|
|
369
|
+
model._openGLRenderer = model._openGLRenderWindow.getViewNodeFor(model._renderer); // todo revisit making selection part of core
|
|
370
370
|
// then we can do this in core
|
|
371
371
|
|
|
372
372
|
model._openGLRenderWindow.getRenderable().preRender(); // int rgba[4];
|
|
@@ -383,8 +383,9 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
|
|
|
383
383
|
}); // Initialize renderer for selection.
|
|
384
384
|
// change the renderer's background to black, which will indicate a miss
|
|
385
385
|
|
|
386
|
-
model.originalBackground = model.
|
|
387
|
-
|
|
386
|
+
model.originalBackground = model._renderer.getBackgroundByReference();
|
|
387
|
+
|
|
388
|
+
model._renderer.setBackground(0.0, 0.0, 0.0);
|
|
388
389
|
|
|
389
390
|
var rpasses = model._openGLRenderWindow.getRenderPasses();
|
|
390
391
|
|
|
@@ -409,7 +410,8 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
|
|
|
409
410
|
|
|
410
411
|
publicAPI.endSelection(); // restore original background
|
|
411
412
|
|
|
412
|
-
model.
|
|
413
|
+
model._renderer.setBackground(model.originalBackground);
|
|
414
|
+
|
|
413
415
|
publicAPI.invokeEvent({
|
|
414
416
|
type: 'EndEvent'
|
|
415
417
|
}); // restore image, not needed?
|
|
@@ -656,13 +658,13 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
|
|
|
656
658
|
}
|
|
657
659
|
}
|
|
658
660
|
|
|
659
|
-
return convertSelection(model.fieldAssociation, dataMap, model.captureZValues, model.
|
|
661
|
+
return convertSelection(model.fieldAssociation, dataMap, model.captureZValues, model._renderer, model._openGLRenderWindow);
|
|
660
662
|
}; //----------------------------------------------------------------------------
|
|
661
663
|
|
|
662
664
|
|
|
663
665
|
publicAPI.attach = function (w, r) {
|
|
664
666
|
model._openGLRenderWindow = w;
|
|
665
|
-
model.
|
|
667
|
+
model._renderer = r;
|
|
666
668
|
}; // override
|
|
667
669
|
|
|
668
670
|
|
|
@@ -2,7 +2,18 @@ import macro from '../../macros.js';
|
|
|
2
2
|
import vtkCellArrayBufferObject from './CellArrayBufferObject.js';
|
|
3
3
|
import vtkShaderProgram from './ShaderProgram.js';
|
|
4
4
|
import vtkVertexArrayObject from './VertexArrayObject.js';
|
|
5
|
+
import { Representation } from '../Core/Property/Constants.js';
|
|
5
6
|
|
|
7
|
+
var primTypes = {
|
|
8
|
+
Start: 0,
|
|
9
|
+
Points: 0,
|
|
10
|
+
Lines: 1,
|
|
11
|
+
Tris: 2,
|
|
12
|
+
TriStrips: 3,
|
|
13
|
+
TrisEdges: 4,
|
|
14
|
+
TriStripsEdges: 5,
|
|
15
|
+
End: 6
|
|
16
|
+
}; // ----------------------------------------------------------------------------
|
|
6
17
|
// vtkOpenGLHelper methods
|
|
7
18
|
// ----------------------------------------------------------------------------
|
|
8
19
|
|
|
@@ -11,7 +22,8 @@ function vtkOpenGLHelper(publicAPI, model) {
|
|
|
11
22
|
model.classHierarchy.push('vtkOpenGLHelper');
|
|
12
23
|
|
|
13
24
|
publicAPI.setOpenGLRenderWindow = function (win) {
|
|
14
|
-
model.
|
|
25
|
+
model.context = win.getContext();
|
|
26
|
+
model.program.setContext(model.context);
|
|
15
27
|
model.VAO.setOpenGLRenderWindow(win);
|
|
16
28
|
model.CABO.setOpenGLRenderWindow(win);
|
|
17
29
|
};
|
|
@@ -21,12 +33,141 @@ function vtkOpenGLHelper(publicAPI, model) {
|
|
|
21
33
|
model.CABO.releaseGraphicsResources();
|
|
22
34
|
model.CABO.setElementCount(0);
|
|
23
35
|
};
|
|
36
|
+
|
|
37
|
+
publicAPI.drawArrays = function (ren, actor, rep, oglMapper) {
|
|
38
|
+
// Are there any entries
|
|
39
|
+
if (model.CABO.getElementCount()) {
|
|
40
|
+
// are we drawing edges
|
|
41
|
+
var mode = publicAPI.getOpenGLMode(rep);
|
|
42
|
+
var wideLines = publicAPI.haveWideLines(ren, actor);
|
|
43
|
+
var gl = model.context;
|
|
44
|
+
var drawingLines = mode === gl.LINES;
|
|
45
|
+
|
|
46
|
+
if (drawingLines && wideLines) {
|
|
47
|
+
publicAPI.updateShaders(ren, actor, oglMapper);
|
|
48
|
+
gl.drawArraysInstanced(mode, 0, model.CABO.getElementCount(), 2 * Math.ceil(actor.getProperty().getLineWidth()));
|
|
49
|
+
} else {
|
|
50
|
+
gl.lineWidth(actor.getProperty().getLineWidth());
|
|
51
|
+
publicAPI.updateShaders(ren, actor, oglMapper);
|
|
52
|
+
gl.drawArrays(mode, 0, model.CABO.getElementCount()); // reset the line width
|
|
53
|
+
|
|
54
|
+
gl.lineWidth(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var stride = (mode === gl.POINTS ? 1 : 0) || (mode === gl.LINES ? 2 : 3);
|
|
58
|
+
return model.CABO.getElementCount() / stride;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return 0;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
publicAPI.getOpenGLMode = function (rep) {
|
|
65
|
+
var type = model.primitiveType;
|
|
66
|
+
|
|
67
|
+
if (rep === Representation.POINTS || type === primTypes.Points) {
|
|
68
|
+
return model.context.POINTS;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (rep === Representation.WIREFRAME || type === primTypes.Lines || type === primTypes.TrisEdges || type === primTypes.TriStripsEdges) {
|
|
72
|
+
return model.context.LINES;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return model.context.TRIANGLES;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
publicAPI.haveWideLines = function (ren, actor) {
|
|
79
|
+
if (actor.getProperty().getLineWidth() > 1.0) {
|
|
80
|
+
// we have wide lines, but the OpenGL implementation may
|
|
81
|
+
// actually support them, check the range to see if we
|
|
82
|
+
// really need have to implement our own wide lines
|
|
83
|
+
if (model.CABO.getOpenGLRenderWindow()) {
|
|
84
|
+
if (model.CABO.getOpenGLRenderWindow().getHardwareMaximumLineWidth() >= actor.getProperty().getLineWidth()) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return false;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
publicAPI.getNeedToRebuildShaders = function (ren, actor, oglMapper) {
|
|
96
|
+
// has something changed that would require us to recreate the shader?
|
|
97
|
+
// candidates are
|
|
98
|
+
// property modified (representation interpolation and lighting)
|
|
99
|
+
// input modified
|
|
100
|
+
// mapper modified (lighting complexity)
|
|
101
|
+
if (oglMapper.getNeedToRebuildShaders(publicAPI, ren, actor) || publicAPI.getProgram() === 0 || publicAPI.getShaderSourceTime().getMTime() < oglMapper.getMTime() || publicAPI.getShaderSourceTime().getMTime() < actor.getMTime()) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return false;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
publicAPI.updateShaders = function (ren, actor, oglMapper) {
|
|
109
|
+
// has something changed that would require us to recreate the shader?
|
|
110
|
+
if (publicAPI.getNeedToRebuildShaders(ren, actor, oglMapper)) {
|
|
111
|
+
var shaders = {
|
|
112
|
+
Vertex: null,
|
|
113
|
+
Fragment: null,
|
|
114
|
+
Geometry: null
|
|
115
|
+
};
|
|
116
|
+
oglMapper.buildShaders(shaders, ren, actor); // compile and bind the program if needed
|
|
117
|
+
|
|
118
|
+
var newShader = model.CABO.getOpenGLRenderWindow().getShaderCache().readyShaderProgramArray(shaders.Vertex, shaders.Fragment, shaders.Geometry); // if the shader changed reinitialize the VAO
|
|
119
|
+
|
|
120
|
+
if (newShader !== publicAPI.getProgram()) {
|
|
121
|
+
publicAPI.setProgram(newShader); // reset the VAO as the shader has changed
|
|
122
|
+
|
|
123
|
+
publicAPI.getVAO().releaseGraphicsResources();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
publicAPI.getShaderSourceTime().modified();
|
|
127
|
+
} else {
|
|
128
|
+
model.CABO.getOpenGLRenderWindow().getShaderCache().readyShaderProgram(publicAPI.getProgram());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
publicAPI.getVAO().bind();
|
|
132
|
+
oglMapper.setMapperShaderParameters(publicAPI, ren, actor);
|
|
133
|
+
oglMapper.setPropertyShaderParameters(publicAPI, ren, actor);
|
|
134
|
+
oglMapper.setCameraShaderParameters(publicAPI, ren, actor);
|
|
135
|
+
oglMapper.setLightingShaderParameters(publicAPI, ren, actor);
|
|
136
|
+
oglMapper.invokeShaderCallbacks(publicAPI, ren, actor);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
publicAPI.setMapperShaderParameters = function (ren, actor, size) {
|
|
140
|
+
if (publicAPI.haveWideLines(ren, actor)) {
|
|
141
|
+
publicAPI.getProgram().setUniform2f('viewportSize', size.usize, size.vsize);
|
|
142
|
+
var lineWidth = parseFloat(actor.getProperty().getLineWidth());
|
|
143
|
+
var halfLineWidth = lineWidth / 2.0;
|
|
144
|
+
publicAPI.getProgram().setUniformf('lineWidthStepSize', lineWidth / Math.ceil(lineWidth));
|
|
145
|
+
publicAPI.getProgram().setUniformf('halfLineWidth', halfLineWidth);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
publicAPI.replaceShaderPositionVC = function (shaders, ren, actor) {
|
|
150
|
+
var VSSource = shaders.Vertex; // for lines, make sure we add the width code
|
|
151
|
+
|
|
152
|
+
if (publicAPI.getOpenGLMode(actor.getProperty().getRepresentation()) === model.context.LINES && publicAPI.haveWideLines(ren, actor)) {
|
|
153
|
+
VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Dec', ['//VTK::PositionVC::Dec', 'uniform vec2 viewportSize;', 'uniform float lineWidthStepSize;', 'uniform float halfLineWidth;']).result;
|
|
154
|
+
VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Impl', ['//VTK::PositionVC::Impl', ' if (halfLineWidth > 0.0)', ' {', ' float offset = float(gl_InstanceID / 2) * lineWidthStepSize - halfLineWidth;', ' vec4 tmpPos = gl_Position;', ' vec3 tmpPos2 = tmpPos.xyz / tmpPos.w;', ' tmpPos2.x = tmpPos2.x + 2.0 * mod(float(gl_InstanceID), 2.0) * offset / viewportSize[0];', ' tmpPos2.y = tmpPos2.y + 2.0 * mod(float(gl_InstanceID + 1), 2.0) * offset / viewportSize[1];', ' gl_Position = vec4(tmpPos2.xyz * tmpPos.w, tmpPos.w);', ' }']).result;
|
|
155
|
+
} // for points make sure to add in the point size
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
if (actor.getProperty().getRepresentation() === Representation.POINTS || model.primitiveType === primTypes.Points) {
|
|
159
|
+
VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Impl', ['//VTK::PositionVC::Impl', " gl_PointSize = ".concat(actor.getProperty().getPointSize(), ".0;")], false).result;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
shaders.Vertex = VSSource;
|
|
163
|
+
};
|
|
24
164
|
} // ----------------------------------------------------------------------------
|
|
25
165
|
// Object factory
|
|
26
166
|
// ----------------------------------------------------------------------------
|
|
27
167
|
|
|
28
168
|
|
|
29
169
|
var DEFAULT_VALUES = {
|
|
170
|
+
context: null,
|
|
30
171
|
program: null,
|
|
31
172
|
shaderSourceTime: null,
|
|
32
173
|
VAO: null,
|
|
@@ -56,7 +197,8 @@ var newInstance = macro.newInstance(extend); // --------------------------------
|
|
|
56
197
|
|
|
57
198
|
var vtkHelper = {
|
|
58
199
|
newInstance: newInstance,
|
|
59
|
-
extend: extend
|
|
200
|
+
extend: extend,
|
|
201
|
+
primTypes: primTypes
|
|
60
202
|
};
|
|
61
203
|
|
|
62
|
-
export { vtkHelper as default, extend, newInstance };
|
|
204
|
+
export { vtkHelper as default, extend, newInstance, primTypes };
|
|
@@ -112,26 +112,18 @@ function vtkOpenGLOrderIndependentTranslucentPass(publicAPI, model) {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
var size = viewNode.getSize();
|
|
115
|
-
var gl = viewNode.getContext();
|
|
116
|
-
|
|
117
|
-
if (gl === null) {
|
|
118
|
-
// nothing to do -> no render context
|
|
119
|
-
// traverse delegate passes -> has to be done in order for the vtk render-pipeline to work correctly
|
|
120
|
-
model.delegates.forEach(function (val) {
|
|
121
|
-
val.traverse(viewNode, publicAPI);
|
|
122
|
-
});
|
|
123
|
-
return;
|
|
124
|
-
} // if we lack the webgl2 and half floatsupport just do
|
|
115
|
+
var gl = viewNode.getContext(); // if we lack the webgl2 and half floatsupport just do
|
|
125
116
|
// basic alpha blending
|
|
126
117
|
|
|
118
|
+
model._supported = false;
|
|
127
119
|
|
|
128
|
-
if (!viewNode.getWebgl2() || !gl.getExtension('EXT_color_buffer_half_float') && !gl.getExtension('EXT_color_buffer_float')) {
|
|
129
|
-
console.log('fallback');
|
|
120
|
+
if (!gl || !viewNode.getWebgl2() || !gl.getExtension('EXT_color_buffer_half_float') && !gl.getExtension('EXT_color_buffer_float')) {
|
|
130
121
|
publicAPI.setCurrentOperation('translucentPass');
|
|
131
122
|
renNode.traverse(publicAPI);
|
|
132
123
|
return;
|
|
133
|
-
}
|
|
124
|
+
}
|
|
134
125
|
|
|
126
|
+
model._supported = true; // prepare framebuffer // allocate framebuffer if needed and bind it
|
|
135
127
|
|
|
136
128
|
if (model.framebuffer === null) {
|
|
137
129
|
publicAPI.createFramebuffer(viewNode);
|
|
@@ -216,7 +208,11 @@ function vtkOpenGLOrderIndependentTranslucentPass(publicAPI, model) {
|
|
|
216
208
|
};
|
|
217
209
|
|
|
218
210
|
publicAPI.getShaderReplacement = function () {
|
|
219
|
-
|
|
211
|
+
if (model._supported) {
|
|
212
|
+
return translucentShaderReplacement;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return {};
|
|
220
216
|
};
|
|
221
217
|
|
|
222
218
|
publicAPI.releaseGraphicsResources = function (viewNode) {
|
|
@@ -15,16 +15,7 @@ import { registerOverride } from './ViewNodeFactory.js';
|
|
|
15
15
|
|
|
16
16
|
/* eslint-disable no-lonely-if */
|
|
17
17
|
|
|
18
|
-
var primTypes =
|
|
19
|
-
Start: 0,
|
|
20
|
-
Points: 0,
|
|
21
|
-
Lines: 1,
|
|
22
|
-
Tris: 2,
|
|
23
|
-
TriStrips: 3,
|
|
24
|
-
TrisEdges: 4,
|
|
25
|
-
TriStripsEdges: 5,
|
|
26
|
-
End: 6
|
|
27
|
-
};
|
|
18
|
+
var primTypes = vtkHelper.primTypes;
|
|
28
19
|
var Representation = vtkProperty.Representation,
|
|
29
20
|
Shading = vtkProperty.Shading;
|
|
30
21
|
var ScalarMode = vtkMapper.ScalarMode;
|
|
@@ -326,7 +317,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
|
|
|
326
317
|
FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Normal::Dec', ['uniform mat3 normalMatrix;', 'uniform samplerBuffer textureN;']).result;
|
|
327
318
|
FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Normal::Impl', ['vec3 normalVCVSOutput = normalize(normalMatrix *', ' texelFetchBuffer(textureN, gl_PrimitiveID + PrimitiveIDOffset).xyz);', ' if (gl_FrontFacing == false) { normalVCVSOutput = -normalVCVSOutput; }']).result;
|
|
328
319
|
} else {
|
|
329
|
-
if (
|
|
320
|
+
if (model.lastBoundBO.getOpenGLMode(actor.getProperty().getRepresentation()) === model.context.LINES) {
|
|
330
321
|
// generate a normal for lines, it will be perpendicular to the line
|
|
331
322
|
// and maximally aligned with the camera view direction
|
|
332
323
|
// no clue if this is the best way to do this.
|
|
@@ -361,14 +352,11 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
|
|
|
361
352
|
};
|
|
362
353
|
|
|
363
354
|
publicAPI.replaceShaderPositionVC = function (shaders, ren, actor) {
|
|
355
|
+
// replace common shader code
|
|
356
|
+
model.lastBoundBO.replaceShaderPositionVC(shaders, ren, actor);
|
|
364
357
|
var VSSource = shaders.Vertex;
|
|
365
358
|
var GSSource = shaders.Geometry;
|
|
366
|
-
var FSSource = shaders.Fragment; //
|
|
367
|
-
|
|
368
|
-
if (actor.getProperty().getRepresentation() === Representation.POINTS || model.lastBoundBO.getPrimitiveType() === primTypes.Points) {
|
|
369
|
-
VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Impl', ['//VTK::PositionVC::Impl', " gl_PointSize = ".concat(actor.getProperty().getPointSize(), ".0;")], false).result;
|
|
370
|
-
} // do we need the vertex in the shader in View Coordinates
|
|
371
|
-
|
|
359
|
+
var FSSource = shaders.Fragment; // do we need the vertex in the shader in View Coordinates
|
|
372
360
|
|
|
373
361
|
var lastLightComplexity = model.lastBoundBO.getReferenceByName('lastLightComplexity');
|
|
374
362
|
|
|
@@ -556,7 +544,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
|
|
|
556
544
|
var cellNormals = poly.getCellData().getNormals();
|
|
557
545
|
var flat = actor.getProperty().getInterpolation() === Shading.FLAT;
|
|
558
546
|
var representation = actor.getProperty().getRepresentation();
|
|
559
|
-
var mode =
|
|
547
|
+
var mode = cellBO.getOpenGLMode(representation, primType); // 1) all surfaces need lighting
|
|
560
548
|
|
|
561
549
|
if (mode === model.context.TRIANGLES) {
|
|
562
550
|
needLighting = true; // 2) all cell normals without point normals need lighting
|
|
@@ -628,7 +616,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
|
|
|
628
616
|
// light complexity changed
|
|
629
617
|
|
|
630
618
|
|
|
631
|
-
if (model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.
|
|
619
|
+
if (model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime() || needRebuild) {
|
|
632
620
|
model.lastHaveSeenDepthRequest = model.haveSeenDepthRequest;
|
|
633
621
|
return true;
|
|
634
622
|
}
|
|
@@ -636,36 +624,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
|
|
|
636
624
|
return false;
|
|
637
625
|
};
|
|
638
626
|
|
|
639
|
-
publicAPI.
|
|
640
|
-
model.lastBoundBO = cellBO; // has something changed that would require us to recreate the shader?
|
|
641
|
-
|
|
642
|
-
if (publicAPI.getNeedToRebuildShaders(cellBO, ren, actor)) {
|
|
643
|
-
var shaders = {
|
|
644
|
-
Vertex: null,
|
|
645
|
-
Fragment: null,
|
|
646
|
-
Geometry: null
|
|
647
|
-
};
|
|
648
|
-
publicAPI.buildShaders(shaders, ren, actor); // compile and bind the program if needed
|
|
649
|
-
|
|
650
|
-
var newShader = model._openGLRenderWindow.getShaderCache().readyShaderProgramArray(shaders.Vertex, shaders.Fragment, shaders.Geometry); // if the shader changed reinitialize the VAO
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
if (newShader !== cellBO.getProgram()) {
|
|
654
|
-
cellBO.setProgram(newShader); // reset the VAO as the shader has changed
|
|
655
|
-
|
|
656
|
-
cellBO.getVAO().releaseGraphicsResources();
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
cellBO.getShaderSourceTime().modified();
|
|
660
|
-
} else {
|
|
661
|
-
model._openGLRenderWindow.getShaderCache().readyShaderProgram(cellBO.getProgram());
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
cellBO.getVAO().bind();
|
|
665
|
-
publicAPI.setMapperShaderParameters(cellBO, ren, actor);
|
|
666
|
-
publicAPI.setPropertyShaderParameters(cellBO, ren, actor);
|
|
667
|
-
publicAPI.setCameraShaderParameters(cellBO, ren, actor);
|
|
668
|
-
publicAPI.setLightingShaderParameters(cellBO, ren, actor);
|
|
627
|
+
publicAPI.invokeShaderCallbacks = function (cellBO, ren, actor) {
|
|
669
628
|
var listCallbacks = model.renderable.getViewSpecificProperties().ShadersCallbacks;
|
|
670
629
|
|
|
671
630
|
if (listCallbacks) {
|
|
@@ -783,8 +742,10 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
|
|
|
783
742
|
if (cellBO.getProgram().isUniformUsed('cfactor')) {
|
|
784
743
|
cellBO.getProgram().setUniformf('cfactor', cp.factor);
|
|
785
744
|
}
|
|
786
|
-
}
|
|
745
|
+
} // handle wide lines
|
|
746
|
+
|
|
787
747
|
|
|
748
|
+
cellBO.setMapperShaderParameters(ren, actor, model.openGLRenderer.getTiledSizeAndOrigin());
|
|
788
749
|
var selector = model.openGLRenderer.getSelector();
|
|
789
750
|
cellBO.getProgram().setUniform3fArray('mapperIndex', selector ? selector.getPropColorValue() : [0.0, 0.0, 0.0]);
|
|
790
751
|
cellBO.getProgram().setUniformi('picking', selector ? selector.getCurrentPass() + 1 : 0);
|
|
@@ -997,9 +958,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
|
|
|
997
958
|
|
|
998
959
|
publicAPI.renderPieceDraw = function (ren, actor) {
|
|
999
960
|
var representation = actor.getProperty().getRepresentation();
|
|
1000
|
-
var
|
|
1001
|
-
var drawSurfaceWithEdges = actor.getProperty().getEdgeVisibility() && representation === Representation.SURFACE;
|
|
1002
|
-
gl.lineWidth(actor.getProperty().getLineWidth()); // for every primitive type
|
|
961
|
+
var drawSurfaceWithEdges = actor.getProperty().getEdgeVisibility() && representation === Representation.SURFACE; // for every primitive type
|
|
1003
962
|
|
|
1004
963
|
for (var i = primTypes.Start; i < primTypes.End; i++) {
|
|
1005
964
|
// if there are entries
|
|
@@ -1008,32 +967,13 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
|
|
|
1008
967
|
if (cabo.getElementCount()) {
|
|
1009
968
|
// are we drawing edges
|
|
1010
969
|
model.drawingEdges = drawSurfaceWithEdges && (i === primTypes.TrisEdges || i === primTypes.TriStripsEdges);
|
|
1011
|
-
var mode = publicAPI.getOpenGLMode(representation, i);
|
|
1012
970
|
|
|
1013
971
|
if (!model.drawingEdges || !model.renderDepth) {
|
|
1014
|
-
|
|
1015
|
-
|
|
972
|
+
model.lastBoundBO = model.primitives[i];
|
|
973
|
+
model.primitiveIDOffset += model.primitives[i].drawArrays(ren, actor, representation, publicAPI);
|
|
1016
974
|
}
|
|
1017
|
-
|
|
1018
|
-
var stride = (mode === gl.POINTS ? 1 : 0) || (mode === gl.LINES ? 2 : 3);
|
|
1019
|
-
model.primitiveIDOffset += cabo.getElementCount() / stride;
|
|
1020
975
|
}
|
|
1021
|
-
} // reset the line width
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
gl.lineWidth(1);
|
|
1025
|
-
};
|
|
1026
|
-
|
|
1027
|
-
publicAPI.getOpenGLMode = function (rep, type) {
|
|
1028
|
-
if (rep === Representation.POINTS || type === primTypes.Points) {
|
|
1029
|
-
return model.context.POINTS;
|
|
1030
976
|
}
|
|
1031
|
-
|
|
1032
|
-
if (rep === Representation.WIREFRAME || type === primTypes.Lines || type === primTypes.TrisEdges || type === primTypes.TriStripsEdges) {
|
|
1033
|
-
return model.context.LINES;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
return model.context.TRIANGLES;
|
|
1037
977
|
};
|
|
1038
978
|
|
|
1039
979
|
publicAPI.renderPieceFinish = function (ren, actor) {
|
|
@@ -1299,10 +1239,9 @@ var newInstance = newInstance$1(extend, 'vtkOpenGLPolyDataMapper'); // ---------
|
|
|
1299
1239
|
|
|
1300
1240
|
var vtkOpenGLPolyDataMapper$1 = {
|
|
1301
1241
|
newInstance: newInstance,
|
|
1302
|
-
extend: extend
|
|
1303
|
-
primTypes: primTypes
|
|
1242
|
+
extend: extend
|
|
1304
1243
|
}; // Register ourself to OpenGL backend if imported
|
|
1305
1244
|
|
|
1306
1245
|
registerOverride('vtkMapper', newInstance);
|
|
1307
1246
|
|
|
1308
|
-
export { vtkOpenGLPolyDataMapper$1 as default, extend, newInstance
|
|
1247
|
+
export { vtkOpenGLPolyDataMapper$1 as default, extend, newInstance };
|