angular-three-soba 2.0.0-beta.4 → 2.0.0-beta.41

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 (323) hide show
  1. package/abstractions/billboard/billboard.d.ts +12 -8
  2. package/abstractions/detailed/detailed.d.ts +26 -0
  3. package/abstractions/edges/edges.d.ts +24 -12
  4. package/abstractions/grid/grid.d.ts +42 -51
  5. package/abstractions/index.d.ts +1 -7
  6. package/abstractions/text/text.d.ts +10 -4
  7. package/abstractions/text-3d/text-3d.d.ts +51 -41
  8. package/cameras/camera/camera-content.d.ts +1 -1
  9. package/cameras/camera/camera.d.ts +16 -13
  10. package/cameras/cube-camera/cube-camera.d.ts +49 -23
  11. package/cameras/index.d.ts +0 -1
  12. package/cameras/orthographic-camera/orthographic-camera.d.ts +29 -18
  13. package/cameras/perspective-camera/perspective-camera.d.ts +10 -1
  14. package/controls/orbit-controls/orbit-controls.d.ts +34 -15
  15. package/esm2022/abstractions/billboard/billboard.mjs +36 -33
  16. package/esm2022/abstractions/detailed/detailed.mjs +64 -0
  17. package/esm2022/abstractions/edges/edges.mjs +58 -63
  18. package/esm2022/abstractions/grid/grid.mjs +140 -110
  19. package/esm2022/abstractions/index.mjs +2 -8
  20. package/esm2022/abstractions/text/text.mjs +123 -122
  21. package/esm2022/abstractions/text-3d/text-3d.mjs +120 -115
  22. package/esm2022/cameras/camera/camera-content.mjs +6 -6
  23. package/esm2022/cameras/camera/camera.mjs +48 -42
  24. package/esm2022/cameras/cube-camera/cube-camera.mjs +120 -100
  25. package/esm2022/cameras/index.mjs +1 -2
  26. package/esm2022/cameras/orthographic-camera/orthographic-camera.mjs +78 -75
  27. package/esm2022/cameras/perspective-camera/perspective-camera.mjs +25 -26
  28. package/esm2022/controls/orbit-controls/orbit-controls.mjs +109 -85
  29. package/esm2022/gizmos/angular-three-soba-gizmos.mjs +5 -0
  30. package/esm2022/gizmos/gizmo-helper/gizmo-helper.mjs +198 -0
  31. package/esm2022/gizmos/gizmo-helper/gizmo-viewcube/constants.mjs +31 -0
  32. package/esm2022/gizmos/gizmo-helper/gizmo-viewcube/gizmo-viewcube-edge.mjs +93 -0
  33. package/esm2022/gizmos/gizmo-helper/gizmo-viewcube/gizmo-viewcube-face.mjs +151 -0
  34. package/esm2022/gizmos/gizmo-helper/gizmo-viewcube/gizmo-viewcube-input.mjs +66 -0
  35. package/esm2022/gizmos/gizmo-helper/gizmo-viewcube/gizmo-viewcube.mjs +71 -0
  36. package/esm2022/gizmos/gizmo-helper/gizmo-viewport/gizmo-viewport-axis.mjs +195 -0
  37. package/esm2022/gizmos/gizmo-helper/gizmo-viewport/gizmo-viewport.mjs +272 -0
  38. package/esm2022/gizmos/index.mjs +4 -0
  39. package/esm2022/loaders/gltf-loader/gltf-loader.mjs +14 -9
  40. package/esm2022/loaders/loader/loader.mjs +92 -87
  41. package/esm2022/loaders/progress/progress.mjs +31 -30
  42. package/esm2022/loaders/texture-loader/texture-loader.mjs +20 -15
  43. package/esm2022/materials/index.mjs +2 -1
  44. package/esm2022/materials/mesh-distort-material/mesh-distort-material.mjs +60 -51
  45. package/esm2022/materials/mesh-reflector-material/mesh-reflector-material.mjs +239 -255
  46. package/esm2022/materials/mesh-refraction-material/mesh-refraction-material.mjs +99 -97
  47. package/esm2022/materials/mesh-transmission-material/mesh-transmission-material.mjs +164 -144
  48. package/esm2022/materials/mesh-wobble-material/mesh-wobble-material.mjs +44 -42
  49. package/esm2022/materials/point-material/point-material.mjs +50 -0
  50. package/esm2022/misc/animations/animations.mjs +28 -23
  51. package/esm2022/misc/bake-shadows/bake-shadows.mjs +13 -13
  52. package/esm2022/misc/caustics/caustics.mjs +387 -0
  53. package/esm2022/misc/decal/decal.mjs +187 -0
  54. package/esm2022/misc/depth-buffer/depth-buffer.mjs +41 -37
  55. package/esm2022/misc/example/example.mjs +161 -0
  56. package/esm2022/misc/fbo/fbo.mjs +42 -36
  57. package/esm2022/misc/html/html-wrapper.mjs +478 -0
  58. package/esm2022/misc/html/html.mjs +305 -0
  59. package/esm2022/misc/index.mjs +10 -1
  60. package/esm2022/misc/sampler/sampler.mjs +132 -0
  61. package/esm2022/misc/shadow/shadow.mjs +111 -0
  62. package/esm2022/misc/stats-gl/stats-gl.mjs +61 -0
  63. package/esm2022/misc/trail/trail.mjs +204 -0
  64. package/esm2022/misc/trail-texture/inject-trail-texture.mjs +17 -0
  65. package/esm2022/misc/trail-texture/trail-texture.mjs +106 -0
  66. package/esm2022/modifiers/angular-three-soba-modifiers.mjs +5 -0
  67. package/esm2022/modifiers/curve-modifier/curve-modifier.mjs +64 -0
  68. package/esm2022/modifiers/index.mjs +2 -0
  69. package/esm2022/performances/adaptive-dpr/adaptive-dpr.mjs +44 -0
  70. package/esm2022/performances/adaptive-events/adaptive-events.mjs +27 -0
  71. package/esm2022/performances/angular-three-soba-performances.mjs +5 -0
  72. package/esm2022/performances/index.mjs +8 -0
  73. package/esm2022/performances/instances/instances.mjs +221 -0
  74. package/esm2022/performances/instances/position-mesh.mjs +52 -0
  75. package/esm2022/performances/points/points-input.mjs +64 -0
  76. package/esm2022/performances/points/points.mjs +327 -0
  77. package/esm2022/performances/points/position-point.mjs +54 -0
  78. package/esm2022/performances/segments/segment-object.mjs +9 -0
  79. package/esm2022/performances/segments/segments.mjs +183 -0
  80. package/esm2022/shaders/blur-pass/blur-pass.mjs +2 -2
  81. package/esm2022/shaders/caustics/caustics-material.mjs +130 -0
  82. package/esm2022/shaders/caustics/caustics-projection-material.mjs +32 -0
  83. package/esm2022/shaders/convolution-material/convolution-material.mjs +3 -2
  84. package/esm2022/shaders/discard-material/discard-material.mjs +1 -1
  85. package/esm2022/shaders/grid-material/grid-material.mjs +30 -14
  86. package/esm2022/shaders/index.mjs +5 -3
  87. package/esm2022/shaders/mesh-distort-material/mesh-distort-material.mjs +42 -41
  88. package/esm2022/shaders/mesh-reflector-material/mesh-reflector-material.mjs +2 -2
  89. package/esm2022/shaders/mesh-refraction-material/mesh-refraction-material.mjs +3 -2
  90. package/esm2022/shaders/mesh-transmission-material/mesh-transmission-material.mjs +7 -4
  91. package/esm2022/shaders/mesh-wobble-material/mesh-wobble-material.mjs +1 -1
  92. package/esm2022/shaders/shader-material/shader-material.mjs +3 -5
  93. package/esm2022/shaders/soft-shadow-material/soft-shadow-material.mjs +18 -25
  94. package/esm2022/shaders/sparkles-material/sparkles-material.mjs +32 -46
  95. package/esm2022/shaders/spot-light-material/spot-light-material.mjs +8 -7
  96. package/esm2022/shaders/star-field-material/star-field-material.mjs +3 -2
  97. package/esm2022/shaders/wireframe-material/wireframe-material.mjs +247 -0
  98. package/esm2022/staging/accumulative-shadows/accumulative-shadows.mjs +161 -176
  99. package/esm2022/staging/accumulative-shadows/progressive-light-map.mjs +8 -8
  100. package/esm2022/staging/accumulative-shadows/randomized-lights.mjs +129 -129
  101. package/esm2022/staging/backdrop/backdrop.mjs +77 -0
  102. package/esm2022/staging/bb-anchor/bb-anchor.mjs +69 -0
  103. package/esm2022/staging/bounds/bounds.mjs +145 -143
  104. package/esm2022/staging/camera-shake/camera-shake.mjs +86 -80
  105. package/esm2022/staging/center/center.mjs +129 -112
  106. package/esm2022/staging/cloud/cloud.mjs +118 -124
  107. package/esm2022/staging/contact-shadows/contact-shadows.mjs +131 -136
  108. package/esm2022/staging/environment/assets.mjs +12 -12
  109. package/esm2022/staging/environment/environment-cube.mjs +28 -30
  110. package/esm2022/staging/environment/environment-ground.mjs +17 -19
  111. package/esm2022/staging/environment/environment-input.mjs +98 -85
  112. package/esm2022/staging/environment/environment-map.mjs +33 -33
  113. package/esm2022/staging/environment/environment-portal.mjs +75 -97
  114. package/esm2022/staging/environment/environment.mjs +34 -51
  115. package/esm2022/staging/environment/utils.mjs +40 -17
  116. package/esm2022/staging/float/float.mjs +70 -58
  117. package/esm2022/staging/index.mjs +7 -3
  118. package/esm2022/staging/matcap-texture/matcap-texture.mjs +64 -0
  119. package/esm2022/staging/normal-texture/normal-texture.mjs +53 -0
  120. package/esm2022/staging/sky/sky.mjs +85 -80
  121. package/esm2022/staging/sparkles/sparkles.mjs +108 -105
  122. package/esm2022/staging/spot-light/shadow-mesh-input.mjs +63 -0
  123. package/esm2022/staging/spot-light/shadow-mesh.mjs +267 -0
  124. package/esm2022/staging/spot-light/spot-light-input.mjs +67 -58
  125. package/esm2022/staging/spot-light/spot-light.mjs +51 -63
  126. package/esm2022/staging/spot-light/volumetric-mesh.mjs +67 -70
  127. package/esm2022/staging/stage/stage.mjs +305 -290
  128. package/esm2022/staging/stars/stars.mjs +101 -102
  129. package/esm2022/staging/wireframe/wireframe-input.mjs +191 -0
  130. package/esm2022/staging/wireframe/wireframe.mjs +228 -0
  131. package/esm2022/utils/angular-three-soba-utils.mjs +5 -0
  132. package/esm2022/utils/constants.mjs +3 -0
  133. package/esm2022/utils/content/content.mjs +15 -0
  134. package/esm2022/utils/index.mjs +3 -0
  135. package/fesm2022/angular-three-soba-abstractions.mjs +504 -2079
  136. package/fesm2022/angular-three-soba-abstractions.mjs.map +1 -1
  137. package/fesm2022/angular-three-soba-cameras.mjs +293 -260
  138. package/fesm2022/angular-three-soba-cameras.mjs.map +1 -1
  139. package/fesm2022/angular-three-soba-controls.mjs +108 -83
  140. package/fesm2022/angular-three-soba-controls.mjs.map +1 -1
  141. package/fesm2022/angular-three-soba-gizmos.mjs +1045 -0
  142. package/fesm2022/angular-three-soba-gizmos.mjs.map +1 -0
  143. package/fesm2022/angular-three-soba-loaders.mjs +148 -132
  144. package/fesm2022/angular-three-soba-loaders.mjs.map +1 -1
  145. package/fesm2022/angular-three-soba-materials.mjs +656 -588
  146. package/fesm2022/angular-three-soba-materials.mjs.map +1 -1
  147. package/fesm2022/angular-three-soba-misc.mjs +2202 -99
  148. package/fesm2022/angular-three-soba-misc.mjs.map +1 -1
  149. package/fesm2022/angular-three-soba-modifiers.mjs +71 -0
  150. package/fesm2022/angular-three-soba-modifiers.mjs.map +1 -0
  151. package/fesm2022/angular-three-soba-performances.mjs +957 -0
  152. package/fesm2022/angular-three-soba-performances.mjs.map +1 -0
  153. package/fesm2022/angular-three-soba-shaders.mjs +508 -269
  154. package/fesm2022/angular-three-soba-shaders.mjs.map +1 -1
  155. package/fesm2022/angular-three-soba-staging.mjs +2910 -2573
  156. package/fesm2022/angular-three-soba-staging.mjs.map +1 -1
  157. package/fesm2022/angular-three-soba-utils.mjs +25 -0
  158. package/fesm2022/angular-three-soba-utils.mjs.map +1 -0
  159. package/gizmos/README.md +3 -0
  160. package/gizmos/gizmo-helper/gizmo-helper.d.ts +73 -0
  161. package/gizmos/gizmo-helper/gizmo-viewcube/gizmo-viewcube-edge.d.ts +22 -0
  162. package/gizmos/gizmo-helper/gizmo-viewcube/gizmo-viewcube-face.d.ts +29 -0
  163. package/gizmos/gizmo-helper/gizmo-viewcube/gizmo-viewcube-input.d.ts +33 -0
  164. package/gizmos/gizmo-helper/gizmo-viewcube/gizmo-viewcube.d.ts +10 -0
  165. package/gizmos/gizmo-helper/gizmo-viewport/gizmo-viewport-axis.d.ts +40 -0
  166. package/gizmos/gizmo-helper/gizmo-viewport/gizmo-viewport.d.ts +30 -0
  167. package/gizmos/index.d.ts +3 -0
  168. package/loaders/gltf-loader/gltf-loader.d.ts +15 -4
  169. package/loaders/loader/loader.d.ts +19 -17
  170. package/loaders/progress/progress.d.ts +1 -1
  171. package/loaders/texture-loader/texture-loader.d.ts +8 -3
  172. package/materials/index.d.ts +1 -0
  173. package/materials/mesh-distort-material/mesh-distort-material.d.ts +25 -15
  174. package/materials/mesh-reflector-material/mesh-reflector-material.d.ts +74 -56
  175. package/materials/mesh-refraction-material/mesh-refraction-material.d.ts +33 -21
  176. package/materials/mesh-transmission-material/mesh-transmission-material.d.ts +55 -39
  177. package/materials/mesh-wobble-material/mesh-wobble-material.d.ts +19 -10
  178. package/materials/point-material/point-material.d.ts +24 -0
  179. package/metadata.json +1 -0
  180. package/misc/animations/animations.d.ts +6 -4
  181. package/misc/caustics/caustics.d.ts +87 -0
  182. package/misc/decal/decal.d.ts +49 -0
  183. package/misc/depth-buffer/depth-buffer.d.ts +2 -2
  184. package/misc/example/example.d.ts +85 -0
  185. package/misc/fbo/fbo.d.ts +2 -2
  186. package/misc/html/html-wrapper.d.ts +559 -0
  187. package/misc/html/html.d.ts +218 -0
  188. package/misc/index.d.ts +9 -0
  189. package/misc/sampler/sampler.d.ts +67 -0
  190. package/misc/shadow/shadow.d.ts +37 -0
  191. package/misc/stats-gl/stats-gl.d.ts +24 -0
  192. package/misc/trail/trail.d.ts +57 -0
  193. package/misc/trail-texture/inject-trail-texture.d.ts +9 -0
  194. package/misc/trail-texture/trail-texture.d.ts +50 -0
  195. package/modifiers/README.md +3 -0
  196. package/modifiers/curve-modifier/curve-modifier.d.ts +23 -0
  197. package/modifiers/index.d.ts +1 -0
  198. package/package.json +42 -24
  199. package/performances/README.md +3 -0
  200. package/performances/adaptive-dpr/adaptive-dpr.d.ts +14 -0
  201. package/{performance/adaptive → performances/adaptive-events}/adaptive-events.d.ts +3 -0
  202. package/performances/index.d.ts +7 -0
  203. package/performances/instances/instances.d.ts +83 -0
  204. package/{performance → performances}/instances/position-mesh.d.ts +1 -1
  205. package/performances/points/points-input.d.ts +32 -0
  206. package/performances/points/points.d.ts +96 -0
  207. package/performances/points/position-point.d.ts +11 -0
  208. package/performances/segments/segment-object.d.ts +7 -0
  209. package/performances/segments/segments.d.ts +128 -0
  210. package/shaders/grid-material/grid-material.d.ts +33 -0
  211. package/shaders/index.d.ts +4 -2
  212. package/shaders/mesh-distort-material/mesh-distort-material.d.ts +173 -6
  213. package/shaders/mesh-transmission-material/mesh-transmission-material.d.ts +1 -1
  214. package/shaders/shader-material/shader-material.d.ts +2 -2
  215. package/shaders/soft-shadow-material/soft-shadow-material.d.ts +10 -1
  216. package/shaders/sparkles-material/sparkles-material.d.ts +13 -0
  217. package/shaders/spot-light-material/spot-light-material.d.ts +11 -2
  218. package/shaders/star-field-material/star-field-material.d.ts +9 -0
  219. package/shaders/wireframe-material/wireframe-material.d.ts +58 -0
  220. package/staging/accumulative-shadows/accumulative-shadows.d.ts +93 -39
  221. package/staging/accumulative-shadows/randomized-lights.d.ts +41 -28
  222. package/staging/backdrop/backdrop.d.ts +30 -0
  223. package/staging/bb-anchor/bb-anchor.d.ts +27 -0
  224. package/staging/bounds/bounds.d.ts +105 -25
  225. package/staging/camera-shake/camera-shake.d.ts +30 -19
  226. package/staging/center/center.d.ts +43 -35
  227. package/staging/cloud/cloud.d.ts +27 -24
  228. package/staging/contact-shadows/contact-shadows.d.ts +43 -30
  229. package/staging/environment/assets.d.ts +9 -9
  230. package/staging/environment/environment-cube.d.ts +9 -5
  231. package/staging/environment/environment-ground.d.ts +7 -7
  232. package/staging/environment/environment-input.d.ts +38 -38
  233. package/staging/environment/environment-map.d.ts +10 -5
  234. package/staging/environment/environment-portal.d.ts +10 -5
  235. package/staging/environment/environment.d.ts +0 -4
  236. package/staging/environment/utils.d.ts +2 -2
  237. package/staging/float/float.d.ts +15 -11
  238. package/staging/index.d.ts +6 -2
  239. package/staging/matcap-texture/matcap-texture.d.ts +13 -0
  240. package/staging/normal-texture/normal-texture.d.ts +16 -0
  241. package/staging/sky/sky.d.ts +28 -21
  242. package/staging/sparkles/sparkles.d.ts +36 -22
  243. package/staging/spot-light/shadow-mesh-input.d.ts +29 -0
  244. package/staging/spot-light/shadow-mesh.d.ts +37 -0
  245. package/staging/spot-light/spot-light-input.d.ts +25 -25
  246. package/staging/spot-light/spot-light.d.ts +35 -15
  247. package/staging/spot-light/volumetric-mesh.d.ts +15 -9
  248. package/staging/stage/stage.d.ts +89 -65
  249. package/staging/stars/stars.d.ts +28 -17
  250. package/staging/wireframe/wireframe-input.d.ts +65 -0
  251. package/staging/wireframe/wireframe.d.ts +28 -0
  252. package/utils/README.md +3 -0
  253. package/utils/constants.d.ts +1 -0
  254. package/utils/content/content.d.ts +8 -0
  255. package/utils/index.d.ts +2 -0
  256. package/web-types.json +1 -0
  257. package/abstractions/catmull-rom-line/catmull-rom-line.d.ts +0 -25
  258. package/abstractions/cubic-bezier-line/cubic-bezier-line.d.ts +0 -25
  259. package/abstractions/gizmo-helper/gizmo-helper.d.ts +0 -34
  260. package/abstractions/gizmo-helper/gizmo-viewcube/gizmo-viewcube-edge.d.ts +0 -22
  261. package/abstractions/gizmo-helper/gizmo-viewcube/gizmo-viewcube-face.d.ts +0 -30
  262. package/abstractions/gizmo-helper/gizmo-viewcube/gizmo-viewcube-inputs.d.ts +0 -32
  263. package/abstractions/gizmo-helper/gizmo-viewcube/gizmo-viewcube.d.ts +0 -14
  264. package/abstractions/gizmo-helper/gizmo-viewport/gizmo-viewport-axis.d.ts +0 -47
  265. package/abstractions/gizmo-helper/gizmo-viewport/gizmo-viewport.d.ts +0 -40
  266. package/abstractions/line/line-input.d.ts +0 -42
  267. package/abstractions/line/line.d.ts +0 -35
  268. package/abstractions/quadratic-bezier-line/quadratic-bezier-line.d.ts +0 -23
  269. package/esm2022/abstractions/catmull-rom-line/catmull-rom-line.mjs +0 -131
  270. package/esm2022/abstractions/cubic-bezier-line/cubic-bezier-line.mjs +0 -113
  271. package/esm2022/abstractions/gizmo-helper/gizmo-helper.mjs +0 -210
  272. package/esm2022/abstractions/gizmo-helper/gizmo-viewcube/constants.mjs +0 -31
  273. package/esm2022/abstractions/gizmo-helper/gizmo-viewcube/gizmo-viewcube-edge.mjs +0 -95
  274. package/esm2022/abstractions/gizmo-helper/gizmo-viewcube/gizmo-viewcube-face.mjs +0 -155
  275. package/esm2022/abstractions/gizmo-helper/gizmo-viewcube/gizmo-viewcube-inputs.mjs +0 -62
  276. package/esm2022/abstractions/gizmo-helper/gizmo-viewcube/gizmo-viewcube.mjs +0 -80
  277. package/esm2022/abstractions/gizmo-helper/gizmo-viewport/gizmo-viewport-axis.mjs +0 -206
  278. package/esm2022/abstractions/gizmo-helper/gizmo-viewport/gizmo-viewport.mjs +0 -273
  279. package/esm2022/abstractions/line/line-input.mjs +0 -113
  280. package/esm2022/abstractions/line/line.mjs +0 -165
  281. package/esm2022/abstractions/quadratic-bezier-line/quadratic-bezier-line.mjs +0 -128
  282. package/esm2022/performance/adaptive/adaptive-dpr.mjs +0 -46
  283. package/esm2022/performance/adaptive/adaptive-events.mjs +0 -31
  284. package/esm2022/performance/angular-three-soba-performance.mjs +0 -5
  285. package/esm2022/performance/detailed/detailed.mjs +0 -61
  286. package/esm2022/performance/index.mjs +0 -7
  287. package/esm2022/performance/instances/instance.mjs +0 -48
  288. package/esm2022/performance/instances/instances.mjs +0 -189
  289. package/esm2022/performance/instances/position-mesh.mjs +0 -52
  290. package/esm2022/performance/stats/stats.mjs +0 -79
  291. package/esm2022/shaders/caustics-material/caustics-material.mjs +0 -128
  292. package/esm2022/shaders/caustics-material/caustics-projection-material.mjs +0 -33
  293. package/esm2022/staging/caustics/caustisc.mjs +0 -384
  294. package/esm2022/staging/spot-light/spot-light-shadow-mesh-input.mjs +0 -57
  295. package/esm2022/staging/spot-light/spot-light-shadow-mesh.mjs +0 -256
  296. package/fesm2022/angular-three-soba-performance.mjs +0 -487
  297. package/fesm2022/angular-three-soba-performance.mjs.map +0 -1
  298. package/performance/README.md +0 -3
  299. package/performance/adaptive/adaptive-dpr.d.ts +0 -8
  300. package/performance/detailed/detailed.d.ts +0 -20
  301. package/performance/index.d.ts +0 -6
  302. package/performance/instances/instance.d.ts +0 -9
  303. package/performance/instances/instances.d.ts +0 -35
  304. package/performance/stats/stats.d.ts +0 -18
  305. package/plugin/generators.json +0 -19
  306. package/plugin/libs/plugin/README.md +0 -11
  307. package/plugin/package.json +0 -9
  308. package/plugin/src/generators/init/compat.d.ts +0 -2
  309. package/plugin/src/generators/init/compat.js +0 -6
  310. package/plugin/src/generators/init/compat.js.map +0 -1
  311. package/plugin/src/generators/init/init.d.ts +0 -7
  312. package/plugin/src/generators/init/init.js +0 -28
  313. package/plugin/src/generators/init/init.js.map +0 -1
  314. package/plugin/src/generators/init/schema.json +0 -6
  315. package/plugin/src/index.d.ts +0 -1
  316. package/plugin/src/index.js +0 -6
  317. package/plugin/src/index.js.map +0 -1
  318. package/staging/caustics/caustisc.d.ts +0 -70
  319. package/staging/spot-light/spot-light-shadow-mesh-input.d.ts +0 -29
  320. package/staging/spot-light/spot-light-shadow-mesh.d.ts +0 -38
  321. /package/{abstractions → gizmos}/gizmo-helper/gizmo-viewcube/constants.d.ts +0 -0
  322. /package/shaders/{caustics-material → caustics}/caustics-material.d.ts +0 -0
  323. /package/shaders/{caustics-material → caustics}/caustics-projection-material.d.ts +0 -0
