@lightningjs/renderer 3.0.0-beta6 → 3.0.0-beta8

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 (497) hide show
  1. package/COPYING +1 -0
  2. package/LICENSE +202 -202
  3. package/NOTICE +3 -3
  4. package/README.md +147 -147
  5. package/dist/exports/utils.d.ts +2 -1
  6. package/dist/exports/utils.js +2 -1
  7. package/dist/exports/utils.js.map +1 -1
  8. package/dist/src/core/CoreNode.d.ts +33 -49
  9. package/dist/src/core/CoreNode.js +268 -255
  10. package/dist/src/core/CoreNode.js.map +1 -1
  11. package/dist/src/core/CoreTextNode.d.ts +1 -1
  12. package/dist/src/core/CoreTextNode.js +14 -15
  13. package/dist/src/core/CoreTextNode.js.map +1 -1
  14. package/dist/src/core/CoreTextureManager.js +11 -4
  15. package/dist/src/core/CoreTextureManager.js.map +1 -1
  16. package/dist/src/core/Stage.d.ts +27 -26
  17. package/dist/src/core/Stage.js +88 -36
  18. package/dist/src/core/Stage.js.map +1 -1
  19. package/dist/src/core/TextureMemoryManager.d.ts +9 -0
  20. package/dist/src/core/TextureMemoryManager.js +78 -48
  21. package/dist/src/core/TextureMemoryManager.js.map +1 -1
  22. package/dist/src/core/animations/CoreAnimation.js +5 -0
  23. package/dist/src/core/animations/CoreAnimation.js.map +1 -1
  24. package/dist/src/core/animations/CoreAnimationController.d.ts +1 -0
  25. package/dist/src/core/animations/CoreAnimationController.js +7 -1
  26. package/dist/src/core/animations/CoreAnimationController.js.map +1 -1
  27. package/dist/src/core/lib/ImageWorker.js +1 -1
  28. package/dist/src/core/lib/ImageWorker.js.map +1 -1
  29. package/dist/src/core/lib/utils.d.ts +1 -0
  30. package/dist/src/core/lib/utils.js +3 -0
  31. package/dist/src/core/lib/utils.js.map +1 -1
  32. package/dist/src/core/renderers/CoreRenderer.d.ts +1 -0
  33. package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
  34. package/dist/src/core/renderers/CoreShaderNode.d.ts +1 -0
  35. package/dist/src/core/renderers/CoreShaderNode.js +9 -0
  36. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -1
  37. package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +1 -0
  38. package/dist/src/core/renderers/canvas/CanvasRenderer.js +3 -0
  39. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
  40. package/dist/src/core/renderers/canvas/CanvasShaderNode.js +1 -4
  41. package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -1
  42. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +0 -3
  43. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -1
  44. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +2 -2
  45. package/dist/src/core/renderers/webgl/WebGlRenderer.js +57 -57
  46. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  47. package/dist/src/core/renderers/webgl/WebGlShaderNode.js +1 -4
  48. package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -1
  49. package/dist/src/core/renderers/webgl/internal/ShaderUtils.js +35 -35
  50. package/dist/src/core/shaders/canvas/LinearGradient.js +5 -3
  51. package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -1
  52. package/dist/src/core/shaders/canvas/RadialGradient.js +13 -11
  53. package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -1
  54. package/dist/src/core/shaders/canvas/RoundedWithBorder.js +7 -5
  55. package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -1
  56. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +10 -8
  57. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -1
  58. package/dist/src/core/shaders/canvas/RoundedWithShadow.js +7 -5
  59. package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -1
  60. package/dist/src/core/shaders/templates/BorderTemplate.d.ts +1 -1
  61. package/dist/src/core/shaders/templates/BorderTemplate.js +1 -1
  62. package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -1
  63. package/dist/src/core/shaders/templates/HolePunchTemplate.js +1 -1
  64. package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +1 -1
  65. package/dist/src/core/shaders/templates/RoundedTemplate.js +1 -1
  66. package/dist/src/core/shaders/templates/RoundedTemplate.js.map +1 -1
  67. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.d.ts +1 -1
  68. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.d.ts +1 -1
  69. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.d.ts +1 -1
  70. package/dist/src/core/shaders/templates/ShadowTemplate.d.ts +1 -1
  71. package/dist/src/core/shaders/{templates/shaderUtils.d.ts → utils.d.ts} +1 -1
  72. package/dist/src/core/shaders/{templates/shaderUtils.js → utils.js} +2 -2
  73. package/dist/src/core/shaders/utils.js.map +1 -0
  74. package/dist/src/core/shaders/webgl/Border.js +82 -82
  75. package/dist/src/core/shaders/webgl/Default.js +47 -47
  76. package/dist/src/core/shaders/webgl/DefaultBatched.js +61 -61
  77. package/dist/src/core/shaders/webgl/HolePunch.js +36 -35
  78. package/dist/src/core/shaders/webgl/HolePunch.js.map +1 -1
  79. package/dist/src/core/shaders/webgl/LinearGradient.js +41 -40
  80. package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -1
  81. package/dist/src/core/shaders/webgl/RadialGradient.js +39 -38
  82. package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -1
  83. package/dist/src/core/shaders/webgl/Rounded.js +71 -71
  84. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +111 -100
  85. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -1
  86. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +136 -123
  87. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
  88. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +54 -54
  89. package/dist/src/core/shaders/webgl/SdfShader.js +62 -62
  90. package/dist/src/core/shaders/webgl/Shadow.js +83 -83
  91. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +0 -50
  92. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +1 -1
  93. package/dist/src/core/textures/ImageTexture.d.ts +1 -1
  94. package/dist/src/core/textures/ImageTexture.js +6 -1
  95. package/dist/src/core/textures/ImageTexture.js.map +1 -1
  96. package/dist/src/core/textures/Texture.d.ts +8 -0
  97. package/dist/src/core/textures/Texture.js +13 -0
  98. package/dist/src/core/textures/Texture.js.map +1 -1
  99. package/dist/src/core/utils.d.ts +1 -1
  100. package/dist/src/main-api/Inspector.d.ts +6 -1
  101. package/dist/src/main-api/Inspector.js +42 -4
  102. package/dist/src/main-api/Inspector.js.map +1 -1
  103. package/dist/src/main-api/Renderer.d.ts +62 -43
  104. package/dist/src/main-api/Renderer.js +119 -31
  105. package/dist/src/main-api/Renderer.js.map +1 -1
  106. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  107. package/exports/canvas-shaders.ts +28 -28
  108. package/exports/canvas.ts +45 -45
  109. package/exports/index.ts +90 -90
  110. package/exports/inspector.ts +24 -24
  111. package/exports/utils.ts +50 -44
  112. package/exports/webgl-shaders.ts +28 -28
  113. package/exports/webgl.ts +50 -50
  114. package/package.json +1 -2
  115. package/src/common/CommonTypes.ts +146 -146
  116. package/src/common/EventEmitter.ts +77 -77
  117. package/src/common/IAnimationController.ts +92 -92
  118. package/src/common/IEventEmitter.ts +28 -28
  119. package/src/core/CoreNode.test.ts +202 -202
  120. package/src/core/CoreNode.ts +2483 -2469
  121. package/src/core/CoreShaderManager.ts +188 -188
  122. package/src/core/CoreTextNode.ts +451 -448
  123. package/src/core/CoreTextureManager.ts +608 -600
  124. package/src/core/Stage.ts +800 -751
  125. package/src/core/TextureMemoryManager.ts +435 -394
  126. package/src/core/animations/AnimationManager.ts +38 -38
  127. package/src/core/animations/CoreAnimation.ts +291 -284
  128. package/src/core/animations/CoreAnimationController.ts +164 -157
  129. package/src/core/lib/ContextSpy.ts +41 -41
  130. package/src/core/lib/ImageWorker.ts +286 -280
  131. package/src/core/lib/Matrix3d.ts +244 -244
  132. package/src/core/lib/RenderCoords.ts +71 -71
  133. package/src/core/lib/WebGlContextWrapper.ts +1374 -1374
  134. package/src/core/lib/textureCompression.ts +152 -152
  135. package/src/core/lib/textureSvg.ts +78 -78
  136. package/src/core/lib/utils.ts +390 -386
  137. package/src/core/lib/validateImageBitmap.ts +87 -87
  138. package/src/core/platforms/Platform.ts +77 -77
  139. package/src/core/platforms/web/WebPlatform.ts +84 -84
  140. package/src/core/renderers/CoreContextTexture.ts +43 -43
  141. package/src/core/renderers/CoreRenderOp.ts +22 -22
  142. package/src/core/renderers/CoreRenderer.ts +110 -109
  143. package/src/core/renderers/CoreShaderNode.ts +175 -165
  144. package/src/core/renderers/CoreShaderProgram.ts +23 -23
  145. package/src/core/renderers/canvas/CanvasRenderer.ts +302 -298
  146. package/src/core/renderers/canvas/CanvasShaderNode.ts +96 -99
  147. package/src/core/renderers/canvas/CanvasTexture.ts +156 -156
  148. package/src/core/renderers/canvas/internal/C2DShaderUtils.ts +220 -220
  149. package/src/core/renderers/canvas/internal/ColorUtils.ts +85 -85
  150. package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +86 -86
  151. package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +50 -50
  152. package/src/core/renderers/webgl/WebGlCtxTexture.ts +298 -301
  153. package/src/core/renderers/webgl/WebGlRenderOp.ts +161 -161
  154. package/src/core/renderers/webgl/WebGlRenderer.ts +747 -750
  155. package/src/core/renderers/webgl/WebGlShaderNode.ts +435 -437
  156. package/src/core/renderers/webgl/WebGlShaderProgram.ts +318 -318
  157. package/src/core/renderers/webgl/internal/BufferCollection.ts +54 -54
  158. package/src/core/renderers/webgl/internal/RendererUtils.ts +155 -155
  159. package/src/core/renderers/webgl/internal/ShaderUtils.ts +281 -281
  160. package/src/core/renderers/webgl/internal/WebGlUtils.ts +35 -35
  161. package/src/core/shaders/canvas/Border.ts +78 -78
  162. package/src/core/shaders/canvas/HolePunch.ts +62 -62
  163. package/src/core/shaders/canvas/LinearGradient.ts +71 -69
  164. package/src/core/shaders/canvas/RadialGradient.ts +99 -113
  165. package/src/core/shaders/canvas/Rounded.ts +55 -55
  166. package/src/core/shaders/canvas/RoundedWithBorder.ts +74 -72
  167. package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +90 -88
  168. package/src/core/shaders/canvas/RoundedWithShadow.ts +70 -69
  169. package/src/core/shaders/canvas/Shadow.ts +52 -52
  170. package/src/core/shaders/canvas/utils/render.ts +151 -151
  171. package/src/core/shaders/templates/BorderTemplate.ts +115 -115
  172. package/src/core/shaders/templates/HolePunchTemplate.ts +82 -82
  173. package/src/core/shaders/templates/LinearGradientTemplate.ts +71 -71
  174. package/src/core/shaders/templates/RadialGradientTemplate.ts +81 -81
  175. package/src/core/shaders/templates/RoundedTemplate.ts +98 -98
  176. package/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.ts +38 -38
  177. package/src/core/shaders/templates/RoundedWithBorderTemplate.ts +35 -35
  178. package/src/core/shaders/templates/RoundedWithShadowTemplate.ts +35 -35
  179. package/src/core/shaders/templates/ShadowTemplate.ts +106 -106
  180. package/src/core/shaders/{templates/shaderUtils.ts → utils.ts} +46 -47
  181. package/src/core/shaders/webgl/Border.ts +116 -116
  182. package/src/core/shaders/webgl/Default.ts +89 -89
  183. package/src/core/shaders/webgl/DefaultBatched.ts +129 -129
  184. package/src/core/shaders/webgl/HolePunch.ts +75 -78
  185. package/src/core/shaders/webgl/LinearGradient.ts +82 -81
  186. package/src/core/shaders/webgl/RadialGradient.ts +85 -84
  187. package/src/core/shaders/webgl/Rounded.ts +117 -117
  188. package/src/core/shaders/webgl/RoundedWithBorder.ts +155 -144
  189. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +175 -166
  190. package/src/core/shaders/webgl/RoundedWithShadow.ts +98 -98
  191. package/src/core/shaders/webgl/SdfShader.ts +134 -134
  192. package/src/core/shaders/webgl/Shadow.ts +115 -115
  193. package/src/core/text-rendering/TextRenderingUtils.ts +36 -36
  194. package/src/core/text-rendering/TextTextureRendererUtils.ts +263 -263
  195. package/src/core/text-rendering/TrFontManager.ts +183 -183
  196. package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +176 -176
  197. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.ts +139 -139
  198. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.test.ts +173 -173
  199. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.ts +171 -171
  200. package/src/core/text-rendering/font-face-types/TrFontFace.ts +187 -187
  201. package/src/core/text-rendering/font-face-types/WebTrFontFace.ts +94 -94
  202. package/src/core/text-rendering/font-face-types/utils.ts +39 -39
  203. package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +514 -514
  204. package/src/core/text-rendering/renderers/LightningTextTextureRenderer.ts +863 -863
  205. package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +793 -849
  206. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.test.ts +48 -48
  207. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.ts +66 -66
  208. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.ts +52 -52
  209. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.ts +32 -32
  210. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.ts +117 -117
  211. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.test.ts +133 -133
  212. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.ts +38 -38
  213. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.ts +497 -497
  214. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.test.ts +49 -49
  215. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.ts +52 -52
  216. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.test.ts +205 -205
  217. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.ts +93 -93
  218. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.ts +40 -40
  219. package/src/core/text-rendering/renderers/TextRenderer.ts +567 -567
  220. package/src/core/textures/ColorTexture.ts +102 -102
  221. package/src/core/textures/ImageTexture.ts +418 -410
  222. package/src/core/textures/NoiseTexture.ts +104 -104
  223. package/src/core/textures/RenderTexture.ts +85 -85
  224. package/src/core/textures/SubTexture.ts +205 -205
  225. package/src/core/textures/Texture.ts +372 -358
  226. package/src/core/utils.ts +227 -227
  227. package/src/env.d.ts +7 -7
  228. package/src/main-api/INode.ts +100 -100
  229. package/src/main-api/Inspector.ts +569 -522
  230. package/src/main-api/Renderer.ts +818 -673
  231. package/src/main-api/utils.ts +45 -45
  232. package/src/utils.ts +267 -267
  233. package/dist/exports/core-api.d.ts +0 -74
  234. package/dist/exports/core-api.js +0 -96
  235. package/dist/exports/core-api.js.map +0 -1
  236. package/dist/exports/main-api.d.ts +0 -30
  237. package/dist/exports/main-api.js +0 -45
  238. package/dist/exports/main-api.js.map +0 -1
  239. package/dist/src/core/CoreExtension.d.ts +0 -12
  240. package/dist/src/core/CoreExtension.js +0 -29
  241. package/dist/src/core/CoreExtension.js.map +0 -1
  242. package/dist/src/core/CoreStuff.d.ts +0 -1
  243. package/dist/src/core/CoreStuff.js +0 -138
  244. package/dist/src/core/CoreStuff.js.map +0 -1
  245. package/dist/src/core/CoreTexturizer.d.ts +0 -14
  246. package/dist/src/core/CoreTexturizer.js +0 -47
  247. package/dist/src/core/CoreTexturizer.js.map +0 -1
  248. package/dist/src/core/LngNode.d.ts +0 -736
  249. package/dist/src/core/LngNode.js +0 -1174
  250. package/dist/src/core/LngNode.js.map +0 -1
  251. package/dist/src/core/Matrix2DContext.d.ts +0 -15
  252. package/dist/src/core/Matrix2DContext.js +0 -45
  253. package/dist/src/core/Matrix2DContext.js.map +0 -1
  254. package/dist/src/core/ShaderNode.d.ts +0 -10
  255. package/dist/src/core/ShaderNode.js +0 -30
  256. package/dist/src/core/ShaderNode.js.map +0 -1
  257. package/dist/src/core/TextNode.d.ts +0 -103
  258. package/dist/src/core/TextNode.js +0 -331
  259. package/dist/src/core/TextNode.js.map +0 -1
  260. package/dist/src/core/lib/Coords.d.ts +0 -14
  261. package/dist/src/core/lib/Coords.js +0 -55
  262. package/dist/src/core/lib/Coords.js.map +0 -1
  263. package/dist/src/core/lib/glm/common.d.ts +0 -162
  264. package/dist/src/core/lib/glm/common.js +0 -81
  265. package/dist/src/core/lib/glm/common.js.map +0 -1
  266. package/dist/src/core/lib/glm/index.d.ts +0 -11
  267. package/dist/src/core/lib/glm/index.js +0 -30
  268. package/dist/src/core/lib/glm/index.js.map +0 -1
  269. package/dist/src/core/lib/glm/mat2.d.ts +0 -219
  270. package/dist/src/core/lib/glm/mat2.js +0 -396
  271. package/dist/src/core/lib/glm/mat2.js.map +0 -1
  272. package/dist/src/core/lib/glm/mat2d.d.ts +0 -237
  273. package/dist/src/core/lib/glm/mat2d.js +0 -442
  274. package/dist/src/core/lib/glm/mat2d.js.map +0 -1
  275. package/dist/src/core/lib/glm/mat3.d.ts +0 -283
  276. package/dist/src/core/lib/glm/mat3.js +0 -680
  277. package/dist/src/core/lib/glm/mat3.js.map +0 -1
  278. package/dist/src/core/lib/glm/mat4.d.ts +0 -550
  279. package/dist/src/core/lib/glm/mat4.js +0 -1802
  280. package/dist/src/core/lib/glm/mat4.js.map +0 -1
  281. package/dist/src/core/lib/glm/quat.d.ts +0 -363
  282. package/dist/src/core/lib/glm/quat.js +0 -693
  283. package/dist/src/core/lib/glm/quat.js.map +0 -1
  284. package/dist/src/core/lib/glm/quat2.d.ts +0 -356
  285. package/dist/src/core/lib/glm/quat2.js +0 -754
  286. package/dist/src/core/lib/glm/quat2.js.map +0 -1
  287. package/dist/src/core/lib/glm/vec2.d.ts +0 -365
  288. package/dist/src/core/lib/glm/vec2.js +0 -569
  289. package/dist/src/core/lib/glm/vec2.js.map +0 -1
  290. package/dist/src/core/lib/glm/vec3.d.ts +0 -406
  291. package/dist/src/core/lib/glm/vec3.js +0 -720
  292. package/dist/src/core/lib/glm/vec3.js.map +0 -1
  293. package/dist/src/core/lib/glm/vec4.d.ts +0 -330
  294. package/dist/src/core/lib/glm/vec4.js +0 -608
  295. package/dist/src/core/lib/glm/vec4.js.map +0 -1
  296. package/dist/src/core/platform.d.ts +0 -10
  297. package/dist/src/core/platform.js +0 -56
  298. package/dist/src/core/platform.js.map +0 -1
  299. package/dist/src/core/renderers/CoreShader.d.ts +0 -9
  300. package/dist/src/core/renderers/CoreShader.js +0 -28
  301. package/dist/src/core/renderers/CoreShader.js.map +0 -1
  302. package/dist/src/core/renderers/CoreShaderManager.d.ts +0 -19
  303. package/dist/src/core/renderers/CoreShaderManager.js +0 -33
  304. package/dist/src/core/renderers/CoreShaderManager.js.map +0 -1
  305. package/dist/src/core/renderers/canvas/CanvasCoreRenderer.d.ts +0 -33
  306. package/dist/src/core/renderers/canvas/CanvasCoreRenderer.js +0 -250
  307. package/dist/src/core/renderers/canvas/CanvasCoreRenderer.js.map +0 -1
  308. package/dist/src/core/renderers/canvas/CanvasCoreTexture.d.ts +0 -16
  309. package/dist/src/core/renderers/canvas/CanvasCoreTexture.js +0 -123
  310. package/dist/src/core/renderers/canvas/CanvasCoreTexture.js.map +0 -1
  311. package/dist/src/core/renderers/canvas/shaders/UnsupportedShader.d.ts +0 -10
  312. package/dist/src/core/renderers/canvas/shaders/UnsupportedShader.js +0 -43
  313. package/dist/src/core/renderers/canvas/shaders/UnsupportedShader.js.map +0 -1
  314. package/dist/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.d.ts +0 -12
  315. package/dist/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.js +0 -55
  316. package/dist/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.js.map +0 -1
  317. package/dist/src/core/renderers/webgl/WebGlCoreCtxSubTexture.d.ts +0 -9
  318. package/dist/src/core/renderers/webgl/WebGlCoreCtxSubTexture.js +0 -38
  319. package/dist/src/core/renderers/webgl/WebGlCoreCtxSubTexture.js.map +0 -1
  320. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.d.ts +0 -57
  321. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js +0 -227
  322. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js.map +0 -1
  323. package/dist/src/core/renderers/webgl/WebGlCoreRenderOp.d.ts +0 -34
  324. package/dist/src/core/renderers/webgl/WebGlCoreRenderOp.js +0 -114
  325. package/dist/src/core/renderers/webgl/WebGlCoreRenderOp.js.map +0 -1
  326. package/dist/src/core/renderers/webgl/WebGlCoreRenderer.d.ts +0 -133
  327. package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +0 -613
  328. package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +0 -1
  329. package/dist/src/core/renderers/webgl/WebGlCoreShader.d.ts +0 -83
  330. package/dist/src/core/renderers/webgl/WebGlCoreShader.js +0 -231
  331. package/dist/src/core/renderers/webgl/WebGlCoreShader.js.map +0 -1
  332. package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.d.ts +0 -27
  333. package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.js +0 -82
  334. package/dist/src/core/renderers/webgl/WebGlCoreShaderManager.js.map +0 -1
  335. package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.d.ts +0 -11
  336. package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.js +0 -34
  337. package/dist/src/core/renderers/webgl/WebGlCoreShaderProgram.js.map +0 -1
  338. package/dist/src/core/renderers/webgl/shaders/DefaultShader.d.ts +0 -9
  339. package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +0 -87
  340. package/dist/src/core/renderers/webgl/shaders/DefaultShader.js.map +0 -1
  341. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.d.ts +0 -10
  342. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +0 -119
  343. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js.map +0 -1
  344. package/dist/src/core/renderers/webgl/shaders/DynamicShader.d.ts +0 -29
  345. package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +0 -413
  346. package/dist/src/core/renderers/webgl/shaders/DynamicShader.js.map +0 -1
  347. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.d.ts +0 -28
  348. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +0 -131
  349. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js.map +0 -1
  350. package/dist/src/core/renderers/webgl/shaders/SdfShader.d.ts +0 -47
  351. package/dist/src/core/renderers/webgl/shaders/SdfShader.js +0 -160
  352. package/dist/src/core/renderers/webgl/shaders/SdfShader.js.map +0 -1
  353. package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.d.ts +0 -31
  354. package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +0 -71
  355. package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js.map +0 -1
  356. package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.d.ts +0 -30
  357. package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +0 -58
  358. package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js.map +0 -1
  359. package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.d.ts +0 -31
  360. package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +0 -71
  361. package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js.map +0 -1
  362. package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.d.ts +0 -31
  363. package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +0 -71
  364. package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js.map +0 -1
  365. package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.d.ts +0 -31
  366. package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +0 -71
  367. package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js.map +0 -1
  368. package/dist/src/core/renderers/webgl/shaders/effects/EffectUtils.d.ts +0 -9
  369. package/dist/src/core/renderers/webgl/shaders/effects/EffectUtils.js +0 -136
  370. package/dist/src/core/renderers/webgl/shaders/effects/EffectUtils.js.map +0 -1
  371. package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.d.ts +0 -36
  372. package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +0 -85
  373. package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js.map +0 -1
  374. package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.d.ts +0 -45
  375. package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +0 -104
  376. package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js.map +0 -1
  377. package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.d.ts +0 -22
  378. package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +0 -45
  379. package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js.map +0 -1
  380. package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.d.ts +0 -58
  381. package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js +0 -80
  382. package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js.map +0 -1
  383. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.d.ts +0 -35
  384. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +0 -129
  385. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js.map +0 -1
  386. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.d.ts +0 -39
  387. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +0 -116
  388. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js.map +0 -1
  389. package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.d.ts +0 -61
  390. package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +0 -127
  391. package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js.map +0 -1
  392. package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.d.ts +0 -40
  393. package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +0 -71
  394. package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js.map +0 -1
  395. package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.d.ts +0 -115
  396. package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.js +0 -61
  397. package/dist/src/core/renderers/webgl/shaders/effects/ShaderEffect.js.map +0 -1
  398. package/dist/src/core/scene/Scene.d.ts +0 -59
  399. package/dist/src/core/scene/Scene.js +0 -106
  400. package/dist/src/core/scene/Scene.js.map +0 -1
  401. package/dist/src/core/shaders/templates/shaderUtils.js.map +0 -1
  402. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.d.ts +0 -20
  403. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js +0 -55
  404. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js.map +0 -1
  405. package/dist/src/main-api/DynamicShaderController.d.ts +0 -29
  406. package/dist/src/main-api/DynamicShaderController.js +0 -58
  407. package/dist/src/main-api/DynamicShaderController.js.map +0 -1
  408. package/dist/src/main-api/ICoreDriver.d.ts +0 -27
  409. package/dist/src/main-api/ICoreDriver.js +0 -20
  410. package/dist/src/main-api/ICoreDriver.js.map +0 -1
  411. package/dist/src/main-api/IRenderDriver.d.ts +0 -20
  412. package/dist/src/main-api/IRenderDriver.js +0 -20
  413. package/dist/src/main-api/IRenderDriver.js.map +0 -1
  414. package/dist/src/main-api/IShaderController.d.ts +0 -14
  415. package/dist/src/main-api/IShaderController.js +0 -30
  416. package/dist/src/main-api/IShaderController.js.map +0 -1
  417. package/dist/src/main-api/IShaderNode.d.ts +0 -17
  418. package/dist/src/main-api/IShaderNode.js +0 -19
  419. package/dist/src/main-api/IShaderNode.js.map +0 -1
  420. package/dist/src/main-api/RendererMain.d.ts +0 -375
  421. package/dist/src/main-api/RendererMain.js +0 -365
  422. package/dist/src/main-api/RendererMain.js.map +0 -1
  423. package/dist/src/main-api/ShaderController.d.ts +0 -31
  424. package/dist/src/main-api/ShaderController.js +0 -37
  425. package/dist/src/main-api/ShaderController.js.map +0 -1
  426. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.d.ts +0 -9
  427. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js +0 -38
  428. package/dist/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.js.map +0 -1
  429. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.d.ts +0 -56
  430. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js +0 -101
  431. package/dist/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.js.map +0 -1
  432. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.d.ts +0 -32
  433. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js +0 -28
  434. package/dist/src/main-api/texture-usage-trackers/TextureUsageTracker.js.map +0 -1
  435. package/dist/src/render-drivers/main/MainCoreDriver.d.ts +0 -24
  436. package/dist/src/render-drivers/main/MainCoreDriver.js +0 -118
  437. package/dist/src/render-drivers/main/MainCoreDriver.js.map +0 -1
  438. package/dist/src/render-drivers/main/MainOnlyNode.d.ts +0 -99
  439. package/dist/src/render-drivers/main/MainOnlyNode.js +0 -396
  440. package/dist/src/render-drivers/main/MainOnlyNode.js.map +0 -1
  441. package/dist/src/render-drivers/main/MainOnlyShaderController.d.ts +0 -6
  442. package/dist/src/render-drivers/main/MainOnlyShaderController.js +0 -15
  443. package/dist/src/render-drivers/main/MainOnlyShaderController.js.map +0 -1
  444. package/dist/src/render-drivers/main/MainOnlyShaderNode.d.ts +0 -7
  445. package/dist/src/render-drivers/main/MainOnlyShaderNode.js +0 -34
  446. package/dist/src/render-drivers/main/MainOnlyShaderNode.js.map +0 -1
  447. package/dist/src/render-drivers/main/MainOnlyTextNode.d.ts +0 -47
  448. package/dist/src/render-drivers/main/MainOnlyTextNode.js +0 -205
  449. package/dist/src/render-drivers/main/MainOnlyTextNode.js.map +0 -1
  450. package/dist/src/render-drivers/main/MainRenderDriver.d.ts +0 -17
  451. package/dist/src/render-drivers/main/MainRenderDriver.js +0 -88
  452. package/dist/src/render-drivers/main/MainRenderDriver.js.map +0 -1
  453. package/dist/src/render-drivers/threadx/NodeStruct.d.ts +0 -90
  454. package/dist/src/render-drivers/threadx/NodeStruct.js +0 -281
  455. package/dist/src/render-drivers/threadx/NodeStruct.js.map +0 -1
  456. package/dist/src/render-drivers/threadx/SharedNode.d.ts +0 -39
  457. package/dist/src/render-drivers/threadx/SharedNode.js +0 -60
  458. package/dist/src/render-drivers/threadx/SharedNode.js.map +0 -1
  459. package/dist/src/render-drivers/threadx/TextNodeStruct.d.ts +0 -44
  460. package/dist/src/render-drivers/threadx/TextNodeStruct.js +0 -201
  461. package/dist/src/render-drivers/threadx/TextNodeStruct.js.map +0 -1
  462. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +0 -28
  463. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +0 -234
  464. package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +0 -1
  465. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.d.ts +0 -20
  466. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js +0 -84
  467. package/dist/src/render-drivers/threadx/ThreadXMainAnimationController.js.map +0 -1
  468. package/dist/src/render-drivers/threadx/ThreadXMainNode.d.ts +0 -44
  469. package/dist/src/render-drivers/threadx/ThreadXMainNode.js +0 -154
  470. package/dist/src/render-drivers/threadx/ThreadXMainNode.js.map +0 -1
  471. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.d.ts +0 -6
  472. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js +0 -16
  473. package/dist/src/render-drivers/threadx/ThreadXMainShaderController.js.map +0 -1
  474. package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.d.ts +0 -7
  475. package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.js +0 -15
  476. package/dist/src/render-drivers/threadx/ThreadXMainShaderNode.js.map +0 -1
  477. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.d.ts +0 -28
  478. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js +0 -55
  479. package/dist/src/render-drivers/threadx/ThreadXMainTextNode.js.map +0 -1
  480. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.d.ts +0 -21
  481. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js +0 -198
  482. package/dist/src/render-drivers/threadx/ThreadXRenderDriver.js.map +0 -1
  483. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +0 -70
  484. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js +0 -32
  485. package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +0 -1
  486. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.d.ts +0 -19
  487. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js +0 -177
  488. package/dist/src/render-drivers/threadx/worker/ThreadXRendererNode.js.map +0 -1
  489. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.d.ts +0 -27
  490. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js +0 -108
  491. package/dist/src/render-drivers/threadx/worker/ThreadXRendererTextNode.js.map +0 -1
  492. package/dist/src/render-drivers/threadx/worker/renderer.d.ts +0 -1
  493. package/dist/src/render-drivers/threadx/worker/renderer.js +0 -145
  494. package/dist/src/render-drivers/threadx/worker/renderer.js.map +0 -1
  495. package/dist/src/render-drivers/utils.d.ts +0 -12
  496. package/dist/src/render-drivers/utils.js +0 -69
  497. package/dist/src/render-drivers/utils.js.map +0 -1
