@realsee/five-webgpu 1.0.0-alpha.14 → 1.0.0-alpha.15

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 (303) hide show
  1. package/_virtual/_rolldown/runtime.js +2 -2
  2. package/docs/assets/hierarchy.js +1 -1
  3. package/docs/assets/search.js +1 -1
  4. package/docs/classes/index.AdaptiveLuminancePass.html +1 -1
  5. package/docs/classes/index.EyeDomeLightingPass.html +1 -1
  6. package/docs/classes/index.Five.html +1 -1
  7. package/docs/classes/index.FivePass.html +1 -1
  8. package/docs/classes/index.FlowingFireworks3DPass.html +1 -1
  9. package/docs/classes/index.FlowingLight2DPass.html +1 -1
  10. package/docs/classes/index.FlowingLight3DPass.html +1 -1
  11. package/docs/classes/index.GaussianBlurPass.html +1 -1
  12. package/docs/classes/index.Model.html +1 -1
  13. package/docs/classes/index.ModelScene.html +1 -1
  14. package/docs/classes/index.PBMCustomNode.html +1 -1
  15. package/docs/classes/index.PBMGaussianSplattingNodeMaterial.html +1 -1
  16. package/docs/classes/index.PBMGaussianSplattingObject.html +1 -1
  17. package/docs/classes/index.PBMGaussianSplattingRenderMesh.html +1 -1
  18. package/docs/classes/index.PBMGroup.html +1 -1
  19. package/docs/classes/index.PBMMesh.html +1 -1
  20. package/docs/classes/index.PBMMeshBasicMaterial.html +1 -1
  21. package/docs/classes/index.PBMMeshBasicNodeMaterial.html +1 -1
  22. package/docs/classes/index.PBMMeshPanoOnlyMaterial.html +1 -1
  23. package/docs/classes/index.PBMMeshPanoOnlyNodeMaterial.html +1 -1
  24. package/docs/classes/index.PBMMeshPhongMaterial.html +1 -1
  25. package/docs/classes/index.PBMMeshPhongNodeMaterial.html +1 -1
  26. package/docs/classes/index.PBMMeshPhysicalMaterial.html +1 -1
  27. package/docs/classes/index.PBMMeshPhysicalNodeMaterial.html +1 -1
  28. package/docs/classes/index.PBMPanoFilter.html +1 -1
  29. package/docs/classes/index.PBMPointCloud.html +1 -1
  30. package/docs/classes/index.PBMPointCloudMaterial.html +1 -1
  31. package/docs/classes/index.PBMSkinnedMesh.html +1 -1
  32. package/docs/classes/index.PBMUpdateable.html +1 -1
  33. package/docs/classes/index.PanoCircleMesh.html +9 -5
  34. package/docs/classes/index.PanoCircleMeshCustom.html +9 -5
  35. package/docs/classes/index.PanoCircleMeshSolid.html +9 -5
  36. package/docs/classes/index.Parameter.html +1 -1
  37. package/docs/classes/index.Tile3D.html +1 -1
  38. package/docs/classes/index.TileNode.html +1 -1
  39. package/docs/classes/index.TrajectoryNode.html +1 -1
  40. package/docs/classes/index.WorkResolvedObserver.html +2 -2
  41. package/docs/hierarchy.html +1 -1
  42. package/docs/interfaces/index.AddableObject.html +1 -1
  43. package/docs/interfaces/index.EventCallback.html +1 -1
  44. package/docs/interfaces/index.IPBMMaterial.html +1 -1
  45. package/docs/interfaces/index.ImageOptions.html +1 -1
  46. package/docs/interfaces/index.IntersectMesh.html +1 -1
  47. package/docs/interfaces/index.IntersectMeshInterface.html +1 -1
  48. package/docs/interfaces/index.Intersection.html +1 -1
  49. package/docs/interfaces/index.LooseWorkObserver.html +2 -2
  50. package/docs/interfaces/index.LooseWorkPanorama.html +2 -2
  51. package/docs/interfaces/index.LooseWorkWithExtrinsics.html +1 -1
  52. package/docs/interfaces/index.ModelControllerCustomInitArgs.html +1 -1
  53. package/docs/interfaces/index.MovePanoOptions.html +1 -1
  54. package/docs/interfaces/index.PanoCircleMeshInterface.html +8 -4
  55. package/docs/interfaces/index.PanoCircleMeshOptions.html +2 -2
  56. package/docs/interfaces/index.PanoCircleMeshSolidOptions.html +2 -2
  57. package/docs/interfaces/index.PanoramaControllerCustomInitArgs.html +1 -1
  58. package/docs/interfaces/index.PanoramaLikeControllerCustomInitArgs.html +1 -1
  59. package/docs/interfaces/index.ParameterMaterialValue.html +1 -1
  60. package/docs/interfaces/index.ParameterTilesetValue.html +1 -1
  61. package/docs/interfaces/index.ParameterValue.html +1 -1
  62. package/docs/interfaces/index.Pose.html +1 -1
  63. package/docs/interfaces/index.ResolvedParameterValue.html +1 -1
  64. package/docs/interfaces/index.State.html +1 -1
  65. package/docs/interfaces/index.TextureOptions.html +1 -1
  66. package/docs/interfaces/index.TopviewControllerCustomInitArgs.html +1 -1
  67. package/docs/interfaces/index.VRPanoramaControllerCustomInitArgs.html +1 -1
  68. package/docs/interfaces/index.ViewLayer.html +1 -1
  69. package/docs/interfaces/index.WorkCubeHdrGainmapImage.html +1 -1
  70. package/docs/interfaces/index.WorkCubeImage.html +1 -1
  71. package/docs/interfaces/index.WorkImage.html +1 -1
  72. package/docs/interfaces/index.WorkObserver.html +2 -2
  73. package/docs/interfaces/index.WorkObserverJson.html +2 -2
  74. package/docs/interfaces/index.WorkPanoramaJson.html +2 -2
  75. package/docs/interfaces/index.WorkTile.html +1 -1
  76. package/docs/interfaces/index.XRPanoramaControllerCustomInitArgs.html +1 -1
  77. package/docs/types/index.ParseOptions.html +1 -1
  78. package/five/chunks/at3d.js +2 -2
  79. package/five/chunks/at3d.mjs +2 -2
  80. package/five/chunks/dome.js +2 -2
  81. package/five/chunks/dome.mjs +2 -2
  82. package/five/chunks/domez.js +2 -2
  83. package/five/chunks/domez.mjs +2 -2
  84. package/five/chunks/fbx.js +2 -2
  85. package/five/chunks/fbx.mjs +2 -2
  86. package/five/chunks/fflate.js +2 -2
  87. package/five/chunks/fflate.mjs +2 -2
  88. package/five/chunks/glTF-helpers.js +2 -2
  89. package/five/chunks/glTF-helpers.mjs +2 -2
  90. package/five/chunks/gltf.js +2 -2
  91. package/five/chunks/gltf.mjs +2 -2
  92. package/five/chunks/imageBitmap.js +2 -2
  93. package/five/chunks/imageBitmap.mjs +2 -2
  94. package/five/chunks/imageSupport.js +2 -2
  95. package/five/chunks/imageSupport.mjs +2 -2
  96. package/five/chunks/lzma.js +2 -2
  97. package/five/chunks/lzma.mjs +2 -2
  98. package/five/chunks/memoryUsage.js +2 -2
  99. package/five/chunks/memoryUsage.mjs +2 -2
  100. package/five/chunks/minimal.js +2 -2
  101. package/five/chunks/minimal.mjs +2 -2
  102. package/five/chunks/pbm.js +2 -2
  103. package/five/chunks/pbm.mjs +2 -2
  104. package/five/chunks/pbmGaussianSplattingObject.js +2 -2
  105. package/five/chunks/pbmGaussianSplattingObject.mjs +2 -2
  106. package/five/chunks/pbmMeshMaterial.js +2 -2
  107. package/five/chunks/pbmMeshMaterial.mjs +2 -2
  108. package/five/chunks/pick.js +2 -2
  109. package/five/chunks/pick.mjs +2 -2
  110. package/five/chunks/ply.js +2 -2
  111. package/five/chunks/ply.mjs +2 -2
  112. package/five/chunks/spz.js +2 -2
  113. package/five/chunks/spz.mjs +2 -2
  114. package/five/controllers/panorama.d.ts +6 -0
  115. package/five/index.js +6 -6
  116. package/five/index.mjs +6 -6
  117. package/five/meshes/panoCircleMesh.d.ts +1 -0
  118. package/five/meshes/panoCircleMeshCustom.d.ts +1 -0
  119. package/five/meshes/panoCircleMeshSolid.d.ts +1 -0
  120. package/five/meshes/panoSphereMesh.d.ts +1 -0
  121. package/five/renderer/postprocessing/passes/pass.js +2 -2
  122. package/five/renderer/postprocessing/passes/pass.mjs +2 -2
  123. package/five/renderer/tools/full-screen-quad.js +2 -2
  124. package/five/renderer/tools/full-screen-quad.mjs +2 -2
  125. package/five/texture/initTexture.d.ts +8 -0
  126. package/five/types/panoCircleMeshInterface.d.ts +6 -0
  127. package/five/utils/calculateThreeMouse.js +2 -2
  128. package/five/utils/calculateThreeMouse.mjs +2 -2
  129. package/five/utils/distance.js +2 -2
  130. package/five/utils/distance.mjs +2 -2
  131. package/five/utils/isNil.js +2 -2
  132. package/five/utils/isNil.mjs +2 -2
  133. package/five/utils/uuid.js +2 -2
  134. package/five/utils/uuid.mjs +2 -2
  135. package/five/work/looseWorkType.d.ts +2 -2
  136. package/five/work/work.d.ts +1 -1
  137. package/five/work/workJsonType.d.ts +2 -2
  138. package/gltf-loader/index.js +3 -3
  139. package/gltf-loader/index.mjs +3 -3
  140. package/line/index.js +3 -3
  141. package/line/index.mjs +3 -3
  142. package/package.json +1 -1
  143. package/plugins/BackgroundPlugin/Controller.js +2 -2
  144. package/plugins/BackgroundPlugin/Controller.mjs +2 -2
  145. package/plugins/BackgroundPlugin/index.js +2 -2
  146. package/plugins/BackgroundPlugin/index.mjs +2 -2
  147. package/plugins/BasePlugin/index.js +2 -2
  148. package/plugins/BasePlugin/index.mjs +2 -2
  149. package/plugins/CSS2DPlugin/Controller.js +2 -2
  150. package/plugins/CSS2DPlugin/Controller.mjs +2 -2
  151. package/plugins/CSS2DPlugin/index.js +2 -2
  152. package/plugins/CSS2DPlugin/index.mjs +2 -2
  153. package/plugins/CSS2DPlugin/style.css_raw.js +2 -2
  154. package/plugins/CSS2DPlugin/style.css_raw.mjs +2 -2
  155. package/plugins/CSS3DPlugin/Controller.js +2 -2
  156. package/plugins/CSS3DPlugin/Controller.mjs +2 -2
  157. package/plugins/CSS3DPlugin/index.js +2 -2
  158. package/plugins/CSS3DPlugin/index.mjs +2 -2
  159. package/plugins/CSS3DPlugin/style.css_raw.js +2 -2
  160. package/plugins/CSS3DPlugin/style.css_raw.mjs +2 -2
  161. package/plugins/FloorplanPlugin/Controller.js +2 -2
  162. package/plugins/FloorplanPlugin/Controller.mjs +2 -2
  163. package/plugins/FloorplanPlugin/index.js +2 -2
  164. package/plugins/FloorplanPlugin/index.mjs +2 -2
  165. package/plugins/FloorplanPlugin/render/assets.js +2 -2
  166. package/plugins/FloorplanPlugin/render/assets.mjs +2 -2
  167. package/plugins/FloorplanPlugin/render/index.js +2 -2
  168. package/plugins/FloorplanPlugin/render/index.mjs +2 -2
  169. package/plugins/FloorplanPlugin/render/isPointInPolygon.js +2 -2
  170. package/plugins/FloorplanPlugin/render/isPointInPolygon.mjs +2 -2
  171. package/plugins/FloorplanPlugin/render/renderFloor.js +2 -2
  172. package/plugins/FloorplanPlugin/render/renderFloor.mjs +2 -2
  173. package/plugins/FloorplanPlugin/render/roomLabelVisibility.js +2 -2
  174. package/plugins/FloorplanPlugin/render/roomLabelVisibility.mjs +2 -2
  175. package/plugins/FloorplanPlugin/render/style.css_raw.js +2 -2
  176. package/plugins/FloorplanPlugin/render/style.css_raw.mjs +2 -2
  177. package/plugins/FloorplanPlugin/utils/changeMode.js +2 -2
  178. package/plugins/FloorplanPlugin/utils/changeMode.mjs +2 -2
  179. package/plugins/FloorplanPlugin/utils/changeModelCanvasOpacity.js +2 -2
  180. package/plugins/FloorplanPlugin/utils/changeModelCanvasOpacity.mjs +2 -2
  181. package/plugins/FloorplanPlugin/utils/correctFiveState.js +2 -2
  182. package/plugins/FloorplanPlugin/utils/correctFiveState.mjs +2 -2
  183. package/plugins/FloorplanPlugin/utils/equal.js +2 -2
  184. package/plugins/FloorplanPlugin/utils/equal.mjs +2 -2
  185. package/plugins/FloorplanPlugin/utils/filter.js +2 -2
  186. package/plugins/FloorplanPlugin/utils/filter.mjs +2 -2
  187. package/plugins/FloorplanPlugin/utils/fiveModelLoad.js +2 -2
  188. package/plugins/FloorplanPlugin/utils/fiveModelLoad.mjs +2 -2
  189. package/plugins/FloorplanPlugin/utils/formatData.js +2 -2
  190. package/plugins/FloorplanPlugin/utils/formatData.mjs +2 -2
  191. package/plugins/FloorplanPlugin/utils/formatFloorplanJson.js +2 -2
  192. package/plugins/FloorplanPlugin/utils/formatFloorplanJson.mjs +2 -2
  193. package/plugins/FloorplanPlugin/utils/formatPosition.js +2 -2
  194. package/plugins/FloorplanPlugin/utils/formatPosition.mjs +2 -2
  195. package/plugins/FloorplanPlugin/utils/getDistanceFromModel.js +2 -2
  196. package/plugins/FloorplanPlugin/utils/getDistanceFromModel.mjs +2 -2
  197. package/plugins/FloorplanPlugin/utils/getPxmm.js +2 -2
  198. package/plugins/FloorplanPlugin/utils/getPxmm.mjs +2 -2
  199. package/plugins/FloorplanPlugin/utils/isTruelyObject.js +2 -2
  200. package/plugins/FloorplanPlugin/utils/isTruelyObject.mjs +2 -2
  201. package/plugins/FloorplanPlugin/utils/nearlyEqual.js +2 -2
  202. package/plugins/FloorplanPlugin/utils/nearlyEqual.mjs +2 -2
  203. package/plugins/FloorplanPlugin/utils/polylabel.js +2 -2
  204. package/plugins/FloorplanPlugin/utils/polylabel.mjs +2 -2
  205. package/plugins/FloorplanPlugin/utils/to.js +2 -2
  206. package/plugins/FloorplanPlugin/utils/to.mjs +2 -2
  207. package/plugins/GaussianSplattingEntranceAnimationPlugin/Controller.js +2 -2
  208. package/plugins/GaussianSplattingEntranceAnimationPlugin/Controller.mjs +2 -2
  209. package/plugins/GaussianSplattingEntranceAnimationPlugin/index.js +2 -2
  210. package/plugins/GaussianSplattingEntranceAnimationPlugin/index.mjs +2 -2
  211. package/plugins/Object3DHelperPlugin/Controller.js +2 -2
  212. package/plugins/Object3DHelperPlugin/Controller.mjs +2 -2
  213. package/plugins/Object3DHelperPlugin/Controllers/BaseController.js +2 -2
  214. package/plugins/Object3DHelperPlugin/Controllers/BaseController.mjs +2 -2
  215. package/plugins/Object3DHelperPlugin/Controllers/BoundingBoxController.js +2 -2
  216. package/plugins/Object3DHelperPlugin/Controllers/BoundingBoxController.mjs +2 -2
  217. package/plugins/Object3DHelperPlugin/Controllers/MoveController.js +2 -2
  218. package/plugins/Object3DHelperPlugin/Controllers/MoveController.mjs +2 -2
  219. package/plugins/Object3DHelperPlugin/Controllers/RotateController.js +2 -2
  220. package/plugins/Object3DHelperPlugin/Controllers/RotateController.mjs +2 -2
  221. package/plugins/Object3DHelperPlugin/FiveControllerWrapper.js +2 -2
  222. package/plugins/Object3DHelperPlugin/FiveControllerWrapper.mjs +2 -2
  223. package/plugins/Object3DHelperPlugin/Helper/BaseHelper.js +2 -2
  224. package/plugins/Object3DHelperPlugin/Helper/BaseHelper.mjs +2 -2
  225. package/plugins/Object3DHelperPlugin/Helper/BoundingBoxHelper.js +2 -2
  226. package/plugins/Object3DHelperPlugin/Helper/BoundingBoxHelper.mjs +2 -2
  227. package/plugins/Object3DHelperPlugin/Helper/MoveHelper.js +2 -2
  228. package/plugins/Object3DHelperPlugin/Helper/MoveHelper.mjs +2 -2
  229. package/plugins/Object3DHelperPlugin/Helper/RotateHelper.js +2 -2
  230. package/plugins/Object3DHelperPlugin/Helper/RotateHelper.mjs +2 -2
  231. package/plugins/Object3DHelperPlugin/constant.js +2 -2
  232. package/plugins/Object3DHelperPlugin/constant.mjs +2 -2
  233. package/plugins/Object3DHelperPlugin/index.js +2 -2
  234. package/plugins/Object3DHelperPlugin/index.mjs +2 -2
  235. package/plugins/Object3DHelperPlugin/utils/ArrowGroup.js +2 -2
  236. package/plugins/Object3DHelperPlugin/utils/ArrowGroup.mjs +2 -2
  237. package/plugins/Object3DHelperPlugin/utils/CenterHandle.js +2 -2
  238. package/plugins/Object3DHelperPlugin/utils/CenterHandle.mjs +2 -2
  239. package/plugins/Object3DHelperPlugin/utils/PlaneHandle.js +2 -2
  240. package/plugins/Object3DHelperPlugin/utils/PlaneHandle.mjs +2 -2
  241. package/plugins/Object3DHelperPlugin/utils/calculateScaleByCamera.js +2 -2
  242. package/plugins/Object3DHelperPlugin/utils/calculateScaleByCamera.mjs +2 -2
  243. package/plugins/Object3DHelperPlugin/utils/cameraHooks.js +2 -2
  244. package/plugins/Object3DHelperPlugin/utils/cameraHooks.mjs +2 -2
  245. package/plugins/Object3DHelperPlugin/utils/direction.js +2 -2
  246. package/plugins/Object3DHelperPlugin/utils/direction.mjs +2 -2
  247. package/plugins/Object3DHelperPlugin/utils/getMouseRaycaster.js +2 -2
  248. package/plugins/Object3DHelperPlugin/utils/getMouseRaycaster.mjs +2 -2
  249. package/plugins/Object3DHelperPlugin/utils/getOrthographicCameraDirection.js +2 -2
  250. package/plugins/Object3DHelperPlugin/utils/getOrthographicCameraDirection.mjs +2 -2
  251. package/plugins/Object3DHelperPlugin/utils/setObjectQuaternion.js +2 -2
  252. package/plugins/Object3DHelperPlugin/utils/setObjectQuaternion.mjs +2 -2
  253. package/plugins/Object3DHelperPlugin/utils/solidGuide.js +2 -2
  254. package/plugins/Object3DHelperPlugin/utils/solidGuide.mjs +2 -2
  255. package/plugins/Object3DHelperPlugin/utils/tipsDom.js +2 -2
  256. package/plugins/Object3DHelperPlugin/utils/tipsDom.mjs +2 -2
  257. package/plugins/PanoAnimePlugin/Controller.js +2 -2
  258. package/plugins/PanoAnimePlugin/Controller.mjs +2 -2
  259. package/plugins/PanoAnimePlugin/index.js +2 -2
  260. package/plugins/PanoAnimePlugin/index.mjs +2 -2
  261. package/plugins/WordPassPlugin/Controller.js +2 -2
  262. package/plugins/WordPassPlugin/Controller.mjs +2 -2
  263. package/plugins/WordPassPlugin/hersheyFont.js +2 -2
  264. package/plugins/WordPassPlugin/hersheyFont.mjs +2 -2
  265. package/plugins/WordPassPlugin/index.js +2 -2
  266. package/plugins/WordPassPlugin/index.mjs +2 -2
  267. package/plugins/WordPassPlugin/textToStrokeOrderStrokes.js +2 -2
  268. package/plugins/WordPassPlugin/textToStrokeOrderStrokes.mjs +2 -2
  269. package/plugins/WordPassPlugin/word-pass.js +3 -3
  270. package/plugins/WordPassPlugin/word-pass.mjs +3 -3
  271. package/plugins/index.js +2 -2
  272. package/plugins/index.mjs +2 -2
  273. package/plugins/thirdParty/CSS2DRenderer.js +2 -2
  274. package/plugins/thirdParty/CSS2DRenderer.mjs +2 -2
  275. package/plugins/thirdParty/CSS3DRenderer.js +2 -2
  276. package/plugins/thirdParty/CSS3DRenderer.mjs +2 -2
  277. package/plugins/thirdParty/doctorstrange-model.js +2 -2
  278. package/plugins/thirdParty/doctorstrange-model.mjs +2 -2
  279. package/plugins/thirdParty/domevents.js +2 -2
  280. package/plugins/thirdParty/domevents.mjs +2 -2
  281. package/plugins/utils/absoluteUrl.js +2 -2
  282. package/plugins/utils/absoluteUrl.mjs +2 -2
  283. package/plugins/utils/calculatePath.js +2 -2
  284. package/plugins/utils/calculatePath.mjs +2 -2
  285. package/plugins/utils/clamp.js +2 -2
  286. package/plugins/utils/clamp.mjs +2 -2
  287. package/plugins/utils/uuid.js +2 -2
  288. package/plugins/utils/uuid.mjs +2 -2
  289. package/react/index.js +2 -2
  290. package/react/index.mjs +2 -2
  291. package/sticker/index.js +3 -3
  292. package/sticker/index.mjs +3 -3
  293. package/umd/five-gltf-loader.js +3 -3
  294. package/umd/five-line.js +3 -3
  295. package/umd/five-plugins.js +4 -4
  296. package/umd/five-react.js +2 -2
  297. package/umd/five-sticker.js +3 -3
  298. package/umd/five-vfx.js +2 -2
  299. package/umd/five.js +47 -47
  300. package/vfx/index.js +2 -2
  301. package/vfx/index.mjs +2 -2
  302. package/work-downloader/index.js +2 -2
  303. package/work-downloader/index.mjs +2 -2
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -335,4 +335,4 @@
335
335
  * writing and signed by Realsee. You and Realsee hereto confirm that this