@@ -1,10 +1,27 @@
1
1
  import * as i0 from '@angular/core';
2
- import { runInInjectionContext, inject, DestroyRef, effect, Directive, ChangeDetectorRef, signal, computed, untracked } from '@angular/core';
3
- import { assertInjectionContext, injectNgtRef, injectBeforeRender, NgtStore, safeDetectChanges } from 'angular-three';
2
+ import { runInInjectionContext, computed, effect, Directive, inject, ChangeDetectorRef, signal, DestroyRef, untracked, Component, CUSTOM_ELEMENTS_SCHEMA, Input, forwardRef, ViewContainerRef, ViewChild, EventEmitter, TemplateRef, ContentChild, Output } from '@angular/core';
3
+ import { injectNgtRef, injectBeforeRender, injectNgtStore, safeDetectChanges, extend, signalStore, is, applyProps, HTML, checkUpdate, NgtArgs, addEffect, addAfterEffect, NgtPortal, NgtPortalContent } from 'angular-three';
4
+ import { assertInjector } from 'ngxtension/assert-injector';
4
5
  import * as THREE from 'three';
6
+ import { Group, Scene, Mesh, PlaneGeometry, OrthographicCamera, LineBasicMaterial, BoxGeometry, MeshNormalMaterial, AxesHelper, MeshStandardMaterial, ShaderMaterial, CanvasTexture, MeshBasicMaterial, Texture } from 'three';
7
+ import { NgIf, DOCUMENT, NgTemplateOutlet } from '@angular/common';
8
+ import { NgtsEdges, NgtsText3D } from 'angular-three-soba/abstractions';
9
+ import { CausticsProjectionMaterial, CausticsMaterial } from 'angular-three-soba/shaders';
10
+ import { NgtsSobaContent } from 'angular-three-soba/utils';
11
+ import { FullScreenQuad, DecalGeometry, MeshSurfaceSampler } from 'three-stdlib';
12
+ import { NgtsCenter } from 'angular-three-soba/staging';
13
+ import { createInjectionToken } from 'ngxtension/create-injection-token';
14
+ import Stats from 'stats-gl';
15
+ import { MeshLineGeometry, MeshLineMaterial } from 'meshline';
5
16
 
6
- function injectNgtsAnimations(animationsFactory, { ref, injector } = {}) {
7
- injector = assertInjectionContext(injectNgtsAnimations, injector);
17
+ function injectNgtsAnimations(animationsFactory, { ref, injector, playFirstClip = true, } = {}) {
18
+ injector = assertInjector(injectNgtsAnimations, injector);
19
+ const mixer = new THREE.AnimationMixer(null);
20
+ const actions = {};
21
+ let cached = {};
22
+ let object = null;
23
+ const names = [];
24
+ const clips = [];
8
25
  return runInInjectionContext(injector, () => {
9
26
  let actualRef = injectNgtRef();
10
27
  if (ref) {
@@ -15,26 +32,13 @@ function injectNgtsAnimations(animationsFactory, { ref, injector } = {}) {
15
32
  actualRef = ref;
16
33
  }
17
34
  }
18
- const mixer = new THREE.AnimationMixer(null);
19
- const actions = {};
20
- let cached = {};
21
- const clips = [];
22
- const names = [];
23
- inject(DestroyRef).onDestroy(() => {
24
- // clear cached
25
- cached = {};
26
- // uncache actions
27
- Object.values(actions).forEach((action) => {
28
- mixer.uncacheAction(action, actualRef.untracked);
29
- });
30
- // stop all actions
31
- mixer.stopAllAction();
32
- });
33
35
  injectBeforeRender(({ delta }) => mixer.update(delta));
34
- effect(() => {
36
+ const ready = computed(() => !!actualRef.nativeElement && !!animationsFactory().length);
37
+ effect((onCleanup) => {
35
38
  const actual = actualRef.nativeElement;
36
39
  if (!actual)
37
40
  return;
41
+ object = actual;
38
42
  const animations = animationsFactory();
39
43
  for (let i = 0; i < animations.length; i++) {
40
44
  const clip = animations[i];
@@ -46,124 +50,2223 @@ function injectNgtsAnimations(animationsFactory, { ref, injector } = {}) {
46
50
  return cached[clip.name] || (cached[clip.name] = mixer.clipAction(clip, actual));
47
51
  },
48
52
  });
49
- if (i === 0) {
53
+ if (i === 0 && playFirstClip) {
50
54
  actions[clip.name].play();
51
55
  }
52
56
  }
57
+ onCleanup(() => {
58
+ // clear cached
59
+ cached = {};
60
+ // stop all actions
61
+ mixer.stopAllAction();
62
+ // uncache actions
63
+ Object.values(actions).forEach((action) => {
64
+ mixer.uncacheAction(action, object);
65
+ });
66
+ object = null;
67
+ });
53
68
  });
54
- return { ref: actualRef, actions, mixer, names, clips };
69
+ return { ref: actualRef, actions, mixer, names, clips, ready };
55
70
  });
56
71
  }
57
72
 
58
73
  class NgtsBakeShadows {
59
74
  constructor() {
60
- const store = inject(NgtStore);
61
- const gl = store.select('gl');
75
+ const store = injectNgtStore();
76
+ const glShadowMap = store.select('gl', 'shadowMap');
62
77
  effect((onCleanup) => {
63
- gl().shadowMap.autoUpdate = false;
64
- gl().shadowMap.needsUpdate = true;
78
+ const shadowMap = glShadowMap();
79
+ shadowMap.autoUpdate = false;
80
+ shadowMap.needsUpdate = true;
65
81
  onCleanup(() => {
66
- gl().shadowMap.autoUpdate = gl().shadowMap.needsUpdate = true;
82
+ shadowMap.autoUpdate = shadowMap.needsUpdate = true;
67
83
  });
68
84
  });
69
85
  }
70
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtsBakeShadows, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
71
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: NgtsBakeShadows, isStandalone: true, selector: "ngts-bake-shadows", ngImport: i0 }); }
86
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsBakeShadows, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
87
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.3", type: NgtsBakeShadows, isStandalone: true, selector: "ngts-bake-shadows", ngImport: i0 }); }
72
88
  }
73
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtsBakeShadows, decorators: [{
89
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsBakeShadows, decorators: [{
74
90
  type: Directive,
75
91
  args: [{ selector: 'ngts-bake-shadows', standalone: true }]
76
92
  }], ctorParameters: function () { return []; } });
77
93
 
