@kitware/vtk.js 28.10.2 → 28.11.1

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 (566) hide show
  1. package/Common/Core/Base64.js +53 -82
  2. package/Common/Core/CellArray.js +52 -60
  3. package/Common/Core/ClassHierarchy.js +8 -36
  4. package/Common/Core/DataArray/Constants.js +6 -6
  5. package/Common/Core/DataArray.js +193 -277
  6. package/Common/Core/Endian.js +14 -17
  7. package/Common/Core/HalfFloat.js +17 -34
  8. package/Common/Core/ImageHelper.js +17 -25
  9. package/Common/Core/LookupTable.js +131 -144
  10. package/Common/Core/Math/Constants.js +8 -8
  11. package/Common/Core/Math/index.js +754 -942
  12. package/Common/Core/Math.js +2 -4
  13. package/Common/Core/MatrixBuilder.js +99 -151
  14. package/Common/Core/Points.js +43 -43
  15. package/Common/Core/PriorityQueue.js +30 -28
  16. package/Common/Core/ProgressHandler.js +31 -32
  17. package/Common/Core/ScalarsToColors/Constants.js +4 -4
  18. package/Common/Core/ScalarsToColors.js +196 -253
  19. package/Common/Core/StringArray.js +48 -73
  20. package/Common/Core/URLExtract.js +10 -29
  21. package/Common/Core/VariantArray.js +48 -73
  22. package/Common/Core.js +11 -11
  23. package/Common/DataModel/AbstractPointLocator.js +19 -17
  24. package/Common/DataModel/BoundingBox.js +322 -490
  25. package/Common/DataModel/Box.js +46 -63
  26. package/Common/DataModel/CardinalSpline1D.js +92 -102
  27. package/Common/DataModel/Cell.js +41 -61
  28. package/Common/DataModel/CellLinks.js +91 -127
  29. package/Common/DataModel/CellTypes/Constants.js +7 -6
  30. package/Common/DataModel/CellTypes.js +55 -74
  31. package/Common/DataModel/Collection.js +45 -61
  32. package/Common/DataModel/Cone.js +28 -20
  33. package/Common/DataModel/Cylinder.js +41 -35
  34. package/Common/DataModel/DataSet/Constants.js +11 -5
  35. package/Common/DataModel/DataSet.js +37 -25
  36. package/Common/DataModel/DataSetAttributes/Constants.js +18 -18
  37. package/Common/DataModel/DataSetAttributes/FieldData.js +103 -194
  38. package/Common/DataModel/DataSetAttributes.js +96 -138
  39. package/Common/DataModel/EdgeLocator.js +45 -70
  40. package/Common/DataModel/ITKHelper.js +67 -137
  41. package/Common/DataModel/ImageData.js +115 -172
  42. package/Common/DataModel/ImplicitBoolean/Constants.js +2 -2
  43. package/Common/DataModel/ImplicitBoolean.js +66 -96
  44. package/Common/DataModel/IncrementalOctreeNode.js +201 -231
  45. package/Common/DataModel/IncrementalOctreePointLocator.js +160 -198
  46. package/Common/DataModel/KochanekSpline1D.js +78 -81
  47. package/Common/DataModel/Line/Constants.js +2 -2
  48. package/Common/DataModel/Line.js +82 -105
  49. package/Common/DataModel/Locator.js +17 -10
  50. package/Common/DataModel/Molecule.js +26 -17
  51. package/Common/DataModel/PiecewiseFunction.js +218 -239
  52. package/Common/DataModel/Plane.js +90 -113
  53. package/Common/DataModel/PointSet.js +30 -26
  54. package/Common/DataModel/PolyData/Constants.js +2 -2
  55. package/Common/DataModel/PolyData.js +95 -120
  56. package/Common/DataModel/PolyLine.js +44 -61
  57. package/Common/DataModel/Polygon/Constants.js +4 -4
  58. package/Common/DataModel/Polygon.js +128 -169
  59. package/Common/DataModel/Quad/Constants.js +2 -2
  60. package/Common/DataModel/Quad.js +61 -100
  61. package/Common/DataModel/SelectionNode/Constants.js +5 -4
  62. package/Common/DataModel/SelectionNode.js +25 -21
  63. package/Common/DataModel/Sphere.js +40 -35
  64. package/Common/DataModel/Spline1D/Constants.js +3 -2
  65. package/Common/DataModel/Spline1D.js +34 -18
  66. package/Common/DataModel/Spline3D/Constants.js +2 -2
  67. package/Common/DataModel/Spline3D.js +46 -41
  68. package/Common/DataModel/StructuredData/Constants.js +2 -2
  69. package/Common/DataModel/StructuredData.js +9 -20
  70. package/Common/DataModel/Triangle.js +207 -250
  71. package/Common/DataModel.js +19 -19
  72. package/Common/System/MobileVR.js +56 -61
  73. package/Common/System/TimerLog.js +1 -1
  74. package/Common/System.js +2 -2
  75. package/Common/Transform/LandmarkTransform/Constants.js +2 -2
  76. package/Common/Transform/LandmarkTransform.js +133 -117
  77. package/Common/Transform/Transform.js +42 -57
  78. package/Common/Transform.js +2 -2
  79. package/Common/index.js +4 -4
  80. package/Filters/Core/Cutter.js +134 -146
  81. package/Filters/Core/PolyDataNormals.js +44 -50
  82. package/Filters/Core.js +2 -2
  83. package/Filters/Cornerstone/ImageDataToCornerstoneImage.js +45 -33
  84. package/Filters/Cornerstone.js +1 -1
  85. package/Filters/General/AppendPolyData.js +84 -100
  86. package/Filters/General/Calculator.js +95 -163
  87. package/Filters/General/ClipClosedSurface/Constants.js +2 -2
  88. package/Filters/General/ClipClosedSurface.js +341 -416
  89. package/Filters/General/ClosedPolyLineToSurfaceFilter.js +141 -156
  90. package/Filters/General/ContourTriangulator/Constants.js +2 -2
  91. package/Filters/General/ContourTriangulator/helper.js +684 -812
  92. package/Filters/General/ContourTriangulator.js +92 -89
  93. package/Filters/General/ImageCropFilter.js +77 -78
  94. package/Filters/General/ImageDataOutlineFilter.js +42 -36
  95. package/Filters/General/ImageMarchingCubes/caseTable.js +9 -521
  96. package/Filters/General/ImageMarchingCubes.js +99 -112
  97. package/Filters/General/ImageMarchingSquares/caseTable.js +9 -41
  98. package/Filters/General/ImageMarchingSquares.js +93 -118
  99. package/Filters/General/ImageOutlineFilter.js +53 -54
  100. package/Filters/General/ImageSliceFilter.js +39 -30
  101. package/Filters/General/ImageStreamline.js +107 -124
  102. package/Filters/General/LineFilter.js +26 -15
  103. package/Filters/General/MoleculeToRepresentation.js +136 -149
  104. package/Filters/General/OBBTree/OBBNode.js +36 -34
  105. package/Filters/General/OBBTree/helper.js +19 -24
  106. package/Filters/General/OBBTree.js +396 -488
  107. package/Filters/General/OutlineFilter.js +52 -34
  108. package/Filters/General/PaintFilter/PaintFilter.worker.js +93 -130
  109. package/Filters/General/PaintFilter.js +150 -162
  110. package/Filters/General/ScalarToRGBA.js +38 -33
  111. package/Filters/General/TriangleFilter.js +65 -62
  112. package/Filters/General/TubeFilter/Constants.js +4 -4
  113. package/Filters/General/TubeFilter.js +376 -496
  114. package/Filters/General/WarpScalar.js +58 -60
  115. package/Filters/General/WindowedSincPolyDataFilter.js +258 -330
  116. package/Filters/General.js +21 -21
  117. package/Filters/Sources/Arrow2DSource/Constants.js +2 -2
  118. package/Filters/Sources/Arrow2DSource.js +56 -56
  119. package/Filters/Sources/ArrowSource.js +39 -29
  120. package/Filters/Sources/CircleSource.js +43 -43
  121. package/Filters/Sources/ConcentricCylinderSource.js +151 -174
  122. package/Filters/Sources/ConeSource.js +51 -42
  123. package/Filters/Sources/CubeSource.js +75 -96
  124. package/Filters/Sources/Cursor3D.js +94 -109
  125. package/Filters/Sources/CylinderSource.js +90 -90
  126. package/Filters/Sources/ImageGridSource.js +43 -43
  127. package/Filters/Sources/LineSource.js +49 -39
  128. package/Filters/Sources/PlaneSource.js +97 -104
  129. package/Filters/Sources/PointSource.js +46 -37
  130. package/Filters/Sources/RTAnalyticSource.js +50 -48
  131. package/Filters/Sources/SLICSource.js +63 -73
  132. package/Filters/Sources/SphereSource.js +88 -78
  133. package/Filters/Sources/ViewFinderSource.js +26 -23
  134. package/Filters/Sources.js +14 -14
  135. package/Filters/Texture/TextureMapToPlane.js +95 -97
  136. package/Filters/Texture/TextureMapToSphere.js +46 -54
  137. package/Filters/Texture.js +2 -2
  138. package/Filters/index.js +5 -5
  139. package/IO/Core/BinaryHelper.js +12 -18
  140. package/IO/Core/DataAccessHelper/HtmlDataAccessHelper.js +43 -59
  141. package/IO/Core/DataAccessHelper/HttpDataAccessHelper.js +76 -113
  142. package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +62 -112
  143. package/IO/Core/DataAccessHelper/LiteHttpDataAccessHelper.js +76 -113
  144. package/IO/Core/DataAccessHelper.js +6 -6
  145. package/IO/Core/HttpDataSetReader.js +136 -139
  146. package/IO/Core/HttpDataSetSeriesReader.js +64 -75
  147. package/IO/Core/HttpSceneLoader.js +130 -179
  148. package/IO/Core/ImageStream/DefaultProtocol.js +29 -43
  149. package/IO/Core/ImageStream/ViewStream.js +100 -103
  150. package/IO/Core/ImageStream.js +62 -54
  151. package/IO/Core/ResourceLoader.js +10 -9
  152. package/IO/Core/Serializer/ArraySerializer.js +40 -40
  153. package/IO/Core/Serializer/FieldDataSerializer.js +18 -28
  154. package/IO/Core/Serializer/ImageDataSerializer.js +22 -23
  155. package/IO/Core/Serializer/PolyDataSerializer.js +17 -21
  156. package/IO/Core/Serializer.js +6 -13
  157. package/IO/Core/WSLinkClient.js +90 -76
  158. package/IO/Core/ZipMultiDataSetReader.js +46 -44
  159. package/IO/Core/ZipMultiDataSetWriter.js +43 -34
  160. package/IO/Core.js +7 -7
  161. package/IO/Geometry/DracoReader.js +118 -121
  162. package/IO/Geometry/PLYReader.js +163 -223
  163. package/IO/Geometry/PLYWriter/Constants.js +5 -5
  164. package/IO/Geometry/PLYWriter.js +139 -154
  165. package/IO/Geometry/STLReader.js +123 -146
  166. package/IO/Geometry/STLWriter/Constants.js +2 -2
  167. package/IO/Geometry/STLWriter.js +83 -82
  168. package/IO/Geometry.js +5 -5
  169. package/IO/Legacy/LegacyAsciiParser.js +78 -139
  170. package/IO/Legacy/PolyDataReader.js +48 -36
  171. package/IO/Legacy.js +2 -2
  172. package/IO/Misc/ElevationReader.js +67 -60
  173. package/IO/Misc/HttpDataSetLODsLoader.js +41 -38
  174. package/IO/Misc/ITKImageReader.js +58 -45
  175. package/IO/Misc/ITKPolyDataReader.js +50 -38
  176. package/IO/Misc/JSONNucleoReader.js +49 -42
  177. package/IO/Misc/JSONReader.js +38 -33
  178. package/IO/Misc/MTLReader.js +74 -119
  179. package/IO/Misc/OBJReader.js +153 -206
  180. package/IO/Misc/PDBReader.js +70 -68
  181. package/IO/Misc/SkyboxReader.js +77 -82
  182. package/IO/Misc.js +9 -9
  183. package/IO/XML/XMLImageDataReader.js +36 -38
  184. package/IO/XML/XMLImageDataWriter.js +28 -21
  185. package/IO/XML/XMLPolyDataReader.js +49 -46
  186. package/IO/XML/XMLPolyDataWriter.js +43 -42
  187. package/IO/XML/XMLReader.js +262 -304
  188. package/IO/XML/XMLWriter/Constants.js +3 -3
  189. package/IO/XML/XMLWriter.js +70 -84
  190. package/IO/XML.js +6 -6
  191. package/IO/index.js +5 -5
  192. package/Imaging/Core/AbstractImageInterpolator/Constants.js +4 -4
  193. package/Imaging/Core/AbstractImageInterpolator/InterpolationInfo.js +30 -27
  194. package/Imaging/Core/AbstractImageInterpolator.js +74 -87
  195. package/Imaging/Core/ImageInterpolator.js +201 -252
  196. package/Imaging/Core/ImagePointDataIterator.js +96 -122
  197. package/Imaging/Core/ImageReslice/Constants.js +2 -2
  198. package/Imaging/Core/ImageReslice.js +327 -464
  199. package/Imaging/Core.js +4 -4
  200. package/Imaging/Hybrid/SampleFunction.js +58 -51
  201. package/Imaging/Hybrid.js +1 -1
  202. package/Imaging/index.js +2 -2
  203. package/Interaction/Animations/TimeStepBasedAnimationHandler.js +39 -54
  204. package/Interaction/Manipulators/CompositeCameraManipulator.js +22 -13
  205. package/Interaction/Manipulators/CompositeGestureManipulator.js +31 -43
  206. package/Interaction/Manipulators/CompositeKeyboardManipulator.js +15 -11
  207. package/Interaction/Manipulators/CompositeMouseManipulator.js +27 -33
  208. package/Interaction/Manipulators/CompositeVRManipulator.js +22 -15
  209. package/Interaction/Manipulators/GestureCameraManipulator.js +54 -36
  210. package/Interaction/Manipulators/KeyboardCameraManipulator.js +95 -97
  211. package/Interaction/Manipulators/MouseBoxSelectorManipulator.js +70 -89
  212. package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +67 -54
  213. package/Interaction/Manipulators/MouseCameraSliceManipulator.js +40 -38
  214. package/Interaction/Manipulators/MouseCameraTrackballFirstPersonManipulator.js +83 -68
  215. package/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator.js +32 -28
  216. package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.js +47 -40
  217. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +55 -43
  218. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +56 -46
  219. package/Interaction/Manipulators/MouseCameraTrackballZoomManipulator.js +41 -46
  220. package/Interaction/Manipulators/MouseCameraTrackballZoomToMouseManipulator.js +29 -27
  221. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +123 -146
  222. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +144 -166
  223. package/Interaction/Manipulators/MouseRangeManipulator.js +127 -132
  224. package/Interaction/Manipulators/VRButtonPanManipulator.js +33 -23
  225. package/Interaction/Manipulators.js +21 -21
  226. package/Interaction/Misc/DeviceOrientationToCamera.js +25 -47
  227. package/Interaction/Misc.js +1 -1
  228. package/Interaction/Style/InteractorStyleImage.js +101 -121
  229. package/Interaction/Style/InteractorStyleMPRSlice.js +111 -128
  230. package/Interaction/Style/InteractorStyleManipulator/Presets.js +9 -17
  231. package/Interaction/Style/InteractorStyleManipulator.js +254 -329
  232. package/Interaction/Style/InteractorStyleRemoteMouse.js +195 -180
  233. package/Interaction/Style/InteractorStyleTrackballCamera.js +154 -157
  234. package/Interaction/Style/InteractorStyleUnicam.js +30 -38
  235. package/Interaction/Style.js +5 -5
  236. package/Interaction/UI/CornerAnnotation/CornerAnnotation.module.css.js +1 -1
  237. package/Interaction/UI/CornerAnnotation.js +65 -48
  238. package/Interaction/UI/FPSMonitor.js +104 -105
  239. package/Interaction/UI/Icons.js +1 -1
  240. package/Interaction/UI/Slider/Constants.js +2 -2
  241. package/Interaction/UI/Slider.js +78 -95
  242. package/Interaction/UI/VolumeController.js +104 -97
  243. package/Interaction/UI.js +5 -5
  244. package/Interaction/Widgets/OrientationMarkerWidget/Constants.js +2 -2
  245. package/Interaction/Widgets/OrientationMarkerWidget.js +90 -135
  246. package/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +0 -3
  247. package/Interaction/Widgets/PiecewiseGaussianWidget.js +381 -498
  248. package/Interaction/Widgets.js +2 -2
  249. package/Interaction/index.js +5 -5
  250. package/Proxy/Animation/AbstractAnimationProxy.js +22 -15
  251. package/Proxy/Animation/AnimationProxyManager.js +43 -51
  252. package/Proxy/Animation/TimeStepBasedAnimationHandlerProxy.js +26 -19
  253. package/Proxy/Core/AbstractRepresentationProxy.js +97 -151
  254. package/Proxy/Core/LookupTableProxy/Constants.js +4 -4
  255. package/Proxy/Core/LookupTableProxy.js +49 -52
  256. package/Proxy/Core/PiecewiseFunctionProxy/Constants.js +4 -4
  257. package/Proxy/Core/PiecewiseFunctionProxy.js +63 -72
  258. package/Proxy/Core/ProxyManager/core.js +83 -106
  259. package/Proxy/Core/ProxyManager/properties.js +53 -76
  260. package/Proxy/Core/ProxyManager/state.js +100 -110
  261. package/Proxy/Core/ProxyManager/view.js +45 -55
  262. package/Proxy/Core/ProxyManager.js +16 -8
  263. package/Proxy/Core/SourceProxy.js +41 -38
  264. package/Proxy/Core/View2DProxy.js +143 -199
  265. package/Proxy/Core/ViewProxy.js +223 -269
  266. package/Proxy/Core.js +7 -7
  267. package/Proxy/Representations/GeometryRepresentationProxy.js +34 -20
  268. package/Proxy/Representations/GlyphRepresentationProxy.js +42 -41
  269. package/Proxy/Representations/MoleculeRepresentationProxy.js +32 -22
  270. package/Proxy/Representations/ResliceRepresentationProxy.js +48 -32
  271. package/Proxy/Representations/SkyboxRepresentationProxy.js +30 -29
  272. package/Proxy/Representations/SliceRepresentationProxy.js +93 -112
  273. package/Proxy/Representations/SlicedGeometryRepresentationProxy.js +46 -42
  274. package/Proxy/Representations/VolumeRepresentationProxy.js +108 -133
  275. package/Proxy/Representations.js +7 -7
  276. package/Proxy/index.js +2 -2
  277. package/README.md +1 -1
  278. package/Rendering/Core/AbstractImageMapper/helper.js +44 -49
  279. package/Rendering/Core/AbstractImageMapper.js +18 -19
  280. package/Rendering/Core/AbstractMapper.js +39 -55
  281. package/Rendering/Core/AbstractMapper3D.js +26 -31
  282. package/Rendering/Core/AbstractPicker.js +25 -21
  283. package/Rendering/Core/Actor.js +71 -93
  284. package/Rendering/Core/Actor2D.js +64 -78
  285. package/Rendering/Core/AnnotatedCubeActor/Presets.js +5 -11
  286. package/Rendering/Core/AnnotatedCubeActor.js +94 -79
  287. package/Rendering/Core/AxesActor.js +65 -87
  288. package/Rendering/Core/Camera.js +246 -271
  289. package/Rendering/Core/CellPicker.js +125 -148
  290. package/Rendering/Core/ColorTransferFunction/ColorMaps.js +20 -21
  291. package/Rendering/Core/ColorTransferFunction/ColorMapsLite.js +20 -21
  292. package/Rendering/Core/ColorTransferFunction/Constants.js +4 -4
  293. package/Rendering/Core/ColorTransferFunction.js +460 -546
  294. package/Rendering/Core/Coordinate/Constants.js +2 -2
  295. package/Rendering/Core/Coordinate.js +119 -198
  296. package/Rendering/Core/CubeAxesActor.js +294 -320
  297. package/Rendering/Core/Follower.js +46 -45
  298. package/Rendering/Core/Glyph3DMapper/Constants.js +4 -4
  299. package/Rendering/Core/Glyph3DMapper.js +96 -148
  300. package/Rendering/Core/HardwareSelector.js +36 -69
  301. package/Rendering/Core/ImageArrayMapper.js +87 -126
  302. package/Rendering/Core/ImageCPRMapper.js +134 -209
  303. package/Rendering/Core/ImageMapper/Constants.js +2 -2
  304. package/Rendering/Core/ImageMapper.js +85 -144
  305. package/Rendering/Core/ImageProperty/Constants.js +2 -2
  306. package/Rendering/Core/ImageProperty.js +66 -81
  307. package/Rendering/Core/ImageResliceMapper/Constants.js +2 -2
  308. package/Rendering/Core/ImageResliceMapper.js +36 -29
  309. package/Rendering/Core/ImageSlice.js +85 -127
  310. package/Rendering/Core/InteractorObserver.js +82 -73
  311. package/Rendering/Core/InteractorStyle/Constants.js +2 -2
  312. package/Rendering/Core/InteractorStyle.js +56 -58
  313. package/Rendering/Core/Light.js +43 -49
  314. package/Rendering/Core/Mapper/CoincidentTopologyHelper.js +37 -48
  315. package/Rendering/Core/Mapper/Constants.js +6 -6
  316. package/Rendering/Core/Mapper/Static.js +15 -12
  317. package/Rendering/Core/Mapper.js +194 -259
  318. package/Rendering/Core/Mapper2D.js +61 -100
  319. package/Rendering/Core/Picker.js +124 -143
  320. package/Rendering/Core/PixelSpaceCallbackMapper.js +40 -37
  321. package/Rendering/Core/PointPicker.js +68 -79
  322. package/Rendering/Core/Prop/Constants.js +2 -2
  323. package/Rendering/Core/Prop.js +58 -106
  324. package/Rendering/Core/Prop3D.js +54 -83
  325. package/Rendering/Core/Property/Constants.js +6 -6
  326. package/Rendering/Core/Property.js +45 -74
  327. package/Rendering/Core/Property2D/Constants.js +2 -2
  328. package/Rendering/Core/Property2D.js +33 -42
  329. package/Rendering/Core/RenderWindow.js +70 -82
  330. package/Rendering/Core/RenderWindowInteractor/Constants.js +7 -7
  331. package/Rendering/Core/RenderWindowInteractor.js +324 -439
  332. package/Rendering/Core/Renderer.js +192 -256
  333. package/Rendering/Core/ScalarBarActor.js +267 -272
  334. package/Rendering/Core/Skybox.js +26 -24
  335. package/Rendering/Core/SphereMapper.js +22 -12
  336. package/Rendering/Core/StickMapper.js +22 -12
  337. package/Rendering/Core/SurfaceLICInterface/Constants.js +6 -6
  338. package/Rendering/Core/SurfaceLICInterface.js +13 -9
  339. package/Rendering/Core/SurfaceLICMapper.js +23 -15
  340. package/Rendering/Core/Texture.js +99 -141
  341. package/Rendering/Core/Viewport.js +60 -88
  342. package/Rendering/Core/Volume.js +55 -77
  343. package/Rendering/Core/VolumeMapper/Constants.js +4 -4
  344. package/Rendering/Core/VolumeMapper.js +59 -91
  345. package/Rendering/Core/VolumeProperty/Constants.js +4 -4
  346. package/Rendering/Core/VolumeProperty.js +78 -115
  347. package/Rendering/Core.js +47 -49
  348. package/Rendering/Misc/CanvasView.js +62 -61
  349. package/Rendering/Misc/FullScreenRenderWindow.js +60 -62
  350. package/Rendering/Misc/GenericRenderWindow.js +48 -37
  351. package/Rendering/Misc/RemoteView.js +86 -80
  352. package/Rendering/Misc/RenderWindowWithControlBar.js +54 -48
  353. package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager/CameraSynchronizer.js +43 -51
  354. package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager.js +52 -82
  355. package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.js +258 -308
  356. package/Rendering/Misc/SynchronizableRenderWindow.js +133 -163
  357. package/Rendering/Misc/TextureLODsDownloader.js +72 -74
  358. package/Rendering/Misc.js +7 -7
  359. package/Rendering/OpenGL/Actor.js +57 -68
  360. package/Rendering/OpenGL/Actor2D.js +56 -56
  361. package/Rendering/OpenGL/BufferObject/Constants.js +2 -2
  362. package/Rendering/OpenGL/BufferObject.js +50 -65
  363. package/Rendering/OpenGL/Camera.js +35 -29
  364. package/Rendering/OpenGL/CellArrayBufferObject.js +119 -149
  365. package/Rendering/OpenGL/Convolution2DPass.js +87 -81
  366. package/Rendering/OpenGL/CubeAxesActor.js +28 -21
  367. package/Rendering/OpenGL/ForwardPass.js +53 -64
  368. package/Rendering/OpenGL/Framebuffer.js +61 -101
  369. package/Rendering/OpenGL/Glyph3DMapper.js +165 -196
  370. package/Rendering/OpenGL/HardwareSelector/Constants.js +2 -2
  371. package/Rendering/OpenGL/HardwareSelector.js +272 -397
  372. package/Rendering/OpenGL/Helper.js +58 -73
  373. package/Rendering/OpenGL/ImageCPRMapper.js +339 -421
  374. package/Rendering/OpenGL/ImageMapper.js +268 -361
  375. package/Rendering/OpenGL/ImageResliceMapper.js +306 -438
  376. package/Rendering/OpenGL/ImageSlice.js +48 -54
  377. package/Rendering/OpenGL/OrderIndependentTranslucentPass.js +102 -84
  378. package/Rendering/OpenGL/PixelSpaceCallbackMapper.js +43 -42
  379. package/Rendering/OpenGL/PolyDataMapper.js +358 -492
  380. package/Rendering/OpenGL/PolyDataMapper2D.js +153 -205
  381. package/Rendering/OpenGL/RadialDistortionPass.js +86 -89
  382. package/Rendering/OpenGL/RenderWindow/Constants.js +2 -2
  383. package/Rendering/OpenGL/RenderWindow/ContextProxy.js +20 -29
  384. package/Rendering/OpenGL/RenderWindow.js +356 -510
  385. package/Rendering/OpenGL/Renderer.js +77 -89
  386. package/Rendering/OpenGL/ReplacementShaderMapper.js +28 -46
  387. package/Rendering/OpenGL/ScalarBarActor.js +28 -21
  388. package/Rendering/OpenGL/Shader.js +37 -31
  389. package/Rendering/OpenGL/ShaderCache.js +67 -74
  390. package/Rendering/OpenGL/ShaderProgram.js +136 -248
  391. package/Rendering/OpenGL/Skybox.js +99 -60
  392. package/Rendering/OpenGL/SphereMapper.js +94 -108
  393. package/Rendering/OpenGL/StickMapper.js +110 -114
  394. package/Rendering/OpenGL/SurfaceLIC/LineIntegralConvolution2D/pingpong.js +91 -157
  395. package/Rendering/OpenGL/SurfaceLIC/LineIntegralConvolution2D.js +142 -151
  396. package/Rendering/OpenGL/SurfaceLIC/SurfaceLICInterface.js +142 -216
  397. package/Rendering/OpenGL/SurfaceLIC/SurfaceLICMapper.js +79 -100
  398. package/Rendering/OpenGL/SurfaceLIC.js +2 -2
  399. package/Rendering/OpenGL/Texture/Constants.js +4 -4
  400. package/Rendering/OpenGL/Texture.js +443 -608
  401. package/Rendering/OpenGL/TextureUnitManager.js +47 -43
  402. package/Rendering/OpenGL/VertexArrayObject.js +92 -131
  403. package/Rendering/OpenGL/ViewNodeFactory.js +25 -13
  404. package/Rendering/OpenGL/Volume.js +38 -34
  405. package/Rendering/OpenGL/VolumeMapper.js +437 -547
  406. package/Rendering/OpenGL.js +28 -28
  407. package/Rendering/SceneGraph/RenderPass.js +34 -31
  408. package/Rendering/SceneGraph/RenderWindowViewNode.js +68 -94
  409. package/Rendering/SceneGraph/ViewNode.js +82 -111
  410. package/Rendering/SceneGraph/ViewNodeFactory.js +31 -26
  411. package/Rendering/SceneGraph.js +4 -4
  412. package/Rendering/WebGPU/Actor.js +49 -49
  413. package/Rendering/WebGPU/Actor2D.js +45 -44
  414. package/Rendering/WebGPU/BindGroup.js +43 -50
  415. package/Rendering/WebGPU/Buffer.js +41 -50
  416. package/Rendering/WebGPU/BufferManager/Constants.js +4 -4
  417. package/Rendering/WebGPU/BufferManager.js +111 -141
  418. package/Rendering/WebGPU/Camera.js +65 -67
  419. package/Rendering/WebGPU/CellArrayMapper.js +621 -388
  420. package/Rendering/WebGPU/CubeAxesActor.js +28 -19
  421. package/Rendering/WebGPU/Device.js +78 -133
  422. package/Rendering/WebGPU/ForwardPass.js +75 -72
  423. package/Rendering/WebGPU/FullScreenQuad.js +25 -18
  424. package/Rendering/WebGPU/Glyph3DMapper.js +62 -74
  425. package/Rendering/WebGPU/HardwareSelectionPass.js +45 -38
  426. package/Rendering/WebGPU/HardwareSelector.js +200 -276
  427. package/Rendering/WebGPU/ImageMapper.js +180 -171
  428. package/Rendering/WebGPU/ImageSlice.js +45 -44
  429. package/Rendering/WebGPU/IndexBuffer.js +166 -200
  430. package/Rendering/WebGPU/OpaquePass.js +37 -36
  431. package/Rendering/WebGPU/OrderIndependentTranslucentPass.js +72 -45
  432. package/Rendering/WebGPU/Pipeline.js +37 -51
  433. package/Rendering/WebGPU/PixelSpaceCallbackMapper.js +27 -19
  434. package/Rendering/WebGPU/PolyDataMapper.js +50 -53
  435. package/Rendering/WebGPU/PolyDataMapper2D.js +39 -39
  436. package/Rendering/WebGPU/RenderEncoder.js +68 -88
  437. package/Rendering/WebGPU/RenderWindow.js +262 -376
  438. package/Rendering/WebGPU/Renderer.js +224 -208
  439. package/Rendering/WebGPU/Sampler.js +27 -21
  440. package/Rendering/WebGPU/ScalarBarActor.js +28 -19
  441. package/Rendering/WebGPU/ShaderCache.js +43 -41
  442. package/Rendering/WebGPU/ShaderDescription.js +52 -59
  443. package/Rendering/WebGPU/ShaderModule.js +26 -17
  444. package/Rendering/WebGPU/SimpleMapper.js +185 -121
  445. package/Rendering/WebGPU/SphereMapper.js +200 -130
  446. package/Rendering/WebGPU/StickMapper.js +289 -152
  447. package/Rendering/WebGPU/StorageBuffer.js +100 -115
  448. package/Rendering/WebGPU/Texture.js +79 -99
  449. package/Rendering/WebGPU/TextureManager.js +52 -54
  450. package/Rendering/WebGPU/TextureView.js +40 -43
  451. package/Rendering/WebGPU/Types.js +53 -70
  452. package/Rendering/WebGPU/UniformBuffer.js +158 -184
  453. package/Rendering/WebGPU/VertexInput.js +64 -90
  454. package/Rendering/WebGPU/ViewNodeFactory.js +25 -13
  455. package/Rendering/WebGPU/Volume.js +52 -51
  456. package/Rendering/WebGPU/VolumePass.js +218 -239
  457. package/Rendering/WebGPU/VolumePassFSQ.js +625 -306
  458. package/Rendering/WebGPU.js +1 -1
  459. package/Rendering/index.js +5 -5
  460. package/Widgets/Core/AbstractWidget/Constants.js +2 -2
  461. package/Widgets/Core/AbstractWidget.js +49 -58
  462. package/Widgets/Core/AbstractWidgetFactory.js +101 -122
  463. package/Widgets/Core/StateBuilder/boundsMixin.js +23 -28
  464. package/Widgets/Core/StateBuilder/color3Mixin.js +10 -7
  465. package/Widgets/Core/StateBuilder/colorMixin.js +10 -6
  466. package/Widgets/Core/StateBuilder/cornerMixin.js +16 -15
  467. package/Widgets/Core/StateBuilder/directionMixin.js +20 -18
  468. package/Widgets/Core/StateBuilder/manipulatorMixin.js +26 -18
  469. package/Widgets/Core/StateBuilder/nameMixin.js +10 -6
  470. package/Widgets/Core/StateBuilder/orientationMixin.js +19 -16
  471. package/Widgets/Core/StateBuilder/originMixin.js +25 -32
  472. package/Widgets/Core/StateBuilder/scale1Mixin.js +10 -6
  473. package/Widgets/Core/StateBuilder/scale3Mixin.js +10 -6
  474. package/Widgets/Core/StateBuilder/shapeMixin.js +12 -6
  475. package/Widgets/Core/StateBuilder/textMixin.js +10 -6
  476. package/Widgets/Core/StateBuilder/visibleMixin.js +10 -6
  477. package/Widgets/Core/StateBuilder.js +120 -149
  478. package/Widgets/Core/WidgetManager/Constants.js +7 -7
  479. package/Widgets/Core/WidgetManager.js +249 -421
  480. package/Widgets/Core/WidgetState.js +48 -57
  481. package/Widgets/Core.js +5 -5
  482. package/Widgets/Manipulators/AbstractManipulator.js +20 -14
  483. package/Widgets/Manipulators/CPRManipulator.js +55 -71
  484. package/Widgets/Manipulators/LineManipulator.js +31 -28
  485. package/Widgets/Manipulators/PickerManipulator.d.ts +48 -0
  486. package/Widgets/Manipulators/PickerManipulator.js +65 -0
  487. package/Widgets/Manipulators/PlaneManipulator.js +26 -23
  488. package/Widgets/Manipulators/TrackballManipulator.js +39 -35
  489. package/Widgets/Manipulators.js +4 -2
  490. package/Widgets/Representations/ArrowHandleRepresentation.js +148 -162
  491. package/Widgets/Representations/CircleContextRepresentation.js +44 -38
  492. package/Widgets/Representations/ContextRepresentation.js +17 -14
  493. package/Widgets/Representations/ConvexFaceContextRepresentation.js +50 -47
  494. package/Widgets/Representations/CroppingOutlineRepresentation.js +38 -27
  495. package/Widgets/Representations/CubeHandleRepresentation.js +21 -18
  496. package/Widgets/Representations/GlyphRepresentation.js +107 -152
  497. package/Widgets/Representations/HandleRepresentation.js +17 -14
  498. package/Widgets/Representations/ImplicitPlaneRepresentation.js +97 -91
  499. package/Widgets/Representations/LineHandleRepresentation.js +44 -41
  500. package/Widgets/Representations/OutlineContextRepresentation.js +42 -36
  501. package/Widgets/Representations/PolyLineRepresentation.js +60 -75
  502. package/Widgets/Representations/RectangleContextRepresentation.js +42 -37
  503. package/Widgets/Representations/SphereContextRepresentation.js +19 -27
  504. package/Widgets/Representations/SphereHandleRepresentation.js +31 -27
  505. package/Widgets/Representations/SplineContextRepresentation.js +46 -70
  506. package/Widgets/Representations/WidgetRepresentation/Constants.js +2 -2
  507. package/Widgets/Representations/WidgetRepresentation.js +99 -134
  508. package/Widgets/Representations.js +13 -13
  509. package/Widgets/Widgets3D/AngleWidget/behavior.js +41 -63
  510. package/Widgets/Widgets3D/AngleWidget.js +40 -38
  511. package/Widgets/Widgets3D/DistanceWidget/behavior.js +40 -61
  512. package/Widgets/Widgets3D/DistanceWidget.js +38 -36
  513. package/Widgets/Widgets3D/EllipseWidget/behavior.js +14 -19
  514. package/Widgets/Widgets3D/EllipseWidget/state.js +4 -2
  515. package/Widgets/Widgets3D/EllipseWidget.js +37 -26
  516. package/Widgets/Widgets3D/ImageCroppingWidget/behavior.js +26 -56
  517. package/Widgets/Widgets3D/ImageCroppingWidget/helpers.js +14 -17
  518. package/Widgets/Widgets3D/ImageCroppingWidget/state.js +20 -16
  519. package/Widgets/Widgets3D/ImageCroppingWidget.js +80 -98
  520. package/Widgets/Widgets3D/ImplicitPlaneWidget.js +55 -77
  521. package/Widgets/Widgets3D/InteractiveOrientationWidget/behavior.js +17 -18
  522. package/Widgets/Widgets3D/InteractiveOrientationWidget/state.js +15 -7
  523. package/Widgets/Widgets3D/InteractiveOrientationWidget.js +30 -29
  524. package/Widgets/Widgets3D/LabelWidget/behavior.js +37 -62
  525. package/Widgets/Widgets3D/LabelWidget.js +31 -25
  526. package/Widgets/Widgets3D/LineWidget/Constants.js +8 -8
  527. package/Widgets/Widgets3D/LineWidget/behavior.js +77 -114
  528. package/Widgets/Widgets3D/LineWidget/helpers.js +13 -20
  529. package/Widgets/Widgets3D/LineWidget/state.js +2 -1
  530. package/Widgets/Widgets3D/LineWidget.js +39 -35
  531. package/Widgets/Widgets3D/PaintWidget/behavior.js +24 -59
  532. package/Widgets/Widgets3D/PaintWidget.js +39 -37
  533. package/Widgets/Widgets3D/PolyLineWidget/behavior.js +44 -68
  534. package/Widgets/Widgets3D/PolyLineWidget.js +36 -31
  535. package/Widgets/Widgets3D/RectangleWidget/behavior.js +6 -11
  536. package/Widgets/Widgets3D/RectangleWidget/state.js +4 -2
  537. package/Widgets/Widgets3D/RectangleWidget.js +37 -25
  538. package/Widgets/Widgets3D/ResliceCursorWidget/Constants.js +35 -21
  539. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +133 -209
  540. package/Widgets/Widgets3D/ResliceCursorWidget/cprBehavior.js +26 -41
  541. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +89 -116
  542. package/Widgets/Widgets3D/ResliceCursorWidget/state.js +33 -40
  543. package/Widgets/Widgets3D/ResliceCursorWidget.js +186 -227
  544. package/Widgets/Widgets3D/SeedWidget/behavior.js +82 -0
  545. package/Widgets/Widgets3D/SeedWidget/state.js +18 -0
  546. package/Widgets/Widgets3D/SeedWidget.d.ts +44 -0
  547. package/Widgets/Widgets3D/SeedWidget.js +43 -0
  548. package/Widgets/Widgets3D/ShapeWidget/Constants.js +19 -19
  549. package/Widgets/Widgets3D/ShapeWidget/behavior.js +150 -252
  550. package/Widgets/Widgets3D/ShapeWidget.js +24 -27
  551. package/Widgets/Widgets3D/SphereWidget/behavior.js +35 -69
  552. package/Widgets/Widgets3D/SphereWidget/state.js +9 -5
  553. package/Widgets/Widgets3D/SphereWidget.js +34 -44
  554. package/Widgets/Widgets3D/SplineWidget/behavior.js +85 -120
  555. package/Widgets/Widgets3D/SplineWidget.js +43 -39
  556. package/Widgets/Widgets3D.js +15 -15
  557. package/Widgets/index.js +4 -4
  558. package/_virtual/rollup-plugin-worker-loader__module_Sources/Filters/General/PaintFilter/PaintFilter.worker.js +95 -207
  559. package/_virtual/rollup-plugin-worker-loader__module_Sources/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +0 -3
  560. package/favicon.js +5 -6
  561. package/index.d.ts +4 -2
  562. package/index.js +4 -3
  563. package/macros.js +4 -1931
  564. package/macros2.js +1684 -0
  565. package/package.json +6 -6
  566. package/vtk.js +18 -31
