@kitware/vtk.js 21.2.2 → 21.3.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.
@@ -0,0 +1,667 @@
1
+ import { mat4 } from 'gl-matrix';
2
+ import { newInstance as newInstance$1, setGet, obj, vtkErrorMacro as vtkErrorMacro$1 } from '../../macros.js';
3
+ import vtkHelper from './Helper.js';
4
+ import vtkMapper2D from '../Core/Mapper2D.js';
5
+ import vtkOpenGLPolyDataMapper from './PolyDataMapper.js';
6
+ import vtkPoints from '../../Common/Core/Points.js';
7
+ import { v as vtkPolyData2DFS } from './glsl/vtkPolyData2DFS.glsl.js';
8
+ import { v as vtkPolyData2DVS } from './glsl/vtkPolyData2DVS.glsl.js';
9
+ import vtkReplacementShaderMapper from './ReplacementShaderMapper.js';
10
+ import vtkShaderProgram from './ShaderProgram.js';
11
+ import vtkViewNode from '../SceneGraph/ViewNode.js';
12
+ import { J as round } from '../../Common/Core/Math/index.js';
13
+ import { Representation } from '../Core/Property/Constants.js';
14
+ import { DisplayLocation } from '../Core/Property2D/Constants.js';
15
+ import { registerOverride } from './ViewNodeFactory.js';
16
+
17
+ // import { mat3, mat4, vec3 } from 'gl-matrix';
18
+ var primTypes = vtkOpenGLPolyDataMapper.primTypes;
19
+ var ScalarMode = vtkMapper2D.ScalarMode;
20
+ var vtkErrorMacro = vtkErrorMacro$1;
21
+ var StartEvent = {
22
+ type: 'StartEvent'
23
+ };
24
+ var EndEvent = {
25
+ type: 'EndEvent'
26
+ }; // ----------------------------------------------------------------------------
27
+ // vtkOpenGLPolyDataMapper2D methods
28
+ // ----------------------------------------------------------------------------
29
+
30
+ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
31
+ // Set our className
32
+ model.classHierarchy.push('vtkOpenGLPolyDataMapper2D');
33
+
34
+ publicAPI.buildPass = function (prepass) {
35
+ if (prepass) {
36
+ model.openGLActor2D = publicAPI.getFirstAncestorOfType('vtkOpenGLActor2D');
37
+ model.openGLRenderer = model.openGLActor2D.getFirstAncestorOfType('vtkOpenGLRenderer');
38
+ model.openGLRenderWindow = model.openGLRenderer.getParent();
39
+ model.openGLCamera = model.openGLRenderer.getViewNodeFor(model.openGLRenderer.getRenderable().getActiveCamera());
40
+ }
41
+ };
42
+
43
+ publicAPI.overlayPass = function (prepass) {
44
+ if (prepass) {
45
+ publicAPI.render();
46
+ }
47
+ };
48
+
49
+ publicAPI.getShaderTemplate = function (shaders, ren, actor) {
50
+ var openGLSpecProp = model.renderable.getViewSpecificProperties().OpenGL;
51
+ var vertexShaderCode = vtkPolyData2DVS;
52
+
53
+ if (openGLSpecProp) {
54
+ var vertexSpecProp = openGLSpecProp.VertexShaderCode;
55
+
56
+ if (vertexSpecProp !== undefined && vertexSpecProp !== '') {
57
+ vertexShaderCode = vertexSpecProp;
58
+ }
59
+ }
60
+
61
+ shaders.Vertex = vertexShaderCode;
62
+ var fragmentShaderCode = vtkPolyData2DFS;
63
+
64
+ if (openGLSpecProp) {
65
+ var fragmentSpecProp = openGLSpecProp.FragmentShaderCode;
66
+
67
+ if (fragmentSpecProp !== undefined && fragmentSpecProp !== '') {
68
+ fragmentShaderCode = fragmentSpecProp;
69
+ }
70
+ }
71
+
72
+ shaders.Fragment = fragmentShaderCode;
73
+ var geometryShaderCode = '';
74
+
75
+ if (openGLSpecProp) {
76
+ var geometrySpecProp = openGLSpecProp.GeometryShaderCode;
77
+
78
+ if (geometrySpecProp !== undefined) {
79
+ geometryShaderCode = geometrySpecProp;
80
+ }
81
+ }
82
+
83
+ shaders.Geometry = geometryShaderCode;
84
+ };
85
+
86
+ publicAPI.render = function () {
87
+ var ctx = model.openGLRenderWindow.getContext();
88
+
89
+ if (model.context !== ctx) {
90
+ model.context = ctx;
91
+
92
+ for (var i = primTypes.Start; i < primTypes.End; i++) {
93
+ model.primitives[i].setOpenGLRenderWindow(model.openGLRenderWindow);
94
+ }
95
+ }
96
+
97
+ var actor = model.openGLActor2D.getRenderable();
98
+ var ren = model.openGLRenderer.getRenderable();
99
+ publicAPI.renderPiece(ren, actor);
100
+ };
101
+
102
+ publicAPI.renderPiece = function (ren, actor) {
103
+ publicAPI.invokeEvent(StartEvent);
104
+
105
+ if (!model.renderable.getStatic()) {
106
+ model.renderable.update();
107
+ }
108
+
109
+ model.currentInput = model.renderable.getInputData();
110
+ publicAPI.invokeEvent(EndEvent);
111
+
112
+ if (!model.currentInput) {
113
+ vtkErrorMacro('No input!');
114
+ return;
115
+ } // if there are no points then we are done
116
+
117
+
118
+ if (!model.currentInput.getPoints || !model.currentInput.getPoints().getNumberOfValues()) {
119
+ return;
120
+ }
121
+
122
+ publicAPI.renderPieceStart(ren, actor);
123
+ publicAPI.renderPieceDraw(ren, actor);
124
+ publicAPI.renderPieceFinish(ren, actor);
125
+ };
126
+
127
+ publicAPI.renderPieceStart = function (ren, actor) {
128
+ model.primitiveIDOffset = 0;
129
+
130
+ if (model.openGLRenderer.getSelector()) {
131
+ switch (model.openGLRenderer.getSelector().getCurrentPass()) {
132
+ default:
133
+ model.openGLRenderer.getSelector().renderProp(actor);
134
+ }
135
+ } // make sure the BOs are up to date
136
+
137
+
138
+ publicAPI.updateBufferObjects(ren, actor); // Bind the OpenGL, this is shared between the different primitive/cell types.
139
+
140
+ model.lastBoundBO = null;
141
+ };
142
+
143
+ publicAPI.getNeedToRebuildShaders = function (cellBO, ren, actor) {
144
+ // has something changed that would require us to recreate the shader?
145
+ // candidates are
146
+ // property modified (representation interpolation and lighting)
147
+ // input modified
148
+ // light complexity changed
149
+ if (cellBO.getProgram() === 0 || cellBO.getShaderSourceTime().getMTime() < publicAPI.getMTime() || cellBO.getShaderSourceTime().getMTime() < actor.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime()) {
150
+ return true;
151
+ }
152
+
153
+ return false;
154
+ };
155
+
156
+ publicAPI.updateBufferObjects = function (ren, actor) {
157
+ // Rebuild buffers if needed
158
+ if (publicAPI.getNeedToRebuildBufferObjects(ren, actor)) {
159
+ publicAPI.buildBufferObjects(ren, actor);
160
+ }
161
+ };
162
+
163
+ publicAPI.getNeedToRebuildBufferObjects = function (ren, actor) {
164
+ // first do a coarse check
165
+ // Note that the actor's mtime includes it's properties mtime
166
+ var vmtime = model.VBOBuildTime.getMTime();
167
+
168
+ if (vmtime < publicAPI.getMTime() || vmtime < model.renderable.getMTime() || vmtime < actor.getMTime() || vmtime < model.currentInput.getMTime() || model.renderable.getTransformCoordinate() && vmtime < ren.getMTime()) {
169
+ return true;
170
+ }
171
+
172
+ return false;
173
+ };
174
+
175
+ publicAPI.getOpenGLMode = function (rep, type) {
176
+ if (rep === Representation.POINTS || type === primTypes.Points) {
177
+ return model.context.POINTS;
178
+ }
179
+
180
+ if (rep === Representation.WIREFRAME || type === primTypes.Lines || type === primTypes.TrisEdges || type === primTypes.TriStripsEdges) {
181
+ return model.context.LINES;
182
+ }
183
+
184
+ return model.context.TRIANGLES;
185
+ };
186
+
187
+ publicAPI.buildBufferObjects = function (ren, actor) {
188
+ var poly = model.currentInput;
189
+
190
+ if (poly === null) {
191
+ return;
192
+ }
193
+
194
+ model.renderable.mapScalars(poly, actor.getProperty().getOpacity());
195
+ var c = model.renderable.getColorMapColors();
196
+ model.haveCellScalars = false;
197
+ var scalarMode = model.renderable.getScalarMode();
198
+
199
+ if (model.renderable.getScalarVisibility()) {
200
+ // We must figure out how the scalars should be mapped to the polydata.
201
+ if ((scalarMode === ScalarMode.USE_CELL_DATA || scalarMode === ScalarMode.USE_CELL_FIELD_DATA || scalarMode === ScalarMode.USE_FIELD_DATA || !poly.getPointData().getScalars()) && scalarMode !== ScalarMode.USE_POINT_FIELD_DATA && c) {
202
+ model.haveCellScalars = true;
203
+ }
204
+ }
205
+
206
+ var representation = actor.getProperty().getRepresentation();
207
+ var tcoords = poly.getPointData().getTCoords();
208
+
209
+ if (!model.openGLActor2D.getActiveTextures()) {
210
+ tcoords = null;
211
+ }
212
+
213
+ var transformCoordinate = model.renderable.getTransformCoordinate();
214
+ var toString = "".concat(poly.getMTime(), "A").concat(representation, "B").concat(poly.getMTime()) + "C".concat(c ? c.getMTime() : 1) + "D".concat(tcoords ? tcoords.getMTime() : 1) + "E".concat(transformCoordinate ? ren.getMTime() : 1);
215
+
216
+ if (model.VBOBuildString !== toString) {
217
+ // Build the VBOs
218
+ var points = poly.getPoints();
219
+
220
+ if (transformCoordinate) {
221
+ var p = vtkPoints.newInstance();
222
+ var numPts = points.getNumberOfPoints();
223
+ p.setNumberOfPoints(numPts);
224
+
225
+ for (var i = 0; i < numPts; ++i) {
226
+ transformCoordinate.setValue(points.getPoint(i));
227
+ var v = transformCoordinate.getComputedDoubleViewportValue(ren);
228
+ p.setPoint(i, v[0], v[1], 0.0);
229
+ }
230
+
231
+ points = p;
232
+ }
233
+
234
+ var options = {
235
+ points: points,
236
+ tcoords: tcoords,
237
+ colors: c,
238
+ cellOffset: 0,
239
+ haveCellScalars: model.haveCellSCalars,
240
+ customAttributes: model.renderable.getCustomShaderAttributes().map(function (arrayName) {
241
+ return poly.getPointData().getArrayByName(arrayName);
242
+ })
243
+ };
244
+ options.cellOffset += model.primitives[primTypes.Points].getCABO().createVBO(poly.getVerts(), 'verts', representation, options);
245
+ options.cellOffset += model.primitives[primTypes.Lines].getCABO().createVBO(poly.getLines(), 'lines', representation, options);
246
+ options.cellOffset += model.primitives[primTypes.Tris].getCABO().createVBO(poly.getPolys(), 'polys', representation, options);
247
+ options.cellOffset += model.primitives[primTypes.TriStrips].getCABO().createVBO(poly.getStrips(), 'strips', representation, options);
248
+ model.VBOBuildTime.modified();
249
+ model.VBOBuildString = toString;
250
+ }
251
+ };
252
+
253
+ publicAPI.renderPieceDraw = function (ren, actor) {
254
+ var representation = actor.getProperty().getRepresentation();
255
+ var drawSurfaceWithEdges = false;
256
+ var gl = model.context;
257
+ gl.lineWidth(actor.getProperty().getLineWidth());
258
+ gl.depthMask(true); // for every primitive type
259
+
260
+ for (var i = primTypes.Start; i < primTypes.End; i++) {
261
+ // if there are entries
262
+ var cabo = model.primitives[i].getCABO();
263
+
264
+ if (cabo.getElementCount()) {
265
+ // are we drawing edges
266
+ model.drawingEdges = drawSurfaceWithEdges ;
267
+ var mode = publicAPI.getOpenGLMode(representation, i);
268
+
269
+ if (!model.drawingEdges || !model.renderDepth) {
270
+ publicAPI.updateShaders(model.primitives[i], ren, actor);
271
+ gl.drawArrays(mode, 0, cabo.getElementCount());
272
+ }
273
+
274
+ var stride = (mode === gl.POINTS ? 1 : 0) || (mode === gl.LINES ? 2 : 3);
275
+ model.primitiveIDOffset += cabo.getElementCount() / stride;
276
+ }
277
+ } // reset the line width
278
+
279
+
280
+ gl.lineWidth(1);
281
+ };
282
+
283
+ publicAPI.renderPieceFinish = function (ren, actor) {
284
+ if (model.LastBoundBO) {
285
+ model.LastBoundBO.getVAO().release();
286
+ }
287
+ };
288
+
289
+ publicAPI.buildShaders = function (shaders, ren, actor) {
290
+ publicAPI.getShaderTemplate(shaders, ren, actor); // user specified pre replacements
291
+
292
+ var openGLSpec = model.renderable.getViewSpecificProperties().OpenGL;
293
+ var shaderReplacements = null;
294
+
295
+ if (openGLSpec) {
296
+ shaderReplacements = openGLSpec.ShaderReplacements;
297
+ }
298
+
299
+ if (shaderReplacements) {
300
+ for (var i = 0; i < shaderReplacements.length; i++) {
301
+ var currReplacement = shaderReplacements[i];
302
+
303
+ if (currReplacement.replaceFirst) {
304
+ var shaderType = currReplacement.shaderType;
305
+ var ssrc = shaders[shaderType];
306
+ var substituteRes = vtkShaderProgram.substitute(ssrc, currReplacement.originalValue, currReplacement.replacementValue, currReplacement.replaceAll);
307
+ shaders[shaderType] = substituteRes.result;
308
+ }
309
+ }
310
+ }
311
+
312
+ publicAPI.replaceShaderValues(shaders, ren, actor); // user specified post replacements
313
+
314
+ if (shaderReplacements) {
315
+ for (var _i = 0; _i < shaderReplacements.length; _i++) {
316
+ var _currReplacement = shaderReplacements[_i];
317
+
318
+ if (!_currReplacement.replaceFirst) {
319
+ var _shaderType = _currReplacement.shaderType;
320
+ var _ssrc = shaders[_shaderType];
321
+
322
+ var _substituteRes = vtkShaderProgram.substitute(_ssrc, _currReplacement.originalValue, _currReplacement.replacementValue, _currReplacement.replaceAll);
323
+
324
+ shaders[_shaderType] = _substituteRes.result;
325
+ }
326
+ }
327
+ }
328
+ };
329
+
330
+ publicAPI.replaceShaderValues = function (shaders, ren, actor) {
331
+ publicAPI.replaceShaderColor(shaders, ren, actor);
332
+ publicAPI.replaceShaderTCoord(shaders, ren, actor);
333
+ publicAPI.replaceShaderPicking(shaders, ren, actor);
334
+ publicAPI.replaceShaderPositionVC(shaders, ren, actor);
335
+ };
336
+
337
+ publicAPI.replaceShaderColor = function (shaders, ren, actor) {
338
+ var VSSource = shaders.Vertex;
339
+ var GSSource = shaders.Geometry;
340
+ var FSSource = shaders.Fragment;
341
+
342
+ if (model.haveCellScalars) {
343
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Dec', ['uniform samplerBuffer texture1;']).result;
344
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Impl', ['gl_FragData[0] = texelFetchBuffer(texture1, gl_PrimitiveID + PrimitiveIDOffset);']).result;
345
+ }
346
+
347
+ if (model.lastBoundBO.getCABO().getColorComponents() !== 0) {
348
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Color::Dec', ['in vec4 diffuseColor;', 'out vec4 fcolorVSOutput;']).result;
349
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Color::Impl', ['fcolorVSOutput = diffuseColor;']).result;
350
+ GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::Color::Dec', ['in vec4 fcolorVSOutput[];\n', 'out vec4 fcolorGSOutput;']).result;
351
+ GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::Color::Impl', ['fcolorGSOutput = fcolorVSOutput[i];']).result;
352
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Dec', ['in vec4 fcolorVSOutput;']).result;
353
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Impl', ['gl_FragData[0] = fcolorVSOutput;']).result;
354
+ } else {
355
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Dec', ['uniform vec4 diffuseColor;']).result;
356
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Impl', ['gl_FragData[0] = diffuseColor;']).result;
357
+ }
358
+
359
+ shaders.Vertex = VSSource;
360
+ shaders.Geometry = GSSource;
361
+ shaders.Fragment = FSSource;
362
+ };
363
+
364
+ publicAPI.replaceShaderTCoord = function (shaders, ren, actor) {
365
+ if (model.lastBoundBO.getCABO().getTCoordOffset()) {
366
+ var VSSource = shaders.Vertex;
367
+ var GSSource = shaders.Geometry;
368
+ var FSSource = shaders.Fragment;
369
+ var tcdim = model.lastBoundBO.getCABO().getTCoordComponents();
370
+
371
+ if (tcdim === 1) {
372
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::TCoord::Dec', ['in float tcoordMC;', 'out float tcoordVCVSOutput;']).result;
373
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::TCoord::Impl', ['tcoordVCVSOutput = tcoordMC;']).result;
374
+ GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::TCoord::Dec', ['in float tcoordVCVSOutput[];\n', 'out float tcoordVCGSOutput;']).result;
375
+ GSSource = vtkShaderProgram.substitute(GSSource, ['//VTK::TCoord::Impl', 'tcoordVCGSOutput = tcoordVCVSOutput[i];']).result;
376
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::TCoord::Dec', ['in float tcoordVCVSOutput;', 'uniform sampler2D texture1;']).result;
377
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::TCoord::Impl', ['gl_FragData[0] = gl_FragData[0]*texture2D(texture1, vec2(tcoordVCVSOutput,0));']).result;
378
+ } else if (tcdim === 2) {
379
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::TCoord::Dec', ['in vec2 tcoordMC;', 'out vec2 tcoordVCVSOutput;']).result;
380
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::TCoord::Impl', ['tcoordVCVSOutput = tcoordMC;']).result;
381
+ GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::TCoord::Dec', ['in vec2 tcoordVCVSOutput[];\n', 'out vec2 tcoordVCGSOutput;']).result;
382
+ GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::TCoord::Impl', ['tcoordVCGSOutput = tcoordVCVSOutput[i];']).result;
383
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::TCoord::Dec', ['in vec2 tcoordVCVSOutput;', 'uniform sampler2D texture1;']).result;
384
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::TCoord::Impl', ['gl_FragData[0] = gl_FragData[0]*texture2D(texture1, tcoordVCVSOutput.st);']).result;
385
+ }
386
+
387
+ if (model.haveCellScalars) {
388
+ GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::PrimID::Impl', ['gl_PrimitiveID = gl_PrimitiveIDIn;']).result;
389
+ }
390
+
391
+ shaders.Vertex = VSSource;
392
+ shaders.Geometry = GSSource;
393
+ shaders.Fragment = FSSource;
394
+ }
395
+ };
396
+
397
+ publicAPI.replaceShaderPicking = function (shaders, ren, actor) {
398
+ var FSSource = shaders.Fragment;
399
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Dec', ['uniform vec3 mapperIndex;', 'uniform int picking;']).result;
400
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', ' gl_FragData[0] = picking != 0 ? vec4(mapperIndex,1.0) : gl_FragData[0];').result;
401
+ shaders.Fragment = FSSource;
402
+ };
403
+
404
+ publicAPI.replaceShaderPositionVC = function (shaders, ren, actor) {
405
+ var VSSource = shaders.Vertex;
406
+ var GSSource = shaders.Geometry;
407
+ var FSSource = shaders.Fragment; // for points make sure to add in the point size
408
+
409
+ if (actor.getProperty().getRepresentation() === Representation.POINTS || model.lastBoundBO.getPrimitiveType() === primTypes.Points) {
410
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::PositionVC::Impl', ['//VTK::PositionVC::Impl', " gl_PointSize = ".concat(actor.getProperty().getPointSize(), ".0;")], false).result;
411
+ }
412
+
413
+ shaders.Vertex = VSSource;
414
+ shaders.Geometry = GSSource;
415
+ shaders.Fragment = FSSource;
416
+ };
417
+
418
+ publicAPI.updateShaders = function (cellBO, ren, actor) {
419
+ model.lastBoundBO = cellBO; // has something changed that would require us to recreate the shader?
420
+
421
+ if (publicAPI.getNeedToRebuildShaders(cellBO, ren, actor)) {
422
+ var shaders = {
423
+ Vertex: null,
424
+ Fragment: null,
425
+ Geometry: null
426
+ };
427
+ publicAPI.buildShaders(shaders, ren, actor); // compile and bind the program if needed
428
+
429
+ var newShader = model.openGLRenderWindow.getShaderCache().readyShaderProgramArray(shaders.Vertex, shaders.Fragment, shaders.Geometry); // if the shader changed reinitialize the VAO
430
+
431
+ if (newShader !== cellBO.getProgram()) {
432
+ cellBO.setProgram(newShader); // reset the VAO as the shader has changed
433
+
434
+ cellBO.getVAO().releaseGraphicsResources();
435
+ }
436
+
437
+ cellBO.getShaderSourceTime().modified();
438
+ } else {
439
+ model.openGLRenderWindow.getShaderCache().readyShaderProgram(cellBO.getProgram());
440
+ }
441
+
442
+ cellBO.getVAO().bind();
443
+ publicAPI.setMapperShaderParameters(cellBO, ren, actor);
444
+ publicAPI.setPropertyShaderParameters(cellBO, ren, actor);
445
+ publicAPI.setCameraShaderParameters(cellBO, ren, actor);
446
+ var listCallbacks = model.renderable.getViewSpecificProperties().ShadersCallbacks;
447
+
448
+ if (listCallbacks) {
449
+ listCallbacks.forEach(function (object) {
450
+ object.callback(object.userData, cellBO, ren, actor);
451
+ });
452
+ }
453
+ };
454
+
455
+ publicAPI.setMapperShaderParameters = function (cellBO, ren, actor) {
456
+ // Now to update the VAO too, if necessary.
457
+ if (cellBO.getProgram().isUniformUsed('PrimitiveIDOffset')) {
458
+ cellBO.getProgram().setUniformi('PrimitiveIDOffset', model.primitiveIDOffset);
459
+ }
460
+
461
+ if (cellBO.getProgram().isAttributeUsed('vertexWC')) {
462
+ if (!cellBO.getVAO().addAttributeArray(cellBO.getProgram(), cellBO.getCABO(), 'vertexWC', cellBO.getCABO().getVertexOffset(), cellBO.getCABO().getStride(), model.context.FLOAT, 3, false)) {
463
+ vtkErrorMacro('Error setting vertexWC in shader VAO.');
464
+ }
465
+ }
466
+
467
+ if (cellBO.getCABO().getElementCount() && (model.VBOBuildTime.getMTime() > cellBO.getAttributeUpdateTime().getMTime() || cellBO.getShaderSourceTime().getMTime() > cellBO.getAttributeUpdateTime().getMTime())) {
468
+ model.renderable.getCustomShaderAttributes().forEach(function (attrName, idx) {
469
+ if (cellBO.getProgram().isAttributeUsed("".concat(attrName, "MC"))) {
470
+ if (!cellBO.getVAO().addAttributeArray(cellBO.getProgram(), cellBO.getCABO(), "".concat(attrName, "MC"), cellBO.getCABO().getCustomData()[idx].offset, cellBO.getCABO().getStride(), model.context.FLOAT, cellBO.getCABO().getCustomData()[idx].components, false)) {
471
+ vtkErrorMacro("Error setting ".concat(attrName, "MC in shader VAO."));
472
+ }
473
+ }
474
+ });
475
+
476
+ if (cellBO.getProgram().isAttributeUsed('tcoordMC') && cellBO.getCABO().getTCoordOffset()) {
477
+ if (!cellBO.getVAO().addAttributeArray(cellBO.getProgram(), cellBO.getCABO(), 'tcoordMC', cellBO.getCABO().getTCoordOffset(), cellBO.getCABO().getStride(), model.context.FLOAT, cellBO.getCABO().getTCoordComponents(), false)) {
478
+ vtkErrorMacro('Error setting tcoordMC in shader VAO.');
479
+ }
480
+ } else {
481
+ cellBO.getVAO().removeAttributeArray('tcoordMC');
482
+ }
483
+
484
+ if (model.internalColorTexture && cellBO.getProgram().isUniformUsed('texture1')) {
485
+ cellBO.getProgram().setUniformi('texture1', model.internalColorTexture.getTextureUnit());
486
+ }
487
+
488
+ var tus = model.openGLActor2D.getActiveTextures();
489
+
490
+ if (tus) {
491
+ for (var index = 0; index < tus.length; ++index) {
492
+ var tex = tus[index];
493
+ var texUnit = tex.getTextureUnit();
494
+ var tname = "texture".concat(texUnit + 1);
495
+
496
+ if (cellBO.getProgram().isUniformUsed(tname)) {
497
+ cellBO.getProgram().setUniformi(tname, texUnit);
498
+ }
499
+ }
500
+ } // handle wide lines
501
+
502
+
503
+ if (publicAPI.haveWideLines(ren, actor)) {
504
+ var gl = model.context;
505
+ var vp = gl.getParameter(gl.VIEWPORT);
506
+ var lineWidth = [1, 1];
507
+ lineWidth[0] = 2.0 * actor.getProperty().getLineWidth() / vp[2];
508
+ lineWidth[1] = 2.0 * actor.getProperty().getLineWidth() / vp[3];
509
+ cellBO.getProgram().setUniform2f('lineWidthNVC', lineWidth);
510
+ }
511
+
512
+ var selector = model.openGLRenderer.getSelector();
513
+ cellBO.getProgram().setUniform3fArray('mapperIndex', selector ? selector.getPropColorValue() : [0.0, 0.0, 0.0]);
514
+ cellBO.getProgram().setUniformi('picking', selector ? selector.getCurrentPass() + 1 : 0);
515
+ }
516
+ };
517
+
518
+ publicAPI.setPropertyShaderParameters = function (cellBO, ren, actor) {
519
+ var c = model.renderable.getColorMapColors();
520
+
521
+ if (!c || c.getNumberOfComponents() === 0) {
522
+ var program = cellBO.getProgram();
523
+ var ppty = actor.getProperty();
524
+ var opacity = ppty.getOpacity();
525
+ var dColor = ppty.getColor();
526
+ var diffuseColor = [dColor[0], dColor[1], dColor[2], opacity];
527
+ program.setUniform4f('diffuseColor', diffuseColor);
528
+ }
529
+ };
530
+
531
+ function safeMatrixMultiply(matrixArray, matrixType, tmpMat) {
532
+ matrixType.identity(tmpMat);
533
+ return matrixArray.reduce(function (res, matrix, index) {
534
+ if (index === 0) {
535
+ return matrix ? matrixType.copy(res, matrix) : matrixType.identity(res);
536
+ }
537
+
538
+ return matrix ? matrixType.multiply(res, res, matrix) : res;
539
+ }, tmpMat);
540
+ }
541
+
542
+ publicAPI.setCameraShaderParameters = function (cellBO, ren, actor) {
543
+ var program = cellBO.getProgram();
544
+ var shiftScaleEnabled = cellBO.getCABO().getCoordShiftAndScaleEnabled();
545
+ var inverseShiftScaleMatrix = shiftScaleEnabled ? cellBO.getCABO().getInverseShiftAndScaleMatrix() : null; // Get the position of the actor
546
+
547
+ var size = model.openGLRenderer.getTiledSizeAndOrigin();
548
+ var vport = ren.getViewport();
549
+ var actorPos = actor.getActualPositionCoordinate().getComputedViewportValue(ren); // Get the window info
550
+ // const tileViewport = ren.getVTKWindow().getTileViewport();
551
+ // Assume tile viewport is 0 1 based on vtkOpenGLRenderer
552
+
553
+ var tileViewport = [0.0, 0.0, 1.0, 1.0];
554
+ var visVP = [0, 1, 0, 1];
555
+ visVP[0] = vport[0] >= tileViewport[0] ? vport[0] : tileViewport[0];
556
+ visVP[1] = vport[1] >= tileViewport[1] ? vport[1] : tileViewport[1];
557
+ visVP[2] = vport[2] >= tileViewport[2] ? vport[2] : tileViewport[2];
558
+ visVP[3] = vport[3] >= tileViewport[3] ? vport[3] : tileViewport[3];
559
+
560
+ if (visVP[0] >= visVP[2]) {
561
+ return;
562
+ }
563
+
564
+ if (visVP[1] >= visVP[3]) {
565
+ return;
566
+ }
567
+
568
+ size.usize = round(size.usize * (visVP[2] - visVP[0]) / (vport[2] - vport[0]));
569
+ size.vsize = round(size.vsize * (visVP[3] - visVP[1]) / (vport[3] - vport[1]));
570
+ var winSize = model.openGLRenderer.getParent().getSize();
571
+ var xoff = round(actorPos[0] - (visVP[0] - vport[0]) * winSize[0]);
572
+ var yoff = round(actorPos[1] - (visVP[1] - vport[1]) * winSize[1]); // set ortho projection
573
+
574
+ var left = -xoff;
575
+ var right = -xoff + size.usize;
576
+ var bottom = -yoff;
577
+ var top = -yoff + size.vsize; // it's an error to call glOrtho with
578
+ // either left==right or top==bottom
579
+
580
+ if (left === right) {
581
+ right = left + 1.0;
582
+ }
583
+
584
+ if (bottom === top) {
585
+ top = bottom + 1.0;
586
+ } // compute the combined ModelView matrix and send it down to save time in the shader
587
+
588
+
589
+ var tmpMat4 = mat4.identity(new Float64Array(16));
590
+ tmpMat4[0] = 2.0 / (right - left);
591
+ tmpMat4[1 * 4 + 1] = 2.0 / (top - bottom);
592
+ tmpMat4[0 * 4 + 3] = -1.0 * (right + left) / (right - left);
593
+ tmpMat4[1 * 4 + 3] = -1.0 * (top + bottom) / (top - bottom);
594
+ tmpMat4[2 * 4 + 2] = 0.0;
595
+ tmpMat4[2 * 4 + 3] = actor.getProperty().getDisplayLocation() === DisplayLocation.FOREGROUND ? -1.0 : 1.0;
596
+ tmpMat4[3 * 4 + 3] = 1.0;
597
+ mat4.transpose(tmpMat4, tmpMat4);
598
+ program.setUniformMatrix('WCVCMatrix', safeMatrixMultiply([tmpMat4, inverseShiftScaleMatrix], mat4, model.tmpMat4));
599
+ };
600
+
601
+ publicAPI.haveWideLines = function (ren, actor) {
602
+ if (model.lastBoundBO === model.lines && actor.getProperty().getLineWidth() > 1.0) {
603
+ // we have wide lines, but the OpenGL implementation may
604
+ // actually support them, check the range to see if we
605
+ // really need have to implement our own wide lines
606
+ // vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(ren->GetVTKWindow());
607
+ // return !(
608
+ // renWin && renWin->GetMaximumHardwareLineWidth() >= actor->GetProperty()->GetLineWidth());
609
+ return true;
610
+ }
611
+
612
+ return false;
613
+ };
614
+ } // ----------------------------------------------------------------------------
615
+ // Object factory
616
+ // ----------------------------------------------------------------------------
617
+
618
+
619
+ var DEFAULT_VALUES = {
620
+ context: null,
621
+ VBOBuildTime: 0,
622
+ VBOBuildString: null,
623
+ primitives: null,
624
+ primTypes: null,
625
+ shaderRebuildString: null
626
+ }; // ----------------------------------------------------------------------------
627
+
628
+ function extend(publicAPI, model) {
629
+ var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
630
+ Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance
631
+
632
+ vtkViewNode.extend(publicAPI, model, initialValues);
633
+ vtkReplacementShaderMapper.implementReplaceShaderCoincidentOffset(publicAPI, model, initialValues);
634
+ model.primitives = [];
635
+ model.primTypes = primTypes;
636
+ model.tmpMat4 = mat4.identity(new Float64Array(16));
637
+
638
+ for (var i = primTypes.Start; i < primTypes.End; i++) {
639
+ model.primitives[i] = vtkHelper.newInstance();
640
+ model.primitives[i].setPrimitiveType(i);
641
+ model.primitives[i].set({
642
+ lastLightComplexity: 0,
643
+ lastLightCount: 0,
644
+ lastSelectionPass: false
645
+ }, true);
646
+ } // Build VTK API
647
+
648
+
649
+ setGet(publicAPI, model, ['context']);
650
+ model.VBOBuildTime = {};
651
+ obj(model.VBOBuildTime, {
652
+ mtime: 0
653
+ }); // Object methods
654
+
655
+ vtkOpenGLPolyDataMapper2D(publicAPI, model);
656
+ } // ----------------------------------------------------------------------------
657
+
658
+ var newInstance = newInstance$1(extend, 'vtkOpenGLPolyDataMapper2D'); // ----------------------------------------------------------------------------
659
+
660
+ var vtkPolyDataMapper2D = {
661
+ newInstance: newInstance,
662
+ extend: extend
663
+ }; // Register ourself to OpenGL backend if imported
664
+
665
+ registerOverride('vtkMapper2D', newInstance);
666
+
667
+ export { vtkPolyDataMapper2D as default, extend, newInstance };
@@ -3,6 +3,7 @@ import '../Renderer.js';
3
3
  import '../Actor.js';
