@kitware/vtk.js 23.0.0 → 23.2.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.
Files changed (152) hide show
  1. package/Common/Core/CellArray.d.ts +2 -2
  2. package/Common/Core/DataArray.d.ts +2 -2
  3. package/Common/Core/Endian.d.ts +3 -1
  4. package/Common/Core/ImageHelper.d.ts +1 -1
  5. package/Common/Core/LookupTable.d.ts +2 -2
  6. package/Common/Core/Math.d.ts +1 -1
  7. package/Common/Core/MatrixBuilder.d.ts +1 -1
  8. package/Common/Core/Points.d.ts +2 -2
  9. package/Common/Core/PriorityQueue.d.ts +1 -1
  10. package/Common/Core/ProgressHandler.d.ts +1 -1
  11. package/Common/Core/ScalarsToColors.d.ts +3 -3
  12. package/Common/Core/StringArray.d.ts +1 -1
  13. package/Common/Core/VariantArray.d.ts +1 -1
  14. package/Common/DataModel/Box.d.ts +2 -2
  15. package/Common/DataModel/CardinalSpline1D.d.ts +2 -2
  16. package/Common/DataModel/Cell.d.ts +3 -3
  17. package/Common/DataModel/Cone.d.ts +2 -2
  18. package/Common/DataModel/Cylinder.d.ts +2 -2
  19. package/Common/DataModel/DataSet.d.ts +2 -2
  20. package/Common/DataModel/DataSetAttributes/FieldData.d.ts +1 -1
  21. package/Common/DataModel/DataSetAttributes.d.ts +3 -3
  22. package/Common/DataModel/ImageData.d.ts +2 -2
  23. package/Common/DataModel/KochanekSpline1D.d.ts +1 -1
  24. package/Common/DataModel/Line.d.ts +2 -2
  25. package/Common/DataModel/PiecewiseFunction.d.ts +2 -2
  26. package/Common/DataModel/Plane.d.ts +2 -2
  27. package/Common/DataModel/PointSet.d.ts +3 -3
  28. package/Common/DataModel/PolyData.d.ts +3 -3
  29. package/Common/DataModel/Polygon.d.ts +2 -2
  30. package/Common/DataModel/SelectionNode.d.ts +2 -2
  31. package/Common/DataModel/Sphere.d.ts +2 -2
  32. package/Common/DataModel/Spline1D.d.ts +1 -1
  33. package/Common/DataModel/Spline3D.d.ts +1 -1
  34. package/Common/DataModel/Triangle.d.ts +2 -2
  35. package/Common/Transform/LandmarkTransform.d.ts +2 -2
  36. package/Filters/General/AppendPolyData.d.ts +1 -1
  37. package/Filters/General/ImageCropFilter.d.ts +1 -1
  38. package/Filters/General/ImageOutlineFilter.d.ts +1 -1
  39. package/Filters/General/ImageSliceFilter.d.ts +1 -1
  40. package/Filters/General/ImageStreamline.d.ts +3 -3
  41. package/Filters/General/LineFilter.d.ts +1 -1
  42. package/Filters/General/OutlineFilter.d.ts +1 -1
  43. package/Filters/General/TriangleFilter.d.ts +1 -1
  44. package/Filters/General/TubeFilter.d.ts +2 -2
  45. package/Filters/Sources/Arrow2DSource.d.ts +2 -2
  46. package/Filters/Sources/ArrowSource.d.ts +2 -2
  47. package/Filters/Sources/CircleSource.d.ts +2 -2
  48. package/Filters/Sources/ConeSource.d.ts +2 -2
  49. package/Filters/Sources/CubeSource.d.ts +2 -2
  50. package/Filters/Sources/Cursor3D.d.ts +3 -3
  51. package/Filters/Sources/CylinderSource.d.ts +2 -2
  52. package/Filters/Sources/LineSource.d.ts +2 -2
  53. package/Filters/Sources/PlaneSource.d.ts +2 -2
  54. package/Filters/Sources/PointSource.d.ts +2 -2
  55. package/Filters/Sources/SphereSource.d.ts +2 -2
  56. package/Filters/Texture/TextureMapToPlane.d.ts +1 -1
  57. package/Filters/Texture/TextureMapToSphere.d.ts +1 -1
  58. package/IO/Core/DataAccessHelper.d.ts +4 -4
  59. package/IO/Core/HttpDataSetReader.d.ts +5 -5
  60. package/IO/Core/HttpSceneLoader.d.ts +5 -5
  61. package/IO/Core/ImageStream/DefaultProtocol.d.ts +1 -1
  62. package/IO/Core/ImageStream/ViewStream.d.ts +4 -4
  63. package/IO/Core/ImageStream.d.ts +3 -3
  64. package/IO/Core/WSLinkClient.d.ts +1 -1
  65. package/IO/Geometry/DracoReader.d.ts +5 -5
  66. package/IO/Geometry/PLYReader.d.ts +5 -5
  67. package/IO/Geometry/PLYWriter.d.ts +2 -2
  68. package/IO/Geometry/STLReader.d.ts +5 -5
  69. package/IO/Geometry/STLWriter.d.ts +2 -2
  70. package/IO/Misc/ElevationReader.d.ts +5 -5
  71. package/IO/Misc/ITKImageReader.d.ts +1 -1
  72. package/IO/Misc/ITKPolyDataReader.d.ts +1 -1
  73. package/IO/Misc/JSONNucleoReader.d.ts +5 -5
  74. package/IO/Misc/JSONReader.d.ts +1 -1
  75. package/IO/Misc/MTLReader.d.ts +6 -6
  76. package/IO/Misc/OBJReader.d.ts +5 -5
  77. package/IO/Misc/PDBReader.d.ts +5 -5
  78. package/IO/XML/XMLImageDataReader.d.ts +1 -1
  79. package/IO/XML/XMLPolyDataReader.d.ts +1 -1
  80. package/IO/XML/XMLReader.d.ts +5 -5
  81. package/Interaction/Manipulators/MouseRangeManipulator.js +55 -1
  82. package/Interaction/Widgets/OrientationMarkerWidget.d.ts +12 -10
  83. package/Rendering/Core/AbstractMapper.d.ts +2 -2
  84. package/Rendering/Core/AbstractMapper3D.d.ts +2 -2
  85. package/Rendering/Core/AbstractPicker.d.ts +4 -4
  86. package/Rendering/Core/Actor.d.ts +4 -4
  87. package/Rendering/Core/Actor2D.d.ts +5 -5
  88. package/Rendering/Core/AnnotatedCubeActor.d.ts +1 -1
  89. package/Rendering/Core/AxesActor.d.ts +1 -1
  90. package/Rendering/Core/Camera.d.ts +2 -2
  91. package/Rendering/Core/CellPicker.d.ts +5 -5
  92. package/Rendering/Core/ColorTransferFunction.d.ts +1 -1
  93. package/Rendering/Core/Coordinate.d.ts +2 -2
  94. package/Rendering/Core/Follower.d.ts +2 -2
  95. package/Rendering/Core/Glyph3DMapper.d.ts +2 -2
  96. package/Rendering/Core/ImageMapper.d.ts +3 -3
  97. package/Rendering/Core/ImageProperty.d.ts +2 -2
  98. package/Rendering/Core/ImageSlice.d.ts +4 -4
  99. package/Rendering/Core/Light.d.ts +2 -2
  100. package/Rendering/Core/Mapper.d.ts +5 -5
  101. package/Rendering/Core/Mapper2D.d.ts +4 -3
  102. package/Rendering/Core/Picker.d.ts +5 -5
  103. package/Rendering/Core/PixelSpaceCallbackMapper.d.ts +2 -2
  104. package/Rendering/Core/PointPicker.d.ts +3 -3
  105. package/Rendering/Core/Prop.d.ts +5 -5
  106. package/Rendering/Core/Prop3D.d.ts +2 -2
  107. package/Rendering/Core/Property.d.ts +2 -2
  108. package/Rendering/Core/Property2D.d.ts +2 -2
  109. package/Rendering/Core/RenderWindow.d.ts +4 -4
  110. package/Rendering/Core/RenderWindowInteractor.d.ts +2 -2
  111. package/Rendering/Core/Renderer.d.ts +12 -11
  112. package/Rendering/Core/ScalarBarActor.d.ts +3 -3
  113. package/Rendering/Core/Skybox.d.ts +1 -1
  114. package/Rendering/Core/SphereMapper.d.ts +1 -1
  115. package/Rendering/Core/StickMapper.d.ts +1 -1
  116. package/Rendering/Core/Texture.d.ts +1 -1
  117. package/Rendering/Core/Viewport.d.ts +4 -4
  118. package/Rendering/Core/Volume.d.ts +4 -4
  119. package/Rendering/Core/VolumeMapper.d.ts +2 -2
  120. package/Rendering/Core/VolumeProperty.d.ts +1 -1
  121. package/Rendering/Misc/CanvasView.d.ts +2 -2
  122. package/Rendering/Misc/FullScreenRenderWindow.d.ts +8 -8
  123. package/Rendering/Misc/GenericRenderWindow.d.ts +6 -6
  124. package/Rendering/Misc/RemoteView.d.ts +3 -3
  125. package/Rendering/Misc/RenderWindowWithControlBar.d.ts +2 -2
  126. package/Rendering/Misc/SynchronizableRenderWindow.d.ts +4 -3
  127. package/Rendering/Misc/TextureLODsDownloader.d.ts +4 -4
  128. package/Rendering/OpenGL/ForwardPass.js +7 -3
  129. package/Rendering/OpenGL/Framebuffer.js +68 -11
  130. package/Rendering/OpenGL/ImageMapper.js +23 -4
  131. package/Rendering/OpenGL/OrderIndependentTranslucentPass.js +293 -0
  132. package/Rendering/OpenGL/PolyDataMapper.js +20 -2
  133. package/Rendering/OpenGL/RenderWindow.d.ts +18 -18
  134. package/Rendering/OpenGL/ShaderCache.js +10 -2
  135. package/Rendering/OpenGL/Texture.js +32 -16
  136. package/Rendering/OpenGL/glsl/vtkPolyDataFS.glsl.js +1 -1
  137. package/Rendering/SceneGraph/RenderPass.d.ts +2 -2
  138. package/Rendering/SceneGraph/ViewNode.d.ts +2 -2
  139. package/Rendering/SceneGraph/ViewNodeFactory.d.ts +1 -1
  140. package/Rendering/WebGPU/HardwareSelectionPass.js +0 -1
  141. package/Rendering/WebGPU/OrderIndependentTranslucentPass.js +1 -3
  142. package/Rendering/WebGPU/RenderEncoder.js +1 -4
  143. package/Widgets/Manipulators/LineManipulator.d.ts +1 -1
  144. package/Widgets/Manipulators/PlaneManipulator.d.ts +1 -1
  145. package/Widgets/Manipulators/TrackballManipulator.d.ts +1 -1
  146. package/Widgets/Representations/ResliceCursorContextRepresentation.d.ts +1 -1
  147. package/Widgets/Representations/WidgetRepresentation.d.ts +1 -1
  148. package/interfaces.d.ts +4 -4
  149. package/macros.d.ts +1 -1
  150. package/package.json +1 -1
  151. package/types.d.ts +22 -1
  152. package/vtk.d.ts +7 -2