@@ -1,5 +1,5 @@
1
1
  import { mat3, mat4 } from 'gl-matrix';
2
- import { newInstance as newInstance$1, setGet } from '../../macros.js';
2
+ import { n as newInstance$1, e as setGet } from '../../macros2.js';
3
3
  import vtkMapper from '../Core/Mapper.js';
4
4
  import vtkProp from '../Core/Prop.js';
5
5
  import vtkProperty from '../Core/Property.js';
@@ -11,28 +11,350 @@ import vtkWebGPUUniformBuffer from './UniformBuffer.js';
11
11
  import vtkWebGPUSimpleMapper from './SimpleMapper.js';
12
12
  import vtkWebGPUTypes from './Types.js';
13
13
 
14
- var BufferUsage = vtkWebGPUBufferManager.BufferUsage,
15
- PrimitiveTypes = vtkWebGPUBufferManager.PrimitiveTypes;
16
- var Representation = vtkProperty.Representation;
17
- var ScalarMode = vtkMapper.ScalarMode;
18
- var CoordinateSystem = vtkProp.CoordinateSystem;
19
- var DisplayLocation = vtkProperty2D.DisplayLocation;
20
- var vtkWebGPUPolyDataVS = "\n//VTK::Renderer::Dec\n\n//VTK::Color::Dec\n\n//VTK::Normal::Dec\n\n//VTK::TCoord::Dec\n\n//VTK::Select::Dec\n\n//VTK::Mapper::Dec\n\n//VTK::IOStructs::Dec\n\n@vertex\nfn main(\n//VTK::IOStructs::Input\n)\n//VTK::IOStructs::Output\n{\n var output : vertexOutput;\n\n var vertex: vec4<f32> = vertexBC;\n\n //VTK::Color::Impl\n\n //VTK::Normal::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Select::Impl\n\n //VTK::Position::Impl\n\n return output;\n}\n";
21
- var vtkWebGPUPolyDataFS = "\nstruct PBRData {\n diffuse: vec3<f32>,\n specular: vec3<f32>,\n}\n\n// Dot product with the max already in it\nfn mdot(a: vec3<f32>, b: vec3<f32>) -> f32 {\n return max(0.0, dot(a, b));\n}\n// Dot product with a max in it that does not allow for negative values\n// Physically based rendering is accurate as long as normals are accurate,\n// however this is pretty often not the case. In order to prevent negative\n// values from ruining light calculations and creating zones of zero light,\n// this remapping is used, which smoothly clamps the dot product between\n// zero and one while still maintaining a good amount of accuracy.\nfn cdot(a: vec3<f32>, b: vec3<f32>) -> f32 {\n var d: f32 = max(0.0, dot(a, b));\n d = pow((d + 1) / 2.0, 2.6);\n return d;\n}\n\n// Lambertian diffuse model\nfn lambertDiffuse(base: vec3<f32>, N: vec3<f32>, L: vec3<f32>) -> vec3<f32> {\n var pi: f32 = 3.14159265359; \n var NdotL: f32 = mdot(N, L);\n NdotL = pow(NdotL, 1.5);\n return (base/pi)*NdotL;\n}\n\n// Yasuhiro Fujii improvement on the Oren-Nayar model\n// https://mimosa-pudica.net/improved-oren-nayar.html\n// p is surface color, o is roughness\nfn fujiiOrenNayar(p: vec3<f32>, o: f32, N: vec3<f32>, L: vec3<f32>, V: vec3<f32>) -> vec3<f32> {\n var invpi: f32 = 0.31830988618; // 1/pi\n\n var o2 = o*o;\n var NdotL: f32 = mdot(N, L);\n NdotL = pow(NdotL, 1.5); // Less physically accurate, but hides the \"seams\" between lights better\n\n var NdotV: f32 = mdot(N, V);\n var LdotV: f32 = mdot(L, V);\n\n var s: f32 = LdotV - NdotL*NdotV;\n var t: f32 = mix(1, max(NdotL, NdotV), step(0, s)); // Mix with step is the equivalent of an if statement\n var A: vec3<f32> = 0.5*(o2 / (o2 + 0.33)) + 0.17*p*(o2 / (o2 + 0.13));\n A = invpi*(1 - A);\n var B: f32 = 0.45*(o2 / (o2 + 0.09));\n B = invpi*B;\n\n return p*NdotL*(A + B*(s/t));\n}\n\n// Fresnel portion of BRDF (IOR only, simplified)\nfn schlickFresnelIOR(V: vec3<f32>, N: vec3<f32>, ior: f32, k: f32) -> f32 {\n var NdotV: f32 = mdot(V, N);\n var F0: f32 = (pow((ior - 1.0), 2) + k*k) / (pow((ior + 1.0), 2) + k*k); // This takes into account the roughness, which the other one does not\n return F0 + (1 - F0) * pow((1-NdotV), 5); \n}\n\n// Fresnel portion of BRDF (Color ior, better)\nfn schlickFresnelRGB(V: vec3<f32>, N: vec3<f32>, F0: vec3<f32>) -> vec3<f32> {\n var NdotV: f32 = mdot(V, N);\n return F0 + (1 - F0) * pow((1-NdotV), 5); \n}\n\n// Normal portion of BRDF\n// https://learnopengl.com/PBR/Theory\n// Trowbridge-Reitz GGX functions: normal, halfway, roughness^2\nfn trGGX(N: vec3<f32>, H: vec3<f32>, a: f32) -> f32 {\n var pi: f32 = 3.14159265359; \n\n var a2: f32 = a*a;\n var NdotH = mdot(N, H);\n var NdotH2 = NdotH*NdotH;\n \n var denom: f32 = NdotH2 * (a2 - 1.0) + 1.0;\n\n return a2 / max((pi*denom*denom), 0.000001);\n}\n\n// A VERY bad approximation of anisotropy. Real anisotropic calculations require tangent and bitangent\nfn anisotrophicTrGGX(N: vec3<f32>, H: vec3<f32>, O: vec3<f32>, s: f32, a: f32) -> f32 {\n var Op: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(O) * s, 0.)).xyz;\n\n var ggx1: f32 = trGGX(N + Op*s, H, a);\n var ggx2: f32 = trGGX(N - Op*s, H, a);\n return (0.5 * ggx1 + 0.5 * ggx2);\n}\n\n// Geometry portion of BRDF\nfn schlickGGX(N: vec3<f32>, X: vec3<f32>, k: f32) -> f32 {\n var NdotX = cdot(N, X);\n return NdotX / max(0.000001, (NdotX*(1-k) + k));\n}\n\nfn smithSurfaceRoughness(N: vec3<f32>, V: vec3<f32>, L: vec3<f32>, k: f32) -> f32 {\n var ggx1: f32 = min(1, schlickGGX(N, V, k));\n var ggx2: f32 = min(1, schlickGGX(N, L, k));\n return ggx1*ggx2;\n}\n\n// BRDF Combination\nfn cookTorrance(D: f32, F: f32, G: f32, N: vec3<f32>, V: vec3<f32>, L: vec3<f32>) -> f32 {\n var num: f32 = D*F*G;\n var denom: f32 = 4*cdot(V, N)*cdot(L, N);\n\n return num / max(denom, 0.000001);\n}\n\n// Different lighting calculations for different light sources\nfn calcDirectionalLight(N: vec3<f32>, V: vec3<f32>, ior: f32, roughness: f32, metallic: f32, direction: vec3<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData { \n var L: vec3<f32> = normalize(direction); // Light Vector\n var H: vec3<f32> = normalize(L + V); // Halfway Vector\n\n var alpha = roughness*roughness;\n var k: f32 = alpha*alpha / 2;\n\n var D: f32 = trGGX(N, H, alpha); // Distribution\n // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel\n var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry\n\n var brdf: f32 = cookTorrance(D, 1, G, N, V, L); // Fresnel term is replaced with 1 because it is added later\n var incoming: vec3<f32> = color;\n var angle: f32 = mdot(L, N);\n angle = pow(angle, 1.5);\n\n var specular: vec3<f32> = brdf*incoming*angle;\n // Oren-Nayar gives a clay-like effect when fully rough which some people may not want, so it might be better to give a separate\n // control property for the diffuse vs specular roughness\n var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V); \n // Stores the specular and diffuse separately to allow for finer post processing\n var out = PBRData(diffuse, specular);\n \n return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)\n}\n\n// TODO: find some way to reduce the number of arguments going in here\nfn calcPointLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, ior: f32, roughness: f32, metallic: f32, position: vec3<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData {\n var L: vec3<f32> = normalize(position - fragPos); // Light Vector\n var H: vec3<f32> = normalize(L + V); // Halfway Vector\n var dist = distance(position, fragPos);\n\n var alpha = roughness*roughness;\n var k: f32 = alpha*alpha / 2; // could also be pow(alpha + 1.0, 2) / 8\n\n var D: f32 = trGGX(N, H, alpha); // Distribution\n // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel\n var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry\n\n var brdf: f32 = cookTorrance(D, 1, G, N, V, L); \n var incoming: vec3<f32> = color * (1. / (dist*dist));\n var angle: f32 = mdot(L, N);\n angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly \"seams\" bewteen light sources\n\n var specular: vec3<f32> = brdf*incoming*angle;\n var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);\n\n // Stores the specular and diffuse separately to allow for finer post processing\n // Could also be done (propably more properly) with a struct\n var out = PBRData(diffuse, specular);\n \n return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)\n}\n\n// For a reason unknown to me, spheres dont seem to behave propperly with head-on spot lights\nfn calcSpotLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, ior: f32, roughness: f32, metallic: f32, position: vec3<f32>, direction: vec3<f32>, cones: vec2<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData {\n var L: vec3<f32> = normalize(position - fragPos);\n var H: vec3<f32> = normalize(L + V); // Halfway Vector\n var dist = distance(position, fragPos);\n\n var alpha = roughness*roughness;\n var k: f32 = alpha*alpha / 2; // could also be pow(alpha + 1.0, 2) / 8\n\n var D: f32 = trGGX(N, H, alpha); // Distribution\n // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel\n var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry\n\n var brdf: f32 = cookTorrance(D, 1, G, N, V, L); \n \n // Cones.x is the inner phi and cones.y is the outer phi\n var theta: f32 = mdot(normalize(direction), L);\n var epsilon: f32 = cones.x - cones.y;\n var intensity: f32 = (theta - cones.y) / epsilon;\n intensity = clamp(intensity, 0.0, 1.0);\n intensity /= dist*dist;\n\n var incoming: vec3<f32> = color * intensity;\n\n var angle: f32 = mdot(L, N);\n angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly \"seams\" bewteen light sources\n\n var specular: vec3<f32> = brdf*incoming*angle;\n var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);\n\n // Stores the specular and diffuse separately to allow for finer post processing\n // Could also be done (propably more properly) with a struct\n var out = PBRData(diffuse, specular);\n \n return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)\n}\n\n// Environment mapping stuff\n// Takes in a vector and converts it to an equivalent coordinate in a rectilinear texture. Should be replaced with cubemaps at some point\nfn vecToRectCoord(dir: vec3<f32>) -> vec2<f32> {\n var tau: f32 = 6.28318530718;\n var pi: f32 = 3.14159265359;\n var out: vec2<f32> = vec2<f32>(0.0);\n\n out.x = atan2(dir.z, dir.x) / tau;\n out.x += 0.5;\n\n var phix: f32 = length(vec2(dir.x, dir.z));\n out.y = atan2(dir.y, phix) / pi + 0.5;\n\n return out;\n}\n\n//VTK::Renderer::Dec\n\n//VTK::Color::Dec\n\n//VTK::TCoord::Dec\n\n// optional surface normal declaration\n//VTK::Normal::Dec\n\n//VTK::Select::Dec\n\n//VTK::RenderEncoder::Dec\n\n//VTK::Mapper::Dec\n\n//VTK::IOStructs::Dec\n\n@fragment\nfn main(\n//VTK::IOStructs::Input\n)\n//VTK::IOStructs::Output\n{\n var output : fragmentOutput;\n\n // Temporary ambient, diffuse, and opacity\n var ambientColor: vec4<f32> = mapperUBO.AmbientColor;\n var diffuseColor: vec4<f32> = mapperUBO.DiffuseColor;\n var opacity: f32 = mapperUBO.Opacity;\n\n // This should be declared somewhere else\n var _diffuseMap: vec4<f32> = vec4<f32>(1);\n var _roughnessMap: vec4<f32> = vec4<f32>(1);\n var _metallicMap: vec4<f32> = vec4<f32>(1);\n var _normalMap: vec4<f32> = vec4<f32>(0, 0, 1, 0); // normal map was setting off the normal vector detection in fragment\n var _ambientOcclusionMap: vec4<f32> = vec4<f32>(1);\n var _emissionMap: vec4<f32> = vec4<f32>(0);\n\n //VTK::Color::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Normal::Impl\n\n var computedColor: vec4<f32> = vec4<f32>(diffuseColor.rgb, 1.0);\n\n //VTK::Light::Impl\n\n //VTK::Select::Impl\n\n if (computedColor.a == 0.0) { discard; };\n\n //VTK::Position::Impl\n\n //VTK::RenderEncoder::Impl\n\n return output;\n}\n";
14
+ const {
15
+ BufferUsage,
16
+ PrimitiveTypes
17
+ } = vtkWebGPUBufferManager;
18
+ const {
19
+ Representation
20
+ } = vtkProperty;
21
+ const {
22
+ ScalarMode
23
+ } = vtkMapper;
24
+ const {
25
+ CoordinateSystem
26
+ } = vtkProp;
27
+ const {
28
+ DisplayLocation
29
+ } = vtkProperty2D;
30
+ const vtkWebGPUPolyDataVS = `
31
+ //VTK::Renderer::Dec
32
+
33
+ //VTK::Color::Dec
34
+
35
+ //VTK::Normal::Dec
36
+
37
+ //VTK::TCoord::Dec
38
+
39
+ //VTK::Select::Dec
40
+
41
+ //VTK::Mapper::Dec
42
+
43
+ //VTK::IOStructs::Dec
44
+
45
+ @vertex
46
+ fn main(
47
+ //VTK::IOStructs::Input
48
+ )
49
+ //VTK::IOStructs::Output
50
+ {
51
+ var output : vertexOutput;
52
+
53
+ var vertex: vec4<f32> = vertexBC;
54
+
55
+ //VTK::Color::Impl
56
+
57
+ //VTK::Normal::Impl
58
+
59
+ //VTK::TCoord::Impl
60
+
61
+ //VTK::Select::Impl
62
+
63
+ //VTK::Position::Impl
64
+
65
+ return output;
66
+ }
67
+ `;
68
+ const vtkWebGPUPolyDataFS = `
69
+ struct PBRData {
70
+ diffuse: vec3<f32>,
71
+ specular: vec3<f32>,
72
+ }
73
+
74
+ // Dot product with the max already in it
75
+ fn mdot(a: vec3<f32>, b: vec3<f32>) -> f32 {
76
+ return max(0.0, dot(a, b));
77
+ }
78
+ // Dot product with a max in it that does not allow for negative values
79
+ // Physically based rendering is accurate as long as normals are accurate,
80
+ // however this is pretty often not the case. In order to prevent negative
81
+ // values from ruining light calculations and creating zones of zero light,
82
+ // this remapping is used, which smoothly clamps the dot product between
83
+ // zero and one while still maintaining a good amount of accuracy.
84
+ fn cdot(a: vec3<f32>, b: vec3<f32>) -> f32 {
85
+ var d: f32 = max(0.0, dot(a, b));
86
+ d = pow((d + 1) / 2.0, 2.6);
87
+ return d;
88
+ }
89
+
90
+ // Lambertian diffuse model
91
+ fn lambertDiffuse(base: vec3<f32>, N: vec3<f32>, L: vec3<f32>) -> vec3<f32> {
92
+ var pi: f32 = 3.14159265359;
93
+ var NdotL: f32 = mdot(N, L);
94
+ NdotL = pow(NdotL, 1.5);
95
+ return (base/pi)*NdotL;
96
+ }
97
+
98
+ // Yasuhiro Fujii improvement on the Oren-Nayar model
99
+ // https://mimosa-pudica.net/improved-oren-nayar.html
100
+ // p is surface color, o is roughness
101
+ fn fujiiOrenNayar(p: vec3<f32>, o: f32, N: vec3<f32>, L: vec3<f32>, V: vec3<f32>) -> vec3<f32> {
102
+ var invpi: f32 = 0.31830988618; // 1/pi
103
+
104
+ var o2 = o*o;
105
+ var NdotL: f32 = mdot(N, L);
106
+ NdotL = pow(NdotL, 1.5); // Less physically accurate, but hides the "seams" between lights better
107
+
108
+ var NdotV: f32 = mdot(N, V);
109
+ var LdotV: f32 = mdot(L, V);
110
+
111
+ var s: f32 = LdotV - NdotL*NdotV;
112
+ var t: f32 = mix(1, max(NdotL, NdotV), step(0, s)); // Mix with step is the equivalent of an if statement
113
+ var A: vec3<f32> = 0.5*(o2 / (o2 + 0.33)) + 0.17*p*(o2 / (o2 + 0.13));
114
+ A = invpi*(1 - A);
115
+ var B: f32 = 0.45*(o2 / (o2 + 0.09));
116
+ B = invpi*B;
117
+
118
+ return p*NdotL*(A + B*(s/t));
119
+ }
120
+
121
+ // Fresnel portion of BRDF (IOR only, simplified)
122
+ fn schlickFresnelIOR(V: vec3<f32>, N: vec3<f32>, ior: f32, k: f32) -> f32 {
123
+ var NdotV: f32 = mdot(V, N);
124
+ var F0: f32 = (pow((ior - 1.0), 2) + k*k) / (pow((ior + 1.0), 2) + k*k); // This takes into account the roughness, which the other one does not
125
+ return F0 + (1 - F0) * pow((1-NdotV), 5);
126
+ }
127
+
128
+ // Fresnel portion of BRDF (Color ior, better)
129
+ fn schlickFresnelRGB(V: vec3<f32>, N: vec3<f32>, F0: vec3<f32>) -> vec3<f32> {
130
+ var NdotV: f32 = mdot(V, N);
131
+ return F0 + (1 - F0) * pow((1-NdotV), 5);
132
+ }
133
+
134
+ // Normal portion of BRDF
135
+ // https://learnopengl.com/PBR/Theory
136
+ // Trowbridge-Reitz GGX functions: normal, halfway, roughness^2
137
+ fn trGGX(N: vec3<f32>, H: vec3<f32>, a: f32) -> f32 {
138
+ var pi: f32 = 3.14159265359;
139
+
140
+ var a2: f32 = a*a;
141
+ var NdotH = mdot(N, H);
142
+ var NdotH2 = NdotH*NdotH;
143
+
144
+ var denom: f32 = NdotH2 * (a2 - 1.0) + 1.0;
145
+
146
+ return a2 / max((pi*denom*denom), 0.000001);
147
+ }
148
+
149
+ // A VERY bad approximation of anisotropy. Real anisotropic calculations require tangent and bitangent
150
+ fn anisotrophicTrGGX(N: vec3<f32>, H: vec3<f32>, O: vec3<f32>, s: f32, a: f32) -> f32 {
151
+ var Op: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(O) * s, 0.)).xyz;
152
+
153
+ var ggx1: f32 = trGGX(N + Op*s, H, a);
154
+ var ggx2: f32 = trGGX(N - Op*s, H, a);
155
+ return (0.5 * ggx1 + 0.5 * ggx2);
156
+ }
157
+
158
+ // Geometry portion of BRDF
159
+ fn schlickGGX(N: vec3<f32>, X: vec3<f32>, k: f32) -> f32 {
160
+ var NdotX = cdot(N, X);
161
+ return NdotX / max(0.000001, (NdotX*(1-k) + k));
162
+ }
163
+
164
+ fn smithSurfaceRoughness(N: vec3<f32>, V: vec3<f32>, L: vec3<f32>, k: f32) -> f32 {
165
+ var ggx1: f32 = min(1, schlickGGX(N, V, k));
166
+ var ggx2: f32 = min(1, schlickGGX(N, L, k));
167
+ return ggx1*ggx2;
168
+ }
169
+
170
+ // BRDF Combination
171
+ fn cookTorrance(D: f32, F: f32, G: f32, N: vec3<f32>, V: vec3<f32>, L: vec3<f32>) -> f32 {
172
+ var num: f32 = D*F*G;
173
+ var denom: f32 = 4*cdot(V, N)*cdot(L, N);
174
+
175
+ return num / max(denom, 0.000001);
176
+ }
177
+
178
+ // Different lighting calculations for different light sources
179
+ fn calcDirectionalLight(N: vec3<f32>, V: vec3<f32>, ior: f32, roughness: f32, metallic: f32, direction: vec3<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData {
180
+ var L: vec3<f32> = normalize(direction); // Light Vector
181
+ var H: vec3<f32> = normalize(L + V); // Halfway Vector
182
+
183
+ var alpha = roughness*roughness;
184
+ var k: f32 = alpha*alpha / 2;
185
+
186
+ var D: f32 = trGGX(N, H, alpha); // Distribution
187
+ // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel
188
+ var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry
189
+
190
+ var brdf: f32 = cookTorrance(D, 1, G, N, V, L); // Fresnel term is replaced with 1 because it is added later
191
+ var incoming: vec3<f32> = color;
192
+ var angle: f32 = mdot(L, N);
193
+ angle = pow(angle, 1.5);
194
+
195
+ var specular: vec3<f32> = brdf*incoming*angle;
196
+ // Oren-Nayar gives a clay-like effect when fully rough which some people may not want, so it might be better to give a separate
197
+ // control property for the diffuse vs specular roughness
198
+ var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);
199
+ // Stores the specular and diffuse separately to allow for finer post processing
200
+ var out = PBRData(diffuse, specular);
201
+
202
+ return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)
203
+ }
204
+
205
+ // TODO: find some way to reduce the number of arguments going in here
206
+ fn calcPointLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, ior: f32, roughness: f32, metallic: f32, position: vec3<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData {
207
+ var L: vec3<f32> = normalize(position - fragPos); // Light Vector
208
+ var H: vec3<f32> = normalize(L + V); // Halfway Vector
209
+ var dist = distance(position, fragPos);
210
+
211
+ var alpha = roughness*roughness;
212
+ var k: f32 = alpha*alpha / 2; // could also be pow(alpha + 1.0, 2) / 8
213
+
214
+ var D: f32 = trGGX(N, H, alpha); // Distribution
215
+ // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel
216
+ var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry
217
+
218
+ var brdf: f32 = cookTorrance(D, 1, G, N, V, L);
219
+ var incoming: vec3<f32> = color * (1. / (dist*dist));
220
+ var angle: f32 = mdot(L, N);
221
+ angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly "seams" bewteen light sources
222
+
223
+ var specular: vec3<f32> = brdf*incoming*angle;
224
+ var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);
225
+
226
+ // Stores the specular and diffuse separately to allow for finer post processing
227
+ // Could also be done (propably more properly) with a struct
228
+ var out = PBRData(diffuse, specular);
229
+
230
+ return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)
231
+ }
232
+
233
+ // For a reason unknown to me, spheres dont seem to behave propperly with head-on spot lights
234
+ fn calcSpotLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, ior: f32, roughness: f32, metallic: f32, position: vec3<f32>, direction: vec3<f32>, cones: vec2<f32>, color: vec3<f32>, base: vec3<f32>) -> PBRData {
235
+ var L: vec3<f32> = normalize(position - fragPos);
236
+ var H: vec3<f32> = normalize(L + V); // Halfway Vector
237
+ var dist = distance(position, fragPos);
22
238
 
239
+ var alpha = roughness*roughness;
240
+ var k: f32 = alpha*alpha / 2; // could also be pow(alpha + 1.0, 2) / 8
241
+
242
+ var D: f32 = trGGX(N, H, alpha); // Distribution
243
+ // var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel
244
+ var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry
245
+
246
+ var brdf: f32 = cookTorrance(D, 1, G, N, V, L);
247
+
248
+ // Cones.x is the inner phi and cones.y is the outer phi
249
+ var theta: f32 = mdot(normalize(direction), L);
250
+ var epsilon: f32 = cones.x - cones.y;
251
+ var intensity: f32 = (theta - cones.y) / epsilon;
252
+ intensity = clamp(intensity, 0.0, 1.0);
253
+ intensity /= dist*dist;
254
+
255
+ var incoming: vec3<f32> = color * intensity;
256
+
257
+ var angle: f32 = mdot(L, N);
258
+ angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly "seams" bewteen light sources
259
+
260
+ var specular: vec3<f32> = brdf*incoming*angle;
261
+ var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);
262
+
263
+ // Stores the specular and diffuse separately to allow for finer post processing
264
+ // Could also be done (propably more properly) with a struct
265
+ var out = PBRData(diffuse, specular);
266
+
267
+ return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)
268
+ }
269
+
270
+ // Environment mapping stuff
271
+ // Takes in a vector and converts it to an equivalent coordinate in a rectilinear texture. Should be replaced with cubemaps at some point
272
+ fn vecToRectCoord(dir: vec3<f32>) -> vec2<f32> {
273
+ var tau: f32 = 6.28318530718;
274
+ var pi: f32 = 3.14159265359;
275
+ var out: vec2<f32> = vec2<f32>(0.0);
276
+
277
+ out.x = atan2(dir.z, dir.x) / tau;
278
+ out.x += 0.5;
279
+
280
+ var phix: f32 = length(vec2(dir.x, dir.z));
281
+ out.y = atan2(dir.y, phix) / pi + 0.5;
282
+
283
+ return out;
284
+ }
285
+
286
+ //VTK::Renderer::Dec
287
+
288
+ //VTK::Color::Dec
289
+
290
+ //VTK::TCoord::Dec
291
+
292
+ // optional surface normal declaration
293
+ //VTK::Normal::Dec
294
+
295
+ //VTK::Select::Dec
296
+
297
+ //VTK::RenderEncoder::Dec
298
+
299
+ //VTK::Mapper::Dec
300
+
301
+ //VTK::IOStructs::Dec
302
+
303
+ @fragment
304
+ fn main(
305
+ //VTK::IOStructs::Input
306
+ )
307
+ //VTK::IOStructs::Output
308
+ {
309
+ var output : fragmentOutput;
310
+
311
+ // Temporary ambient, diffuse, and opacity
312
+ var ambientColor: vec4<f32> = mapperUBO.AmbientColor;
313
+ var diffuseColor: vec4<f32> = mapperUBO.DiffuseColor;
314
+ var opacity: f32 = mapperUBO.Opacity;
315
+
316
+ // This should be declared somewhere else
317
+ var _diffuseMap: vec4<f32> = vec4<f32>(1);
318
+ var _roughnessMap: vec4<f32> = vec4<f32>(1);
319
+ var _metallicMap: vec4<f32> = vec4<f32>(1);
320
+ var _normalMap: vec4<f32> = vec4<f32>(0, 0, 1, 0); // normal map was setting off the normal vector detection in fragment
321
+ var _ambientOcclusionMap: vec4<f32> = vec4<f32>(1);
322
+ var _emissionMap: vec4<f32> = vec4<f32>(0);
323
+
324
+ //VTK::Color::Impl
325
+
326
+ //VTK::TCoord::Impl
327
+
328
+ //VTK::Normal::Impl
329
+
330
+ var computedColor: vec4<f32> = vec4<f32>(diffuseColor.rgb, 1.0);
331
+
332
+ //VTK::Light::Impl
333
+
334
+ //VTK::Select::Impl
335
+
336
+ if (computedColor.a == 0.0) { discard; };
337
+
338
+ //VTK::Position::Impl
339
+
340
+ //VTK::RenderEncoder::Impl
341
+
342
+ return output;
343
+ }
344
+ `;
23
345
  function isEdges(hash) {
24
346
  // edge pipelines have "edge" in them
25
347
  return hash.indexOf('edge') >= 0;
26
- } // ----------------------------------------------------------------------------
348
+ }
349
+
350
+ // ----------------------------------------------------------------------------
27
351
  // vtkWebGPUCellArrayMapper methods
