angular-three-soba 2.0.0-beta.26 → 2.0.0-beta.261

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