@@ -0,0 +1,293 @@
1
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
+ import macro from '../../macros.js';
3
+ import vtkOpenGLTexture from './Texture.js';
4
+ import vtkOpenGLFramebuffer from './Framebuffer.js';
5
+ import vtkRenderPass from '../SceneGraph/RenderPass.js';
6
+ import vtkDataArray from '../../Common/Core/DataArray.js';
7
+ import vtkHelper from './Helper.js';
8
+ import vtkProperty from '../Core/Property.js';
9
+ import vtkShaderProgram from './ShaderProgram.js';
10
+ import vtkVertexArrayObject from './VertexArrayObject.js';
11
+
12
+ var Representation = vtkProperty.Representation;
13
+ var vtkErrorMacro = macro.vtkErrorMacro; // ----------------------------------------------------------------------------
14
+
15
+ function translucentShaderReplacement(shaders) {
16
+ var substituteRes = vtkShaderProgram.substitute(shaders.Fragment, '//VTK::RenderPassFragmentShader::Impl', "\n float weight = gl_FragData[0].a * pow(max(1.1 - gl_FragCoord.z, 0.0), 2.0);\n gl_FragData[0] = vec4(gl_FragData[0].rgb*weight, gl_FragData[0].a);\n gl_FragData[1].r = weight;\n ", false);
17
+ shaders.Fragment = substituteRes.result;
18
+ }
19
+
20
+ var oitpFragTemplate = "//VTK::System::Dec\n\nin vec2 tcoord;\n\nuniform sampler2D translucentRTexture;\nuniform sampler2D translucentRGBATexture;\n\n// the output of this shader\n//VTK::Output::Dec\n\nvoid main()\n{\n vec4 t1Color = texture(translucentRGBATexture, tcoord);\n float t2Color = texture(translucentRTexture, tcoord).r;\n gl_FragData[0] = vec4(t1Color.rgb/max(t2Color,0.01), 1.0 - t1Color.a);\n}\n";
21
+
22
+ function vtkOpenGLOrderIndependentTranslucentPass(publicAPI, model) {
23
+ // Set our className
24
+ model.classHierarchy.push('vtkOpenGLOrderIndependentTranslucentPass'); // build vertices etc
25
+
26
+ publicAPI.createVertexBuffer = function () {
27
+ // 4 corner points in clipping space in order (x, y, z) where z is always set to -1
28
+ // prettier-ignore
29
+ var ptsArray = new Float32Array([-1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1]); // 4 corresponding corner points in texture space in order (x, y)
30
+
31
+ var tcoordArray = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]); // a square defined as cell relation ship in order (cell_size, v1, v2, v3, v4)
32
+
33
+ var cellArray = new Uint16Array([4, 0, 1, 3, 2]);
34
+ var points = vtkDataArray.newInstance({
35
+ numberOfComponents: 3,
36
+ values: ptsArray
37
+ });
38
+ points.setName('points');
39
+ var tcoords = vtkDataArray.newInstance({
40
+ numberOfComponents: 2,
41
+ values: tcoordArray
42
+ });
43
+ tcoords.setName('tcoords');
44
+ var cells = vtkDataArray.newInstance({
45
+ numberOfComponents: 1,
46
+ values: cellArray
47
+ });
48
+ model.tris.getCABO().createVBO(cells, 'polys', Representation.SURFACE, {
49
+ points: points,
50
+ tcoords: tcoords,
51
+ cellOffset: 0
52
+ });
53
+ model.VBOBuildTime.modified();
54
+ };
55
+
56
+ publicAPI.createFramebuffer = function (viewNode) {
57
+ var _model$framebuffer;
58
+
59
+ var size = viewNode.getSize();
60
+ var gl = viewNode.getContext();
61
+ model.framebuffer = vtkOpenGLFramebuffer.newInstance();
62
+ model.framebuffer.setOpenGLRenderWindow(viewNode);
63
+
64
+ (_model$framebuffer = model.framebuffer).create.apply(_model$framebuffer, _toConsumableArray(size));
65
+
66
+ model.framebuffer.saveCurrentBindingsAndBuffers();
67
+ model.framebuffer.bind();
68
+ model.translucentRGBATexture = vtkOpenGLTexture.newInstance();
69
+ model.translucentRGBATexture.setInternalFormat(gl.RGBA16F);
70
+ model.translucentRGBATexture.setFormat(gl.RGBA);
71
+ model.translucentRGBATexture.setOpenGLDataType(gl.HALF_FLOAT);
72
+ model.translucentRGBATexture.setOpenGLRenderWindow(viewNode);
73
+ model.translucentRGBATexture.create2DFromRaw(size[0], size[1], 4, 'Float32Array', null);
74
+ model.translucentRTexture = vtkOpenGLTexture.newInstance();
75
+ model.translucentRTexture.setInternalFormat(gl.R16F);
76
+ model.translucentRTexture.setFormat(gl.RED);
77
+ model.translucentRTexture.setOpenGLDataType(gl.HALF_FLOAT);
78
+ model.translucentRTexture.setOpenGLRenderWindow(viewNode);
79
+ model.translucentRTexture.create2DFromRaw(size[0], size[1], 1, 'Float32Array', null);
80
+ model.translucentZTexture = vtkOpenGLTexture.newInstance();
81
+ model.translucentZTexture.setOpenGLRenderWindow(viewNode);
82
+ model.translucentZTexture.createDepthFromRaw(size[0], size[1], 'Float32Array', null);
83
+ model.framebuffer.setColorBuffer(model.translucentRGBATexture, 0);
84
+ model.framebuffer.setColorBuffer(model.translucentRTexture, 1);
85
+ model.framebuffer.setDepthBuffer(model.translucentZTexture);
86
+ };
87
+
88
+ publicAPI.createCopyShader = function (viewNode) {
89
+ model.copyShader = viewNode.getShaderCache().readyShaderProgramArray(['//VTK::System::Dec', 'attribute vec4 vertexDC;', 'attribute vec2 tcoordTC;', 'varying vec2 tcoord;', 'void main() { tcoord = tcoordTC; gl_Position = vertexDC; }'].join('\n'), oitpFragTemplate, '');
90
+ };
91
+
92
+ publicAPI.createVBO = function (viewNode) {
93
+ var gl = viewNode.getContext();
94
+ model.tris.setOpenGLRenderWindow(viewNode);
95
+ publicAPI.createVertexBuffer();
96
+ var program = model.copyShader; // prepare the vertex and triangle data for the image plane to render to
97
+
98
+ model.tris.getCABO().bind();
99
+
100
+ if (!model.copyVAO.addAttributeArray(program, model.tris.getCABO(), 'vertexDC', model.tris.getCABO().getVertexOffset(), model.tris.getCABO().getStride(), gl.FLOAT, 3, gl.FALSE)) {
101
+ vtkErrorMacro('Error setting vertexDC in copy shader VAO.');
102
+ }
103
+
104
+ if (!model.copyVAO.addAttributeArray(program, model.tris.getCABO(), 'tcoordTC', model.tris.getCABO().getTCoordOffset(), model.tris.getCABO().getStride(), gl.FLOAT, 2, gl.FALSE)) {
105
+ vtkErrorMacro('Error setting vertexDC in copy shader VAO.');
106
+ }
107
+ };
108
+
109
+ publicAPI.traverse = function (viewNode, renNode, forwardPass) {
110
+ if (model.deleted) {
111
+ return;
112
+ }
113
+
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
125
+ // basic alpha blending
126
+
127
+
128
+ if (!viewNode.getWebgl2() || !gl.getExtension('EXT_color_buffer_half_float') && !gl.getExtension('EXT_color_buffer_float')) {
129
+ console.log('fallback');
130
+ publicAPI.setCurrentOperation('translucentPass');
131
+ renNode.traverse(publicAPI);
132
+ return;
133
+ } // prepare framebuffer // allocate framebuffer if needed and bind it
134
+
135
+
136
+ if (model.framebuffer === null) {
137
+ publicAPI.createFramebuffer(viewNode);
138
+ } else {
139
+ var fbSize = model.framebuffer.getSize();
140
+
141
+ if (fbSize === null || fbSize[0] !== size[0] || fbSize[1] !== size[1]) {
142
+ model.framebuffer.releaseGraphicsResources();
143
+ model.translucentRGBATexture.releaseGraphicsResources(viewNode);
144
+ model.translucentRTexture.releaseGraphicsResources(viewNode);
145
+ model.translucentZTexture.releaseGraphicsResources(viewNode);
146
+ publicAPI.createFramebuffer(viewNode);
147
+ } else {
148
+ // store framebuffer bindings to restore them later
149
+ model.framebuffer.saveCurrentBindingsAndBuffers();
150
+ model.framebuffer.bind();
151
+ }
152
+ }
153
+
154
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
155
+ gl.clearBufferfv(gl.COLOR, 0, [0.0, 0.0, 0.0, 0.0]);
156
+ gl.clearBufferfv(gl.DEPTH, 0, [1.0]);
157
+ gl.colorMask(false, false, false, false); // rerender the opaque pass to set the depth buffer
158
+ // TODO remove when webgl1 is deprecated and instead
159
+ // have the forward pass use a texture backed zbuffer
160
+
161
+ if (forwardPass.getOpaqueActorCount() > 0) {
162
+ forwardPass.setCurrentOperation('opaquePass');
163
+ renNode.traverse(forwardPass);
164
+ }
165
+
166
+ gl.colorMask(true, true, true, true);
167
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1]);
168
+ gl.clearBufferfv(gl.COLOR, 0, [0.0, 0.0, 0.0, 1.0]);
169
+ gl.clearBufferfv(gl.COLOR, 1, [0.0, 0.0, 0.0, 0.0]);
170
+ gl.enable(gl.DEPTH_TEST);
171
+ gl.enable(gl.BLEND); // basic gist is we accumulate color into RGB We compute final opacity
172
+ // into A We store accumulated opacity into R of the R texture.
173
+
174
+ gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ZERO, gl.ONE_MINUS_SRC_ALPHA); // now do the translucent rendering
175
+
176
+ publicAPI.setCurrentOperation('translucentPass');
177
+ renNode.traverse(publicAPI);
178
+ gl.drawBuffers([gl.NONE]);
179
+ model.framebuffer.restorePreviousBindingsAndBuffers(); // gl.drawBuffers([gl.BACK]);
180
+ // make sure the copy shader is ready
181
+
182
+ if (model.copyShader === null) {
183
+ publicAPI.createCopyShader(viewNode);
184
+ } else {
185
+ viewNode.getShaderCache().readyShaderProgram(model.copyShader);
186
+ } // make sure we have a VAO
187
+
188
+
189
+ if (!model.copyVAO) {
190
+ model.copyVAO = vtkVertexArrayObject.newInstance();
191
+ model.copyVAO.setOpenGLRenderWindow(viewNode);
192
+ }
193
+
194
+ model.copyVAO.bind(); // make sure the VBO is up to date
195
+
196
+ if (model.VBOBuildTime.getMTime() < publicAPI.getMTime()) {
197
+ publicAPI.createVBO(viewNode);
198
+ }
199
+
200
+ gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
201
+ gl.depthMask(false);
202
+ gl.depthFunc(gl.ALWAYS);
203
+ gl.viewport(0, 0, size[0], size[1]);
204
+ gl.scissor(0, 0, size[0], size[1]); // activate texture
205
+
206
+ model.translucentRGBATexture.activate();
207
+ model.copyShader.setUniformi('translucentRGBATexture', model.translucentRGBATexture.getTextureUnit());
208
+ model.translucentRTexture.activate();
209
+ model.copyShader.setUniformi('translucentRTexture', model.translucentRTexture.getTextureUnit()); // render quad
210
+
211
+ gl.drawArrays(gl.TRIANGLES, 0, model.tris.getCABO().getElementCount());
212
+ gl.depthMask(true);
213
+ gl.depthFunc(gl.LEQUAL);
214
+ model.translucentRGBATexture.deactivate();
215
+ model.translucentRTexture.deactivate();
216
+ };
217
+
218
+ publicAPI.getShaderReplacement = function () {
219
+ return translucentShaderReplacement;
220
+ };
221
+
222
+ publicAPI.releaseGraphicsResources = function (viewNode) {
223
+ if (model.framebuffer) {
224
+ model.framebuffer.releaseGraphicsResources(viewNode);
225
+ model.framebuffer = null;
226
+ }
227
+
228
+ if (model.translucentRGBATexture) {
229
+ model.translucentRGBATexture.releaseGraphicsResources(viewNode);
230
+ model.translucentRGBATexture = null;
231
+ }
232
+
233
+ if (model.translucentRTexture) {
234
+ model.translucentRTexture.releaseGraphicsResources(viewNode);
235
+ model.translucentRTexture = null;
236
+ }
237
+
238
+ if (model.translucentZTexture) {
239
+ model.translucentZTexture.releaseGraphicsResources(viewNode);
240
+ model.translucentZTexture = null;
241
+ }
242
+
243
+ if (model.copyVAO) {
244
+ model.copyVAO.releaseGraphicsResources(viewNode);
245
+ model.copyVAO = null;
246
+ }
247
+
248
+ if (model.copyShader) {
249
+ model.copyShader.releaseGraphicsResources(viewNode);
250
+ model.copyShader = null;
251
+ }
252
+
253
+ if (model.tris) {
254
+ model.tris.releaseGraphicsResources(viewNode);
255
+ model.tris = null;
256
+ }
257
+
258
+ publicAPI.modified();
259
+ };
260
+ } // ----------------------------------------------------------------------------
261
+ // Object factory
262
+ // ----------------------------------------------------------------------------
263
+
264
+
265
+ var DEFAULT_VALUES = {
266
+ framebuffer: null,
267
+ copyShader: null,
268
+ tris: null
269
+ }; // ----------------------------------------------------------------------------
270
+
271
+ function extend(publicAPI, model) {
272
+ var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
273
+ Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
274
+
275
+ vtkRenderPass.extend(publicAPI, model, initialValues);
276
+ model.VBOBuildTime = {};
277
+ macro.obj(model.VBOBuildTime, {
278
+ mtime: 0
279
+ });
280
+ model.tris = vtkHelper.newInstance();
281
+ macro.get(publicAPI, model, ['framebuffer']); // Object methods
282
+
283
+ vtkOpenGLOrderIndependentTranslucentPass(publicAPI, model);
284
+ } // ----------------------------------------------------------------------------
285
+
286
+ var newInstance = macro.newInstance(extend, 'vtkOpenGLOrderIndependentTranslucentPass'); // ----------------------------------------------------------------------------
287
+
288
+ var vtkOpenGLOrderIndependentTranslucentPass$1 = {
289
+ newInstance: newInstance,
290
+ extend: extend
291
+ };
292
+
293
+ export { vtkOpenGLOrderIndependentTranslucentPass$1 as default, extend, newInstance };
@@ -46,6 +46,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
46
46
 