336
336
  * Agreement and all related documents shall be drafted in English.
337
337
 
338
- */const require_runtime=require("../../_virtual/_rolldown/runtime.js"),require_full_screen_quad=require("../../five/renderer/tools/full-screen-quad.js"),require_pass=require("../../five/renderer/postprocessing/passes/pass.js"),require_uuid=require("../../five/utils/uuid.js");let tslib=require("tslib"),three_webgpu=require("three/webgpu");three_webgpu=require_runtime.__toESM(three_webgpu,1);let three_tsl=require("three/tsl");var DEFAULT_COLOR=16767392,GLOW_RADIUS_EXTRA=3,WordPass=class extends require_pass.FivePass{constructor(camera,outputType=three_webgpu.UnsignedByteType){super(),this.uTime=0,this.words=[],this.lineMesh=null,this.lineMaterial=null,this.points=null,this.particleMaterial=null,this.particleGeometry=null,this.arrPosition=null,this.arrVelocity=null,this.arrAccel=null,this.arrColor=null,this.arrParams=null,this._tmpTip=new three_webgpu.Vector3,this.uTimeLine=(0,three_tsl.uniform)(0),this.uResolutionLine=(0,three_tsl.uniform)(new three_webgpu.Vector2(1,1)),this.uProjLine=(0,three_tsl.uniform)(new three_webgpu.Matrix4),this.uViewLine=(0,three_tsl.uniform)(new three_webgpu.Matrix4),this.uPixelRatioLine=(0,three_tsl.uniform)(1),this.uMaxDisplayBoost=(0,three_tsl.uniform)(1),this.uTimeParticle=(0,three_tsl.uniform)(0),this.uResolutionParticle=(0,three_tsl.uniform)(new three_webgpu.Vector2(1,1)),this.uProjParticle=(0,three_tsl.uniform)(new three_webgpu.Matrix4),this.uViewParticle=(0,three_tsl.uniform)(new three_webgpu.Matrix4),this.uBase=(0,three_tsl.texture)(new three_webgpu.Texture),this.uEffect=(0,three_tsl.texture)(new three_webgpu.Texture),this.camera=camera,this.effectScene=new three_webgpu.Scene,this.orthoCamera=new three_webgpu.OrthographicCamera(-1,1,1,-1,0,1),this.effectRenderTarget=new three_webgpu.RenderTarget(Math.max(1,this.camera.resolution.x),Math.max(1,this.camera.resolution.y),{type:outputType,minFilter:three_webgpu.LinearFilter,magFilter:three_webgpu.LinearFilter,format:three_webgpu.RGBAFormat}),this.blendMaterial=this.createBlendMaterial(),this.blendQuad=new require_full_screen_quad.FullScreenQuad(this.blendMaterial)}setWords(words){return this.words=words.map(w=>{var _a;return this._resolveWord(w,this.uTime+((_a=w.startTime)==null?0:_a)/1e3)}),this._rebuild(),this.words.map(w=>w.id)}addWord(...words){let added=words.map(w=>{var _a;return this._resolveWord(w,this.uTime+((_a=w.startTime)==null?0:_a)/1e3)});return this.words.push(...added),this._rebuild(),added.map(w=>w.id)}hasWord(id){return this.words.some(w=>w.id===id)}removeWord(...ids){let removed=0;for(let id of ids){let i=this.words.findIndex(w=>w.id===id);if(i===-1){console.warn(`WordPass: word "${id}" not found`);continue}this.words.splice(i,1),removed++}return removed>0&&this._rebuild(),removed}setWord(params){var _a;let{id}=params,updates=(0,tslib.__rest)(params,[`id`]),idx=this.words.findIndex(w=>w.id===id);if(idx===-1){console.warn(`WordPass: word "${id}" not found`);return}let prev=this.words[idx],merged=Object.assign(Object.assign(Object.assign({},prev.source),updates),{id}),wordStart=updates.startTime===void 0?prev.wordStart:this.uTime+((_a=updates.startTime)==null?0:_a)/1e3;this.words[idx]=this._resolveWord(merged,wordStart),this._rebuild()}clearWords(){this.words=[],this._rebuild()}setMaxDisplayBoost(value){this.uMaxDisplayBoost.value=Math.max(value,1)}_resolveWord(w,wordStart){let{color=new three_webgpu.Color(DEFAULT_COLOR),opacity=1,lineWidth=3,hdrIntensity=1,writeSpeed=4,minStrokeDuration=200,strokeGap=120,holdDuration=1500,fadeDuration=1200,loop=!0,restartPause=800,persist=!1,fireworks=!0,fireworksColor,particleCount=400,emissionRate=500,sparkSpeed=.6,particleSize=.012,particleLife=.8,gravity}=w,valid=w.strokes.filter(s=>s.points.length>=2),blocks=[],cursorTime=0,gap=strokeGap/1e3;for(let s of valid){let dur=Math.max(s.totalLength/Math.max(writeSpeed,1e-4),minStrokeDuration/1e3);blocks.push({points:s.points,strokeLength:s.totalLength,writeStart:cursorTime,writeDuration:dur}),cursorTime+=dur+gap}let totalWriteTime=cursorTime>0?cursorTime-gap:0,fadeStart=persist?1e9:totalWriteTime+holdDuration/1e3,fadeDur=persist?1:fadeDuration/1e3,cycleLength=persist?0:loop?fadeStart+fadeDur+restartPause/1e3:0;return{id:w.id||require_uuid.uuid(),source:Object.assign(Object.assign({},w),{id:w.id}),blocks,color:color.clone(),opacity,lineWidth,hdrIntensity:Math.max(hdrIntensity,1),wordStart,fadeStart,fadeDuration:fadeDur,cycleLength,fireworks,sparkColor:fireworksColor?fireworksColor.clone():color.clone().lerp(new three_webgpu.Color(16777215),.4),emissionRate,sparkSpeed,particleSize,particleLife,gravity:gravity?gravity.clone():new three_webgpu.Vector3(0,-.6,0),particleCount:fireworks?Math.max(1,Math.floor(particleCount)):0,particleOffset:0,particleCursor:0,emitAccum:blocks.map(()=>0)}}_rebuild(){this._buildLineMesh(),this._buildParticles()}createLineMaterial(){let vColor=(0,three_tsl.varyingProperty)(`vec4`,`wpColor`),vSegLen=(0,three_tsl.varyingProperty)(`float`,`wpSegLen`),vAccum=(0,three_tsl.varyingProperty)(`float`,`wpAccum`),vStrokeLen=(0,three_tsl.varyingProperty)(`float`,`wpStrokeLen`),vDrawnLen=(0,three_tsl.varyingProperty)(`float`,`wpDrawnLen`),vFade=(0,three_tsl.varyingProperty)(`float`,`wpFade`),vStart=(0,three_tsl.varyingProperty)(`vec2`,`wpStart`),vEnd=(0,three_tsl.varyingProperty)(`vec2`,`wpEnd`),vLineWidth=(0,three_tsl.varyingProperty)(`float`,`wpLineWidth`),vHdrBoost=(0,three_tsl.varyingProperty)(`float`,`wpHdrBoost`),vNdc=(0,three_tsl.varyingProperty)(`vec2`,`wpNdc`),nearEps=.001,attr=(name,type)=>(0,three_tsl.attribute)(name,type),vertex=(0,three_tsl.Fn)(()=>{let instanceStart=attr(`instanceStart`,`vec3`),instanceEnd=attr(`instanceEnd`,`vec3`),instanceColor=attr(`instanceColor`,`vec4`),instanceData=attr(`instanceData`,`vec4`),instanceReveal=attr(`instanceReveal`,`vec2`),instanceTime=attr(`instanceTime`,`vec4`),pos=three_tsl.positionGeometry,accum=instanceData.x,lineWidth=instanceData.y.mul(this.uPixelRatioLine),strokeLen=instanceData.z,writeStart=instanceReveal.x,writeDur=instanceReveal.y,wordStart=instanceTime.x,fadeStart=instanceTime.y,fadeDur=instanceTime.z,cycle=instanceTime.w;vColor.assign(instanceColor);let segLen=(0,three_tsl.length)(instanceEnd.sub(instanceStart));vSegLen.assign(segLen),vAccum.assign(accum),vStrokeLen.assign(strokeLen),vLineWidth.assign(lineWidth);let elapsed=this.uTimeLine.sub(wordStart),local=(0,three_tsl.select)(cycle.greaterThan(0),(0,three_tsl.mod)((0,three_tsl.max)(elapsed,0),cycle),elapsed),drawnLen=(0,three_tsl.clamp)(local.sub(writeStart).div((0,three_tsl.max)(writeDur,1e-4)),0,1).mul(strokeLen).toVar(),fade=(0,three_tsl.float)(1).toVar();(0,three_tsl.If)(local.greaterThanEqual(fadeStart),()=>{fade.assign((0,three_tsl.float)(1).sub((0,three_tsl.clamp)(local.sub(fadeStart).div((0,three_tsl.max)(fadeDur,1e-4)),0,1)))}),(0,three_tsl.If)(elapsed.lessThan(0),()=>{fade.assign(0),drawnLen.assign(0)}),vFade.assign(fade),vDrawnLen.assign(drawnLen);let hdrIntensity=instanceData.w,logContentMax=(0,three_tsl.max)((0,three_tsl.log2)((0,three_tsl.max)(hdrIntensity,1.0001)),1e-4),hdrWeight=(0,three_tsl.clamp)((0,three_tsl.log2)((0,three_tsl.max)(this.uMaxDisplayBoost,1)).div(logContentMax),0,1);vHdrBoost.assign((0,three_tsl.mix)(1,hdrIntensity,hdrWeight));let clipStart=this.uProjLine.mul(this.uViewLine).mul((0,three_tsl.vec4)(instanceStart,1)).toVar(),clipEnd=this.uProjLine.mul(this.uViewLine).mul((0,three_tsl.vec4)(instanceEnd,1)).toVar(),invisible=(0,three_tsl.float)(0).toVar(),startBehind=clipStart.w.lessThan(nearEps).toVar(),endBehind=clipEnd.w.lessThan(nearEps).toVar();(0,three_tsl.If)(startBehind.and(endBehind),()=>{invisible.assign(1)}),(0,three_tsl.If)(startBehind,()=>{let tc=(0,three_tsl.float)(nearEps).sub(clipStart.w).div(clipEnd.w.sub(clipStart.w));clipStart.assign((0,three_tsl.mix)(clipStart,clipEnd,tc))}),(0,three_tsl.If)(endBehind,()=>{let tc=(0,three_tsl.float)(nearEps).sub(clipEnd.w).div(clipStart.w.sub(clipEnd.w));clipEnd.assign((0,three_tsl.mix)(clipEnd,clipStart,tc))});let ndcStart=clipStart.xy.div(clipStart.w),ndcEnd=clipEnd.xy.div(clipEnd.w);vStart.assign(ndcStart),vEnd.assign(ndcEnd);let screenStart=ndcStart.add(1).mul(.5).mul(this.uResolutionLine),screenEnd=ndcEnd.add(1).mul(.5).mul(this.uResolutionLine),seg=screenEnd.sub(screenStart),segLenPix=(0,three_tsl.length)(seg),dir=(0,three_tsl.select)(segLenPix.greaterThan(1e-5),seg.div((0,three_tsl.max)(segLenPix,1e-5)),(0,three_tsl.vec2)(1,0)),normal=(0,three_tsl.vec2)(dir.y.negate(),dir.x),tt=pos.y.add(.5),coverRadius=(0,three_tsl.max)(lineWidth.mul(.5),.5).add(GLOW_RADIUS_EXTRA),extStart=screenStart.sub(dir.mul(coverRadius)),extEnd=screenEnd.add(dir.mul(coverRadius)),offset=normal.mul(pos.x).mul(2).mul(coverRadius),ndc=(0,three_tsl.mix)(extStart,extEnd,tt).add(offset).div(this.uResolutionLine).mul(2).sub(1);vNdc.assign(ndc);let clipPos=(0,three_tsl.mix)(clipStart,clipEnd,tt),safeW=(0,three_tsl.max)(clipPos.w,nearEps);return(0,three_tsl.mix)((0,three_tsl.vec4)(ndc.mul(safeW),clipPos.z,safeW),(0,three_tsl.vec4)(0,0,-2,1),invisible)}),sdCapsule=(0,three_tsl.Fn)(([p,a,b])=>{let pa=p.sub(a),ba=b.sub(a),h=(0,three_tsl.clamp)((0,three_tsl.dot)(pa,ba).div((0,three_tsl.dot)(ba,ba)),0,1);return(0,three_tsl.length)(pa.sub(ba.mul(h)))}),fragment=(0,three_tsl.Fn)(()=>{let uvNdc=vNdc,screenDiff=vEnd.sub(vStart),screenDist=(0,three_tsl.max)((0,three_tsl.length)(screenDiff),1e-6),screenDir=screenDiff.div(screenDist),projRatio=(0,three_tsl.clamp)((0,three_tsl.dot)(uvNdc.sub(vStart),screenDir),0,screenDist).div(screenDist),posAlong=vAccum.add(projRatio.mul(vSegLen)),notDrawn=vDrawnLen.lessThanEqual(1e-4).or(posAlong.greaterThan(vDrawnLen)),aspect=(0,three_tsl.vec2)(this.uResolutionLine.x.div(this.uResolutionLine.y),1),dPix=sdCapsule(uvNdc.mul(aspect),vStart.mul(aspect),vEnd.mul(aspect)).mul(this.uResolutionLine.y).mul(.5),halfW=(0,three_tsl.max)(vLineWidth.mul(.5),.5),core=(0,three_tsl.float)(1).sub((0,three_tsl.smoothstep)(halfW.sub(1),halfW.add(1),dPix)),coverRadius=halfW.add(GLOW_RADIUS_EXTRA),x=(0,three_tsl.clamp)((0,three_tsl.max)(dPix.sub(halfW),0).div((0,three_tsl.max)(coverRadius.sub(halfW),1e-4)),0,1),glow=(0,three_tsl.pow)((0,three_tsl.float)(1).sub(x),4).mul(.9),intensity=(0,three_tsl.clamp)(core.add(glow.mul((0,three_tsl.float)(1).sub(core))),0,1),tip=(0,three_tsl.exp)((0,three_tsl.max)(vDrawnLen.sub(posAlong),0).mul(-5).div((0,three_tsl.max)(vStrokeLen,1e-4))),writing=(0,three_tsl.float)(1).sub((0,three_tsl.smoothstep)(vStrokeLen.mul(.98),vStrokeLen,vDrawnLen)),bright=(0,three_tsl.float)(1).add(tip.mul(.6).mul(writing)),alpha=intensity.mul(vColor.a).mul(vFade),outAlpha=(0,three_tsl.select)(notDrawn.not().and(alpha.greaterThanEqual(.004)),alpha,0);return(0,three_tsl.vec4)(vColor.rgb.mul(bright).mul(vHdrBoost).mul(outAlpha),outAlpha)}),material=new three_webgpu.NodeMaterial;return material.vertexNode=vertex(),material.fragmentNode=fragment(),material.transparent=!0,material.depthTest=!1,material.depthWrite=!1,material.side=three_webgpu.DoubleSide,material.blending=three_webgpu.CustomBlending,material.blendEquation=three_webgpu.MaxEquation,material.blendSrc=three_webgpu.OneFactor,material.blendDst=three_webgpu.OneFactor,material}_buildLineMesh(){this._disposeLineMesh();let totalSegments=0;for(let w of this.words)for(let b of w.blocks)totalSegments+=b.points.length-1;if(totalSegments===0)return;let plane=new three_webgpu.PlaneGeometry(1,1,1,1),geometry=new three_webgpu.InstancedBufferGeometry;geometry.index=plane.index,geometry.attributes=plane.attributes,geometry.instanceCount=totalSegments;let instanceStart=new Float32Array(totalSegments*3),instanceEnd=new Float32Array(totalSegments*3),instanceColor=new Float32Array(totalSegments*4),instanceData=new Float32Array(totalSegments*4),instanceReveal=new Float32Array(totalSegments*2),instanceTime=new Float32Array(totalSegments*4),idx=0;for(let w of this.words)for(let b of w.blocks){let accum=0;for(let i=0;i<b.points.length-1;i++){let start=b.points[i],end=b.points[i+1],segLen=start.distanceTo(end),i2=idx*2,i3=idx*3,i4=idx*4;instanceStart[i3+0]=start.x,instanceStart[i3+1]=start.y,instanceStart[i3+2]=start.z,instanceEnd[i3+0]=end.x,instanceEnd[i3+1]=end.y,instanceEnd[i3+2]=end.z,instanceColor[i4+0]=w.color.r,instanceColor[i4+1]=w.color.g,instanceColor[i4+2]=w.color.b,instanceColor[i4+3]=w.opacity,instanceData[i4+0]=accum,instanceData[i4+1]=w.lineWidth,instanceData[i4+2]=b.strokeLength,instanceData[i4+3]=w.hdrIntensity,instanceReveal[i2+0]=b.writeStart,instanceReveal[i2+1]=b.writeDuration,instanceTime[i4+0]=w.wordStart,instanceTime[i4+1]=w.fadeStart,instanceTime[i4+2]=w.fadeDuration,instanceTime[i4+3]=w.cycleLength,accum+=segLen,idx++}}geometry.setAttribute(`instanceStart`,new three_webgpu.InstancedBufferAttribute(instanceStart,3)),geometry.setAttribute(`instanceEnd`,new three_webgpu.InstancedBufferAttribute(instanceEnd,3)),geometry.setAttribute(`instanceColor`,new three_webgpu.InstancedBufferAttribute(instanceColor,4)),geometry.setAttribute(`instanceData`,new three_webgpu.InstancedBufferAttribute(instanceData,4)),geometry.setAttribute(`instanceReveal`,new three_webgpu.InstancedBufferAttribute(instanceReveal,2)),geometry.setAttribute(`instanceTime`,new three_webgpu.InstancedBufferAttribute(instanceTime,4)),this.lineMaterial=this.createLineMaterial(),this.lineMesh=new three_webgpu.Mesh(geometry,this.lineMaterial),this.lineMesh.frustumCulled=!1,this.effectScene.add(this.lineMesh)}createParticleMaterial(){let vColor=(0,three_tsl.varyingProperty)(`vec4`,`wpSparkColor`),vAlpha=(0,three_tsl.varyingProperty)(`float`,`wpSparkAlpha`),vLocal=(0,three_tsl.varyingProperty)(`vec2`,`wpSparkLocal`),eps=.001,attr=(name,type)=>(0,three_tsl.attribute)(name,type),vertex=(0,three_tsl.Fn)(()=>{let birth=attr(`aPosition`,`vec3`),aVelocity=attr(`aVelocity`,`vec3`),aAccel=attr(`aAccel`,`vec3`),aColor=attr(`aColor`,`vec4`),aParams=attr(`aParams`,`vec4`),aBirthTime=aParams.x,aMaxLife=aParams.y,aSeed=aParams.z,aSize=aParams.w,corner=three_tsl.positionGeometry.xy;vColor.assign(aColor),vLocal.assign(corner);let age=this.uTimeParticle.sub(aBirthTime),invisible=(0,three_tsl.float)(0).toVar();(0,three_tsl.If)(aMaxLife.lessThanEqual(0).or(age.lessThan(0)).or(age.greaterThan(aMaxLife)),()=>{invisible.assign(1)});let lifeT=age.div((0,three_tsl.max)(aMaxLife,eps)),worldPos=birth.add(aVelocity.mul(age)).add(aAccel.mul(.5).mul(age).mul(age)),clip=this.uProjParticle.mul(this.uViewParticle).mul((0,three_tsl.vec4)(worldPos,1)).toVar();(0,three_tsl.If)(clip.w.lessThanEqual(eps),()=>{invisible.assign(1)});let safeW=(0,three_tsl.max)(clip.w,eps),ndc=clip.xy.div(safeW),p11=this.uProjParticle.element(1).y,sizeFade=(0,three_tsl.float)(1).sub(lifeT.mul(.7)),pixelSize=(0,three_tsl.max)(aSize.mul(p11).mul(.5).mul(this.uResolutionParticle.y).div(safeW).mul(sizeFade),0),ndc2=ndc.add(1).mul(.5).mul(this.uResolutionParticle).add(corner.mul(pixelSize)).div(this.uResolutionParticle).mul(2).sub(1),twinkle=(0,three_tsl.float)(.7).add((0,three_tsl.float)(.3).mul((0,three_tsl.sin)(this.uTimeParticle.mul(30).add(aSeed.mul(6.2831)))));return vAlpha.assign((0,three_tsl.pow)((0,three_tsl.float)(1).sub(lifeT),.8).mul(twinkle)),(0,three_tsl.mix)((0,three_tsl.vec4)(ndc2.mul(safeW),clip.z,safeW),(0,three_tsl.vec4)(0,0,-2,1),invisible)}),fragment=(0,three_tsl.Fn)(()=>{let core=(0,three_tsl.smoothstep)(.5,0,(0,three_tsl.length)(vLocal)),intensity=core.mul(core).mul(vAlpha).mul(vColor.a);return(0,three_tsl.vec4)(vColor.rgb,intensity)}),material=new three_webgpu.NodeMaterial;return material.vertexNode=vertex(),material.fragmentNode=fragment(),material.transparent=!0,material.depthTest=!1,material.depthWrite=!1,material.blending=three_webgpu.AdditiveBlending,material}createBlendMaterial(){let material=new three_webgpu.NodeMaterial,base=this.uBase.sample((0,three_tsl.uv)()),effect=this.uEffect.sample((0,three_tsl.uv)());return material.fragmentNode=(0,three_tsl.vec4)(base.rgb.add(effect.rgb),base.a),material.transparent=!1,material.depthTest=!1,material.depthWrite=!1,material}_buildParticles(){this._disposeParticles();let total=0;for(let w of this.words)w.particleOffset=total,w.particleCursor=0,total+=w.particleCount;if(total===0)return;this.arrPosition=new Float32Array(total*3),this.arrVelocity=new Float32Array(total*3),this.arrAccel=new Float32Array(total*3),this.arrColor=new Float32Array(total*4),this.arrParams=new Float32Array(total*4);let quad=new three_webgpu.PlaneGeometry(1,1,1,1),geometry=new three_webgpu.InstancedBufferGeometry;geometry.index=quad.index,geometry.attributes=quad.attributes,geometry.instanceCount=total,geometry.setAttribute(`aPosition`,new three_webgpu.InstancedBufferAttribute(this.arrPosition,3)),geometry.setAttribute(`aVelocity`,new three_webgpu.InstancedBufferAttribute(this.arrVelocity,3)),geometry.setAttribute(`aAccel`,new three_webgpu.InstancedBufferAttribute(this.arrAccel,3)),geometry.setAttribute(`aColor`,new three_webgpu.InstancedBufferAttribute(this.arrColor,4)),geometry.setAttribute(`aParams`,new three_webgpu.InstancedBufferAttribute(this.arrParams,4)),this.particleGeometry=geometry,this.particleMaterial=this.createParticleMaterial(),this.points=new three_webgpu.Mesh(geometry,this.particleMaterial),this.points.frustumCulled=!1,this.effectScene.add(this.points)}_samplePointAtLength(points,s,out){if(points.length===1||s<=0){out.copy(points[0]);return}let acc=0;for(let i=0;i<points.length-1;i++){let a=points[i],b=points[i+1],segLen=a.distanceTo(b);if(!(segLen<=1e-9)){if(acc+segLen>=s){out.lerpVectors(a,b,(s-acc)/segLen);return}acc+=segLen}}out.copy(points[points.length-1])}_emitParticle(w,origin){if(!this.arrPosition)return;let idx=w.particleOffset+w.particleCursor;w.particleCursor=(w.particleCursor+1)%w.particleCount;let i3=idx*3,i4=idx*4,theta=Math.random()*Math.PI*2,r=Math.random(),dx=Math.cos(theta)*r,dz=Math.sin(theta)*r,dy=.3+Math.random()*.7,speed=w.sparkSpeed*(.4+Math.random()*.8);this.arrPosition[i3+0]=origin.x,this.arrPosition[i3+1]=origin.y,this.arrPosition[i3+2]=origin.z,this.arrVelocity[i3+0]=dx*speed,this.arrVelocity[i3+1]=dy*speed,this.arrVelocity[i3+2]=dz*speed,this.arrAccel[i3+0]=w.gravity.x,this.arrAccel[i3+1]=w.gravity.y,this.arrAccel[i3+2]=w.gravity.z;let bright=.8+Math.random()*.5;this.arrColor[i4+0]=w.sparkColor.r*bright,this.arrColor[i4+1]=w.sparkColor.g*bright,this.arrColor[i4+2]=w.sparkColor.b*bright,this.arrColor[i4+3]=1,this.arrParams[i4+0]=this.uTime,this.arrParams[i4+1]=w.particleLife*(.6+Math.random()*.8),this.arrParams[i4+2]=Math.random(),this.arrParams[i4+3]=w.particleSize*(.6+Math.random()*.9)}_emit(deltaTime){if(!this.particleGeometry)return;let dirty=!1;for(let w of this.words){if(!w.fireworks||w.particleCount===0)continue;let elapsed=this.uTime-w.wordStart;if(elapsed<0)continue;let local=w.cycleLength>0?elapsed%w.cycleLength:elapsed;for(let s=0;s<w.blocks.length;s++){let b=w.blocks[s],rel=local-b.writeStart;if(rel<0||rel>b.writeDuration)continue;let t=rel/b.writeDuration;this._samplePointAtLength(b.points,t*b.strokeLength,this._tmpTip),w.emitAccum[s]+=w.emissionRate*deltaTime;let n=Math.floor(w.emitAccum[s]);w.emitAccum[s]-=n,n=Math.min(n,w.particleCount);for(let i=0;i<n;i++)this._emitParticle(w,this._tmpTip),dirty=!0}}if(dirty){let g=this.particleGeometry;g.getAttribute(`aPosition`).needsUpdate=!0,g.getAttribute(`aVelocity`).needsUpdate=!0,g.getAttribute(`aAccel`).needsUpdate=!0,g.getAttribute(`aColor`).needsUpdate=!0,g.getAttribute(`aParams`).needsUpdate=!0}}render(renderer,writeBuffer,readBuffer,deltaTime,_maskActive){let active=!!(this.lineMesh||this.points);active&&(this.uTime+=deltaTime==null?0:deltaTime,this._emit(deltaTime==null?0:deltaTime));let targetWidth=readBuffer.width,targetHeight=readBuffer.height;(this.effectRenderTarget.width!==targetWidth||this.effectRenderTarget.height!==targetHeight)&&this.effectRenderTarget.setSize(targetWidth,targetHeight);let oldRenderTarget=renderer.getRenderTarget();if(renderer.setRenderTarget(this.effectRenderTarget),renderer.setClearColor(0,0),renderer.clear(),active){let proj=this.camera.projectionMatrix,view=this.camera.matrixWorldInverse;this.lineMaterial&&(this.uTimeLine.value=this.uTime,this.uResolutionLine.value.set(targetWidth,targetHeight),this.uProjLine.value=proj,this.uViewLine.value=view,this.uPixelRatioLine.value=this.camera.pixelRatio),this.particleMaterial&&(this.uTimeParticle.value=this.uTime,this.uResolutionParticle.value.set(targetWidth,targetHeight),this.uProjParticle.value=proj,this.uViewParticle.value=view),renderer.render(this.effectScene,this.orthoCamera)}renderer.setRenderTarget(oldRenderTarget),this.uBase.value=readBuffer.texture,this.uEffect.value=this.effectRenderTarget.texture,renderer.setRenderTarget(this.renderToScreen?null:writeBuffer),this.blendQuad.render(renderer)}_disposeLineMesh(){this.lineMesh&&(this.effectScene.remove(this.lineMesh),this.lineMesh.geometry.dispose(),this.lineMesh=null),this.lineMaterial&&(this.lineMaterial.dispose(),this.lineMaterial=null)}_disposeParticles(){this.points&&(this.effectScene.remove(this.points),this.points=null),this.particleGeometry&&(this.particleGeometry.dispose(),this.particleGeometry=null),this.particleMaterial&&(this.particleMaterial.dispose(),this.particleMaterial=null),this.arrPosition=null,this.arrVelocity=null,this.arrAccel=null,this.arrColor=null,this.arrParams=null}dispose(){this._disposeLineMesh(),this._disposeParticles(),this.effectRenderTarget.dispose(),this.blendMaterial.dispose(),this.blendQuad.dispose()}};exports.WordPass=WordPass;
338
+ */const require_runtime=require("../../_virtual/_rolldown/runtime.js"),require_full_screen_quad=require("../../five/renderer/tools/full-screen-quad.js"),require_pass=require("../../five/renderer/postprocessing/passes/pass.js"),require_uuid=require("../../five/utils/uuid.js");let tslib=require("tslib"),three_webgpu=require("three/webgpu");three_webgpu=require_runtime.__toESM(three_webgpu,1);let three_tsl=require("three/tsl");var DEFAULT_COLOR=16767392,MAX_FRAME_DELTA_TIME=.1,GLOW_RADIUS_EXTRA=3,WordPass=class extends require_pass.FivePass{constructor(camera,outputType=three_webgpu.UnsignedByteType){super(),this.uTime=0,this.words=[],this.lineMesh=null,this.lineMaterial=null,this.points=null,this.particleMaterial=null,this.particleGeometry=null,this.arrPosition=null,this.arrVelocity=null,this.arrAccel=null,this.arrColor=null,this.arrParams=null,this._tmpTip=new three_webgpu.Vector3,this.uTimeLine=(0,three_tsl.uniform)(0),this.uResolutionLine=(0,three_tsl.uniform)(new three_webgpu.Vector2(1,1)),this.uProjLine=(0,three_tsl.uniform)(new three_webgpu.Matrix4),this.uViewLine=(0,three_tsl.uniform)(new three_webgpu.Matrix4),this.uPixelRatioLine=(0,three_tsl.uniform)(1),this.uMaxDisplayBoost=(0,three_tsl.uniform)(1),this.uTimeParticle=(0,three_tsl.uniform)(0),this.uResolutionParticle=(0,three_tsl.uniform)(new three_webgpu.Vector2(1,1)),this.uProjParticle=(0,three_tsl.uniform)(new three_webgpu.Matrix4),this.uViewParticle=(0,three_tsl.uniform)(new three_webgpu.Matrix4),this.uBase=(0,three_tsl.texture)(new three_webgpu.Texture),this.uEffect=(0,three_tsl.texture)(new three_webgpu.Texture),this.camera=camera,this.effectScene=new three_webgpu.Scene,this.orthoCamera=new three_webgpu.OrthographicCamera(-1,1,1,-1,0,1),this.effectRenderTarget=new three_webgpu.RenderTarget(Math.max(1,this.camera.resolution.x),Math.max(1,this.camera.resolution.y),{type:outputType,minFilter:three_webgpu.LinearFilter,magFilter:three_webgpu.LinearFilter,format:three_webgpu.RGBAFormat}),this.blendMaterial=this.createBlendMaterial(),this.blendQuad=new require_full_screen_quad.FullScreenQuad(this.blendMaterial)}setWords(words){return this.words=words.map(w=>{var _a;return this._resolveWord(w,this.uTime+((_a=w.startTime)==null?0:_a)/1e3)}),this._rebuild(),this.words.map(w=>w.id)}addWord(...words){let added=words.map(w=>{var _a;return this._resolveWord(w,this.uTime+((_a=w.startTime)==null?0:_a)/1e3)});return this.words.push(...added),this._rebuild(),added.map(w=>w.id)}hasWord(id){return this.words.some(w=>w.id===id)}removeWord(...ids){let removed=0;for(let id of ids){let i=this.words.findIndex(w=>w.id===id);if(i===-1){console.warn(`WordPass: word "${id}" not found`);continue}this.words.splice(i,1),removed++}return removed>0&&this._rebuild(),removed}setWord(params){var _a;let{id}=params,updates=(0,tslib.__rest)(params,[`id`]),idx=this.words.findIndex(w=>w.id===id);if(idx===-1){console.warn(`WordPass: word "${id}" not found`);return}let prev=this.words[idx],merged=Object.assign(Object.assign(Object.assign({},prev.source),updates),{id}),wordStart=updates.startTime===void 0?prev.wordStart:this.uTime+((_a=updates.startTime)==null?0:_a)/1e3;this.words[idx]=this._resolveWord(merged,wordStart),this._rebuild()}clearWords(){this.words=[],this._rebuild()}setMaxDisplayBoost(value){this.uMaxDisplayBoost.value=Math.max(value,1)}_resolveWord(w,wordStart){let{color=new three_webgpu.Color(DEFAULT_COLOR),opacity=1,lineWidth=3,hdrIntensity=1,writeSpeed=4,minStrokeDuration=200,strokeGap=120,holdDuration=1500,fadeDuration=1200,loop=!0,restartPause=800,persist=!1,fireworks=!0,fireworksColor,particleCount=400,emissionRate=500,sparkSpeed=.6,particleSize=.012,particleLife=.8,gravity}=w,valid=w.strokes.filter(s=>s.points.length>=2),blocks=[],cursorTime=0,gap=strokeGap/1e3;for(let s of valid){let dur=Math.max(s.totalLength/Math.max(writeSpeed,1e-4),minStrokeDuration/1e3);blocks.push({points:s.points,strokeLength:s.totalLength,writeStart:cursorTime,writeDuration:dur}),cursorTime+=dur+gap}let totalWriteTime=cursorTime>0?cursorTime-gap:0,fadeStart=persist?1e9:totalWriteTime+holdDuration/1e3,fadeDur=persist?1:fadeDuration/1e3,cycleLength=persist?0:loop?fadeStart+fadeDur+restartPause/1e3:0;return{id:w.id||require_uuid.uuid(),source:Object.assign(Object.assign({},w),{id:w.id}),blocks,color:color.clone(),opacity,lineWidth,hdrIntensity:Math.max(hdrIntensity,1),wordStart,fadeStart,fadeDuration:fadeDur,cycleLength,fireworks,sparkColor:fireworksColor?fireworksColor.clone():color.clone().lerp(new three_webgpu.Color(16777215),.4),emissionRate,sparkSpeed,particleSize,particleLife,gravity:gravity?gravity.clone():new three_webgpu.Vector3(0,-.6,0),particleCount:fireworks?Math.max(1,Math.floor(particleCount)):0,particleOffset:0,particleCursor:0,emitAccum:blocks.map(()=>0)}}_rebuild(){this._buildLineMesh(),this._buildParticles()}createLineMaterial(){let vColor=(0,three_tsl.varyingProperty)(`vec4`,`wpColor`),vSegLen=(0,three_tsl.varyingProperty)(`float`,`wpSegLen`),vAccum=(0,three_tsl.varyingProperty)(`float`,`wpAccum`),vStrokeLen=(0,three_tsl.varyingProperty)(`float`,`wpStrokeLen`),vDrawnLen=(0,three_tsl.varyingProperty)(`float`,`wpDrawnLen`),vFade=(0,three_tsl.varyingProperty)(`float`,`wpFade`),vStart=(0,three_tsl.varyingProperty)(`vec2`,`wpStart`),vEnd=(0,three_tsl.varyingProperty)(`vec2`,`wpEnd`),vLineWidth=(0,three_tsl.varyingProperty)(`float`,`wpLineWidth`),vHdrBoost=(0,three_tsl.varyingProperty)(`float`,`wpHdrBoost`),vNdc=(0,three_tsl.varyingProperty)(`vec2`,`wpNdc`),nearEps=.001,attr=(name,type)=>(0,three_tsl.attribute)(name,type),vertex=(0,three_tsl.Fn)(()=>{let instanceStart=attr(`instanceStart`,`vec3`),instanceEnd=attr(`instanceEnd`,`vec3`),instanceColor=attr(`instanceColor`,`vec4`),instanceData=attr(`instanceData`,`vec4`),instanceReveal=attr(`instanceReveal`,`vec2`),instanceTime=attr(`instanceTime`,`vec4`),pos=three_tsl.positionGeometry,accum=instanceData.x,lineWidth=instanceData.y.mul(this.uPixelRatioLine),strokeLen=instanceData.z,writeStart=instanceReveal.x,writeDur=instanceReveal.y,wordStart=instanceTime.x,fadeStart=instanceTime.y,fadeDur=instanceTime.z,cycle=instanceTime.w;vColor.assign(instanceColor);let segLen=(0,three_tsl.length)(instanceEnd.sub(instanceStart));vSegLen.assign(segLen),vAccum.assign(accum),vStrokeLen.assign(strokeLen),vLineWidth.assign(lineWidth);let elapsed=this.uTimeLine.sub(wordStart),local=(0,three_tsl.select)(cycle.greaterThan(0),(0,three_tsl.mod)((0,three_tsl.max)(elapsed,0),cycle),elapsed),drawnLen=(0,three_tsl.clamp)(local.sub(writeStart).div((0,three_tsl.max)(writeDur,1e-4)),0,1).mul(strokeLen).toVar(),fade=(0,three_tsl.float)(1).toVar();(0,three_tsl.If)(local.greaterThanEqual(fadeStart),()=>{fade.assign((0,three_tsl.float)(1).sub((0,three_tsl.clamp)(local.sub(fadeStart).div((0,three_tsl.max)(fadeDur,1e-4)),0,1)))}),(0,three_tsl.If)(elapsed.lessThan(0),()=>{fade.assign(0),drawnLen.assign(0)}),vFade.assign(fade),vDrawnLen.assign(drawnLen);let hdrIntensity=instanceData.w,logContentMax=(0,three_tsl.max)((0,three_tsl.log2)((0,three_tsl.max)(hdrIntensity,1.0001)),1e-4),hdrWeight=(0,three_tsl.clamp)((0,three_tsl.log2)((0,three_tsl.max)(this.uMaxDisplayBoost,1)).div(logContentMax),0,1);vHdrBoost.assign((0,three_tsl.mix)(1,hdrIntensity,hdrWeight));let clipStart=this.uProjLine.mul(this.uViewLine).mul((0,three_tsl.vec4)(instanceStart,1)).toVar(),clipEnd=this.uProjLine.mul(this.uViewLine).mul((0,three_tsl.vec4)(instanceEnd,1)).toVar(),invisible=(0,three_tsl.float)(0).toVar(),startBehind=clipStart.w.lessThan(nearEps).toVar(),endBehind=clipEnd.w.lessThan(nearEps).toVar();(0,three_tsl.If)(startBehind.and(endBehind),()=>{invisible.assign(1)}),(0,three_tsl.If)(startBehind,()=>{let tc=(0,three_tsl.float)(nearEps).sub(clipStart.w).div(clipEnd.w.sub(clipStart.w));clipStart.assign((0,three_tsl.mix)(clipStart,clipEnd,tc))}),(0,three_tsl.If)(endBehind,()=>{let tc=(0,three_tsl.float)(nearEps).sub(clipEnd.w).div(clipStart.w.sub(clipEnd.w));clipEnd.assign((0,three_tsl.mix)(clipEnd,clipStart,tc))});let ndcStart=clipStart.xy.div(clipStart.w),ndcEnd=clipEnd.xy.div(clipEnd.w);vStart.assign(ndcStart),vEnd.assign(ndcEnd);let screenStart=ndcStart.add(1).mul(.5).mul(this.uResolutionLine),screenEnd=ndcEnd.add(1).mul(.5).mul(this.uResolutionLine),seg=screenEnd.sub(screenStart),segLenPix=(0,three_tsl.length)(seg),dir=(0,three_tsl.select)(segLenPix.greaterThan(1e-5),seg.div((0,three_tsl.max)(segLenPix,1e-5)),(0,three_tsl.vec2)(1,0)),normal=(0,three_tsl.vec2)(dir.y.negate(),dir.x),tt=pos.y.add(.5),coverRadius=(0,three_tsl.max)(lineWidth.mul(.5),.5).add(GLOW_RADIUS_EXTRA),extStart=screenStart.sub(dir.mul(coverRadius)),extEnd=screenEnd.add(dir.mul(coverRadius)),offset=normal.mul(pos.x).mul(2).mul(coverRadius),ndc=(0,three_tsl.mix)(extStart,extEnd,tt).add(offset).div(this.uResolutionLine).mul(2).sub(1);vNdc.assign(ndc);let clipPos=(0,three_tsl.mix)(clipStart,clipEnd,tt),safeW=(0,three_tsl.max)(clipPos.w,nearEps);return(0,three_tsl.mix)((0,three_tsl.vec4)(ndc.mul(safeW),clipPos.z,safeW),(0,three_tsl.vec4)(0,0,-2,1),invisible)}),sdCapsule=(0,three_tsl.Fn)(([p,a,b])=>{let pa=p.sub(a),ba=b.sub(a),h=(0,three_tsl.clamp)((0,three_tsl.dot)(pa,ba).div((0,three_tsl.dot)(ba,ba)),0,1);return(0,three_tsl.length)(pa.sub(ba.mul(h)))}),fragment=(0,three_tsl.Fn)(()=>{let uvNdc=vNdc,screenDiff=vEnd.sub(vStart),screenDist=(0,three_tsl.max)((0,three_tsl.length)(screenDiff),1e-6),screenDir=screenDiff.div(screenDist),projRatio=(0,three_tsl.clamp)((0,three_tsl.dot)(uvNdc.sub(vStart),screenDir),0,screenDist).div(screenDist),posAlong=vAccum.add(projRatio.mul(vSegLen)),notDrawn=vDrawnLen.lessThanEqual(1e-4).or(posAlong.greaterThan(vDrawnLen)),aspect=(0,three_tsl.vec2)(this.uResolutionLine.x.div(this.uResolutionLine.y),1),dPix=sdCapsule(uvNdc.mul(aspect),vStart.mul(aspect),vEnd.mul(aspect)).mul(this.uResolutionLine.y).mul(.5),halfW=(0,three_tsl.max)(vLineWidth.mul(.5),.5),core=(0,three_tsl.float)(1).sub((0,three_tsl.smoothstep)(halfW.sub(1),halfW.add(1),dPix)),coverRadius=halfW.add(GLOW_RADIUS_EXTRA),x=(0,three_tsl.clamp)((0,three_tsl.max)(dPix.sub(halfW),0).div((0,three_tsl.max)(coverRadius.sub(halfW),1e-4)),0,1),glow=(0,three_tsl.pow)((0,three_tsl.float)(1).sub(x),4).mul(.9),intensity=(0,three_tsl.clamp)(core.add(glow.mul((0,three_tsl.float)(1).sub(core))),0,1),tip=(0,three_tsl.exp)((0,three_tsl.max)(vDrawnLen.sub(posAlong),0).mul(-5).div((0,three_tsl.max)(vStrokeLen,1e-4))),writing=(0,three_tsl.float)(1).sub((0,three_tsl.smoothstep)(vStrokeLen.mul(.98),vStrokeLen,vDrawnLen)),bright=(0,three_tsl.float)(1).add(tip.mul(.6).mul(writing)),alpha=intensity.mul(vColor.a).mul(vFade),outAlpha=(0,three_tsl.select)(notDrawn.not().and(alpha.greaterThanEqual(.004)),alpha,0);return(0,three_tsl.vec4)(vColor.rgb.mul(bright).mul(vHdrBoost).mul(outAlpha),outAlpha)}),material=new three_webgpu.NodeMaterial;return material.vertexNode=vertex(),material.fragmentNode=fragment(),material.transparent=!0,material.depthTest=!1,material.depthWrite=!1,material.side=three_webgpu.DoubleSide,material.blending=three_webgpu.CustomBlending,material.blendEquation=three_webgpu.MaxEquation,material.blendSrc=three_webgpu.OneFactor,material.blendDst=three_webgpu.OneFactor,material}_buildLineMesh(){this._disposeLineMesh();let totalSegments=0;for(let w of this.words)for(let b of w.blocks)totalSegments+=b.points.length-1;if(totalSegments===0)return;let plane=new three_webgpu.PlaneGeometry(1,1,1,1),geometry=new three_webgpu.InstancedBufferGeometry;geometry.index=plane.index,geometry.attributes=plane.attributes,geometry.instanceCount=totalSegments;let instanceStart=new Float32Array(totalSegments*3),instanceEnd=new Float32Array(totalSegments*3),instanceColor=new Float32Array(totalSegments*4),instanceData=new Float32Array(totalSegments*4),instanceReveal=new Float32Array(totalSegments*2),instanceTime=new Float32Array(totalSegments*4),idx=0;for(let w of this.words)for(let b of w.blocks){let accum=0;for(let i=0;i<b.points.length-1;i++){let start=b.points[i],end=b.points[i+1],segLen=start.distanceTo(end),i2=idx*2,i3=idx*3,i4=idx*4;instanceStart[i3+0]=start.x,instanceStart[i3+1]=start.y,instanceStart[i3+2]=start.z,instanceEnd[i3+0]=end.x,instanceEnd[i3+1]=end.y,instanceEnd[i3+2]=end.z,instanceColor[i4+0]=w.color.r,instanceColor[i4+1]=w.color.g,instanceColor[i4+2]=w.color.b,instanceColor[i4+3]=w.opacity,instanceData[i4+0]=accum,instanceData[i4+1]=w.lineWidth,instanceData[i4+2]=b.strokeLength,instanceData[i4+3]=w.hdrIntensity,instanceReveal[i2+0]=b.writeStart,instanceReveal[i2+1]=b.writeDuration,instanceTime[i4+0]=w.wordStart,instanceTime[i4+1]=w.fadeStart,instanceTime[i4+2]=w.fadeDuration,instanceTime[i4+3]=w.cycleLength,accum+=segLen,idx++}}geometry.setAttribute(`instanceStart`,new three_webgpu.InstancedBufferAttribute(instanceStart,3)),geometry.setAttribute(`instanceEnd`,new three_webgpu.InstancedBufferAttribute(instanceEnd,3)),geometry.setAttribute(`instanceColor`,new three_webgpu.InstancedBufferAttribute(instanceColor,4)),geometry.setAttribute(`instanceData`,new three_webgpu.InstancedBufferAttribute(instanceData,4)),geometry.setAttribute(`instanceReveal`,new three_webgpu.InstancedBufferAttribute(instanceReveal,2)),geometry.setAttribute(`instanceTime`,new three_webgpu.InstancedBufferAttribute(instanceTime,4)),this.lineMaterial=this.createLineMaterial(),this.lineMesh=new three_webgpu.Mesh(geometry,this.lineMaterial),this.lineMesh.frustumCulled=!1,this.effectScene.add(this.lineMesh)}createParticleMaterial(){let vColor=(0,three_tsl.varyingProperty)(`vec4`,`wpSparkColor`),vAlpha=(0,three_tsl.varyingProperty)(`float`,`wpSparkAlpha`),vLocal=(0,three_tsl.varyingProperty)(`vec2`,`wpSparkLocal`),eps=.001,attr=(name,type)=>(0,three_tsl.attribute)(name,type),vertex=(0,three_tsl.Fn)(()=>{let birth=attr(`aPosition`,`vec3`),aVelocity=attr(`aVelocity`,`vec3`),aAccel=attr(`aAccel`,`vec3`),aColor=attr(`aColor`,`vec4`),aParams=attr(`aParams`,`vec4`),aBirthTime=aParams.x,aMaxLife=aParams.y,aSeed=aParams.z,aSize=aParams.w,corner=three_tsl.positionGeometry.xy;vColor.assign(aColor),vLocal.assign(corner);let age=this.uTimeParticle.sub(aBirthTime),invisible=(0,three_tsl.float)(0).toVar();(0,three_tsl.If)(aMaxLife.lessThanEqual(0).or(age.lessThan(0)).or(age.greaterThan(aMaxLife)),()=>{invisible.assign(1)});let lifeT=age.div((0,three_tsl.max)(aMaxLife,eps)),worldPos=birth.add(aVelocity.mul(age)).add(aAccel.mul(.5).mul(age).mul(age)),clip=this.uProjParticle.mul(this.uViewParticle).mul((0,three_tsl.vec4)(worldPos,1)).toVar();(0,three_tsl.If)(clip.w.lessThanEqual(eps),()=>{invisible.assign(1)});let safeW=(0,three_tsl.max)(clip.w,eps),ndc=clip.xy.div(safeW),p11=this.uProjParticle.element(1).y,sizeFade=(0,three_tsl.float)(1).sub(lifeT.mul(.7)),pixelSize=(0,three_tsl.max)(aSize.mul(p11).mul(.5).mul(this.uResolutionParticle.y).div(safeW).mul(sizeFade),0),ndc2=ndc.add(1).mul(.5).mul(this.uResolutionParticle).add(corner.mul(pixelSize)).div(this.uResolutionParticle).mul(2).sub(1),twinkle=(0,three_tsl.float)(.7).add((0,three_tsl.float)(.3).mul((0,three_tsl.sin)(this.uTimeParticle.mul(30).add(aSeed.mul(6.2831)))));return vAlpha.assign((0,three_tsl.pow)((0,three_tsl.float)(1).sub(lifeT),.8).mul(twinkle)),(0,three_tsl.mix)((0,three_tsl.vec4)(ndc2.mul(safeW),clip.z,safeW),(0,three_tsl.vec4)(0,0,-2,1),invisible)}),fragment=(0,three_tsl.Fn)(()=>{let core=(0,three_tsl.smoothstep)(.5,0,(0,three_tsl.length)(vLocal)),intensity=core.mul(core).mul(vAlpha).mul(vColor.a);return(0,three_tsl.vec4)(vColor.rgb,intensity)}),material=new three_webgpu.NodeMaterial;return material.vertexNode=vertex(),material.fragmentNode=fragment(),material.transparent=!0,material.depthTest=!1,material.depthWrite=!1,material.blending=three_webgpu.AdditiveBlending,material}createBlendMaterial(){let material=new three_webgpu.NodeMaterial,base=this.uBase.sample((0,three_tsl.uv)()),effect=this.uEffect.sample((0,three_tsl.uv)());return material.fragmentNode=(0,three_tsl.vec4)(base.rgb.add(effect.rgb),base.a),material.transparent=!1,material.depthTest=!1,material.depthWrite=!1,material}_buildParticles(){this._disposeParticles();let total=0;for(let w of this.words)w.particleOffset=total,w.particleCursor=0,total+=w.particleCount;if(total===0)return;this.arrPosition=new Float32Array(total*3),this.arrVelocity=new Float32Array(total*3),this.arrAccel=new Float32Array(total*3),this.arrColor=new Float32Array(total*4),this.arrParams=new Float32Array(total*4);let quad=new three_webgpu.PlaneGeometry(1,1,1,1),geometry=new three_webgpu.InstancedBufferGeometry;geometry.index=quad.index,geometry.attributes=quad.attributes,geometry.instanceCount=total,geometry.setAttribute(`aPosition`,new three_webgpu.InstancedBufferAttribute(this.arrPosition,3)),geometry.setAttribute(`aVelocity`,new three_webgpu.InstancedBufferAttribute(this.arrVelocity,3)),geometry.setAttribute(`aAccel`,new three_webgpu.InstancedBufferAttribute(this.arrAccel,3)),geometry.setAttribute(`aColor`,new three_webgpu.InstancedBufferAttribute(this.arrColor,4)),geometry.setAttribute(`aParams`,new three_webgpu.InstancedBufferAttribute(this.arrParams,4)),this.particleGeometry=geometry,this.particleMaterial=this.createParticleMaterial(),this.points=new three_webgpu.Mesh(geometry,this.particleMaterial),this.points.frustumCulled=!1,this.effectScene.add(this.points)}_samplePointAtLength(points,s,out){if(points.length===1||s<=0){out.copy(points[0]);return}let acc=0;for(let i=0;i<points.length-1;i++){let a=points[i],b=points[i+1],segLen=a.distanceTo(b);if(!(segLen<=1e-9)){if(acc+segLen>=s){out.lerpVectors(a,b,(s-acc)/segLen);return}acc+=segLen}}out.copy(points[points.length-1])}_emitParticle(w,origin){if(!this.arrPosition)return;let idx=w.particleOffset+w.particleCursor;w.particleCursor=(w.particleCursor+1)%w.particleCount;let i3=idx*3,i4=idx*4,theta=Math.random()*Math.PI*2,r=Math.random(),dx=Math.cos(theta)*r,dz=Math.sin(theta)*r,dy=.3+Math.random()*.7,speed=w.sparkSpeed*(.4+Math.random()*.8);this.arrPosition[i3+0]=origin.x,this.arrPosition[i3+1]=origin.y,this.arrPosition[i3+2]=origin.z,this.arrVelocity[i3+0]=dx*speed,this.arrVelocity[i3+1]=dy*speed,this.arrVelocity[i3+2]=dz*speed,this.arrAccel[i3+0]=w.gravity.x,this.arrAccel[i3+1]=w.gravity.y,this.arrAccel[i3+2]=w.gravity.z;let bright=.8+Math.random()*.5;this.arrColor[i4+0]=w.sparkColor.r*bright,this.arrColor[i4+1]=w.sparkColor.g*bright,this.arrColor[i4+2]=w.sparkColor.b*bright,this.arrColor[i4+3]=1,this.arrParams[i4+0]=this.uTime,this.arrParams[i4+1]=w.particleLife*(.6+Math.random()*.8),this.arrParams[i4+2]=Math.random(),this.arrParams[i4+3]=w.particleSize*(.6+Math.random()*.9)}_emit(deltaTime){if(!this.particleGeometry)return;let dirty=!1;for(let w of this.words){if(!w.fireworks||w.particleCount===0)continue;let elapsed=this.uTime-w.wordStart;if(elapsed<0)continue;let local=w.cycleLength>0?elapsed%w.cycleLength:elapsed;for(let s=0;s<w.blocks.length;s++){let b=w.blocks[s],rel=local-b.writeStart;if(rel<0||rel>b.writeDuration)continue;let t=rel/b.writeDuration;this._samplePointAtLength(b.points,t*b.strokeLength,this._tmpTip),w.emitAccum[s]+=w.emissionRate*deltaTime;let n=Math.floor(w.emitAccum[s]);w.emitAccum[s]-=n,n=Math.min(n,w.particleCount);for(let i=0;i<n;i++)this._emitParticle(w,this._tmpTip),dirty=!0}}if(dirty){let g=this.particleGeometry;g.getAttribute(`aPosition`).needsUpdate=!0,g.getAttribute(`aVelocity`).needsUpdate=!0,g.getAttribute(`aAccel`).needsUpdate=!0,g.getAttribute(`aColor`).needsUpdate=!0,g.getAttribute(`aParams`).needsUpdate=!0}}render(renderer,writeBuffer,readBuffer,deltaTime,_maskActive){let active=!!(this.lineMesh||this.points);if(active){let dt=Math.min(Math.max(deltaTime==null?0:deltaTime,0),MAX_FRAME_DELTA_TIME);this.uTime+=dt,this._emit(dt)}let targetWidth=readBuffer.width,targetHeight=readBuffer.height;(this.effectRenderTarget.width!==targetWidth||this.effectRenderTarget.height!==targetHeight)&&this.effectRenderTarget.setSize(targetWidth,targetHeight);let oldRenderTarget=renderer.getRenderTarget();if(renderer.setRenderTarget(this.effectRenderTarget),renderer.setClearColor(0,0),renderer.clear(),active){let proj=this.camera.projectionMatrix,view=this.camera.matrixWorldInverse;this.lineMaterial&&(this.uTimeLine.value=this.uTime,this.uResolutionLine.value.set(targetWidth,targetHeight),this.uProjLine.value=proj,this.uViewLine.value=view,this.uPixelRatioLine.value=this.camera.pixelRatio),this.particleMaterial&&(this.uTimeParticle.value=this.uTime,this.uResolutionParticle.value.set(targetWidth,targetHeight),this.uProjParticle.value=proj,this.uViewParticle.value=view),renderer.render(this.effectScene,this.orthoCamera)}renderer.setRenderTarget(oldRenderTarget),this.uBase.value=readBuffer.texture,this.uEffect.value=this.effectRenderTarget.texture,renderer.setRenderTarget(this.renderToScreen?null:writeBuffer),this.blendQuad.render(renderer)}_disposeLineMesh(){this.lineMesh&&(this.effectScene.remove(this.lineMesh),this.lineMesh.geometry.dispose(),this.lineMesh=null),this.lineMaterial&&(this.lineMaterial.dispose(),this.lineMaterial=null)}_disposeParticles(){this.points&&(this.effectScene.remove(this.points),this.points=null),this.particleGeometry&&(this.particleGeometry.dispose(),this.particleGeometry=null),this.particleMaterial&&(this.particleMaterial.dispose(),this.particleMaterial=null),this.arrPosition=null,this.arrVelocity=null,this.arrAccel=null,this.arrColor=null,this.arrParams=null}dispose(){this._disposeLineMesh(),this._disposeParticles(),this.effectRenderTarget.dispose(),this.blendMaterial.dispose(),this.blendQuad.dispose()}};exports.WordPass=WordPass;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -335,4 +335,4 @@
335
335
  * writing and signed by Realsee. You and Realsee hereto confirm that this