4
4
  import '../Actor2D.js';
5
5
  import '../PolyDataMapper.js';
6
+ import '../PolyDataMapper2D.js';
6
7
  import '../Skybox.js';
7
8
  import '../Texture.js';
8
9
  import '../Glyph3DMapper.js';
@@ -3,6 +3,7 @@ import '../Renderer.js';
3
3
  import '../Actor.js';
4
4
  import '../Actor2D.js';
5
5
  import '../PolyDataMapper.js';
6
+ import '../PolyDataMapper2D.js';
6
7
  import '../Skybox.js';
7
8
  import '../Texture.js';
8
9
  import '../PixelSpaceCallbackMapper.js';
@@ -0,0 +1,3 @@
1
+ var vtkPolyData2DFS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkPolyData2DFS.glsl\n\n Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n All rights reserved.\n See Copyright.txt or http://www.kitware.com/Copyright.htm for details.\n\n This software is distributed WITHOUT ANY WARRANTY; without even\n the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n PURPOSE. See the above copyright notice for more information.\n\n=========================================================================*/\n\nuniform int PrimitiveIDOffset;\n\n// Texture coordinates\n//VTK::TCoord::Dec\n\n// Scalar coloring\n//VTK::Color::Dec\n\n// Depth Peeling\n//VTK::DepthPeeling::Dec\n\n// picking support\n//VTK::Picking::Dec\n\n// the output of this shader\n//VTK::Output::Dec\n\n// Apple Bug\n//VTK::PrimID::Dec\n\nvoid main()\n{\n // Apple Bug\n //VTK::PrimID::Impl\n\n //VTK::Color::Impl\n //VTK::TCoord::Impl\n\n //VTK::DepthPeeling::Impl\n //VTK::Picking::Impl\n\n if (gl_FragData[0].a <= 0.0)\n {\n discard;\n }\n}\n";
2
+
3
+ export { vtkPolyData2DFS as v };