47
47
  publicAPI.buildPass = function (prepass) {
48
48
  if (prepass) {
49
+ model.currentRenderPass = null;
49
50
  model.openGLActor = publicAPI.getFirstAncestorOfType('vtkOpenGLActor');
50
51
  model.openGLRenderer = model.openGLActor.getFirstAncestorOfType('vtkOpenGLRenderer');
51
52
  model.openGLRenderWindow = model.openGLRenderer.getParent();
@@ -54,8 +55,9 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
54
55
  }; // Renders myself
55
56
 
56
57
 
57
- publicAPI.translucentPass = function (prepass) {
58
+ publicAPI.translucentPass = function (prepass, renderPass) {
58
59
  if (prepass) {
60
+ model.currentRenderPass = renderPass;
59
61
  publicAPI.render();
60
62
  }
61
63
  };
@@ -92,7 +94,12 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
92
94
  };
93
95
 
94
96
  publicAPI.buildShaders = function (shaders, ren, actor) {
95
- publicAPI.getShaderTemplate(shaders, ren, actor); // user specified pre replacements
97
+ publicAPI.getShaderTemplate(shaders, ren, actor); // apply any renderPassReplacements
98
+
99
+ if (model.lastRenderPassShaderReplacement) {
100
+ model.lastRenderPassShaderReplacement(shaders);
101
+ } // user specified pre replacements
102
+
96
103
 
97
104
  var openGLSpec = model.renderable.getViewSpecificProperties().OpenGL;
98
105
  var shaderReplacements = null;
@@ -603,6 +610,17 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
603
610
  lastLightCount: numberOfLights
604
611
  }, true);