78
94
  function injectNgtsFBO(fboParams, { injector } = {}) {
79
- injector = assertInjectionContext(injectNgtsFBO, injector);
95
+ injector = assertInjector(injectNgtsFBO, injector);
80
96
  return runInInjectionContext(injector, () => {
81
- const store = inject(NgtStore);
97
+ const store = injectNgtStore();
82
98
  const cdr = inject(ChangeDetectorRef);
83
- const targetRef = signal(null);
84
- inject(DestroyRef).onDestroy(() => targetRef().dispose());
85
- requestAnimationFrame(() => {
86
- const size = store.select('size');
87
- const dpr = store.select('viewport', 'dpr');
88
- const trigger = computed(() => {
89
- const { width, height, settings } = fboParams();
90
- const _width = typeof width === 'number' ? width : size().width * dpr();
91
- const _height = typeof height === 'number' ? height : size().height * dpr();
92
- const _settings = (typeof width === 'number' ? settings : width) || {};
93
- return { width: _width, height: _height, settings: _settings };
94
- });
95
- effect(() => {
96
- const { width, height, settings } = trigger();
97
- const { samples = 0, depth, ...targetSettings } = settings;
98
- let untrackedTarget = untracked(targetRef);
99
- if (!untrackedTarget) {
100
- const target = new THREE.WebGLRenderTarget(width, height, {
101
- minFilter: THREE.LinearFilter,
102
- magFilter: THREE.LinearFilter,
103
- type: THREE.HalfFloatType,
104
- ...targetSettings,
105
- });
106
- if (depth)
107
- target.depthTexture = new THREE.DepthTexture(width, height, THREE.FloatType);
108
- target.samples = samples;
109
- targetRef.set(target);
110
- untrackedTarget = untracked(targetRef);
111
- }
99
+ const targetSignal = signal(null);
100
+ inject(DestroyRef).onDestroy(() => targetSignal()?.dispose());
101
+ const [defaultWidth, defaultHeight, dpr] = [
102
+ store.select('size', 'width'),
103
+ store.select('size', 'height'),
104
+ store.select('viewport', 'dpr'),
105
+ ];
106
+ const fboSettings = computed(() => {
107
+ const { width, height, settings } = fboParams();
108
+ return [
109
+ typeof width === 'number' ? width : defaultWidth() * dpr(),
110
+ typeof height === 'number' ? height : defaultHeight() * dpr(),
111
+ (typeof width === 'number' ? settings : width) || {},
112
+ ];
113
+ });
114
+ effect(() => {
115
+ const [width, height, { samples = 0, depth, ...settings }] = fboSettings();
116
+ let untrackedTarget = untracked(targetSignal);
117
+ if (!untrackedTarget) {
118
+ const target = new THREE.WebGLRenderTarget(width, height, {
119
+ minFilter: THREE.LinearFilter,
120
+ magFilter: THREE.LinearFilter,
121
+ type: THREE.HalfFloatType,
122
+ ...settings,
123
+ });
124
+ if (depth)
125
+ target.depthTexture = new THREE.DepthTexture(width, height, THREE.FloatType);
126
+ target.samples = samples;
127
+ untracked(() => {
128
+ targetSignal.set(target);
129
+ });
130
+ untrackedTarget = untracked(targetSignal);
131
+ }
132
+ if (untrackedTarget) {
112
133
  untrackedTarget.setSize(width, height);
113
134
  if (samples)
114
135
  untrackedTarget.samples = samples;
115
136
  safeDetectChanges(cdr);
116
- }, { allowSignalWrites: true, injector });
137
+ }
117
138
  });
118
- return targetRef.asReadonly();
139
+ return targetSignal.asReadonly();
140
+ });
141
+ }
142
+
143
+ extend({ Group, Scene, Mesh, PlaneGeometry, OrthographicCamera, CausticsProjectionMaterial, LineBasicMaterial });
144
+ const NORMALPROPS = {
145
+ depth: true,
146
+ minFilter: THREE.LinearFilter,
147
+ magFilter: THREE.LinearFilter,
148
+ type: THREE.UnsignedByteType,
149
+ };
150
+ const CAUSTICPROPS = {
151
+ minFilter: THREE.LinearMipmapLinearFilter,
152
+ magFilter: THREE.LinearFilter,
153
+ type: THREE.FloatType,
154
+ generateMipmaps: true,
155
+ };
156
+ function createNormalMaterial(side = THREE.FrontSide) {
157
+ const viewMatrix = { value: new THREE.Matrix4() };
158
+ return Object.assign(new THREE.MeshNormalMaterial({ side }), {
159
+ viewMatrix,
160
+ onBeforeCompile: (shader) => {
161
+ shader.uniforms.viewMatrix = viewMatrix;
162
+ shader.fragmentShader =
163
+ `vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
164
+ return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
165
+ }\n` +
166
+ shader.fragmentShader.replace('#include <normal_fragment_maps>', `#include <normal_fragment_maps>
167
+ normal = inverseTransformDirection( normal, viewMatrix );\n`);
168
+ },
119
169
  });
120
170
  }
171
+ class NgtsCaustics {
172
+ /** How many frames it will render, set it to Infinity for runtime, default: 1 */
173
+ set _frames(frames) {
174
+ this.inputs.set({ frames });
175
+ }
176
+ /** Enables visual cues to help you stage your scene, default: false */
177
+ set _debug(debug) {
178
+ this.inputs.set({ debug });
179
+ }
180
+ /** Will display caustics only and skip the models, default: false */
181
+ set _causticsOnly(causticsOnly) {
182
+ this.inputs.set({ causticsOnly });
183
+ }
184
+ /** Will include back faces and enable the backsideIOR prop, default: false */
185
+ set _backside(backside) {
186
+ this.inputs.set({ backside });
187
+ }
188
+ /** The IOR refraction index, default: 1.1 */
189
+ set _ior(ior) {
190
+ this.inputs.set({ ior });
191
+ }
192
+ /** The IOR refraction index for back faces (only available when backside is enabled), default: 1.1 */
193
+ set _backsideIOR(backsideIOR) {
194
+ this.inputs.set({ backsideIOR });
195
+ }
196
+ /** The texel size, default: 0.3125 */
197
+ set _worldRadius(worldRadius) {
198
+ this.inputs.set({ worldRadius });
199
+ }
200
+ /** Intensity of the prjected caustics, default: 0.05 */
201
+ set _intensity(intensity) {
202
+ this.inputs.set({ intensity });
203
+ }
204
+ /** Caustics color, default: white */
205
+ set _color(color) {
206
+ this.inputs.set({ color });
207
+ }
208
+ /** Buffer resolution, default: 2048 */
209
+ set _resolution(resolution) {
210
+ this.inputs.set({ resolution });
211
+ }
212
+ /** Camera position, it will point towards the contents bounds center, default: [5, 5, 5] */
213
+ set _lightSource(lightSource) {
214
+ this.inputs.set({ lightSource });
215
+ }
216
+ constructor() {
217
+ this.CustomBlending = THREE.CustomBlending;
218
+ this.OneFactor = THREE.OneFactor;
219
+ this.SrcAlphaFactor = THREE.SrcAlphaFactor;
220
+ this.Math = Math;
221
+ this.inputs = signalStore({
222
+ frames: 1,
223
+ ior: 1.1,
224
+ color: 'white',
225
+ causticsOnly: false,
226
+ backside: false,
227
+ backsideIOR: 1.1,
228
+ worldRadius: 0.3125,
229
+ intensity: 0.05,
230
+ resolution: 2024,
231
+ lightSource: [5, 5, 5],
232
+ });
233
+ this.causticsRef = injectNgtRef();
234
+ this.resolution = this.inputs.select('resolution');
235
+ this.normalTargetSettings = computed(() => ({
236
+ width: this.resolution(),
237
+ height: this.resolution(),
238
+ settings: NORMALPROPS,
239
+ }));
240
+ this.causticsTargetSettings = computed(() => ({
241
+ width: this.resolution(),
242
+ height: this.resolution(),
243
+ settings: CAUSTICPROPS,
244
+ }));
245
+ this.normalTargetFbo = injectNgtsFBO(this.normalTargetSettings);
246
+ this.normalTargetBFbo = injectNgtsFBO(this.normalTargetSettings);
247
+ this.causticsTargetFbo = injectNgtsFBO(this.causticsTargetSettings);
248
+ this.causticsTargetBFbo = injectNgtsFBO(this.causticsTargetSettings);
249
+ this.store = injectNgtStore();
250
+ this.color = this.inputs.select('color');
251
+ this.debug = this.inputs.select('debug');
252
+ this.planeRef = injectNgtRef();
253
+ this.sceneRef = injectNgtRef();
254
+ this.cameraRef = injectNgtRef();
255
+ this.sceneChildren = this.sceneRef.children();
256
+ this.planeChildren = this.planeRef.children('both');
257
+ this.causticsChildren = this.causticsRef.children();
258
+ this.updateWorldMatrix();
259
+ this.setBeforeRender();
260
+ }
261
+ updateWorldMatrix() {
262
+ effect(() => {
263
+ const [caustics] = [
264
+ this.causticsRef.nativeElement,
265
+ this.inputs.state(),
266
+ this.causticsChildren(),
267
+ this.sceneChildren(),
268
+ ];
269
+ if (!caustics)
270
+ return;
271
+ caustics.updateWorldMatrix(false, true);
272
+ });
273
+ }
274
+ setBeforeRender() {
275
+ const causticsMaterial = new CausticsMaterial();
276
+ const causticsQuad = new FullScreenQuad(causticsMaterial);
277
+ const normalMaterial = createNormalMaterial();
278
+ const normalMaterialB = createNormalMaterial(THREE.BackSide);
279
+ effect((onCleanup) => {
280
+ const [caustics, scene, camera, normalTarget, normalTargetB, causticsTarget, causticsTargetB, plane, sceneChildren,] = [
281
+ this.causticsRef.nativeElement,
282
+ this.sceneRef.nativeElement,
283
+ this.cameraRef.nativeElement,
284
+ this.normalTargetFbo(),
285
+ this.normalTargetBFbo(),
286
+ this.causticsTargetFbo(),
287
+ this.causticsTargetBFbo(),
288
+ this.planeRef.nativeElement,
289
+ this.sceneChildren(),
290
+ this.planeChildren(),
291
+ ];
292
+ if (!caustics)
293
+ return;
294
+ caustics.updateWorldMatrix(false, true);
295
+ if (sceneChildren.length > 1) {
296
+ const v = new THREE.Vector3();
297
+ const lpF = new THREE.Frustum();
298
+ const lpM = new THREE.Matrix4();
299
+ const lpP = new THREE.Plane();
300
+ const lightDir = new THREE.Vector3();
301
+ const lightDirInv = new THREE.Vector3();
302
+ const bounds = new THREE.Box3();
303
+ const focusPos = new THREE.Vector3();
304
+ let count = 0;
305
+ const sub = this.store.get('internal').subscribe(({ gl }) => {
306
+ const { frames, lightSource, resolution, worldRadius, intensity, backside, backsideIOR, ior, causticsOnly, } = this.inputs.get();
307
+ if (frames === Infinity || count++ < frames) {
308
+ if (Array.isArray(lightSource))
309
+ lightDir.fromArray(lightSource).normalize();
310
+ else
311
+ lightDir.copy(caustics.worldToLocal(lightSource.nativeElement.getWorldPosition(v)).normalize());
312
+ lightDirInv.copy(lightDir).multiplyScalar(-1);
313
+ let boundsVertices = [];
314
+ scene.parent?.matrixWorld.identity();
315
+ bounds.setFromObject(scene, true);
316
+ boundsVertices.push(new THREE.Vector3(bounds.min.x, bounds.min.y, bounds.min.z));
317
+ boundsVertices.push(new THREE.Vector3(bounds.min.x, bounds.min.y, bounds.max.z));
318
+ boundsVertices.push(new THREE.Vector3(bounds.min.x, bounds.max.y, bounds.min.z));
319
+ boundsVertices.push(new THREE.Vector3(bounds.min.x, bounds.max.y, bounds.max.z));
320
+ boundsVertices.push(new THREE.Vector3(bounds.max.x, bounds.min.y, bounds.min.z));
321
+ boundsVertices.push(new THREE.Vector3(bounds.max.x, bounds.min.y, bounds.max.z));
322
+ boundsVertices.push(new THREE.Vector3(bounds.max.x, bounds.max.y, bounds.min.z));
323
+ boundsVertices.push(new THREE.Vector3(bounds.max.x, bounds.max.y, bounds.max.z));
324
+ const worldVerts = boundsVertices.map((v) => v.clone());
325
+ bounds.getCenter(focusPos);
326
+ boundsVertices = boundsVertices.map((v) => v.clone().sub(focusPos));
327
+ const lightPlane = lpP.set(lightDirInv, 0);
328
+ const projectedVerts = boundsVertices.map((v) => lightPlane.projectPoint(v, new THREE.Vector3()));
329
+ const centralVert = projectedVerts
330
+ .reduce((a, b) => a.add(b), v.set(0, 0, 0))
331
+ .divideScalar(projectedVerts.length);
332
+ const radius = projectedVerts
333
+ .map((v) => v.distanceTo(centralVert))
334
+ .reduce((a, b) => Math.max(a, b));
335
+ const dirLength = boundsVertices.map((x) => x.dot(lightDir)).reduce((a, b) => Math.max(a, b));
336
+ // Shadows
337
+ camera.position.copy(lightDir.clone().multiplyScalar(dirLength).add(focusPos));
338
+ camera.lookAt(scene.localToWorld(focusPos.clone()));
339
+ const dirMatrix = lpM.lookAt(camera.position, focusPos, v.set(0, 1, 0));
340
+ camera.left = -radius;
341
+ camera.right = radius;
342
+ camera.top = radius;
343
+ camera.bottom = -radius;
344
+ const yOffset = v.set(0, radius, 0).applyMatrix4(dirMatrix);
345
+ const yTime = (camera.position.y + yOffset.y) / lightDir.y;
346
+ camera.near = 0.1;
347
+ camera.far = yTime;
348
+ camera.updateProjectionMatrix();
349
+ camera.updateMatrixWorld();
350
+ // Now find size of ground plane
351
+ const groundProjectedCoords = worldVerts.map((v) => v.add(lightDir.clone().multiplyScalar(-v.y / lightDir.y)));
352
+ const centerPos = groundProjectedCoords
353
+ .reduce((a, b) => a.add(b), v.set(0, 0, 0))
354
+ .divideScalar(groundProjectedCoords.length);
355
+ const maxSize = 2 *
356
+ groundProjectedCoords
357
+ .map((v) => Math.hypot(v.x - centerPos.x, v.z - centerPos.z))
358
+ .reduce((a, b) => Math.max(a, b));
359
+ plane.scale.setScalar(maxSize);
360
+ plane.position.copy(centerPos);
361
+ // if (debug) helper.current?.update();
362
+ // Inject uniforms
363
+ normalMaterialB.viewMatrix.value = normalMaterial.viewMatrix.value = camera.matrixWorldInverse;
364
+ const dirLightNearPlane = lpF.setFromProjectionMatrix(lpM.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse)).planes[4];
365
+ causticsMaterial.cameraMatrixWorld = camera.matrixWorld;
366
+ causticsMaterial.cameraProjectionMatrixInv = camera.projectionMatrixInverse;
367
+ causticsMaterial.lightDir = lightDirInv;
368
+ causticsMaterial.lightPlaneNormal = dirLightNearPlane.normal;
369
+ causticsMaterial.lightPlaneConstant = dirLightNearPlane.constant;
370
+ causticsMaterial.near = camera.near;
371
+ causticsMaterial.far = camera.far;
372
+ causticsMaterial.resolution = resolution;
373
+ causticsMaterial.size = radius;
374
+ causticsMaterial.intensity = intensity;
375
+ causticsMaterial.worldRadius = worldRadius;
376
+ // Switch the scene on
377
+ scene.visible = true;
378
+ // Render front face normals
379
+ gl.setRenderTarget(normalTarget);
380
+ gl.clear();
381
+ scene.overrideMaterial = normalMaterial;
382
+ gl.render(scene, camera);
383
+ // Render back face normals, if enabled
384
+ gl.setRenderTarget(normalTargetB);
385
+ gl.clear();
386
+ if (backside) {
387
+ scene.overrideMaterial = normalMaterialB;
388
+ gl.render(scene, camera);
389
+ }
390
+ // Remove the override material
391
+ scene.overrideMaterial = null;
392
+ // Render front face caustics
393
+ causticsMaterial.ior = ior;
394
+ plane.material.lightProjMatrix = camera.projectionMatrix;
395
+ plane.material.lightViewMatrix = camera.matrixWorldInverse;
396
+ causticsMaterial.normalTexture = normalTarget?.texture;
397
+ causticsMaterial.depthTexture = normalTarget?.depthTexture;
398
+ gl.setRenderTarget(causticsTarget);
399
+ gl.clear();
400
+ causticsQuad.render(gl);
401
+ // Render back face caustics, if enabled
402
+ causticsMaterial.ior = backsideIOR;
403
+ causticsMaterial.normalTexture = normalTargetB?.texture;
404
+ causticsMaterial.depthTexture = normalTargetB?.depthTexture;
405
+ gl.setRenderTarget(causticsTargetB);
406
+ gl.clear();
407
+ if (backside)
408
+ causticsQuad.render(gl);
409
+ // Reset render target
410
+ gl.setRenderTarget(null);
411
+ // Switch the scene off if caustics is all that's wanted
412
+ if (causticsOnly)
413
+ scene.visible = false;
414
+ }
415
+ });
416
+ onCleanup(() => sub());
417
+ }
418
+ });
419
+ }
420
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsCaustics, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
421
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: NgtsCaustics, isStandalone: true, selector: "ngts-caustics", inputs: { causticsRef: "causticsRef", _frames: ["frames", "_frames"], _debug: ["debug", "_debug"], _causticsOnly: ["causticsOnly", "_causticsOnly"], _backside: ["backside", "_backside"], _ior: ["ior", "_ior"], _backsideIOR: ["backsideIOR", "_backsideIOR"], _worldRadius: ["worldRadius", "_worldRadius"], _intensity: ["intensity", "_intensity"], _color: ["color", "_color"], _resolution: ["resolution", "_resolution"], _lightSource: ["lightSource", "_lightSource"] }, ngImport: i0, template: `
422
+ <ngt-group [ref]="causticsRef" ngtCompound>
423
+ <ngt-scene [ref]="sceneRef">
424
+ <ngt-orthographic-camera [ref]="cameraRef" [up]="[0, 1, 0]" />
425
+ <ng-content />
426
+ </ngt-scene>
427
+ <ngt-mesh [renderOrder]="2" [ref]="planeRef" [rotation]="[-Math.PI / 2, 0, 0]">
428
+ <ngt-plane-geometry />
429
+ <ngt-caustics-projection-material
430
+ *ngIf="causticsTargetFbo() && causticsTargetBFbo()"
431
+ [transparent]="true"
432
+ [color]="color()"
433
+ [causticsTexture]="causticsTargetFbo()!.texture"
434
+ [causticsTextureB]="causticsTargetBFbo()!.texture"
435
+ [blending]="CustomBlending"
436
+ [blendSrc]="OneFactor"
437
+ [blendDst]="SrcAlphaFactor"
438
+ [depthWrite]="false"
439
+ />
440
+
441
+ <ngts-edges *ngIf="debug()">
442
+ <ngt-line-basic-material *ngtsSobaContent color="#ffff00" [toneMapped]="false" />
443
+ </ngts-edges>
444
+ </ngt-mesh>
445
+ </ngt-group>
446
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: NgtsEdges, selector: "ngts-edges", inputs: ["edgesRef", "threshold", "color", "geometry", "userData"] }, { kind: "directive", type: NgtsSobaContent, selector: "ng-template[ngtsSobaContent]", exportAs: ["sobaContent"] }] }); }
447
+ }
448
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsCaustics, decorators: [{
449
+ type: Component,
450
+ args: [{
451
+ selector: 'ngts-caustics',
452
+ standalone: true,
453
+ template: `
454
+ <ngt-group [ref]="causticsRef" ngtCompound>
455
+ <ngt-scene [ref]="sceneRef">
456
+ <ngt-orthographic-camera [ref]="cameraRef" [up]="[0, 1, 0]" />
457
+ <ng-content />
458
+ </ngt-scene>
459
+ <ngt-mesh [renderOrder]="2" [ref]="planeRef" [rotation]="[-Math.PI / 2, 0, 0]">
460
+ <ngt-plane-geometry />
461
+ <ngt-caustics-projection-material
462
+ *ngIf="causticsTargetFbo() && causticsTargetBFbo()"
463
+ [transparent]="true"
464
+ [color]="color()"
465
+ [causticsTexture]="causticsTargetFbo()!.texture"
466
+ [causticsTextureB]="causticsTargetBFbo()!.texture"
467
+ [blending]="CustomBlending"
468
+ [blendSrc]="OneFactor"
469
+ [blendDst]="SrcAlphaFactor"
470
+ [depthWrite]="false"
471
+ />
472
+
473
+ <ngts-edges *ngIf="debug()">
474
+ <ngt-line-basic-material *ngtsSobaContent color="#ffff00" [toneMapped]="false" />
475
+ </ngts-edges>
476
+ </ngt-mesh>
477
+ </ngt-group>
478
+ `,
479
+ imports: [NgIf, NgtsEdges, NgtsSobaContent],
480
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
481
+ }]
482
+ }], ctorParameters: function () { return []; }, propDecorators: { causticsRef: [{
483
+ type: Input
484
+ }], _frames: [{
485
+ type: Input,
486
+ args: [{ alias: 'frames' }]
487
+ }], _debug: [{
488
+ type: Input,
489
+ args: [{ alias: 'debug' }]
490
+ }], _causticsOnly: [{
491
+ type: Input,
492
+ args: [{ alias: 'causticsOnly' }]
493
+ }], _backside: [{
494
+ type: Input,
495
+ args: [{ alias: 'backside' }]
496
+ }], _ior: [{
497
+ type: Input,
498
+ args: [{ alias: 'ior' }]
499
+ }], _backsideIOR: [{
500
+ type: Input,
501
+ args: [{ alias: 'backsideIOR' }]
502
+ }], _worldRadius: [{
503
+ type: Input,
504
+ args: [{ alias: 'worldRadius' }]
505
+ }], _intensity: [{
506
+ type: Input,
507
+ args: [{ alias: 'intensity' }]
508
+ }], _color: [{
509
+ type: Input,
510
+ args: [{ alias: 'color' }]
511
+ }], _resolution: [{
512
+ type: Input,
513
+ args: [{ alias: 'resolution' }]
514
+ }], _lightSource: [{
515
+ type: Input,
516
+ args: [{ alias: 'lightSource' }]
517
+ }] } });
518
+
519
+ extend({ Mesh, BoxGeometry, MeshNormalMaterial, AxesHelper });
520
+ function vecToArray(vec = [0, 0, 0]) {
521
+ if (Array.isArray(vec)) {
522
+ return vec;
523
+ }
524
+ if (vec instanceof THREE.Vector3 || vec instanceof THREE.Euler) {
525
+ return [vec.x, vec.y, vec.z];
526
+ }
527
+ return [vec, vec, vec];
528
+ }
529
+ class NgtsDecal {
530
+ set _debug(debug) {
531
+ this.inputs.set({ debug });
532
+ }
533
+ set _mesh(mesh) {
534
+ this.inputs.set({ mesh });
535
+ }
536
+ set _position(position) {
537
+ this.inputs.set({ position });
538
+ }
539
+ set _rotation(rotation) {
540
+ this.inputs.set({ rotation });
541
+ }
542
+ set _scale(scale) {
543
+ this.inputs.set({ scale });
544
+ }
545
+ set _map(map) {
546
+ this.inputs.set({ map });
547
+ }
548
+ set _polygonOffsetFactor(polygonOffsetFactor) {
549
+ this.inputs.set({ polygonOffsetFactor });
550
+ }
551
+ set _depthTest(depthTest) {
552
+ this.inputs.set({ depthTest });
553
+ }
554
+ constructor() {
555
+ this.inputs = signalStore({
556
+ debug: false,
557
+ depthTest: false,
558
+ polygonOffsetFactor: -10,
559
+ position: [0, 0, 0],
560
+ rotation: [0, 0, 0],
561
+ scale: 1,
562
+ });
563
+ this.decalRef = injectNgtRef();
564
+ this.mesh = this.inputs.select('mesh');
565
+ this.__position = this.inputs.select('position');
566
+ this.__rotation = this.inputs.select('rotation');
567
+ this.__scale = this.inputs.select('scale');
568
+ this.position = computed(() => vecToArray(this.__position()));
569
+ this.rotation = computed(() => vecToArray(this.__rotation()));
570
+ this.scale = computed(() => vecToArray(this.__scale()));
571
+ this.helperRef = injectNgtRef();
572
+ this.debug = this.inputs.select('debug');
573
+ this.depthTest = this.inputs.select('depthTest');
574
+ this.polygonOffsetFactor = this.inputs.select('polygonOffsetFactor');
575
+ this.map = this.inputs.select('map');
576
+ this.processDecal();
577
+ }
578
+ processDecal() {
579
+ effect((onCleanup) => {
580
+ const decal = this.decalRef.nativeElement;
581
+ if (!decal)
582
+ return;
583
+ const [mesh, position, rotation, scale, helper] = [
584
+ this.mesh(),
585
+ this.position(),
586
+ this.rotation(),
587
+ this.scale(),
588
+ this.helperRef.nativeElement,
589
+ ];
590
+ const parent = mesh ? (is.ref(mesh) ? mesh.nativeElement : mesh) : decal.parent;
591
+ if (!(parent instanceof Mesh)) {
592
+ throw new Error('[NGT] ngts-decal must have a ngt-mesh as parent or specify its "mesh" input');
593
+ }
594
+ const state = {
595
+ position: new THREE.Vector3(),
596
+ rotation: new THREE.Euler(),
597
+ scale: new THREE.Vector3(1, 1, 1),
598
+ };
599
+ if (parent) {
600
+ applyProps(state, { position, scale });
601
+ // Zero out the parents matrix world for this operation
602
+ const matrixWorld = parent.matrixWorld.clone();
603
+ parent.matrixWorld.identity();
604
+ if (!rotation || typeof rotation === 'number') {
605
+ const o = new THREE.Object3D();
606
+ o.position.copy(state.position);
607
+ o.lookAt(parent.position);
608
+ if (typeof rotation === 'number')
609
+ o.rotateZ(rotation);
610
+ applyProps(state, { rotation: o.rotation });
611
+ }
612
+ else {
613
+ applyProps(state, { rotation });
614
+ }
615
+ decal.geometry = new DecalGeometry(parent, state.position, state.rotation, state.scale);
616
+ if (helper) {
617
+ applyProps(helper, state);
618
+ // Prevent the helpers from blocking rays
619
+ helper.traverse((child) => (child.raycast = () => null));
620
+ }
621
+ // Reset parents matix-world
622
+ parent.matrixWorld = matrixWorld;
623
+ onCleanup(() => {
624
+ decal.geometry.dispose();
625
+ });
626
+ }
627
+ });
628
+ }
629
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsDecal, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
630
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: NgtsDecal, isStandalone: true, selector: "ngts-decal", inputs: { decalRef: "decalRef", _debug: ["debug", "_debug"], _mesh: ["mesh", "_mesh"], _position: ["position", "_position"], _rotation: ["rotation", "_rotation"], _scale: ["scale", "_scale"], _map: ["map", "_map"], _polygonOffsetFactor: ["polygonOffsetFactor", "_polygonOffsetFactor"], _depthTest: ["depthTest", "_depthTest"] }, ngImport: i0, template: `
631
+ <ngt-mesh [ref]="decalRef" ngtCompound>
632
+ <ngt-value [rawValue]="true" attach="material.transparent" />
633
+ <ngt-value [rawValue]="true" attach="material.polygonOffset" />
634
+ <ngt-value [rawValue]="polygonOffsetFactor()" attach="material.polygonOffsetFactor" />
635
+ <ngt-value [rawValue]="depthTest()" attach="material.depthTest" />
636
+ <ngt-value [rawValue]="map()" attach="material.map" />
637
+ <ng-content />
638
+
639
+ <ngt-mesh *ngIf="debug()" [ref]="helperRef">
640
+ <ngt-box-geometry />
641
+ <ngt-mesh-normal-material [wireframe]="true" />
642
+ <ngt-axes-helper />
643
+ </ngt-mesh>
644
+ </ngt-mesh>
645
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
646
+ }
647
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsDecal, decorators: [{
648
+ type: Component,
649
+ args: [{
650
+ selector: 'ngts-decal',
651
+ standalone: true,
652
+ template: `
653
+ <ngt-mesh [ref]="decalRef" ngtCompound>
654
+ <ngt-value [rawValue]="true" attach="material.transparent" />
655
+ <ngt-value [rawValue]="true" attach="material.polygonOffset" />
656
+ <ngt-value [rawValue]="polygonOffsetFactor()" attach="material.polygonOffsetFactor" />
657
+ <ngt-value [rawValue]="depthTest()" attach="material.depthTest" />
658
+ <ngt-value [rawValue]="map()" attach="material.map" />
659
+ <ng-content />
660
+
661
+ <ngt-mesh *ngIf="debug()" [ref]="helperRef">
662
+ <ngt-box-geometry />
663
+ <ngt-mesh-normal-material [wireframe]="true" />
664
+ <ngt-axes-helper />
665
+ </ngt-mesh>
666
+ </ngt-mesh>
667
+ `,
668
+ imports: [NgIf],
669
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
670
+ }]
671
+ }], ctorParameters: function () { return []; }, propDecorators: { decalRef: [{
672
+ type: Input
673
+ }], _debug: [{
674
+ type: Input,
675
+ args: [{ alias: 'debug' }]
676
+ }], _mesh: [{
677
+ type: Input,
678
+ args: [{ alias: 'mesh' }]
679
+ }], _position: [{
680
+ type: Input,
681
+ args: [{ alias: 'position' }]
682
+ }], _rotation: [{
683
+ type: Input,
684
+ args: [{ alias: 'rotation' }]
685
+ }], _scale: [{
686
+ type: Input,
687
+ args: [{ alias: 'scale' }]
688
+ }], _map: [{
689
+ type: Input,
690
+ args: [{ alias: 'map' }]
691
+ }], _polygonOffsetFactor: [{
692
+ type: Input,
693
+ args: [{ alias: 'polygonOffsetFactor' }]
694
+ }], _depthTest: [{
695
+ type: Input,
696
+ args: [{ alias: 'depthTest' }]
697
+ }] } });
121
698
 