28
352
  // ----------------------------------------------------------------------------
29
353
 
30
-
31
354
  function vtkWebGPUCellArrayMapper(publicAPI, model) {
32
355
  // Set our className
33
356
  model.classHierarchy.push('vtkWebGPUCellArrayMapper');
34
-
35
- publicAPI.buildPass = function (prepass) {
357
+ publicAPI.buildPass = prepass => {
36
358
  if (prepass) {
37
359
  if (model.is2D) {
38
360
  model.WebGPUActor = publicAPI.getFirstAncestorOfType('vtkWebGPUActor2D');
@@ -41,421 +363,363 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
41
363
  model.WebGPUActor = publicAPI.getFirstAncestorOfType('vtkWebGPUActor');
42
364
  model.forceZValue = false;
43
365
  }
44
-
45
366
  model.coordinateSystem = model.WebGPUActor.getRenderable().getCoordinateSystem();
46
367
  model.useRendererMatrix = model.coordinateSystem !== CoordinateSystem.DISPLAY;
47
368
  model.WebGPURenderer = model.WebGPUActor.getFirstAncestorOfType('vtkWebGPURenderer');
48
369
  model.WebGPURenderWindow = model.WebGPURenderer.getParent();
49
370
  model.device = model.WebGPURenderWindow.getDevice();
50
371
  }
51
- }; // Renders myself
52
-
372
+ };
53
373
 
54
- publicAPI.translucentPass = function (prepass) {
374
+ // Renders myself
375
+ publicAPI.translucentPass = prepass => {
55
376
  if (prepass) {
56
377
  publicAPI.prepareToDraw(model.WebGPURenderer.getRenderEncoder());
57
378
  model.renderEncoder.registerDrawCallback(model.pipeline, publicAPI.draw);
58
379
  }
59
380
  };
60
-
61
- publicAPI.opaquePass = function (prepass) {
381
+ publicAPI.opaquePass = prepass => {
62
382
  if (prepass) {
63
383
  publicAPI.prepareToDraw(model.WebGPURenderer.getRenderEncoder());
64
384
  model.renderEncoder.registerDrawCallback(model.pipeline, publicAPI.draw);
65
385
  }
66
386
  };
67
-
68
- publicAPI.updateUBO = function () {
387
+ publicAPI.updateUBO = () => {
69
388
  // make sure the data is up to date
70
- var actor = model.WebGPUActor.getRenderable();
71
- var ppty = actor.getProperty();
72
- var utime = model.UBO.getSendTime();
73
-
389
+ const actor = model.WebGPUActor.getRenderable();
390
+ const ppty = actor.getProperty();
391
+ const utime = model.UBO.getSendTime();
74
392
  if (publicAPI.getMTime() > utime || ppty.getMTime() > utime || model.renderable.getMTime() > utime) {
75
- var _ppty$getEdgeColorByR;
76
-
77
393
  // Matricies
78
- var keyMats = model.WebGPUActor.getKeyMatrices(model.WebGPURenderer);
394
+ const keyMats = model.WebGPUActor.getKeyMatrices(model.WebGPURenderer);
79
395
  model.UBO.setArray('BCWCMatrix', keyMats.bcwc);
80
396
  model.UBO.setArray('BCSCMatrix', keyMats.bcsc);
81
397
  model.UBO.setArray('MCWCNormals', keyMats.normalMatrix);
82
-
83
398
  if (model.is2D) {
84
399
  model.UBO.setValue('ZValue', model.WebGPUActor.getRenderable().getProperty().getDisplayLocation() === DisplayLocation.FOREGROUND ? 1.0 : 0.0);
85
-
86
- var _aColor = ppty.getColorByReference();
87
-
400
+ const aColor = ppty.getColorByReference();
88
401
  model.UBO.setValue('AmbientIntensity', 1.0);
89
- model.UBO.setArray('DiffuseColor', [_aColor[0], _aColor[1], _aColor[2], 1.0]);
402
+ model.UBO.setArray('DiffuseColor', [aColor[0], aColor[1], aColor[2], 1.0]);
90
403
  model.UBO.setValue('DiffuseIntensity', 0.0);
91
404
  model.UBO.setValue('SpecularIntensity', 0.0);
92
405
  } else {
93
406
  // Base Colors
94
- var _aColor2 = ppty.getAmbientColorByReference();
95
-
407
+ let aColor = ppty.getAmbientColorByReference();
96
408
  model.UBO.setValue('AmbientIntensity', ppty.getAmbient());
97
- model.UBO.setArray('AmbientColor', [_aColor2[0], _aColor2[1], _aColor2[2], 1.0]);
409
+ model.UBO.setArray('AmbientColor', [aColor[0], aColor[1], aColor[2], 1.0]);
98
410
  model.UBO.setValue('DiffuseIntensity', ppty.getDiffuse());
99
- _aColor2 = ppty.getDiffuseColorByReference();
100
- model.UBO.setArray('DiffuseColor', [_aColor2[0], _aColor2[1], _aColor2[2], 1.0]); // Roughness
101
-
411
+ aColor = ppty.getDiffuseColorByReference();
412
+ model.UBO.setArray('DiffuseColor', [aColor[0], aColor[1], aColor[2], 1.0]);
413
+ // Roughness
102
414
  model.UBO.setValue('Roughness', ppty.getRoughness());
103
- model.UBO.setValue('BaseIOR', ppty.getBaseIOR()); // Metallic
104
-
105
- model.UBO.setValue('Metallic', ppty.getMetallic()); // Normal
106
-
107
- model.UBO.setValue('NormalStrength', ppty.getNormalStrength()); // Emission
108
-
109
- model.UBO.setValue('Emission', ppty.getEmission()); // Specular
110
-
415
+ model.UBO.setValue('BaseIOR', ppty.getBaseIOR());
416
+ // Metallic
417
+ model.UBO.setValue('Metallic', ppty.getMetallic());
418
+ // Normal
419
+ model.UBO.setValue('NormalStrength', ppty.getNormalStrength());
420
+ // Emission
421
+ model.UBO.setValue('Emission', ppty.getEmission());
422
+ // Specular
111
423
  model.UBO.setValue('SpecularIntensity', ppty.getSpecular());
112
- _aColor2 = ppty.getSpecularColorByReference();
113
- model.UBO.setArray('SpecularColor', [_aColor2[0], _aColor2[1], _aColor2[2], 1.0]);
114
- } // Edge and line rendering
115
-
116
-
117
- var aColor = (_ppty$getEdgeColorByR = ppty.getEdgeColorByReference) === null || _ppty$getEdgeColorByR === void 0 ? void 0 : _ppty$getEdgeColorByR.call(ppty);
118
-
424
+ aColor = ppty.getSpecularColorByReference();
425
+ model.UBO.setArray('SpecularColor', [aColor[0], aColor[1], aColor[2], 1.0]);
426
+ }
427
+ // Edge and line rendering
428
+ const aColor = ppty.getEdgeColorByReference?.();
119
429
  if (aColor) {
120
430
  model.UBO.setArray('EdgeColor', [aColor[0], aColor[1], aColor[2], 1.0]);
121
431
  }
122
-
123
432
  model.UBO.setValue('LineWidth', ppty.getLineWidth());
124
433
  model.UBO.setValue('Opacity', ppty.getOpacity());
125
434
  model.UBO.setValue('PropID', model.WebGPUActor.getPropID());
126
- var device = model.WebGPURenderWindow.getDevice();
435
+ const device = model.WebGPURenderWindow.getDevice();
127
436
  model.UBO.sendIfNeeded(device);
128
437
  }
129
438
  };
130
-
131
- publicAPI.haveWideLines = function () {
132
- var actor = model.WebGPUActor.getRenderable();
133
- var representation = actor.getProperty().getRepresentation();
134
-
439
+ publicAPI.haveWideLines = () => {
440
+ const actor = model.WebGPUActor.getRenderable();
441
+ const representation = actor.getProperty().getRepresentation();
135
442
  if (actor.getProperty().getLineWidth() <= 1.0) {
136
443
  return false;
137
444
  }
138
-
139
445
  if (model.primitiveType === PrimitiveTypes.Verts) {
140
446
  return false;
141
447
  }
142
-
143
448
  if (model.primitiveType === PrimitiveTypes.Triangles || model.primitiveType === PrimitiveTypes.TriangleStrips) {
144
449
  return representation === Representation.WIREFRAME;
145
450
  }
146
-
147
451
  return true;
148
452
  };
149
-
150
- publicAPI.replaceShaderPosition = function (hash, pipeline, vertexInput) {
151
- var vDesc = pipeline.getShaderDescription('vertex');
453
+ publicAPI.replaceShaderPosition = (hash, pipeline, vertexInput) => {
454
+ const vDesc = pipeline.getShaderDescription('vertex');
152
455
  vDesc.addBuiltinOutput('vec4<f32>', '@builtin(position) Position');
153
456
  if (!vDesc.hasOutput('vertexVC')) vDesc.addOutput('vec4<f32>', 'vertexVC');
154
- var code = vDesc.getCode();
155
-
457
+ let code = vDesc.getCode();
156
458
  if (model.useRendererMatrix) {
157
459
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' var pCoord: vec4<f32> = rendererUBO.SCPCMatrix*mapperUBO.BCSCMatrix*vertexBC;', ' output.vertexVC = rendererUBO.SCVCMatrix * mapperUBO.BCSCMatrix * vec4<f32>(vertexBC.xyz, 1.0);', '//VTK::Position::Impl']).result;
158
-
159
460
  if (model.forceZValue) {
160
461
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', ['pCoord = vec4<f32>(pCoord.xyz/pCoord.w, 1.0);', 'pCoord.z = mapperUBO.ZValue;', '//VTK::Position::Impl']).result;
161
462
  }
162
463
  } else {
163
464
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' var pCoord: vec4<f32> = mapperUBO.BCSCMatrix*vertexBC;', ' pCoord.x = 2.0* pCoord.x / rendererUBO.viewportSize.x - 1.0;', ' pCoord.y = 2.0* pCoord.y / rendererUBO.viewportSize.y - 1.0;', ' pCoord.z = 0.5 - 0.5 * pCoord.z;', '//VTK::Position::Impl']).result;
164
-
165
465
  if (model.forceZValue) {
166
466
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' pCoord.z = mapperUBO.ZValue;', '//VTK::Position::Impl']).result;
167
467
  }
168
468
  }