605
612
  needRebuild = true;
613
+ } // has the render pass shader replacement changed? Two options
614
+
615
+
616
+ if (!model.currentRenderPass && model.lastRenderPassShaderReplacement) {
617
+ needRebuild = true;
618
+ model.lastRenderPassShaderReplacement = null;
619
+ }
620
+
621
+ if (model.currentRenderPass && model.currentRenderPass.getShaderReplacement() !== model.lastRenderPassShaderReplacement) {
622
+ model.lastRenderPassShaderReplacement = model.currentRenderPass.getShaderReplacement();
623
+ needRebuild = true;
606
624
  } // has something changed that would require us to recreate the shader?
607
625
  // candidates are
608
626
  // property modified (representation interpolation and lighting)
@@ -1,9 +1,9 @@
1
- import { vtkAlgorithm, vtkObject } from '@kitware/vtk.js/interfaces';
2
- import { Size, Vector2, Vector3 } from '@kitware/vtk.js/types';
3
- import { vtkRenderer } from '@kitware/vtk.js/Rendering/Core/Renderer';
4
- import { VtkDataTypes } from '@kitware/vtk.js/Common/Core/DataArray';
5
- import vtkTexture from '@kitware/vtk.js/Rendering/Core/Texture';
6
- import vtkViewStream from '@kitware/vtk.js/IO/Core/ImageStream/ViewStream';
1
+ import { vtkAlgorithm, vtkObject } from '../../interfaces';
2
+ import { Nullable, Size, Vector2, Vector3 } from '../../types';
3
+ import { vtkRenderer } from '../../Rendering/Core/Renderer';
4
+ import { VtkDataTypes } from '../../Common/Core/DataArray';
5
+ import vtkTexture from '../Core/Texture';
6
+ import vtkViewStream from '../../IO/Core/ImageStream/ViewStream';
7
7
 