336
336
  * Agreement and all related documents shall be drafted in English.
337
337
 
338
- */import{FullScreenQuad}from"../../five/renderer/tools/full-screen-quad.mjs";import{FivePass}from"../../five/renderer/postprocessing/passes/pass.mjs";import{uuid as createUuid}from"../../five/utils/uuid.mjs";import{__rest}from"tslib";import*as THREE from"three/webgpu";import{Fn,If,attribute,clamp,dot,exp,float,length,log2,max,mix,mod,positionGeometry,pow,select,sin,smoothstep,texture,uniform,uv,varyingProperty,vec2,vec4}from"three/tsl";var DEFAULT_COLOR=16767392,GLOW_RADIUS_EXTRA=3,WordPass=class extends FivePass{constructor(camera,outputType=THREE.UnsignedByteType){super(),this.uTime=0,this.words=[],this.lineMesh=null,this.lineMaterial=null,this.points=null,this.particleMaterial=null,this.particleGeometry=null,this.arrPosition=null,this.arrVelocity=null,this.arrAccel=null,this.arrColor=null,this.arrParams=null,this._tmpTip=new THREE.Vector3,this.uTimeLine=uniform(0),this.uResolutionLine=uniform(new THREE.Vector2(1,1)),this.uProjLine=uniform(new THREE.Matrix4),this.uViewLine=uniform(new THREE.Matrix4),this.uPixelRatioLine=uniform(1),this.uMaxDisplayBoost=uniform(1),this.uTimeParticle=uniform(0),this.uResolutionParticle=uniform(new THREE.Vector2(1,1)),this.uProjParticle=uniform(new THREE.Matrix4),this.uViewParticle=uniform(new THREE.Matrix4),this.uBase=texture(new THREE.Texture),this.uEffect=texture(new THREE.Texture),this.camera=camera,this.effectScene=new THREE.Scene,this.orthoCamera=new THREE.OrthographicCamera(-1,1,1,-1,0,1),this.effectRenderTarget=new THREE.RenderTarget(Math.max(1,this.camera.resolution.x),Math.max(1,this.camera.resolution.y),{type:outputType,minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBAFormat}),this.blendMaterial=this.createBlendMaterial(),this.blendQuad=new FullScreenQuad(this.blendMaterial)}setWords(words){return this.words=words.map(w=>{var _a;return this._resolveWord(w,this.uTime+((_a=w.startTime)==null?0:_a)/1e3)}),this._rebuild(),this.words.map(w=>w.id)}addWord(...words){let added=words.map(w=>{var _a;return this._resolveWord(w,this.uTime+((_a=w.startTime)==null?0:_a)/1e3)});return this.words.push(...added),this._rebuild(),added.map(w=>w.id)}hasWord(id){return this.words.some(w=>w.id===id)}removeWord(...ids){let removed=0;for(let id of ids){let i=this.words.findIndex(w=>w.id===id);if(i===-1){console.warn(`WordPass: word "${id}" not found`);continue}this.words.splice(i,1),removed++}return removed>0&&this._rebuild(),removed}setWord(params){var _a;let{id}=params,updates=__rest(params,[`id`]),idx=this.words.findIndex(w=>w.id===id);if(idx===-1){console.warn(`WordPass: word "${id}" not found`);return}let prev=this.words[idx],merged=Object.assign(Object.assign(Object.assign({},prev.source),updates),{id}),wordStart=updates.startTime===void 0?prev.wordStart:this.uTime+((_a=updates.startTime)==null?0:_a)/1e3;this.words[idx]=this._resolveWord(merged,wordStart),this._rebuild()}clearWords(){this.words=[],this._rebuild()}setMaxDisplayBoost(value){this.uMaxDisplayBoost.value=Math.max(value,1)}_resolveWord(w,wordStart){let{color=new THREE.Color(DEFAULT_COLOR),opacity=1,lineWidth=3,hdrIntensity=1,writeSpeed=4,minStrokeDuration=200,strokeGap=120,holdDuration=1500,fadeDuration=1200,loop=!0,restartPause=800,persist=!1,fireworks=!0,fireworksColor,particleCount=400,emissionRate=500,sparkSpeed=.6,particleSize=.012,particleLife=.8,gravity}=w,valid=w.strokes.filter(s=>s.points.length>=2),blocks=[],cursorTime=0,gap=strokeGap/1e3;for(let s of valid){let dur=Math.max(s.totalLength/Math.max(writeSpeed,1e-4),minStrokeDuration/1e3);blocks.push({points:s.points,strokeLength:s.totalLength,writeStart:cursorTime,writeDuration:dur}),cursorTime+=dur+gap}let totalWriteTime=cursorTime>0?cursorTime-gap:0,fadeStart=persist?1e9:totalWriteTime+holdDuration/1e3,fadeDur=persist?1:fadeDuration/1e3,cycleLength=persist?0:loop?fadeStart+fadeDur+restartPause/1e3:0;return{id:w.id||createUuid(),source:Object.assign(Object.assign({},w),{id:w.id}),blocks,color:color.clone(),opacity,lineWidth,hdrIntensity:Math.max(hdrIntensity,1),wordStart,fadeStart,fadeDuration:fadeDur,cycleLength,fireworks,sparkColor:fireworksColor?fireworksColor.clone():color.clone().lerp(new THREE.Color(16777215),.4),emissionRate,sparkSpeed,particleSize,particleLife,gravity:gravity?gravity.clone():new THREE.Vector3(0,-.6,0),particleCount:fireworks?Math.max(1,Math.floor(particleCount)):0,particleOffset:0,particleCursor:0,emitAccum:blocks.map(()=>0)}}_rebuild(){this._buildLineMesh(),this._buildParticles()}createLineMaterial(){let vColor=varyingProperty(`vec4`,`wpColor`),vSegLen=varyingProperty(`float`,`wpSegLen`),vAccum=varyingProperty(`float`,`wpAccum`),vStrokeLen=varyingProperty(`float`,`wpStrokeLen`),vDrawnLen=varyingProperty(`float`,`wpDrawnLen`),vFade=varyingProperty(`float`,`wpFade`),vStart=varyingProperty(`vec2`,`wpStart`),vEnd=varyingProperty(`vec2`,`wpEnd`),vLineWidth=varyingProperty(`float`,`wpLineWidth`),vHdrBoost=varyingProperty(`float`,`wpHdrBoost`),vNdc=varyingProperty(`vec2`,`wpNdc`),nearEps=.001,attr=(name,type)=>attribute(name,type),vertex=Fn(()=>{let instanceStart=attr(`instanceStart`,`vec3`),instanceEnd=attr(`instanceEnd`,`vec3`),instanceColor=attr(`instanceColor`,`vec4`),instanceData=attr(`instanceData`,`vec4`),instanceReveal=attr(`instanceReveal`,`vec2`),instanceTime=attr(`instanceTime`,`vec4`),pos=positionGeometry,accum=instanceData.x,lineWidth=instanceData.y.mul(this.uPixelRatioLine),strokeLen=instanceData.z,writeStart=instanceReveal.x,writeDur=instanceReveal.y,wordStart=instanceTime.x,fadeStart=instanceTime.y,fadeDur=instanceTime.z,cycle=instanceTime.w;vColor.assign(instanceColor);let segLen=length(instanceEnd.sub(instanceStart));vSegLen.assign(segLen),vAccum.assign(accum),vStrokeLen.assign(strokeLen),vLineWidth.assign(lineWidth);let elapsed=this.uTimeLine.sub(wordStart),local=select(cycle.greaterThan(0),mod(max(elapsed,0),cycle),elapsed),drawnLen=clamp(local.sub(writeStart).div(max(writeDur,1e-4)),0,1).mul(strokeLen).toVar(),fade=float(1).toVar();If(local.greaterThanEqual(fadeStart),()=>{fade.assign(float(1).sub(clamp(local.sub(fadeStart).div(max(fadeDur,1e-4)),0,1)))}),If(elapsed.lessThan(0),()=>{fade.assign(0),drawnLen.assign(0)}),vFade.assign(fade),vDrawnLen.assign(drawnLen);let hdrIntensity=instanceData.w,logContentMax=max(log2(max(hdrIntensity,1.0001)),1e-4),hdrWeight=clamp(log2(max(this.uMaxDisplayBoost,1)).div(logContentMax),0,1);vHdrBoost.assign(mix(1,hdrIntensity,hdrWeight));let clipStart=this.uProjLine.mul(this.uViewLine).mul(vec4(instanceStart,1)).toVar(),clipEnd=this.uProjLine.mul(this.uViewLine).mul(vec4(instanceEnd,1)).toVar(),invisible=float(0).toVar(),startBehind=clipStart.w.lessThan(nearEps).toVar(),endBehind=clipEnd.w.lessThan(nearEps).toVar();If(startBehind.and(endBehind),()=>{invisible.assign(1)}),If(startBehind,()=>{let tc=float(nearEps).sub(clipStart.w).div(clipEnd.w.sub(clipStart.w));clipStart.assign(mix(clipStart,clipEnd,tc))}),If(endBehind,()=>{let tc=float(nearEps).sub(clipEnd.w).div(clipStart.w.sub(clipEnd.w));clipEnd.assign(mix(clipEnd,clipStart,tc))});let ndcStart=clipStart.xy.div(clipStart.w),ndcEnd=clipEnd.xy.div(clipEnd.w);vStart.assign(ndcStart),vEnd.assign(ndcEnd);let screenStart=ndcStart.add(1).mul(.5).mul(this.uResolutionLine),screenEnd=ndcEnd.add(1).mul(.5).mul(this.uResolutionLine),seg=screenEnd.sub(screenStart),segLenPix=length(seg),dir=select(segLenPix.greaterThan(1e-5),seg.div(max(segLenPix,1e-5)),vec2(1,0)),normal=vec2(dir.y.negate(),dir.x),tt=pos.y.add(.5),coverRadius=max(lineWidth.mul(.5),.5).add(GLOW_RADIUS_EXTRA),extStart=screenStart.sub(dir.mul(coverRadius)),extEnd=screenEnd.add(dir.mul(coverRadius)),offset=normal.mul(pos.x).mul(2).mul(coverRadius),ndc=mix(extStart,extEnd,tt).add(offset).div(this.uResolutionLine).mul(2).sub(1);vNdc.assign(ndc);let clipPos=mix(clipStart,clipEnd,tt),safeW=max(clipPos.w,nearEps);return mix(vec4(ndc.mul(safeW),clipPos.z,safeW),vec4(0,0,-2,1),invisible)}),sdCapsule=Fn(([p,a,b])=>{let pa=p.sub(a),ba=b.sub(a),h=clamp(dot(pa,ba).div(dot(ba,ba)),0,1);return length(pa.sub(ba.mul(h)))}),fragment=Fn(()=>{let uvNdc=vNdc,screenDiff=vEnd.sub(vStart),screenDist=max(length(screenDiff),1e-6),screenDir=screenDiff.div(screenDist),projRatio=clamp(dot(uvNdc.sub(vStart),screenDir),0,screenDist).div(screenDist),posAlong=vAccum.add(projRatio.mul(vSegLen)),notDrawn=vDrawnLen.lessThanEqual(1e-4).or(posAlong.greaterThan(vDrawnLen)),aspect=vec2(this.uResolutionLine.x.div(this.uResolutionLine.y),1),dPix=sdCapsule(uvNdc.mul(aspect),vStart.mul(aspect),vEnd.mul(aspect)).mul(this.uResolutionLine.y).mul(.5),halfW=max(vLineWidth.mul(.5),.5),core=float(1).sub(smoothstep(halfW.sub(1),halfW.add(1),dPix)),coverRadius=halfW.add(GLOW_RADIUS_EXTRA),x=clamp(max(dPix.sub(halfW),0).div(max(coverRadius.sub(halfW),1e-4)),0,1),glow=pow(float(1).sub(x),4).mul(.9),intensity=clamp(core.add(glow.mul(float(1).sub(core))),0,1),tip=exp(max(vDrawnLen.sub(posAlong),0).mul(-5).div(max(vStrokeLen,1e-4))),writing=float(1).sub(smoothstep(vStrokeLen.mul(.98),vStrokeLen,vDrawnLen)),bright=float(1).add(tip.mul(.6).mul(writing)),alpha=intensity.mul(vColor.a).mul(vFade),outAlpha=select(notDrawn.not().and(alpha.greaterThanEqual(.004)),alpha,0);return vec4(vColor.rgb.mul(bright).mul(vHdrBoost).mul(outAlpha),outAlpha)}),material=new THREE.NodeMaterial;return material.vertexNode=vertex(),material.fragmentNode=fragment(),material.transparent=!0,material.depthTest=!1,material.depthWrite=!1,material.side=THREE.DoubleSide,material.blending=THREE.CustomBlending,material.blendEquation=THREE.MaxEquation,material.blendSrc=THREE.OneFactor,material.blendDst=THREE.OneFactor,material}_buildLineMesh(){this._disposeLineMesh();let totalSegments=0;for(let w of this.words)for(let b of w.blocks)totalSegments+=b.points.length-1;if(totalSegments===0)return;let plane=new THREE.PlaneGeometry(1,1,1,1),geometry=new THREE.InstancedBufferGeometry;geometry.index=plane.index,geometry.attributes=plane.attributes,geometry.instanceCount=totalSegments;let instanceStart=new Float32Array(totalSegments*3),instanceEnd=new Float32Array(totalSegments*3),instanceColor=new Float32Array(totalSegments*4),instanceData=new Float32Array(totalSegments*4),instanceReveal=new Float32Array(totalSegments*2),instanceTime=new Float32Array(totalSegments*4),idx=0;for(let w of this.words)for(let b of w.blocks){let accum=0;for(let i=0;i<b.points.length-1;i++){let start=b.points[i],end=b.points[i+1],segLen=start.distanceTo(end),i2=idx*2,i3=idx*3,i4=idx*4;instanceStart[i3+0]=start.x,instanceStart[i3+1]=start.y,instanceStart[i3+2]=start.z,instanceEnd[i3+0]=end.x,instanceEnd[i3+1]=end.y,instanceEnd[i3+2]=end.z,instanceColor[i4+0]=w.color.r,instanceColor[i4+1]=w.color.g,instanceColor[i4+2]=w.color.b,instanceColor[i4+3]=w.opacity,instanceData[i4+0]=accum,instanceData[i4+1]=w.lineWidth,instanceData[i4+2]=b.strokeLength,instanceData[i4+3]=w.hdrIntensity,instanceReveal[i2+0]=b.writeStart,instanceReveal[i2+1]=b.writeDuration,instanceTime[i4+0]=w.wordStart,instanceTime[i4+1]=w.fadeStart,instanceTime[i4+2]=w.fadeDuration,instanceTime[i4+3]=w.cycleLength,accum+=segLen,idx++}}geometry.setAttribute(`instanceStart`,new THREE.InstancedBufferAttribute(instanceStart,3)),geometry.setAttribute(`instanceEnd`,new THREE.InstancedBufferAttribute(instanceEnd,3)),geometry.setAttribute(`instanceColor`,new THREE.InstancedBufferAttribute(instanceColor,4)),geometry.setAttribute(`instanceData`,new THREE.InstancedBufferAttribute(instanceData,4)),geometry.setAttribute(`instanceReveal`,new THREE.InstancedBufferAttribute(instanceReveal,2)),geometry.setAttribute(`instanceTime`,new THREE.InstancedBufferAttribute(instanceTime,4)),this.lineMaterial=this.createLineMaterial(),this.lineMesh=new THREE.Mesh(geometry,this.lineMaterial),this.lineMesh.frustumCulled=!1,this.effectScene.add(this.lineMesh)}createParticleMaterial(){let vColor=varyingProperty(`vec4`,`wpSparkColor`),vAlpha=varyingProperty(`float`,`wpSparkAlpha`),vLocal=varyingProperty(`vec2`,`wpSparkLocal`),eps=.001,attr=(name,type)=>attribute(name,type),vertex=Fn(()=>{let birth=attr(`aPosition`,`vec3`),aVelocity=attr(`aVelocity`,`vec3`),aAccel=attr(`aAccel`,`vec3`),aColor=attr(`aColor`,`vec4`),aParams=attr(`aParams`,`vec4`),aBirthTime=aParams.x,aMaxLife=aParams.y,aSeed=aParams.z,aSize=aParams.w,corner=positionGeometry.xy;vColor.assign(aColor),vLocal.assign(corner);let age=this.uTimeParticle.sub(aBirthTime),invisible=float(0).toVar();If(aMaxLife.lessThanEqual(0).or(age.lessThan(0)).or(age.greaterThan(aMaxLife)),()=>{invisible.assign(1)});let lifeT=age.div(max(aMaxLife,eps)),worldPos=birth.add(aVelocity.mul(age)).add(aAccel.mul(.5).mul(age).mul(age)),clip=this.uProjParticle.mul(this.uViewParticle).mul(vec4(worldPos,1)).toVar();If(clip.w.lessThanEqual(eps),()=>{invisible.assign(1)});let safeW=max(clip.w,eps),ndc=clip.xy.div(safeW),p11=this.uProjParticle.element(1).y,sizeFade=float(1).sub(lifeT.mul(.7)),pixelSize=max(aSize.mul(p11).mul(.5).mul(this.uResolutionParticle.y).div(safeW).mul(sizeFade),0),ndc2=ndc.add(1).mul(.5).mul(this.uResolutionParticle).add(corner.mul(pixelSize)).div(this.uResolutionParticle).mul(2).sub(1),twinkle=float(.7).add(float(.3).mul(sin(this.uTimeParticle.mul(30).add(aSeed.mul(6.2831)))));return vAlpha.assign(pow(float(1).sub(lifeT),.8).mul(twinkle)),mix(vec4(ndc2.mul(safeW),clip.z,safeW),vec4(0,0,-2,1),invisible)}),fragment=Fn(()=>{let core=smoothstep(.5,0,length(vLocal)),intensity=core.mul(core).mul(vAlpha).mul(vColor.a);return vec4(vColor.rgb,intensity)}),material=new THREE.NodeMaterial;return material.vertexNode=vertex(),material.fragmentNode=fragment(),material.transparent=!0,material.depthTest=!1,material.depthWrite=!1,material.blending=THREE.AdditiveBlending,material}createBlendMaterial(){let material=new THREE.NodeMaterial,base=this.uBase.sample(uv()),effect=this.uEffect.sample(uv());return material.fragmentNode=vec4(base.rgb.add(effect.rgb),base.a),material.transparent=!1,material.depthTest=!1,material.depthWrite=!1,material}_buildParticles(){this._disposeParticles();let total=0;for(let w of this.words)w.particleOffset=total,w.particleCursor=0,total+=w.particleCount;if(total===0)return;this.arrPosition=new Float32Array(total*3),this.arrVelocity=new Float32Array(total*3),this.arrAccel=new Float32Array(total*3),this.arrColor=new Float32Array(total*4),this.arrParams=new Float32Array(total*4);let quad=new THREE.PlaneGeometry(1,1,1,1),geometry=new THREE.InstancedBufferGeometry;geometry.index=quad.index,geometry.attributes=quad.attributes,geometry.instanceCount=total,geometry.setAttribute(`aPosition`,new THREE.InstancedBufferAttribute(this.arrPosition,3)),geometry.setAttribute(`aVelocity`,new THREE.InstancedBufferAttribute(this.arrVelocity,3)),geometry.setAttribute(`aAccel`,new THREE.InstancedBufferAttribute(this.arrAccel,3)),geometry.setAttribute(`aColor`,new THREE.InstancedBufferAttribute(this.arrColor,4)),geometry.setAttribute(`aParams`,new THREE.InstancedBufferAttribute(this.arrParams,4)),this.particleGeometry=geometry,this.particleMaterial=this.createParticleMaterial(),this.points=new THREE.Mesh(geometry,this.particleMaterial),this.points.frustumCulled=!1,this.effectScene.add(this.points)}_samplePointAtLength(points,s,out){if(points.length===1||s<=0){out.copy(points[0]);return}let acc=0;for(let i=0;i<points.length-1;i++){let a=points[i],b=points[i+1],segLen=a.distanceTo(b);if(!(segLen<=1e-9)){if(acc+segLen>=s){out.lerpVectors(a,b,(s-acc)/segLen);return}acc+=segLen}}out.copy(points[points.length-1])}_emitParticle(w,origin){if(!this.arrPosition)return;let idx=w.particleOffset+w.particleCursor;w.particleCursor=(w.particleCursor+1)%w.particleCount;let i3=idx*3,i4=idx*4,theta=Math.random()*Math.PI*2,r=Math.random(),dx=Math.cos(theta)*r,dz=Math.sin(theta)*r,dy=.3+Math.random()*.7,speed=w.sparkSpeed*(.4+Math.random()*.8);this.arrPosition[i3+0]=origin.x,this.arrPosition[i3+1]=origin.y,this.arrPosition[i3+2]=origin.z,this.arrVelocity[i3+0]=dx*speed,this.arrVelocity[i3+1]=dy*speed,this.arrVelocity[i3+2]=dz*speed,this.arrAccel[i3+0]=w.gravity.x,this.arrAccel[i3+1]=w.gravity.y,this.arrAccel[i3+2]=w.gravity.z;let bright=.8+Math.random()*.5;this.arrColor[i4+0]=w.sparkColor.r*bright,this.arrColor[i4+1]=w.sparkColor.g*bright,this.arrColor[i4+2]=w.sparkColor.b*bright,this.arrColor[i4+3]=1,this.arrParams[i4+0]=this.uTime,this.arrParams[i4+1]=w.particleLife*(.6+Math.random()*.8),this.arrParams[i4+2]=Math.random(),this.arrParams[i4+3]=w.particleSize*(.6+Math.random()*.9)}_emit(deltaTime){if(!this.particleGeometry)return;let dirty=!1;for(let w of this.words){if(!w.fireworks||w.particleCount===0)continue;let elapsed=this.uTime-w.wordStart;if(elapsed<0)continue;let local=w.cycleLength>0?elapsed%w.cycleLength:elapsed;for(let s=0;s<w.blocks.length;s++){let b=w.blocks[s],rel=local-b.writeStart;if(rel<0||rel>b.writeDuration)continue;let t=rel/b.writeDuration;this._samplePointAtLength(b.points,t*b.strokeLength,this._tmpTip),w.emitAccum[s]+=w.emissionRate*deltaTime;let n=Math.floor(w.emitAccum[s]);w.emitAccum[s]-=n,n=Math.min(n,w.particleCount);for(let i=0;i<n;i++)this._emitParticle(w,this._tmpTip),dirty=!0}}if(dirty){let g=this.particleGeometry;g.getAttribute(`aPosition`).needsUpdate=!0,g.getAttribute(`aVelocity`).needsUpdate=!0,g.getAttribute(`aAccel`).needsUpdate=!0,g.getAttribute(`aColor`).needsUpdate=!0,g.getAttribute(`aParams`).needsUpdate=!0}}render(renderer,writeBuffer,readBuffer,deltaTime,_maskActive){let active=!!(this.lineMesh||this.points);active&&(this.uTime+=deltaTime==null?0:deltaTime,this._emit(deltaTime==null?0:deltaTime));let targetWidth=readBuffer.width,targetHeight=readBuffer.height;(this.effectRenderTarget.width!==targetWidth||this.effectRenderTarget.height!==targetHeight)&&this.effectRenderTarget.setSize(targetWidth,targetHeight);let oldRenderTarget=renderer.getRenderTarget();if(renderer.setRenderTarget(this.effectRenderTarget),renderer.setClearColor(0,0),renderer.clear(),active){let proj=this.camera.projectionMatrix,view=this.camera.matrixWorldInverse;this.lineMaterial&&(this.uTimeLine.value=this.uTime,this.uResolutionLine.value.set(targetWidth,targetHeight),this.uProjLine.value=proj,this.uViewLine.value=view,this.uPixelRatioLine.value=this.camera.pixelRatio),this.particleMaterial&&(this.uTimeParticle.value=this.uTime,this.uResolutionParticle.value.set(targetWidth,targetHeight),this.uProjParticle.value=proj,this.uViewParticle.value=view),renderer.render(this.effectScene,this.orthoCamera)}renderer.setRenderTarget(oldRenderTarget),this.uBase.value=readBuffer.texture,this.uEffect.value=this.effectRenderTarget.texture,renderer.setRenderTarget(this.renderToScreen?null:writeBuffer),this.blendQuad.render(renderer)}_disposeLineMesh(){this.lineMesh&&(this.effectScene.remove(this.lineMesh),this.lineMesh.geometry.dispose(),this.lineMesh=null),this.lineMaterial&&(this.lineMaterial.dispose(),this.lineMaterial=null)}_disposeParticles(){this.points&&(this.effectScene.remove(this.points),this.points=null),this.particleGeometry&&(this.particleGeometry.dispose(),this.particleGeometry=null),this.particleMaterial&&(this.particleMaterial.dispose(),this.particleMaterial=null),this.arrPosition=null,this.arrVelocity=null,this.arrAccel=null,this.arrColor=null,this.arrParams=null}dispose(){this._disposeLineMesh(),this._disposeParticles(),this.effectRenderTarget.dispose(),this.blendMaterial.dispose(),this.blendQuad.dispose()}};export{WordPass};
338
+ */import{FullScreenQuad}from"../../five/renderer/tools/full-screen-quad.mjs";import{FivePass}from"../../five/renderer/postprocessing/passes/pass.mjs";import{uuid as createUuid}from"../../five/utils/uuid.mjs";import{__rest}from"tslib";import*as THREE from"three/webgpu";import{Fn,If,attribute,clamp,dot,exp,float,length,log2,max,mix,mod,positionGeometry,pow,select,sin,smoothstep,texture,uniform,uv,varyingProperty,vec2,vec4}from"three/tsl";var DEFAULT_COLOR=16767392,MAX_FRAME_DELTA_TIME=.1,GLOW_RADIUS_EXTRA=3,WordPass=class extends FivePass{constructor(camera,outputType=THREE.UnsignedByteType){super(),this.uTime=0,this.words=[],this.lineMesh=null,this.lineMaterial=null,this.points=null,this.particleMaterial=null,this.particleGeometry=null,this.arrPosition=null,this.arrVelocity=null,this.arrAccel=null,this.arrColor=null,this.arrParams=null,this._tmpTip=new THREE.Vector3,this.uTimeLine=uniform(0),this.uResolutionLine=uniform(new THREE.Vector2(1,1)),this.uProjLine=uniform(new THREE.Matrix4),this.uViewLine=uniform(new THREE.Matrix4),this.uPixelRatioLine=uniform(1),this.uMaxDisplayBoost=uniform(1),this.uTimeParticle=uniform(0),this.uResolutionParticle=uniform(new THREE.Vector2(1,1)),this.uProjParticle=uniform(new THREE.Matrix4),this.uViewParticle=uniform(new THREE.Matrix4),this.uBase=texture(new THREE.Texture),this.uEffect=texture(new THREE.Texture),this.camera=camera,this.effectScene=new THREE.Scene,this.orthoCamera=new THREE.OrthographicCamera(-1,1,1,-1,0,1),this.effectRenderTarget=new THREE.RenderTarget(Math.max(1,this.camera.resolution.x),Math.max(1,this.camera.resolution.y),{type:outputType,minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBAFormat}),this.blendMaterial=this.createBlendMaterial(),this.blendQuad=new FullScreenQuad(this.blendMaterial)}setWords(words){return this.words=words.map(w=>{var _a;return this._resolveWord(w,this.uTime+((_a=w.startTime)==null?0:_a)/1e3)}),this._rebuild(),this.words.map(w=>w.id)}addWord(...words){let added=words.map(w=>{var _a;return this._resolveWord(w,this.uTime+((_a=w.startTime)==null?0:_a)/1e3)});return this.words.push(...added),this._rebuild(),added.map(w=>w.id)}hasWord(id){return this.words.some(w=>w.id===id)}removeWord(...ids){let removed=0;for(let id of ids){let i=this.words.findIndex(w=>w.id===id);if(i===-1){console.warn(`WordPass: word "${id}" not found`);continue}this.words.splice(i,1),removed++}return removed>0&&this._rebuild(),removed}setWord(params){var _a;let{id}=params,updates=__rest(params,[`id`]),idx=this.words.findIndex(w=>w.id===id);if(idx===-1){console.warn(`WordPass: word "${id}" not found`);return}let prev=this.words[idx],merged=Object.assign(Object.assign(Object.assign({},prev.source),updates),{id}),wordStart=updates.startTime===void 0?prev.wordStart:this.uTime+((_a=updates.startTime)==null?0:_a)/1e3;this.words[idx]=this._resolveWord(merged,wordStart),this._rebuild()}clearWords(){this.words=[],this._rebuild()}setMaxDisplayBoost(value){this.uMaxDisplayBoost.value=Math.max(value,1)}_resolveWord(w,wordStart){let{color=new THREE.Color(DEFAULT_COLOR),opacity=1,lineWidth=3,hdrIntensity=1,writeSpeed=4,minStrokeDuration=200,strokeGap=120,holdDuration=1500,fadeDuration=1200,loop=!0,restartPause=800,persist=!1,fireworks=!0,fireworksColor,particleCount=400,emissionRate=500,sparkSpeed=.6,particleSize=.012,particleLife=.8,gravity}=w,valid=w.strokes.filter(s=>s.points.length>=2),blocks=[],cursorTime=0,gap=strokeGap/1e3;for(let s of valid){let dur=Math.max(s.totalLength/Math.max(writeSpeed,1e-4),minStrokeDuration/1e3);blocks.push({points:s.points,strokeLength:s.totalLength,writeStart:cursorTime,writeDuration:dur}),cursorTime+=dur+gap}let totalWriteTime=cursorTime>0?cursorTime-gap:0,fadeStart=persist?1e9:totalWriteTime+holdDuration/1e3,fadeDur=persist?1:fadeDuration/1e3,cycleLength=persist?0:loop?fadeStart+fadeDur+restartPause/1e3:0;return{id:w.id||createUuid(),source:Object.assign(Object.assign({},w),{id:w.id}),blocks,color:color.clone(),opacity,lineWidth,hdrIntensity:Math.max(hdrIntensity,1),wordStart,fadeStart,fadeDuration:fadeDur,cycleLength,fireworks,sparkColor:fireworksColor?fireworksColor.clone():color.clone().lerp(new THREE.Color(16777215),.4),emissionRate,sparkSpeed,particleSize,particleLife,gravity:gravity?gravity.clone():new THREE.Vector3(0,-.6,0),particleCount:fireworks?Math.max(1,Math.floor(particleCount)):0,particleOffset:0,particleCursor:0,emitAccum:blocks.map(()=>0)}}_rebuild(){this._buildLineMesh(),this._buildParticles()}createLineMaterial(){let vColor=varyingProperty(`vec4`,`wpColor`),vSegLen=varyingProperty(`float`,`wpSegLen`),vAccum=varyingProperty(`float`,`wpAccum`),vStrokeLen=varyingProperty(`float`,`wpStrokeLen`),vDrawnLen=varyingProperty(`float`,`wpDrawnLen`),vFade=varyingProperty(`float`,`wpFade`),vStart=varyingProperty(`vec2`,`wpStart`),vEnd=varyingProperty(`vec2`,`wpEnd`),vLineWidth=varyingProperty(`float`,`wpLineWidth`),vHdrBoost=varyingProperty(`float`,`wpHdrBoost`),vNdc=varyingProperty(`vec2`,`wpNdc`),nearEps=.001,attr=(name,type)=>attribute(name,type),vertex=Fn(()=>{let instanceStart=attr(`instanceStart`,`vec3`),instanceEnd=attr(`instanceEnd`,`vec3`),instanceColor=attr(`instanceColor`,`vec4`),instanceData=attr(`instanceData`,`vec4`),instanceReveal=attr(`instanceReveal`,`vec2`),instanceTime=attr(`instanceTime`,`vec4`),pos=positionGeometry,accum=instanceData.x,lineWidth=instanceData.y.mul(this.uPixelRatioLine),strokeLen=instanceData.z,writeStart=instanceReveal.x,writeDur=instanceReveal.y,wordStart=instanceTime.x,fadeStart=instanceTime.y,fadeDur=instanceTime.z,cycle=instanceTime.w;vColor.assign(instanceColor);let segLen=length(instanceEnd.sub(instanceStart));vSegLen.assign(segLen),vAccum.assign(accum),vStrokeLen.assign(strokeLen),vLineWidth.assign(lineWidth);let elapsed=this.uTimeLine.sub(wordStart),local=select(cycle.greaterThan(0),mod(max(elapsed,0),cycle),elapsed),drawnLen=clamp(local.sub(writeStart).div(max(writeDur,1e-4)),0,1).mul(strokeLen).toVar(),fade=float(1).toVar();If(local.greaterThanEqual(fadeStart),()=>{fade.assign(float(1).sub(clamp(local.sub(fadeStart).div(max(fadeDur,1e-4)),0,1)))}),If(elapsed.lessThan(0),()=>{fade.assign(0),drawnLen.assign(0)}),vFade.assign(fade),vDrawnLen.assign(drawnLen);let hdrIntensity=instanceData.w,logContentMax=max(log2(max(hdrIntensity,1.0001)),1e-4),hdrWeight=clamp(log2(max(this.uMaxDisplayBoost,1)).div(logContentMax),0,1);vHdrBoost.assign(mix(1,hdrIntensity,hdrWeight));let clipStart=this.uProjLine.mul(this.uViewLine).mul(vec4(instanceStart,1)).toVar(),clipEnd=this.uProjLine.mul(this.uViewLine).mul(vec4(instanceEnd,1)).toVar(),invisible=float(0).toVar(),startBehind=clipStart.w.lessThan(nearEps).toVar(),endBehind=clipEnd.w.lessThan(nearEps).toVar();If(startBehind.and(endBehind),()=>{invisible.assign(1)}),If(startBehind,()=>{let tc=float(nearEps).sub(clipStart.w).div(clipEnd.w.sub(clipStart.w));clipStart.assign(mix(clipStart,clipEnd,tc))}),If(endBehind,()=>{let tc=float(nearEps).sub(clipEnd.w).div(clipStart.w.sub(clipEnd.w));clipEnd.assign(mix(clipEnd,clipStart,tc))});let ndcStart=clipStart.xy.div(clipStart.w),ndcEnd=clipEnd.xy.div(clipEnd.w);vStart.assign(ndcStart),vEnd.assign(ndcEnd);let screenStart=ndcStart.add(1).mul(.5).mul(this.uResolutionLine),screenEnd=ndcEnd.add(1).mul(.5).mul(this.uResolutionLine),seg=screenEnd.sub(screenStart),segLenPix=length(seg),dir=select(segLenPix.greaterThan(1e-5),seg.div(max(segLenPix,1e-5)),vec2(1,0)),normal=vec2(dir.y.negate(),dir.x),tt=pos.y.add(.5),coverRadius=max(lineWidth.mul(.5),.5).add(GLOW_RADIUS_EXTRA),extStart=screenStart.sub(dir.mul(coverRadius)),extEnd=screenEnd.add(dir.mul(coverRadius)),offset=normal.mul(pos.x).mul(2).mul(coverRadius),ndc=mix(extStart,extEnd,tt).add(offset).div(this.uResolutionLine).mul(2).sub(1);vNdc.assign(ndc);let clipPos=mix(clipStart,clipEnd,tt),safeW=max(clipPos.w,nearEps);return mix(vec4(ndc.mul(safeW),clipPos.z,safeW),vec4(0,0,-2,1),invisible)}),sdCapsule=Fn(([p,a,b])=>{let pa=p.sub(a),ba=b.sub(a),h=clamp(dot(pa,ba).div(dot(ba,ba)),0,1);return length(pa.sub(ba.mul(h)))}),fragment=Fn(()=>{let uvNdc=vNdc,screenDiff=vEnd.sub(vStart),screenDist=max(length(screenDiff),1e-6),screenDir=screenDiff.div(screenDist),projRatio=clamp(dot(uvNdc.sub(vStart),screenDir),0,screenDist).div(screenDist),posAlong=vAccum.add(projRatio.mul(vSegLen)),notDrawn=vDrawnLen.lessThanEqual(1e-4).or(posAlong.greaterThan(vDrawnLen)),aspect=vec2(this.uResolutionLine.x.div(this.uResolutionLine.y),1),dPix=sdCapsule(uvNdc.mul(aspect),vStart.mul(aspect),vEnd.mul(aspect)).mul(this.uResolutionLine.y).mul(.5),halfW=max(vLineWidth.mul(.5),.5),core=float(1).sub(smoothstep(halfW.sub(1),halfW.add(1),dPix)),coverRadius=halfW.add(GLOW_RADIUS_EXTRA),x=clamp(max(dPix.sub(halfW),0).div(max(coverRadius.sub(halfW),1e-4)),0,1),glow=pow(float(1).sub(x),4).mul(.9),intensity=clamp(core.add(glow.mul(float(1).sub(core))),0,1),tip=exp(max(vDrawnLen.sub(posAlong),0).mul(-5).div(max(vStrokeLen,1e-4))),writing=float(1).sub(smoothstep(vStrokeLen.mul(.98),vStrokeLen,vDrawnLen)),bright=float(1).add(tip.mul(.6).mul(writing)),alpha=intensity.mul(vColor.a).mul(vFade),outAlpha=select(notDrawn.not().and(alpha.greaterThanEqual(.004)),alpha,0);return vec4(vColor.rgb.mul(bright).mul(vHdrBoost).mul(outAlpha),outAlpha)}),material=new THREE.NodeMaterial;return material.vertexNode=vertex(),material.fragmentNode=fragment(),material.transparent=!0,material.depthTest=!1,material.depthWrite=!1,material.side=THREE.DoubleSide,material.blending=THREE.CustomBlending,material.blendEquation=THREE.MaxEquation,material.blendSrc=THREE.OneFactor,material.blendDst=THREE.OneFactor,material}_buildLineMesh(){this._disposeLineMesh();let totalSegments=0;for(let w of this.words)for(let b of w.blocks)totalSegments+=b.points.length-1;if(totalSegments===0)return;let plane=new THREE.PlaneGeometry(1,1,1,1),geometry=new THREE.InstancedBufferGeometry;geometry.index=plane.index,geometry.attributes=plane.attributes,geometry.instanceCount=totalSegments;let instanceStart=new Float32Array(totalSegments*3),instanceEnd=new Float32Array(totalSegments*3),instanceColor=new Float32Array(totalSegments*4),instanceData=new Float32Array(totalSegments*4),instanceReveal=new Float32Array(totalSegments*2),instanceTime=new Float32Array(totalSegments*4),idx=0;for(let w of this.words)for(let b of w.blocks){let accum=0;for(let i=0;i<b.points.length-1;i++){let start=b.points[i],end=b.points[i+1],segLen=start.distanceTo(end),i2=idx*2,i3=idx*3,i4=idx*4;instanceStart[i3+0]=start.x,instanceStart[i3+1]=start.y,instanceStart[i3+2]=start.z,instanceEnd[i3+0]=end.x,instanceEnd[i3+1]=end.y,instanceEnd[i3+2]=end.z,instanceColor[i4+0]=w.color.r,instanceColor[i4+1]=w.color.g,instanceColor[i4+2]=w.color.b,instanceColor[i4+3]=w.opacity,instanceData[i4+0]=accum,instanceData[i4+1]=w.lineWidth,instanceData[i4+2]=b.strokeLength,instanceData[i4+3]=w.hdrIntensity,instanceReveal[i2+0]=b.writeStart,instanceReveal[i2+1]=b.writeDuration,instanceTime[i4+0]=w.wordStart,instanceTime[i4+1]=w.fadeStart,instanceTime[i4+2]=w.fadeDuration,instanceTime[i4+3]=w.cycleLength,accum+=segLen,idx++}}geometry.setAttribute(`instanceStart`,new THREE.InstancedBufferAttribute(instanceStart,3)),geometry.setAttribute(`instanceEnd`,new THREE.InstancedBufferAttribute(instanceEnd,3)),geometry.setAttribute(`instanceColor`,new THREE.InstancedBufferAttribute(instanceColor,4)),geometry.setAttribute(`instanceData`,new THREE.InstancedBufferAttribute(instanceData,4)),geometry.setAttribute(`instanceReveal`,new THREE.InstancedBufferAttribute(instanceReveal,2)),geometry.setAttribute(`instanceTime`,new THREE.InstancedBufferAttribute(instanceTime,4)),this.lineMaterial=this.createLineMaterial(),this.lineMesh=new THREE.Mesh(geometry,this.lineMaterial),this.lineMesh.frustumCulled=!1,this.effectScene.add(this.lineMesh)}createParticleMaterial(){let vColor=varyingProperty(`vec4`,`wpSparkColor`),vAlpha=varyingProperty(`float`,`wpSparkAlpha`),vLocal=varyingProperty(`vec2`,`wpSparkLocal`),eps=.001,attr=(name,type)=>attribute(name,type),vertex=Fn(()=>{let birth=attr(`aPosition`,`vec3`),aVelocity=attr(`aVelocity`,`vec3`),aAccel=attr(`aAccel`,`vec3`),aColor=attr(`aColor`,`vec4`),aParams=attr(`aParams`,`vec4`),aBirthTime=aParams.x,aMaxLife=aParams.y,aSeed=aParams.z,aSize=aParams.w,corner=positionGeometry.xy;vColor.assign(aColor),vLocal.assign(corner);let age=this.uTimeParticle.sub(aBirthTime),invisible=float(0).toVar();If(aMaxLife.lessThanEqual(0).or(age.lessThan(0)).or(age.greaterThan(aMaxLife)),()=>{invisible.assign(1)});let lifeT=age.div(max(aMaxLife,eps)),worldPos=birth.add(aVelocity.mul(age)).add(aAccel.mul(.5).mul(age).mul(age)),clip=this.uProjParticle.mul(this.uViewParticle).mul(vec4(worldPos,1)).toVar();If(clip.w.lessThanEqual(eps),()=>{invisible.assign(1)});let safeW=max(clip.w,eps),ndc=clip.xy.div(safeW),p11=this.uProjParticle.element(1).y,sizeFade=float(1).sub(lifeT.mul(.7)),pixelSize=max(aSize.mul(p11).mul(.5).mul(this.uResolutionParticle.y).div(safeW).mul(sizeFade),0),ndc2=ndc.add(1).mul(.5).mul(this.uResolutionParticle).add(corner.mul(pixelSize)).div(this.uResolutionParticle).mul(2).sub(1),twinkle=float(.7).add(float(.3).mul(sin(this.uTimeParticle.mul(30).add(aSeed.mul(6.2831)))));return vAlpha.assign(pow(float(1).sub(lifeT),.8).mul(twinkle)),mix(vec4(ndc2.mul(safeW),clip.z,safeW),vec4(0,0,-2,1),invisible)}),fragment=Fn(()=>{let core=smoothstep(.5,0,length(vLocal)),intensity=core.mul(core).mul(vAlpha).mul(vColor.a);return vec4(vColor.rgb,intensity)}),material=new THREE.NodeMaterial;return material.vertexNode=vertex(),material.fragmentNode=fragment(),material.transparent=!0,material.depthTest=!1,material.depthWrite=!1,material.blending=THREE.AdditiveBlending,material}createBlendMaterial(){let material=new THREE.NodeMaterial,base=this.uBase.sample(uv()),effect=this.uEffect.sample(uv());return material.fragmentNode=vec4(base.rgb.add(effect.rgb),base.a),material.transparent=!1,material.depthTest=!1,material.depthWrite=!1,material}_buildParticles(){this._disposeParticles();let total=0;for(let w of this.words)w.particleOffset=total,w.particleCursor=0,total+=w.particleCount;if(total===0)return;this.arrPosition=new Float32Array(total*3),this.arrVelocity=new Float32Array(total*3),this.arrAccel=new Float32Array(total*3),this.arrColor=new Float32Array(total*4),this.arrParams=new Float32Array(total*4);let quad=new THREE.PlaneGeometry(1,1,1,1),geometry=new THREE.InstancedBufferGeometry;geometry.index=quad.index,geometry.attributes=quad.attributes,geometry.instanceCount=total,geometry.setAttribute(`aPosition`,new THREE.InstancedBufferAttribute(this.arrPosition,3)),geometry.setAttribute(`aVelocity`,new THREE.InstancedBufferAttribute(this.arrVelocity,3)),geometry.setAttribute(`aAccel`,new THREE.InstancedBufferAttribute(this.arrAccel,3)),geometry.setAttribute(`aColor`,new THREE.InstancedBufferAttribute(this.arrColor,4)),geometry.setAttribute(`aParams`,new THREE.InstancedBufferAttribute(this.arrParams,4)),this.particleGeometry=geometry,this.particleMaterial=this.createParticleMaterial(),this.points=new THREE.Mesh(geometry,this.particleMaterial),this.points.frustumCulled=!1,this.effectScene.add(this.points)}_samplePointAtLength(points,s,out){if(points.length===1||s<=0){out.copy(points[0]);return}let acc=0;for(let i=0;i<points.length-1;i++){let a=points[i],b=points[i+1],segLen=a.distanceTo(b);if(!(segLen<=1e-9)){if(acc+segLen>=s){out.lerpVectors(a,b,(s-acc)/segLen);return}acc+=segLen}}out.copy(points[points.length-1])}_emitParticle(w,origin){if(!this.arrPosition)return;let idx=w.particleOffset+w.particleCursor;w.particleCursor=(w.particleCursor+1)%w.particleCount;let i3=idx*3,i4=idx*4,theta=Math.random()*Math.PI*2,r=Math.random(),dx=Math.cos(theta)*r,dz=Math.sin(theta)*r,dy=.3+Math.random()*.7,speed=w.sparkSpeed*(.4+Math.random()*.8);this.arrPosition[i3+0]=origin.x,this.arrPosition[i3+1]=origin.y,this.arrPosition[i3+2]=origin.z,this.arrVelocity[i3+0]=dx*speed,this.arrVelocity[i3+1]=dy*speed,this.arrVelocity[i3+2]=dz*speed,this.arrAccel[i3+0]=w.gravity.x,this.arrAccel[i3+1]=w.gravity.y,this.arrAccel[i3+2]=w.gravity.z;let bright=.8+Math.random()*.5;this.arrColor[i4+0]=w.sparkColor.r*bright,this.arrColor[i4+1]=w.sparkColor.g*bright,this.arrColor[i4+2]=w.sparkColor.b*bright,this.arrColor[i4+3]=1,this.arrParams[i4+0]=this.uTime,this.arrParams[i4+1]=w.particleLife*(.6+Math.random()*.8),this.arrParams[i4+2]=Math.random(),this.arrParams[i4+3]=w.particleSize*(.6+Math.random()*.9)}_emit(deltaTime){if(!this.particleGeometry)return;let dirty=!1;for(let w of this.words){if(!w.fireworks||w.particleCount===0)continue;let elapsed=this.uTime-w.wordStart;if(elapsed<0)continue;let local=w.cycleLength>0?elapsed%w.cycleLength:elapsed;for(let s=0;s<w.blocks.length;s++){let b=w.blocks[s],rel=local-b.writeStart;if(rel<0||rel>b.writeDuration)continue;let t=rel/b.writeDuration;this._samplePointAtLength(b.points,t*b.strokeLength,this._tmpTip),w.emitAccum[s]+=w.emissionRate*deltaTime;let n=Math.floor(w.emitAccum[s]);w.emitAccum[s]-=n,n=Math.min(n,w.particleCount);for(let i=0;i<n;i++)this._emitParticle(w,this._tmpTip),dirty=!0}}if(dirty){let g=this.particleGeometry;g.getAttribute(`aPosition`).needsUpdate=!0,g.getAttribute(`aVelocity`).needsUpdate=!0,g.getAttribute(`aAccel`).needsUpdate=!0,g.getAttribute(`aColor`).needsUpdate=!0,g.getAttribute(`aParams`).needsUpdate=!0}}render(renderer,writeBuffer,readBuffer,deltaTime,_maskActive){let active=!!(this.lineMesh||this.points);if(active){let dt=Math.min(Math.max(deltaTime==null?0:deltaTime,0),MAX_FRAME_DELTA_TIME);this.uTime+=dt,this._emit(dt)}let targetWidth=readBuffer.width,targetHeight=readBuffer.height;(this.effectRenderTarget.width!==targetWidth||this.effectRenderTarget.height!==targetHeight)&&this.effectRenderTarget.setSize(targetWidth,targetHeight);let oldRenderTarget=renderer.getRenderTarget();if(renderer.setRenderTarget(this.effectRenderTarget),renderer.setClearColor(0,0),renderer.clear(),active){let proj=this.camera.projectionMatrix,view=this.camera.matrixWorldInverse;this.lineMaterial&&(this.uTimeLine.value=this.uTime,this.uResolutionLine.value.set(targetWidth,targetHeight),this.uProjLine.value=proj,this.uViewLine.value=view,this.uPixelRatioLine.value=this.camera.pixelRatio),this.particleMaterial&&(this.uTimeParticle.value=this.uTime,this.uResolutionParticle.value.set(targetWidth,targetHeight),this.uProjParticle.value=proj,this.uViewParticle.value=view),renderer.render(this.effectScene,this.orthoCamera)}renderer.setRenderTarget(oldRenderTarget),this.uBase.value=readBuffer.texture,this.uEffect.value=this.effectRenderTarget.texture,renderer.setRenderTarget(this.renderToScreen?null:writeBuffer),this.blendQuad.render(renderer)}_disposeLineMesh(){this.lineMesh&&(this.effectScene.remove(this.lineMesh),this.lineMesh.geometry.dispose(),this.lineMesh=null),this.lineMaterial&&(this.lineMaterial.dispose(),this.lineMaterial=null)}_disposeParticles(){this.points&&(this.effectScene.remove(this.points),this.points=null),this.particleGeometry&&(this.particleGeometry.dispose(),this.particleGeometry=null),this.particleMaterial&&(this.particleMaterial.dispose(),this.particleMaterial=null),this.arrPosition=null,this.arrVelocity=null,this.arrAccel=null,this.arrColor=null,this.arrParams=null}dispose(){this._disposeLineMesh(),this._disposeParticles(),this.effectRenderTarget.dispose(),this.blendMaterial.dispose(),this.blendQuad.dispose()}};export{WordPass};
package/plugins/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
package/plugins/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
package/react/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
package/react/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
package/sticker/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @license
3
3
  * @realsee/five-webgpu