169
-
170
469
  if (publicAPI.haveWideLines()) {
171
- vDesc.addBuiltinInput('u32', '@builtin(instance_index) instanceIndex'); // widen the edge
172
-
173
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' var tmpPos: vec4<f32> = pCoord;', ' var numSteps: f32 = ceil(mapperUBO.LineWidth - 1.0);', ' var offset: f32 = (mapperUBO.LineWidth - 1.0) * (f32(input.instanceIndex / 2u) - numSteps/2.0) / numSteps;', ' var tmpPos2: vec3<f32> = tmpPos.xyz / tmpPos.w;', ' tmpPos2.x = tmpPos2.x + 2.0 * (f32(input.instanceIndex) % 2.0) * offset / rendererUBO.viewportSize.x;', ' tmpPos2.y = tmpPos2.y + 2.0 * (f32(input.instanceIndex + 1u) % 2.0) * offset / rendererUBO.viewportSize.y;', ' tmpPos2.z = min(1.0, tmpPos2.z + 0.00001);', // could become a setting
470
+ vDesc.addBuiltinInput('u32', '@builtin(instance_index) instanceIndex');
471
+ // widen the edge
472
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' var tmpPos: vec4<f32> = pCoord;', ' var numSteps: f32 = ceil(mapperUBO.LineWidth - 1.0);', ' var offset: f32 = (mapperUBO.LineWidth - 1.0) * (f32(input.instanceIndex / 2u) - numSteps/2.0) / numSteps;', ' var tmpPos2: vec3<f32> = tmpPos.xyz / tmpPos.w;', ' tmpPos2.x = tmpPos2.x + 2.0 * (f32(input.instanceIndex) % 2.0) * offset / rendererUBO.viewportSize.x;', ' tmpPos2.y = tmpPos2.y + 2.0 * (f32(input.instanceIndex + 1u) % 2.0) * offset / rendererUBO.viewportSize.y;', ' tmpPos2.z = min(1.0, tmpPos2.z + 0.00001);',
473
+ // could become a setting
174
474
  ' pCoord = vec4<f32>(tmpPos2.xyz * tmpPos.w, tmpPos.w);', '//VTK::Position::Impl']).result;