@@ -1,2469 +1,2483 @@
1
- /*
2
- * If not stated otherwise in this file or this component's LICENSE file the
3
- * following copyright and licenses apply:
4
- *
5
- * Copyright 2023 Comcast Cable Communications Management, LLC.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the License);
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
-
20
- import {
21
- assertTruthy,
22
- getNewId,
23
- mergeColorAlphaPremultiplied,
24
- isProductionEnvironment,
25
- } from '../utils.js';
26
- import type { TextureOptions } from './CoreTextureManager.js';
27
- import type { CoreRenderer } from './renderers/CoreRenderer.js';
28
- import type { Stage } from './Stage.js';
29
- import {
30
- type Texture,
31
- type TextureCoords,
32
- type TextureFailedEventHandler,
33
- type TextureFreedEventHandler,
34
- type TextureLoadedEventHandler,
35
- } from './textures/Texture.js';
36
- import type {
37
- Dimensions,
38
- NodeTextureFailedPayload,
39
- NodeTextureFreedPayload,
40
- NodeTextureLoadedPayload,
41
- } from '../common/CommonTypes.js';
42
- import { EventEmitter } from '../common/EventEmitter.js';
43
- import {
44
- copyRect,
45
- intersectRect,
46
- type Bound,
47
- type RectWithValid,
48
- createBound,
49
- boundInsideBound,
50
- boundLargeThanBound,
51
- createPreloadBounds,
52
- } from './lib/utils.js';
53
- import { Matrix3d } from './lib/Matrix3d.js';
54
- import { RenderCoords } from './lib/RenderCoords.js';
55
- import type { AnimationSettings } from './animations/CoreAnimation.js';
56
- import type { IAnimationController } from '../common/IAnimationController.js';
57
- import { CoreAnimation } from './animations/CoreAnimation.js';
58
- import { CoreAnimationController } from './animations/CoreAnimationController.js';
59
- import type { CoreShaderNode } from './renderers/CoreShaderNode.js';
60
-
61
- export enum CoreNodeRenderState {
62
- Init = 0,
63
- OutOfBounds = 2,
64
- InBounds = 4,
65
- InViewport = 8,
66
- }
67
-
68
- const CoreNodeRenderStateMap: Map<CoreNodeRenderState, string> = new Map();
69
- CoreNodeRenderStateMap.set(CoreNodeRenderState.Init, 'init');
70
- CoreNodeRenderStateMap.set(CoreNodeRenderState.OutOfBounds, 'outOfBounds');
71
- CoreNodeRenderStateMap.set(CoreNodeRenderState.InBounds, 'inBounds');
72
- CoreNodeRenderStateMap.set(CoreNodeRenderState.InViewport, 'inViewport');
73
-
74
- export enum UpdateType {
75
- /**
76
- * Child updates
77
- */
78
- Children = 1,
79
-
80
- /**
81
- * Scale/Rotate transform update
82
- *
83
- * @remarks
84
- * CoreNode Properties Updated:
85
- * - `scaleRotateTransform`
86
- */
87
- ScaleRotate = 2,
88
-
89
- /**
90
- * Translate transform update (x/y/width/height/pivot/mount)
91
- *
92
- * @remarks
93
- * CoreNode Properties Updated:
94
- * - `localTransform`
95
- */
96
- Local = 4,
97
-
98
- /**
99
- * Global Transform update
100
- *
101
- * @remarks
102
- * CoreNode Properties Updated:
103
- * - `globalTransform`
104
- * - `renderCoords`
105
- * - `renderBound`
106
- */
107
- Global = 8,
108
-
109
- /**
110
- * Clipping rect update
111
- *
112
- * @remarks
113
- * CoreNode Properties Updated:
114
- * - `clippingRect`
115
- */
116
- Clipping = 16,
117
-
118
- /**
119
- * Calculated ZIndex update
120
- *
121
- * @remarks
122
- * CoreNode Properties Updated:
123
- * - `calcZIndex`
124
- */
125
- CalculatedZIndex = 32,
126
-
127
- /**
128
- * Z-Index Sorted Children update
129
- *
130
- * @remarks
131
- * CoreNode Properties Updated:
132
- * - `children` (sorts children by their `calcZIndex`)
133
- */
134
- ZIndexSortedChildren = 64,
135
-
136
- /**
137
- * Premultiplied Colors update
138
- *
139
- * @remarks
140
- * CoreNode Properties Updated:
141
- * - `premultipliedColorTl`
142
- * - `premultipliedColorTr`
143
- * - `premultipliedColorBl`
144
- * - `premultipliedColorBr`
145
- */
146
- PremultipliedColors = 128,
147
-
148
- /**
149
- * World Alpha update
150
- *
151
- * @remarks
152
- * CoreNode Properties Updated:
153
- * - `worldAlpha` = `parent.worldAlpha` * `alpha`
154
- */
155
- WorldAlpha = 256,
156
-
157
- /**
158
- * Render State update
159
- *
160
- * @remarks
161
- * CoreNode Properties Updated:
162
- * - `renderState`
163
- */
164
- RenderState = 512,
165
-
166
- /**
167
- * Is Renderable update
168
- *
169
- * @remarks
170
- * CoreNode Properties Updated:
171
- * - `isRenderable`
172
- */
173
- IsRenderable = 1024,
174
-
175
- /**
176
- * Render Texture update
177
- */
178
- RenderTexture = 2048,
179
-
180
- /**
181
- * Track if parent has render texture
182
- */
183
- ParentRenderTexture = 4096,
184
-
185
- /**
186
- * Render Bounds update
187
- */
188
- RenderBounds = 8192,
189
-
190
- /**
191
- * None
192
- */
193
- None = 0,
194
-
195
- /**
196
- * All
197
- */
198
- All = 14335,
199
-
200
- /**
201
- * RecalcUniforms
202
- */
203
- RecalcUniforms = 16384,
204
- }
205
-
206
- /**
207
- * A custom data map which can be stored on an CoreNode
208
- *
209
- * @remarks
210
- * This is a map of key-value pairs that can be stored on an INode. It is used
211
- * to store custom data that can be used by the application.
212
- * The data stored can only be of type string, number or boolean.
213
- */
214
- export type CustomDataMap = {
215
- [key: string]: string | number | boolean | undefined;
216
- };
217
-
218
- /**
219
- * Writable properties of a Node.
220
- */
221
- export interface CoreNodeProps {
222
- /**
223
- * The x coordinate of the Node's Mount Point.
224
- *
225
- * @remarks
226
- * See {@link mountX} and {@link mountY} for more information about setting
227
- * the Mount Point.
228
- *
229
- * @default `0`
230
- */
231
- x: number;
232
- /**
233
- * The y coordinate of the Node's Mount Point.
234
- *
235
- * @remarks
236
- * See {@link mountX} and {@link mountY} for more information about setting
237
- * the Mount Point.
238
- *
239
- * @default `0`
240
- */
241
- y: number;
242
- /**
243
- * The width of the Node.
244
- *
245
- * @default `0`
246
- */
247
- width: number;
248
- /**
249
- * The height of the Node.
250
- *
251
- * @default `0`
252
- */
253
- height: number;
254
- /**
255
- * The alpha opacity of the Node.
256
- *
257
- * @remarks
258
- * The alpha value is a number between 0 and 1, where 0 is fully transparent
259
- * and 1 is fully opaque.
260
- *
261
- * @default `1`
262
- */
263
- alpha: number;
264
- /**
265
- * Autosize mode
266
- *
267
- * @remarks
268
- * When enabled, when a texture is loaded into the Node, the Node will
269
- * automatically resize to the dimensions of the texture.
270
- *
271
- * Text Nodes are always autosized based on their text content regardless
272
- * of this mode setting.
273
- *
274
- * @default `false`
275
- */
276
- autosize: boolean;
277
- /**
278
- * Margin around the Node's bounds for preloading
279
- *
280
- * @default `null`
281
- */
282
- boundsMargin: number | [number, number, number, number] | null;
283
- /**
284
- * Clipping Mode
285
- *
286
- * @remarks
287
- * Enable Clipping Mode when you want to prevent the drawing of a Node and
288
- * its descendants from overflowing outside of the Node's x/y/width/height
289
- * bounds.
290
- *
291
- * For WebGL, clipping is implemented using the high-performance WebGL
292
- * operation scissor. As a consequence, clipping does not work for
293
- * non-rectangular areas. So, if the element is rotated
294
- * (by itself or by any of its ancestors), clipping will not work as intended.
295
- *
296
- * TODO: Add support for non-rectangular clipping either automatically or
297
- * via Render-To-Texture.
298
- *
299
- * @default `false`
300
- */
301
- clipping: boolean;
302
- /**
303
- * The color of the Node.
304
- *
305
- * @remarks
306
- * The color value is a number in the format 0xRRGGBBAA, where RR is the red
307
- * component, GG is the green component, BB is the blue component, and AA is
308
- * the alpha component.
309
- *
310
- * Gradient colors may be set by setting the different color sub-properties:
311
- * {@link colorTop}, {@link colorBottom}, {@link colorLeft}, {@link colorRight},
312
- * {@link colorTl}, {@link colorTr}, {@link colorBr}, {@link colorBl} accordingly.
313
- *
314
- * @default `0xffffffff` (opaque white)
315
- */
316
- color: number;
317
- /**
318
- * The color of the top edge of the Node for gradient rendering.
319
- *
320
- * @remarks
321
- * See {@link color} for more information about color values and gradient
322
- * rendering.
323
- */
324
- colorTop: number;
325
- /**
326
- * The color of the bottom edge of the Node for gradient rendering.
327
- *
328
- * @remarks
329
- * See {@link color} for more information about color values and gradient
330
- * rendering.
331
- */
332
- colorBottom: number;
333
- /**
334
- * The color of the left edge of the Node for gradient rendering.
335
- *
336
- * @remarks
337
- * See {@link color} for more information about color values and gradient
338
- * rendering.
339
- */
340
- colorLeft: number;
341
- /**
342
- * The color of the right edge of the Node for gradient rendering.
343
- *
344
- * @remarks
345
- * See {@link color} for more information about color values and gradient
346
- * rendering.
347
- */
348
- colorRight: number;
349
- /**
350
- * The color of the top-left corner of the Node for gradient rendering.
351
- *
352
- * @remarks
353
- * See {@link color} for more information about color values and gradient
354
- * rendering.
355
- */
356
- colorTl: number;
357
- /**
358
- * The color of the top-right corner of the Node for gradient rendering.
359
- *
360
- * @remarks
361
- * See {@link color} for more information about color values and gradient
362
- * rendering.
363
- */
364
- colorTr: number;
365
- /**
366
- * The color of the bottom-right corner of the Node for gradient rendering.
367
- *
368
- * @remarks
369
- * See {@link color} for more information about color values and gradient
370
- * rendering.
371
- */
372
- colorBr: number;
373
- /**
374
- * The color of the bottom-left corner of the Node for gradient rendering.
375
- *
376
- * @remarks
377
- * See {@link color} for more information about color values and gradient
378
- * rendering.
379
- */
380
- colorBl: number;
381
- /**
382
- * The Node's parent Node.
383
- *
384
- * @remarks
385
- * The value `null` indicates that the Node has no parent. This may either be
386
- * because the Node is the root Node of the scene graph, or because the Node
387
- * has been removed from the scene graph.
388
- *
389
- * In order to make sure that a Node can be rendered on the screen, it must
390
- * be added to the scene graph by setting it's parent property to a Node that
391
- * is already in the scene graph such as the root Node.
392
- *
393
- * @default `null`
394
- */
395
- parent: CoreNode | null;
396
- /**
397
- * The Node's z-index.
398
- *
399
- * @remarks
400
- * TBD
401
- */
402
- zIndex: number;
403
- /**
404
- * The Node's Texture.
405
- *
406
- * @remarks
407
- * The `texture` defines a rasterized image that is contained within the
408
- * {@link width} and {@link height} dimensions of the Node. If null, the
409
- * Node will use an opaque white {@link ColorTexture} when being drawn, which
410
- * essentially enables colors (including gradients) to be drawn.
411
- *
412
- * If set, by default, the texture will be drawn, as is, stretched to the
413
- * dimensions of the Node. This behavior can be modified by setting the TBD
414
- * and TBD properties.
415
- *
416
- * To create a Texture in order to set it on this property, call
417
- * {@link RendererMain.createTexture}.
418
- *
419
- * If the {@link src} is set on a Node, the Node will use the
420
- * {@link ImageTexture} by default and the Node will simply load the image at
421
- * the specified URL.
422
- *
423
- * Note: If this is a Text Node, the Texture will be managed by the Node's
424
- * {@link TextRenderer} and should not be set explicitly.
425
- */
426
- texture: Texture | null;
427
-
428
- /**
429
- * Options to associate with the Node's Texture
430
- */
431
- textureOptions: TextureOptions;
432
-
433
- /**
434
- * The Node's shader
435
- *
436
- * @remarks
437
- * The `shader` defines a {@link Shader} used to draw the Node. By default,
438
- * the Default Shader is used which simply draws the defined {@link texture}
439
- * or {@link color}(s) within the Node without any special effects.
440
- *
441
- * To create a Shader in order to set it on this property, call
442
- * {@link RendererMain.createShader}.
443
- *
444
- * Note: If this is a Text Node, the Shader will be managed by the Node's
445
- * {@link TextRenderer} and should not be set explicitly.
446
- */
447
- shader: CoreShaderNode<any> | null;
448
- /**
449
- * Image URL
450
- *
451
- * @remarks
452
- * When set, the Node's {@link texture} is automatically set to an
453
- * {@link ImageTexture} using the source image URL provided (with all other
454
- * settings being defaults)
455
- */
456
- src: string | null;
457
- zIndexLocked: number;
458
- /**
459
- * Scale to render the Node at
460
- *
461
- * @remarks
462
- * The scale value multiplies the provided {@link width} and {@link height}
463
- * of the Node around the Node's Pivot Point (defined by the {@link pivot}
464
- * props).
465
- *
466
- * Behind the scenes, setting this property sets both the {@link scaleX} and
467
- * {@link scaleY} props to the same value.
468
- *
469
- * NOTE: When the scaleX and scaleY props are explicitly set to different values,
470
- * this property returns `null`. Setting `null` on this property will have no
471
- * effect.
472
- *
473
- * @default 1.0
474
- */
475
- scale: number | null;
476
- /**
477
- * Scale to render the Node at (X-Axis)
478
- *
479
- * @remarks
480
- * The scaleX value multiplies the provided {@link width} of the Node around
481
- * the Node's Pivot Point (defined by the {@link pivot} props).
482
- *
483
- * @default 1.0
484
- */
485
- scaleX: number;
486
- /**
487
- * Scale to render the Node at (Y-Axis)
488
- *
489
- * @remarks
490
- * The scaleY value multiplies the provided {@link height} of the Node around
491
- * the Node's Pivot Point (defined by the {@link pivot} props).
492
- *
493
- * @default 1.0
494
- */
495
- scaleY: number;
496
- /**
497
- * Combined position of the Node's Mount Point
498
- *
499
- * @remarks
500
- * The value can be any number between `0.0` and `1.0`:
501
- * - `0.0` defines the Mount Point at the top-left corner of the Node.
502
- * - `0.5` defines it at the center of the Node.
503
- * - `1.0` defines it at the bottom-right corner of the node.
504
- *
505
- * Use the {@link mountX} and {@link mountY} props seperately for more control
506
- * of the Mount Point.
507
- *
508
- * When assigned, the same value is also passed to both the {@link mountX} and
509
- * {@link mountY} props.
510
- *
511
- * @default 0 (top-left)
512
- */
513
- mount: number;
514
- /**
515
- * X position of the Node's Mount Point
516
- *
517
- * @remarks
518
- * The value can be any number between `0.0` and `1.0`:
519
- * - `0.0` defines the Mount Point's X position as the left-most edge of the
520
- * Node
521
- * - `0.5` defines it as the horizontal center of the Node
522
- * - `1.0` defines it as the right-most edge of the Node.
523
- *
524
- * The combination of {@link mountX} and {@link mountY} define the Mount Point
525
- *
526
- * @default 0 (left-most edge)
527
- */
528
- mountX: number;
529
- /**
530
- * Y position of the Node's Mount Point
531
- *
532
- * @remarks
533
- * The value can be any number between `0.0` and `1.0`:
534
- * - `0.0` defines the Mount Point's Y position as the top-most edge of the
535
- * Node
536
- * - `0.5` defines it as the vertical center of the Node
537
- * - `1.0` defines it as the bottom-most edge of the Node.
538
- *
539
- * The combination of {@link mountX} and {@link mountY} define the Mount Point
540
- *
541
- * @default 0 (top-most edge)
542
- */
543
- mountY: number;
544
- /**
545
- * Combined position of the Node's Pivot Point
546
- *
547
- * @remarks
548
- * The value can be any number between `0.0` and `1.0`:
549
- * - `0.0` defines the Pivot Point at the top-left corner of the Node.
550
- * - `0.5` defines it at the center of the Node.
551
- * - `1.0` defines it at the bottom-right corner of the node.
552
- *
553
- * Use the {@link pivotX} and {@link pivotY} props seperately for more control
554
- * of the Pivot Point.
555
- *
556
- * When assigned, the same value is also passed to both the {@link pivotX} and
557
- * {@link pivotY} props.
558
- *
559
- * @default 0.5 (center)
560
- */
561
- pivot: number;
562
- /**
563
- * X position of the Node's Pivot Point
564
- *
565
- * @remarks
566
- * The value can be any number between `0.0` and `1.0`:
567
- * - `0.0` defines the Pivot Point's X position as the left-most edge of the
568
- * Node
569
- * - `0.5` defines it as the horizontal center of the Node
570
- * - `1.0` defines it as the right-most edge of the Node.
571
- *
572
- * The combination of {@link pivotX} and {@link pivotY} define the Pivot Point
573
- *
574
- * @default 0.5 (centered on x-axis)
575
- */
576
- pivotX: number;
577
- /**
578
- * Y position of the Node's Pivot Point
579
- *
580
- * @remarks
581
- * The value can be any number between `0.0` and `1.0`:
582
- * - `0.0` defines the Pivot Point's Y position as the top-most edge of the
583
- * Node
584
- * - `0.5` defines it as the vertical center of the Node
585
- * - `1.0` defines it as the bottom-most edge of the Node.
586
- *
587
- * The combination of {@link pivotX} and {@link pivotY} define the Pivot Point
588
- *
589
- * @default 0.5 (centered on y-axis)
590
- */
591
- pivotY: number;
592
- /**
593
- * Rotation of the Node (in Radians)
594
- *
595
- * @remarks
596
- * Sets the amount to rotate the Node by around it's Pivot Point (defined by
597
- * the {@link pivot} props). Positive values rotate the Node clockwise, while
598
- * negative values rotate it counter-clockwise.
599
- *
600
- * Example values:
601
- * - `-Math.PI / 2`: 90 degree rotation counter-clockwise
602
- * - `0`: No rotation
603
- * - `Math.PI / 2`: 90 degree rotation clockwise
604
- * - `Math.PI`: 180 degree rotation clockwise
605
- * - `3 * Math.PI / 2`: 270 degree rotation clockwise
606
- * - `2 * Math.PI`: 360 rotation clockwise
607
- */
608
- rotation: number;
609
-
610
- /**
611
- * Whether the Node is rendered to a texture
612
- *
613
- * @remarks
614
- * TBD
615
- *
616
- * @default false
617
- */
618
- rtt: boolean;
619
-
620
- /**
621
- * Node data element for custom data storage (optional)
622
- *
623
- * @remarks
624
- * This property is used to store custom data on the Node as a key/value data store.
625
- * Data values are limited to string, numbers, booleans. Strings will be truncated
626
- * to a 2048 character limit for performance reasons.
627
- *
628
- * This is not a data storage mechanism for large amounts of data please use a
629
- * dedicated data storage mechanism for that.
630
- *
631
- * The custom data will be reflected in the inspector as part of `data-*` attributes
632
- *
633
- * @default `undefined`
634
- */
635
- data?: CustomDataMap;
636
-
637
- /**
638
- * Image Type to explicitly set the image type that is being loaded
639
- *
640
- * @remarks
641
- * This property must be used with a `src` that points at an image. In some cases
642
- * the extension doesn't provide a reliable representation of the image type. In such
643
- * cases set the ImageType explicitly.
644
- *
645
- * `regular` is used for normal images such as png, jpg, etc
646
- * `compressed` is used for ETC1/ETC2 compressed images with a PVR or KTX container
647
- * `svg` is used for scalable vector graphics
648
- *
649
- * @default `undefined`
650
- */
651
- imageType?: 'regular' | 'compressed' | 'svg' | null;
652
-
653
- /**
654
- * She width of the rectangle from which the Image Texture will be extracted.
655
- * This value can be negative. If not provided, the image's source natural
656
- * width will be used.
657
- */
658
- srcWidth?: number;
659
- /**
660
- * The height of the rectangle from which the Image Texture will be extracted.
661
- * This value can be negative. If not provided, the image's source natural
662
- * height will be used.
663
- */
664
- srcHeight?: number;
665
- /**
666
- * The x coordinate of the reference point of the rectangle from which the Texture
667
- * will be extracted. `width` and `height` are provided. And only works when
668
- * createImageBitmap is available. Only works when createImageBitmap is supported on the browser.
669
- */
670
- srcX?: number;
671
- /**
672
- * The y coordinate of the reference point of the rectangle from which the Texture
673
- * will be extracted. Only used when source `srcWidth` width and `srcHeight` height
674
- * are provided. Only works when createImageBitmap is supported on the browser.
675
- */
676
- srcY?: number;
677
- /**
678
- * By enabling Strict bounds the renderer will not process & render child nodes of a node that is out of the visible area
679
- *
680
- * @remarks
681
- * When enabled out of bound nodes, i.e. nodes that are out of the visible area, will
682
- * **NOT** have their children processed and renderer anymore. This means the children of a out of bound
683
- * node will not receive update processing such as positioning updates and will not be drawn on screen.
684
- * As such the rest of the branch of the update tree that sits below this node will not be processed anymore
685
- *
686
- * This is a big performance gain but may be disabled in cases where the width of the parent node is
687
- * unknown and the render must process the child nodes regardless of the viewport status of the parent node
688
- *
689
- * @default false
690
- */
691
- strictBounds: boolean;
692
- }
693
-
694
- /**
695
- * Grab all the number properties of type T
696
- */
697
- type NumberProps<T> = {
698
- [Key in keyof T as NonNullable<T[Key]> extends number ? Key : never]: number;
699
- };
700
-
701
- /**
702
- * Properties of a Node used by the animate() function
703
- */
704
- export interface CoreNodeAnimateProps extends NumberProps<CoreNodeProps> {
705
- /**
706
- * Shader properties to animate
707
- */
708
- shaderProps: Record<string, number>;
709
- // TODO: textureProps: Record<string, number>;
710
- }
711
-
712
- /**
713
- * A visual Node in the Renderer scene graph.
714
- *
715
- * @remarks
716
- * CoreNode is an internally used class that represents a Renderer Node in the
717
- * scene graph. See INode.ts for the public APIs exposed to Renderer users
718
- * that include generic types for Shaders.
719
- */
720
- export class CoreNode extends EventEmitter {
721
- readonly children: CoreNode[] = [];
722
- protected _id: number = getNewId();
723
- readonly props: CoreNodeProps;
724
-
725
- private hasShaderUpdater = false;
726
- public updateType = UpdateType.All;
727
- public childUpdateType = UpdateType.None;
728
-
729
- public globalTransform?: Matrix3d;
730
- public scaleRotateTransform?: Matrix3d;
731
- public localTransform?: Matrix3d;
732
- public sceneGlobalTransform?: Matrix3d;
733
- public renderCoords?: RenderCoords;
734
- public sceneRenderCoords?: RenderCoords;
735
- public renderBound?: Bound;
736
- public strictBound?: Bound;
737
- public preloadBound?: Bound;
738
- public clippingRect: RectWithValid = {
739
- x: 0,
740
- y: 0,
741
- width: 0,
742
- height: 0,
743
- valid: false,
744
- };
745
- public textureCoords?: TextureCoords;
746
- public updateTextureCoords?: boolean = false;
747
- public isRenderable = false;
748
- public renderState: CoreNodeRenderState = CoreNodeRenderState.Init;
749
-
750
- public worldAlpha = 1;
751
- public premultipliedColorTl = 0;
752
- public premultipliedColorTr = 0;
753
- public premultipliedColorBl = 0;
754
- public premultipliedColorBr = 0;
755
- public calcZIndex = 0;
756
- public hasRTTupdates = false;
757
- public parentHasRenderTexture = false;
758
- public rttParent: CoreNode | null = null;
759
- /**
760
- * only used when rtt = true
761
- */
762
- public framebufferDimensions: Dimensions | null = null;
763
-
764
- constructor(readonly stage: Stage, props: CoreNodeProps) {
765
- super();
766
-
767
- this.props = {
768
- ...props,
769
- parent: null,
770
- texture: null,
771
- shader: null,
772
- src: null,
773
- rtt: false,
774
- };
775
-
776
- // Assign props to instances
777
- this.parent = props.parent;
778
- this.texture = props.texture;
779
- this.shader = props.shader;
780
- this.src = props.src;
781
- this.rtt = props.rtt;
782
-
783
- if (props.boundsMargin) {
784
- this.boundsMargin = Array.isArray(props.boundsMargin)
785
- ? props.boundsMargin
786
- : [
787
- props.boundsMargin,
788
- props.boundsMargin,
789
- props.boundsMargin,
790
- props.boundsMargin,
791
- ];
792
- }
793
-
794
- this.setUpdateType(
795
- UpdateType.ScaleRotate |
796
- UpdateType.Local |
797
- UpdateType.RenderBounds |
798
- UpdateType.RenderState,
799
- );
800
-
801
- // if the default texture isn't loaded yet, wait for it to load
802
- // this only happens when the node is created before the stage is ready
803
- if (
804
- this.stage.defaultTexture &&
805
- this.stage.defaultTexture.state !== 'loaded'
806
- ) {
807
- this.stage.defaultTexture.once('loaded', () => {
808
- this.setUpdateType(UpdateType.IsRenderable);
809
- });
810
- }
811
- }
812
-
813
- //#region Textures
814
- loadTexture(): void {
815
- const { texture } = this.props;
816
- assertTruthy(texture);
817
-
818
- // If texture is already loaded / failed, trigger loaded event manually
819
- // so that users get a consistent event experience.
820
- // We do this in a microtask to allow listeners to be attached in the same
821
- // synchronous task after calling loadTexture()
822
- queueMicrotask(() => {
823
- if (this.textureOptions.preload === true) {
824
- this.stage.txManager.loadTexture(texture);
825
- }
826
-
827
- texture.preventCleanup =
828
- this.props.textureOptions?.preventCleanup ?? false;
829
- texture.on('loaded', this.onTextureLoaded);
830
- texture.on('failed', this.onTextureFailed);
831
- texture.on('freed', this.onTextureFreed);
832
-
833
- // If the parent is a render texture, the initial texture status
834
- // will be set to freed until the texture is processed by the
835
- // Render RTT nodes. So we only need to listen fo changes and
836
- // no need to check the texture.state until we restructure how
837
- // textures are being processed.
838
- if (this.parentHasRenderTexture) {
839
- this.notifyParentRTTOfUpdate();
840
- return;
841
- }
842
-
843
- if (texture.state === 'loaded') {
844
- assertTruthy(texture.dimensions);
845
- this.onTextureLoaded(texture, texture.dimensions);
846
- } else if (texture.state === 'failed') {
847
- assertTruthy(texture.error);
848
- this.onTextureFailed(texture, texture.error);
849
- } else if (texture.state === 'freed') {
850
- this.onTextureFreed(texture);
851
- }
852
- });
853
- }
854
-
855
- unloadTexture(): void {
856
- if (this.texture !== null) {
857
- this.texture.off('loaded', this.onTextureLoaded);
858
- this.texture.off('failed', this.onTextureFailed);
859
- this.texture.off('freed', this.onTextureFreed);
860
- this.texture.setRenderableOwner(this, false);
861
- }
862
- }
863
-
864
- autosizeNode(dimensions: Dimensions) {
865
- if (this.autosize) {
866
- this.width = dimensions.width;
867
- this.height = dimensions.height;
868
- }
869
- }
870
-
871
- private onTextureLoaded: TextureLoadedEventHandler = (_, dimensions) => {
872
- this.autosizeNode(dimensions);
873
- this.setUpdateType(UpdateType.IsRenderable);
874
-
875
- // Texture was loaded. In case the RAF loop has already stopped, we request
876
- // a render to ensure the texture is rendered.
877
- this.stage.requestRender();
878
-
879
- // If parent has a render texture, flag that we need to update
880
- if (this.parentHasRenderTexture) {
881
- this.notifyParentRTTOfUpdate();
882
- }
883
-
884
- // ignore 1x1 pixel textures
885
- if (dimensions.width > 1 && dimensions.height > 1) {
886
- this.emit('loaded', {
887
- type: 'texture',
888
- dimensions,
889
- } satisfies NodeTextureLoadedPayload);
890
- }
891
-
892
- // Trigger a local update if the texture is loaded and the resizeMode is 'contain'
893
- if (this.props.textureOptions?.resizeMode?.type === 'contain') {
894
- this.setUpdateType(UpdateType.Local);
895
- }
896
- };
897
-
898
- private onTextureFailed: TextureFailedEventHandler = (_, error) => {
899
- this.setUpdateType(UpdateType.IsRenderable);
900
-
901
- // If parent has a render texture, flag that we need to update
902
- if (this.parentHasRenderTexture) {
903
- this.notifyParentRTTOfUpdate();
904
- }
905
-
906
- this.emit('failed', {
907
- type: 'texture',
908
- error,
909
- } satisfies NodeTextureFailedPayload);
910
- };
911
-
912
- private onTextureFreed: TextureFreedEventHandler = () => {
913
- this.setUpdateType(UpdateType.IsRenderable);
914
-
915
- // If parent has a render texture, flag that we need to update
916
- if (this.parentHasRenderTexture) {
917
- this.notifyParentRTTOfUpdate();
918
- }
919
-
920
- this.emit('freed', {
921
- type: 'texture',
922
- } satisfies NodeTextureFreedPayload);
923
- };
924
- //#endregion Textures
925
-
926
- /**
927
- * Change types types is used to determine the scope of the changes being applied
928
- *
929
- * @remarks
930
- * See {@link UpdateType} for more information on each type
931
- *
932
- * @param type
933
- */
934
- setUpdateType(type: UpdateType): void {
935
- this.updateType |= type;
936
-
937
- const parent = this.props.parent;
938
- if (!parent) return;
939
-
940
- if ((parent.updateType & UpdateType.Children) === 0) {
941
- // Inform the parent if it doesn’t already have a child update
942
- parent.setUpdateType(UpdateType.Children);
943
- }
944
- }
945
-
946
- sortChildren() {
947
- this.children.sort((a, b) => a.calcZIndex - b.calcZIndex);
948
- }
949
-
950
- updateScaleRotateTransform() {
951
- const { rotation, scaleX, scaleY } = this.props;
952
-
953
- // optimize simple translation cases
954
- if (rotation === 0 && scaleX === 1 && scaleY === 1) {
955
- this.scaleRotateTransform = undefined;
956
- return;
957
- }
958
-
959
- this.scaleRotateTransform = Matrix3d.rotate(
960
- rotation,
961
- this.scaleRotateTransform,
962
- ).scale(scaleX, scaleY);
963
- }
964
-
965
- updateLocalTransform() {
966
- const { x, y, width, height } = this.props;
967
- const mountTranslateX = this.props.mountX * width;
968
- const mountTranslateY = this.props.mountY * height;
969
-
970
- if (this.scaleRotateTransform) {
971
- const pivotTranslateX = this.props.pivotX * width;
972
- const pivotTranslateY = this.props.pivotY * height;
973
-
974
- this.localTransform = Matrix3d.translate(
975
- x - mountTranslateX + pivotTranslateX,
976
- y - mountTranslateY + pivotTranslateY,
977
- this.localTransform,
978
- )
979
- .multiply(this.scaleRotateTransform)
980
- .translate(-pivotTranslateX, -pivotTranslateY);
981
- } else {
982
- this.localTransform = Matrix3d.translate(
983
- x - mountTranslateX,
984
- y - mountTranslateY,
985
- this.localTransform,
986
- );
987
- }
988
-
989
- // Handle 'contain' resize mode
990
- const texture = this.props.texture;
991
- if (
992
- texture &&
993
- texture.dimensions &&
994
- this.props.textureOptions?.resizeMode?.type === 'contain'
995
- ) {
996
- let resizeModeScaleX = 1;
997
- let resizeModeScaleY = 1;
998
- let extraX = 0;
999
- let extraY = 0;
1000
- const { width: tw, height: th } = texture.dimensions;
1001
- const txAspectRatio = tw / th;
1002
- const nodeAspectRatio = width / height;
1003
- if (txAspectRatio > nodeAspectRatio) {
1004
- // Texture is wider than node
1005
- // Center the node vertically (shift down by extraY)
1006
- // Scale the node vertically to maintain original aspect ratio
1007
- const scaleX = width / tw;
1008
- const scaledTxHeight = th * scaleX;
1009
- extraY = (height - scaledTxHeight) / 2;
1010
- resizeModeScaleY = scaledTxHeight / height;
1011
- } else {
1012
- // Texture is taller than node (or equal)
1013
- // Center the node horizontally (shift right by extraX)
1014
- // Scale the node horizontally to maintain original aspect ratio
1015
- const scaleY = height / th;
1016
- const scaledTxWidth = tw * scaleY;
1017
- extraX = (width - scaledTxWidth) / 2;
1018
- resizeModeScaleX = scaledTxWidth / width;
1019
- }
1020
-
1021
- // Apply the extra translation and scale to the local transform
1022
- this.localTransform
1023
- .translate(extraX, extraY)
1024
- .scale(resizeModeScaleX, resizeModeScaleY);
1025
- }
1026
-
1027
- this.setUpdateType(UpdateType.Global);
1028
- }
1029
-
1030
- /**
1031
- * @todo: test for correct calculation flag
1032
- * @param delta
1033
- */
1034
- update(delta: number, parentClippingRect: RectWithValid): void {
1035
- if (this.updateType & UpdateType.ScaleRotate) {
1036
- this.updateScaleRotateTransform();
1037
- this.setUpdateType(UpdateType.Local);
1038
- }
1039
-
1040
- if (this.updateType & UpdateType.Local) {
1041
- this.updateLocalTransform();
1042
- this.setUpdateType(UpdateType.Global);
1043
- }
1044
-
1045
- const parent = this.props.parent;
1046
- let renderState: CoreNodeRenderState | null = null;
1047
-
1048
- // Handle specific RTT updates at this node level
1049
- if (this.updateType & UpdateType.RenderTexture && this.rtt) {
1050
- this.hasRTTupdates = true;
1051
- }
1052
-
1053
- if (this.updateType & UpdateType.Global) {
1054
- assertTruthy(this.localTransform);
1055
-
1056
- if (this.parentHasRenderTexture === true && parent?.rtt === true) {
1057
- // we are at the start of the RTT chain, so we need to reset the globalTransform
1058
- // for correct RTT rendering
1059
- this.globalTransform = Matrix3d.identity();
1060
-
1061
- // Maintain a full scene global transform for bounds detection
1062
- this.sceneGlobalTransform = Matrix3d.copy(
1063
- parent?.globalTransform || Matrix3d.identity(),
1064
- ).multiply(this.localTransform);
1065
- } else if (
1066
- this.parentHasRenderTexture === true &&
1067
- parent?.rtt === false
1068
- ) {
1069
- // we're part of an RTT chain but our parent is not the main RTT node
1070
- // so we need to propogate the sceneGlobalTransform of the parent
1071
- // to maintain a full scene global transform for bounds detection
1072
- this.sceneGlobalTransform = Matrix3d.copy(
1073
- parent?.sceneGlobalTransform || this.localTransform,
1074
- ).multiply(this.localTransform);
1075
-
1076
- this.globalTransform = Matrix3d.copy(
1077
- parent?.globalTransform || this.localTransform,
1078
- this.globalTransform,
1079
- );
1080
- } else {
1081
- this.globalTransform = Matrix3d.copy(
1082
- parent?.globalTransform || this.localTransform,
1083
- this.globalTransform,
1084
- );
1085
- }
1086
-
1087
- if (parent !== null) {
1088
- this.globalTransform.multiply(this.localTransform);
1089
- }
1090
- this.calculateRenderCoords();
1091
- this.updateBoundingRect();
1092
-
1093
- this.setUpdateType(
1094
- UpdateType.RenderState |
1095
- UpdateType.Children |
1096
- UpdateType.RecalcUniforms,
1097
- );
1098
- this.childUpdateType |= UpdateType.Global;
1099
-
1100
- if (this.clipping === true) {
1101
- this.setUpdateType(UpdateType.Clipping | UpdateType.RenderBounds);
1102
- this.childUpdateType |= UpdateType.RenderBounds;
1103
- }
1104
- }
1105
-
1106
- if (this.updateType & UpdateType.RenderBounds) {
1107
- this.createRenderBounds();
1108
- this.setUpdateType(UpdateType.RenderState);
1109
- this.setUpdateType(UpdateType.Children);
1110
-
1111
- this.childUpdateType |= UpdateType.RenderBounds;
1112
- }
1113
-
1114
- if (this.updateType & UpdateType.RenderState) {
1115
- renderState = this.checkRenderBounds();
1116
- this.setUpdateType(UpdateType.IsRenderable);
1117
-
1118
- // if we're not going out of bounds, update the render state
1119
- // this is done so the update loop can finish before we mark a node
1120
- // as out of bounds
1121
- if (renderState !== CoreNodeRenderState.OutOfBounds) {
1122
- this.updateRenderState(renderState);
1123
- }
1124
- }
1125
-
1126
- if (this.updateType & UpdateType.WorldAlpha) {
1127
- if (parent) {
1128
- this.worldAlpha = parent.worldAlpha * this.props.alpha;
1129
- } else {
1130
- this.worldAlpha = this.props.alpha;
1131
- }
1132
- this.setUpdateType(
1133
- UpdateType.Children |
1134
- UpdateType.PremultipliedColors |
1135
- UpdateType.IsRenderable,
1136
- );
1137
- this.childUpdateType |= UpdateType.WorldAlpha;
1138
- }
1139
-
1140
- if (this.updateType & UpdateType.IsRenderable) {
1141
- this.updateIsRenderable();
1142
- }
1143
-
1144
- if (this.updateType & UpdateType.Clipping) {
1145
- this.calculateClippingRect(parentClippingRect);
1146
- this.setUpdateType(UpdateType.Children);
1147
-
1148
- this.childUpdateType |= UpdateType.Clipping;
1149
- this.childUpdateType |= UpdateType.RenderBounds;
1150
- }
1151
-
1152
- if (this.updateType & UpdateType.PremultipliedColors) {
1153
- this.premultipliedColorTl = mergeColorAlphaPremultiplied(
1154
- this.props.colorTl,
1155
- this.worldAlpha,
1156
- true,
1157
- );
1158
-
1159
- // If all the colors are the same just sent them all to the same value
1160
- if (
1161
- this.props.colorTl === this.props.colorTr &&
1162
- this.props.colorBl === this.props.colorBr &&
1163
- this.props.colorTl === this.props.colorBl
1164
- ) {
1165
- this.premultipliedColorTr =
1166
- this.premultipliedColorBl =
1167
- this.premultipliedColorBr =
1168
- this.premultipliedColorTl;
1169
- } else {
1170
- this.premultipliedColorTr = mergeColorAlphaPremultiplied(
1171
- this.props.colorTr,
1172
- this.worldAlpha,
1173
- true,
1174
- );
1175
- this.premultipliedColorBl = mergeColorAlphaPremultiplied(
1176
- this.props.colorBl,
1177
- this.worldAlpha,
1178
- true,
1179
- );
1180
- this.premultipliedColorBr = mergeColorAlphaPremultiplied(
1181
- this.props.colorBr,
1182
- this.worldAlpha,
1183
- true,
1184
- );
1185
- }
1186
- }
1187
-
1188
- // No need to update zIndex if there is no parent
1189
- if (parent !== null && this.updateType & UpdateType.CalculatedZIndex) {
1190
- this.calculateZIndex();
1191
- // Tell parent to re-sort children
1192
- parent.setUpdateType(UpdateType.ZIndexSortedChildren);
1193
- }
1194
-
1195
- if (
1196
- this.props.strictBounds === true &&
1197
- this.renderState === CoreNodeRenderState.OutOfBounds
1198
- ) {
1199
- this.updateType &= ~UpdateType.RenderBounds; // remove render bounds update
1200
- return;
1201
- }
1202
-
1203
- if (
1204
- this.updateType & UpdateType.RecalcUniforms &&
1205
- this.hasShaderUpdater === true
1206
- ) {
1207
- //this exists because the boolean hasShaderUpdater === true
1208
- this.shader!.update!();
1209
- }
1210
-
1211
- if (this.updateType & UpdateType.Children && this.children.length > 0) {
1212
- for (let i = 0, length = this.children.length; i < length; i++) {
1213
- const child = this.children[i] as CoreNode;
1214
-
1215
- child.setUpdateType(this.childUpdateType);
1216
-
1217
- if (child.updateType === 0) {
1218
- continue;
1219
- }
1220
-
1221
- let childClippingRect = this.clippingRect;
1222
- if (this.rtt === true) {
1223
- childClippingRect = {
1224
- x: 0,
1225
- y: 0,
1226
- width: 0,
1227
- height: 0,
1228
- valid: false,
1229
- };
1230
- }
1231
-
1232
- child.update(delta, childClippingRect);
1233
- }
1234
- }
1235
-
1236
- // If the node has an RTT parent and requires a texture re-render, inform the RTT parent
1237
- // if (this.parentHasRenderTexture && this.updateType & UpdateType.RenderTexture) {
1238
- // @TODO have a more scoped down updateType for RTT updates
1239
- if (this.parentHasRenderTexture && this.updateType > 0) {
1240
- this.notifyParentRTTOfUpdate();
1241
- }
1242
-
1243
- // Sorting children MUST happen after children have been updated so
1244
- // that they have the oppotunity to update their calculated zIndex.
1245
- if (this.updateType & UpdateType.ZIndexSortedChildren) {
1246
- // reorder z-index
1247
- this.sortChildren();
1248
- }
1249
-
1250
- if (this.updateTextureCoords === true) {
1251
- this.updateTextureCoords = false;
1252
- this.textureCoords = this.stage.renderer.getTextureCoords!(this);
1253
- }
1254
-
1255
- // If we're out of bounds, apply the render state now
1256
- // this is done so nodes can finish their entire update loop before
1257
- // being marked as out of bounds
1258
- if (renderState === CoreNodeRenderState.OutOfBounds) {
1259
- this.updateRenderState(renderState);
1260
- this.updateIsRenderable();
1261
-
1262
- if (
1263
- this.rtt === true &&
1264
- renderState === CoreNodeRenderState.OutOfBounds
1265
- ) {
1266
- // notify children that we are going out of bounds
1267
- // we have to do this now before we stop processing the render tree
1268
- this.notifyChildrenRTTOfUpdate(renderState);
1269
- // this.childUpdateType |= UpdateType.RenderState;
1270
- }
1271
- }
1272
-
1273
- // reset update type
1274
- this.updateType = 0;
1275
- this.childUpdateType = 0;
1276
- }
1277
-
1278
- private findParentRTTNode(): CoreNode | null {
1279
- let rttNode: CoreNode | null = this.parent;
1280
- while (rttNode && !rttNode.rtt) {
1281
- rttNode = rttNode.parent;
1282
- }
1283
- return rttNode;
1284
- }
1285
-
1286
- private notifyChildrenRTTOfUpdate(renderState: CoreNodeRenderState) {
1287
- for (const child of this.children) {
1288
- // force child to update render state
1289
- child.updateRenderState(renderState);
1290
- child.updateIsRenderable();
1291
- child.notifyChildrenRTTOfUpdate(renderState);
1292
- }
1293
- }
1294
-
1295
- private notifyParentRTTOfUpdate() {
1296
- if (this.parent === null) {
1297
- return;
1298
- }
1299
-
1300
- const rttNode = this.rttParent || this.findParentRTTNode();
1301
- if (!rttNode) {
1302
- return;
1303
- }
1304
-
1305
- // If an RTT node is found, mark it for re-rendering
1306
- rttNode.hasRTTupdates = true;
1307
- rttNode.setUpdateType(UpdateType.RenderTexture);
1308
-
1309
- // if rttNode is nested, also make it update its RTT parent
1310
- if (rttNode.parentHasRenderTexture === true) {
1311
- rttNode.notifyParentRTTOfUpdate();
1312
- }
1313
- }
1314
-
1315
- checkRenderBounds(): CoreNodeRenderState {
1316
- assertTruthy(this.renderBound);
1317
- assertTruthy(this.strictBound);
1318
- assertTruthy(this.preloadBound);
1319
-
1320
- if (boundInsideBound(this.renderBound, this.strictBound)) {
1321
- return CoreNodeRenderState.InViewport;
1322
- }
1323
-
1324
- if (boundInsideBound(this.renderBound, this.preloadBound)) {
1325
- return CoreNodeRenderState.InBounds;
1326
- }
1327
-
1328
- // check if we're larger then our parent, we're definitely in the viewport
1329
- if (boundLargeThanBound(this.renderBound, this.strictBound)) {
1330
- return CoreNodeRenderState.InViewport;
1331
- }
1332
-
1333
- // check if we dont have dimensions, take our parent's render state
1334
- if (
1335
- this.parent !== null &&
1336
- (this.props.width === 0 || this.props.height === 0)
1337
- ) {
1338
- return this.parent.renderState;
1339
- }
1340
-
1341
- return CoreNodeRenderState.OutOfBounds;
1342
- }
1343
-
1344
- updateBoundingRect() {
1345
- const transform = this.sceneGlobalTransform || this.globalTransform;
1346
- const renderCoords = this.sceneRenderCoords || this.renderCoords;
1347
-
1348
- assertTruthy(transform);
1349
- assertTruthy(renderCoords);
1350
-
1351
- if (transform.tb === 0 || transform.tc === 0) {
1352
- this.renderBound = createBound(
1353
- renderCoords.x1,
1354
- renderCoords.y1,
1355
- renderCoords.x3,
1356
- renderCoords.y3,
1357
- this.renderBound,
1358
- );
1359
- } else {
1360
- const { x1, y1, x2, y2, x3, y3, x4, y4 } = renderCoords;
1361
- this.renderBound = createBound(
1362
- Math.min(x1, x2, x3, x4),
1363
- Math.min(y1, y2, y3, y4),
1364
- Math.max(x1, x2, x3, x4),
1365
- Math.max(y1, y2, y3, y4),
1366
- this.renderBound,
1367
- );
1368
- }
1369
- }
1370
-
1371
- createRenderBounds(): void {
1372
- if (this.parent !== null && this.parent.strictBound !== undefined) {
1373
- // we have a parent with a valid bound, copy it
1374
- const parentBound = this.parent.strictBound;
1375
- this.strictBound = createBound(
1376
- parentBound.x1,
1377
- parentBound.y1,
1378
- parentBound.x2,
1379
- parentBound.y2,
1380
- );
1381
-
1382
- this.preloadBound = createPreloadBounds(
1383
- this.strictBound,
1384
- this.boundsMargin as [number, number, number, number],
1385
- );
1386
- } else {
1387
- // no parent or parent does not have a bound, take the stage boundaries
1388
- this.strictBound = this.stage.strictBound;
1389
- this.preloadBound = this.stage.preloadBound;
1390
- }
1391
-
1392
- // if clipping is disabled, we're done
1393
- if (this.props.clipping === false) {
1394
- return;
1395
- }
1396
-
1397
- // only create local clipping bounds if node itself is in bounds
1398
- // this can only be done if we have a render bound already
1399
- if (this.renderBound === undefined) {
1400
- return;
1401
- }
1402
-
1403
- // if we're out of bounds, we're done
1404
- if (boundInsideBound(this.renderBound, this.strictBound) === false) {
1405
- return;
1406
- }
1407
-
1408
- // clipping is enabled and we are in bounds create our own bounds
1409
- const { x, y, width, height } = this.props;
1410
-
1411
- // Pick the global transform if available, otherwise use the local transform
1412
- // global transform is only available if the node in an RTT chain
1413
- const { tx, ty } = this.sceneGlobalTransform || this.globalTransform || {};
1414
- const _x = tx ?? x;
1415
- const _y = ty ?? y;
1416
- this.strictBound = createBound(
1417
- _x,
1418
- _y,
1419
- _x + width,
1420
- _y + height,
1421
- this.strictBound,
1422
- );
1423
-
1424
- this.preloadBound = createPreloadBounds(
1425
- this.strictBound,
1426
- this.boundsMargin as [number, number, number, number],
1427
- );
1428
- }
1429
-
1430
- updateRenderState(renderState: CoreNodeRenderState) {
1431
- if (renderState === this.renderState) {
1432
- return;
1433
- }
1434
-
1435
- const previous = this.renderState;
1436
- this.renderState = renderState;
1437
- const event = CoreNodeRenderStateMap.get(renderState);
1438
- assertTruthy(event);
1439
- this.emit(event, {
1440
- previous,
1441
- current: renderState,
1442
- });
1443
- }
1444
-
1445
- /**
1446
- * Updates the `isRenderable` property based on various conditions.
1447
- */
1448
- updateIsRenderable() {
1449
- let newIsRenderable = false;
1450
- let needsTextureOwnership = false;
1451
-
1452
- // If the node is out of bounds or has an alpha of 0, it is not renderable
1453
- if (this.checkBasicRenderability() === false) {
1454
- this.updateTextureOwnership(false);
1455
- this.setRenderable(false);
1456
- return;
1457
- }
1458
-
1459
- if (this.texture !== null) {
1460
- needsTextureOwnership = true;
1461
-
1462
- // we're only renderable if the texture state is loaded
1463
- newIsRenderable = this.texture.state === 'loaded';
1464
- } else if (
1465
- (this.hasShader() || this.hasColorProperties() === true) &&
1466
- this.hasDimensions() === true
1467
- ) {
1468
- // This mean we have dimensions and a color set, so we can render a ColorTexture
1469
- if (
1470
- this.stage.defaultTexture &&
1471
- this.stage.defaultTexture.state === 'loaded'
1472
- ) {
1473
- newIsRenderable = true;
1474
- }
1475
- }
1476
-
1477
- this.updateTextureOwnership(needsTextureOwnership);
1478
- this.setRenderable(newIsRenderable);
1479
- }
1480
-
1481
- /**
1482
- * Checks if the node is renderable based on world alpha, dimensions and out of bounds status.
1483
- */
1484
- checkBasicRenderability(): boolean {
1485
- if (this.worldAlpha === 0 || this.isOutOfBounds() === true) {
1486
- return false;
1487
- } else {
1488
- return true;
1489
- }
1490
- }
1491
-
1492
- /**
1493
- * Sets the renderable state and triggers changes if necessary.
1494
- * @param isRenderable - The new renderable state
1495
- */
1496
- setRenderable(isRenderable: boolean) {
1497
- this.isRenderable = isRenderable;
1498
- if (
1499
- isRenderable === true &&
1500
- this.stage.calculateTextureCoord === true &&
1501
- this.textureCoords === undefined
1502
- ) {
1503
- this.updateTextureCoords = true;
1504
- }
1505
- }
1506
-
1507
- /**
1508
- * Changes the renderable state of the node.
1509
- */
1510
- updateTextureOwnership(isRenderable: boolean) {
1511
- this.texture?.setRenderableOwner(this, isRenderable);
1512
- }
1513
-
1514
- /**
1515
- * Checks if the node is out of the viewport bounds.
1516
- */
1517
- isOutOfBounds(): boolean {
1518
- return this.renderState <= CoreNodeRenderState.OutOfBounds;
1519
- }
1520
-
1521
- /**
1522
- * Checks if the node has dimensions (width/height)
1523
- */
1524
- hasDimensions(): boolean {
1525
- return this.props.width !== 0 && this.props.height !== 0;
1526
- }
1527
-
1528
- /**
1529
- * Checks if the node has any color properties set.
1530
- */
1531
- hasColorProperties(): boolean {
1532
- return (
1533
- this.props.color !== 0 ||
1534
- this.props.colorTop !== 0 ||
1535
- this.props.colorBottom !== 0 ||
1536
- this.props.colorLeft !== 0 ||
1537
- this.props.colorRight !== 0 ||
1538
- this.props.colorTl !== 0 ||
1539
- this.props.colorTr !== 0 ||
1540
- this.props.colorBl !== 0 ||
1541
- this.props.colorBr !== 0
1542
- );
1543
- }
1544
-
1545
- hasShader(): boolean {
1546
- return this.props.shader !== null;
1547
- }
1548
-
1549
- calculateRenderCoords() {
1550
- const { width, height } = this;
1551
- const { tx, ty, ta, tb, tc, td } = this.globalTransform!;
1552
- if (tb === 0 && tc === 0) {
1553
- const minX = tx;
1554
- const maxX = tx + width * ta;
1555
- const minY = ty;
1556
- const maxY = ty + height * td;
1557
- this.renderCoords = RenderCoords.translate(
1558
- //top-left
1559
- minX,
1560
- minY,
1561
- //top-right
1562
- maxX,
1563
- minY,
1564
- //bottom-right
1565
- maxX,
1566
- maxY,
1567
- //bottom-left
1568
- minX,
1569
- maxY,
1570
- this.renderCoords,
1571
- );
1572
- } else {
1573
- this.renderCoords = RenderCoords.translate(
1574
- //top-left
1575
- tx,
1576
- ty,
1577
- //top-right
1578
- tx + width * ta,
1579
- ty + width * tc,
1580
- //bottom-right
1581
- tx + width * ta + height * tb,
1582
- ty + width * tc + height * td,
1583
- //bottom-left
1584
- tx + height * tb,
1585
- ty + height * td,
1586
- this.renderCoords,
1587
- );
1588
- }
1589
- if (this.sceneGlobalTransform === undefined) {
1590
- return;
1591
- }
1592
-
1593
- const {
1594
- tx: stx,
1595
- ty: sty,
1596
- ta: sta,
1597
- tb: stb,
1598
- tc: stc,
1599
- td: std,
1600
- } = this.sceneGlobalTransform;
1601
- if (stb === 0 && stc === 0) {
1602
- const minX = stx;
1603
- const maxX = stx + width * sta;
1604
- const minY = sty;
1605
- const maxY = sty + height * std;
1606
- this.sceneRenderCoords = RenderCoords.translate(
1607
- //top-left
1608
- minX,
1609
- minY,
1610
- //top-right
1611
- maxX,
1612
- minY,
1613
- //bottom-right
1614
- maxX,
1615
- maxY,
1616
- //bottom-left
1617
- minX,
1618
- maxY,
1619
- this.sceneRenderCoords,
1620
- );
1621
- } else {
1622
- this.sceneRenderCoords = RenderCoords.translate(
1623
- //top-left
1624
- stx,
1625
- sty,
1626
- //top-right
1627
- stx + width * sta,
1628
- sty + width * stc,
1629
- //bottom-right
1630
- stx + width * sta + height * stb,
1631
- sty + width * stc + height * std,
1632
- //bottom-left
1633
- stx + height * stb,
1634
- sty + height * std,
1635
- this.sceneRenderCoords,
1636
- );
1637
- }
1638
- }
1639
-
1640
- /**
1641
- * This function calculates the clipping rectangle for a node.
1642
- *
1643
- * The function then checks if the node is rotated. If the node requires clipping and is not rotated, a new clipping rectangle is created based on the node's global transform and dimensions.
1644
- * If a parent clipping rectangle exists, it is intersected with the node's clipping rectangle (if it exists), or replaces the node's clipping rectangle.
1645
- *
1646
- * Finally, the node's parentClippingRect and clippingRect properties are updated.
1647
- */
1648
- calculateClippingRect(parentClippingRect: RectWithValid) {
1649
- assertTruthy(this.globalTransform);
1650
- const { clippingRect, props, globalTransform: gt } = this;
1651
- const { clipping } = props;
1652
- const isRotated = gt.tb !== 0 || gt.tc !== 0;
1653
-
1654
- if (clipping === true && isRotated === false) {
1655
- clippingRect.x = gt.tx;
1656
- clippingRect.y = gt.ty;
1657
- clippingRect.width = this.width * gt.ta;
1658
- clippingRect.height = this.height * gt.td;
1659
- clippingRect.valid = true;
1660
- } else {
1661
- clippingRect.valid = false;
1662
- }
1663
-
1664
- if (parentClippingRect.valid === true && clippingRect.valid === true) {
1665
- // Intersect parent clipping rect with node clipping rect
1666
- intersectRect(parentClippingRect, clippingRect, clippingRect);
1667
- } else if (parentClippingRect.valid === true) {
1668
- // Copy parent clipping rect
1669
- copyRect(parentClippingRect, clippingRect);
1670
- clippingRect.valid = true;
1671
- }
1672
- }
1673
-
1674
- calculateZIndex(): void {
1675
- const props = this.props;
1676
- const z = props.zIndex || 0;
1677
- const p = props.parent?.zIndex || 0;
1678
-
1679
- let zIndex = z;
1680
- if (props.parent?.zIndexLocked) {
1681
- zIndex = z < p ? z : p;
1682
- }
1683
- this.calcZIndex = zIndex;
1684
- }
1685
-
1686
- /**
1687
- * Destroy the node and cleanup all resources
1688
- */
1689
- destroy(): void {
1690
- this.unloadTexture();
1691
-
1692
- this.clippingRect.valid = false;
1693
- this.isRenderable = false;
1694
-
1695
- this.renderCoords = undefined;
1696
- this.renderBound = undefined;
1697
- this.strictBound = undefined;
1698
- this.preloadBound = undefined;
1699
- this.globalTransform = undefined;
1700
- this.scaleRotateTransform = undefined;
1701
- this.localTransform = undefined;
1702
-
1703
- this.props.texture = null;
1704
- this.props.shader = null;
1705
-
1706
- while (this.children.length > 0) {
1707
- this.children[0]?.destroy();
1708
- }
1709
-
1710
- // This very action will also remove the node from the parent's children array
1711
- this.parent = null;
1712
-
1713
- if (this.rtt) {
1714
- this.stage.renderer.removeRTTNode(this);
1715
- }
1716
-
1717
- this.removeAllListeners();
1718
- }
1719
-
1720
- renderQuads(renderer: CoreRenderer): void {
1721
- // Prevent quad rendering if parent has a render texture
1722
- // and renderer is not currently rendering to a texture
1723
- if (this.parentHasRenderTexture) {
1724
- if (!renderer.renderToTextureActive) {
1725
- return;
1726
- }
1727
- // Prevent quad rendering if parent render texture is not the active render texture
1728
- if (this.parentRenderTexture !== renderer.activeRttNode) {
1729
- return;
1730
- }
1731
- }
1732
-
1733
- assertTruthy(this.globalTransform);
1734
-
1735
- // add to list of renderables to be sorted before rendering
1736
- renderer.addQuad({
1737
- width: this.props.width,
1738
- height: this.props.height,
1739
- colorTl: this.premultipliedColorTl,
1740
- colorTr: this.premultipliedColorTr,
1741
- colorBl: this.premultipliedColorBl,
1742
- colorBr: this.premultipliedColorBr,
1743
- // if we do not have a texture, use the default texture
1744
- // this assumes any renderable node is either a distinct texture or a ColorTexture
1745
- texture: this.texture || this.stage.defaultTexture,
1746
- textureOptions: this.textureOptions,
1747
- textureCoords: this.textureCoords,
1748
- zIndex: this.zIndex,
1749
- shader: this.props.shader as CoreShaderNode<any>,
1750
- alpha: this.worldAlpha,
1751
- clippingRect: this.clippingRect,
1752
- tx: this.globalTransform.tx,
1753
- ty: this.globalTransform.ty,
1754
- ta: this.globalTransform.ta,
1755
- tb: this.globalTransform.tb,
1756
- tc: this.globalTransform.tc,
1757
- td: this.globalTransform.td,
1758
- renderCoords: this.renderCoords,
1759
- rtt: this.rtt,
1760
- parentHasRenderTexture: this.parentHasRenderTexture,
1761
- framebufferDimensions:
1762
- this.parentHasRenderTexture === true
1763
- ? this.parentFramebufferDimensions
1764
- : null,
1765
- });
1766
- }
1767
-
1768
- //#region Properties
1769
- get id(): number {
1770
- return this._id;
1771
- }
1772
-
1773
- get data(): CustomDataMap | undefined {
1774
- return this.props.data;
1775
- }
1776
-
1777
- set data(d: CustomDataMap | undefined) {
1778
- this.props.data = d;
1779
- }
1780
-
1781
- get x(): number {
1782
- return this.props.x;
1783
- }
1784
-
1785
- set x(value: number) {
1786
- if (this.props.x !== value) {
1787
- this.props.x = value;
1788
- this.setUpdateType(UpdateType.Local);
1789
- }
1790
- }
1791
-
1792
- get absX(): number {
1793
- return (
1794
- this.props.x +
1795
- -this.props.width * this.props.mountX +
1796
- (this.props.parent?.absX || this.props.parent?.globalTransform?.tx || 0)
1797
- );
1798
- }
1799
-
1800
- get absY(): number {
1801
- return (
1802
- this.props.y +
1803
- -this.props.height * this.props.mountY +
1804
- (this.props.parent?.absY ?? 0)
1805
- );
1806
- }
1807
-
1808
- get y(): number {
1809
- return this.props.y;
1810
- }
1811
-
1812
- set y(value: number) {
1813
- if (this.props.y !== value) {
1814
- this.props.y = value;
1815
- this.setUpdateType(UpdateType.Local);
1816
- }
1817
- }
1818
-
1819
- get width(): number {
1820
- return this.props.width;
1821
- }
1822
-
1823
- set width(value: number) {
1824
- if (this.props.width !== value) {
1825
- this.props.width = value;
1826
- this.setUpdateType(UpdateType.Local);
1827
-
1828
- if (this.props.rtt === true) {
1829
- this.framebufferDimensions!.width = value;
1830
- this.texture = this.stage.txManager.createTexture(
1831
- 'RenderTexture',
1832
- this.framebufferDimensions!,
1833
- );
1834
-
1835
- this.setUpdateType(UpdateType.RenderTexture);
1836
- }
1837
- }
1838
- }
1839
-
1840
- get height(): number {
1841
- return this.props.height;
1842
- }
1843
-
1844
- set height(value: number) {
1845
- if (this.props.height !== value) {
1846
- this.props.height = value;
1847
- this.setUpdateType(UpdateType.Local);
1848
-
1849
- if (this.props.rtt === true) {
1850
- this.framebufferDimensions!.height = value;
1851
- this.texture = this.stage.txManager.createTexture(
1852
- 'RenderTexture',
1853
- this.framebufferDimensions!,
1854
- );
1855
-
1856
- this.setUpdateType(UpdateType.RenderTexture);
1857
- }
1858
- }
1859
- }
1860
-
1861
- get scale(): number {
1862
- // The CoreNode `scale` property is only used by Animations.
1863
- // Unlike INode, `null` should never be possibility for Animations.
1864
- return this.scaleX;
1865
- }
1866
-
1867
- set scale(value: number) {
1868
- // The CoreNode `scale` property is only used by Animations.
1869
- // Unlike INode, `null` should never be possibility for Animations.
1870
- this.scaleX = value;
1871
- this.scaleY = value;
1872
- }
1873
-
1874
- get scaleX(): number {
1875
- return this.props.scaleX;
1876
- }
1877
-
1878
- set scaleX(value: number) {
1879
- if (this.props.scaleX !== value) {
1880
- this.props.scaleX = value;
1881
- this.setUpdateType(UpdateType.ScaleRotate);
1882
- }
1883
- }
1884
-
1885
- get scaleY(): number {
1886
- return this.props.scaleY;
1887
- }
1888
-
1889
- set scaleY(value: number) {
1890
- if (this.props.scaleY !== value) {
1891
- this.props.scaleY = value;
1892
- this.setUpdateType(UpdateType.ScaleRotate);
1893
- }
1894
- }
1895
-
1896
- get mount(): number {
1897
- return this.props.mount;
1898
- }
1899
-
1900
- set mount(value: number) {
1901
- if (this.props.mountX !== value || this.props.mountY !== value) {
1902
- this.props.mountX = value;
1903
- this.props.mountY = value;
1904
- this.props.mount = value;
1905
- this.setUpdateType(UpdateType.Local);
1906
- }
1907
- }
1908
-
1909
- get mountX(): number {
1910
- return this.props.mountX;
1911
- }
1912
-
1913
- set mountX(value: number) {
1914
- if (this.props.mountX !== value) {
1915
- this.props.mountX = value;
1916
- this.setUpdateType(UpdateType.Local);
1917
- }
1918
- }
1919
-
1920
- get mountY(): number {
1921
- return this.props.mountY;
1922
- }
1923
-
1924
- set mountY(value: number) {
1925
- if (this.props.mountY !== value) {
1926
- this.props.mountY = value;
1927
- this.setUpdateType(UpdateType.Local);
1928
- }
1929
- }
1930
-
1931
- get pivot(): number {
1932
- return this.props.pivot;
1933
- }
1934
-
1935
- set pivot(value: number) {
1936
- if (this.props.pivotX !== value || this.props.pivotY !== value) {
1937
- this.props.pivotX = value;
1938
- this.props.pivotY = value;
1939
- this.props.pivot = value;
1940
- this.setUpdateType(UpdateType.Local);
1941
- }
1942
- }
1943
-
1944
- get pivotX(): number {
1945
- return this.props.pivotX;
1946
- }
1947
-
1948
- set pivotX(value: number) {
1949
- if (this.props.pivotX !== value) {
1950
- this.props.pivotX = value;
1951
- this.setUpdateType(UpdateType.Local);
1952
- }
1953
- }
1954
-
1955
- get pivotY(): number {
1956
- return this.props.pivotY;
1957
- }
1958
-
1959
- set pivotY(value: number) {
1960
- if (this.props.pivotY !== value) {
1961
- this.props.pivotY = value;
1962
- this.setUpdateType(UpdateType.Local);
1963
- }
1964
- }
1965
-
1966
- get rotation(): number {
1967
- return this.props.rotation;
1968
- }
1969
-
1970
- set rotation(value: number) {
1971
- if (this.props.rotation !== value) {
1972
- this.props.rotation = value;
1973
- this.setUpdateType(UpdateType.ScaleRotate);
1974
- }
1975
- }
1976
-
1977
- get alpha(): number {
1978
- return this.props.alpha;
1979
- }
1980
-
1981
- set alpha(value: number) {
1982
- this.props.alpha = value;
1983
- this.setUpdateType(
1984
- UpdateType.PremultipliedColors |
1985
- UpdateType.WorldAlpha |
1986
- UpdateType.Children |
1987
- UpdateType.IsRenderable,
1988
- );
1989
- this.childUpdateType |= UpdateType.WorldAlpha;
1990
- }
1991
-
1992
- get autosize(): boolean {
1993
- return this.props.autosize;
1994
- }
1995
-
1996
- set autosize(value: boolean) {
1997
- this.props.autosize = value;
1998
- }
1999
-
2000
- get boundsMargin(): number | [number, number, number, number] | null {
2001
- return (
2002
- this.props.boundsMargin ??
2003
- this.parent?.boundsMargin ??
2004
- this.stage.boundsMargin
2005
- );
2006
- }
2007
-
2008
- set boundsMargin(value: number | [number, number, number, number] | null) {
2009
- if (value === this.props.boundsMargin) {
2010
- return;
2011
- }
2012
-
2013
- if (value === null) {
2014
- this.props.boundsMargin = value;
2015
- } else {
2016
- const bm: [number, number, number, number] = Array.isArray(value)
2017
- ? value
2018
- : [value, value, value, value];
2019
-
2020
- this.props.boundsMargin = bm;
2021
- }
2022
- this.setUpdateType(UpdateType.RenderBounds);
2023
- }
2024
-
2025
- get clipping(): boolean {
2026
- return this.props.clipping;
2027
- }
2028
-
2029
- set clipping(value: boolean) {
2030
- this.props.clipping = value;
2031
- this.setUpdateType(
2032
- UpdateType.Clipping | UpdateType.RenderBounds | UpdateType.Children,
2033
- );
2034
- this.childUpdateType |= UpdateType.Global | UpdateType.Clipping;
2035
- }
2036
-
2037
- get color(): number {
2038
- return this.props.color;
2039
- }
2040
-
2041
- set color(value: number) {
2042
- this.colorTop = value;
2043
- this.colorBottom = value;
2044
- this.colorLeft = value;
2045
- this.colorRight = value;
2046
- this.props.color = value;
2047
-
2048
- this.setUpdateType(UpdateType.PremultipliedColors);
2049
- }
2050
-
2051
- get colorTop(): number {
2052
- return this.props.colorTop;
2053
- }
2054
-
2055
- set colorTop(value: number) {
2056
- if (this.props.colorTl !== value || this.props.colorTr !== value) {
2057
- this.colorTl = value;
2058
- this.colorTr = value;
2059
- }
2060
- this.props.colorTop = value;
2061
- this.setUpdateType(UpdateType.PremultipliedColors);
2062
- }
2063
-
2064
- get colorBottom(): number {
2065
- return this.props.colorBottom;
2066
- }
2067
-
2068
- set colorBottom(value: number) {
2069
- if (this.props.colorBl !== value || this.props.colorBr !== value) {
2070
- this.colorBl = value;
2071
- this.colorBr = value;
2072
- }
2073
- this.props.colorBottom = value;
2074
- this.setUpdateType(UpdateType.PremultipliedColors);
2075
- }
2076
-
2077
- get colorLeft(): number {
2078
- return this.props.colorLeft;
2079
- }
2080
-
2081
- set colorLeft(value: number) {
2082
- if (this.props.colorTl !== value || this.props.colorBl !== value) {
2083
- this.colorTl = value;
2084
- this.colorBl = value;
2085
- }
2086
- this.props.colorLeft = value;
2087
- this.setUpdateType(UpdateType.PremultipliedColors);
2088
- }
2089
-
2090
- get colorRight(): number {
2091
- return this.props.colorRight;
2092
- }
2093
-
2094
- set colorRight(value: number) {
2095
- if (this.props.colorTr !== value || this.props.colorBr !== value) {
2096
- this.colorTr = value;
2097
- this.colorBr = value;
2098
- }
2099
- this.props.colorRight = value;
2100
- this.setUpdateType(UpdateType.PremultipliedColors);
2101
- }
2102
-
2103
- get colorTl(): number {
2104
- return this.props.colorTl;
2105
- }
2106
-
2107
- set colorTl(value: number) {
2108
- this.props.colorTl = value;
2109
- this.setUpdateType(UpdateType.PremultipliedColors);
2110
- }
2111
-
2112
- get colorTr(): number {
2113
- return this.props.colorTr;
2114
- }
2115
-
2116
- set colorTr(value: number) {
2117
- this.props.colorTr = value;
2118
- this.setUpdateType(UpdateType.PremultipliedColors);
2119
- }
2120
-
2121
- get colorBl(): number {
2122
- return this.props.colorBl;
2123
- }
2124
-
2125
- set colorBl(value: number) {
2126
- this.props.colorBl = value;
2127
- this.setUpdateType(UpdateType.PremultipliedColors);
2128
- }
2129
-
2130
- get colorBr(): number {
2131
- return this.props.colorBr;
2132
- }
2133
-
2134
- set colorBr(value: number) {
2135
- this.props.colorBr = value;
2136
- this.setUpdateType(UpdateType.PremultipliedColors);
2137
- }
2138
-
2139
- // we're only interested in parent zIndex to test
2140
- // if we should use node zIndex is higher then parent zIndex
2141
- get zIndexLocked(): number {
2142
- return this.props.zIndexLocked || 0;
2143
- }
2144
-
2145
- set zIndexLocked(value: number) {
2146
- this.props.zIndexLocked = value;
2147
- this.setUpdateType(UpdateType.CalculatedZIndex | UpdateType.Children);
2148
- for (let i = 0, length = this.children.length; i < length; i++) {
2149
- this.children[i]!.setUpdateType(UpdateType.CalculatedZIndex);
2150
- }
2151
- }
2152
-
2153
- get zIndex(): number {
2154
- return this.props.zIndex;
2155
- }
2156
-
2157
- set zIndex(value: number) {
2158
- this.props.zIndex = value;
2159
- this.setUpdateType(UpdateType.CalculatedZIndex | UpdateType.Children);
2160
- for (let i = 0, length = this.children.length; i < length; i++) {
2161
- this.children[i]!.setUpdateType(UpdateType.CalculatedZIndex);
2162
- }
2163
- }
2164
-
2165
- get parent(): CoreNode | null {
2166
- return this.props.parent;
2167
- }
2168
-
2169
- set parent(newParent: CoreNode | null) {
2170
- const oldParent = this.props.parent;
2171
- if (oldParent === newParent) {
2172
- return;
2173
- }
2174
- this.props.parent = newParent;
2175
- if (oldParent) {
2176
- const index = oldParent.children.indexOf(this);
2177
- oldParent.children.splice(index, 1);
2178
- oldParent.setUpdateType(
2179
- UpdateType.Children | UpdateType.ZIndexSortedChildren,
2180
- );
2181
- }
2182
- if (newParent) {
2183
- newParent.children.push(this);
2184
- // Since this node has a new parent, to be safe, have it do a full update.
2185
- this.setUpdateType(UpdateType.All);
2186
- // Tell parent that it's children need to be updated and sorted.
2187
- newParent.setUpdateType(
2188
- UpdateType.Children | UpdateType.ZIndexSortedChildren,
2189
- );
2190
-
2191
- // If the new parent has an RTT enabled, apply RTT inheritance
2192
- if (newParent.rtt || newParent.parentHasRenderTexture) {
2193
- this.applyRTTInheritance(newParent);
2194
- }
2195
- }
2196
- this.updateScaleRotateTransform();
2197
-
2198
- // fetch render bounds from parent
2199
- this.setUpdateType(UpdateType.RenderBounds | UpdateType.Children);
2200
- }
2201
-
2202
- get rtt(): boolean {
2203
- return this.props.rtt;
2204
- }
2205
-
2206
- set rtt(value: boolean) {
2207
- if (this.props.rtt === value) {
2208
- return;
2209
- }
2210
- this.props.rtt = value;
2211
-
2212
- if (value === true) {
2213
- this.initRenderTexture();
2214
- this.markChildrenWithRTT();
2215
- } else {
2216
- this.cleanupRenderTexture();
2217
- }
2218
-
2219
- this.setUpdateType(UpdateType.RenderTexture);
2220
-
2221
- if (this.parentHasRenderTexture === true) {
2222
- this.notifyParentRTTOfUpdate();
2223
- }
2224
- }
2225
- private initRenderTexture() {
2226
- this.framebufferDimensions = {
2227
- width: this.width,
2228
- height: this.height,
2229
- };
2230
- this.texture = this.stage.txManager.createTexture(
2231
- 'RenderTexture',
2232
- this.framebufferDimensions,
2233
- );
2234
- this.stage.renderer.renderToTexture(this);
2235
- }
2236
-
2237
- private cleanupRenderTexture() {
2238
- this.unloadTexture();
2239
- this.clearRTTInheritance();
2240
-
2241
- this.hasRTTupdates = false;
2242
- this.texture = null;
2243
- this.framebufferDimensions = null;
2244
- }
2245
-
2246
- private markChildrenWithRTT(node: CoreNode | null = null) {
2247
- const parent = node || this;
2248
-
2249
- for (const child of parent.children) {
2250
- child.setUpdateType(UpdateType.All);
2251
- child.parentHasRenderTexture = true;
2252
- child.markChildrenWithRTT();
2253
- }
2254
- }
2255
-
2256
- // Apply RTT inheritance when a node has an RTT-enabled parent
2257
- private applyRTTInheritance(parent: CoreNode) {
2258
- if (parent.rtt) {
2259
- // Only the RTT node should be added to `renderToTexture`
2260
- parent.setUpdateType(UpdateType.RenderTexture);
2261
- }
2262
-
2263
- // Propagate `parentHasRenderTexture` downwards
2264
- this.markChildrenWithRTT(parent);
2265
- }
2266
-
2267
- // Clear RTT inheritance when detaching from an RTT chain
2268
- private clearRTTInheritance() {
2269
- // if this node is RTT itself stop the propagation important for nested RTT nodes
2270
- // for the initial RTT node this is already handled in `set rtt`
2271
- if (this.rtt) {
2272
- return;
2273
- }
2274
-
2275
- for (const child of this.children) {
2276
- // force child to update everything as the RTT inheritance has changed
2277
- child.parentHasRenderTexture = false;
2278
- child.rttParent = null;
2279
- child.setUpdateType(UpdateType.All);
2280
- child.clearRTTInheritance();
2281
- }
2282
- }
2283
-
2284
- get shader(): CoreShaderNode<any> | null {
2285
- return this.props.shader;
2286
- }
2287
-
2288
- set shader(shader: CoreShaderNode<any> | null) {
2289
- if (this.props.shader === shader) {
2290
- return;
2291
- }
2292
- if (shader === null) {
2293
- this.hasShaderUpdater = false;
2294
- this.props.shader = this.stage.defShaderNode;
2295
- this.setUpdateType(UpdateType.IsRenderable);
2296
- return;
2297
- }
2298
- if (shader.shaderKey !== 'default') {
2299
- this.hasShaderUpdater = shader.update !== undefined;
2300
- shader.attachNode(this);
2301
- }
2302
- this.props.shader = shader;
2303
- this.setUpdateType(UpdateType.IsRenderable | UpdateType.RecalcUniforms);
2304
- }
2305
-
2306
- get src(): string | null {
2307
- return this.props.src;
2308
- }
2309
-
2310
- set src(imageUrl: string | null) {
2311
- if (this.props.src === imageUrl) {
2312
- return;
2313
- }
2314
-
2315
- this.props.src = imageUrl;
2316
-
2317
- if (!imageUrl) {
2318
- this.texture = null;
2319
- return;
2320
- }
2321
-
2322
- this.texture = this.stage.txManager.createTexture('ImageTexture', {
2323
- src: imageUrl,
2324
- width: this.props.width,
2325
- height: this.props.height,
2326
- type: this.props.imageType,
2327
- sx: this.props.srcX,
2328
- sy: this.props.srcY,
2329
- sw: this.props.srcWidth,
2330
- sh: this.props.srcHeight,
2331
- });
2332
- }
2333
-
2334
- set imageType(type: 'regular' | 'compressed' | 'svg' | null) {
2335
- if (this.props.imageType === type) {
2336
- return;
2337
- }
2338
-
2339
- this.props.imageType = type;
2340
- }
2341
-
2342
- get imageType() {
2343
- return this.props.imageType || null;
2344
- }
2345
-
2346
- get srcHeight(): number | undefined {
2347
- return this.props.srcHeight;
2348
- }
2349
-
2350
- set srcHeight(value: number) {
2351
- this.props.srcHeight = value;
2352
- }
2353
-
2354
- get srcWidth(): number | undefined {
2355
- return this.props.srcWidth;
2356
- }
2357
-
2358
- set srcWidth(value: number) {
2359
- this.props.srcWidth = value;
2360
- }
2361
-
2362
- get srcX(): number | undefined {
2363
- return this.props.srcX;
2364
- }
2365
-
2366
- set srcX(value: number) {
2367
- this.props.srcX = value;
2368
- }
2369
-
2370
- get srcY(): number | undefined {
2371
- return this.props.srcY;
2372
- }
2373
-
2374
- set srcY(value: number) {
2375
- this.props.srcY = value;
2376
- }
2377
-
2378
- /**
2379
- * Returns the framebuffer dimensions of the RTT parent
2380
- */
2381
- get parentFramebufferDimensions(): Dimensions {
2382
- if (this.rttParent !== null) {
2383
- return this.rttParent.framebufferDimensions as Dimensions;
2384
- }
2385
- this.rttParent = this.findParentRTTNode() as CoreNode;
2386
- return this.rttParent.framebufferDimensions as Dimensions;
2387
- }
2388
-
2389
- /**
2390
- * Returns the parent render texture node if it exists.
2391
- */
2392
- get parentRenderTexture(): CoreNode | null {
2393
- let parent = this.parent;
2394
- while (parent) {
2395
- if (parent.rtt) {
2396
- return parent;
2397
- }
2398
- parent = parent.parent;
2399
- }
2400
- return null;
2401
- }
2402
-
2403
- get texture(): Texture | null {
2404
- return this.props.texture;
2405
- }
2406
-
2407
- set texture(value: Texture | null) {
2408
- if (this.props.texture === value) {
2409
- return;
2410
- }
2411
-
2412
- const oldTexture = this.props.texture;
2413
- if (oldTexture) {
2414
- oldTexture.setRenderableOwner(this, false);
2415
- this.unloadTexture();
2416
- }
2417
-
2418
- this.textureCoords = undefined;
2419
- this.props.texture = value;
2420
- if (value !== null) {
2421
- value.setRenderableOwner(this, this.isRenderable);
2422
- this.loadTexture();
2423
- }
2424
-
2425
- this.setUpdateType(UpdateType.IsRenderable);
2426
- }
2427
-
2428
- set textureOptions(value: TextureOptions) {
2429
- this.props.textureOptions = value;
2430
- }
2431
-
2432
- get textureOptions(): TextureOptions {
2433
- return this.props.textureOptions;
2434
- }
2435
-
2436
- get strictBounds(): boolean {
2437
- return this.props.strictBounds;
2438
- }
2439
-
2440
- set strictBounds(v) {
2441
- if (v === this.props.strictBounds) {
2442
- return;
2443
- }
2444
-
2445
- this.props.strictBounds = v;
2446
- this.setUpdateType(UpdateType.RenderBounds | UpdateType.Children);
2447
- this.childUpdateType |= UpdateType.RenderBounds | UpdateType.Children;
2448
- }
2449
-
2450
- animate(
2451
- props: Partial<CoreNodeAnimateProps>,
2452
- settings: Partial<AnimationSettings>,
2453
- ): IAnimationController {
2454
- const animation = new CoreAnimation(this, props, settings);
2455
-
2456
- const controller = new CoreAnimationController(
2457
- this.stage.animationManager,
2458
- animation,
2459
- );
2460
-
2461
- return controller;
2462
- }
2463
-
2464
- flush() {
2465
- // no-op
2466
- }
2467
-
2468
- //#endregion Properties
2469
- }
1
+ /*
2
+ * If not stated otherwise in this file or this component's LICENSE file the
3
+ * following copyright and licenses apply:
4
+ *
5
+ * Copyright 2023 Comcast Cable Communications Management, LLC.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the License);
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ import {
21
+ assertTruthy,
22
+ getNewId,
23
+ mergeColorAlphaPremultiplied,
24
+ } from '../utils.js';
25
+ import type { TextureOptions } from './CoreTextureManager.js';
26
+ import type { CoreRenderer } from './renderers/CoreRenderer.js';
27
+ import type { Stage } from './Stage.js';
28
+ import {
29
+ type Texture,
30
+ type TextureCoords,
31
+ type TextureFailedEventHandler,
32
+ type TextureFreedEventHandler,
33
+ type TextureLoadedEventHandler,
34
+ } from './textures/Texture.js';
35
+ import type {
36
+ Dimensions,
37
+ NodeTextureFailedPayload,
38
+ NodeTextureFreedPayload,
39
+ NodeTextureLoadedPayload,
40
+ } from '../common/CommonTypes.js';
41
+ import { EventEmitter } from '../common/EventEmitter.js';
42
+ import {
43
+ copyRect,
44
+ intersectRect,
45
+ type Bound,
46
+ type RectWithValid,
47
+ createBound,
48
+ boundInsideBound,
49
+ boundLargeThanBound,
50
+ createPreloadBounds,
51
+ } from './lib/utils.js';
52
+ import { Matrix3d } from './lib/Matrix3d.js';
53
+ import { RenderCoords } from './lib/RenderCoords.js';
54
+ import type { AnimationSettings } from './animations/CoreAnimation.js';
55
+ import type { IAnimationController } from '../common/IAnimationController.js';
56
+ import { CoreAnimation } from './animations/CoreAnimation.js';
57
+ import { CoreAnimationController } from './animations/CoreAnimationController.js';
58
+ import type { CoreShaderNode } from './renderers/CoreShaderNode.js';
59
+
60
+ export enum CoreNodeRenderState {
61
+ Init = 0,
62
+ OutOfBounds = 2,
63
+ InBounds = 4,
64
+ InViewport = 8,
65
+ }
66
+
67
+ const CoreNodeRenderStateMap: Map<CoreNodeRenderState, string> = new Map();
68
+ CoreNodeRenderStateMap.set(CoreNodeRenderState.Init, 'init');
69
+ CoreNodeRenderStateMap.set(CoreNodeRenderState.OutOfBounds, 'outOfBounds');
70
+ CoreNodeRenderStateMap.set(CoreNodeRenderState.InBounds, 'inBounds');
71
+ CoreNodeRenderStateMap.set(CoreNodeRenderState.InViewport, 'inViewport');
72
+
73
+ export enum UpdateType {
74
+ /**
75
+ * Child updates
76
+ */
77
+ Children = 1,
78
+
79
+ /**
80
+ * localTransform
81
+ *
82
+ * @remarks
83
+ * CoreNode Properties Updated:
84
+ * - `localTransform`
85
+ */
86
+ Local = 2,
87
+
88
+ /**
89
+ * globalTransform
90
+ *
91
+ * * @remarks
92
+ * CoreNode Properties Updated:
93
+ * - `globalTransform`
94
+ * - `renderBounds`
95
+ * - `renderCoords`
96
+ */
97
+ Global = 4,
98
+
99
+ /**
100
+ * Clipping rect update
101
+ *
102
+ * @remarks
103
+ * CoreNode Properties Updated:
104
+ * - `clippingRect`
105
+ */
106
+ Clipping = 8,
107
+
108
+ /**
109
+ * Calculated ZIndex update
110
+ *
111
+ * @remarks
112
+ * CoreNode Properties Updated:
113
+ * - `calcZIndex`
114
+ */
115
+ CalculatedZIndex = 16,
116
+
117
+ /**
118
+ * Z-Index Sorted Children update
119
+ *
120
+ * @remarks
121
+ * CoreNode Properties Updated:
122
+ * - `children` (sorts children by their `calcZIndex`)
123
+ */
124
+ ZIndexSortedChildren = 32,
125
+
126
+ /**
127
+ * Premultiplied Colors update
128
+ *
129
+ * @remarks
130
+ * CoreNode Properties Updated:
131
+ * - `premultipliedColorTl`
132
+ * - `premultipliedColorTr`
133
+ * - `premultipliedColorBl`
134
+ * - `premultipliedColorBr`
135
+ */
136
+ PremultipliedColors = 64,
137
+
138
+ /**
139
+ * World Alpha update
140
+ *
141
+ * @remarks
142
+ * CoreNode Properties Updated:
143
+ * - `worldAlpha` = `parent.worldAlpha` * `alpha`
144
+ */
145
+ WorldAlpha = 128,
146
+
147
+ /**
148
+ * Render State update
149
+ *
150
+ * @remarks
151
+ * CoreNode Properties Updated:
152
+ * - `renderState`
153
+ */
154
+ RenderState = 256,
155
+
156
+ /**
157
+ * Is Renderable update
158
+ *
159
+ * @remarks
160
+ * CoreNode Properties Updated:
161
+ * - `isRenderable`
162
+ */
163
+ IsRenderable = 512,
164
+
165
+ /**
166
+ * Render Texture update
167
+ */
168
+ RenderTexture = 1024,
169
+
170
+ /**
171
+ * Track if parent has render texture
172
+ */
173
+ ParentRenderTexture = 2048,
174
+
175
+ /**
176
+ * Render Bounds update
177
+ */
178
+ RenderBounds = 4096,
179
+
180
+ /**
181
+ * RecalcUniforms
182
+ */
183
+ RecalcUniforms = 8192,
184
+
185
+ /**
186
+ * None
187
+ */
188
+ None = 0,
189
+
190
+ /**
191
+ * All
192
+ */
193
+ All = 16383,
194
+ }
195
+
196
+ /**
197
+ * A custom data map which can be stored on an CoreNode
198
+ *
199
+ * @remarks
200
+ * This is a map of key-value pairs that can be stored on an INode. It is used
201
+ * to store custom data that can be used by the application.
202
+ * The data stored can only be of type string, number or boolean.
203
+ */
204
+ export type CustomDataMap = {
205
+ [key: string]: string | number | boolean | undefined;
206
+ };
207
+
208
+ /**
209
+ * Writable properties of a Node.
210
+ */
211
+ export interface CoreNodeProps {
212
+ /**
213
+ * The x coordinate of the Node's Mount Point.
214
+ *
215
+ * @remarks
216
+ * See {@link mountX} and {@link mountY} for more information about setting
217
+ * the Mount Point.
218
+ *
219
+ * @default `0`
220
+ */
221
+ x: number;
222
+ /**
223
+ * The y coordinate of the Node's Mount Point.
224
+ *
225
+ * @remarks
226
+ * See {@link mountX} and {@link mountY} for more information about setting
227
+ * the Mount Point.
228
+ *
229
+ * @default `0`
230
+ */
231
+ y: number;
232
+ /**
233
+ * The width of the Node.
234
+ *
235
+ * @default `0`
236
+ */
237
+ width: number;
238
+ /**
239
+ * The height of the Node.
240
+ *
241
+ * @default `0`
242
+ */
243
+ height: number;
244
+ /**
245
+ * The alpha opacity of the Node.
246
+ *
247
+ * @remarks
248
+ * The alpha value is a number between 0 and 1, where 0 is fully transparent
249
+ * and 1 is fully opaque.
250
+ *
251
+ * @default `1`
252
+ */
253
+ alpha: number;
254
+ /**
255
+ * Autosize mode
256
+ *
257
+ * @remarks
258
+ * When enabled, when a texture is loaded into the Node, the Node will
259
+ * automatically resize to the dimensions of the texture.
260
+ *
261
+ * Text Nodes are always autosized based on their text content regardless
262
+ * of this mode setting.
263
+ *
264
+ * @default `false`
265
+ */
266
+ autosize: boolean;
267
+ /**
268
+ * Margin around the Node's bounds for preloading
269
+ *
270
+ * @default `null`
271
+ */
272
+ boundsMargin: number | [number, number, number, number] | null;
273
+ /**
274
+ * Clipping Mode
275
+ *
276
+ * @remarks
277
+ * Enable Clipping Mode when you want to prevent the drawing of a Node and
278
+ * its descendants from overflowing outside of the Node's x/y/width/height
279
+ * bounds.
280
+ *
281
+ * For WebGL, clipping is implemented using the high-performance WebGL
282
+ * operation scissor. As a consequence, clipping does not work for
283
+ * non-rectangular areas. So, if the element is rotated
284
+ * (by itself or by any of its ancestors), clipping will not work as intended.
285
+ *
286
+ * TODO: Add support for non-rectangular clipping either automatically or
287
+ * via Render-To-Texture.
288
+ *
289
+ * @default `false`
290
+ */
291
+ clipping: boolean;
292
+ /**
293
+ * The color of the Node.
294
+ *
295
+ * @remarks
296
+ * The color value is a number in the format 0xRRGGBBAA, where RR is the red
297
+ * component, GG is the green component, BB is the blue component, and AA is
298
+ * the alpha component.
299
+ *
300
+ * Gradient colors may be set by setting the different color sub-properties:
301
+ * {@link colorTop}, {@link colorBottom}, {@link colorLeft}, {@link colorRight},
302
+ * {@link colorTl}, {@link colorTr}, {@link colorBr}, {@link colorBl} accordingly.
303
+ *
304
+ * @default `0xffffffff` (opaque white)
305
+ */
306
+ color: number;
307
+ /**
308
+ * The color of the top edge of the Node for gradient rendering.
309
+ *
310
+ * @remarks
311
+ * See {@link color} for more information about color values and gradient
312
+ * rendering.
313
+ */
314
+ colorTop: number;
315
+ /**
316
+ * The color of the bottom edge of the Node for gradient rendering.
317
+ *
318
+ * @remarks
319
+ * See {@link color} for more information about color values and gradient
320
+ * rendering.
321
+ */
322
+ colorBottom: number;
323
+ /**
324
+ * The color of the left edge of the Node for gradient rendering.
325
+ *
326
+ * @remarks
327
+ * See {@link color} for more information about color values and gradient
328
+ * rendering.
329
+ */
330
+ colorLeft: number;
331
+ /**
332
+ * The color of the right edge of the Node for gradient rendering.
333
+ *
334
+ * @remarks
335
+ * See {@link color} for more information about color values and gradient
336
+ * rendering.
337
+ */
338
+ colorRight: number;
339
+ /**
340
+ * The color of the top-left corner of the Node for gradient rendering.
341
+ *
342
+ * @remarks
343
+ * See {@link color} for more information about color values and gradient
344
+ * rendering.
345
+ */
346
+ colorTl: number;
347
+ /**
348
+ * The color of the top-right corner of the Node for gradient rendering.
349
+ *
350
+ * @remarks
351
+ * See {@link color} for more information about color values and gradient
352
+ * rendering.
353
+ */
354
+ colorTr: number;
355
+ /**
356
+ * The color of the bottom-right corner of the Node for gradient rendering.
357
+ *
358
+ * @remarks
359
+ * See {@link color} for more information about color values and gradient
360
+ * rendering.
361
+ */
362
+ colorBr: number;
363
+ /**
364
+ * The color of the bottom-left corner of the Node for gradient rendering.
365
+ *
366
+ * @remarks
367
+ * See {@link color} for more information about color values and gradient
368
+ * rendering.
369
+ */
370
+ colorBl: number;
371
+ /**
372
+ * The Node's parent Node.
373
+ *
374
+ * @remarks
375
+ * The value `null` indicates that the Node has no parent. This may either be
376
+ * because the Node is the root Node of the scene graph, or because the Node
377
+ * has been removed from the scene graph.
378
+ *
379
+ * In order to make sure that a Node can be rendered on the screen, it must
380
+ * be added to the scene graph by setting it's parent property to a Node that
381
+ * is already in the scene graph such as the root Node.
382
+ *
383
+ * @default `null`
384
+ */
385
+ parent: CoreNode | null;
386
+ /**
387
+ * The Node's z-index.
388
+ *
389
+ * @remarks
390
+ * TBD
391
+ */
392
+ zIndex: number;
393
+ /**
394
+ * The Node's Texture.
395
+ *
396
+ * @remarks
397
+ * The `texture` defines a rasterized image that is contained within the
398
+ * {@link width} and {@link height} dimensions of the Node. If null, the
399
+ * Node will use an opaque white {@link ColorTexture} when being drawn, which
400
+ * essentially enables colors (including gradients) to be drawn.
401
+ *
402
+ * If set, by default, the texture will be drawn, as is, stretched to the
403
+ * dimensions of the Node. This behavior can be modified by setting the TBD
404
+ * and TBD properties.
405
+ *
406
+ * To create a Texture in order to set it on this property, call
407
+ * {@link RendererMain.createTexture}.
408
+ *
409
+ * If the {@link src} is set on a Node, the Node will use the
410
+ * {@link ImageTexture} by default and the Node will simply load the image at
411
+ * the specified URL.
412
+ *
413
+ * Note: If this is a Text Node, the Texture will be managed by the Node's
414
+ * {@link TextRenderer} and should not be set explicitly.
415
+ */
416
+ texture: Texture | null;
417
+
418
+ /**
419
+ * Options to associate with the Node's Texture
420
+ */
421
+ textureOptions: TextureOptions;
422
+
423
+ /**
424
+ * The Node's shader
425
+ *
426
+ * @remarks
427
+ * The `shader` defines a {@link Shader} used to draw the Node. By default,
428
+ * the Default Shader is used which simply draws the defined {@link texture}
429
+ * or {@link color}(s) within the Node without any special effects.
430
+ *
431
+ * To create a Shader in order to set it on this property, call
432
+ * {@link RendererMain.createShader}.
433
+ *
434
+ * Note: If this is a Text Node, the Shader will be managed by the Node's
435
+ * {@link TextRenderer} and should not be set explicitly.
436
+ */
437
+ shader: CoreShaderNode<any> | null;
438
+ /**
439
+ * Image URL
440
+ *
441
+ * @remarks
442
+ * When set, the Node's {@link texture} is automatically set to an
443
+ * {@link ImageTexture} using the source image URL provided (with all other
444
+ * settings being defaults)
445
+ */
446
+ src: string | null;
447
+ zIndexLocked: number;
448
+ /**
449
+ * Scale to render the Node at
450
+ *
451
+ * @remarks
452
+ * The scale value multiplies the provided {@link width} and {@link height}
453
+ * of the Node around the Node's Pivot Point (defined by the {@link pivot}
454
+ * props).
455
+ *
456
+ * Behind the scenes, setting this property sets both the {@link scaleX} and
457
+ * {@link scaleY} props to the same value.
458
+ *
459
+ * NOTE: When the scaleX and scaleY props are explicitly set to different values,
460
+ * this property returns `null`. Setting `null` on this property will have no
461
+ * effect.
462
+ *
463
+ * @default 1.0
464
+ */
465
+ scale: number | null;
466
+ /**
467
+ * Scale to render the Node at (X-Axis)
468
+ *
469
+ * @remarks
470
+ * The scaleX value multiplies the provided {@link width} of the Node around
471
+ * the Node's Pivot Point (defined by the {@link pivot} props).
472
+ *
473
+ * @default 1.0
474
+ */
475
+ scaleX: number;
476
+ /**
477
+ * Scale to render the Node at (Y-Axis)
478
+ *
479
+ * @remarks
480
+ * The scaleY value multiplies the provided {@link height} of the Node around
481
+ * the Node's Pivot Point (defined by the {@link pivot} props).
482
+ *
483
+ * @default 1.0
484
+ */
485
+ scaleY: number;
486
+ /**
487
+ * Combined position of the Node's Mount Point
488
+ *
489
+ * @remarks
490
+ * The value can be any number between `0.0` and `1.0`:
491
+ * - `0.0` defines the Mount Point at the top-left corner of the Node.
492
+ * - `0.5` defines it at the center of the Node.
493
+ * - `1.0` defines it at the bottom-right corner of the node.
494
+ *
495
+ * Use the {@link mountX} and {@link mountY} props seperately for more control
496
+ * of the Mount Point.
497
+ *
498
+ * When assigned, the same value is also passed to both the {@link mountX} and
499
+ * {@link mountY} props.
500
+ *
501
+ * @default 0 (top-left)
502
+ */
503
+ mount: number;
504
+ /**
505
+ * X position of the Node's Mount Point
506
+ *
507
+ * @remarks
508
+ * The value can be any number between `0.0` and `1.0`:
509
+ * - `0.0` defines the Mount Point's X position as the left-most edge of the
510
+ * Node
511
+ * - `0.5` defines it as the horizontal center of the Node
512
+ * - `1.0` defines it as the right-most edge of the Node.
513
+ *
514
+ * The combination of {@link mountX} and {@link mountY} define the Mount Point
515
+ *
516
+ * @default 0 (left-most edge)
517
+ */
518
+ mountX: number;
519
+ /**
520
+ * Y position of the Node's Mount Point
521
+ *
522
+ * @remarks
523
+ * The value can be any number between `0.0` and `1.0`:
524
+ * - `0.0` defines the Mount Point's Y position as the top-most edge of the
525
+ * Node
526
+ * - `0.5` defines it as the vertical center of the Node
527
+ * - `1.0` defines it as the bottom-most edge of the Node.
528
+ *
529
+ * The combination of {@link mountX} and {@link mountY} define the Mount Point
530
+ *
531
+ * @default 0 (top-most edge)
532
+ */
533
+ mountY: number;
534
+ /**
535
+ * Combined position of the Node's Pivot Point
536
+ *
537
+ * @remarks
538
+ * The value can be any number between `0.0` and `1.0`:
539
+ * - `0.0` defines the Pivot Point at the top-left corner of the Node.
540
+ * - `0.5` defines it at the center of the Node.
541
+ * - `1.0` defines it at the bottom-right corner of the node.
542
+ *
543
+ * Use the {@link pivotX} and {@link pivotY} props seperately for more control
544
+ * of the Pivot Point.
545
+ *
546
+ * When assigned, the same value is also passed to both the {@link pivotX} and
547
+ * {@link pivotY} props.
548
+ *
549
+ * @default 0.5 (center)
550
+ */
551
+ pivot: number;
552
+ /**
553
+ * X position of the Node's Pivot Point
554
+ *
555
+ * @remarks
556
+ * The value can be any number between `0.0` and `1.0`:
557
+ * - `0.0` defines the Pivot Point's X position as the left-most edge of the
558
+ * Node
559
+ * - `0.5` defines it as the horizontal center of the Node
560
+ * - `1.0` defines it as the right-most edge of the Node.
561
+ *
562
+ * The combination of {@link pivotX} and {@link pivotY} define the Pivot Point
563
+ *
564
+ * @default 0.5 (centered on x-axis)
565
+ */
566
+ pivotX: number;
567
+ /**
568
+ * Y position of the Node's Pivot Point
569
+ *
570
+ * @remarks
571
+ * The value can be any number between `0.0` and `1.0`:
572
+ * - `0.0` defines the Pivot Point's Y position as the top-most edge of the
573
+ * Node
574
+ * - `0.5` defines it as the vertical center of the Node
575
+ * - `1.0` defines it as the bottom-most edge of the Node.
576
+ *
577
+ * The combination of {@link pivotX} and {@link pivotY} define the Pivot Point
578
+ *
579
+ * @default 0.5 (centered on y-axis)
580
+ */
581
+ pivotY: number;
582
+ /**
583
+ * Rotation of the Node (in Radians)
584
+ *
585
+ * @remarks
586
+ * Sets the amount to rotate the Node by around it's Pivot Point (defined by
587
+ * the {@link pivot} props). Positive values rotate the Node clockwise, while
588
+ * negative values rotate it counter-clockwise.
589
+ *
590
+ * Example values:
591
+ * - `-Math.PI / 2`: 90 degree rotation counter-clockwise
592
+ * - `0`: No rotation
593
+ * - `Math.PI / 2`: 90 degree rotation clockwise
594
+ * - `Math.PI`: 180 degree rotation clockwise
595
+ * - `3 * Math.PI / 2`: 270 degree rotation clockwise
596
+ * - `2 * Math.PI`: 360 rotation clockwise
597
+ */
598
+ rotation: number;
599
+
600
+ /**
601
+ * Whether the Node is rendered to a texture
602
+ *
603
+ * @remarks
604
+ * TBD
605
+ *
606
+ * @default false
607
+ */
608
+ rtt: boolean;
609
+
610
+ /**
611
+ * Node data element for custom data storage (optional)
612
+ *
613
+ * @remarks
614
+ * This property is used to store custom data on the Node as a key/value data store.
615
+ * Data values are limited to string, numbers, booleans. Strings will be truncated
616
+ * to a 2048 character limit for performance reasons.
617
+ *
618
+ * This is not a data storage mechanism for large amounts of data please use a
619
+ * dedicated data storage mechanism for that.
620
+ *
621
+ * The custom data will be reflected in the inspector as part of `data-*` attributes
622
+ *
623
+ * @default `undefined`
624
+ */
625
+ data?: CustomDataMap;
626
+
627
+ /**
628
+ * Image Type to explicitly set the image type that is being loaded
629
+ *
630
+ * @remarks
631
+ * This property must be used with a `src` that points at an image. In some cases
632
+ * the extension doesn't provide a reliable representation of the image type. In such
633
+ * cases set the ImageType explicitly.
634
+ *
635
+ * `regular` is used for normal images such as png, jpg, etc
636
+ * `compressed` is used for ETC1/ETC2 compressed images with a PVR or KTX container
637
+ * `svg` is used for scalable vector graphics
638
+ *
639
+ * @default `undefined`
640
+ */
641
+ imageType?: 'regular' | 'compressed' | 'svg' | null;
642
+
643
+ /**
644
+ * She width of the rectangle from which the Image Texture will be extracted.
645
+ * This value can be negative. If not provided, the image's source natural
646
+ * width will be used.
647
+ */
648
+ srcWidth?: number;
649
+ /**
650
+ * The height of the rectangle from which the Image Texture will be extracted.
651
+ * This value can be negative. If not provided, the image's source natural
652
+ * height will be used.
653
+ */
654
+ srcHeight?: number;
655
+ /**
656
+ * The x coordinate of the reference point of the rectangle from which the Texture
657
+ * will be extracted. `width` and `height` are provided. And only works when
658
+ * createImageBitmap is available. Only works when createImageBitmap is supported on the browser.
659
+ */
660
+ srcX?: number;
661
+ /**
662
+ * The y coordinate of the reference point of the rectangle from which the Texture
663
+ * will be extracted. Only used when source `srcWidth` width and `srcHeight` height
664
+ * are provided. Only works when createImageBitmap is supported on the browser.
665
+ */
666
+ srcY?: number;
667
+ /**
668
+ * Mark the node as interactive so we can perform hit tests on it
669
+ * when pointer events are registered.
670
+ * @default false
671
+ */
672
+ interactive?: boolean;
673
+ /**
674
+ * By enabling Strict bounds the renderer will not process & render child nodes of a node that is out of the visible area
675
+ *
676
+ * @remarks
677
+ * When enabled out of bound nodes, i.e. nodes that are out of the visible area, will
678
+ * **NOT** have their children processed and renderer anymore. This means the children of a out of bound
679
+ * node will not receive update processing such as positioning updates and will not be drawn on screen.
680
+ * As such the rest of the branch of the update tree that sits below this node will not be processed anymore
681
+ *
682
+ * This is a big performance gain but may be disabled in cases where the width of the parent node is
683
+ * unknown and the render must process the child nodes regardless of the viewport status of the parent node
684
+ *
685
+ * @default true
686
+ */
687
+ strictBounds: boolean;
688
+ }
689
+
690
+ /**
691
+ * Grab all the number properties of type T
692
+ */
693
+ type NumberProps<T> = {
694
+ [Key in keyof T as NonNullable<T[Key]> extends number ? Key : never]: number;
695
+ };
696
+
697
+ /**
698
+ * Properties of a Node used by the animate() function
699
+ */
700
+ export interface CoreNodeAnimateProps extends NumberProps<CoreNodeProps> {
701
+ /**
702
+ * Shader properties to animate
703
+ */
704
+ shaderProps: Record<string, number>;
705
+ // TODO: textureProps: Record<string, number>;
706
+ }
707
+
708
+ /**
709
+ * A visual Node in the Renderer scene graph.
710
+ *
711
+ * @remarks
712
+ * CoreNode is an internally used class that represents a Renderer Node in the
713
+ * scene graph. See INode.ts for the public APIs exposed to Renderer users
714
+ * that include generic types for Shaders.
715
+ */
716
+ export class CoreNode extends EventEmitter {
717
+ readonly children: CoreNode[] = [];
718
+ protected _id: number = getNewId();
719
+ readonly props: CoreNodeProps;
720
+
721
+ private hasShaderUpdater = false;
722
+ private hasColorProps = false;
723
+
724
+ public updateType = UpdateType.All;
725
+ public childUpdateType = UpdateType.None;
726
+
727
+ public globalTransform?: Matrix3d;
728
+ public localTransform?: Matrix3d;
729
+ public sceneGlobalTransform?: Matrix3d;
730
+ public renderCoords?: RenderCoords;
731
+ public sceneRenderCoords?: RenderCoords;
732
+ public renderBound?: Bound;
733
+ public strictBound?: Bound;
734
+ public preloadBound?: Bound;
735
+ public clippingRect: RectWithValid = {
736
+ x: 0,
737
+ y: 0,
738
+ width: 0,
739
+ height: 0,
740
+ valid: false,
741
+ };
742
+ public textureCoords?: TextureCoords;
743
+ public updateTextureCoords?: boolean = false;
744
+ public isRenderable = false;
745
+ public renderState: CoreNodeRenderState = CoreNodeRenderState.Init;
746
+
747
+ public worldAlpha = 1;
748
+ public premultipliedColorTl = 0;
749
+ public premultipliedColorTr = 0;
750
+ public premultipliedColorBl = 0;
751
+ public premultipliedColorBr = 0;
752
+ public calcZIndex = 0;
753
+ public hasRTTupdates = false;
754
+ public parentHasRenderTexture = false;
755
+ public rttParent: CoreNode | null = null;
756
+ /**
757
+ * only used when rtt = true
758
+ */
759
+ public framebufferDimensions: Dimensions | null = null;
760
+
761
+ public destroyed = false;
762
+
763
+ constructor(readonly stage: Stage, props: CoreNodeProps) {
764
+ super();
765
+
766
+ const p = (this.props = {} as CoreNodeProps);
767
+
768
+ // Fast-path assign only known keys
769
+ p.x = props.x;
770
+ p.y = props.y;
771
+ p.width = props.width;
772
+ p.height = props.height;
773
+ p.alpha = props.alpha;
774
+ p.autosize = props.autosize;
775
+ p.clipping = props.clipping;
776
+ p.color = props.color;
777
+
778
+ p.colorTop = props.colorTop;
779
+ p.colorBottom = props.colorBottom;
780
+ p.colorLeft = props.colorLeft;
781
+ p.colorRight = props.colorRight;
782
+ p.colorTl = props.colorTl;
783
+ p.colorTr = props.colorTr;
784
+ p.colorBl = props.colorBl;
785
+ p.colorBr = props.colorBr;
786
+
787
+ p.scaleX = props.scaleX;
788
+ p.scaleY = props.scaleY;
789
+ p.rotation = props.rotation;
790
+ p.pivotX = props.pivotX;
791
+ p.pivotY = props.pivotY;
792
+ p.mountX = props.mountX;
793
+ p.mountY = props.mountY;
794
+ p.mount = props.mount;
795
+ p.pivot = props.pivot;
796
+ p.strictBounds = props.strictBounds;
797
+
798
+ p.zIndex = props.zIndex;
799
+ p.zIndexLocked = props.zIndexLocked;
800
+ p.textureOptions = props.textureOptions;
801
+
802
+ p.data = props.data;
803
+ p.imageType = props.imageType;
804
+ p.srcX = props.srcX;
805
+ p.srcY = props.srcY;
806
+ p.srcWidth = props.srcWidth;
807
+ p.srcHeight = props.srcHeight;
808
+
809
+ p.parent = null;
810
+ p.texture = null;
811
+ p.shader = null;
812
+ p.src = null;
813
+ p.rtt = false;
814
+ p.boundsMargin = null;
815
+
816
+ // Assign props to instances
817
+ this.parent = props.parent;
818
+ this.texture = props.texture;
819
+ this.shader = props.shader;
820
+ this.src = props.src;
821
+ this.rtt = props.rtt;
822
+ this.boundsMargin = props.boundsMargin;
823
+ this.interactive = props.interactive;
824
+
825
+ this.setUpdateType(
826
+ UpdateType.Local | UpdateType.RenderBounds | UpdateType.RenderState,
827
+ );
828
+
829
+ // if the default texture isn't loaded yet, wait for it to load
830
+ // this only happens when the node is created before the stage is ready
831
+ const dt = this.stage.defaultTexture;
832
+ if (dt !== null && dt.state !== 'loaded') {
833
+ dt.once('loaded', () => this.setUpdateType(UpdateType.IsRenderable));
834
+ }
835
+ }
836
+
837
+ //#region Textures
838
+ loadTexture(): void {
839
+ const { texture } = this.props;
840
+ if (!texture) {
841
+ return;
842
+ }
843
+
844
+ // If texture is already loaded / failed, trigger loaded event manually
845
+ // so that users get a consistent event experience.
846
+ // We do this in a microtask to allow listeners to be attached in the same
847
+ // synchronous task after calling loadTexture()
848
+ queueMicrotask(() => {
849
+ if (this.textureOptions.preload === true) {
850
+ this.stage.txManager.loadTexture(texture);
851
+ }
852
+
853
+ texture.preventCleanup =
854
+ this.props.textureOptions?.preventCleanup ?? false;
855
+ texture.on('loaded', this.onTextureLoaded);
856
+ texture.on('failed', this.onTextureFailed);
857
+ texture.on('freed', this.onTextureFreed);
858
+
859
+ // If the parent is a render texture, the initial texture status
860
+ // will be set to freed until the texture is processed by the
861
+ // Render RTT nodes. So we only need to listen fo changes and
862
+ // no need to check the texture.state until we restructure how
863
+ // textures are being processed.
864
+ if (this.parentHasRenderTexture) {
865
+ this.notifyParentRTTOfUpdate();
866
+ return;
867
+ }
868
+
869
+ if (texture.state === 'loaded') {
870
+ this.onTextureLoaded(texture, texture.dimensions!);
871
+ } else if (texture.state === 'failed') {
872
+ this.onTextureFailed(texture, texture.error!);
873
+ } else if (texture.state === 'freed') {
874
+ this.onTextureFreed(texture);
875
+ }
876
+ });
877
+ }
878
+
879
+ unloadTexture(): void {
880
+ if (this.texture === null) {
881
+ return;
882
+ }
883
+
884
+ const texture = this.texture;
885
+ texture.off('loaded', this.onTextureLoaded);
886
+ texture.off('failed', this.onTextureFailed);
887
+ texture.off('freed', this.onTextureFreed);
888
+ texture.setRenderableOwner(this, false);
889
+ }
890
+
891
+ autosizeNode(dimensions: Dimensions) {
892
+ if (this.autosize) {
893
+ this.width = dimensions.width;
894
+ this.height = dimensions.height;
895
+ }
896
+ }
897
+
898
+ private onTextureLoaded: TextureLoadedEventHandler = (_, dimensions) => {
899
+ this.autosizeNode(dimensions);
900
+ this.setUpdateType(UpdateType.IsRenderable);
901
+
902
+ // Texture was loaded. In case the RAF loop has already stopped, we request
903
+ // a render to ensure the texture is rendered.
904
+ this.stage.requestRender();
905
+
906
+ // If parent has a render texture, flag that we need to update
907
+ if (this.parentHasRenderTexture) {
908
+ this.notifyParentRTTOfUpdate();
909
+ }
910
+
911
+ // ignore 1x1 pixel textures
912
+ if (dimensions.width > 1 && dimensions.height > 1) {
913
+ this.emit('loaded', {
914
+ type: 'texture',
915
+ dimensions,
916
+ } satisfies NodeTextureLoadedPayload);
917
+ }
918
+
919
+ // Trigger a local update if the texture is loaded and the resizeMode is 'contain'
920
+ if (this.props.textureOptions?.resizeMode?.type === 'contain') {
921
+ this.setUpdateType(UpdateType.Local);
922
+ }
923
+ };
924
+
925
+ private onTextureFailed: TextureFailedEventHandler = (_, error) => {
926
+ this.setUpdateType(UpdateType.IsRenderable);
927
+
928
+ // If parent has a render texture, flag that we need to update
929
+ if (this.parentHasRenderTexture) {
930
+ this.notifyParentRTTOfUpdate();
931
+ }
932
+
933
+ this.emit('failed', {
934
+ type: 'texture',
935
+ error,
936
+ } satisfies NodeTextureFailedPayload);
937
+ };
938
+
939
+ private onTextureFreed: TextureFreedEventHandler = () => {
940
+ this.setUpdateType(UpdateType.IsRenderable);
941
+
942
+ // If parent has a render texture, flag that we need to update
943
+ if (this.parentHasRenderTexture) {
944
+ this.notifyParentRTTOfUpdate();
945
+ }
946
+
947
+ this.emit('freed', {
948
+ type: 'texture',
949
+ } satisfies NodeTextureFreedPayload);
950
+ };
951
+ //#endregion Textures
952
+
953
+ /**
954
+ * Change types types is used to determine the scope of the changes being applied
955
+ *
956
+ * @remarks
957
+ * See {@link UpdateType} for more information on each type
958
+ *
959
+ * @param type
960
+ */
961
+ setUpdateType(type: UpdateType): void {
962
+ this.updateType |= type;
963
+
964
+ const parent = this.props.parent;
965
+ if (!parent) return;
966
+
967
+ parent.setUpdateType(UpdateType.Children);
968
+ }
969
+
970
+ sortChildren() {
971
+ this.children.sort((a, b) => a.calcZIndex - b.calcZIndex);
972
+ }
973
+
974
+ updateLocalTransform() {
975
+ const p = this.props;
976
+ const { x, y, width, height } = p;
977
+ const mountTranslateX = p.mountX * width;
978
+ const mountTranslateY = p.mountY * height;
979
+
980
+ if (p.rotation !== 0 || p.scaleX !== 1 || p.scaleY !== 1) {
981
+ const pivotTranslateX = p.pivotX * width;
982
+ const pivotTranslateY = p.pivotY * height;
983
+
984
+ this.localTransform = Matrix3d.translate(
985
+ x - mountTranslateX + pivotTranslateX,
986
+ y - mountTranslateY + pivotTranslateY,
987
+ this.localTransform,
988
+ )
989
+ .rotate(p.rotation)
990
+ .scale(p.scaleX, p.scaleY)
991
+ .translate(-pivotTranslateX, -pivotTranslateY);
992
+ } else {
993
+ this.localTransform = Matrix3d.translate(
994
+ x - mountTranslateX,
995
+ y - mountTranslateY,
996
+ this.localTransform,
997
+ );
998
+ }
999
+
1000
+ // Handle 'contain' resize mode
1001
+ const texture = p.texture;
1002
+ if (
1003
+ texture &&
1004
+ texture.dimensions &&
1005
+ p.textureOptions.resizeMode?.type === 'contain'
1006
+ ) {
1007
+ let resizeModeScaleX = 1;
1008
+ let resizeModeScaleY = 1;
1009
+ let extraX = 0;
1010
+ let extraY = 0;
1011
+ const { width: tw, height: th } = texture.dimensions;
1012
+ const txAspectRatio = tw / th;
1013
+ const nodeAspectRatio = width / height;
1014
+ if (txAspectRatio > nodeAspectRatio) {
1015
+ // Texture is wider than node
1016
+ // Center the node vertically (shift down by extraY)
1017
+ // Scale the node vertically to maintain original aspect ratio
1018
+ const scaleX = width / tw;
1019
+ const scaledTxHeight = th * scaleX;
1020
+ extraY = (height - scaledTxHeight) / 2;
1021
+ resizeModeScaleY = scaledTxHeight / height;
1022
+ } else {
1023
+ // Texture is taller than node (or equal)
1024
+ // Center the node horizontally (shift right by extraX)
1025
+ // Scale the node horizontally to maintain original aspect ratio
1026
+ const scaleY = height / th;
1027
+ const scaledTxWidth = tw * scaleY;
1028
+ extraX = (width - scaledTxWidth) / 2;
1029
+ resizeModeScaleX = scaledTxWidth / width;
1030
+ }
1031
+
1032
+ // Apply the extra translation and scale to the local transform
1033
+ this.localTransform
1034
+ .translate(extraX, extraY)
1035
+ .scale(resizeModeScaleX, resizeModeScaleY);
1036
+ }
1037
+ }
1038
+
1039
+ /**
1040
+ * @todo: test for correct calculation flag
1041
+ * @param delta
1042
+ */
1043
+ update(delta: number, parentClippingRect: RectWithValid): void {
1044
+ if (this.updateType === UpdateType.None) {
1045
+ return;
1046
+ }
1047
+
1048
+ const props = this.props;
1049
+ const parent = props.parent;
1050
+ const parentHasRenderTexture = this.parentHasRenderTexture;
1051
+ const hasParent = props.parent !== null;
1052
+
1053
+ let renderState: CoreNodeRenderState | null = null;
1054
+
1055
+ let updateType = this.updateType;
1056
+ let childUpdateType = this.childUpdateType;
1057
+ let updateParent = false;
1058
+
1059
+ if (updateType & UpdateType.Local) {
1060
+ this.updateLocalTransform();
1061
+
1062
+ updateType |= UpdateType.Global;
1063
+ updateParent = hasParent;
1064
+ }
1065
+
1066
+ // Handle specific RTT updates at this node level
1067
+ if (updateType & UpdateType.RenderTexture && this.rtt === true) {
1068
+ this.hasRTTupdates = true;
1069
+ }
1070
+
1071
+ if (updateType & UpdateType.Global) {
1072
+ if (this.parentHasRenderTexture === true && parent?.rtt === true) {
1073
+ // we are at the start of the RTT chain, so we need to reset the globalTransform
1074
+ // for correct RTT rendering
1075
+ this.globalTransform = Matrix3d.identity();
1076
+
1077
+ // Maintain a full scene global transform for bounds detection
1078
+ this.sceneGlobalTransform = Matrix3d.copy(
1079
+ parent?.globalTransform || Matrix3d.identity(),
1080
+ ).multiply(this.localTransform!);
1081
+ } else if (
1082
+ this.parentHasRenderTexture === true &&
1083
+ parent?.rtt === false
1084
+ ) {
1085
+ // we're part of an RTT chain but our parent is not the main RTT node
1086
+ // so we need to propogate the sceneGlobalTransform of the parent
1087
+ // to maintain a full scene global transform for bounds detection
1088
+ this.sceneGlobalTransform = Matrix3d.copy(
1089
+ parent?.sceneGlobalTransform || this.localTransform!,
1090
+ ).multiply(this.localTransform!);
1091
+
1092
+ this.globalTransform = Matrix3d.copy(
1093
+ parent?.globalTransform || this.localTransform!,
1094
+ this.globalTransform,
1095
+ );
1096
+ } else {
1097
+ this.globalTransform = Matrix3d.copy(
1098
+ parent?.globalTransform || this.localTransform!,
1099
+ this.globalTransform,
1100
+ );
1101
+ }
1102
+
1103
+ if (parent !== null) {
1104
+ this.globalTransform.multiply(this.localTransform!);
1105
+ }
1106
+ this.calculateRenderCoords();
1107
+ this.updateBoundingRect();
1108
+
1109
+ updateType |=
1110
+ UpdateType.RenderState |
1111
+ UpdateType.Children |
1112
+ UpdateType.RecalcUniforms;
1113
+ updateParent = hasParent;
1114
+ childUpdateType |= UpdateType.Global;
1115
+
1116
+ if (this.clipping === true) {
1117
+ updateType |= UpdateType.Clipping | UpdateType.RenderBounds;
1118
+ updateParent = hasParent;
1119
+ childUpdateType |= UpdateType.RenderBounds;
1120
+ }
1121
+ }
1122
+
1123
+ if (updateType & UpdateType.RenderBounds) {
1124
+ this.createRenderBounds();
1125
+
1126
+ updateType |= UpdateType.RenderState | UpdateType.Children;
1127
+ updateParent = hasParent;
1128
+ childUpdateType |= UpdateType.RenderBounds;
1129
+ }
1130
+
1131
+ if (updateType & UpdateType.RenderState) {
1132
+ renderState = this.checkRenderBounds();
1133
+
1134
+ updateType |= UpdateType.IsRenderable;
1135
+ updateParent = hasParent;
1136
+
1137
+ // if we're not going out of bounds, update the render state
1138
+ // this is done so the update loop can finish before we mark a node
1139
+ // as out of bounds
1140
+ if (renderState !== CoreNodeRenderState.OutOfBounds) {
1141
+ this.updateRenderState(renderState);
1142
+ }
1143
+ }
1144
+
1145
+ if (updateType & UpdateType.WorldAlpha) {
1146
+ this.worldAlpha = ((parent && parent.worldAlpha) || 1) * props.alpha;
1147
+ updateType |=
1148
+ UpdateType.PremultipliedColors |
1149
+ UpdateType.Children |
1150
+ UpdateType.IsRenderable;
1151
+ updateParent = hasParent;
1152
+ childUpdateType |= UpdateType.WorldAlpha;
1153
+ }
1154
+
1155
+ if (updateType & UpdateType.IsRenderable) {
1156
+ this.updateIsRenderable();
1157
+ }
1158
+
1159
+ if (updateType & UpdateType.Clipping) {
1160
+ this.calculateClippingRect(parentClippingRect);
1161
+ updateType |= UpdateType.Children;
1162
+ updateParent = hasParent;
1163
+
1164
+ childUpdateType |= UpdateType.Clipping | UpdateType.RenderBounds;
1165
+ }
1166
+
1167
+ if (updateType & UpdateType.PremultipliedColors) {
1168
+ const alpha = this.worldAlpha;
1169
+
1170
+ const tl = props.colorTl;
1171
+ const tr = props.colorTr;
1172
+ const bl = props.colorBl;
1173
+ const br = props.colorBr;
1174
+
1175
+ // Fast equality check (covers all 4 corners)
1176
+ const same = tl === tr && tl === bl && tl === br;
1177
+
1178
+ const merged = mergeColorAlphaPremultiplied(tl, alpha, true);
1179
+
1180
+ this.premultipliedColorTl = merged;
1181
+
1182
+ if (same) {
1183
+ this.premultipliedColorTr =
1184
+ this.premultipliedColorBl =
1185
+ this.premultipliedColorBr =
1186
+ merged;
1187
+ } else {
1188
+ this.premultipliedColorTr = mergeColorAlphaPremultiplied(
1189
+ tr,
1190
+ alpha,
1191
+ true,
1192
+ );
1193
+ this.premultipliedColorBl = mergeColorAlphaPremultiplied(
1194
+ bl,
1195
+ alpha,
1196
+ true,
1197
+ );
1198
+ this.premultipliedColorBr = mergeColorAlphaPremultiplied(
1199
+ br,
1200
+ alpha,
1201
+ true,
1202
+ );
1203
+ }
1204
+ }
1205
+
1206
+ if (updateParent === true) {
1207
+ parent!.setUpdateType(UpdateType.Children);
1208
+ }
1209
+ // No need to update zIndex if there is no parent
1210
+ if (updateType & UpdateType.CalculatedZIndex && parent !== null) {
1211
+ this.calculateZIndex();
1212
+ // Tell parent to re-sort children
1213
+ parent.setUpdateType(UpdateType.ZIndexSortedChildren);
1214
+ }
1215
+
1216
+ if (
1217
+ props.strictBounds === true &&
1218
+ this.renderState === CoreNodeRenderState.OutOfBounds
1219
+ ) {
1220
+ updateType &= ~UpdateType.RenderBounds; // remove render bounds update
1221
+ return;
1222
+ }
1223
+
1224
+ if (
1225
+ updateType & UpdateType.RecalcUniforms &&
1226
+ this.hasShaderUpdater === true
1227
+ ) {
1228
+ //this exists because the boolean hasShaderUpdater === true
1229
+ this.shader!.update!();
1230
+ }
1231
+
1232
+ if (updateType & UpdateType.Children && this.children.length > 0) {
1233
+ for (let i = 0, length = this.children.length; i < length; i++) {
1234
+ const child = this.children[i] as CoreNode;
1235
+
1236
+ child.setUpdateType(childUpdateType);
1237
+
1238
+ if (child.updateType === 0) {
1239
+ continue;
1240
+ }
1241
+
1242
+ let childClippingRect = this.clippingRect;
1243
+ if (this.rtt === true) {
1244
+ childClippingRect = {
1245
+ x: 0,
1246
+ y: 0,
1247
+ width: 0,
1248
+ height: 0,
1249
+ valid: false,
1250
+ };
1251
+ }
1252
+
1253
+ child.update(delta, childClippingRect);
1254
+ }
1255
+ }
1256
+
1257
+ // If the node has an RTT parent and requires a texture re-render, inform the RTT parent
1258
+ // if (this.parentHasRenderTexture && updateType & UpdateType.RenderTexture) {
1259
+ // @TODO have a more scoped down updateType for RTT updates
1260
+ if (parentHasRenderTexture === true) {
1261
+ this.notifyParentRTTOfUpdate();
1262
+ }
1263
+
1264
+ // Sorting children MUST happen after children have been updated so
1265
+ // that they have the oppotunity to update their calculated zIndex.
1266
+ if (updateType & UpdateType.ZIndexSortedChildren) {
1267
+ // reorder z-index
1268
+ this.sortChildren();
1269
+ }
1270
+
1271
+ if (this.updateTextureCoords === true) {
1272
+ this.updateTextureCoords = false;
1273
+ this.textureCoords = this.stage.renderer.getTextureCoords!(this);
1274
+ }
1275
+
1276
+ // If we're out of bounds, apply the render state now
1277
+ // this is done so nodes can finish their entire update loop before
1278
+ // being marked as out of bounds
1279
+ if (renderState === CoreNodeRenderState.OutOfBounds) {
1280
+ this.updateRenderState(renderState);
1281
+ this.updateIsRenderable();
1282
+
1283
+ if (
1284
+ this.rtt === true &&
1285
+ renderState === CoreNodeRenderState.OutOfBounds
1286
+ ) {
1287
+ // notify children that we are going out of bounds
1288
+ // we have to do this now before we stop processing the render tree
1289
+ this.notifyChildrenRTTOfUpdate(renderState);
1290
+ }
1291
+ }
1292
+
1293
+ // reset update type
1294
+ this.updateType = 0;
1295
+ this.childUpdateType = 0;
1296
+ }
1297
+
1298
+ private findParentRTTNode(): CoreNode | null {
1299
+ let rttNode: CoreNode | null = this.parent;
1300
+ while (rttNode && !rttNode.rtt) {
1301
+ rttNode = rttNode.parent;
1302
+ }
1303
+ return rttNode;
1304
+ }
1305
+
1306
+ private notifyChildrenRTTOfUpdate(renderState: CoreNodeRenderState) {
1307
+ for (const child of this.children) {
1308
+ // force child to update render state
1309
+ child.updateRenderState(renderState);
1310
+ child.updateIsRenderable();
1311
+ child.notifyChildrenRTTOfUpdate(renderState);
1312
+ }
1313
+ }
1314
+
1315
+ private notifyParentRTTOfUpdate() {
1316
+ if (this.parent === null) {
1317
+ return;
1318
+ }
1319
+
1320
+ const rttNode = this.rttParent || this.findParentRTTNode();
1321
+ if (!rttNode) {
1322
+ return;
1323
+ }
1324
+
1325
+ // If an RTT node is found, mark it for re-rendering
1326
+ rttNode.hasRTTupdates = true;
1327
+ rttNode.setUpdateType(UpdateType.RenderTexture);
1328
+
1329
+ // if rttNode is nested, also make it update its RTT parent
1330
+ if (rttNode.parentHasRenderTexture === true) {
1331
+ rttNode.notifyParentRTTOfUpdate();
1332
+ }
1333
+ }
1334
+
1335
+ checkRenderBounds(): CoreNodeRenderState {
1336
+ if (boundInsideBound(this.renderBound!, this.strictBound!)) {
1337
+ return CoreNodeRenderState.InViewport;
1338
+ }
1339
+
1340
+ if (boundInsideBound(this.renderBound!, this.preloadBound!)) {
1341
+ return CoreNodeRenderState.InBounds;
1342
+ }
1343
+
1344
+ // check if we're larger then our parent, we're definitely in the viewport
1345
+ if (boundLargeThanBound(this.renderBound!, this.strictBound!)) {
1346
+ return CoreNodeRenderState.InViewport;
1347
+ }
1348
+
1349
+ // check if we dont have dimensions, take our parent's render state
1350
+ if (
1351
+ this.parent !== null &&
1352
+ (this.props.width === 0 || this.props.height === 0)
1353
+ ) {
1354
+ return this.parent.renderState;
1355
+ }
1356
+
1357
+ return CoreNodeRenderState.OutOfBounds;
1358
+ }
1359
+
1360
+ updateBoundingRect() {
1361
+ const transform = (this.sceneGlobalTransform || this.globalTransform)!;
1362
+ const renderCoords = (this.sceneRenderCoords || this.renderCoords)!;
1363
+
1364
+ if (transform.tb === 0 || transform.tc === 0) {
1365
+ this.renderBound = createBound(
1366
+ renderCoords.x1,
1367
+ renderCoords.y1,
1368
+ renderCoords.x3,
1369
+ renderCoords.y3,
1370
+ this.renderBound,
1371
+ );
1372
+ } else {
1373
+ const { x1, y1, x2, y2, x3, y3, x4, y4 } = renderCoords;
1374
+ this.renderBound = createBound(
1375
+ Math.min(x1, x2, x3, x4),
1376
+ Math.min(y1, y2, y3, y4),
1377
+ Math.max(x1, x2, x3, x4),
1378
+ Math.max(y1, y2, y3, y4),
1379
+ this.renderBound,
1380
+ );
1381
+ }
1382
+ }
1383
+
1384
+ createRenderBounds(): void {
1385
+ if (this.parent !== null && this.parent.strictBound !== undefined) {
1386
+ // we have a parent with a valid bound, copy it
1387
+ const parentBound = this.parent.strictBound;
1388
+ this.strictBound = createBound(
1389
+ parentBound.x1,
1390
+ parentBound.y1,
1391
+ parentBound.x2,
1392
+ parentBound.y2,
1393
+ );
1394
+
1395
+ this.preloadBound = createPreloadBounds(
1396
+ this.strictBound,
1397
+ this.boundsMargin as [number, number, number, number],
1398
+ );
1399
+ } else {
1400
+ // no parent or parent does not have a bound, take the stage boundaries
1401
+ this.strictBound = this.stage.strictBound;
1402
+ this.preloadBound = this.stage.preloadBound;
1403
+ }
1404
+
1405
+ // if clipping is disabled, we're done
1406
+ if (this.props.clipping === false) {
1407
+ return;
1408
+ }
1409
+
1410
+ // only create local clipping bounds if node itself is in bounds
1411
+ // this can only be done if we have a render bound already
1412
+ if (this.renderBound === undefined) {
1413
+ return;
1414
+ }
1415
+
1416
+ // if we're out of bounds, we're done
1417
+ if (boundInsideBound(this.renderBound, this.strictBound) === false) {
1418
+ return;
1419
+ }
1420
+
1421
+ // clipping is enabled and we are in bounds create our own bounds
1422
+ const { x, y, width, height } = this.props;
1423
+
1424
+ // Pick the global transform if available, otherwise use the local transform
1425
+ // global transform is only available if the node in an RTT chain
1426
+ const { tx, ty } = this.sceneGlobalTransform || this.globalTransform || {};
1427
+ const _x = tx ?? x;
1428
+ const _y = ty ?? y;
1429
+ this.strictBound = createBound(
1430
+ _x,
1431
+ _y,
1432
+ _x + width,
1433
+ _y + height,
1434
+ this.strictBound,
1435
+ );
1436
+
1437
+ this.preloadBound = createPreloadBounds(
1438
+ this.strictBound,
1439
+ this.boundsMargin as [number, number, number, number],
1440
+ );
1441
+ }
1442
+
1443
+ updateRenderState(renderState: CoreNodeRenderState) {
1444
+ if (renderState === this.renderState) {
1445
+ return;
1446
+ }
1447
+
1448
+ const previous = this.renderState;
1449
+ this.renderState = renderState;
1450
+ const event = CoreNodeRenderStateMap.get(renderState);
1451
+ assertTruthy(event);
1452
+ this.emit(event, {
1453
+ previous,
1454
+ current: renderState,
1455
+ });
1456
+ }
1457
+
1458
+ /**
1459
+ * Updates the `isRenderable` property based on various conditions.
1460
+ */
1461
+ updateIsRenderable() {
1462
+ let newIsRenderable = false;
1463
+ let needsTextureOwnership = false;
1464
+
1465
+ // If the node is out of bounds or has an alpha of 0, it is not renderable
1466
+ if (
1467
+ this.worldAlpha === 0 ||
1468
+ this.renderState <= CoreNodeRenderState.OutOfBounds
1469
+ ) {
1470
+ this.updateTextureOwnership(false);
1471
+ this.setRenderable(false);
1472
+ return;
1473
+ }
1474
+
1475
+ if (this.texture !== null) {
1476
+ needsTextureOwnership = true;
1477
+
1478
+ // we're only renderable if the texture state is loaded
1479
+ newIsRenderable = this.texture.state === 'loaded';
1480
+ } else if (
1481
+ // check shader
1482
+ (this.props.shader !== null || this.hasColorProps === true) &&
1483
+ // check dimensions
1484
+ (this.props.width !== 0 && this.props.height !== 0) === true
1485
+ ) {
1486
+ // This mean we have dimensions and a color set, so we can render a ColorTexture
1487
+ if (
1488
+ this.stage.defaultTexture &&
1489
+ this.stage.defaultTexture.state === 'loaded'
1490
+ ) {
1491
+ newIsRenderable = true;
1492
+ }
1493
+ }
1494
+
1495
+ this.updateTextureOwnership(needsTextureOwnership);
1496
+ this.setRenderable(newIsRenderable);
1497
+ }
1498
+
1499
+ /**
1500
+ * Sets the renderable state and triggers changes if necessary.
1501
+ * @param isRenderable - The new renderable state
1502
+ */
1503
+ setRenderable(isRenderable: boolean) {
1504
+ this.isRenderable = isRenderable;
1505
+ if (
1506
+ isRenderable === true &&
1507
+ this.stage.calculateTextureCoord === true &&
1508
+ this.textureCoords === undefined
1509
+ ) {
1510
+ this.updateTextureCoords = true;
1511
+ }
1512
+ }
1513
+
1514
+ /**
1515
+ * Changes the renderable state of the node.
1516
+ */
1517
+ updateTextureOwnership(isRenderable: boolean) {
1518
+ this.texture?.setRenderableOwner(this, isRenderable);
1519
+ }
1520
+
1521
+ calculateRenderCoords() {
1522
+ const { width, height } = this;
1523
+
1524
+ const g = this.globalTransform!;
1525
+ const tx = g.tx,
1526
+ ty = g.ty,
1527
+ ta = g.ta,
1528
+ tb = g.tb,
1529
+ tc = g.tc,
1530
+ td = g.td;
1531
+ if (tb === 0 && tc === 0) {
1532
+ const minX = tx;
1533
+ const maxX = tx + width * ta;
1534
+ const minY = ty;
1535
+ const maxY = ty + height * td;
1536
+ this.renderCoords = RenderCoords.translate(
1537
+ //top-left
1538
+ minX,
1539
+ minY,
1540
+ //top-right
1541
+ maxX,
1542
+ minY,
1543
+ //bottom-right
1544
+ maxX,
1545
+ maxY,
1546
+ //bottom-left
1547
+ minX,
1548
+ maxY,
1549
+ this.renderCoords,
1550
+ );
1551
+ } else {
1552
+ this.renderCoords = RenderCoords.translate(
1553
+ //top-left
1554
+ tx,
1555
+ ty,
1556
+ //top-right
1557
+ tx + width * ta,
1558
+ ty + width * tc,
1559
+ //bottom-right
1560
+ tx + width * ta + height * tb,
1561
+ ty + width * tc + height * td,
1562
+ //bottom-left
1563
+ tx + height * tb,
1564
+ ty + height * td,
1565
+ this.renderCoords,
1566
+ );
1567
+ }
1568
+ if (this.sceneGlobalTransform === undefined) {
1569
+ return;
1570
+ }
1571
+
1572
+ const {
1573
+ tx: stx,
1574
+ ty: sty,
1575
+ ta: sta,
1576
+ tb: stb,
1577
+ tc: stc,
1578
+ td: std,
1579
+ } = this.sceneGlobalTransform;
1580
+ if (stb === 0 && stc === 0) {
1581
+ const minX = stx;
1582
+ const maxX = stx + width * sta;
1583
+ const minY = sty;
1584
+ const maxY = sty + height * std;
1585
+ this.sceneRenderCoords = RenderCoords.translate(
1586
+ //top-left
1587
+ minX,
1588
+ minY,
1589
+ //top-right
1590
+ maxX,
1591
+ minY,
1592
+ //bottom-right
1593
+ maxX,
1594
+ maxY,
1595
+ //bottom-left
1596
+ minX,
1597
+ maxY,
1598
+ this.sceneRenderCoords,
1599
+ );
1600
+ } else {
1601
+ this.sceneRenderCoords = RenderCoords.translate(
1602
+ //top-left
1603
+ stx,
1604
+ sty,
1605
+ //top-right
1606
+ stx + width * sta,
1607
+ sty + width * stc,
1608
+ //bottom-right
1609
+ stx + width * sta + height * stb,
1610
+ sty + width * stc + height * std,
1611
+ //bottom-left
1612
+ stx + height * stb,
1613
+ sty + height * std,
1614
+ this.sceneRenderCoords,
1615
+ );
1616
+ }
1617
+ }
1618
+
1619
+ /**
1620
+ * This function calculates the clipping rectangle for a node.
1621
+ *
1622
+ * The function then checks if the node is rotated. If the node requires clipping and is not rotated, a new clipping rectangle is created based on the node's global transform and dimensions.
1623
+ * If a parent clipping rectangle exists, it is intersected with the node's clipping rectangle (if it exists), or replaces the node's clipping rectangle.
1624
+ *
1625
+ * Finally, the node's parentClippingRect and clippingRect properties are updated.
1626
+ */
1627
+ calculateClippingRect(parentClippingRect: RectWithValid) {
1628
+ const { clippingRect, props, globalTransform: gt } = this;
1629
+ const { clipping } = props;
1630
+ const isRotated = gt!.tb !== 0 || gt!.tc !== 0;
1631
+
1632
+ if (clipping === true && isRotated === false) {
1633
+ clippingRect.x = gt!.tx;
1634
+ clippingRect.y = gt!.ty;
1635
+ clippingRect.width = this.width * gt!.ta;
1636
+ clippingRect.height = this.height * gt!.td;
1637
+ clippingRect.valid = true;
1638
+ } else {
1639
+ clippingRect.valid = false;
1640
+ }
1641
+
1642
+ if (parentClippingRect.valid === true && clippingRect.valid === true) {
1643
+ // Intersect parent clipping rect with node clipping rect
1644
+ intersectRect(parentClippingRect, clippingRect, clippingRect);
1645
+ } else if (parentClippingRect.valid === true) {
1646
+ // Copy parent clipping rect
1647
+ copyRect(parentClippingRect, clippingRect);
1648
+ clippingRect.valid = true;
1649
+ }
1650
+ }
1651
+
1652
+ calculateZIndex(): void {
1653
+ const props = this.props;
1654
+ const z = props.zIndex || 0;
1655
+ const p = props.parent?.zIndex || 0;
1656
+
1657
+ let zIndex = z;
1658
+ if (props.parent?.zIndexLocked) {
1659
+ zIndex = z < p ? z : p;
1660
+ }
1661
+ this.calcZIndex = zIndex;
1662
+ }
1663
+
1664
+ /**
1665
+ * Destroy the node and cleanup all resources
1666
+ */
1667
+ destroy(): void {
1668
+ if (this.destroyed === true) {
1669
+ return;
1670
+ }
1671
+
1672
+ this.removeAllListeners();
1673
+
1674
+ this.destroyed = true;
1675
+ this.unloadTexture();
1676
+ this.isRenderable = false;
1677
+
1678
+ // Kill children
1679
+ while (this.children.length > 0) {
1680
+ this.children[0]!.destroy();
1681
+ }
1682
+
1683
+ const parent = this.parent;
1684
+ if (parent !== null) {
1685
+ const index = parent.children.indexOf(this);
1686
+ parent.children.splice(index, 1);
1687
+ parent.setUpdateType(
1688
+ UpdateType.Children | UpdateType.ZIndexSortedChildren,
1689
+ );
1690
+ }
1691
+
1692
+ this.props.parent = null;
1693
+ this.props.texture = null;
1694
+
1695
+ if (this.rtt === true) {
1696
+ this.stage.renderer.removeRTTNode(this);
1697
+ }
1698
+ }
1699
+
1700
+ renderQuads(renderer: CoreRenderer): void {
1701
+ if (this.parentHasRenderTexture === true) {
1702
+ const rtt = renderer.renderToTextureActive;
1703
+ if (rtt === false || this.parentRenderTexture !== renderer.activeRttNode)
1704
+ return;
1705
+ }
1706
+
1707
+ const p = this.props;
1708
+ const t = this.globalTransform!;
1709
+ const coords = this.renderCoords;
1710
+ const texture = p.texture || this.stage.defaultTexture;
1711
+
1712
+ renderer.addQuad({
1713
+ width: p.width,
1714
+ height: p.height,
1715
+ colorTl: this.premultipliedColorTl,
1716
+ colorTr: this.premultipliedColorTr,
1717
+ colorBl: this.premultipliedColorBl,
1718
+ colorBr: this.premultipliedColorBr,
1719
+ texture,
1720
+ textureOptions: p.textureOptions,
1721
+ textureCoords: this.textureCoords,
1722
+ shader: p.shader as CoreShaderNode<any>,
1723
+ alpha: this.worldAlpha,
1724
+ clippingRect: this.clippingRect,
1725
+ tx: t.tx,
1726
+ ty: t.ty,
1727
+ ta: t.ta,
1728
+ tb: t.tb,
1729
+ tc: t.tc,
1730
+ td: t.td,
1731
+ renderCoords: coords,
1732
+ rtt: p.rtt,
1733
+ zIndex: this.calcZIndex,
1734
+ parentHasRenderTexture: this.parentHasRenderTexture,
1735
+ framebufferDimensions: this.parentHasRenderTexture
1736
+ ? this.parentFramebufferDimensions
1737
+ : null,
1738
+ });
1739
+ }
1740
+
1741
+ //#region Properties
1742
+ get id(): number {
1743
+ return this._id;
1744
+ }
1745
+
1746
+ get data(): CustomDataMap | undefined {
1747
+ return this.props.data;
1748
+ }
1749
+
1750
+ set data(d: CustomDataMap | undefined) {
1751
+ this.props.data = d;
1752
+ }
1753
+
1754
+ get x(): number {
1755
+ return this.props.x;
1756
+ }
1757
+
1758
+ set x(value: number) {
1759
+ if (this.props.x !== value) {
1760
+ this.props.x = value;
1761
+ this.setUpdateType(UpdateType.Local);
1762
+ }
1763
+ }
1764
+
1765
+ get absX(): number {
1766
+ return (
1767
+ this.props.x +
1768
+ -this.props.width * this.props.mountX +
1769
+ (this.props.parent?.absX || this.props.parent?.globalTransform?.tx || 0)
1770
+ );
1771
+ }
1772
+
1773
+ get absY(): number {
1774
+ return (
1775
+ this.props.y +
1776
+ -this.props.height * this.props.mountY +
1777
+ (this.props.parent?.absY ?? 0)
1778
+ );
1779
+ }
1780
+
1781
+ get y(): number {
1782
+ return this.props.y;
1783
+ }
1784
+
1785
+ set y(value: number) {
1786
+ if (this.props.y !== value) {
1787
+ this.props.y = value;
1788
+ this.setUpdateType(UpdateType.Local);
1789
+ }
1790
+ }
1791
+
1792
+ get width(): number {
1793
+ return this.props.width;
1794
+ }
1795
+
1796
+ set width(value: number) {
1797
+ if (this.props.width !== value) {
1798
+ this.textureCoords = undefined;
1799
+ this.props.width = value;
1800
+ this.setUpdateType(UpdateType.Local);
1801
+
1802
+ if (this.props.rtt === true) {
1803
+ this.framebufferDimensions!.width = value;
1804
+ this.texture = this.stage.txManager.createTexture(
1805
+ 'RenderTexture',
1806
+ this.framebufferDimensions!,
1807
+ );
1808
+
1809
+ this.setUpdateType(UpdateType.RenderTexture);
1810
+ }
1811
+ }
1812
+ }
1813
+
1814
+ get height(): number {
1815
+ return this.props.height;
1816
+ }
1817
+
1818
+ set height(value: number) {
1819
+ if (this.props.height !== value) {
1820
+ this.textureCoords = undefined;
1821
+ this.props.height = value;
1822
+ this.setUpdateType(UpdateType.Local);
1823
+
1824
+ if (this.props.rtt === true) {
1825
+ this.framebufferDimensions!.height = value;
1826
+ this.texture = this.stage.txManager.createTexture(
1827
+ 'RenderTexture',
1828
+ this.framebufferDimensions!,
1829
+ );
1830
+
1831
+ this.setUpdateType(UpdateType.RenderTexture);
1832
+ }
1833
+ }
1834
+ }
1835
+
1836
+ get scale(): number {
1837
+ // The CoreNode `scale` property is only used by Animations.
1838
+ // Unlike INode, `null` should never be possibility for Animations.
1839
+ return this.scaleX;
1840
+ }
1841
+
1842
+ set scale(value: number) {
1843
+ // The CoreNode `scale` property is only used by Animations.
1844
+ // Unlike INode, `null` should never be possibility for Animations.
1845
+ this.scaleX = value;
1846
+ this.scaleY = value;
1847
+ }
1848
+
1849
+ get scaleX(): number {
1850
+ return this.props.scaleX;
1851
+ }
1852
+
1853
+ set scaleX(value: number) {
1854
+ if (this.props.scaleX !== value) {
1855
+ this.props.scaleX = value;
1856
+ this.setUpdateType(UpdateType.Local);
1857
+ }
1858
+ }
1859
+
1860
+ get scaleY(): number {
1861
+ return this.props.scaleY;
1862
+ }
1863
+
1864
+ set scaleY(value: number) {
1865
+ if (this.props.scaleY !== value) {
1866
+ this.props.scaleY = value;
1867
+ this.setUpdateType(UpdateType.Local);
1868
+ }
1869
+ }
1870
+
1871
+ get mount(): number {
1872
+ return this.props.mount;
1873
+ }
1874
+
1875
+ set mount(value: number) {
1876
+ if (this.props.mountX !== value || this.props.mountY !== value) {
1877
+ this.props.mountX = value;
1878
+ this.props.mountY = value;
1879
+ this.props.mount = value;
1880
+ this.setUpdateType(UpdateType.Local);
1881
+ }
1882
+ }
1883
+
1884
+ get mountX(): number {
1885
+ return this.props.mountX;
1886
+ }
1887
+
1888
+ set mountX(value: number) {
1889
+ if (this.props.mountX !== value) {
1890
+ this.props.mountX = value;
1891
+ this.setUpdateType(UpdateType.Local);
1892
+ }
1893
+ }
1894
+
1895
+ get mountY(): number {
1896
+ return this.props.mountY;
1897
+ }
1898
+
1899
+ set mountY(value: number) {
1900
+ if (this.props.mountY !== value) {
1901
+ this.props.mountY = value;
1902
+ this.setUpdateType(UpdateType.Local);
1903
+ }
1904
+ }
1905
+
1906
+ get pivot(): number {
1907
+ return this.props.pivot;
1908
+ }
1909
+
1910
+ set pivot(value: number) {
1911
+ if (this.props.pivotX !== value || this.props.pivotY !== value) {
1912
+ this.props.pivotX = value;
1913
+ this.props.pivotY = value;
1914
+ this.props.pivot = value;
1915
+ this.setUpdateType(UpdateType.Local);
1916
+ }
1917
+ }
1918
+
1919
+ get pivotX(): number {
1920
+ return this.props.pivotX;
1921
+ }
1922
+
1923
+ set pivotX(value: number) {
1924
+ if (this.props.pivotX !== value) {
1925
+ this.props.pivotX = value;
1926
+ this.setUpdateType(UpdateType.Local);
1927
+ }
1928
+ }
1929
+
1930
+ get pivotY(): number {
1931
+ return this.props.pivotY;
1932
+ }
1933
+
1934
+ set pivotY(value: number) {
1935
+ if (this.props.pivotY !== value) {
1936
+ this.props.pivotY = value;
1937
+ this.setUpdateType(UpdateType.Local);
1938
+ }
1939
+ }
1940
+
1941
+ get rotation(): number {
1942
+ return this.props.rotation;
1943
+ }
1944
+
1945
+ set rotation(value: number) {
1946
+ if (this.props.rotation !== value) {
1947
+ this.props.rotation = value;
1948
+ this.setUpdateType(UpdateType.Local);
1949
+ }
1950
+ }
1951
+
1952
+ get alpha(): number {
1953
+ return this.props.alpha;
1954
+ }
1955
+
1956
+ set alpha(value: number) {
1957
+ this.props.alpha = value;
1958
+ this.setUpdateType(
1959
+ UpdateType.PremultipliedColors |
1960
+ UpdateType.WorldAlpha |
1961
+ UpdateType.Children |
1962
+ UpdateType.IsRenderable,
1963
+ );
1964
+ this.childUpdateType |= UpdateType.WorldAlpha;
1965
+ }
1966
+
1967
+ get autosize(): boolean {
1968
+ return this.props.autosize;
1969
+ }
1970
+
1971
+ set autosize(value: boolean) {
1972
+ this.props.autosize = value;
1973
+ }
1974
+
1975
+ get boundsMargin(): number | [number, number, number, number] | null {
1976
+ const props = this.props;
1977
+ if (props.boundsMargin !== null) {
1978
+ return props.boundsMargin;
1979
+ }
1980
+
1981
+ const parent = this.parent;
1982
+ if (parent !== null) {
1983
+ const margin = parent.boundsMargin;
1984
+ if (margin !== undefined) {
1985
+ return margin;
1986
+ }
1987
+ }
1988
+
1989
+ return this.stage.boundsMargin;
1990
+ }
1991
+
1992
+ set boundsMargin(value: number | [number, number, number, number] | null) {
1993
+ if (value === this.props.boundsMargin) {
1994
+ return;
1995
+ }
1996
+
1997
+ if (value === null) {
1998
+ this.props.boundsMargin = value;
1999
+ } else {
2000
+ const bm: [number, number, number, number] = Array.isArray(value)
2001
+ ? value
2002
+ : [value, value, value, value];
2003
+
2004
+ this.props.boundsMargin = bm;
2005
+ }
2006
+ this.setUpdateType(UpdateType.RenderBounds);
2007
+ }
2008
+
2009
+ get clipping(): boolean {
2010
+ return this.props.clipping;
2011
+ }
2012
+
2013
+ set clipping(value: boolean) {
2014
+ this.props.clipping = value;
2015
+ this.setUpdateType(
2016
+ UpdateType.Clipping | UpdateType.RenderBounds | UpdateType.Children,
2017
+ );
2018
+ this.childUpdateType |= UpdateType.Global | UpdateType.Clipping;
2019
+ }
2020
+
2021
+ get color(): number {
2022
+ return this.props.color;
2023
+ }
2024
+
2025
+ set color(value: number) {
2026
+ const p = this.props;
2027
+ if (p.color === value) return;
2028
+
2029
+ p.color = value;
2030
+
2031
+ const has = value > 0;
2032
+ this.hasColorProps = has;
2033
+
2034
+ if (p.colorTop !== value) this.colorTop = value;
2035
+ if (p.colorBottom !== value) this.colorBottom = value;
2036
+ if (p.colorLeft !== value) this.colorLeft = value;
2037
+ if (p.colorRight !== value) this.colorRight = value;
2038
+
2039
+ this.setUpdateType(UpdateType.PremultipliedColors);
2040
+ }
2041
+
2042
+ get colorTop(): number {
2043
+ return this.props.colorTop;
2044
+ }
2045
+
2046
+ set colorTop(value: number) {
2047
+ if (this.props.colorTl !== value || this.props.colorTr !== value) {
2048
+ this.colorTl = value;
2049
+ this.colorTr = value;
2050
+ }
2051
+ this.props.colorTop = value;
2052
+ this.hasColorProps = value > 0;
2053
+ this.setUpdateType(UpdateType.PremultipliedColors);
2054
+ }
2055
+
2056
+ get colorBottom(): number {
2057
+ return this.props.colorBottom;
2058
+ }
2059
+
2060
+ set colorBottom(value: number) {
2061
+ if (this.props.colorBl !== value || this.props.colorBr !== value) {
2062
+ this.colorBl = value;
2063
+ this.colorBr = value;
2064
+ }
2065
+ this.props.colorBottom = value;
2066
+ this.hasColorProps = value > 0;
2067
+ this.setUpdateType(UpdateType.PremultipliedColors);
2068
+ }
2069
+
2070
+ get colorLeft(): number {
2071
+ return this.props.colorLeft;
2072
+ }
2073
+
2074
+ set colorLeft(value: number) {
2075
+ if (this.props.colorTl !== value || this.props.colorBl !== value) {
2076
+ this.colorTl = value;
2077
+ this.colorBl = value;
2078
+ }
2079
+ this.props.colorLeft = value;
2080
+ this.hasColorProps = value > 0;
2081
+ this.setUpdateType(UpdateType.PremultipliedColors);
2082
+ }
2083
+
2084
+ get colorRight(): number {
2085
+ return this.props.colorRight;
2086
+ }
2087
+
2088
+ set colorRight(value: number) {
2089
+ if (this.props.colorTr !== value || this.props.colorBr !== value) {
2090
+ this.colorTr = value;
2091
+ this.colorBr = value;
2092
+ }
2093
+ this.props.colorRight = value;
2094
+ this.hasColorProps = value > 0;
2095
+ this.setUpdateType(UpdateType.PremultipliedColors);
2096
+ }
2097
+
2098
+ get colorTl(): number {
2099
+ return this.props.colorTl;
2100
+ }
2101
+
2102
+ set colorTl(value: number) {
2103
+ this.props.colorTl = value;
2104
+ this.hasColorProps = value > 0;
2105
+ this.setUpdateType(UpdateType.PremultipliedColors);
2106
+ }
2107
+
2108
+ get colorTr(): number {
2109
+ return this.props.colorTr;
2110
+ }
2111
+
2112
+ set colorTr(value: number) {
2113
+ this.props.colorTr = value;
2114
+ this.hasColorProps = value > 0;
2115
+ this.setUpdateType(UpdateType.PremultipliedColors);
2116
+ }
2117
+
2118
+ get colorBl(): number {
2119
+ return this.props.colorBl;
2120
+ }
2121
+
2122
+ set colorBl(value: number) {
2123
+ this.props.colorBl = value;
2124
+ this.hasColorProps = value > 0;
2125
+ this.setUpdateType(UpdateType.PremultipliedColors);
2126
+ }
2127
+
2128
+ get colorBr(): number {
2129
+ return this.props.colorBr;
2130
+ }
2131
+
2132
+ set colorBr(value: number) {
2133
+ this.props.colorBr = value;
2134
+ this.hasColorProps = value > 0;
2135
+ this.setUpdateType(UpdateType.PremultipliedColors);
2136
+ }
2137
+
2138
+ // we're only interested in parent zIndex to test
2139
+ // if we should use node zIndex is higher then parent zIndex
2140
+ get zIndexLocked(): number {
2141
+ return this.props.zIndexLocked || 0;
2142
+ }
2143
+
2144
+ set zIndexLocked(value: number) {
2145
+ this.props.zIndexLocked = value;
2146
+ this.setUpdateType(UpdateType.CalculatedZIndex | UpdateType.Children);
2147
+ for (let i = 0, length = this.children.length; i < length; i++) {
2148
+ this.children[i]!.setUpdateType(UpdateType.CalculatedZIndex);
2149
+ }
2150
+ }
2151
+
2152
+ get zIndex(): number {
2153
+ return this.props.zIndex;
2154
+ }
2155
+
2156
+ set zIndex(value: number) {
2157
+ this.props.zIndex = value;
2158
+ this.setUpdateType(UpdateType.CalculatedZIndex | UpdateType.Children);
2159
+ for (let i = 0, length = this.children.length; i < length; i++) {
2160
+ this.children[i]!.setUpdateType(UpdateType.CalculatedZIndex);
2161
+ }
2162
+ }
2163
+
2164
+ get parent(): CoreNode | null {
2165
+ return this.props.parent;
2166
+ }
2167
+
2168
+ set parent(newParent: CoreNode | null) {
2169
+ const oldParent = this.props.parent;
2170
+ if (oldParent === newParent) {
2171
+ return;
2172
+ }
2173
+ this.props.parent = newParent;
2174
+ if (oldParent) {
2175
+ const index = oldParent.children.indexOf(this);
2176
+ oldParent.children.splice(index, 1);
2177
+ oldParent.setUpdateType(
2178
+ UpdateType.Children | UpdateType.ZIndexSortedChildren,
2179
+ );
2180
+ }
2181
+ if (newParent) {
2182
+ newParent.children.push(this);
2183
+ // Since this node has a new parent, to be safe, have it do a full update.
2184
+ this.setUpdateType(UpdateType.All);
2185
+ // Tell parent that it's children need to be updated and sorted.
2186
+ newParent.setUpdateType(
2187
+ UpdateType.Children | UpdateType.ZIndexSortedChildren,
2188
+ );
2189
+
2190
+ // If the new parent has an RTT enabled, apply RTT inheritance
2191
+ if (newParent.rtt || newParent.parentHasRenderTexture) {
2192
+ this.applyRTTInheritance(newParent);
2193
+ }
2194
+ }
2195
+
2196
+ // fetch render bounds from parent
2197
+ this.setUpdateType(UpdateType.RenderBounds | UpdateType.Children);
2198
+ }
2199
+
2200
+ get rtt(): boolean {
2201
+ return this.props.rtt;
2202
+ }
2203
+
2204
+ set rtt(value: boolean) {
2205
+ if (this.props.rtt === value) {
2206
+ return;
2207
+ }
2208
+ this.props.rtt = value;
2209
+
2210
+ if (value === true) {
2211
+ this.initRenderTexture();
2212
+ this.markChildrenWithRTT();
2213
+ } else {
2214
+ this.cleanupRenderTexture();
2215
+ }
2216
+
2217
+ this.setUpdateType(UpdateType.RenderTexture);
2218
+
2219
+ if (this.parentHasRenderTexture === true) {
2220
+ this.notifyParentRTTOfUpdate();
2221
+ }
2222
+ }
2223
+ private initRenderTexture() {
2224
+ this.framebufferDimensions = {
2225
+ width: this.width,
2226
+ height: this.height,
2227
+ };
2228
+ this.texture = this.stage.txManager.createTexture(
2229
+ 'RenderTexture',
2230
+ this.framebufferDimensions,
2231
+ );
2232
+ this.stage.renderer.renderToTexture(this);
2233
+ }
2234
+
2235
+ private cleanupRenderTexture() {
2236
+ this.unloadTexture();
2237
+ this.clearRTTInheritance();
2238
+
2239
+ this.hasRTTupdates = false;
2240
+ this.texture = null;
2241
+ this.framebufferDimensions = null;
2242
+ }
2243
+
2244
+ private markChildrenWithRTT(node: CoreNode | null = null) {
2245
+ const parent = node || this;
2246
+
2247
+ for (const child of parent.children) {
2248
+ child.setUpdateType(UpdateType.All);
2249
+ child.parentHasRenderTexture = true;
2250
+ child.markChildrenWithRTT();
2251
+ }
2252
+ }
2253
+
2254
+ // Apply RTT inheritance when a node has an RTT-enabled parent
2255
+ private applyRTTInheritance(parent: CoreNode) {
2256
+ if (parent.rtt) {
2257
+ // Only the RTT node should be added to `renderToTexture`
2258
+ parent.setUpdateType(UpdateType.RenderTexture);
2259
+ }
2260
+
2261
+ // Propagate `parentHasRenderTexture` downwards
2262
+ this.markChildrenWithRTT(parent);
2263
+ }
2264
+
2265
+ // Clear RTT inheritance when detaching from an RTT chain
2266
+ private clearRTTInheritance() {
2267
+ // if this node is RTT itself stop the propagation important for nested RTT nodes
2268
+ // for the initial RTT node this is already handled in `set rtt`
2269
+ if (this.rtt) {
2270
+ return;
2271
+ }
2272
+
2273
+ for (const child of this.children) {
2274
+ // force child to update everything as the RTT inheritance has changed
2275
+ child.parentHasRenderTexture = false;
2276
+ child.rttParent = null;
2277
+ child.setUpdateType(UpdateType.All);
2278
+ child.clearRTTInheritance();
2279
+ }
2280
+ }
2281
+
2282
+ get shader(): CoreShaderNode<any> | null {
2283
+ return this.props.shader;
2284
+ }
2285
+
2286
+ set shader(shader: CoreShaderNode<any> | null) {
2287
+ if (this.props.shader === shader) {
2288
+ return;
2289
+ }
2290
+ if (shader === null) {
2291
+ this.hasShaderUpdater = false;
2292
+ this.props.shader = this.stage.defShaderNode;
2293
+ this.setUpdateType(UpdateType.IsRenderable);
2294
+ return;
2295
+ }
2296
+ if (shader.shaderKey !== 'default') {
2297
+ this.hasShaderUpdater = shader.update !== undefined;
2298
+ shader.attachNode(this);
2299
+ }
2300
+ this.props.shader = shader;
2301
+ this.setUpdateType(UpdateType.IsRenderable | UpdateType.RecalcUniforms);
2302
+ }
2303
+
2304
+ get src(): string | null {
2305
+ return this.props.src;
2306
+ }
2307
+
2308
+ set src(imageUrl: string | null) {
2309
+ if (this.props.src === imageUrl) {
2310
+ return;
2311
+ }
2312
+
2313
+ this.props.src = imageUrl;
2314
+
2315
+ if (!imageUrl) {
2316
+ this.texture = null;
2317
+ return;
2318
+ }
2319
+
2320
+ this.texture = this.stage.txManager.createTexture('ImageTexture', {
2321
+ src: imageUrl,
2322
+ width: this.props.width,
2323
+ height: this.props.height,
2324
+ type: this.props.imageType,
2325
+ sx: this.props.srcX,
2326
+ sy: this.props.srcY,
2327
+ sw: this.props.srcWidth,
2328
+ sh: this.props.srcHeight,
2329
+ });
2330
+ }
2331
+
2332
+ set imageType(type: 'regular' | 'compressed' | 'svg' | null) {
2333
+ if (this.props.imageType === type) {
2334
+ return;
2335
+ }
2336
+
2337
+ this.props.imageType = type;
2338
+ }
2339
+
2340
+ get imageType() {
2341
+ return this.props.imageType || null;
2342
+ }
2343
+
2344
+ get srcHeight(): number | undefined {
2345
+ return this.props.srcHeight;
2346
+ }
2347
+
2348
+ set srcHeight(value: number) {
2349
+ this.props.srcHeight = value;
2350
+ }
2351
+
2352
+ get srcWidth(): number | undefined {
2353
+ return this.props.srcWidth;
2354
+ }
2355
+
2356
+ set srcWidth(value: number) {
2357
+ this.props.srcWidth = value;
2358
+ }
2359
+
2360
+ get srcX(): number | undefined {
2361
+ return this.props.srcX;
2362
+ }
2363
+
2364
+ set srcX(value: number) {
2365
+ this.props.srcX = value;
2366
+ }
2367
+
2368
+ get srcY(): number | undefined {
2369
+ return this.props.srcY;
2370
+ }
2371
+
2372
+ set srcY(value: number) {
2373
+ this.props.srcY = value;
2374
+ }
2375
+
2376
+ /**
2377
+ * Returns the framebuffer dimensions of the RTT parent
2378
+ */
2379
+ get parentFramebufferDimensions(): Dimensions {
2380
+ if (this.rttParent !== null) {
2381
+ return this.rttParent.framebufferDimensions as Dimensions;
2382
+ }
2383
+ this.rttParent = this.findParentRTTNode() as CoreNode;
2384
+ return this.rttParent.framebufferDimensions as Dimensions;
2385
+ }
2386
+
2387
+ /**
2388
+ * Returns the parent render texture node if it exists.
2389
+ */
2390
+ get parentRenderTexture(): CoreNode | null {
2391
+ let parent = this.parent;
2392
+ while (parent) {
2393
+ if (parent.rtt) {
2394
+ return parent;
2395
+ }
2396
+ parent = parent.parent;
2397
+ }
2398
+ return null;
2399
+ }
2400
+
2401
+ get texture(): Texture | null {
2402
+ return this.props.texture;
2403
+ }
2404
+
2405
+ set texture(value: Texture | null) {
2406
+ if (this.props.texture === value) {
2407
+ return;
2408
+ }
2409
+
2410
+ const oldTexture = this.props.texture;
2411
+ if (oldTexture) {
2412
+ this.unloadTexture();
2413
+ }
2414
+
2415
+ this.textureCoords = undefined;
2416
+ this.props.texture = value;
2417
+ if (value !== null) {
2418
+ value.setRenderableOwner(this, this.isRenderable);
2419
+ this.loadTexture();
2420
+ }
2421
+
2422
+ this.setUpdateType(UpdateType.IsRenderable);
2423
+ }
2424
+
2425
+ set textureOptions(value: TextureOptions) {
2426
+ this.props.textureOptions = value;
2427
+ }
2428
+
2429
+ get textureOptions(): TextureOptions {
2430
+ return this.props.textureOptions;
2431
+ }
2432
+
2433
+ set interactive(value: boolean | undefined) {
2434
+ this.props.interactive = value;
2435
+ // Update Stage's interactive Set
2436
+ if (value === true) {
2437
+ this.stage.interactiveNodes.add(this);
2438
+ }
2439
+ }
2440
+
2441
+ get interactive(): boolean | undefined {
2442
+ return this.props.interactive;
2443
+ }
2444
+
2445
+ setRTTUpdates(type: number) {
2446
+ this.hasRTTupdates = true;
2447
+ this.parent?.setRTTUpdates(type);
2448
+ }
2449
+
2450
+ get strictBounds(): boolean {
2451
+ return this.props.strictBounds;
2452
+ }
2453
+
2454
+ set strictBounds(v) {
2455
+ if (v === this.props.strictBounds) {
2456
+ return;
2457
+ }
2458
+
2459
+ this.props.strictBounds = v;
2460
+ this.setUpdateType(UpdateType.RenderBounds | UpdateType.Children);
2461
+ this.childUpdateType |= UpdateType.RenderBounds | UpdateType.Children;
2462
+ }
2463
+
2464
+ animate(
2465
+ props: Partial<CoreNodeAnimateProps>,
2466
+ settings: Partial<AnimationSettings>,
2467
+ ): IAnimationController {
2468
+ const animation = new CoreAnimation(this, props, settings);
2469
+
2470
+ const controller = new CoreAnimationController(
2471
+ this.stage.animationManager,
2472
+ animation,
2473
+ );
2474
+
2475
+ return controller;
2476
+ }
2477
+
2478
+ flush() {
2479
+ // no-op
2480
+ }
2481
+
2482
+ //#endregion Properties
2483
+ }