8
8
  /**
9
9
  *
@@ -199,7 +199,7 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
199
199
  *
200
200
  * @param options
201
201
  */
202
- get3DContext(options: object): WebGLRenderingContext | null;
202
+ get3DContext(options: object): Nullable<WebGLRenderingContext>;
203
203
 
204
204
  /**
205
205
  *
@@ -241,20 +241,20 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
241
241
 
242
242
  /**
243
243
  *
244
- * @param vtktype
245
- * @param numComps
246
- * @param useFloat
244
+ * @param {VtkDataTypes} vtktype
245
+ * @param {Number} numComps
246
+ * @param {Boolean} useFloat
247
247
  */
248
248
  getDefaultTextureInternalFormat(vtktype: VtkDataTypes, numComps: number, useFloat: boolean): void;
249
249
 
250
250
  /**
251
- *
252
- * @param {HTMLImageElement} img
251
+ *
252
+ * @param {HTMLImageElement} img The background image.
253
253
  */
254
254
  setBackgroundImage(img: HTMLImageElement): void;
255
255
 
256
256
  /**
257
- *
257
+ *
258
258
  * @param {Boolean} value
259
259
  */
260
260
  setUseBackgroundImage(value: boolean): void;
@@ -273,7 +273,7 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
273
273
  * @param {String} format