175
475
  }
176
-
177
476
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Position::Impl', [' output.Position = pCoord;']).result;
178
477
  vDesc.setCode(code);
179
478
  };
180
-
181
479
  model.shaderReplacements.set('replaceShaderPosition', publicAPI.replaceShaderPosition);
182
-
183
- publicAPI.replaceShaderNormal = function (hash, pipeline, vertexInput) {
184
- var normalBuffer = vertexInput.getBuffer('normalMC');
185
- var actor = model.WebGPUActor.getRenderable();
186
-
480
+ publicAPI.replaceShaderNormal = (hash, pipeline, vertexInput) => {
481
+ const normalBuffer = vertexInput.getBuffer('normalMC');
482
+ const actor = model.WebGPUActor.getRenderable();
187
483
  if (normalBuffer) {
188
- var vDesc = pipeline.getShaderDescription('vertex');
189
-
484
+ const vDesc = pipeline.getShaderDescription('vertex');
190
485
  if (!vDesc.hasOutput('normalVC')) {
191
486
  vDesc.addOutput('vec3<f32>', 'normalVC', normalBuffer.getArrayInformation()[0].interpolation);
192
487
  }
193
-
194
488
  if (!vDesc.hasOutput('tangentVC')) {
195
489
  vDesc.addOutput('vec3<f32>', 'tangentVC', normalBuffer.getArrayInformation()[0].interpolation);
196
490
  }
197
-
198
491
  if (!vDesc.hasOutput('bitangentVC')) {
199
492
  vDesc.addOutput('vec3<f32>', 'bitangentVC', normalBuffer.getArrayInformation()[0].interpolation);
200
493
  }
201
-
202
- var code = vDesc.getCode();
203
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' output.normalVC = normalize((rendererUBO.WCVCNormals * mapperUBO.MCWCNormals * normalMC).xyz);', // This is just an approximation, but it happens to work extremely well
494
+ let code = vDesc.getCode();
495
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' output.normalVC = normalize((rendererUBO.WCVCNormals * mapperUBO.MCWCNormals * normalMC).xyz);',
496
+ // This is just an approximation, but it happens to work extremely well
204
497
  // It only works well for normals that are head on and not super angled though
205
498
  // Definitely needs to be replaced
206
499
  ' var c1: vec3<f32> = cross(output.normalVC, vec3<f32>(0, 0, 1));', ' var c2: vec3<f32> = cross(output.normalVC, vec3<f32>(0, 1, 0));', ' var tangent: vec3<f32> = mix(c1, c2, distance(c1, c2));', ' output.tangentVC = normalize(tangent);', ' output.bitangentVC = normalize(cross(output.normalVC, tangent));']).result;
207
500
  vDesc.setCode(code);
208
- var fDesc = pipeline.getShaderDescription('fragment');
501
+ const fDesc = pipeline.getShaderDescription('fragment');
209
502
  code = fDesc.getCode();
210
-
211
503
  if (actor.getProperty().getNormalTexture()) {
212
504
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' var normal: vec3<f32> = input.normalVC;', ' if (!input.frontFacing) { normal = -normal; }', ' var tangent: vec3<f32> = input.tangentVC;', ' var bitangent: vec3<f32> = input.bitangentVC;', ' var TCVCMatrix: mat3x3<f32> = mat3x3<f32>(', ' tangent.x, bitangent.x, normal.x,', ' tangent.y, bitangent.y, normal.y,', ' tangent.z, bitangent.z, normal.z,', ' );', ' var mappedNormal: vec3<f32> = TCVCMatrix * (_normalMap.xyz * 2 - 1);', ' normal = mix(normal, mappedNormal, mapperUBO.NormalStrength);', ' normal = normalize(normal);']).result;
213
505
  } else {
214
506
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' var normal: vec3<f32> = input.normalVC;', ' if (!input.frontFacing) { normal = -normal; }', ' normal = normalize(normal);']).result;
215
507
  }
216
-
217
508
  fDesc.setCode(code);
218
509
  }
219
510
  };
511
+ model.shaderReplacements.set('replaceShaderNormal', publicAPI.replaceShaderNormal);
220
512
 
221
- model.shaderReplacements.set('replaceShaderNormal', publicAPI.replaceShaderNormal); // we only apply lighting when there is a "var normal" declaration in the
513
+ // we only apply lighting when there is a "var normal" declaration in the
222
514
  // fragment shader code. That is the lighting trigger.