122
699
  function injectNgtsDepthBuffer(paramsFactory = () => ({}), { injector } = {}) {
123
- injector = assertInjectionContext(injectNgtsDepthBuffer, injector);
700
+ injector = assertInjector(injectNgtsDepthBuffer, injector);
124
701
  return runInInjectionContext(injector, () => {
125
- const depthBufferRef = signal(null);
126
- const store = inject(NgtStore);
702
+ const depthBufferSignal = signal(null);
703
+ const store = injectNgtStore();
127
704
  const cdr = inject(ChangeDetectorRef);
128
- const size = store.select('size');
129
- const dpr = store.select('viewport', 'dpr');
130
- requestAnimationFrame(() => {
131
- const fboParams = computed(() => {
132
- const params = { size: 256, frames: Infinity, ...paramsFactory() };
133
- const width = params.size || size().width * dpr();
134
- const height = params.size || size().height * dpr();
135
- const depthTexture = new THREE.DepthTexture(width, height);
136
- depthTexture.format = THREE.DepthFormat;
137
- depthTexture.type = THREE.UnsignedShortType;
138
- return { width, height, settings: { depthTexture } };
705
+ const [defaultWidth, defaultHeight, dpr] = [
706
+ store.select('size', 'width'),
707
+ store.select('size', 'height'),
708
+ store.select('viewport', 'dpr'),
709
+ ];
710
+ const fboParams = computed(() => {
711
+ const params = { size: 256, frames: Infinity, ...paramsFactory() };
712
+ const width = params.size || defaultWidth() * dpr();
713
+ const height = params.size || defaultHeight() * dpr();
714
+ const depthTexture = new THREE.DepthTexture(width, height);
715
+ depthTexture.format = THREE.DepthFormat;
716
+ depthTexture.type = THREE.UnsignedShortType;
717
+ return { width, height, settings: { depthTexture } };
718
+ });
719
+ const _fbo = injectNgtsFBO(fboParams, { injector });
720
+ effect(() => {
721
+ const fbo = _fbo();
722
+ if (fbo) {
723
+ untracked(() => {
724
+ depthBufferSignal.set(fbo.depthTexture);
725
+ });
726
+ safeDetectChanges(cdr);
727
+ }
728
+ });
729
+ let count = 0;
730
+ injectBeforeRender(({ gl, scene, camera }) => {
731
+ const params = { size: 256, frames: Infinity, ...paramsFactory() };
732
+ const fbo = _fbo();
733
+ if ((params.frames === Infinity || count < params.frames) && fbo) {
734
+ gl.setRenderTarget(fbo);
735
+ gl.render(scene, camera);
736
+ gl.setRenderTarget(null);
737
+ count++;
738
+ }
739
+ }, { injector });
740
+ return depthBufferSignal.asReadonly();
741
+ });
742
+ }
743
+
744
+ /**
745
+ * augment HTMLElementTagNameMap with the selector of the component.
746
+ * the type is usually the Inputs' state and the root THREE element
747
+
748
+ declare global {
749
+ interface HTMLElementTagNameMap {
750
+ \/**
751
+ * @extends ngt-group
752
+ *\/
753
+ 'ngts-example': NgtsExampleState & NgtGroup;
754
+ }
755
+ }
756
+
757
+ */
758
+ /**
759
+ * make sure soba's component extends all regular THREE entities that it needs
760
+ */
761
+ extend({ Group, MeshNormalMaterial, MeshStandardMaterial });
762
+ /**
763
+ * We can setup public API for this soba component with createInjectionToken + forwardRef
764
+ * the `example.api` is **usually** a computed property in the component class
765
+ *
766
+ * @see Bounds for example
767
+ */
768
+ const [injectNgtsExampleApi, provideNgtsExampleApi] = createInjectionToken((example) => example.api, { isRoot: false, deps: [forwardRef(() => NgtsExample)] });
769
+ /**
770
+ * @description this component is only for documentation purposes.
771
+ */
772
+ class NgtsExample {
773
+ constructor() {
774
+ /**
775
+ * use signalStore to store inputs with default inputs
776
+ */
777
+ this.inputs = signalStore({ color: '#cbcbcb', bevelSize: 0.04, debug: false });
778
+ /**
779
+ * a soba component usually has a Input for the component ref and this Input always has a default value with injectNgtRef
780
+ */
781
+ this.exampleRef = injectNgtRef();
782
+ /**
783
+ * exposes signals from inputs
784
+ */
785
+ this.bevelSize = this.inputs.select('bevelSize');
786
+ this.font = this.inputs.select('font');
787
+ this.debug = this.inputs.select('debug');
788
+ this.color = this.inputs.select('color');
789
+ /**
790
+ * can have internal state
791
+ */
792
+ this.count = signal(0);
793
+ /**
794
+ * Expose the public API for this soba component
795
+ */
796
+ this.api = computed(() => ({
797
+ bevelSize: this.bevelSize(),
798
+ increment: () => this.count.update((v) => v + 1),
799
+ decrement: () => this.count.update((v) => v - 1),
800
+ }));
801
+ }
802
+ /**
803
+ * setup Input for the Inputs state. Use alias to have an easier time to setup computed
804
+ *
805
+ * @example: this way "private font" and "set _font" won't conflict
806
+ * private font = this.inputs.select('font');
807
+ */
808
+ set _font(font) {
809
+ this.inputs.set({ font });
810
+ }
811
+ set _color(color) {
812
+ this.inputs.set({ color });
813
+ }
814
+ set _debug(debug) {
815
+ this.inputs.set({ debug });
816
+ }
817
+ set _bevelSize(bevelSize) {
818
+ this.inputs.set({ bevelSize });
819
+ }
820
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsExample, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
821
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: NgtsExample, isStandalone: true, selector: "ngts-example", inputs: { exampleRef: "exampleRef", _font: ["font", "_font"], _color: ["color", "_color"], _debug: ["debug", "_debug"], _bevelSize: ["bevelSize", "_bevelSize"] }, providers: [provideNgtsExampleApi()], ngImport: i0, template: `
822
+ <!-- ngtCompound is used by the Renderer to spread props from ngts-example down to ngt-group -->
823
+ <!-- i.e: <ngts-example [position]="[1, 1, 1]" />, [1, 1, 1] will be passed down to ngt-group -->
824
+ <!-- [ref] is used with the Input so that the consumer can pass an external ref and control this internal ngt-group -->
825
+ <ngt-group ngtCompound [ref]="exampleRef">
826
+ <ngts-center [top]="true">
827
+ <ngts-text-3d
828
+ [bevelEnabled]="true"
829
+ [bevelSize]="bevelSize()"
830
+ [font]="font()"
831
+ [text]="count().toString()"
832
+ >
833
+ <ngt-mesh-standard-material *ngIf="!debug(); else withDebug" [color]="color()" />
834
+ <ng-template #withDebug>
835
+ <ngt-mesh-normal-material [wireframe]="true" />
836
+ </ng-template>
837
+ </ngts-text-3d>
838
+ </ngts-center>
839
+ <!-- use Content Projection here so consumers can pass in children for ngt-group -->
840
+ <ng-content />
841
+ </ngt-group>
842
+ `, isInline: true, dependencies: [{ kind: "component", type: NgtsCenter, selector: "ngts-center", inputs: ["centerRef", "top", "right", "bottom", "left", "front", "back", "disableX", "disableY", "disableZ", "disable", "precise", "cacheKey"], outputs: ["centered"] }, { kind: "component", type: NgtsText3D, selector: "ngts-text-3d", inputs: ["textRef", "font", "text", "bevelEnabled", "bevelOffset", "bevelSize", "bevelThickness", "curveSegments", "bevelSegments", "height", "size", "lineHeight", "letterSpacing", "smooth"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
843
+ }
844
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsExample, decorators: [{
845
+ type: Component,
846
+ args: [{
847
+ selector: 'ngts-example',
848
+ standalone: true,
849
+ template: `
850
+ <!-- ngtCompound is used by the Renderer to spread props from ngts-example down to ngt-group -->
851
+ <!-- i.e: <ngts-example [position]="[1, 1, 1]" />, [1, 1, 1] will be passed down to ngt-group -->
852
+ <!-- [ref] is used with the Input so that the consumer can pass an external ref and control this internal ngt-group -->
853
+ <ngt-group ngtCompound [ref]="exampleRef">
854
+ <ngts-center [top]="true">
855
+ <ngts-text-3d
856
+ [bevelEnabled]="true"
857
+ [bevelSize]="bevelSize()"
858
+ [font]="font()"
859
+ [text]="count().toString()"
860
+ >
861
+ <ngt-mesh-standard-material *ngIf="!debug(); else withDebug" [color]="color()" />
862
+ <ng-template #withDebug>
863
+ <ngt-mesh-normal-material [wireframe]="true" />
864
+ </ng-template>
865
+ </ngts-text-3d>
866
+ </ngts-center>
867
+ <!-- use Content Projection here so consumers can pass in children for ngt-group -->
868
+ <ng-content />
869
+ </ngt-group>
870
+ `,
871
+ /**
872
+ * can definitely use other Soba components
873
+ */
874
+ imports: [NgtsCenter, NgtsText3D, NgIf],
875
+ /**
876
+ * call the API provider here to actually provide the API for the component's children
877
+ */
878
+ providers: [provideNgtsExampleApi()],
879
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
880
+ }]
881
+ }], propDecorators: { exampleRef: [{
882
+ type: Input
883
+ }], _font: [{
884
+ type: Input,
885
+ args: [{ alias: 'font', required: true }]
886
+ }], _color: [{
887
+ type: Input,
888
+ args: [{ alias: 'color' }]
889
+ }], _debug: [{
890
+ type: Input,
891
+ args: [{ alias: 'debug' }]
892
+ }], _bevelSize: [{
893
+ type: Input,
894
+ args: [{ alias: 'bevelSize' }]
895
+ }] } });
896
+
897
+ var _a;
898
+ const v1 = new THREE.Vector3();
899
+ const v2 = new THREE.Vector3();
900
+ const v3 = new THREE.Vector3();
901
+ function defaultCalculatePosition(el, camera, size) {
902
+ const objectPos = v1.setFromMatrixPosition(el.matrixWorld);
903
+ objectPos.project(camera);
904
+ const widthHalf = size.width / 2;
905
+ const heightHalf = size.height / 2;
906
+ return [objectPos.x * widthHalf + widthHalf, -(objectPos.y * heightHalf) + heightHalf];
907
+ }
908
+ function isObjectBehindCamera(el, camera) {
909
+ const objectPos = v1.setFromMatrixPosition(el.matrixWorld);
910
+ const cameraPos = v2.setFromMatrixPosition(camera.matrixWorld);
911
+ const deltaCamObj = objectPos.sub(cameraPos);
912
+ const camDir = camera.getWorldDirection(v3);
913
+ return deltaCamObj.angleTo(camDir) > Math.PI / 2;
914
+ }
915
+ function isObjectVisible(el, camera, raycaster, occlude) {
916
+ const elPos = v1.setFromMatrixPosition(el.matrixWorld);
917
+ const screenPos = elPos.clone();
918
+ screenPos.project(camera);
919
+ raycaster.setFromCamera(screenPos, camera);
920
+ const intersects = raycaster.intersectObjects(occlude, true);
921
+ if (intersects.length) {
922
+ const intersectionDistance = intersects[0].distance;
923
+ const pointDistance = elPos.distanceTo(raycaster.ray.origin);
924
+ return pointDistance < intersectionDistance;
925
+ }
926
+ return true;
927
+ }
928
+ function objectScale(el, camera) {
929
+ if (camera instanceof THREE.OrthographicCamera) {
930
+ return camera.zoom;
931
+ }
932
+ else if (camera instanceof THREE.PerspectiveCamera) {
933
+ const objectPos = v1.setFromMatrixPosition(el.matrixWorld);
934
+ const cameraPos = v2.setFromMatrixPosition(camera.matrixWorld);
935
+ const vFOV = (camera.fov * Math.PI) / 180;
936
+ const dist = objectPos.distanceTo(cameraPos);
937
+ const scaleFOV = 2 * Math.tan(vFOV / 2) * dist;
938
+ return 1 / scaleFOV;
939
+ }
940
+ else {
941
+ return 1;
942
+ }
943
+ }
944
+ function objectZIndex(el, camera, zIndexRange) {
945
+ if (camera instanceof THREE.PerspectiveCamera || camera instanceof THREE.OrthographicCamera) {
946
+ const objectPos = v1.setFromMatrixPosition(el.matrixWorld);
947
+ const cameraPos = v2.setFromMatrixPosition(camera.matrixWorld);
948
+ const dist = objectPos.distanceTo(cameraPos);
949
+ const A = (zIndexRange[1] - zIndexRange[0]) / (camera.far - camera.near);
950
+ const B = zIndexRange[1] - A * camera.far;
951
+ return Math.round(A * dist + B);
952
+ }
953
+ return undefined;
954
+ }
955
+ const epsilon = (value) => (Math.abs(value) < 1e-10 ? 0 : value);
956
+ function getCSSMatrix(matrix, multipliers, prepend = '') {
957
+ let matrix3d = 'matrix3d(';
958
+ for (let i = 0; i !== 16; i++) {
959
+ matrix3d += epsilon(multipliers[i] * matrix.elements[i]) + (i !== 15 ? ',' : ')');
960
+ }
961
+ return prepend + matrix3d;
962
+ }
963
+ const getCameraCSSMatrix = ((multipliers) => {
964
+ return (matrix) => getCSSMatrix(matrix, multipliers);
965
+ })([1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1]);
966
+ const getObjectCSSMatrix = ((scaleMultipliers) => {
967
+ return (matrix, factor) => getCSSMatrix(matrix, scaleMultipliers(factor), 'translate(-50%,-50%)');
968
+ })((f) => [1 / f, 1 / f, 1 / f, 1, -1 / f, -1 / f, -1 / f, -1, 1 / f, 1 / f, 1 / f, 1, 1, 1, 1, 1]);
969
+ class NgtsHtmlWrapper {
970
+ static { _a = HTML; }
971
+ static { this[_a] = true; }
972
+ constructor() {
973
+ this.htmlInputs = injectNgtsHtmlInputs();
974
+ this.store = injectNgtStore();
975
+ this.gl = this.store.select('gl');
976
+ this.connected = this.store.select('events', 'connected');
977
+ this.viewport = this.store.select('viewport');
978
+ this.scene = this.store.select('scene');
979
+ this.camera = this.store.select('camera');
980
+ this.size = this.store.select('size');
981
+ this.raycaster = this.store.select('raycaster');
982
+ this.isMeshSizeSet = false;
983
+ this.document = inject(DOCUMENT);
984
+ this.vcr = inject(ViewContainerRef);
985
+ this.portalElement = computed(() => {
986
+ const portal = this.htmlInputs.portal();
987
+ if (!portal)
988
+ return null;
989
+ return is.ref(portal) ? portal.nativeElement : portal;
990
+ });
991
+ this.element = computed(() => this.document.createElement(this.htmlInputs.as()));
992
+ this.target = computed(() => {
993
+ const portalElement = this.portalElement();
994
+ if (portalElement)
995
+ return portalElement;
996
+ const connected = this.connected();
997
+ if (connected)
998
+ return connected;
999
+ return this.gl().domElement.parentElement;
1000
+ });
1001
+ this.styles = computed(() => {
1002
+ const [style, center, transform, size, fullscreen] = [
1003
+ this.htmlInputs.style(),
1004
+ this.htmlInputs.center(),
1005
+ this.htmlInputs.transform(),
1006
+ this.size(),
1007
+ this.htmlInputs.fullscreen(),
1008
+ ];
1009
+ if (transform) {
1010
+ return {
1011
+ position: 'absolute',
1012
+ top: 0,
1013
+ left: 0,
1014
+ width: size.width,
1015
+ height: size.height,
1016
+ transformStyle: 'preserve-3d',
1017
+ pointerEvents: 'none',
1018
+ };
1019
+ }
1020
+ return {
1021
+ position: 'absolute',
1022
+ transform: center ? 'translate3d(-50%,-50%,0)' : 'none',
1023
+ ...(fullscreen && {
1024
+ top: -size.height / 2,
1025
+ left: -size.width / 2,
1026
+ width: size.width,
1027
+ height: size.height,
1028
+ }),
1029
+ ...(style || {}),
1030
+ };
1031
+ });
1032
+ this.transformInnerStyles = computed(() => ({ position: 'absolute', pointerEvents: this.htmlInputs.pointerEvents() }));
1033
+ this.setCanvasElementStyle();
1034
+ this.appendElement();
1035
+ this.setWrapperClass();
1036
+ this.render();
1037
+ this.beforeRender();
1038
+ }
1039
+ setCanvasElementStyle() {
1040
+ effect(() => {
1041
+ const el = untracked(this.gl).domElement;
1042
+ const occlude = this.htmlInputs.occlude();
1043
+ if (occlude && occlude === 'blending') {
1044
+ el.style.zIndex = `${Math.floor(untracked(this.htmlInputs.zIndexRange)[0] / 2)}`;
1045
+ el.style.position = 'absolute';
1046
+ el.style.pointerEvents = 'none';
1047
+ }
1048
+ else {
1049
+ el.style.zIndex = null;
1050
+ el.style.position = null;
1051
+ el.style.pointerEvents = null;
1052
+ }
1053
+ });
1054
+ }
1055
+ appendElement() {
1056
+ effect((onCleanup) => {
1057
+ const [group, element] = [this.htmlInputs.groupRef.nativeElement, this.element()];
1058
+ if (group && element) {
1059
+ const [target, transform, scene, camera, size, calculatePosition, prepend] = [
1060
+ this.target(),
1061
+ this.htmlInputs.transform(),
1062
+ untracked(this.scene),
1063
+ untracked(this.camera),
1064
+ untracked(this.size),
1065
+ untracked(this.htmlInputs.calculatePosition),
1066
+ untracked(this.htmlInputs.prepend),
1067
+ ];
1068
+ scene.updateMatrixWorld();
1069
+ if (transform) {
1070
+ element.style.cssText = `position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;`;
1071
+ }
1072
+ else {
1073
+ const vec = calculatePosition(group, camera, size);
1074
+ element.style.cssText = `position:absolute;top:0;left:0;transform:translate3d(${vec[0]}px,${vec[1]}px,0);transform-origin:0 0;`;
1075
+ }
1076
+ if (target) {
1077
+ if (prepend)
1078
+ target.prepend(element);
1079
+ else
1080
+ target.appendChild(element);
1081
+ }
1082
+ onCleanup(() => {
1083
+ if (target)
1084
+ target.removeChild(element);
1085
+ this.vcr.clear();
1086
+ });
1087
+ }
1088
+ });
1089
+ }
1090
+ setWrapperClass() {
1091
+ effect(() => {
1092
+ const [element, wrapperClass] = [this.element(), this.htmlInputs.wrapperClass()];
1093
+ if (element && wrapperClass) {
1094
+ element.className = wrapperClass;
1095
+ }
1096
+ });
1097
+ }
1098
+ render() {
1099
+ effect((onCleanup) => {
1100
+ const [{ transform }, element, content] = [
1101
+ this.htmlInputs.state(),
1102
+ this.element(),
1103
+ this.htmlInputs.content(),
1104
+ ];
1105
+ if (element) {
1106
+ this.isMeshSizeSet = false;
1107
+ const params = transform
1108
+ ? [this.transformTemplate, {}]
1109
+ : [this.renderTemplate, { styles: this.styles }];
1110
+ const ref = this.vcr.createEmbeddedView(...params);
1111
+ if (ref.rootNodes?.[0]) {
1112
+ if (element.hasChildNodes()) {
1113
+ element.replaceChildren(...ref.rootNodes);
1114
+ }
1115
+ else {
1116
+ element.append(...ref.rootNodes);
1117
+ }
1118
+ }
1119
+ safeDetectChanges(ref);
1120
+ let contentRef;
1121
+ let contentParent;
1122
+ /**
1123
+ * NOTE: utilizing rAF here so that renderAnchor (ViewContainerRef) has a chance to be resolved
1124
+ * TODO: Another approach is to call render() in ngOnInit and pass in an injector to the effect
1125
+ */
1126
+ const rAF = requestAnimationFrame(() => {
1127
+ if (content && this.renderAnchor) {
1128
+ contentRef = this.renderAnchor.createEmbeddedView(content);
1129
+ contentParent = ref.rootNodes[0].lastElementChild || ref.rootNodes[0];
1130
+ while (contentParent && contentParent.lastElementChild) {
1131
+ contentParent = contentParent.lastElementChild;
1132
+ }
1133
+ if (contentRef.rootNodes?.[0]) {
1134
+ if (contentParent.hasChildNodes()) {
1135
+ contentParent.replaceChildren(...contentRef.rootNodes);
1136
+ }
1137
+ else {
1138
+ contentParent.append(...contentRef.rootNodes);
1139
+ }
1140
+ }
1141
+ safeDetectChanges(contentRef);
1142
+ }
1143
+ });
1144
+ onCleanup(() => {
1145
+ cancelAnimationFrame(rAF);
1146
+ if (contentRef && contentParent) {
1147
+ contentRef.rootNodes.forEach((node) => {
1148
+ if (contentParent.hasChildNodes()) {
1149
+ contentParent.removeChild(node);
1150
+ }
1151
+ node.remove();
1152
+ });
1153
+ contentRef.destroy();
1154
+ }
1155
+ ref.rootNodes.forEach((node) => {
1156
+ if (element.hasChildNodes()) {
1157
+ element.removeChild(node);
1158
+ }
1159
+ node.remove();
1160
+ });
1161
+ ref.destroy();
1162
+ this.renderAnchor?.clear();
1163
+ this.vcr.clear();
1164
+ });
1165
+ }
1166
+ });
1167
+ }
1168
+ beforeRender() {
1169
+ let oldPosition = [0, 0];
1170
+ let oldZoom = 0;
1171
+ let visible = true;
1172
+ injectBeforeRender((gl) => {
1173
+ const [group, camera, transform, calculatePosition, size, eps, isRayCastOcclusion, occlude, scene, raycaster, element, zIndexRange, sprite, distanceFactor, occlusionMeshRef, geometry, viewport, scale,] = [
1174
+ this.htmlInputs.groupRef.nativeElement,
1175
+ this.camera(),
1176
+ this.htmlInputs.transform(),
1177
+ this.htmlInputs.calculatePosition(),
1178
+ this.size(),
1179
+ this.htmlInputs.eps(),
1180
+ this.htmlInputs.isRayCastOcclusion(),
1181
+ this.htmlInputs.occlude(),
1182
+ this.scene(),
1183
+ this.raycaster(),
1184
+ this.element(),
1185
+ this.htmlInputs.zIndexRange(),
1186
+ this.htmlInputs.sprite(),
1187
+ this.htmlInputs.distanceFactor(),
1188
+ this.htmlInputs.occlusionMeshRef.nativeElement,
1189
+ this.htmlInputs.geometry(),
1190
+ this.viewport(),
1191
+ this.htmlInputs.scale(),
1192
+ ];
1193
+ if (group && element) {
1194
+ camera.updateMatrixWorld();
1195
+ group.updateWorldMatrix(true, false);
1196
+ const vec = transform ? oldPosition : calculatePosition(group, camera, size);
1197
+ if (transform ||
1198
+ Math.abs(oldZoom - camera.zoom) > eps ||
1199
+ Math.abs(oldPosition[0] - vec[0]) > eps ||
1200
+ Math.abs(oldPosition[1] - vec[1]) > eps) {
1201
+ const isBehindCamera = isObjectBehindCamera(group, camera);
1202
+ let raytraceTarget = false;
1203
+ if (isRayCastOcclusion) {
1204
+ if (Array.isArray(occlude)) {
1205
+ raytraceTarget = occlude.map((item) => (is.ref(item) ? item.nativeElement : item));
1206
+ }
1207
+ else if (occlude !== 'blending') {
1208
+ raytraceTarget = [scene];
1209
+ }
1210
+ }
1211
+ const previouslyVisible = visible;
1212
+ if (raytraceTarget) {
1213
+ const isVisible = isObjectVisible(group, camera, raycaster, raytraceTarget);
1214
+ visible = isVisible && !isBehindCamera;
1215
+ }
1216
+ else {
1217
+ visible = !isBehindCamera;
1218
+ }
1219
+ if (previouslyVisible !== visible) {
1220
+ if (this.htmlInputs.occluded.observed) {
1221
+ this.htmlInputs.occluded.emit(!visible);
1222
+ }
1223
+ else {
1224
+ element.style.display = visible ? 'block' : 'none';
1225
+ }
1226
+ }
1227
+ const halfRange = Math.floor(zIndexRange[0] / 2);
1228
+ const zRange = occlude
1229
+ ? isRayCastOcclusion //
1230
+ ? [zIndexRange[0], halfRange]
1231
+ : [halfRange - 1, 0]
1232
+ : zIndexRange;
1233
+ element.style.zIndex = `${objectZIndex(group, camera, zRange)}`;
1234
+ if (transform) {
1235
+ const [widthHalf, heightHalf] = [size.width / 2, size.height / 2];
1236
+ const fov = camera.projectionMatrix.elements[5] * heightHalf;
1237
+ const { isOrthographicCamera, top, left, bottom, right } = camera;
1238
+ const cameraMatrix = getCameraCSSMatrix(camera.matrixWorldInverse);
1239
+ const cameraTransform = isOrthographicCamera
1240
+ ? `scale(${fov})translate(${epsilon(-(right + left) / 2)}px,${epsilon((top + bottom) / 2)}px)`
1241
+ : `translateZ(${fov}px)`;
1242
+ let matrix = group.matrixWorld;
1243
+ if (sprite) {
1244
+ matrix = camera.matrixWorldInverse
1245
+ .clone()
1246
+ .transpose()
1247
+ .copyPosition(matrix)
1248
+ .scale(group.scale);
1249
+ matrix.elements[3] = matrix.elements[7] = matrix.elements[11] = 0;
1250
+ matrix.elements[15] = 1;
1251
+ }
1252
+ element.style.width = size.width + 'px';
1253
+ element.style.height = size.height + 'px';
1254
+ element.style.perspective = isOrthographicCamera ? '' : `${fov}px`;
1255
+ if (this.outerDiv?.nativeElement && this.innerDiv?.nativeElement) {
1256
+ this.outerDiv.nativeElement.style.width = size.width + 'px';
1257
+ this.outerDiv.nativeElement.style.height = size.height + 'px';
1258
+ this.outerDiv.nativeElement.style.transform = `${cameraTransform}${cameraMatrix}translate(${widthHalf}px,${heightHalf}px)`;
1259
+ this.innerDiv.nativeElement.style.transform = getObjectCSSMatrix(matrix, 1 / ((distanceFactor || 10) / 400));
1260
+ }
1261
+ }
1262
+ else {
1263
+ const scale = distanceFactor === undefined ? 1 : objectScale(group, camera) * distanceFactor;
1264
+ element.style.transform = `translate3d(${vec[0]}px,${vec[1]}px,0) scale(${scale})`;
1265
+ }
1266
+ oldPosition = vec;
1267
+ oldZoom = camera.zoom;
1268
+ }
1269
+ }
1270
+ if (!isRayCastOcclusion && occlusionMeshRef && !this.isMeshSizeSet) {
1271
+ if (transform) {
1272
+ if (this.outerDiv?.nativeElement) {
1273
+ const el = this.outerDiv.nativeElement.children[0];
1274
+ if (el?.clientWidth && el?.clientHeight) {
1275
+ const { isOrthographicCamera } = camera;
1276
+ if (isOrthographicCamera || geometry) {
1277
+ if (scale !== 1) {
1278
+ if (!Array.isArray(scale)) {
1279
+ occlusionMeshRef.scale.setScalar(1 / scale);
1280
+ }
1281
+ else if (scale instanceof THREE.Vector3) {
1282
+ occlusionMeshRef.scale.copy(scale.clone().divideScalar(1));
1283
+ }
1284
+ else {
1285
+ occlusionMeshRef.scale.set(1 / scale[0], 1 / scale[1], 1 / scale[2]);
1286
+ }
1287
+ }
1288
+ }
1289
+ else {
1290
+ const ratio = (distanceFactor || 10) / 400;
1291
+ const w = el.clientWidth * ratio;
1292
+ const h = el.clientHeight * ratio;
1293
+ occlusionMeshRef.scale.set(w, h, 1);
1294
+ }
1295
+ this.isMeshSizeSet = true;
1296
+ }
1297
+ }
1298
+ }
1299
+ else {
1300
+ const ele = element.children[0];
1301
+ if (ele?.clientWidth && ele?.clientHeight) {
1302
+ const ratio = 1 / viewport.factor;
1303
+ const w = ele.clientWidth * ratio;
1304
+ const h = ele.clientHeight * ratio;
1305
+ occlusionMeshRef.scale.set(w, h, 1);
1306
+ this.isMeshSizeSet = true;
1307
+ }
1308
+ occlusionMeshRef.lookAt(gl.camera.position);
1309
+ }
1310
+ }
1311
+ });
1312
+ }
1313
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsHtmlWrapper, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1314
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: NgtsHtmlWrapper, isStandalone: true, selector: "ngts-html-wrapper", viewQueries: [{ propertyName: "transformTemplate", first: true, predicate: ["transformTemplate"], descendants: true, static: true }, { propertyName: "renderTemplate", first: true, predicate: ["renderTemplate"], descendants: true, static: true }, { propertyName: "outerDiv", first: true, predicate: ["transformedOuterDiv"], descendants: true }, { propertyName: "innerDiv", first: true, predicate: ["transformedInnerDiv"], descendants: true }, { propertyName: "renderAnchor", first: true, predicate: ["renderAnchor"], descendants: true, read: ViewContainerRef }], ngImport: i0, template: `
1315
+ <ng-template #transformTemplate>
1316
+ <div #transformedOuterDiv [style]="styles()">
1317
+ <div #transformedInnerDiv [style]="transformInnerStyles()">
1318
+ <ng-container *ngTemplateOutlet="renderTemplate; context: { styles: htmlInputs.style }" />
1319
+ </div>
1320
+ </div>
1321
+ </ng-template>
1322
+
1323
+ <ng-template #renderTemplate let-renderedStyles="styles">
1324
+ <div #renderedDiv [class]="htmlInputs.renderedDivClass()" [style]="renderedStyles()">
1325
+ <ng-container #renderAnchor />
1326
+ </div>
1327
+ </ng-template>
1328
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
1329
+ }
1330
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsHtmlWrapper, decorators: [{
1331
+ type: Component,
1332
+ args: [{
1333
+ selector: 'ngts-html-wrapper',
1334
+ standalone: true,
1335
+ template: `
1336
+ <ng-template #transformTemplate>
1337
+ <div #transformedOuterDiv [style]="styles()">
1338
+ <div #transformedInnerDiv [style]="transformInnerStyles()">
1339
+ <ng-container *ngTemplateOutlet="renderTemplate; context: { styles: htmlInputs.style }" />
1340
+ </div>
1341
+ </div>
1342
+ </ng-template>
1343
+
1344
+ <ng-template #renderTemplate let-renderedStyles="styles">
1345
+ <div #renderedDiv [class]="htmlInputs.renderedDivClass()" [style]="renderedStyles()">
1346
+ <ng-container #renderAnchor />
1347
+ </div>
1348
+ </ng-template>
1349
+ `,
1350
+ imports: [NgTemplateOutlet],
1351
+ }]
1352
+ }], ctorParameters: function () { return []; }, propDecorators: { transformTemplate: [{
1353
+ type: ViewChild,
1354
+ args: ['transformTemplate', { static: true }]
1355
+ }], renderTemplate: [{
1356
+ type: ViewChild,
1357
+ args: ['renderTemplate', { static: true }]
1358
+ }], outerDiv: [{
1359
+ type: ViewChild,
1360
+ args: ['transformedOuterDiv']
1361
+ }], innerDiv: [{
1362
+ type: ViewChild,
1363
+ args: ['transformedInnerDiv']
1364
+ }], renderAnchor: [{
1365
+ type: ViewChild,
1366
+ args: ['renderAnchor', { read: ViewContainerRef }]
1367
+ }] } });
1368
+
1369
+ extend({ Group, PlaneGeometry, Mesh, ShaderMaterial });
1370
+ const [injectNgtsHtmlInputs, provideNgtsHtmlInputs] = createInjectionToken((html) => ({ state: html.inputs.state, ...html.state }), { isRoot: false, deps: [forwardRef(() => NgtsHtml)] });
1371
+ class NgtsHtml {
1372
+ constructor() {
1373
+ this.DoubleSide = THREE.DoubleSide;
1374
+ this.inputs = signalStore({
1375
+ as: 'div',
1376
+ prepend: false,
1377
+ transform: false,
1378
+ fullscreen: false,
1379
+ center: false,
1380
+ sprite: false,
1381
+ zIndexRange: [16777271, 0],
1382
+ eps: 0.001,
1383
+ scale: 1,
1384
+ calculatePosition: defaultCalculatePosition,
1385
+ pointerEvents: 'auto',
1386
+ occlude: false,
1387
+ castShadow: false,
1388
+ receiveShadow: false,
1389
+ });
1390
+ this.groupRef = injectNgtRef();
1391
+ this.occluded = new EventEmitter();
1392
+ this.occlusionMeshRef = injectNgtRef();
1393
+ this.transform = this.inputs.select('transform');
1394
+ this.isRayCastOcclusion = computed(() => {
1395
+ const occlude = this.occlude();
1396
+ return ((occlude && occlude !== 'blending') || (Array.isArray(occlude) && !!occlude.length && is.ref(occlude[0])));
1397
+ });
1398
+ this.occlude = this.inputs.select('occlude');
1399
+ this.castShadow = this.inputs.select('castShadow');
1400
+ this.receiveShadow = this.inputs.select('receiveShadow');
1401
+ this.geometry = this.inputs.select('geometry');
1402
+ this.material = this.inputs.select('material');
1403
+ this.scale = this.inputs.select('scale');
1404
+ this.shaders = computed(() => {
1405
+ const transform = this.transform();
1406
+ return {
1407
+ vertexShader: !transform
1408
+ ? /* glsl */ `
1409
+ /*
1410
+ This shader is from the THREE's SpriteMaterial.
1411
+ We need to turn the backing plane into a Sprite
1412
+ (make it always face the camera) if "transfrom"
1413
+ is false.
1414
+ */
1415
+ #include <common>
1416
+
1417
+ void main() {
1418
+ vec2 center = vec2(0., 1.);
1419
+ float rotation = 0.0;
1420
+
1421
+ // This is somewhat arbitrary, but it seems to work well
1422
+ // Need to figure out how to derive this dynamically if it even matters
1423
+ float size = 0.03;
1424
+
1425
+ vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
1426
+ vec2 scale;
1427
+ scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );
1428
+ scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );
1429
+
1430
+ bool isPerspective = isPerspectiveMatrix( projectionMatrix );
1431
+ if ( isPerspective ) scale *= - mvPosition.z;
1432
+
1433
+ vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale * size;
1434
+ vec2 rotatedPosition;
1435
+ rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
1436
+ rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
1437
+ mvPosition.xy += rotatedPosition;
1438
+
1439
+ gl_Position = projectionMatrix * mvPosition;
1440
+ }
1441
+ `
1442
+ : undefined,
1443
+ fragmentShader: /* glsl */ `
1444
+ void main() {
1445
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
1446
+ }
1447
+ `,
1448
+ };
1449
+ });
1450
+ this.state = {
1451
+ zIndexRange: this.inputs.select('zIndexRange'),
1452
+ prepend: this.inputs.select('prepend'),
1453
+ transform: this.transform,
1454
+ center: this.inputs.select('center'),
1455
+ fullscreen: this.inputs.select('fullscreen'),
1456
+ calculatePosition: this.inputs.select('calculatePosition'),
1457
+ wrapperClass: this.inputs.select('wrapperClass'),
1458
+ renderedDivClass: this.inputs.select('renderedDivClass'),
1459
+ style: this.inputs.select('style'),
1460
+ pointerEvents: this.inputs.select('pointerEvents'),
1461
+ eps: this.inputs.select('eps'),
1462
+ distanceFactor: this.inputs.select('distanceFactor'),
1463
+ sprite: this.inputs.select('sprite'),
1464
+ as: this.inputs.select('as'),
1465
+ portal: this.inputs.select('portal'),
1466
+ content: this.inputs.select('content'),
1467
+ occlude: this.occlude,
1468
+ isRayCastOcclusion: this.isRayCastOcclusion,
1469
+ occlusionMeshRef: this.occlusionMeshRef,
1470
+ occluded: this.occluded,
1471
+ geometry: this.geometry,
1472
+ scale: this.scale,
1473
+ groupRef: this.groupRef,
1474
+ };
1475
+ }
1476
+ set content(content) {
1477
+ this.inputs.set({ content });
1478
+ }
1479
+ set _as(as) {
1480
+ this.inputs.set({ as });
1481
+ }
1482
+ set _zIndexRange(zIndexRange) {
1483
+ this.inputs.set({ zIndexRange });
1484
+ }
1485
+ set _portal(portal) {
1486
+ this.inputs.set({ portal });
1487
+ }
1488
+ set _occlude(occlude) {
1489
+ this.inputs.set({ occlude });
1490
+ }
1491
+ set _castShadow(castShadow) {
1492
+ this.inputs.set({ castShadow });
1493
+ }
1494
+ set _receiveShadow(receiveShadow) {
1495
+ this.inputs.set({ receiveShadow });
1496
+ }
1497
+ set _material(material) {
1498
+ this.inputs.set({ material });
1499
+ }
1500
+ set _geometry(geometry) {
1501
+ this.inputs.set({ geometry });
1502
+ }
1503
+ set _scale(scale) {
1504
+ this.inputs.set({ scale });
1505
+ }
1506
+ set _prepend(prepend) {
1507
+ this.inputs.set({ prepend });
1508
+ }
1509
+ set _transform(transform) {
1510
+ this.inputs.set({ transform });
1511
+ }
1512
+ set _center(center) {
1513
+ this.inputs.set({ center });
1514
+ }
1515
+ set _sprite(sprite) {
1516
+ this.inputs.set({ sprite });
1517
+ }
1518
+ set _fullscreen(fullscreen) {
1519
+ this.inputs.set({ fullscreen });
1520
+ }
1521
+ set _eps(eps) {
1522
+ this.inputs.set({ eps });
1523
+ }
1524
+ set _distanceFactor(distanceFactor) {
1525
+ this.inputs.set({ distanceFactor });
1526
+ }
1527
+ set _wrapperClass(wrapperClass) {
1528
+ this.inputs.set({ wrapperClass });
1529
+ }
1530
+ set _renderedDivClass(renderedDivClass) {
1531
+ this.inputs.set({ renderedDivClass });
1532
+ }
1533
+ set _style(style) {
1534
+ this.inputs.set({ style });
1535
+ }
1536
+ set _pointerEvents(pointerEvents) {
1537
+ this.inputs.set({ pointerEvents });
1538
+ }
1539
+ set _calculatePosition(calculatePosition) {
1540
+ this.inputs.set({ calculatePosition });
1541
+ }
1542
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsHtml, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1543
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: NgtsHtml, isStandalone: true, selector: "ngts-html", inputs: { groupRef: "groupRef", _as: ["as", "_as"], _zIndexRange: ["zIndexRange", "_zIndexRange"], _portal: ["portal", "_portal"], _occlude: ["occlude", "_occlude"], _castShadow: ["castShadow", "_castShadow"], _receiveShadow: ["receiveShadow", "_receiveShadow"], _material: ["material", "_material"], _geometry: ["geometry", "_geometry"], _scale: ["scale", "_scale"], _prepend: ["prepend", "_prepend"], _transform: ["transform", "_transform"], _center: ["center", "_center"], _sprite: ["sprite", "_sprite"], _fullscreen: ["fullscreen", "_fullscreen"], _eps: ["eps", "_eps"], _distanceFactor: ["distanceFactor", "_distanceFactor"], _wrapperClass: ["wrapperClass", "_wrapperClass"], _renderedDivClass: ["renderedDivClass", "_renderedDivClass"], _style: ["style", "_style"], _pointerEvents: ["pointerEvents", "_pointerEvents"], _calculatePosition: ["calculatePosition", "_calculatePosition"] }, outputs: { occluded: "occluded" }, providers: [provideNgtsHtmlInputs()], queries: [{ propertyName: "content", first: true, predicate: NgtsSobaContent, descendants: true, read: TemplateRef }], ngImport: i0, template: `
1544
+ <ngt-group ngtCompound [ref]="groupRef" [scale]="scale()">
1545
+ <ngt-mesh
1546
+ *ngIf="occlude() && !isRayCastOcclusion()"
1547
+ [castShadow]="castShadow()"
1548
+ [receiveShadow]="receiveShadow()"
1549
+ [ref]="occlusionMeshRef"
1550
+ >
1551
+ <ngt-plane-geometry *ngIf="geometry()" />
1552
+ <ngt-shader-material
1553
+ *ngIf="material()"
1554
+ [side]="DoubleSide"
1555
+ [vertexShader]="shaders().vertexShader"
1556
+ [fragmentShader]="shaders().fragmentShader"
1557
+ />
1558
+ </ngt-mesh>
1559
+ </ngt-group>
1560
+
1561
+ <ngts-html-wrapper />
1562
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: NgtsHtmlWrapper, selector: "ngts-html-wrapper" }] }); }
1563
+ }
1564
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsHtml, decorators: [{
1565
+ type: Component,
1566
+ args: [{
1567
+ selector: 'ngts-html',
1568
+ standalone: true,
1569
+ template: `
1570
+ <ngt-group ngtCompound [ref]="groupRef" [scale]="scale()">
1571
+ <ngt-mesh
1572
+ *ngIf="occlude() && !isRayCastOcclusion()"
1573
+ [castShadow]="castShadow()"
1574
+ [receiveShadow]="receiveShadow()"
1575
+ [ref]="occlusionMeshRef"
1576
+ >
1577
+ <ngt-plane-geometry *ngIf="geometry()" />
1578
+ <ngt-shader-material
1579
+ *ngIf="material()"
1580
+ [side]="DoubleSide"
1581
+ [vertexShader]="shaders().vertexShader"
1582
+ [fragmentShader]="shaders().fragmentShader"
1583
+ />
1584
+ </ngt-mesh>
1585
+ </ngt-group>
1586
+
1587
+ <ngts-html-wrapper />
1588
+ `,
1589
+ imports: [NgIf, NgtsHtmlWrapper],
1590
+ providers: [provideNgtsHtmlInputs()],
1591
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
1592
+ }]
1593
+ }], propDecorators: { content: [{
1594
+ type: ContentChild,
1595
+ args: [NgtsSobaContent, { read: TemplateRef }]
1596
+ }], groupRef: [{
1597
+ type: Input
1598
+ }], _as: [{
1599
+ type: Input,
1600
+ args: [{ alias: 'as' }]
1601
+ }], _zIndexRange: [{
1602
+ type: Input,
1603
+ args: [{ alias: 'zIndexRange' }]
1604
+ }], _portal: [{
1605
+ type: Input,
1606
+ args: [{ alias: 'portal' }]
1607
+ }], _occlude: [{
1608
+ type: Input,
1609
+ args: [{ alias: 'occlude' }]
1610
+ }], _castShadow: [{
1611
+ type: Input,
1612
+ args: [{ alias: 'castShadow' }]
1613
+ }], _receiveShadow: [{
1614
+ type: Input,
1615
+ args: [{ alias: 'receiveShadow' }]
1616
+ }], _material: [{
1617
+ type: Input,
1618
+ args: [{ alias: 'material' }]
1619
+ }], _geometry: [{
1620
+ type: Input,
1621
+ args: [{ alias: 'geometry' }]
1622
+ }], _scale: [{
1623
+ type: Input,
1624
+ args: [{ alias: 'scale' }]
1625
+ }], _prepend: [{
1626
+ type: Input,
1627
+ args: [{ alias: 'prepend' }]
1628
+ }], _transform: [{
1629
+ type: Input,
1630
+ args: [{ alias: 'transform' }]
1631
+ }], _center: [{
1632
+ type: Input,
1633
+ args: [{ alias: 'center' }]
1634
+ }], _sprite: [{
1635
+ type: Input,
1636
+ args: [{ alias: 'sprite' }]
1637
+ }], _fullscreen: [{
1638
+ type: Input,
1639
+ args: [{ alias: 'fullscreen' }]
1640
+ }], _eps: [{
1641
+ type: Input,
1642
+ args: [{ alias: 'eps' }]
1643
+ }], _distanceFactor: [{
1644
+ type: Input,
1645
+ args: [{ alias: 'distanceFactor' }]
1646
+ }], _wrapperClass: [{
1647
+ type: Input,
1648
+ args: [{ alias: 'wrapperClass' }]
1649
+ }], _renderedDivClass: [{
1650
+ type: Input,
1651
+ args: [{ alias: 'renderedDivClass' }]
1652
+ }], _style: [{
1653
+ type: Input,
1654
+ args: [{ alias: 'style' }]
1655
+ }], _pointerEvents: [{
1656
+ type: Input,
1657
+ args: [{ alias: 'pointerEvents' }]
1658
+ }], _calculatePosition: [{
1659
+ type: Input,
1660
+ args: [{ alias: 'calculatePosition' }]
1661
+ }], occluded: [{
1662
+ type: Output
1663
+ }] } });
1664
+
1665
+ const defaultState = {
1666
+ count: 16,
1667
+ };
1668
+ function injectNgtsSurfaceSampler(surfaceSamplerState, { injector } = {}) {
1669
+ injector = assertInjector(injectNgtsSurfaceSampler, injector);
1670
+ return runInInjectionContext(injector, () => {
1671
+ const state = computed(() => ({ ...defaultState, ...(surfaceSamplerState() || {}) }));
1672
+ const _buffer = signal((() => {
1673
+ const arr = Array.from({ length: state().count }, () => [
1674
+ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
1675
+ ]).flat();
1676
+ return new THREE.InstancedBufferAttribute(Float32Array.from(arr), 16);
1677
+ })());
1678
+ effect(() => {
1679
+ const { mesh, count, transform, instancedMesh, weight } = state();
1680
+ const meshObj = is.ref(mesh) ? mesh.nativeElement : mesh;
1681
+ if (!meshObj)
1682
+ return;
1683
+ const instancedMeshObj = is.ref(instancedMesh) ? instancedMesh.nativeElement : instancedMesh;
1684
+ const buffer = untracked(_buffer);
1685
+ const sampler = new MeshSurfaceSampler(meshObj);
1686
+ if (weight) {
1687
+ sampler.setWeightAttribute(weight);
1688
+ }
1689
+ sampler.build();
1690
+ const position = new THREE.Vector3();
1691
+ const normal = new THREE.Vector3();
1692
+ const color = new THREE.Color();
1693
+ const dummy = new THREE.Object3D();
1694
+ meshObj.updateMatrixWorld(true);
1695
+ for (let i = 0; i < count; i++) {
1696
+ sampler.sample(position, normal, color);
1697
+ if (typeof transform === 'function') {
1698
+ transform({ dummy, sampledMesh: meshObj, position, normal, color }, i);
1699
+ }
1700
+ else {
1701
+ dummy.position.copy(position);
1702
+ }
1703
+ dummy.updateMatrix();
1704
+ if (instancedMeshObj) {
1705
+ instancedMeshObj.setMatrixAt(i, dummy.matrix);
1706
+ }
1707
+ dummy.matrix.toArray(buffer.array, i * 16);
1708
+ }
1709
+ if (instancedMeshObj) {
1710
+ checkUpdate(instancedMeshObj.instanceMatrix);
1711
+ }
1712
+ checkUpdate(buffer);
1713
+ untracked(() => {
1714
+ _buffer.set(buffer.clone());
1715
+ });
1716
+ });
1717
+ return _buffer.asReadonly();
1718
+ });
1719
+ }
1720
+ extend({ Group });
1721
+ class NgtsSampler {
1722
+ set _count(count) {
1723
+ this.inputs.set({ count });
1724
+ }
1725
+ set _mesh(mesh) {
1726
+ this.inputs.set({ mesh });
1727
+ }
1728
+ set _transform(transform) {
1729
+ this.inputs.set({ transform });
1730
+ }
1731
+ set _weight(weight) {
1732
+ this.inputs.set({ weight });
1733
+ }
1734
+ set _instancedMesh(instancedMesh) {
1735
+ this.inputs.set({ instancedMesh });
1736
+ }
1737
+ constructor() {
1738
+ this.inputs = signalStore({ count: 16 });
1739
+ this.samplerRef = injectNgtRef();
1740
+ this.surfaceSamplerState = computed(() => {
1741
+ const sampler = this.samplerRef.nativeElement;
1742
+ if (!sampler)
1743
+ return null;
1744
+ const { count, weight, transform, mesh, instancedMesh } = this.inputs.state();
1745
+ const instancedMeshRef = instancedMesh ??
1746
+ sampler.children.find((child) => child.hasOwnProperty('instanceMatrix'));
1747
+ const meshRef = mesh ?? sampler.children.find((child) => child.type === 'Mesh');
1748
+ return { count, weight, transform, mesh: meshRef, instancedMesh: instancedMeshRef };
1749
+ });
1750
+ injectNgtsSurfaceSampler(this.surfaceSamplerState);
1751
+ }
1752
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsSampler, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1753
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: NgtsSampler, isStandalone: true, selector: "ngts-sampler", inputs: { samplerRef: "samplerRef", _count: ["count", "_count"], _mesh: ["mesh", "_mesh"], _transform: ["transform", "_transform"], _weight: ["weight", "_weight"], _instancedMesh: ["instancedMesh", "_instancedMesh"] }, ngImport: i0, template: `
1754
+ <ngt-group ngtCompound [ref]="samplerRef">
1755
+ <ng-content />
1756
+ </ngt-group>
1757
+ `, isInline: true }); }
1758
+ }
1759
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsSampler, decorators: [{
1760
+ type: Component,
1761
+ args: [{
1762
+ selector: 'ngts-sampler',
1763
+ standalone: true,
1764
+ template: `
1765
+ <ngt-group ngtCompound [ref]="samplerRef">
1766
+ <ng-content />
1767
+ </ngt-group>
1768
+ `,
1769
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
1770
+ }]
1771
+ }], ctorParameters: function () { return []; }, propDecorators: { samplerRef: [{
1772
+ type: Input
1773
+ }], _count: [{
1774
+ type: Input,
1775
+ args: [{ alias: 'count' }]
1776
+ }], _mesh: [{
1777
+ type: Input,
1778
+ args: [{ alias: 'mesh' }]
1779
+ }], _transform: [{
1780
+ type: Input,
1781
+ args: [{ alias: 'transform' }]
1782
+ }], _weight: [{
1783
+ type: Input,
1784
+ args: [{ alias: 'weight' }]
1785
+ }], _instancedMesh: [{
1786
+ type: Input,
1787
+ args: [{ alias: 'instancedMesh' }]
1788
+ }] } });
1789
+
1790
+ extend({ Mesh, CanvasTexture, PlaneGeometry, MeshBasicMaterial });
1791
+ class NgtsShadow {
1792
+ constructor() {
1793
+ this.Math = Math;
1794
+ this.DoubleSide = THREE.DoubleSide;
1795
+ this.inputs = signalStore({
1796
+ fog: false,
1797
+ depthWrite: false,
1798
+ colorStop: 0.0,
1799
+ color: 'black',
1800
+ opacity: 0.5,
1801
+ });
1802
+ this.shadowRef = injectNgtRef();
1803
+ this.colorStop = this.inputs.select('colorStop');
1804
+ this.color = this.inputs.select('color');
1805
+ this.opacity = this.inputs.select('opacity');
1806
+ this.fog = this.inputs.select('fog');
1807
+ this.depthWrite = this.inputs.select('depthWrite');
1808
+ this.canvas = computed(() => {
1809
+ const [colorStop, color] = [this.colorStop(), this.color()];
1810
+ const canvas = document.createElement('canvas');
1811
+ canvas.width = 128;
1812
+ canvas.height = 128;
1813
+ const context = canvas.getContext('2d');
1814
+ const gradient = context.createRadialGradient(canvas.width / 2, canvas.height / 2, 0, canvas.width / 2, canvas.height / 2, canvas.width / 2);
1815
+ gradient.addColorStop(colorStop, new THREE.Color(color).getStyle());
1816
+ gradient.addColorStop(1, 'rgba(0,0,0,0)');
1817
+ context.fillStyle = gradient;
1818
+ context.fillRect(0, 0, canvas.width, canvas.height);
1819
+ return canvas;
1820
+ });
1821
+ }
1822
+ set _colorStop(colorStop) {
1823
+ this.inputs.set({ colorStop });
1824
+ }
1825
+ set _fog(fog) {
1826
+ this.inputs.set({ fog });
1827
+ }
1828
+ set _color(color) {
1829
+ this.inputs.set({ color });
1830
+ }
1831
+ set _opacity(opacity) {
1832
+ this.inputs.set({ opacity });
1833
+ }
1834
+ set _depthWrite(depthWrite) {
1835
+ this.inputs.set({ depthWrite });
1836
+ }
1837
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsShadow, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1838
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: NgtsShadow, isStandalone: true, selector: "ngts-shadow", inputs: { shadowRef: "shadowRef", _colorStop: ["colorStop", "_colorStop"], _fog: ["fog", "_fog"], _color: ["color", "_color"], _opacity: ["opacity", "_opacity"], _depthWrite: ["depthWrite", "_depthWrite"] }, ngImport: i0, template: `
1839
+ <ngt-mesh ngtCompound [ref]="shadowRef" [rotation]="[-Math.PI / 2, 0, 0]">
1840
+ <ngt-plane-geometry />
1841
+ <ngt-mesh-basic-material
1842
+ [transparent]="true"
1843
+ [opacity]="opacity()"
1844
+ [fog]="fog()"
1845
+ [depthWrite]="depthWrite()"
1846
+ [side]="DoubleSide"
1847
+ >
1848
+ <ngt-canvas-texture *args="[canvas()]" attach="map" />
1849
+ </ngt-mesh-basic-material>
1850
+ <ng-content />
1851
+ </ngt-mesh>
1852
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgtArgs, selector: "ng-template[args]", inputs: ["args"] }] }); }
1853
+ }
1854
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsShadow, decorators: [{
1855
+ type: Component,
1856
+ args: [{
1857
+ selector: 'ngts-shadow',
1858
+ standalone: true,
1859
+ template: `
1860
+ <ngt-mesh ngtCompound [ref]="shadowRef" [rotation]="[-Math.PI / 2, 0, 0]">
1861
+ <ngt-plane-geometry />
1862
+ <ngt-mesh-basic-material
1863
+ [transparent]="true"
1864
+ [opacity]="opacity()"
1865
+ [fog]="fog()"
1866
+ [depthWrite]="depthWrite()"
1867
+ [side]="DoubleSide"
1868
+ >
1869
+ <ngt-canvas-texture *args="[canvas()]" attach="map" />
1870
+ </ngt-mesh-basic-material>
1871
+ <ng-content />
1872
+ </ngt-mesh>
1873
+ `,
1874
+ imports: [NgtArgs],
1875
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
1876
+ }]
1877
+ }], propDecorators: { shadowRef: [{
1878
+ type: Input
1879
+ }], _colorStop: [{
1880
+ type: Input,
1881
+ args: [{ alias: 'colorStop' }]
1882
+ }], _fog: [{
1883
+ type: Input,
1884
+ args: [{ alias: 'fog' }]
1885
+ }], _color: [{
1886
+ type: Input,
1887
+ args: [{ alias: 'color' }]
1888
+ }], _opacity: [{
1889
+ type: Input,
1890
+ args: [{ alias: 'opacity' }]
1891
+ }], _depthWrite: [{
1892
+ type: Input,
1893
+ args: [{ alias: 'depthWrite' }]
1894
+ }] } });
1895
+
1896
+ class NgtsStatsGL {
1897
+ set _parent(parent) {
1898
+ this.inputs.set({ parent });
1899
+ }
1900
+ set _containerClass(containerClass) {
1901
+ this.inputs.set({ containerClass });
1902
+ }
1903
+ set _config(config) {
1904
+ this.inputs.set({ config });
1905
+ }
1906
+ constructor() {
1907
+ this.inputs = signalStore();
1908
+ this.document = inject(DOCUMENT);
1909
+ this.store = injectNgtStore();
1910
+ this.gl = this.store.select('gl');
1911
+ this.config = this.inputs.select('config');
1912
+ this.parent = this.inputs.select('parent');
1913
+ this.containerClass = this.inputs.select('containerClass');
1914
+ this.stats = computed(() => {
1915
+ const [config, gl] = [this.config() || {}, this.gl()];
1916
+ const stats = new Stats(config);
1917
+ stats.init(gl.domElement);
1918
+ return stats;
1919
+ });
1920
+ effect((onCleanup) => {
1921
+ const [parent, stats, containerClass] = [this.parent(), this.stats(), this.containerClass()];
1922
+ const node = parent ? (is.ref(parent) ? parent.nativeElement : parent) : this.document.body;
1923
+ node.appendChild(stats.container);
1924
+ if (containerClass)
1925
+ stats.container.classList.add(...containerClass.split(' ').filter(Boolean));
1926
+ const begin = addEffect(() => stats.begin());
1927
+ const end = addAfterEffect(() => stats.end());
1928
+ onCleanup(() => {
1929
+ node.removeChild(stats.container);
1930
+ begin();
1931
+ end();
139
1932
  });
140
- const fboRef = injectNgtsFBO(fboParams, { injector });
141
- effect(() => {
142
- const fbo = fboRef();
143
- if (fbo) {
144
- depthBufferRef.set(fbo.depthTexture);
145
- safeDetectChanges(cdr);
146
- }
147
- }, { allowSignalWrites: true, injector });
148
- let count = 0;
149
- injectBeforeRender(({ gl, scene, camera }) => {
150
- const params = { size: 256, frames: Infinity, ...paramsFactory() };
151
- const fbo = untracked(fboRef);
152
- if ((params.frames === Infinity || count < params.frames) && fbo) {
153
- gl.setRenderTarget(fbo);
154
- gl.render(scene, camera);
155
- gl.setRenderTarget(null);
156
- count++;
157
- }
158
- }, { injector });
159
- });
160
- return depthBufferRef.asReadonly();
1933
+ });
1934
+ }
1935
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsStatsGL, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1936
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.3", type: NgtsStatsGL, isStandalone: true, selector: "ngts-stats-gl", inputs: { _parent: ["parent", "_parent"], _containerClass: ["containerClass", "_containerClass"], _config: ["config", "_config"] }, ngImport: i0 }); }
1937
+ }
1938
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsStatsGL, decorators: [{
1939
+ type: Directive,
1940
+ args: [{ selector: 'ngts-stats-gl', standalone: true }]
1941
+ }], ctorParameters: function () { return []; }, propDecorators: { _parent: [{
1942
+ type: Input,
1943
+ args: [{ alias: 'parent' }]
1944
+ }], _containerClass: [{
1945
+ type: Input,
1946
+ args: [{ alias: 'containerClass' }]
1947
+ }], _config: [{
1948
+ type: Input,
1949
+ args: [{ alias: 'config' }]
1950
+ }] } });
1951
+
1952
+ // default ease
1953
+ const easeCircleOut = (x) => Math.sqrt(1 - Math.pow(x - 1, 2));
1954
+ // smooth new sample (measurement) based on previous sample (current)
1955
+ function smoothAverage(current, measurement, smoothing = 0.9) {
1956
+ return measurement * smoothing + current * (1.0 - smoothing);
1957
+ }
1958
+ class TrailTexture {
1959
+ constructor({ size = 256, maxAge = 750, radius = 0.3, intensity = 0.2, interpolate = 0, smoothing = 0, minForce = 0.3, blend = 'screen', // source-over is canvas default. Others are slower
1960
+ ease = easeCircleOut, } = {}) {
1961
+ this.size = size;
1962
+ this.maxAge = maxAge;
1963
+ this.radius = radius;
1964
+ this.intensity = intensity;
1965
+ this.ease = ease;
1966
+ this.interpolate = interpolate;
1967
+ this.smoothing = smoothing;
1968
+ this.minForce = minForce;
1969
+ this.blend = blend;
1970
+ this.trail = [];
1971
+ this.force = 0;
1972
+ this.initTexture();
1973
+ }
1974
+ initTexture() {
1975
+ this.canvas = document.createElement('canvas');
1976
+ this.canvas.width = this.canvas.height = this.size;
1977
+ this.ctx = this.canvas.getContext('2d');
1978
+ this.ctx.fillStyle = 'black';
1979
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
1980
+ this.texture = new Texture(this.canvas);
1981
+ this.canvas.id = 'touchTexture';
1982
+ this.canvas.style.width = this.canvas.style.height = `${this.canvas.width}px`;
1983
+ }
1984
+ update(delta) {
1985
+ this.clear();
1986
+ // age points
1987
+ this.trail.forEach((point, i) => {
1988
+ point.age += delta * 1000;
1989
+ // remove old
1990
+ if (point.age > this.maxAge) {
1991
+ this.trail.splice(i, 1);
1992
+ }
1993
+ });
1994
+ // reset force when empty (when smoothing)
1995
+ if (!this.trail.length)
1996
+ this.force = 0;
1997
+ this.trail.forEach((point) => {
1998
+ this.drawTouch(point);
1999
+ });
2000
+ this.texture.needsUpdate = true;
2001
+ }
2002
+ clear() {
2003
+ this.ctx.globalCompositeOperation = 'source-over';
2004
+ this.ctx.fillStyle = 'black';
2005
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
2006
+ }
2007
+ addTouch(point) {
2008
+ const last = this.trail[this.trail.length - 1];
2009
+ if (last) {
2010
+ const dx = last.x - point.x;
2011
+ const dy = last.y - point.y;
2012
+ const dd = dx * dx + dy * dy;
2013
+ const force = Math.max(this.minForce, Math.min(dd * 10000, 1));
2014
+ this.force = smoothAverage(force, this.force, this.smoothing);
2015
+ if (!!this.interpolate) {
2016
+ const lines = Math.ceil(dd / Math.pow((this.radius * 0.5) / this.interpolate, 2));
2017
+ if (lines > 1) {
2018
+ for (let i = 1; i < lines; i++) {
2019
+ this.trail.push({
2020
+ x: last.x - (dx / lines) * i,
2021
+ y: last.y - (dy / lines) * i,
2022
+ age: 0,
2023
+ force,
2024
+ });
2025
+ }
2026
+ }
2027
+ }
2028
+ }
2029
+ this.trail.push({ x: point.x, y: point.y, age: 0, force: this.force });
2030
+ }
2031
+ drawTouch(point) {
2032
+ const pos = {
2033
+ x: point.x * this.size,
2034
+ y: (1 - point.y) * this.size,
2035
+ };
2036
+ let intensity = 1;
2037
+ if (point.age < this.maxAge * 0.3) {
2038
+ intensity = this.ease(point.age / (this.maxAge * 0.3));
2039
+ }
2040
+ else {
2041
+ intensity = this.ease(1 - (point.age - this.maxAge * 0.3) / (this.maxAge * 0.7));
2042
+ }
2043
+ intensity *= point.force;
2044
+ // apply blending
2045
+ this.ctx.globalCompositeOperation = this.blend;
2046
+ const radius = this.size * this.radius * intensity;
2047
+ const grd = this.ctx.createRadialGradient(pos.x, pos.y, Math.max(0, radius * 0.25), pos.x, pos.y, Math.max(0, radius));
2048
+ grd.addColorStop(0, `rgba(255, 255, 255, ${this.intensity})`);
2049
+ grd.addColorStop(1, `rgba(0, 0, 0, 0.0)`);
2050
+ this.ctx.beginPath();
2051
+ this.ctx.fillStyle = grd;
2052
+ this.ctx.arc(pos.x, pos.y, Math.max(0, radius), 0, Math.PI * 2);
2053
+ this.ctx.fill();
2054
+ }
2055
+ }
2056
+
2057
+ function injectNgtsTrailTexture(trailConfigFn, { injector } = {}) {
2058
+ injector = assertInjector(injectNgtsTrailTexture, injector);
2059
+ return runInInjectionContext(injector, () => {
2060
+ const trail = computed(() => new TrailTexture(trailConfigFn() || {}));
2061
+ const texture = computed(() => trail().texture);
2062
+ injectBeforeRender(({ delta }) => {
2063
+ trail().update(delta);
2064
+ });
2065
+ const onMove = (ev) => trail().addTouch(ev.uv);
2066
+ return { texture, onMove };
2067
+ });
2068
+ }
2069
+
2070
+ const shiftLeft = (collection, steps = 1) => {
2071
+ collection.set(collection.subarray(steps));
2072
+ collection.fill(-Infinity, -steps);
2073
+ return collection;
2074
+ };
2075
+ const defaultSettings = {
2076
+ width: 0.2,
2077
+ length: 1,
2078
+ decay: 1,
2079
+ local: false,
2080
+ stride: 0,
2081
+ interval: 1,
2082
+ };
2083
+ function injectNgtsTrail(targetFactory, settingsFactory, { injector } = {}) {
2084
+ injector = assertInjector(injectNgtsTrail, injector);
2085
+ return runInInjectionContext(injector, () => {
2086
+ const _points = signal(new Float32Array());
2087
+ let frameCount = 0;
2088
+ const prevPosition = new THREE.Vector3();
2089
+ const worldPosition = new THREE.Vector3();
2090
+ const _target = computed(() => {
2091
+ const _target = targetFactory();
2092
+ if (is.ref(_target))
2093
+ return _target.nativeElement;
2094
+ return _target;
2095
+ });
2096
+ const _settings = computed(() => ({ ...defaultSettings, ...settingsFactory() }));
2097
+ const _length = computed(() => _settings().length);
2098
+ effect(() => {
2099
+ const [target, length] = [_target(), _length()];
2100
+ if (target) {
2101
+ untracked(() => {
2102
+ _points.set(Float32Array.from({ length: length * 10 * 3 }, (_, i) => target.position.getComponent(i % 3)));
2103
+ });
2104
+ }
2105
+ });
2106
+ injectBeforeRender(() => {
2107
+ const [target, points, { local, decay, stride, interval }] = [_target(), _points(), _settings()];
2108
+ if (!target || !points)
2109
+ return;
2110
+ if (frameCount === 0) {
2111
+ let newPosition;
2112
+ if (local) {
2113
+ newPosition = target.position;
2114
+ }
2115
+ else {
2116
+ target.getWorldPosition(worldPosition);
2117
+ newPosition = worldPosition;
2118
+ }
2119
+ const steps = 1 * decay;
2120
+ for (let i = 0; i < steps; i++) {
2121
+ if (newPosition.distanceTo(prevPosition) < stride)
2122
+ continue;
2123
+ shiftLeft(points, 3);
2124
+ points.set(newPosition.toArray(), points.length - 3);
2125
+ }
2126
+ prevPosition.copy(newPosition);
2127
+ }
2128
+ frameCount++;
2129
+ frameCount = frameCount % interval;
2130
+ });
2131
+ return _points.asReadonly();
161
2132
  });
162
2133
  }
2134
+ extend({ Group, Mesh });
2135
+ class NgtsTrail {
2136
+ set _color(color) {
2137
+ this.inputs.set({ color });
2138
+ }
2139
+ set _attenuation(attenuation) {
2140
+ this.inputs.set({ attenuation });
2141
+ }
2142
+ set _target(target) {
2143
+ this.inputs.set({ target });
2144
+ }
2145
+ set _settings(settings) {
2146
+ this.inputs.set({ settings: { ...defaultSettings, ...settings } });
2147
+ }
2148
+ constructor() {
2149
+ this.inputs = signalStore({ settings: defaultSettings, color: 'hotpink' });
2150
+ this.trailRef = injectNgtRef();
2151
+ this.groupRef = injectNgtRef();
2152
+ this.children = this.groupRef.children('both');
2153
+ this.store = injectNgtStore();
2154
+ this.size = this.store.select('size');
2155
+ this.target = this.inputs.select('target');
2156
+ this.settings = this.inputs.select('settings');
2157
+ this.width = computed(() => this.settings().width);
2158
+ this.color = this.inputs.select('color');
2159
+ this.attenuation = this.inputs.select('attenuation');
2160
+ this.anchor = computed(() => {
2161
+ const target = this.target();
2162
+ if (target)
2163
+ return target;
2164
+ const group = this.groupRef.nativeElement;
2165
+ if (group) {
2166
+ return group.children.find((child) => child instanceof THREE.Object3D) || null;
2167
+ }
2168
+ return null;
2169
+ });
2170
+ this.points = injectNgtsTrail(this.anchor, this.settings);
2171
+ this.scene = this.store.select('scene');
2172
+ this.geometry = new MeshLineGeometry();
2173
+ this.material = computed(() => {
2174
+ const [width, color, size] = [this.width(), this.color(), this.size()];
2175
+ const m = new MeshLineMaterial({
2176
+ lineWidth: 0.1 * width,
2177
+ color,
2178
+ sizeAttenuation: 1,
2179
+ resolution: new THREE.Vector2(size.width, size.height),
2180
+ });
2181
+ // TODO: understand this first
2182
+ // Get and apply first <meshLineMaterial /> from children
2183
+ // let matOverride: React.ReactElement | undefined;
2184
+ // if (children) {
2185
+ // if (Array.isArray(children)) {
2186
+ // matOverride = children.find((child: React.ReactNode) => {
2187
+ // const c = child as React.ReactElement;
2188
+ // return typeof c.type === 'string' && c.type === 'meshLineMaterial';
2189
+ // }) as React.ReactElement | undefined;
2190
+ // } else {
2191
+ // const c = children as React.ReactElement;
2192
+ // if (typeof c.type === 'string' && c.type === 'meshLineMaterial') {
2193
+ // matOverride = c;
2194
+ // }
2195
+ // }
2196
+ // }
2197
+ // if (typeof matOverride?.props === 'object') {
2198
+ // m.setValues(matOverride.props);
2199
+ // }
2200
+ return m;
2201
+ });
2202
+ this.setMaterialSize();
2203
+ this.beforeRender();
2204
+ }
2205
+ setMaterialSize() {
2206
+ effect(() => {
2207
+ const [material, size] = [this.material(), this.size()];
2208
+ material.uniforms['resolution'].value.set(size.width, size.height);
2209
+ });
2210
+ }
2211
+ beforeRender() {
2212
+ injectBeforeRender(() => {
2213
+ const [points, attenuation] = [this.points(), this.attenuation()];
2214
+ this.geometry.setPoints(points, attenuation);
2215
+ });
2216
+ }
2217
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsTrail, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2218
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: NgtsTrail, isStandalone: true, selector: "ngts-trail", inputs: { trailRef: "trailRef", _color: ["color", "_color"], _attenuation: ["attenuation", "_attenuation"], _target: ["target", "_target"], _settings: ["settings", "_settings"] }, ngImport: i0, template: `
2219
+ <ngt-group>
2220
+ <ngt-portal [container]="scene()" [autoRender]="false">
2221
+ <ng-template ngtPortalContent>
2222
+ <ngt-mesh [ref]="trailRef" [geometry]="geometry" [material]="material()" />
2223
+ </ng-template>
2224
+ </ngt-portal>
2225
+ <ngt-group [ref]="groupRef">
2226
+ <ng-content />
2227
+ </ngt-group>
2228
+ </ngt-group>
2229
+ `, isInline: true, dependencies: [{ kind: "component", type: NgtPortal, selector: "ngt-portal", inputs: ["container", "state", "autoRender", "autoRenderPriority"], outputs: ["beforeRender"] }, { kind: "directive", type: NgtPortalContent, selector: "ng-template[ngtPortalContent]" }] }); }
2230
+ }
2231
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: NgtsTrail, decorators: [{
2232
+ type: Component,
2233
+ args: [{
2234
+ selector: 'ngts-trail',
2235
+ standalone: true,
2236
+ template: `
2237
+ <ngt-group>
2238
+ <ngt-portal [container]="scene()" [autoRender]="false">
2239
+ <ng-template ngtPortalContent>
2240
+ <ngt-mesh [ref]="trailRef" [geometry]="geometry" [material]="material()" />
2241
+ </ng-template>
2242
+ </ngt-portal>
2243
+ <ngt-group [ref]="groupRef">
2244
+ <ng-content />
2245
+ </ngt-group>
2246
+ </ngt-group>
2247
+ `,
2248
+ imports: [NgtPortal, NgtPortalContent],
2249
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
2250
+ }]
2251
+ }], ctorParameters: function () { return []; }, propDecorators: { trailRef: [{
2252
+ type: Input
2253
+ }], _color: [{
2254
+ type: Input,
2255
+ args: [{ alias: 'color' }]
2256
+ }], _attenuation: [{
2257
+ type: Input,
2258
+ args: [{ alias: 'attenuation' }]
2259
+ }], _target: [{
2260
+ type: Input,
2261
+ args: [{ alias: 'target' }]
2262
+ }], _settings: [{
2263
+ type: Input,
2264
+ args: [{ alias: 'settings' }]
2265
+ }] } });
163
2266
 
164
2267
  /**
165
2268
  * Generated bundle index. Do not edit.
166
2269
  */
167
2270
 
168
- export { NgtsBakeShadows, injectNgtsAnimations, injectNgtsDepthBuffer, injectNgtsFBO };
2271
+ export { NgtsBakeShadows, NgtsCaustics, NgtsDecal, NgtsExample, NgtsHtml, NgtsSampler, NgtsShadow, NgtsStatsGL, NgtsTrail, injectNgtsAnimations, injectNgtsDepthBuffer, injectNgtsExampleApi, injectNgtsFBO, injectNgtsHtmlInputs, injectNgtsSurfaceSampler, injectNgtsTrail, injectNgtsTrailTexture, provideNgtsExampleApi, provideNgtsHtmlInputs };
169
2272
  //# sourceMappingURL=angular-three-soba-misc.mjs.map