274
274
  * @param {IOptions} options
275
275
  */
276
- captureNextImage(format: string, options: IOptions): Promise<string> | null;
276
+ captureNextImage(format: string, options: IOptions): Nullable<Promise<string>>;
277
277
 
278
278
  /**
279
279
  *
@@ -297,20 +297,20 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
297
297
 
298
298
  /**
299
299
  *
300
- * @param stream
300
+ * @param {vtkViewStream} stream The vtkViewStream instance.
301
301
  */
302
302
  setViewStream(stream: vtkViewStream): boolean;
303
303
 
304
304
  /**
305
305
  *
306
- * @param {Vector2} size
306
+ * @param {Vector2} size
307
307
  */
308
308
  setSize(size: Vector2): void;
309
309
 
310
310
  /**
311
311
  *
312
- * @param {Number} x
313
- * @param {Number} y
312
+ * @param {Number} x
313
+ * @param {Number} y
314
314
  */
315
315
  setSize(x: number, y: number): void;
316
316
 
@@ -46,8 +46,16 @@ function vtkShaderCache(publicAPI, model) {
46
46
  if (gl2) {
47
47
  nVSSource = vtkShaderProgram.substitute(nVSSource, 'varying', 'out').result;
48
48
  nFSSource = vtkShaderProgram.substitute(nFSSource, 'varying', 'in').result;
49
- nFSSource = vtkShaderProgram.substitute(nFSSource, 'gl_FragData\\[0\\]', 'fragOutput0').result;
50
- nFSSource = vtkShaderProgram.substitute(nFSSource, '//VTK::Output::Dec', 'layout(location = 0) out vec4 fragOutput0;').result;
49
+ var shaderOutputs = '';
50
+ var outputCount = 0;
51
+
52
+ while (nFSSource.includes("gl_FragData[".concat(outputCount, "]"))) {
53
+ nFSSource = vtkShaderProgram.substitute(nFSSource, "gl_FragData\\[".concat(outputCount, "\\]"), "fragOutput".concat(outputCount)).result;
54
+ shaderOutputs += "layout(location = ".concat(outputCount, ") out vec4 fragOutput").concat(outputCount, ";\n");
55
+ outputCount++;
56
+ }
57
+
58
+ nFSSource = vtkShaderProgram.substitute(nFSSource, '//VTK::Output::Dec', shaderOutputs).result;
51
59
  } // nFSSource = ShaderProgram.substitute(nFSSource, 'gl_FragData\\[0\\]',
52
60
  // 'gl_FragColor').result;
53
61
 
@@ -456,7 +456,11 @@ function vtkOpenGLTexture(publicAPI, model) {
456
456
 
457
457
  publicAPI.getOpenGLDataType = function (vtkScalarType) {
458
458
  var useHalfFloatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
459
- model.openGLDataType = publicAPI.getDefaultDataType(vtkScalarType, useHalfFloatType);
459
+
460
+ if (!model.openGLDataType) {
461
+ model.openGLDataType = publicAPI.getDefaultDataType(vtkScalarType, useHalfFloatType);
462
+ }
463
+
460
464
  return model.openGLDataType;
461
465
  };
462
466
 
@@ -561,13 +565,17 @@ function vtkOpenGLTexture(publicAPI, model) {
561
565
 
562
566
  if (dataType !== VtkDataTypes.FLOAT && model.openGLDataType === model.context.FLOAT) {
563
567
  for (var idx = 0; idx < data.length; idx++) {
564
- var newArray = new Float32Array(pixCount);
568
+ if (data[idx]) {
569
+ var newArray = new Float32Array(pixCount);
565
570
 
566
- for (var i = 0; i < pixCount; i++) {
567
- newArray[i] = data[idx][i];
568
- }
571
+ for (var i = 0; i < pixCount; i++) {
572
+ newArray[i] = data[idx][i];
573
+ }
569
574
 
570
- pixData.push(newArray);
575
+ pixData.push(newArray);
576
+ } else {
577
+ pixData.push(null);
578
+ }
571
579
  }
572
580
  } // if the opengl data type is ubyte
573
581
  // then the data array must be u8, we currently simply truncate the data
@@ -575,13 +583,17 @@ function vtkOpenGLTexture(publicAPI, model) {
575
583
 
576
584
  if (dataType !== VtkDataTypes.UNSIGNED_CHAR && model.openGLDataType === model.context.UNSIGNED_BYTE) {
577
585
  for (var _idx = 0; _idx < data.length; _idx++) {
578
- var _newArray = new Uint8Array(pixCount);
586
+ if (data[_idx]) {
587
+ var _newArray = new Uint8Array(pixCount);
579
588
 
580
- for (var _i = 0; _i < pixCount; _i++) {
581
- _newArray[_i] = data[_idx][_i];
582
- }
589
+ for (var _i = 0; _i < pixCount; _i++) {
590
+ _newArray[_i] = data[_idx][_i];
591
+ }
583
592
 
584
- pixData.push(_newArray);
593
+ pixData.push(_newArray);
594
+ } else {
595
+ pixData.push(null);
596
+ }
585
597
  }
586
598
  } // if the opengl data type is half float
587
599
  // then the data array must be u16
@@ -592,13 +604,17 @@ function vtkOpenGLTexture(publicAPI, model) {
592
604
 
593
605
  if (halfFloat) {
594
606
  for (var _idx2 = 0; _idx2 < data.length; _idx2++) {
595
- var _newArray2 = new Uint16Array(pixCount);
607
+ if (data[_idx2]) {
608
+ var _newArray2 = new Uint16Array(pixCount);
596
609
 
597
- for (var _i2 = 0; _i2 < pixCount; _i2++) {
598
- _newArray2[_i2] = HalfFloat.toHalf(data[_idx2][_i2]);
599
- }
610
+ for (var _i2 = 0; _i2 < pixCount; _i2++) {
611
+ _newArray2[_i2] = HalfFloat.toHalf(data[_idx2][_i2]);
612
+ }
600
613
 
601
- pixData.push(_newArray2);
614
+ pixData.push(_newArray2);
615
+ } else {
616
+ pixData.push(null);
617
+ }
602
618
  }
603
619
  } // The output has to be filled
604
620
 
@@ -1,3 +1,3 @@
1
- var vtkPolyDataFS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkPolyDataFS.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// Template for the polydata mappers fragment shader\n\nuniform int PrimitiveIDOffset;\n\n// VC position of this fragment\n//VTK::PositionVC::Dec\n\n// optional color passed in from the vertex shader, vertexColor\n//VTK::Color::Dec\n\n// optional surface normal declaration\n//VTK::Normal::Dec\n\n// extra lighting parameters\n//VTK::Light::Dec\n\n// Texture coordinates\n//VTK::TCoord::Dec\n\n// picking support\n//VTK::Picking::Dec\n\n// Depth Peeling Support\n//VTK::DepthPeeling::Dec\n\n// clipping plane vars\n//VTK::Clip::Dec\n\n// the output of this shader\n//VTK::Output::Dec\n\n// Apple Bug\n//VTK::PrimID::Dec\n\n// handle coincident offsets\n//VTK::Coincident::Dec\n\n//VTK::ZBuffer::Dec\n\nvoid main()\n{\n // VC position of this fragment. This should not branch/return/discard.\n //VTK::PositionVC::Impl\n\n // Place any calls that require uniform flow (e.g. dFdx) here.\n //VTK::UniformFlow::Impl\n\n // Set gl_FragDepth here (gl_FragCoord.z by default)\n //VTK::Depth::Impl\n\n // Early depth peeling abort:\n //VTK::DepthPeeling::PreColor\n\n // Apple Bug\n //VTK::PrimID::Impl\n\n //VTK::Clip::Impl\n\n //VTK::Color::Impl\n\n // Generate the normal if we are not passed in one\n //VTK::Normal::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Light::Impl\n\n if (gl_FragData[0].a <= 0.0)\n {\n discard;\n }\n\n //VTK::DepthPeeling::Impl\n\n //VTK::Picking::Impl\n\n // handle coincident offsets\n //VTK::Coincident::Impl\n\n //VTK::ZBuffer::Impl\n}\n";
1
+ var vtkPolyDataFS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkPolyDataFS.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// Template for the polydata mappers fragment shader\n\nuniform int PrimitiveIDOffset;\n\n// VC position of this fragment\n//VTK::PositionVC::Dec\n\n// optional color passed in from the vertex shader, vertexColor\n//VTK::Color::Dec\n\n// optional surface normal declaration\n//VTK::Normal::Dec\n\n// extra lighting parameters\n//VTK::Light::Dec\n\n// Texture coordinates\n//VTK::TCoord::Dec\n\n// picking support\n//VTK::Picking::Dec\n\n// Depth Peeling Support\n//VTK::DepthPeeling::Dec\n\n// clipping plane vars\n//VTK::Clip::Dec\n\n// the output of this shader\n//VTK::Output::Dec\n\n// Apple Bug\n//VTK::PrimID::Dec\n\n// handle coincident offsets\n//VTK::Coincident::Dec\n\n//VTK::ZBuffer::Dec\n\nvoid main()\n{\n // VC position of this fragment. This should not branch/return/discard.\n //VTK::PositionVC::Impl\n\n // Place any calls that require uniform flow (e.g. dFdx) here.\n //VTK::UniformFlow::Impl\n\n // Set gl_FragDepth here (gl_FragCoord.z by default)\n //VTK::Depth::Impl\n\n // Early depth peeling abort:\n //VTK::DepthPeeling::PreColor\n\n // Apple Bug\n //VTK::PrimID::Impl\n\n //VTK::Clip::Impl\n\n //VTK::Color::Impl\n\n // Generate the normal if we are not passed in one\n //VTK::Normal::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Light::Impl\n\n if (gl_FragData[0].a <= 0.0)\n {\n discard;\n }\n\n //VTK::DepthPeeling::Impl\n\n //VTK::Picking::Impl\n\n // handle coincident offsets\n //VTK::Coincident::Impl\n\n //VTK::ZBuffer::Impl\n\n //VTK::RenderPassFragmentShader::Impl\n}\n";
2
2
 
3
3
  export { vtkPolyDataFS as v };
@@ -1,5 +1,5 @@
1
- import { vtkObject } from '@kitware/vtk.js/interfaces';
2
- import vtkViewNode from '@kitware/vtk.js/Rendering/SceneGraph/ViewNode';
1
+ import { vtkObject } from '../../interfaces';
2
+ import vtkViewNode from './ViewNode';
3
3
 
4
4
  /**
5
5
  *
@@ -1,5 +1,5 @@
1
- import { vtkObject } from '@kitware/vtk.js/interfaces';
2
- import vtkRenderPass from '@kitware/vtk.js/Rendering/SceneGraph/RenderPass';
1
+ import { vtkObject } from '../../interfaces';
2
+ import vtkRenderPass from './RenderPass';
3
3
 
4
4
  export enum PASS_TYPES {
5
5
  'Build',
@@ -1,4 +1,4 @@
1
- import { vtkObject } from '@kitware/vtk.js/interfaces';
1
+ import { vtkObject } from '../../interfaces';
2
2
 
3
3
  /**
4
4
  *
@@ -85,7 +85,6 @@ function vtkWebGPUHardwareSelectionPass(publicAPI, model) {
85
85
  });
86
86
  var renDesc = model.selectionRenderEncoder.getDescription();
87
87
  renDesc.colorAttachments[0].clearValue = [0.0, 0.0, 0.0, 0.0];
88
- renDesc.depthStencilAttachment.stencilLoadOp = 'load';
89
88
  model.selectionRenderEncoder.setPipelineSettings({
90
89
  primitive: {
91
90
  cullMode: 'none'
@@ -108,9 +108,7 @@ function vtkWebGPUOrderIndependentTranslucentPass(publicAPI, model) {
108
108
  rDesc.depthStencilAttachment = {
109
109
  view: undefined,
110
110
  depthLoadOp: 'load',
111
- depthStoreOp: 'store',
112
- stencilLoadOp: 'load',
113
- stencilStoreOp: 'store'
111
+ depthStoreOp: 'store'
114
112
  };
115
113
  model.translucentRenderEncoder.setReplaceShaderCodeFunction(function (pipeline) {
116
114
  var fDesc = pipeline.getShaderDescription('fragment');
@@ -145,10 +145,7 @@ function extend(publicAPI, model) {
145
145
  view: undefined,
146
146
  depthLoadOp: 'clear',
147
147
  depthClearValue: 0.0,
148
- depthStoreOp: 'store',
149
- stencilLoadOp: 'clear',
150
- stencilClearValue: 0,
151
- stencilStoreOp: 'store'
148
+ depthStoreOp: 'store'
152
149
  }
153
150
  }; // default shader code just writes out the computedColor
154
151
 
@@ -1,4 +1,4 @@
1
- import { vtkObject } from '@kitware/vtk.js/interfaces';
1
+ import { vtkObject } from '../../interfaces';
2
2
 
3
3
  /**
4
4
  *
@@ -1,4 +1,4 @@
1
- import { vtkObject } from '@kitware/vtk.js/interfaces';
1
+ import { vtkObject } from '../../interfaces';
2
2
 
3
3
  /**
4
4
  *
@@ -1,4 +1,4 @@
1
- import { vtkObject } from '@kitware/vtk.js/interfaces';
1
+ import { vtkObject } from '../../interfaces';
2
2
 
3
3
  /**
4
4
  *
@@ -1,4 +1,4 @@
1
- import {vtkWidgetRepresentation, IWidgetRepresentationInitialValues} from '@kitware/vtk.js/Widgets/Representations/WidgetRepresentation';
1
+ import {vtkWidgetRepresentation, IWidgetRepresentationInitialValues} from './WidgetRepresentation';
2
2
 
3
3
  export interface IResliceCursorContextRepresentationInitialValues extends IWidgetRepresentationInitialValues {
4
4
  axis1Name?: string,
@@ -1,4 +1,4 @@
1
- import vtkProp from '@kitware/vtk.js/Rendering/Core/Prop';
1
+ import vtkProp from '../../Rendering/Core/Prop';
2
2
 
3
3
  export interface IWidgetRepresentationInitialValues {
4
4
  labels?: Array<any>,
package/interfaces.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
2
- import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
3
- import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
4
- import { vtkPipelineConnection } from '@kitware/vtk.js/types';
1
+ import vtkDataArray from '././Common/Core/DataArray';
2
+ import vtkImageData from '././Common/DataModel/ImageData';
3
+ import vtkPolyData from '././Common/DataModel/PolyData';
4
+ import { vtkPipelineConnection } from '././types';
5
5
 
6
6
  /**
7
7
  * Object returned on any subscription call
package/macros.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { vtkSubscription, vtkDebouncedFunction, vtkProperty, vtkPropertyDomain } from '@kitware/vtk.js/interfaces';
1
+ import { vtkSubscription, vtkDebouncedFunction, vtkProperty, vtkPropertyDomain } from '././interfaces';
2
2
 
3
3
  /**
4
4
  * Allow user to redefine vtkXXXMacro method call.