223
-
224
- publicAPI.replaceShaderLight = function (hash, pipeline, vertexInput) {
515
+ publicAPI.replaceShaderLight = (hash, pipeline, vertexInput) => {
225
516
  if (hash.includes('sel')) return;
226
- var vDesc = pipeline.getShaderDescription('vertex');
517
+ const vDesc = pipeline.getShaderDescription('vertex');
227
518
  if (!vDesc.hasOutput('vertexVC')) vDesc.addOutput('vec4<f32>', 'vertexVC');
228
- var renderer = model.WebGPURenderer.getRenderable();
229
- var fDesc = pipeline.getShaderDescription('fragment');
230
- var code = fDesc.getCode(); // Code that runs if the fragment shader includes normals
519
+ const renderer = model.WebGPURenderer.getRenderable();
520
+ const fDesc = pipeline.getShaderDescription('fragment');
521
+ let code = fDesc.getCode();
231
522
 
523
+ // Code that runs if the fragment shader includes normals
232
524
  if (code.includes('var normal:') && model.useRendererMatrix && !isEdges(hash) && !model.is2D && !hash.includes('sel')) {
233
- var _renderer$getEnvironm;
234
-
235
- var lightingCode = [// Constants
236
- ' var pi: f32 = 3.14159265359;', // Vectors needed for light calculations
237
- ' var fragPos: vec3<f32> = vec3<f32>(input.vertexVC.xyz);', ' var V: vec3<f32> = mix(normalize(-fragPos), vec3<f32>(0, 0, 1), f32(rendererUBO.cameraParallel)); // View Vector', // Values needed for light calculations
238
- ' var baseColor: vec3<f32> = _diffuseMap.rgb * diffuseColor.rgb;', ' var roughness: f32 = max(0.000001, mapperUBO.Roughness * _roughnessMap.r);', // Need to have a different way of sampling greyscale values aside from .r
239
- ' var metallic: f32 = mapperUBO.Metallic * _metallicMap.r;', ' var alpha: f32 = roughness*roughness;', ' var ior: f32 = mapperUBO.BaseIOR;', ' var k: f32 = alpha*alpha / 2;', // Split diffuse and specular components
240
- ' var diffuse: vec3<f32> = vec3<f32>(0.);', ' var specular: vec3<f32> = vec3<f32>(0.);', ' var emission: vec3<f32> = _emissionMap.rgb * mapperUBO.Emission;', // Summing diffuse and specular components of directional lights
241
- ' {', ' var i: i32 = 0;', ' loop {', ' if !(i < rendererUBO.LightCount) { break; }', ' switch (i32(rendererLightSSBO.values[i].LightData.x)) {', ' // Point Light', ' case 0 {', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var pos: vec3<f32> = (rendererLightSSBO.values[i].LightPos).xyz;', ' var calculated: PBRData = calcPointLight(normal, V, fragPos, ior, roughness, metallic, pos, color, baseColor);', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' // Directional light', ' case 1 {', ' var dir: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(rendererLightSSBO.values[i].LightDir.xyz), 0.)).xyz;', ' dir = normalize(dir);', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var calculated: PBRData = calcDirectionalLight(normal, V, ior, roughness, metallic, dir, color, baseColor); // diffuseColor.rgb needs to be fixed with a more dynamic diffuse color', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' // Spot Light', ' case 2 {', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var pos: vec3<f32> = (rendererLightSSBO.values[i].LightPos).xyz;', ' var dir: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(rendererLightSSBO.values[i].LightDir.xyz), 0.)).xyz;', ' dir = normalize(dir);', ' var cones: vec2<f32> = vec2<f32>(rendererLightSSBO.values[i].LightData.y, rendererLightSSBO.values[i].LightData.z);', ' var calculated: PBRData = calcSpotLight(normal, V, fragPos, ior, roughness, metallic, pos, dir, cones, color, baseColor);', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' default { continue; }', ' }', ' continuing { i++; }', ' }', ' }', // Final variables for combining specular and diffuse
525
+ const lightingCode = [
526
+ // Constants
527
+ ' var pi: f32 = 3.14159265359;',
528
+ // Vectors needed for light calculations
529
+ ' var fragPos: vec3<f32> = vec3<f32>(input.vertexVC.xyz);', ' var V: vec3<f32> = mix(normalize(-fragPos), vec3<f32>(0, 0, 1), f32(rendererUBO.cameraParallel)); // View Vector',
530
+ // Values needed for light calculations
531
+ ' var baseColor: vec3<f32> = _diffuseMap.rgb * diffuseColor.rgb;', ' var roughness: f32 = max(0.000001, mapperUBO.Roughness * _roughnessMap.r);',
532
+ // Need to have a different way of sampling greyscale values aside from .r
533
+ ' var metallic: f32 = mapperUBO.Metallic * _metallicMap.r;', ' var alpha: f32 = roughness*roughness;', ' var ior: f32 = mapperUBO.BaseIOR;', ' var k: f32 = alpha*alpha / 2;',
534
+ // Split diffuse and specular components
535
+ ' var diffuse: vec3<f32> = vec3<f32>(0.);', ' var specular: vec3<f32> = vec3<f32>(0.);', ' var emission: vec3<f32> = _emissionMap.rgb * mapperUBO.Emission;',
536
+ // Summing diffuse and specular components of directional lights
537
+ ' {', ' var i: i32 = 0;', ' loop {', ' if !(i < rendererUBO.LightCount) { break; }', ' switch (i32(rendererLightSSBO.values[i].LightData.x)) {', ' // Point Light', ' case 0 {', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var pos: vec3<f32> = (rendererLightSSBO.values[i].LightPos).xyz;', ' var calculated: PBRData = calcPointLight(normal, V, fragPos, ior, roughness, metallic, pos, color, baseColor);', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' // Directional light', ' case 1 {', ' var dir: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(rendererLightSSBO.values[i].LightDir.xyz), 0.)).xyz;', ' dir = normalize(dir);', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var calculated: PBRData = calcDirectionalLight(normal, V, ior, roughness, metallic, dir, color, baseColor); // diffuseColor.rgb needs to be fixed with a more dynamic diffuse color', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' // Spot Light', ' case 2 {', ' var color: vec3<f32> = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' var pos: vec3<f32> = (rendererLightSSBO.values[i].LightPos).xyz;', ' var dir: vec3<f32> = (rendererUBO.WCVCNormals * vec4<f32>(normalize(rendererLightSSBO.values[i].LightDir.xyz), 0.)).xyz;', ' dir = normalize(dir);', ' var cones: vec2<f32> = vec2<f32>(rendererLightSSBO.values[i].LightData.y, rendererLightSSBO.values[i].LightData.z);', ' var calculated: PBRData = calcSpotLight(normal, V, fragPos, ior, roughness, metallic, pos, dir, cones, color, baseColor);', ' diffuse += max(vec3<f32>(0), calculated.diffuse);', ' specular += max(vec3<f32>(0), calculated.specular);', ' }', ' default { continue; }', ' }', ' continuing { i++; }', ' }', ' }',
538
+ // Final variables for combining specular and diffuse
242
539
  ' var fresnel: f32 = schlickFresnelIOR(V, normal, ior, k); // Fresnel', ' fresnel = min(1, fresnel);', ' // This could be controlled with its own variable (that isnt base color) for better artistic control', ' var fresnelMetallic: vec3<f32> = schlickFresnelRGB(V, normal, baseColor); // Fresnel for metal, takes color into account', ' var kS: vec3<f32> = mix(vec3<f32>(fresnel), fresnelMetallic, metallic);', ' kS = min(vec3<f32>(1), kS);', ' var kD: vec3<f32> = (1.0 - kS) * (1.0 - metallic);', ' var PBR: vec3<f32> = mapperUBO.DiffuseIntensity*kD*diffuse + kS*specular;', ' PBR += emission;', ' computedColor = vec4<f32>(PBR, mapperUBO.Opacity);'];
243
-
244
- if ((_renderer$getEnvironm = renderer.getEnvironmentTexture()) !== null && _renderer$getEnvironm !== void 0 && _renderer$getEnvironm.getImageLoaded()) {
245
- lightingCode.push(' // To get diffuse IBL, the texture is sampled with normals in worldspace', ' var diffuseIBLCoords: vec3<f32> = (transpose(rendererUBO.WCVCNormals) * vec4<f32>(normal, 1.)).xyz;', ' var diffuseCoords: vec2<f32> = vecToRectCoord(diffuseIBLCoords);', ' // To get specular IBL, the texture is sampled as the worldspace reflection between the normal and view vectors', ' // Reflections are first calculated in viewspace, then converted to worldspace to sample the environment', ' var VreflN: vec3<f32> = normalize(reflect(-V, normal));', ' var reflectionIBLCoords = (transpose(rendererUBO.WCVCNormals) * vec4<f32>(VreflN, 1.)).xyz;', ' var specularCoords: vec2<f32> = vecToRectCoord(reflectionIBLCoords);', ' var diffuseIBL = textureSampleLevel(EnvironmentTexture, EnvironmentTextureSampler, diffuseCoords, rendererUBO.MaxEnvironmentMipLevel);', // Level multiplier should be set by UBO
246
- ' var level = roughness * rendererUBO.MaxEnvironmentMipLevel;', ' var specularIBL = textureSampleLevel(EnvironmentTexture, EnvironmentTextureSampler, specularCoords, level);', // Manual mip smoothing since not all formats support smooth level sampling
247
- ' var specularIBLContribution: vec3<f32> = specularIBL.rgb*rendererUBO.BackgroundSpecularStrength;', ' computedColor += vec4<f32>(specularIBLContribution*kS, 0);', ' var diffuseIBLContribution: vec3<f32> = diffuseIBL.rgb*rendererUBO.BackgroundDiffuseStrength;', ' diffuseIBLContribution *= baseColor * _ambientOcclusionMap.rgb;', // Multipy by baseColor may be changed
540
+ if (renderer.getEnvironmentTexture()?.getImageLoaded()) {
541
+ lightingCode.push(' // To get diffuse IBL, the texture is sampled with normals in worldspace', ' var diffuseIBLCoords: vec3<f32> = (transpose(rendererUBO.WCVCNormals) * vec4<f32>(normal, 1.)).xyz;', ' var diffuseCoords: vec2<f32> = vecToRectCoord(diffuseIBLCoords);', ' // To get specular IBL, the texture is sampled as the worldspace reflection between the normal and view vectors', ' // Reflections are first calculated in viewspace, then converted to worldspace to sample the environment', ' var VreflN: vec3<f32> = normalize(reflect(-V, normal));', ' var reflectionIBLCoords = (transpose(rendererUBO.WCVCNormals) * vec4<f32>(VreflN, 1.)).xyz;', ' var specularCoords: vec2<f32> = vecToRectCoord(reflectionIBLCoords);', ' var diffuseIBL = textureSampleLevel(EnvironmentTexture, EnvironmentTextureSampler, diffuseCoords, rendererUBO.MaxEnvironmentMipLevel);',
542
+ // Level multiplier should be set by UBO
543
+ ' var level = roughness * rendererUBO.MaxEnvironmentMipLevel;', ' var specularIBL = textureSampleLevel(EnvironmentTexture, EnvironmentTextureSampler, specularCoords, level);',
544
+ // Manual mip smoothing since not all formats support smooth level sampling
545
+ ' var specularIBLContribution: vec3<f32> = specularIBL.rgb*rendererUBO.BackgroundSpecularStrength;', ' computedColor += vec4<f32>(specularIBLContribution*kS, 0);', ' var diffuseIBLContribution: vec3<f32> = diffuseIBL.rgb*rendererUBO.BackgroundDiffuseStrength;', ' diffuseIBLContribution *= baseColor * _ambientOcclusionMap.rgb;',
546
+ // Multipy by baseColor may be changed
248
547
  ' computedColor += vec4<f32>(diffuseIBLContribution*kD, 0);');
249
548
  }
250
-
251
549
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', lightingCode).result;
252
- fDesc.setCode(code); // If theres no normals, just set the specular color to be flat
550
+ fDesc.setCode(code);
551
+ // If theres no normals, just set the specular color to be flat
253
552
  } else {
254
553
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', [' var diffuse: vec3<f32> = diffuseColor.rgb;', ' var specular: vec3<f32> = mapperUBO.SpecularColor.rgb * mapperUBO.SpecularColor.a;', ' computedColor = vec4<f32>(diffuse * _diffuseMap.rgb, mapperUBO.Opacity);']).result;
255
554
  fDesc.setCode(code);
256
555
  }
257
556
  };
258
-
259
557
  model.shaderReplacements.set('replaceShaderLight', publicAPI.replaceShaderLight);
260
-
261
- publicAPI.replaceShaderColor = function (hash, pipeline, vertexInput) {
558
+ publicAPI.replaceShaderColor = (hash, pipeline, vertexInput) => {
262
559
  // By default, set the colors to be flat
263
560
  if (isEdges(hash)) {
264
- var _fDesc = pipeline.getShaderDescription('fragment');
265
-
266
- var _code = _fDesc.getCode();
267
-
268
- _code = vtkWebGPUShaderCache.substitute(_code, '//VTK::Color::Impl', ['ambientColor = mapperUBO.EdgeColor;', 'diffuseColor = mapperUBO.EdgeColor;']).result;
269
-
270
- _fDesc.setCode(_code);
271
-
561
+ const fDesc = pipeline.getShaderDescription('fragment');
562
+ let code = fDesc.getCode();
563
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::Color::Impl', ['ambientColor = mapperUBO.EdgeColor;', 'diffuseColor = mapperUBO.EdgeColor;']).result;
564
+ fDesc.setCode(code);
272
565
  return;
273
- } // If there's no vertex color buffer return the shader as is
274
-
566
+ }
275
567
 
276
- var colorBuffer = vertexInput.getBuffer('colorVI');
277
- if (!colorBuffer) return; // Modifies the vertex shader to include the vertex colors and interpolation in the outputs
568
+ // If there's no vertex color buffer return the shader as is
569
+ const colorBuffer = vertexInput.getBuffer('colorVI');
570
+ if (!colorBuffer) return;
278
571
 
279
- var vDesc = pipeline.getShaderDescription('vertex');
572
+ // Modifies the vertex shader to include the vertex colors and interpolation in the outputs
573
+ const vDesc = pipeline.getShaderDescription('vertex');
280
574
  vDesc.addOutput('vec4<f32>', 'color', colorBuffer.getArrayInformation()[0].interpolation);
281
- var code = vDesc.getCode();
575
+ let code = vDesc.getCode();
282
576
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Color::Impl', [' output.color = colorVI;']).result;
283
- vDesc.setCode(code); // Sets the fragment shader to accept the color inputs from the vertex shader
577
+ vDesc.setCode(code);
284
578
 
285
- var fDesc = pipeline.getShaderDescription('fragment');
579
+ // Sets the fragment shader to accept the color inputs from the vertex shader
580
+ const fDesc = pipeline.getShaderDescription('fragment');
286
581
  code = fDesc.getCode();
287
582
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Color::Impl', ['ambientColor = input.color;', 'diffuseColor = input.color;', 'opacity = mapperUBO.Opacity * input.color.a;']).result;
288
583
  fDesc.setCode(code);
289
584
  };
290
-
291
585
  model.shaderReplacements.set('replaceShaderColor', publicAPI.replaceShaderColor);
292
-
293
- publicAPI.replaceShaderTCoord = function (hash, pipeline, vertexInput) {
294
- var _actor$getProperty$ge, _actor$getProperty, _actor$getProperty$ge2, _actor$getProperty$ge4, _actor$getProperty3, _actor$getProperty$ge5, _actor$getProperty$ge6, _actor$getProperty4, _actor$getProperty$ge7, _actor$getProperty$ge8, _actor$getProperty5, _actor$getProperty$ge9, _actor$getProperty$ge10, _actor$getProperty6, _actor$getProperty$ge11, _actor$getProperty$ge12, _actor$getProperty7, _actor$getProperty$ge13;
295
-
586
+ publicAPI.replaceShaderTCoord = (hash, pipeline, vertexInput) => {
296
587
  if (!vertexInput.hasAttribute('tcoord')) return;
297
- var vDesc = pipeline.getShaderDescription('vertex');
298
- var tcoords = vertexInput.getBuffer('tcoord');
299
- var numComp = vtkWebGPUTypes.getNumberOfComponentsFromBufferFormat(tcoords.getArrayInformation()[0].format);
300
- var code = vDesc.getCode();
301
- vDesc.addOutput("vec".concat(numComp, "<f32>"), 'tcoordVS');
588
+ const vDesc = pipeline.getShaderDescription('vertex');
589
+ const tcoords = vertexInput.getBuffer('tcoord');
590
+ const numComp = vtkWebGPUTypes.getNumberOfComponentsFromBufferFormat(tcoords.getArrayInformation()[0].format);
591
+ let code = vDesc.getCode();
592
+ vDesc.addOutput(`vec${numComp}<f32>`, 'tcoordVS');
302
593
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::TCoord::Impl', [' output.tcoordVS = tcoord;']).result;
303
594
  vDesc.setCode(code);
304
- var fDesc = pipeline.getShaderDescription('fragment');
595
+ const fDesc = pipeline.getShaderDescription('fragment');
305
596
  code = fDesc.getCode();
306
- var actor = model.WebGPUActor.getRenderable();
307
-
308
- var checkDims = function checkDims(texture) {
597
+ const actor = model.WebGPUActor.getRenderable();
598
+ const checkDims = texture => {
309
599
  if (!texture) return false;
310
- var dims = texture.getDimensionality();
600
+ const dims = texture.getDimensionality();
311
601
  return dims === numComp;
312
602
  };
313
-
314
- var usedTextures = [];
315
-
316
- if ((_actor$getProperty$ge = (_actor$getProperty = actor.getProperty()).getDiffuseTexture) !== null && _actor$getProperty$ge !== void 0 && (_actor$getProperty$ge2 = _actor$getProperty$ge.call(_actor$getProperty)) !== null && _actor$getProperty$ge2 !== void 0 && _actor$getProperty$ge2.getImageLoaded() || actor.getTextures()[0] || model.colorTexture) {
317
- var _actor$getProperty$ge3, _actor$getProperty2;
318
-
319
- if ( // Chained or statements here are questionable
320
- checkDims((_actor$getProperty$ge3 = (_actor$getProperty2 = actor.getProperty()).getDiffuseTexture) === null || _actor$getProperty$ge3 === void 0 ? void 0 : _actor$getProperty$ge3.call(_actor$getProperty2)) || checkDims(actor.getTextures()[0]) || checkDims(model.colorTexture)) {
603
+ const usedTextures = [];
604
+ if (actor.getProperty().getDiffuseTexture?.()?.getImageLoaded() || actor.getTextures()[0] || model.colorTexture) {
605
+ if (
606
+ // Chained or statements here are questionable
607
+ checkDims(actor.getProperty().getDiffuseTexture?.()) || checkDims(actor.getTextures()[0]) || checkDims(model.colorTexture)) {
321
608
  usedTextures.push('_diffuseMap = textureSample(DiffuseTexture, DiffuseTextureSampler, input.tcoordVS);');
322
609
  }
323
610
  }
324
-
325
- if ((_actor$getProperty$ge4 = (_actor$getProperty3 = actor.getProperty()).getRoughnessTexture) !== null && _actor$getProperty$ge4 !== void 0 && (_actor$getProperty$ge5 = _actor$getProperty$ge4.call(_actor$getProperty3)) !== null && _actor$getProperty$ge5 !== void 0 && _actor$getProperty$ge5.getImageLoaded()) {
611
+ if (actor.getProperty().getRoughnessTexture?.()?.getImageLoaded()) {
326
612
  if (checkDims(actor.getProperty().getRoughnessTexture())) {
327
613
  usedTextures.push('_roughnessMap = textureSample(RoughnessTexture, RoughnessTextureSampler, input.tcoordVS);');
328
614
  }
329
615
  }
330
-
331
- if ((_actor$getProperty$ge6 = (_actor$getProperty4 = actor.getProperty()).getMetallicTexture) !== null && _actor$getProperty$ge6 !== void 0 && (_actor$getProperty$ge7 = _actor$getProperty$ge6.call(_actor$getProperty4)) !== null && _actor$getProperty$ge7 !== void 0 && _actor$getProperty$ge7.getImageLoaded()) {
616
+ if (actor.getProperty().getMetallicTexture?.()?.getImageLoaded()) {
332
617
  if (checkDims(actor.getProperty().getMetallicTexture())) {
333
618
  usedTextures.push('_metallicMap = textureSample(MetallicTexture, MetallicTextureSampler, input.tcoordVS);');
334
619
  }
335
620
  }
336
-
337
- if ((_actor$getProperty$ge8 = (_actor$getProperty5 = actor.getProperty()).getNormalTexture) !== null && _actor$getProperty$ge8 !== void 0 && (_actor$getProperty$ge9 = _actor$getProperty$ge8.call(_actor$getProperty5)) !== null && _actor$getProperty$ge9 !== void 0 && _actor$getProperty$ge9.getImageLoaded()) {
621
+ if (actor.getProperty().getNormalTexture?.()?.getImageLoaded()) {
338
622
  if (checkDims(actor.getProperty().getNormalTexture())) {
339
623
  usedTextures.push('_normalMap = textureSample(NormalTexture, NormalTextureSampler, input.tcoordVS);');
340
624
  }
341
625
  }
342
-
343
- if ((_actor$getProperty$ge10 = (_actor$getProperty6 = actor.getProperty()).getAmbientOcclusionTexture) !== null && _actor$getProperty$ge10 !== void 0 && (_actor$getProperty$ge11 = _actor$getProperty$ge10.call(_actor$getProperty6)) !== null && _actor$getProperty$ge11 !== void 0 && _actor$getProperty$ge11.getImageLoaded()) {
626
+ if (actor.getProperty().getAmbientOcclusionTexture?.()?.getImageLoaded()) {
344
627
  if (checkDims(actor.getProperty().getAmbientOcclusionTexture())) {
345
628
  usedTextures.push('_ambientOcclusionMap = textureSample(AmbientOcclusionTexture, AmbientOcclusionTextureSampler, input.tcoordVS);');
346
629
  }
347
630
  }
348
-
349
- if ((_actor$getProperty$ge12 = (_actor$getProperty7 = actor.getProperty()).getEmissionTexture) !== null && _actor$getProperty$ge12 !== void 0 && (_actor$getProperty$ge13 = _actor$getProperty$ge12.call(_actor$getProperty7)) !== null && _actor$getProperty$ge13 !== void 0 && _actor$getProperty$ge13.getImageLoaded()) {
631
+ if (actor.getProperty().getEmissionTexture?.()?.getImageLoaded()) {
350
632
  if (checkDims(actor.getProperty().getEmissionTexture())) {
351
633
  usedTextures.push('_emissionMap = textureSample(EmissionTexture, EmissionTextureSampler, input.tcoordVS);');
352
634
  }
353
635
  }
354
-
355
636
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::TCoord::Impl', usedTextures).result;
356
637
  fDesc.setCode(code);
357
638
  };
358
-
359
639
  model.shaderReplacements.set('replaceShaderTCoord', publicAPI.replaceShaderTCoord);
360
-
361
- publicAPI.replaceShaderSelect = function (hash, pipeline, vertexInput) {
640
+ publicAPI.replaceShaderSelect = (hash, pipeline, vertexInput) => {
362
641
  if (hash.includes('sel')) {
363
- var fDesc = pipeline.getShaderDescription('fragment');
364
- var code = fDesc.getCode(); // by default there are no composites, so just 0
365
-
642
+ const fDesc = pipeline.getShaderDescription('fragment');
643
+ let code = fDesc.getCode();
644
+ // by default there are no composites, so just 0
366
645
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::Select::Impl', [' var compositeID: u32 = 0u;']).result;
367
646
  fDesc.setCode(code);
368
647
  }
369
648
  };
370
-
371
649
  model.shaderReplacements.set('replaceShaderSelect', publicAPI.replaceShaderSelect);
372
-
373
- publicAPI.getUsage = function (rep, i) {
650
+ publicAPI.getUsage = (rep, i) => {
374
651
  if (rep === Representation.POINTS || i === PrimitiveTypes.Points) {
375
652
  return BufferUsage.Verts;
376
653
  }
377
-
378
654
  if (i === PrimitiveTypes.Lines) {
379
655
  return BufferUsage.Lines;
380
656
  }
381
-
382
657
  if (rep === Representation.WIREFRAME) {
383
658
  if (i === PrimitiveTypes.Triangles) {
384
659
  return BufferUsage.LinesFromTriangles;
385
660
  }
386
-
387
661
  return BufferUsage.LinesFromStrips;
388
662
  }
389
-
390
663
  if (i === PrimitiveTypes.Triangles) {
391
664
  return BufferUsage.Triangles;
392
665
  }
393
-
394
666
  if (i === PrimitiveTypes.TriangleStrips) {
395
667
  return BufferUsage.Strips;
396
668
  }
397
-
398
669
  if (i === PrimitiveTypes.TriangleEdges) {
399
670
  return BufferUsage.LinesFromTriangles;
400
- } // only strip edges left which are lines
401
-
671
+ }
402
672
 
673
+ // only strip edges left which are lines
403
674
  return BufferUsage.LinesFromStrips;
404
675
  };
405
-
406
- publicAPI.getHashFromUsage = function (usage) {
407
- return "pt".concat(usage);
408
- };
409
-
410
- publicAPI.getTopologyFromUsage = function (usage) {
676
+ publicAPI.getHashFromUsage = usage => `pt${usage}`;
677
+ publicAPI.getTopologyFromUsage = usage => {
411
678
  switch (usage) {
412
679
  case BufferUsage.Triangles:
413
680
  return 'triangle-list';
414
-
415
681
  case BufferUsage.Verts:
416
682
  return 'point-list';
417
-
418
683
  case BufferUsage.Lines:
419
684
  default:
420
685
  return 'line-list';
421
686
  }
422
- }; // TODO: calculate tangents
423
-
424
-
425
- publicAPI.buildVertexInput = function () {
426
- var _model$renderable$get, _model$renderable;
427
-
428
- var pd = model.currentInput;
429
- var cells = model.cellArray;
430
- var primType = model.primitiveType;
431
- var actor = model.WebGPUActor.getRenderable();
432
- var representation = actor.getProperty().getRepresentation();
433
- var device = model.WebGPURenderWindow.getDevice();
434
- var edges = false;
687
+ };
435
688
 
689
+ // TODO: calculate tangents
690
+ publicAPI.buildVertexInput = () => {
691
+ const pd = model.currentInput;
692
+ const cells = model.cellArray;
693
+ const primType = model.primitiveType;
694
+ const actor = model.WebGPUActor.getRenderable();
695
+ let representation = actor.getProperty().getRepresentation();
696
+ const device = model.WebGPURenderWindow.getDevice();
697
+ let edges = false;
436
698
  if (primType === PrimitiveTypes.TriangleEdges) {
437
699
  edges = true;
438
700
  representation = Representation.WIREFRAME;
439
701
  }
702
+ const vertexInput = model.vertexInput;
703
+ const points = pd.getPoints();
704
+ let indexBuffer;
440
705
 
441
- var vertexInput = model.vertexInput;
442
- var points = pd.getPoints();
443
- var indexBuffer; // get the flat mapping indexBuffer for the cells
444
-
706
+ // get the flat mapping indexBuffer for the cells
445
707
  if (cells) {
446
- var buffRequest = {
447
- hash: "R".concat(representation, "P").concat(primType).concat(cells.getMTime()),
708
+ const buffRequest = {
709
+ hash: `R${representation}P${primType}${cells.getMTime()}`,
448
710
  usage: BufferUsage.Index,
449
- cells: cells,
711
+ cells,
450
712
  numberOfPoints: points.getNumberOfPoints(),
451
713
  primitiveType: primType,
452
- representation: representation
714
+ representation
453
715
  };
454
716
  indexBuffer = device.getBufferManager().getBuffer(buffRequest);
455
717
  vertexInput.setIndexBuffer(indexBuffer);
456
718
  } else {
457
719
  vertexInput.setIndexBuffer(null);
458
- } // hash = all things that can change the values on the buffer
720
+ }
721
+
722
+ // hash = all things that can change the values on the buffer
459
723
  // since mtimes are unique we can use
460
724
  // - indexBuffer mtime - because cells drive how we pack
461
725
  // - relevant dataArray mtime - the source data
@@ -464,229 +728,196 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
464
728
  // - format
465
729
  // - usage
466
730
  // - packExtra - covered by format
467
- // points
468
-
469
731
 
732
+ // points
470
733
  if (points) {
471
- var shift = model.WebGPUActor.getBufferShift(model.WebGPURenderer);
472
- var _buffRequest = {
473
- hash: "".concat(points.getMTime(), "I").concat(indexBuffer.getMTime()).concat(shift.join(), "float32x4"),
734
+ const shift = model.WebGPUActor.getBufferShift(model.WebGPURenderer);
735
+ const buffRequest = {
736
+ hash: `${points.getMTime()}I${indexBuffer.getMTime()}${shift.join()}float32x4`,
474
737
  usage: BufferUsage.PointArray,
475
738
  format: 'float32x4',
476
739
  dataArray: points,
477
- indexBuffer: indexBuffer,
478
- shift: shift,
740
+ indexBuffer,
741
+ shift,
479
742
  packExtra: true
480
743
  };
481
- var buff = device.getBufferManager().getBuffer(_buffRequest);
744
+ const buff = device.getBufferManager().getBuffer(buffRequest);
482
745
  vertexInput.addBuffer(buff, ['vertexBC']);
483
746
  } else {
484
747
  vertexInput.removeBufferIfPresent('vertexBC');
485
- } // normals, only used for surface rendering
486
-
748
+ }
487
749
 
488
- var usage = publicAPI.getUsage(representation, primType);
750
+ // normals, only used for surface rendering
751
+ const usage = publicAPI.getUsage(representation, primType);
489
752
  model._usesCellNormals = false;
490
-
491
- if (!model.is2D && ( // no lighting on Property2D
753
+ if (!model.is2D && (
754
+ // no lighting on Property2D
492
755
  usage === BufferUsage.Triangles || usage === BufferUsage.Strips)) {
493
- var normals = pd.getPointData().getNormals(); // https://vtk.org/doc/nightly/html/classvtkPolyDataTangents.html
756
+ const normals = pd.getPointData().getNormals();
757
+ // https://vtk.org/doc/nightly/html/classvtkPolyDataTangents.html
494
758
  // Need to find some way of using precomputed tangents (or computing new ones)
495
-
496
- var _buffRequest2 = {
759
+ const buffRequest = {
497
760
  format: 'snorm8x4',
498
- indexBuffer: indexBuffer,
761
+ indexBuffer,
499
762
  packExtra: true,
500
763
  shift: 0,
501
764
  scale: 127
502
765
  };
503
-
504
766
  if (normals) {
505
- _buffRequest2.hash = "".concat(normals.getMTime(), "I").concat(indexBuffer.getMTime(), "snorm8x4");
506
- _buffRequest2.dataArray = normals;
507
- _buffRequest2.usage = BufferUsage.PointArray;
508
-
509
- var _buff = device.getBufferManager().getBuffer(_buffRequest2);
510
-
511
- vertexInput.addBuffer(_buff, ['normalMC']);
767
+ buffRequest.hash = `${normals.getMTime()}I${indexBuffer.getMTime()}snorm8x4`;
768
+ buffRequest.dataArray = normals;
769
+ buffRequest.usage = BufferUsage.PointArray;
770
+ const buff = device.getBufferManager().getBuffer(buffRequest);
771
+ vertexInput.addBuffer(buff, ['normalMC']);
512
772
  } else if (primType === PrimitiveTypes.Triangles) {
513
773
  model._usesCellNormals = true;
514
- _buffRequest2.hash = "PFN".concat(points.getMTime(), "I").concat(indexBuffer.getMTime(), "snorm8x4");
515
- _buffRequest2.dataArray = points;
516
- _buffRequest2.cells = cells;
517
- _buffRequest2.usage = BufferUsage.NormalsFromPoints;
518
-
519
- var _buff2 = device.getBufferManager().getBuffer(_buffRequest2);
520
-
521
- vertexInput.addBuffer(_buff2, ['normalMC']);
774
+ buffRequest.hash = `PFN${points.getMTime()}I${indexBuffer.getMTime()}snorm8x4`;
775
+ buffRequest.dataArray = points;
776
+ buffRequest.cells = cells;
777
+ buffRequest.usage = BufferUsage.NormalsFromPoints;
778
+ const buff = device.getBufferManager().getBuffer(buffRequest);
779
+ vertexInput.addBuffer(buff, ['normalMC']);
522
780
  } else {
523
781
  vertexInput.removeBufferIfPresent('normalMC');
524
782
  }
525
783
  } else {
526
784
  vertexInput.removeBufferIfPresent('normalMC');
527
- } // deal with colors but only if modified
528
-
529
-
530
- var haveColors = false;
785
+ }
531
786
 
787
+ // deal with colors but only if modified
788
+ let haveColors = false;
532
789
  if (model.renderable.getScalarVisibility()) {
533
- var c = model.renderable.getColorMapColors();
534
-
790
+ const c = model.renderable.getColorMapColors();
535
791
  if (c && !edges) {
536
- var scalarMode = model.renderable.getScalarMode();
537
- var haveCellScalars = false; // We must figure out how the scalars should be mapped to the polydata.
538
-
792
+ const scalarMode = model.renderable.getScalarMode();
793
+ let haveCellScalars = false;
794
+ // We must figure out how the scalars should be mapped to the polydata.
539
795
  if ((scalarMode === ScalarMode.USE_CELL_DATA || scalarMode === ScalarMode.USE_CELL_FIELD_DATA || scalarMode === ScalarMode.USE_FIELD_DATA || !pd.getPointData().getScalars()) && scalarMode !== ScalarMode.USE_POINT_FIELD_DATA && c) {
540
796
  haveCellScalars = true;
541
797
  }
542
-
543
- var _buffRequest3 = {
798
+ const buffRequest = {
544
799
  usage: BufferUsage.PointArray,
545
800
  format: 'unorm8x4',
546
- hash: "".concat(haveCellScalars).concat(c.getMTime(), "I").concat(indexBuffer.getMTime(), "unorm8x4"),
801
+ hash: `${haveCellScalars}${c.getMTime()}I${indexBuffer.getMTime()}unorm8x4`,
547
802
  dataArray: c,
548
- indexBuffer: indexBuffer,
803
+ indexBuffer,
549
804
  cellData: haveCellScalars,
550
805
  cellOffset: 0
551
806
  };
552
-
553
- var _buff3 = device.getBufferManager().getBuffer(_buffRequest3);
554
-
555
- vertexInput.addBuffer(_buff3, ['colorVI']);
807
+ const buff = device.getBufferManager().getBuffer(buffRequest);
808
+ vertexInput.addBuffer(buff, ['colorVI']);
556
809
  haveColors = true;
557
810
  }
558
811
  }
559
-
560
812
  if (!haveColors) {
561
813
  vertexInput.removeBufferIfPresent('colorVI');
562
814
  }
563
-
564
- var tcoords = null;
565
-
566
- if ((_model$renderable$get = (_model$renderable = model.renderable).getInterpolateScalarsBeforeMapping) !== null && _model$renderable$get !== void 0 && _model$renderable$get.call(_model$renderable) && model.renderable.getColorCoordinates()) {
815
+ let tcoords = null;
816
+ if (model.renderable.getInterpolateScalarsBeforeMapping?.() && model.renderable.getColorCoordinates()) {
567
817
  tcoords = model.renderable.getColorCoordinates();
568
818
  } else {
569
819
  tcoords = pd.getPointData().getTCoords();
570
820
  }
571
-
572
821
  if (tcoords && !edges) {
573
- var _buff4 = device.getBufferManager().getBufferForPointArray(tcoords, vertexInput.getIndexBuffer());
574
-
575
- vertexInput.addBuffer(_buff4, ['tcoord']);
822
+ const buff = device.getBufferManager().getBufferForPointArray(tcoords, vertexInput.getIndexBuffer());
823
+ vertexInput.addBuffer(buff, ['tcoord']);
576
824
  } else {
577
825
  vertexInput.removeBufferIfPresent('tcoord');
578
826
  }
579
827
  };
580
-
581
- publicAPI.updateTextures = function () {
582
- var _model$renderable$get2, _model$renderable2, _actor$getProperty$ge14, _actor$getProperty8, _actor$getProperty$ge15, _actor$getProperty9, _actor$getProperty$ge16, _actor$getProperty10, _actor$getProperty$ge17, _actor$getProperty11, _actor$getProperty$ge18, _actor$getProperty12, _actor$getProperty$ge19, _actor$getProperty13, _renderer$getEnvironm2;
583
-
828
+ publicAPI.updateTextures = () => {
584
829
  // we keep track of new and used textures so
585
830
  // that we can clean up any unused textures so we don't hold onto them
586
- var usedTextures = [];
587
- var newTextures = []; // do we have a scalar color texture
588
-
589
- var idata = (_model$renderable$get2 = (_model$renderable2 = model.renderable).getColorTextureMap) === null || _model$renderable$get2 === void 0 ? void 0 : _model$renderable$get2.call(_model$renderable2);
831
+ const usedTextures = [];
832
+ const newTextures = [];
590
833
 
834
+ // do we have a scalar color texture
835
+ const idata = model.renderable.getColorTextureMap?.();
591
836
  if (idata) {
592
837
  if (!model.colorTexture) {
593
838
  model.colorTexture = vtkTexture.newInstance({
594
839
  label: 'polyDataColor'
595
840
  });
596
841
  }
597
-
598
842
  model.colorTexture.setInputData(idata);
599
843
  newTextures.push(['Diffuse', model.colorTexture]);
600
- } // actor textures?
601
-
844
+ }
602
845
 
603
- var actor = model.WebGPUActor.getRenderable();
604
- var renderer = model.WebGPURenderer.getRenderable(); // Reusing the old code for new and old textures, just loading in from properties instead of actor.getTextures()
846
+ // actor textures?
847
+ const actor = model.WebGPUActor.getRenderable();
848
+ const renderer = model.WebGPURenderer.getRenderable();
605
849
 
606
- var textures = []; // Feels like there should be a better way than individually adding all
850
+ // Reusing the old code for new and old textures, just loading in from properties instead of actor.getTextures()
851
+ const textures = [];
607
852
 
608
- if ((_actor$getProperty$ge14 = (_actor$getProperty8 = actor.getProperty()).getDiffuseTexture) !== null && _actor$getProperty$ge14 !== void 0 && _actor$getProperty$ge14.call(_actor$getProperty8)) {
609
- var pair = ['Diffuse', actor.getProperty().getDiffuseTexture()];
853
+ // Feels like there should be a better way than individually adding all
854
+ if (actor.getProperty().getDiffuseTexture?.()) {
855
+ const pair = ['Diffuse', actor.getProperty().getDiffuseTexture()];
610
856
  textures.push(pair);
611
857
  }
612
-
613
858
  if (actor.getTextures()[0]) {
614
- var _pair = ['Diffuse', actor.getTextures()[0]];
615
- textures.push(_pair);
859
+ const pair = ['Diffuse', actor.getTextures()[0]];
860
+ textures.push(pair);
616
861
  }
617
-
618
862
  if (model.colorTexture) {
619
- var _pair2 = ['Diffuse', model.colorTexture];
620
- textures.push(_pair2);
863
+ const pair = ['Diffuse', model.colorTexture];
864
+ textures.push(pair);
621
865
  }
622
-
623
- if ((_actor$getProperty$ge15 = (_actor$getProperty9 = actor.getProperty()).getRoughnessTexture) !== null && _actor$getProperty$ge15 !== void 0 && _actor$getProperty$ge15.call(_actor$getProperty9)) {
624
- var _pair3 = ['Roughness', actor.getProperty().getRoughnessTexture()];
625
- textures.push(_pair3);
866
+ if (actor.getProperty().getRoughnessTexture?.()) {
867
+ const pair = ['Roughness', actor.getProperty().getRoughnessTexture()];
868
+ textures.push(pair);
626
869
  }
627
-
628
- if ((_actor$getProperty$ge16 = (_actor$getProperty10 = actor.getProperty()).getMetallicTexture) !== null && _actor$getProperty$ge16 !== void 0 && _actor$getProperty$ge16.call(_actor$getProperty10)) {
629
- var _pair4 = ['Metallic', actor.getProperty().getMetallicTexture()];
630
- textures.push(_pair4);
870
+ if (actor.getProperty().getMetallicTexture?.()) {
871
+ const pair = ['Metallic', actor.getProperty().getMetallicTexture()];
872
+ textures.push(pair);
631
873
  }
632
-
633
- if ((_actor$getProperty$ge17 = (_actor$getProperty11 = actor.getProperty()).getNormalTexture) !== null && _actor$getProperty$ge17 !== void 0 && _actor$getProperty$ge17.call(_actor$getProperty11)) {
634
- var _pair5 = ['Normal', actor.getProperty().getNormalTexture()];
635
- textures.push(_pair5);
874
+ if (actor.getProperty().getNormalTexture?.()) {
875
+ const pair = ['Normal', actor.getProperty().getNormalTexture()];
876
+ textures.push(pair);
636
877
  }
637
-
638
- if ((_actor$getProperty$ge18 = (_actor$getProperty12 = actor.getProperty()).getAmbientOcclusionTexture) !== null && _actor$getProperty$ge18 !== void 0 && _actor$getProperty$ge18.call(_actor$getProperty12)) {
639
- var _pair6 = ['AmbientOcclusion', actor.getProperty().getAmbientOcclusionTexture()];
640
- textures.push(_pair6);
878
+ if (actor.getProperty().getAmbientOcclusionTexture?.()) {
879
+ const pair = ['AmbientOcclusion', actor.getProperty().getAmbientOcclusionTexture()];
880
+ textures.push(pair);
641
881
  }
642
-
643
- if ((_actor$getProperty$ge19 = (_actor$getProperty13 = actor.getProperty()).getEmissionTexture) !== null && _actor$getProperty$ge19 !== void 0 && _actor$getProperty$ge19.call(_actor$getProperty13)) {
644
- var _pair7 = ['Emission', actor.getProperty().getEmissionTexture()];
645
- textures.push(_pair7);
882
+ if (actor.getProperty().getEmissionTexture?.()) {
883
+ const pair = ['Emission', actor.getProperty().getEmissionTexture()];
884
+ textures.push(pair);
646
885
  }
647
-
648
- if ((_renderer$getEnvironm2 = renderer.getEnvironmentTexture) !== null && _renderer$getEnvironm2 !== void 0 && _renderer$getEnvironm2.call(renderer)) {
649
- var _pair8 = ['Environment', renderer.getEnvironmentTexture()];
650
- textures.push(_pair8);
886
+ if (renderer.getEnvironmentTexture?.()) {
887
+ const pair = ['Environment', renderer.getEnvironmentTexture()];
888
+ textures.push(pair);
651
889
  }
652
-
653
- for (var i = 0; i < textures.length; i++) {
890
+ for (let i = 0; i < textures.length; i++) {
654
891
  if (textures[i][1].getInputData() || textures[i][1].getJsImageData() || textures[i][1].getCanvas()) {
655
892
  newTextures.push(textures[i]);
656
893
  }
657
-
658
894
  if (textures[i][1].getImage() && textures[i][1].getImageLoaded()) {
659
895
  newTextures.push(textures[i]);
660
896
  }
661
897
  }
662
-
663
- for (var _i = 0; _i < newTextures.length; _i++) {
664
- var srcTexture = newTextures[_i][1];
665
- var textureName = newTextures[_i][0];
666
- var newTex = model.device.getTextureManager().getTextureForVTKTexture(srcTexture); // Generates hash
667
-
898
+ for (let i = 0; i < newTextures.length; i++) {
899
+ const srcTexture = newTextures[i][1];
900
+ const textureName = newTextures[i][0];
901
+ const newTex = model.device.getTextureManager().getTextureForVTKTexture(srcTexture); // Generates hash
668
902
  if (newTex.getReady()) {
669
903
  // is this a new texture
670
- var found = false;
671
-
672
- for (var t = 0; t < model.textures.length; t++) {
904
+ let found = false;
905
+ for (let t = 0; t < model.textures.length; t++) {
673
906
  if (model.textures[t] === newTex) {
674
907
  found = true;
675
908
  usedTextures[t] = true;
676
909
  }
677
910
  }
678
-
679
911
  if (!found) {
680
912
  usedTextures[model.textures.length] = true;
681
- var tview = newTex.createView("".concat(textureName, "Texture"));
913
+ const tview = newTex.createView(`${textureName}Texture`);
682
914
  model.textures.push(newTex);
683
915
  model.textureViews.push(tview);
684
- var interpolate = srcTexture.getInterpolate() ? 'linear' : 'nearest';
685
- var addressMode = null;
916
+ const interpolate = srcTexture.getInterpolate() ? 'linear' : 'nearest';
917
+ let addressMode = null;
686
918
  if (!addressMode && srcTexture.getEdgeClamp() && srcTexture.getRepeat()) addressMode = 'mirror-repeat';
687
919
  if (!addressMode && srcTexture.getEdgeClamp()) addressMode = 'clamp-to-edge';
688
920
  if (!addressMode && srcTexture.getRepeat()) addressMode = 'repeat';
689
-
690
921
  if (textureName !== 'Environment') {
691
922
  tview.addSampler(model.device, {
692
923
  addressModeU: addressMode,
@@ -707,88 +938,80 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
707
938
  }
708
939
  }
709
940
  }
710
- } // remove unused textures
711
-
941
+ }
712
942
 
713
- for (var _i2 = model.textures.length - 1; _i2 >= 0; _i2--) {
714
- if (!usedTextures[_i2]) {
715
- model.textures.splice(_i2, 1);
716
- model.textureViews.splice(_i2, 1);
943
+ // remove unused textures
944
+ for (let i = model.textures.length - 1; i >= 0; i--) {
945
+ if (!usedTextures[i]) {
946
+ model.textures.splice(i, 1);
947
+ model.textureViews.splice(i, 1);
717
948
  }
718
949
  }
719
- }; // compute a unique hash for a pipeline, this needs to be unique enough to
950
+ };
951
+
952
+ // compute a unique hash for a pipeline, this needs to be unique enough to
720
953
  // capture any pipeline code changes (which includes shader changes)
721
954
  // or vertex input changes/ bind groups/ etc
722
-
723
-
724
- publicAPI.computePipelineHash = function () {
725
- var pipelineHash = "pd".concat(model.useRendererMatrix ? 'r' : '').concat(model.forceZValue ? 'z' : '');
726
-
955
+ publicAPI.computePipelineHash = () => {
956
+ let pipelineHash = `pd${model.useRendererMatrix ? 'r' : ''}${model.forceZValue ? 'z' : ''}`;
727
957
  if (model.primitiveType === PrimitiveTypes.TriangleEdges || model.primitiveType === PrimitiveTypes.TriangleStripEdges) {
728
958
  pipelineHash += 'edge';
729
959
  } else {
730
- if (model.vertexInput.hasAttribute("normalMC")) {
731
- pipelineHash += "n";
960
+ if (model.vertexInput.hasAttribute(`normalMC`)) {
961
+ pipelineHash += `n`;
732
962
  }
733
-
734
- if (model.vertexInput.hasAttribute("colorVI")) {
735
- pipelineHash += "c";
963
+ if (model.vertexInput.hasAttribute(`colorVI`)) {
964
+ pipelineHash += `c`;
736
965
  }
737
-
738
- if (model.vertexInput.hasAttribute("tcoord")) {
739
- var tcoords = model.vertexInput.getBuffer('tcoord');
740
- var numComp = vtkWebGPUTypes.getNumberOfComponentsFromBufferFormat(tcoords.getArrayInformation()[0].format);
741
- pipelineHash += "t".concat(numComp);
966
+ if (model.vertexInput.hasAttribute(`tcoord`)) {
967
+ const tcoords = model.vertexInput.getBuffer('tcoord');
968
+ const numComp = vtkWebGPUTypes.getNumberOfComponentsFromBufferFormat(tcoords.getArrayInformation()[0].format);
969
+ pipelineHash += `t${numComp}`;
742
970
  }
743
-
744
971
  if (model.textures.length) {
745
- pipelineHash += "tx".concat(model.textures.length);
972
+ pipelineHash += `tx${model.textures.length}`;
746
973
  }
747
974
  }
748
-
749
975
  if (model._usesCellNormals) {
750
- pipelineHash += "cn";
976
+ pipelineHash += `cn`;
751
977
  }
752
-
753
978
  if (model.SSBO) {
754
- pipelineHash += "ssbo";
979
+ pipelineHash += `ssbo`;
755
980
  }
756
-
757
- var uhash = publicAPI.getHashFromUsage(model.usage);
981
+ const uhash = publicAPI.getHashFromUsage(model.usage);
758
982
  pipelineHash += uhash;
759
983
  pipelineHash += model.renderEncoder.getPipelineHash();
760
984
  model.pipelineHash = pipelineHash;
761
985
  };
762
-
763
- publicAPI.updateBuffers = function () {
986
+ publicAPI.updateBuffers = () => {
764
987
  // handle textures if not edges
765
988
  if (model.primitiveType !== PrimitiveTypes.TriangleEdges && model.primitiveType !== PrimitiveTypes.TriangleStripEdges) {
766
989
  publicAPI.updateTextures();
767
990
  }
991
+ const actor = model.WebGPUActor.getRenderable();
992
+ const rep = actor.getProperty().getRepresentation();
768
993
 
769
- var actor = model.WebGPUActor.getRenderable();
770
- var rep = actor.getProperty().getRepresentation(); // handle per primitive type
771
-
994
+ // handle per primitive type
772
995
  model.usage = publicAPI.getUsage(rep, model.primitiveType);
773
996
  publicAPI.buildVertexInput();
774
- var vbo = model.vertexInput.getBuffer('vertexBC');
997
+ const vbo = model.vertexInput.getBuffer('vertexBC');
775
998
  publicAPI.setNumberOfVertices(vbo.getSizeInBytes() / vbo.getStrideInBytes());
776
999
  publicAPI.setTopology(publicAPI.getTopologyFromUsage(model.usage));
777
1000
  publicAPI.updateUBO();
778
-
779
1001
  if (publicAPI.haveWideLines()) {
780
- var ppty = actor.getProperty();
1002
+ const ppty = actor.getProperty();
781
1003
  publicAPI.setNumberOfInstances(Math.ceil(ppty.getLineWidth() * 2.0));
782
1004
  } else {
783
1005
  publicAPI.setNumberOfInstances(1);
784
1006
  }
785
1007
  };
786
- } // ----------------------------------------------------------------------------
1008
+ }
1009
+
1010
+ // ----------------------------------------------------------------------------
787
1011
  // Object factory
788
1012
  // ----------------------------------------------------------------------------
789
1013
 
790
-
791
- var DEFAULT_VALUES = {
1014
+ const DEFAULT_VALUES = {
792
1015
  is2D: false,
793
1016
  cellArray: null,
794
1017
  currentInput: null,
@@ -797,18 +1020,22 @@ var DEFAULT_VALUES = {
797
1020
  colorTexture: null,
798
1021
  renderEncoder: null,
799
1022
  textures: null
800
- }; // ----------------------------------------------------------------------------
1023
+ };
1024
+
1025
+ // ----------------------------------------------------------------------------
801
1026
 
802
1027
  function extend(publicAPI, model) {
803
- var initiaLalues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
804
- Object.assign(model, DEFAULT_VALUES, initiaLalues); // Inheritance
1028
+ let initiaLalues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1029
+ Object.assign(model, DEFAULT_VALUES, initiaLalues);
805
1030
 
1031
+ // Inheritance
806
1032
  vtkWebGPUSimpleMapper.extend(publicAPI, model, initiaLalues);
807
1033
  model.fragmentShaderTemplate = vtkWebGPUPolyDataFS;
808
1034
  model.vertexShaderTemplate = vtkWebGPUPolyDataVS;
809
1035
  model._tmpMat3 = mat3.identity(new Float64Array(9));
810
- model._tmpMat4 = mat4.identity(new Float64Array(16)); // UBO
1036
+ model._tmpMat4 = mat4.identity(new Float64Array(16));
811
1037
 
1038
+ // UBO
812
1039
  model.UBO = vtkWebGPUUniformBuffer.newInstance({
813
1040
  label: 'mapperUBO'
814
1041
  });
@@ -835,19 +1062,25 @@ function extend(publicAPI, model) {
835
1062
  model.UBO.addEntry('PropID', 'u32');
836
1063
  model.UBO.addEntry('ClipNear', 'f32');
837
1064
  model.UBO.addEntry('ClipFar', 'f32');
838
- model.UBO.addEntry('Time', 'u32'); // Build VTK API
1065
+ model.UBO.addEntry('Time', 'u32');
839
1066
 
1067
+ // Build VTK API
840
1068
  setGet(publicAPI, model, ['cellArray', 'currentInput', 'cellOffset', 'is2D', 'primitiveType', 'renderEncoder']);
841
- model.textures = []; // Object methods
1069
+ model.textures = [];
842
1070
 
1071
+ // Object methods
843
1072
  vtkWebGPUCellArrayMapper(publicAPI, model);
844
- } // ----------------------------------------------------------------------------
1073
+ }
1074
+
1075
+ // ----------------------------------------------------------------------------
1076
+
1077
+ const newInstance = newInstance$1(extend, 'vtkWebGPUCellArrayMapper');
845
1078
 
846
- var newInstance = newInstance$1(extend, 'vtkWebGPUCellArrayMapper'); // ----------------------------------------------------------------------------
1079
+ // ----------------------------------------------------------------------------
847
1080
 
848
1081
  var vtkWebGPUCellArrayMapper$1 = {
849
- newInstance: newInstance,
850
- extend: extend
1082
+ newInstance,
1083
+ extend
851
1084
  };
852
1085
 
853
1086
  export { vtkWebGPUCellArrayMapper$1 as default, extend, newInstance };