4
- * Generated: 2026/11/3
5
- * Version: 1.0.0-alpha.14
4
+ * Generated: 2026/11/4
5
+ * Version: 1.0.0-alpha.15
6
6
  * License:
7
7
  * Realsee SDK License Agreement
8
8
 
@@ -378,4 +378,4 @@ fn fs(in: VSOut) -> @location(0) vec4f {
378
378
  }`)),gl.attachShader(program,compile(gl.FRAGMENT_SHADER,`#version 300 es
379
379
  precision mediump float;
380
380
  in vec2 uv; uniform sampler2D tex; out vec4 color;
381
- void main() { color = vec4(texture(tex, uv).rgb, 1.0); }`)),gl.linkProgram(program),!gl.getProgramParameter(program,gl.LINK_STATUS))return null;let texture=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,texture),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),{canvas,gl,texture,program,pixels:new Uint8Array(GL_PROBE_SIZE*GL_PROBE_SIZE*4)}}catch(_a){return null}}function disposeGLProbe(probe){var _a;let{gl}=probe;gl.deleteTexture(probe.texture),gl.deleteProgram(probe.program),(_a=gl.getExtension(`WEBGL_lose_context`))==null||_a.loseContext()}var GPU_PROBE_WIDTH=64,GPU_PROBE_HEIGHT=16,VideoTextureBridge=class{constructor(videoTexture){var _a;this.debug={path:`pending`,candidate:``,locked:!1,probe:``,updateCalls:0,skipNotReady:0,blitCount:0,rvfcCount:0,fails:0,targetSize:``,lastError:``},this.mode=`unknown`,this.device=null,this.broken=!1,this.disposed=!1,this.locked=!1,this.blacklist=new Map,this.probing=!1,this.nextProbeAt=0,this.probeInterval=300,this.consecutiveFails=0,this.failingSince=0,this.frameTexture=null,this.frameReady=!1,this.heldFrame=null,this.canvas=null,this.canvasContext=null,this.gpuTexture=null,this.externalTexture=null,this.externalReady=!1,this.width=0,this.height=0,this.frameDirty=!0,this.lastVideoTime=-1,this.videoFrameCallbackId=null,this.glProbe=null,this.glProbeFailed=!1,this.gpuProbe=null,this.probeCanvas=null,this.forced=!1,this.onSourceChange=()=>{this.forced||(this.blacklist.clear(),this.locked=!1,this.debug.locked=!1,this.probeInterval=300,this.nextProbeAt=0,this.consecutiveFails=0,this.frameDirty=!0)},this.videoTexture=videoTexture,this.current=(_a=CANDIDATE_ORDER.find(isAvailable))==null?`video`:_a,this.debug.candidate=this.current,this.scheduleVideoFrameCallback();let video=this.video;typeof(video==null?void 0:video.addEventListener)==`function`&&video.addEventListener(`loadstart`,this.onSourceChange)}get video(){return this.videoTexture.image}scheduleVideoFrameCallback(){let video=this.video;this.disposed||typeof(video==null?void 0:video.requestVideoFrameCallback)!=`function`||(this.videoFrameCallbackId=video.requestVideoFrameCallback(()=>{this.videoFrameCallbackId=null,this.frameDirty=!0,this.debug.rvfcCount++,this.scheduleVideoFrameCallback()}))}get texture(){var _a;if(this.broken||this.mode===`unknown`)return this.videoTexture;let wantsExternal=this.mode===`webgpu`&&(this.current===`videoFrame`||this.current===`video`),external=this.externalReady?this.externalTexture:null,frame=this.frameReady?this.frameTexture:null;return(_a=wantsExternal?external==null?frame:external:frame==null?external:frame)==null?getPlaceholder():_a}update(renderer){if(this.debug.updateCalls++,this.disposed||this.broken||!this.resolveMode(renderer))return;let video=this.video;if(!(video instanceof HTMLVideoElement))return;if(video.readyState<2||video.videoWidth===0||video.videoHeight===0){this.debug.skipNotReady++;return}let now=performance.now();if(!this.locked&&!this.probing&&now>=this.nextProbeAt&&this.startProbe(),!(!this.frameDirty&&(this.debug.rvfcCount>0||video.currentTime===this.lastVideoTime)))try{this.produce(this.current,video),this.frameDirty=!1,this.lastVideoTime=video.currentTime,this.consecutiveFails=0,this.debug.blitCount++}catch(error){this.onProduceFailed(error)}}forceCandidate(candidate){if(candidate===null){this.forced=!1,this.onSourceChange();return}this.forced=!0,this.current=candidate,this.locked=!0,this.debug.candidate=candidate,this.debug.locked=!0,this.frameDirty=!0,this.releaseProbeResources()}resolveMode(renderer){if(this.mode!==`unknown`)return!0;let backend=renderer==null?void 0:renderer.backend;if(!backend)return!1;if(backend.isWebGPUBackend===!0){if(!backend.device)return!1;this.device=backend.device,this.mode=`webgpu`}else this.mode=`webgl`;return this.debug.path=this.mode,this.ensureFrameTexture(),!0}ensureFrameTexture(){if(this.frameTexture)return;let source=this.videoTexture,texture=new three_webgpu.VideoFrameTexture;texture.colorSpace=three_webgpu.SRGBColorSpace,texture.generateMipmaps=!1,texture.minFilter=source.minFilter,texture.magFilter=source.magFilter,texture.wrapS=source.wrapS,texture.wrapT=source.wrapT,this.frameTexture=texture}produce(candidate,video){let webgpu=this.mode===`webgpu`;switch(candidate){case`videoFrame`:{let frame=createVideoFrame(video);if(webgpu)try{this.blit(frame,video)}finally{frame.close()}else this.setFrame(frame,frame);break}case`video`:webgpu?this.blit(video,video):this.setFrame(video,null);break;case`canvasFromVideoFrame`:{let frame=createVideoFrame(video);try{this.drawCanvas(frame,video)}finally{frame.close()}this.setFrame(this.canvas,null);break}case`canvasFromVideo`:this.drawCanvas(video,video),this.setFrame(this.canvas,null);break}}setFrame(image,owned){this.frameTexture.setFrame(image);let previous=this.heldFrame;this.heldFrame=owned,previous&&previous!==owned&&previous.close(),this.frameReady=!0}drawCanvas(source,video){let scale=Math.min(1,MAX_CANVAS_SIZE/Math.max(video.videoWidth,video.videoHeight)),width=Math.max(1,Math.floor(video.videoWidth*scale)),height=Math.max(1,Math.floor(video.videoHeight*scale));if(!this.canvas&&(this.canvas=document.createElement(`canvas`),this.canvasContext=this.canvas.getContext(`2d`,{alpha:!1}),!this.canvasContext))throw Error(`canvas 2d 上下文不可用`);this.canvas.width!==width&&(this.canvas.width=width),this.canvas.height!==height&&(this.canvas.height=height),this.canvasContext.drawImage(source,0,0,width,height)}isBlacklisted(candidate){let expiresAt=this.blacklist.get(candidate);return expiresAt===void 0?!1:performance.now()>=expiresAt?(this.blacklist.delete(candidate),!1):!0}onProduceFailed(error){var _a;let now=performance.now();if(this.consecutiveFails===0&&(this.failingSince=now),this.consecutiveFails++,this.debug.fails++,this.debug.lastError=String((_a=error==null?void 0:error.message)==null?error:_a),this.consecutiveFails<MAX_CONSECUTIVE_FAILS||now-this.failingSince<MIN_FAIL_DURATION_MS)return;console.warn(`[Five] 视频候选路径 ${this.current} 持续失败,暂时弃用`,error),this.blacklist.set(this.current,now+BLACKLIST_TTL_MS);let next=CANDIDATE_ORDER.find(c=>isAvailable(c)&&!this.isBlacklisted(c));this.consecutiveFails=0,next?(this.current=next,this.debug.candidate=next,this.locked=!1,this.debug.locked=!1,this.nextProbeAt=0,this.frameDirty=!0):(console.warn(`[Five] 视频所有候选路径均失败,回退为 VideoTexture 上传`),this.broken=!0,this.debug.path=`fallback`,this.releaseOutputs())}blit(source,video){this.ensureTarget(video.videoWidth,video.videoHeight);let device=this.device,{pipeline,bindGroupLayout,sampler}=getBlitPipeline(device),external=device.importExternalTexture({source}),bindGroup=device.createBindGroup({layout:bindGroupLayout,entries:[{binding:0,resource:external},{binding:1,resource:sampler}]}),encoder=device.createCommandEncoder({label:`five.videoBlit`}),pass=encoder.beginRenderPass({colorAttachments:[{view:this.gpuTexture.createView(),loadOp:`clear`,storeOp:`store`,clearValue:{r:0,g:0,b:0,a:1}}]});pass.setPipeline(pipeline),pass.setBindGroup(0,bindGroup),pass.draw(3),pass.end(),device.queue.submit([encoder.finish()]),this.externalReady=!0,this.debug.targetSize=`${this.width}x${this.height}`}ensureTarget(videoWidth,videoHeight){let device=this.device,maxSize=device.limits.maxTextureDimension2D,scale=Math.min(1,maxSize/Math.max(videoWidth,videoHeight)),width=Math.max(1,Math.floor(videoWidth*scale)),height=Math.max(1,Math.floor(videoHeight*scale));if(this.gpuTexture&&this.width===width&&this.height===height)return;let prevGPUTexture=this.gpuTexture,gpuTexture=device.createTexture({label:`five.videoBlit.target`,size:{width,height},format:INTERMEDIATE_FORMAT,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT});if(this.gpuTexture=gpuTexture,this.width=width,this.height=height,this.externalTexture)this.externalTexture.sourceTexture=gpuTexture,this.externalTexture.image={width,height},this.externalTexture.dispose();else{let texture=new three_webgpu.ExternalTexture(gpuTexture);texture.colorSpace=three_webgpu.SRGBColorSpace,texture.flipY=!1,texture.generateMipmaps=!1,texture.minFilter=three_webgpu.LinearFilter,texture.magFilter=three_webgpu.LinearFilter,texture.wrapS=three_webgpu.ClampToEdgeWrapping,texture.wrapT=three_webgpu.ClampToEdgeWrapping,texture.image={width,height},this.externalTexture=texture}prevGPUTexture==null||prevGPUTexture.destroy()}startProbe(){this.probing=!0,this.runProbe().catch(error=>{var _a;this.debug.lastError=String((_a=error==null?void 0:error.message)==null?error:_a)}).finally(()=>{this.probing=!1,this.nextProbeAt=performance.now()+this.probeInterval,this.probeInterval=Math.min(this.probeInterval*1.5,5e3)})}runProbe(){return(0,tslib.__awaiter)(this,void 0,void 0,function*(){let results=[],chosen=null;for(let candidate of CANDIDATE_ORDER){let label=CANDIDATE_SHORT[candidate];if(this.disposed)return;if(this.isBlacklisted(candidate)||!isAvailable(candidate)){results.push(`${label}:n/a`);continue}let brightness;try{brightness=yield this.probeCandidate(candidate)}catch(_a){brightness=-1}if(results.push(`${label}:${brightness===null?`?`:brightness}`),brightness===null||brightness>=BRIGHT_THRESHOLD){chosen=candidate;break}}this.debug.probe=results.join(` `),chosen&&this.select(chosen)})}select(candidate){this.current=candidate,this.locked=!0,this.debug.candidate=candidate,this.debug.locked=!0,this.frameDirty=!0,this.releaseProbeResources()}probeCandidate(candidate){return(0,tslib.__awaiter)(this,void 0,void 0,function*(){let video=this.video;if(!(video instanceof HTMLVideoElement)||video.readyState<2)return-1;switch(candidate){case`canvasFromVideoFrame`:return this.probe2d(video,!0);case`canvasFromVideo`:return this.probe2d(video,!1);default:return this.mode===`webgpu`?this.probeGPU(video,candidate===`videoFrame`):this.probeGL(video,candidate===`videoFrame`)}})}probe2d(video,useFrame){if(!this.probeCanvas){let canvas=document.createElement(`canvas`);canvas.width=canvas.height=GL_PROBE_SIZE;let context=canvas.getContext(`2d`,{willReadFrequently:!0});if(!context)return-1;this.probeCanvas=context}let frame=useFrame?createVideoFrame(video):null;try{return this.probeCanvas.drawImage(frame==null?video:frame,0,0,GL_PROBE_SIZE,GL_PROBE_SIZE),maxChannel(this.probeCanvas.getImageData(0,0,GL_PROBE_SIZE,GL_PROBE_SIZE).data)}finally{frame==null||frame.close()}}probeGL(video,useFrame){!this.glProbe&&!this.glProbeFailed&&(this.glProbe=createGLProbe(),this.glProbeFailed=this.glProbe===null);let probe=this.glProbe;if(!probe)return null;let{gl}=probe,frame=useFrame?createVideoFrame(video):null;try{return gl.getError(),gl.viewport(0,0,GL_PROBE_SIZE,GL_PROBE_SIZE),gl.bindTexture(gl.TEXTURE_2D,probe.texture),gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,frame==null?video:frame),gl.getError()===gl.NO_ERROR?(gl.useProgram(probe.program),gl.drawArrays(gl.TRIANGLES,0,3),gl.readPixels(0,0,GL_PROBE_SIZE,GL_PROBE_SIZE,gl.RGBA,gl.UNSIGNED_BYTE,probe.pixels),maxChannel(probe.pixels)):-1}finally{frame==null||frame.close()}}probeGPU(video,useFrame){return(0,tslib.__awaiter)(this,void 0,void 0,function*(){let device=this.device,{pipeline,bindGroupLayout,sampler}=getBlitPipeline(device);this.gpuProbe||(this.gpuProbe={texture:device.createTexture({label:`five.videoProbe.target`,size:{width:GPU_PROBE_WIDTH,height:GPU_PROBE_HEIGHT},format:INTERMEDIATE_FORMAT,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),buffer:device.createBuffer({label:`five.videoProbe.readback`,size:GPU_PROBE_WIDTH*4*GPU_PROBE_HEIGHT,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})});let probe=this.gpuProbe;device.pushErrorScope(`validation`);let encodeError=null,frame=useFrame?createVideoFrame(video):null;try{let external=device.importExternalTexture({source:frame==null?video:frame}),bindGroup=device.createBindGroup({layout:bindGroupLayout,entries:[{binding:0,resource:external},{binding:1,resource:sampler}]}),encoder=device.createCommandEncoder({label:`five.videoProbe`}),pass=encoder.beginRenderPass({colorAttachments:[{view:probe.texture.createView(),loadOp:`clear`,storeOp:`store`,clearValue:{r:0,g:0,b:0,a:1}}]});pass.setPipeline(pipeline),pass.setBindGroup(0,bindGroup),pass.draw(3),pass.end(),encoder.copyTextureToBuffer({texture:probe.texture},{buffer:probe.buffer,bytesPerRow:GPU_PROBE_WIDTH*4},{width:GPU_PROBE_WIDTH,height:GPU_PROBE_HEIGHT}),device.queue.submit([encoder.finish()])}catch(error){encodeError=error}finally{frame==null||frame.close()}let scopeError=yield device.popErrorScope();if(encodeError||scopeError)return-1;yield probe.buffer.mapAsync(GPUMapMode.READ);let brightness=maxChannel(new Uint8Array(probe.buffer.getMappedRange()));return probe.buffer.unmap(),brightness})}releaseProbeResources(){this.glProbe&&(disposeGLProbe(this.glProbe),this.glProbe=null),this.glProbeFailed=!1,this.probeCanvas=null,this.gpuProbe&&(this.gpuProbe.texture.destroy(),this.gpuProbe.buffer.destroy(),this.gpuProbe=null)}releaseOutputs(){var _a,_b,_c,_d;(_a=this.heldFrame)==null||_a.close(),this.heldFrame=null,(_b=this.frameTexture)==null||_b.dispose(),this.frameTexture=null,this.frameReady=!1,(_c=this.externalTexture)==null||_c.dispose(),this.externalTexture=null,this.externalReady=!1,(_d=this.gpuTexture)==null||_d.destroy(),this.gpuTexture=null,this.width=this.height=0,this.canvas=null,this.canvasContext=null}dispose(){if(this.disposed)return;this.disposed=!0;let video=this.video;this.videoFrameCallbackId!==null&&typeof(video==null?void 0:video.cancelVideoFrameCallback)==`function`&&video.cancelVideoFrameCallback(this.videoFrameCallbackId),this.videoFrameCallbackId=null,typeof(video==null?void 0:video.removeEventListener)==`function`&&video.removeEventListener(`loadstart`,this.onSourceChange),this.releaseOutputs(),this.releaseProbeResources()}},bridges=new WeakMap;function getVideoTextureBridge(videoTexture){let bridge=bridges.get(videoTexture);if(!bridge){let created=new VideoTextureBridge(videoTexture);bridge=created,bridges.set(videoTexture,created);let onDispose=()=>{videoTexture.removeEventListener(`dispose`,onDispose),bridges.get(videoTexture)===created&&bridges.delete(videoTexture),created.dispose()};videoTexture.addEventListener(`dispose`,onDispose)}return bridge}var window_=window,_requestAnimationFrame=window_.requestAnimationFrame||window_.mozRequestAnimationFrame||window_.webkitRequestAnimationFrame||window_.msRequestAnimationFrame||(fn=>setTimeout(fn,16)),start=typeof performance<`u`&&performance.timing!==void 0?performance.timing.navigationStart:Date.now(),now=typeof performance<`u`?(()=>start+performance.now()):(()=>Date.now());function imageReady(image,callback){image.naturalWidth>0&&_requestAnimationFrame(()=>callback());let onLoad=()=>callback();return image.addEventListener(`load`,onLoad,!1),()=>image.removeEventListener(`load`,onLoad,!1)}function videoReady(video,callback){let lastUpdateTime=now(),looping=!1,loop=()=>{looping=!0,callback(),now()-lastUpdateTime<3e3?_requestAnimationFrame(loop):looping=!1},onUpdate=()=>{lastUpdateTime=now(),looping===!1&&loop()};return video.addEventListener(`timeupdate`,onUpdate,!1),()=>{video.removeEventListener(`timeupdate`,onUpdate,!1),looping=!1}}function injectDispose(texture,dispose){let _dispose=texture.dispose;texture.dispose=()=>{dispose(),_dispose.call(texture)}}var Sticker=class extends three_webgpu.Mesh{static get version(){return`1.0.0-alpha.14`}constructor(width,height,resource){let material=new three_webgpu.MeshBasicMaterial;if(super(geometry,material),this._sourceTexture=null,this._needsRender=!1,this.scale.set(width,height,1),typeof resource==`string`){material.transparent=/\.png$/.test(resource);let image=new Image;image.src=resource,image.crossOrigin=``,resource=image}if(resource instanceof HTMLImageElement){let texture=material.map=new three_webgpu.Texture;texture.wrapS=three_webgpu.ClampToEdgeWrapping,texture.wrapT=three_webgpu.ClampToEdgeWrapping,texture.minFilter=three_webgpu.LinearFilter,texture.colorSpace=three_webgpu.SRGBColorSpace,injectDispose(texture,imageReady(resource,()=>{texture.image=resource,texture.needsUpdate=!0,this._needsRender=!0}))}else if(resource instanceof HTMLCanvasElement)material.map=new three_webgpu.CanvasTexture(resource);else if(resource instanceof HTMLVideoElement){let texture=material.map=new three_webgpu.VideoTexture(resource);texture.wrapS=three_webgpu.ClampToEdgeWrapping,texture.wrapT=three_webgpu.ClampToEdgeWrapping,texture.minFilter=three_webgpu.LinearFilter,texture.colorSpace=three_webgpu.SRGBColorSpace,injectDispose(texture,videoReady(resource,()=>{this._needsRender=!0}));let bridge=getVideoTextureBridge(texture);this.onBeforeRender=renderer=>{bridge.update(renderer);let map=bridge.texture;material.map!==map&&(material.map=map)}}this._sourceTexture=material.map}get needsRender(){return this._needsRender}set needsRender(value){this._needsRender=value,value===!0&&this._sourceTexture&&(this._sourceTexture.needsUpdate=!0)}setSize(width,height){this.scale.set(width,height,1),this._needsRender=!0}setTransparent(transparent){this.material.transparent=transparent,this._needsRender=!0}locationWithIntersection(intersection,offset=.005){let{point,face}=intersection;this.position.copy(point),face&&(this.position.add(face.normal.clone().setLength(offset)),this.lookAt(point.clone().add(face.normal))),this._needsRender=!0}dispose(){var _a;(_a=this._sourceTexture)==null||_a.dispose(),this.material.dispose()}};exports.Sticker=Sticker;
381
+ void main() { color = vec4(texture(tex, uv).rgb, 1.0); }`)),gl.linkProgram(program),!gl.getProgramParameter(program,gl.LINK_STATUS))return null;let texture=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,texture),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),{canvas,gl,texture,program,pixels:new Uint8Array(GL_PROBE_SIZE*GL_PROBE_SIZE*4)}}catch(_a){return null}}function disposeGLProbe(probe){var _a;let{gl}=probe;gl.deleteTexture(probe.texture),gl.deleteProgram(probe.program),(_a=gl.getExtension(`WEBGL_lose_context`))==null||_a.loseContext()}var GPU_PROBE_WIDTH=64,GPU_PROBE_HEIGHT=16,VideoTextureBridge=class{constructor(videoTexture){var _a;this.debug={path:`pending`,candidate:``,locked:!1,probe:``,updateCalls:0,skipNotReady:0,blitCount:0,rvfcCount:0,fails:0,targetSize:``,lastError:``},this.mode=`unknown`,this.device=null,this.broken=!1,this.disposed=!1,this.locked=!1,this.blacklist=new Map,this.probing=!1,this.nextProbeAt=0,this.probeInterval=300,this.consecutiveFails=0,this.failingSince=0,this.frameTexture=null,this.frameReady=!1,this.heldFrame=null,this.canvas=null,this.canvasContext=null,this.gpuTexture=null,this.externalTexture=null,this.externalReady=!1,this.width=0,this.height=0,this.frameDirty=!0,this.lastVideoTime=-1,this.videoFrameCallbackId=null,this.glProbe=null,this.glProbeFailed=!1,this.gpuProbe=null,this.probeCanvas=null,this.forced=!1,this.onSourceChange=()=>{this.forced||(this.blacklist.clear(),this.locked=!1,this.debug.locked=!1,this.probeInterval=300,this.nextProbeAt=0,this.consecutiveFails=0,this.frameDirty=!0)},this.videoTexture=videoTexture,this.current=(_a=CANDIDATE_ORDER.find(isAvailable))==null?`video`:_a,this.debug.candidate=this.current,this.scheduleVideoFrameCallback();let video=this.video;typeof(video==null?void 0:video.addEventListener)==`function`&&video.addEventListener(`loadstart`,this.onSourceChange)}get video(){return this.videoTexture.image}scheduleVideoFrameCallback(){let video=this.video;this.disposed||typeof(video==null?void 0:video.requestVideoFrameCallback)!=`function`||(this.videoFrameCallbackId=video.requestVideoFrameCallback(()=>{this.videoFrameCallbackId=null,this.frameDirty=!0,this.debug.rvfcCount++,this.scheduleVideoFrameCallback()}))}get texture(){var _a;if(this.broken||this.mode===`unknown`)return this.videoTexture;let wantsExternal=this.mode===`webgpu`&&(this.current===`videoFrame`||this.current===`video`),external=this.externalReady?this.externalTexture:null,frame=this.frameReady?this.frameTexture:null;return(_a=wantsExternal?external==null?frame:external:frame==null?external:frame)==null?getPlaceholder():_a}update(renderer){if(this.debug.updateCalls++,this.disposed||this.broken||!this.resolveMode(renderer))return;let video=this.video;if(!(video instanceof HTMLVideoElement))return;if(video.readyState<2||video.videoWidth===0||video.videoHeight===0){this.debug.skipNotReady++;return}let now=performance.now();if(!this.locked&&!this.probing&&now>=this.nextProbeAt&&this.startProbe(),!(!this.frameDirty&&(this.debug.rvfcCount>0||video.currentTime===this.lastVideoTime)))try{this.produce(this.current,video),this.frameDirty=!1,this.lastVideoTime=video.currentTime,this.consecutiveFails=0,this.debug.blitCount++}catch(error){this.onProduceFailed(error)}}forceCandidate(candidate){if(candidate===null){this.forced=!1,this.onSourceChange();return}this.forced=!0,this.current=candidate,this.locked=!0,this.debug.candidate=candidate,this.debug.locked=!0,this.frameDirty=!0,this.releaseProbeResources()}resolveMode(renderer){if(this.mode!==`unknown`)return!0;let backend=renderer==null?void 0:renderer.backend;if(!backend)return!1;if(backend.isWebGPUBackend===!0){if(!backend.device)return!1;this.device=backend.device,this.mode=`webgpu`}else this.mode=`webgl`;return this.debug.path=this.mode,this.ensureFrameTexture(),!0}ensureFrameTexture(){if(this.frameTexture)return;let source=this.videoTexture,texture=new three_webgpu.VideoFrameTexture;texture.colorSpace=three_webgpu.SRGBColorSpace,texture.generateMipmaps=!1,texture.minFilter=source.minFilter,texture.magFilter=source.magFilter,texture.wrapS=source.wrapS,texture.wrapT=source.wrapT,this.frameTexture=texture}produce(candidate,video){let webgpu=this.mode===`webgpu`;switch(candidate){case`videoFrame`:{let frame=createVideoFrame(video);if(webgpu)try{this.blit(frame,video)}finally{frame.close()}else this.setFrame(frame,frame);break}case`video`:webgpu?this.blit(video,video):this.setFrame(video,null);break;case`canvasFromVideoFrame`:{let frame=createVideoFrame(video);try{this.drawCanvas(frame,video)}finally{frame.close()}this.setFrame(this.canvas,null);break}case`canvasFromVideo`:this.drawCanvas(video,video),this.setFrame(this.canvas,null);break}}setFrame(image,owned){this.frameTexture.setFrame(image);let previous=this.heldFrame;this.heldFrame=owned,previous&&previous!==owned&&previous.close(),this.frameReady=!0}drawCanvas(source,video){let scale=Math.min(1,MAX_CANVAS_SIZE/Math.max(video.videoWidth,video.videoHeight)),width=Math.max(1,Math.floor(video.videoWidth*scale)),height=Math.max(1,Math.floor(video.videoHeight*scale));if(!this.canvas&&(this.canvas=document.createElement(`canvas`),this.canvasContext=this.canvas.getContext(`2d`,{alpha:!1}),!this.canvasContext))throw Error(`canvas 2d 上下文不可用`);this.canvas.width!==width&&(this.canvas.width=width),this.canvas.height!==height&&(this.canvas.height=height),this.canvasContext.drawImage(source,0,0,width,height)}isBlacklisted(candidate){let expiresAt=this.blacklist.get(candidate);return expiresAt===void 0?!1:performance.now()>=expiresAt?(this.blacklist.delete(candidate),!1):!0}onProduceFailed(error){var _a;let now=performance.now();if(this.consecutiveFails===0&&(this.failingSince=now),this.consecutiveFails++,this.debug.fails++,this.debug.lastError=String((_a=error==null?void 0:error.message)==null?error:_a),this.consecutiveFails<MAX_CONSECUTIVE_FAILS||now-this.failingSince<MIN_FAIL_DURATION_MS)return;console.warn(`[Five] 视频候选路径 ${this.current} 持续失败,暂时弃用`,error),this.blacklist.set(this.current,now+BLACKLIST_TTL_MS);let next=CANDIDATE_ORDER.find(c=>isAvailable(c)&&!this.isBlacklisted(c));this.consecutiveFails=0,next?(this.current=next,this.debug.candidate=next,this.locked=!1,this.debug.locked=!1,this.nextProbeAt=0,this.frameDirty=!0):(console.warn(`[Five] 视频所有候选路径均失败,回退为 VideoTexture 上传`),this.broken=!0,this.debug.path=`fallback`,this.releaseOutputs())}blit(source,video){this.ensureTarget(video.videoWidth,video.videoHeight);let device=this.device,{pipeline,bindGroupLayout,sampler}=getBlitPipeline(device),external=device.importExternalTexture({source}),bindGroup=device.createBindGroup({layout:bindGroupLayout,entries:[{binding:0,resource:external},{binding:1,resource:sampler}]}),encoder=device.createCommandEncoder({label:`five.videoBlit`}),pass=encoder.beginRenderPass({colorAttachments:[{view:this.gpuTexture.createView(),loadOp:`clear`,storeOp:`store`,clearValue:{r:0,g:0,b:0,a:1}}]});pass.setPipeline(pipeline),pass.setBindGroup(0,bindGroup),pass.draw(3),pass.end(),device.queue.submit([encoder.finish()]),this.externalReady=!0,this.debug.targetSize=`${this.width}x${this.height}`}ensureTarget(videoWidth,videoHeight){let device=this.device,maxSize=device.limits.maxTextureDimension2D,scale=Math.min(1,maxSize/Math.max(videoWidth,videoHeight)),width=Math.max(1,Math.floor(videoWidth*scale)),height=Math.max(1,Math.floor(videoHeight*scale));if(this.gpuTexture&&this.width===width&&this.height===height)return;let prevGPUTexture=this.gpuTexture,gpuTexture=device.createTexture({label:`five.videoBlit.target`,size:{width,height},format:INTERMEDIATE_FORMAT,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT});if(this.gpuTexture=gpuTexture,this.width=width,this.height=height,this.externalTexture)this.externalTexture.sourceTexture=gpuTexture,this.externalTexture.image={width,height},this.externalTexture.dispose();else{let texture=new three_webgpu.ExternalTexture(gpuTexture);texture.colorSpace=three_webgpu.SRGBColorSpace,texture.flipY=!1,texture.generateMipmaps=!1,texture.minFilter=three_webgpu.LinearFilter,texture.magFilter=three_webgpu.LinearFilter,texture.wrapS=three_webgpu.ClampToEdgeWrapping,texture.wrapT=three_webgpu.ClampToEdgeWrapping,texture.image={width,height},this.externalTexture=texture}prevGPUTexture==null||prevGPUTexture.destroy()}startProbe(){this.probing=!0,this.runProbe().catch(error=>{var _a;this.debug.lastError=String((_a=error==null?void 0:error.message)==null?error:_a)}).finally(()=>{this.probing=!1,this.nextProbeAt=performance.now()+this.probeInterval,this.probeInterval=Math.min(this.probeInterval*1.5,5e3)})}runProbe(){return(0,tslib.__awaiter)(this,void 0,void 0,function*(){let results=[],chosen=null;for(let candidate of CANDIDATE_ORDER){let label=CANDIDATE_SHORT[candidate];if(this.disposed)return;if(this.isBlacklisted(candidate)||!isAvailable(candidate)){results.push(`${label}:n/a`);continue}let brightness;try{brightness=yield this.probeCandidate(candidate)}catch(_a){brightness=-1}if(results.push(`${label}:${brightness===null?`?`:brightness}`),brightness===null||brightness>=BRIGHT_THRESHOLD){chosen=candidate;break}}this.debug.probe=results.join(` `),chosen&&this.select(chosen)})}select(candidate){this.current=candidate,this.locked=!0,this.debug.candidate=candidate,this.debug.locked=!0,this.frameDirty=!0,this.releaseProbeResources()}probeCandidate(candidate){return(0,tslib.__awaiter)(this,void 0,void 0,function*(){let video=this.video;if(!(video instanceof HTMLVideoElement)||video.readyState<2)return-1;switch(candidate){case`canvasFromVideoFrame`:return this.probe2d(video,!0);case`canvasFromVideo`:return this.probe2d(video,!1);default:return this.mode===`webgpu`?this.probeGPU(video,candidate===`videoFrame`):this.probeGL(video,candidate===`videoFrame`)}})}probe2d(video,useFrame){if(!this.probeCanvas){let canvas=document.createElement(`canvas`);canvas.width=canvas.height=GL_PROBE_SIZE;let context=canvas.getContext(`2d`,{willReadFrequently:!0});if(!context)return-1;this.probeCanvas=context}let frame=useFrame?createVideoFrame(video):null;try{return this.probeCanvas.drawImage(frame==null?video:frame,0,0,GL_PROBE_SIZE,GL_PROBE_SIZE),maxChannel(this.probeCanvas.getImageData(0,0,GL_PROBE_SIZE,GL_PROBE_SIZE).data)}finally{frame==null||frame.close()}}probeGL(video,useFrame){!this.glProbe&&!this.glProbeFailed&&(this.glProbe=createGLProbe(),this.glProbeFailed=this.glProbe===null);let probe=this.glProbe;if(!probe)return null;let{gl}=probe,frame=useFrame?createVideoFrame(video):null;try{return gl.getError(),gl.viewport(0,0,GL_PROBE_SIZE,GL_PROBE_SIZE),gl.bindTexture(gl.TEXTURE_2D,probe.texture),gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,frame==null?video:frame),gl.getError()===gl.NO_ERROR?(gl.useProgram(probe.program),gl.drawArrays(gl.TRIANGLES,0,3),gl.readPixels(0,0,GL_PROBE_SIZE,GL_PROBE_SIZE,gl.RGBA,gl.UNSIGNED_BYTE,probe.pixels),maxChannel(probe.pixels)):-1}finally{frame==null||frame.close()}}probeGPU(video,useFrame){return(0,tslib.__awaiter)(this,void 0,void 0,function*(){let device=this.device,{pipeline,bindGroupLayout,sampler}=getBlitPipeline(device);this.gpuProbe||(this.gpuProbe={texture:device.createTexture({label:`five.videoProbe.target`,size:{width:GPU_PROBE_WIDTH,height:GPU_PROBE_HEIGHT},format:INTERMEDIATE_FORMAT,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),buffer:device.createBuffer({label:`five.videoProbe.readback`,size:GPU_PROBE_WIDTH*4*GPU_PROBE_HEIGHT,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})});let probe=this.gpuProbe;device.pushErrorScope(`validation`);let encodeError=null,frame=useFrame?createVideoFrame(video):null;try{let external=device.importExternalTexture({source:frame==null?video:frame}),bindGroup=device.createBindGroup({layout:bindGroupLayout,entries:[{binding:0,resource:external},{binding:1,resource:sampler}]}),encoder=device.createCommandEncoder({label:`five.videoProbe`}),pass=encoder.beginRenderPass({colorAttachments:[{view:probe.texture.createView(),loadOp:`clear`,storeOp:`store`,clearValue:{r:0,g:0,b:0,a:1}}]});pass.setPipeline(pipeline),pass.setBindGroup(0,bindGroup),pass.draw(3),pass.end(),encoder.copyTextureToBuffer({texture:probe.texture},{buffer:probe.buffer,bytesPerRow:GPU_PROBE_WIDTH*4},{width:GPU_PROBE_WIDTH,height:GPU_PROBE_HEIGHT}),device.queue.submit([encoder.finish()])}catch(error){encodeError=error}finally{frame==null||frame.close()}let scopeError=yield device.popErrorScope();if(encodeError||scopeError)return-1;yield probe.buffer.mapAsync(GPUMapMode.READ);let brightness=maxChannel(new Uint8Array(probe.buffer.getMappedRange()));return probe.buffer.unmap(),brightness})}releaseProbeResources(){this.glProbe&&(disposeGLProbe(this.glProbe),this.glProbe=null),this.glProbeFailed=!1,this.probeCanvas=null,this.gpuProbe&&(this.gpuProbe.texture.destroy(),this.gpuProbe.buffer.destroy(),this.gpuProbe=null)}releaseOutputs(){var _a,_b,_c,_d;(_a=this.heldFrame)==null||_a.close(),this.heldFrame=null,(_b=this.frameTexture)==null||_b.dispose(),this.frameTexture=null,this.frameReady=!1,(_c=this.externalTexture)==null||_c.dispose(),this.externalTexture=null,this.externalReady=!1,(_d=this.gpuTexture)==null||_d.destroy(),this.gpuTexture=null,this.width=this.height=0,this.canvas=null,this.canvasContext=null}dispose(){if(this.disposed)return;this.disposed=!0;let video=this.video;this.videoFrameCallbackId!==null&&typeof(video==null?void 0:video.cancelVideoFrameCallback)==`function`&&video.cancelVideoFrameCallback(this.videoFrameCallbackId),this.videoFrameCallbackId=null,typeof(video==null?void 0:video.removeEventListener)==`function`&&video.removeEventListener(`loadstart`,this.onSourceChange),this.releaseOutputs(),this.releaseProbeResources()}},bridges=new WeakMap;function getVideoTextureBridge(videoTexture){let bridge=bridges.get(videoTexture);if(!bridge){let created=new VideoTextureBridge(videoTexture);bridge=created,bridges.set(videoTexture,created);let onDispose=()=>{videoTexture.removeEventListener(`dispose`,onDispose),bridges.get(videoTexture)===created&&bridges.delete(videoTexture),created.dispose()};videoTexture.addEventListener(`dispose`,onDispose)}return bridge}var window_=window,_requestAnimationFrame=window_.requestAnimationFrame||window_.mozRequestAnimationFrame||window_.webkitRequestAnimationFrame||window_.msRequestAnimationFrame||(fn=>setTimeout(fn,16)),start=typeof performance<`u`&&performance.timing!==void 0?performance.timing.navigationStart:Date.now(),now=typeof performance<`u`?(()=>start+performance.now()):(()=>Date.now());function imageReady(image,callback){image.naturalWidth>0&&_requestAnimationFrame(()=>callback());let onLoad=()=>callback();return image.addEventListener(`load`,onLoad,!1),()=>image.removeEventListener(`load`,onLoad,!1)}function videoReady(video,callback){let lastUpdateTime=now(),looping=!1,loop=()=>{looping=!0,callback(),now()-lastUpdateTime<3e3?_requestAnimationFrame(loop):looping=!1},onUpdate=()=>{lastUpdateTime=now(),looping===!1&&loop()};return video.addEventListener(`timeupdate`,onUpdate,!1),()=>{video.removeEventListener(`timeupdate`,onUpdate,!1),looping=!1}}function injectDispose(texture,dispose){let _dispose=texture.dispose;texture.dispose=()=>{dispose(),_dispose.call(texture)}}var Sticker=class extends three_webgpu.Mesh{static get version(){return`1.0.0-alpha.15`}constructor(width,height,resource){let material=new three_webgpu.MeshBasicMaterial;if(super(geometry,material),this._sourceTexture=null,this._needsRender=!1,this.scale.set(width,height,1),typeof resource==`string`){material.transparent=/\.png$/.test(resource);let image=new Image;image.src=resource,image.crossOrigin=``,resource=image}if(resource instanceof HTMLImageElement){let texture=material.map=new three_webgpu.Texture;texture.wrapS=three_webgpu.ClampToEdgeWrapping,texture.wrapT=three_webgpu.ClampToEdgeWrapping,texture.minFilter=three_webgpu.LinearFilter,texture.colorSpace=three_webgpu.SRGBColorSpace,injectDispose(texture,imageReady(resource,()=>{texture.image=resource,texture.needsUpdate=!0,this._needsRender=!0}))}else if(resource instanceof HTMLCanvasElement)material.map=new three_webgpu.CanvasTexture(resource);else if(resource instanceof HTMLVideoElement){let texture=material.map=new three_webgpu.VideoTexture(resource);texture.wrapS=three_webgpu.ClampToEdgeWrapping,texture.wrapT=three_webgpu.ClampToEdgeWrapping,texture.minFilter=three_webgpu.LinearFilter,texture.colorSpace=three_webgpu.SRGBColorSpace,injectDispose(texture,videoReady(resource,()=>{this._needsRender=!0}));let bridge=getVideoTextureBridge(texture);this.onBeforeRender=renderer=>{bridge.update(renderer);let map=bridge.texture;material.map!==map&&(material.map=map)}}this._sourceTexture=material.map}get needsRender(){return this._needsRender}set needsRender(value){this._needsRender=value,value===!0&&this._sourceTexture&&(this._sourceTexture.needsUpdate=!0)}setSize(width,height){this.scale.set(width,height,1),this._needsRender=!0}setTransparent(transparent){this.material.transparent=transparent,this._needsRender=!0}locationWithIntersection(intersection,offset=.005){let{point,face}=intersection;this.position.copy(point),face&&(this.position.add(face.normal.clone().setLength(offset)),this.lookAt(point.clone().add(face.normal))),this._needsRender=!0}dispose(){var _a;(_a=this._sourceTexture)==null||_a.dispose(),this.material.dispose()}};exports.Sticker=Sticker;