@bloopjs/toodle 0.0.100

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 (358) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/Toodle.d.ts +304 -0
  4. package/dist/Toodle.d.ts.map +1 -0
  5. package/dist/colors/mod.d.ts +872 -0
  6. package/dist/colors/mod.d.ts.map +1 -0
  7. package/dist/coreTypes/Color.d.ts +7 -0
  8. package/dist/coreTypes/Color.d.ts.map +1 -0
  9. package/dist/coreTypes/Point.d.ts +8 -0
  10. package/dist/coreTypes/Point.d.ts.map +1 -0
  11. package/dist/coreTypes/Size.d.ts +5 -0
  12. package/dist/coreTypes/Size.d.ts.map +1 -0
  13. package/dist/coreTypes/Transform.d.ts +16 -0
  14. package/dist/coreTypes/Transform.d.ts.map +1 -0
  15. package/dist/coreTypes/Vec2.d.ts +8 -0
  16. package/dist/coreTypes/Vec2.d.ts.map +1 -0
  17. package/dist/coreTypes/mod.d.ts +6 -0
  18. package/dist/coreTypes/mod.d.ts.map +1 -0
  19. package/dist/docs/snippets/add-remove-children.d.ts +1 -0
  20. package/dist/docs/snippets/basic-quad.d.ts +1 -0
  21. package/dist/docs/snippets/filter-linear.d.ts +1 -0
  22. package/dist/docs/snippets/filter-nearest.d.ts +1 -0
  23. package/dist/docs/snippets/flipxy.d.ts +1 -0
  24. package/dist/docs/snippets/hello-text.d.ts +1 -0
  25. package/dist/docs/snippets/jumbo-textures.d.ts +1 -0
  26. package/dist/docs/snippets/layer.d.ts +1 -0
  27. package/dist/docs/snippets/layout-edges.d.ts +1 -0
  28. package/dist/docs/snippets/layout-screen-and-world-space.d.ts +1 -0
  29. package/dist/docs/snippets/postprocess.d.ts +1 -0
  30. package/dist/docs/snippets/quad-size-scale.d.ts +1 -0
  31. package/dist/docs/snippets/quickstart.d.ts +1 -0
  32. package/dist/docs/snippets/repeat-texture-loading.d.ts +1 -0
  33. package/dist/docs/snippets/screen-shaders.d.ts +1 -0
  34. package/dist/docs/snippets/shader-color-flash.d.ts +1 -0
  35. package/dist/docs/snippets/shader-default.d.ts +1 -0
  36. package/dist/docs/snippets/shader-fill.d.ts +1 -0
  37. package/dist/docs/snippets/shapes-line.d.ts +1 -0
  38. package/dist/docs/snippets/sprite-region.d.ts +1 -0
  39. package/dist/docs/snippets/text-alignment.d.ts +1 -0
  40. package/dist/docs/snippets/text-shrink-to-fit.d.ts +1 -0
  41. package/dist/docs/snippets/text-word-wrap.d.ts +1 -0
  42. package/dist/docs/snippets/texture-bundles-prebaked.d.ts +1 -0
  43. package/dist/docs/snippets/texture-bundles.d.ts +1 -0
  44. package/dist/docs/snippets/transforms.d.ts +1 -0
  45. package/dist/docs/snippets/transparent-cropping.d.ts +1 -0
  46. package/dist/examples/0-hello.d.ts +1 -0
  47. package/dist/examples/1-hello.d.ts +1 -0
  48. package/dist/examples/1-hello.d.ts.map +1 -0
  49. package/dist/examples/1-quad.d.ts +1 -0
  50. package/dist/examples/10-resize.d.ts +1 -0
  51. package/dist/examples/10-resize.d.ts.map +1 -0
  52. package/dist/examples/11-bundle-test.d.ts +1 -0
  53. package/dist/examples/11-bundle-test.d.ts.map +1 -0
  54. package/dist/examples/12-transparent-pixel-cropping.d.ts +1 -0
  55. package/dist/examples/12-transparent-pixel-cropping.d.ts.map +1 -0
  56. package/dist/examples/13-crop.d.ts +1 -0
  57. package/dist/examples/13-crop.d.ts.map +1 -0
  58. package/dist/examples/14-bundle-bench.d.ts +1 -0
  59. package/dist/examples/14-bundle-bench.d.ts.map +1 -0
  60. package/dist/examples/15-text-layer.d.ts +1 -0
  61. package/dist/examples/15-text-layer.d.ts.map +1 -0
  62. package/dist/examples/16-jumbo-texture.d.ts +1 -0
  63. package/dist/examples/16-jumbo-textures.d.ts +1 -0
  64. package/dist/examples/16-screen-shader.d.ts +1 -0
  65. package/dist/examples/16-screen-shader.d.ts.map +1 -0
  66. package/dist/examples/17-lighting.d.ts +1 -0
  67. package/dist/examples/17-lighting.d.ts.map +1 -0
  68. package/dist/examples/17-translations.d.ts +1 -0
  69. package/dist/examples/18-blur.d.ts +1 -0
  70. package/dist/examples/19-postprocess.d.ts +1 -0
  71. package/dist/examples/19-screenshader.d.ts +1 -0
  72. package/dist/examples/2-shapes.d.ts +1 -0
  73. package/dist/examples/2-shapes.d.ts.map +1 -0
  74. package/dist/examples/3-shader.d.ts +1 -0
  75. package/dist/examples/3-shader.d.ts.map +1 -0
  76. package/dist/examples/4-shader-bench.d.ts +1 -0
  77. package/dist/examples/4-shader-bench.d.ts.map +1 -0
  78. package/dist/examples/5-z.d.ts +1 -0
  79. package/dist/examples/5-z.d.ts.map +1 -0
  80. package/dist/examples/6-atlas.d.ts +1 -0
  81. package/dist/examples/6-atlas.d.ts.map +1 -0
  82. package/dist/examples/7-text.d.ts +1 -0
  83. package/dist/examples/7-text.d.ts.map +1 -0
  84. package/dist/examples/8-text-bench.d.ts +1 -0
  85. package/dist/examples/8-text-bench.d.ts.map +1 -0
  86. package/dist/examples/9-alignment.d.ts +1 -0
  87. package/dist/examples/9-alignment.d.ts.map +1 -0
  88. package/dist/examples/main.d.ts +1 -0
  89. package/dist/examples/main.d.ts.map +1 -0
  90. package/dist/examples/util.d.ts +82 -0
  91. package/dist/examples/util.d.ts.map +1 -0
  92. package/dist/limits.d.ts +23 -0
  93. package/dist/limits.d.ts.map +1 -0
  94. package/dist/math/angle.d.ts +13 -0
  95. package/dist/math/angle.d.ts.map +1 -0
  96. package/dist/math/matrix.d.ts +26 -0
  97. package/dist/math/matrix.d.ts.map +1 -0
  98. package/dist/math/mod.d.ts +3 -0
  99. package/dist/math/mod.d.ts.map +1 -0
  100. package/dist/mod.d.ts +17 -0
  101. package/dist/mod.d.ts.map +1 -0
  102. package/dist/mod.js +19665 -0
  103. package/dist/mod.js.map +41 -0
  104. package/dist/postprocess.d.ts +10 -0
  105. package/dist/postprocess.d.ts.map +1 -0
  106. package/dist/scene/Batcher.d.ts +20 -0
  107. package/dist/scene/Batcher.d.ts.map +1 -0
  108. package/dist/scene/Camera.d.ts +16 -0
  109. package/dist/scene/Camera.d.ts.map +1 -0
  110. package/dist/scene/JumboQuadNode.d.ts +29 -0
  111. package/dist/scene/JumboQuadNode.d.ts.map +1 -0
  112. package/dist/scene/QuadNode.d.ts +159 -0
  113. package/dist/scene/QuadNode.d.ts.map +1 -0
  114. package/dist/scene/RenderComponent.d.ts +11 -0
  115. package/dist/scene/RenderComponent.d.ts.map +1 -0
  116. package/dist/scene/SceneNode.d.ts +300 -0
  117. package/dist/scene/SceneNode.d.ts.map +1 -0
  118. package/dist/scene/mod.d.ts +5 -0
  119. package/dist/scene/mod.d.ts.map +1 -0
  120. package/dist/screen/mod.d.ts +2 -0
  121. package/dist/screen/mod.d.ts.map +1 -0
  122. package/dist/screen/resolution.d.ts +5 -0
  123. package/dist/screen/resolution.d.ts.map +1 -0
  124. package/dist/shaders/EngineUniform.d.ts +9 -0
  125. package/dist/shaders/EngineUniform.d.ts.map +1 -0
  126. package/dist/shaders/IShader.d.ts +15 -0
  127. package/dist/shaders/IShader.d.ts.map +1 -0
  128. package/dist/shaders/QuadShader.d.ts +18 -0
  129. package/dist/shaders/QuadShader.d.ts.map +1 -0
  130. package/dist/shaders/ShaderDescriptor.d.ts +7 -0
  131. package/dist/shaders/ShaderDescriptor.d.ts.map +1 -0
  132. package/dist/shaders/mod.d.ts +6 -0
  133. package/dist/shaders/mod.d.ts.map +1 -0
  134. package/dist/shaders/parser.d.ts +8 -0
  135. package/dist/shaders/parser.d.ts.map +1 -0
  136. package/dist/shaders/postprocess/blur.d.ts +3 -0
  137. package/dist/shaders/postprocess/blur.d.ts.map +1 -0
  138. package/dist/shaders/postprocess/mod.d.ts +17 -0
  139. package/dist/shaders/postprocess/mod.d.ts.map +1 -0
  140. package/dist/shaders/samplers.d.ts +3 -0
  141. package/dist/shaders/samplers.d.ts.map +1 -0
  142. package/dist/shaders/wgsl/example.wgsl.d.ts +3 -0
  143. package/dist/shaders/wgsl/example.wgsl.d.ts.map +1 -0
  144. package/dist/shaders/wgsl/hello.wgsl.d.ts +3 -0
  145. package/dist/shaders/wgsl/hello.wgsl.d.ts.map +1 -0
  146. package/dist/shaders/wgsl/helloInstanced.wgsl.d.ts +3 -0
  147. package/dist/shaders/wgsl/helloInstanced.wgsl.d.ts.map +1 -0
  148. package/dist/shaders/wgsl/quad.wgsl.d.ts +3 -0
  149. package/dist/shaders/wgsl/quad.wgsl.d.ts.map +1 -0
  150. package/dist/src/Toodle.d.ts +303 -0
  151. package/dist/src/Toodle.d.ts.map +1 -0
  152. package/dist/src/colors/mod.d.ts +871 -0
  153. package/dist/src/coreTypes/Color.d.ts +6 -0
  154. package/dist/src/coreTypes/Color.d.ts.map +1 -0
  155. package/dist/src/coreTypes/Point.d.ts +7 -0
  156. package/dist/src/coreTypes/Point.d.ts.map +1 -0
  157. package/dist/src/coreTypes/Size.d.ts +4 -0
  158. package/dist/src/coreTypes/Size.d.ts.map +1 -0
  159. package/dist/src/coreTypes/Transform.d.ts +15 -0
  160. package/dist/src/coreTypes/Transform.d.ts.map +1 -0
  161. package/dist/src/coreTypes/Vec2.d.ts +7 -0
  162. package/dist/src/coreTypes/Vec2.d.ts.map +1 -0
  163. package/dist/src/coreTypes/mod.d.ts +5 -0
  164. package/dist/src/coreTypes/mod.d.ts.map +1 -0
  165. package/dist/src/limits.d.ts +22 -0
  166. package/dist/src/limits.d.ts.map +1 -0
  167. package/dist/src/math/angle.d.ts +12 -0
  168. package/dist/src/math/angle.d.ts.map +1 -0
  169. package/dist/src/math/matrix.d.ts +25 -0
  170. package/dist/src/math/matrix.d.ts.map +1 -0
  171. package/dist/src/math/mod.d.ts +2 -0
  172. package/dist/src/math/mod.d.ts.map +1 -0
  173. package/dist/src/mod.d.ts +16 -0
  174. package/dist/src/mod.d.ts.map +1 -0
  175. package/dist/src/postprocess.d.ts +10 -0
  176. package/dist/src/postprocess.d.ts.map +1 -0
  177. package/dist/src/scene/Batcher.d.ts +19 -0
  178. package/dist/src/scene/Batcher.d.ts.map +1 -0
  179. package/dist/src/scene/Camera.d.ts +15 -0
  180. package/dist/src/scene/Camera.d.ts.map +1 -0
  181. package/dist/src/scene/JumboQuadNode.d.ts +28 -0
  182. package/dist/src/scene/QuadNode.d.ts +158 -0
  183. package/dist/src/scene/QuadNode.d.ts.map +1 -0
  184. package/dist/src/scene/RenderComponent.d.ts +10 -0
  185. package/dist/src/scene/RenderComponent.d.ts.map +1 -0
  186. package/dist/src/scene/SceneNode.d.ts +299 -0
  187. package/dist/src/scene/SceneNode.d.ts.map +1 -0
  188. package/dist/src/scene/mod.d.ts +4 -0
  189. package/dist/src/scene/mod.d.ts.map +1 -0
  190. package/dist/src/screen/mod.d.ts +1 -0
  191. package/dist/src/screen/mod.d.ts.map +1 -0
  192. package/dist/src/screen/resolution.d.ts +4 -0
  193. package/dist/src/screen/resolution.d.ts.map +1 -0
  194. package/dist/src/shaders/EngineUniform.d.ts +8 -0
  195. package/dist/src/shaders/EngineUniform.d.ts.map +1 -0
  196. package/dist/src/shaders/IShader.d.ts +14 -0
  197. package/dist/src/shaders/IShader.d.ts.map +1 -0
  198. package/dist/src/shaders/QuadShader.d.ts +17 -0
  199. package/dist/src/shaders/QuadShader.d.ts.map +1 -0
  200. package/dist/src/shaders/ShaderDescriptor.d.ts +6 -0
  201. package/dist/src/shaders/ShaderDescriptor.d.ts.map +1 -0
  202. package/dist/src/shaders/mod.d.ts +5 -0
  203. package/dist/src/shaders/mod.d.ts.map +1 -0
  204. package/dist/src/shaders/parser.d.ts +7 -0
  205. package/dist/src/shaders/parser.d.ts.map +1 -0
  206. package/dist/src/shaders/postprocess/blur.d.ts +2 -0
  207. package/dist/src/shaders/postprocess/mod.d.ts +16 -0
  208. package/dist/src/shaders/postprocess/postprocess.d.ts +8 -0
  209. package/dist/src/shaders/postprocess/util.d.ts +2 -0
  210. package/dist/src/shaders/samplers.d.ts +2 -0
  211. package/dist/src/shaders/samplers.d.ts.map +1 -0
  212. package/dist/src/shaders/wgsl/example.wgsl.d.ts +2 -0
  213. package/dist/src/shaders/wgsl/example.wgsl.d.ts.map +1 -0
  214. package/dist/src/shaders/wgsl/hello.wgsl.d.ts +2 -0
  215. package/dist/src/shaders/wgsl/hello.wgsl.d.ts.map +1 -0
  216. package/dist/src/shaders/wgsl/helloInstanced.wgsl.d.ts +2 -0
  217. package/dist/src/shaders/wgsl/helloInstanced.wgsl.d.ts.map +1 -0
  218. package/dist/src/shaders/wgsl/quad.wgsl.d.ts +2 -0
  219. package/dist/src/shaders/wgsl/quad.wgsl.d.ts.map +1 -0
  220. package/dist/src/text/FontPipeline.d.ts +13 -0
  221. package/dist/src/text/FontPipeline.d.ts.map +1 -0
  222. package/dist/src/text/MsdfFont.d.ts +81 -0
  223. package/dist/src/text/MsdfFont.d.ts.map +1 -0
  224. package/dist/src/text/TextFormatting.d.ts +18 -0
  225. package/dist/src/text/TextFormatting.d.ts.map +1 -0
  226. package/dist/src/text/TextNode.d.ts +18 -0
  227. package/dist/src/text/TextNode.d.ts.map +1 -0
  228. package/dist/src/text/TextShader.d.ts +14 -0
  229. package/dist/src/text/TextShader.d.ts.map +1 -0
  230. package/dist/src/text/mod.d.ts +3 -0
  231. package/dist/src/text/mod.d.ts.map +1 -0
  232. package/dist/src/text/shaping.d.ts +38 -0
  233. package/dist/src/text/shaping.d.ts.map +1 -0
  234. package/dist/src/text/text.wgsl.d.ts +2 -0
  235. package/dist/src/text/text.wgsl.d.ts.map +1 -0
  236. package/dist/src/textures/AssetManager.d.ts +181 -0
  237. package/dist/src/textures/AssetManager.d.ts.map +1 -0
  238. package/dist/src/textures/NewTextureComputeShader.d.ts +28 -0
  239. package/dist/src/textures/TextureComputeShader.d.ts +20 -0
  240. package/dist/src/textures/TextureComputeShader.d.ts.map +1 -0
  241. package/dist/src/textures/crop.wgsl.d.ts +2 -0
  242. package/dist/src/textures/mod.d.ts +1 -0
  243. package/dist/src/textures/mod.d.ts.map +1 -0
  244. package/dist/src/textures/pixel-scraping.wgsl.d.ts +2 -0
  245. package/dist/src/textures/pixel-scraping.wgsl.d.ts.map +1 -0
  246. package/dist/src/textures/texture-processing.wgsl.d.ts +2 -0
  247. package/dist/src/textures/types.d.ts +176 -0
  248. package/dist/src/textures/types.d.ts.map +1 -0
  249. package/dist/src/textures/util.d.ts +7 -0
  250. package/dist/src/textures/util.d.ts.map +1 -0
  251. package/dist/src/utils/assert.d.ts +1 -0
  252. package/dist/src/utils/assert.d.ts.map +1 -0
  253. package/dist/src/utils/boilerplate.d.ts +10 -0
  254. package/dist/src/utils/boilerplate.d.ts.map +1 -0
  255. package/dist/src/utils/error.d.ts +7 -0
  256. package/dist/src/utils/error.d.ts.map +1 -0
  257. package/dist/src/utils/mod.d.ts +2 -0
  258. package/dist/src/utils/mod.d.ts.map +1 -0
  259. package/dist/src/utils/pool.d.ts +22 -0
  260. package/dist/src/utils/pool.d.ts.map +1 -0
  261. package/dist/test/math/matrix.test.d.ts +1 -0
  262. package/dist/test/scene/Batcher.test.d.ts +1 -0
  263. package/dist/test/scene/SceneNode.test.d.ts +1 -0
  264. package/dist/test/shader/parser.test.d.ts +1 -0
  265. package/dist/text/FontPipeline.d.ts +14 -0
  266. package/dist/text/FontPipeline.d.ts.map +1 -0
  267. package/dist/text/MsdfFont.d.ts +82 -0
  268. package/dist/text/MsdfFont.d.ts.map +1 -0
  269. package/dist/text/TextFormatting.d.ts +19 -0
  270. package/dist/text/TextFormatting.d.ts.map +1 -0
  271. package/dist/text/TextNode.d.ts +19 -0
  272. package/dist/text/TextNode.d.ts.map +1 -0
  273. package/dist/text/TextShader.d.ts +15 -0
  274. package/dist/text/TextShader.d.ts.map +1 -0
  275. package/dist/text/mod.d.ts +4 -0
  276. package/dist/text/mod.d.ts.map +1 -0
  277. package/dist/text/shaping.d.ts +39 -0
  278. package/dist/text/shaping.d.ts.map +1 -0
  279. package/dist/text/text.wgsl.d.ts +3 -0
  280. package/dist/text/text.wgsl.d.ts.map +1 -0
  281. package/dist/textures/AssetManager.d.ts +182 -0
  282. package/dist/textures/AssetManager.d.ts.map +1 -0
  283. package/dist/textures/TextureComputeShader.d.ts +21 -0
  284. package/dist/textures/TextureComputeShader.d.ts.map +1 -0
  285. package/dist/textures/mod.d.ts +2 -0
  286. package/dist/textures/mod.d.ts.map +1 -0
  287. package/dist/textures/pixel-scraping.wgsl.d.ts +3 -0
  288. package/dist/textures/pixel-scraping.wgsl.d.ts.map +1 -0
  289. package/dist/textures/types.d.ts +177 -0
  290. package/dist/textures/types.d.ts.map +1 -0
  291. package/dist/textures/util.d.ts +8 -0
  292. package/dist/textures/util.d.ts.map +1 -0
  293. package/dist/utils/assert.d.ts +2 -0
  294. package/dist/utils/assert.d.ts.map +1 -0
  295. package/dist/utils/boilerplate.d.ts +11 -0
  296. package/dist/utils/boilerplate.d.ts.map +1 -0
  297. package/dist/utils/error.d.ts +8 -0
  298. package/dist/utils/error.d.ts.map +1 -0
  299. package/dist/utils/mod.d.ts +3 -0
  300. package/dist/utils/mod.d.ts.map +1 -0
  301. package/dist/utils/pool.d.ts +23 -0
  302. package/dist/utils/pool.d.ts.map +1 -0
  303. package/package.json +47 -0
  304. package/src/Toodle.ts +853 -0
  305. package/src/colors/mod.ts +151 -0
  306. package/src/coreTypes/Color.ts +1 -0
  307. package/src/coreTypes/Point.ts +7 -0
  308. package/src/coreTypes/Size.ts +4 -0
  309. package/src/coreTypes/Transform.ts +16 -0
  310. package/src/coreTypes/Vec2.ts +7 -0
  311. package/src/coreTypes/mod.ts +5 -0
  312. package/src/globals.d.ts +4 -0
  313. package/src/limits.ts +23 -0
  314. package/src/math/angle.ts +17 -0
  315. package/src/math/matrix.ts +99 -0
  316. package/src/math/mod.ts +2 -0
  317. package/src/mod.ts +22 -0
  318. package/src/scene/Batcher.ts +61 -0
  319. package/src/scene/Camera.ts +69 -0
  320. package/src/scene/JumboQuadNode.ts +219 -0
  321. package/src/scene/QuadNode.ts +403 -0
  322. package/src/scene/RenderComponent.ts +12 -0
  323. package/src/scene/SceneNode.ts +668 -0
  324. package/src/scene/mod.ts +4 -0
  325. package/src/screen/mod.ts +1 -0
  326. package/src/screen/resolution.ts +1 -0
  327. package/src/shaders/EngineUniform.ts +11 -0
  328. package/src/shaders/IShader.ts +20 -0
  329. package/src/shaders/QuadShader.ts +288 -0
  330. package/src/shaders/ShaderDescriptor.ts +6 -0
  331. package/src/shaders/mod.ts +5 -0
  332. package/src/shaders/parser.ts +221 -0
  333. package/src/shaders/postprocess/blur.ts +245 -0
  334. package/src/shaders/postprocess/mod.ts +71 -0
  335. package/src/shaders/samplers.ts +13 -0
  336. package/src/shaders/wgsl/example.wgsl.ts +24 -0
  337. package/src/shaders/wgsl/hello.wgsl.ts +62 -0
  338. package/src/shaders/wgsl/helloInstanced.wgsl.ts +46 -0
  339. package/src/shaders/wgsl/quad.wgsl.ts +140 -0
  340. package/src/text/FontPipeline.ts +212 -0
  341. package/src/text/MsdfFont.ts +190 -0
  342. package/src/text/TextFormatting.ts +28 -0
  343. package/src/text/TextNode.ts +82 -0
  344. package/src/text/TextShader.ts +223 -0
  345. package/src/text/mod.ts +8 -0
  346. package/src/text/shaping.ts +280 -0
  347. package/src/text/text.wgsl.ts +149 -0
  348. package/src/textures/AssetManager.ts +746 -0
  349. package/src/textures/TextureComputeShader.ts +434 -0
  350. package/src/textures/mod.ts +1 -0
  351. package/src/textures/pixel-scraping.wgsl.ts +131 -0
  352. package/src/textures/types.ts +182 -0
  353. package/src/textures/util.ts +352 -0
  354. package/src/utils/assert.ts +5 -0
  355. package/src/utils/boilerplate.ts +110 -0
  356. package/src/utils/error.ts +14 -0
  357. package/src/utils/mod.ts +2 -0
  358. package/src/utils/pool.ts +42 -0
@@ -0,0 +1,219 @@
1
+ import { type Mat3, mat3 } from "wgpu-matrix";
2
+ import type { Size } from "../coreTypes/Size";
3
+ import type { Vec2 } from "../coreTypes/Vec2";
4
+ import type { TextureId } from "../textures/AssetManager";
5
+ import type { AtlasCoords } from "../textures/types";
6
+ import { assert } from "../utils/assert";
7
+ import type { Pool } from "../utils/pool";
8
+ import { QuadNode, type QuadOptions } from "./QuadNode";
9
+ import type { SceneNode } from "./SceneNode";
10
+
11
+ const MAT3_SIZE = 12;
12
+ const VEC4F_SIZE = 4;
13
+
14
+ export type JumboTileDef = Required<JumboTileOptions>;
15
+
16
+ export type JumboTileOptions = {
17
+ /** Texture id of the tile */
18
+ textureId: TextureId;
19
+ /** The offset of this tile in texels from the top left of the full texture */
20
+ offset: Vec2;
21
+ /** The size of the tile in texels. If not provided, the size will be inferred from the texture atlas. */
22
+ size?: Size;
23
+ /** The coordinates of the tile in the texture atlas. If not provided, the size will be read from the loaded texture. */
24
+ atlasCoords?: AtlasCoords;
25
+ };
26
+
27
+ export type JumboQuadOptions = Omit<QuadOptions, "atlasCoords"> & {
28
+ tiles: JumboTileOptions[];
29
+ };
30
+
31
+ export class JumboQuadNode extends QuadNode {
32
+ #tiles: Required<JumboTileOptions>[];
33
+ #matrixPool: Pool<Mat3>;
34
+
35
+ constructor(options: JumboQuadOptions, matrixPool: Pool<Mat3>) {
36
+ assert(
37
+ options.shader,
38
+ "JumboQuadNode requires a shader to be explicitly provided",
39
+ );
40
+
41
+ assert(
42
+ options.tiles && options.tiles.length > 0,
43
+ "JumboQuadNode requires at least one tile to be provided",
44
+ );
45
+
46
+ options.render ??= {
47
+ shader: options.shader,
48
+ writeInstance: writeJumboQuadInstance,
49
+ };
50
+
51
+ super(
52
+ {
53
+ ...options,
54
+ atlasCoords: options.tiles[0].atlasCoords,
55
+ },
56
+ matrixPool,
57
+ );
58
+
59
+ this.#matrixPool = matrixPool;
60
+
61
+ this.#tiles = [];
62
+
63
+ for (const tile of options.tiles) {
64
+ assert(
65
+ tile.atlasCoords,
66
+ "JumboQuadNode requires atlas coords to be provided",
67
+ );
68
+
69
+ assert(tile.size, "JumboQuadNode requires a size to be provided");
70
+
71
+ this.#tiles.push({
72
+ textureId: tile.textureId,
73
+ offset: tile.offset,
74
+ size: tile.size,
75
+ atlasCoords: tile.atlasCoords,
76
+ });
77
+ }
78
+ }
79
+
80
+ get atlasCoords(): AtlasCoords {
81
+ throw new Error("JumboQuadNode does not have a single atlas coords");
82
+ }
83
+
84
+ get tiles(): JumboTileDef[] {
85
+ return this.#tiles;
86
+ }
87
+
88
+ getTileMatrix(tile: JumboTileDef) {
89
+ const matrix = mat3.clone(this.matrix, this.#matrixPool.get());
90
+
91
+ // Find maximum dimensions across all tiles
92
+ const originalSize = {
93
+ width: Math.max(...this.#tiles.map((t) => t.offset.x + t.size.width)),
94
+ height: Math.max(...this.#tiles.map((t) => t.offset.y + t.size.height)),
95
+ };
96
+
97
+ const proportionalSize = {
98
+ width: this.size.width / originalSize.width,
99
+ height: this.size.height / originalSize.height,
100
+ };
101
+
102
+ // Apply translation
103
+ // calculate the offset of the tile's center from the center of the jumbo quad
104
+ // eg if the tile is at (0,0) in texels and is 4000x4000 and the whole texture is 5000x5000 this would give us
105
+ // (2000 - 2500) / 2 = -250, -(2000 - 2500) / 2 = 250
106
+ const centerOffset = {
107
+ x: tile.offset.x + tile.size.width / 2 - originalSize.width / 2,
108
+ y: -(tile.offset.y + tile.size.height / 2 - originalSize.height / 2),
109
+ };
110
+ mat3.translate(
111
+ matrix,
112
+ [
113
+ centerOffset.x * proportionalSize.width,
114
+ centerOffset.y * proportionalSize.height,
115
+ ],
116
+ matrix,
117
+ );
118
+
119
+ // Scale proportionally by size of the jumbo quad
120
+ mat3.scale(
121
+ matrix,
122
+ [
123
+ tile.size.width * proportionalSize.width * (this.flipX ? -1 : 1),
124
+ tile.size.height * proportionalSize.height * (this.flipY ? -1 : 1),
125
+ ],
126
+ matrix,
127
+ );
128
+
129
+ return matrix;
130
+ }
131
+ }
132
+
133
+ function writeJumboQuadInstance(
134
+ node: SceneNode,
135
+ array: Float32Array,
136
+ offset: number,
137
+ ): number {
138
+ if (!(node instanceof JumboQuadNode)) {
139
+ throw new Error(
140
+ "JumboQuadNode.writeJumboQuadInstance can only be called on JumboQuadNodes",
141
+ );
142
+ }
143
+
144
+ // Initialize the local offset for each tile to render...
145
+ let tileOffset = 0;
146
+
147
+ // Iterate through each AtlasCoords found in the coords...
148
+ for (const tile of node.tiles) {
149
+ const coord = tile.atlasCoords;
150
+
151
+ // write model matrix
152
+ const matrix = node.getTileMatrix(tile);
153
+ array.set(matrix, offset + tileOffset);
154
+ tileOffset += MAT3_SIZE;
155
+
156
+ // write tint color
157
+ array.set(
158
+ [node.color.r, node.color.g, node.color.b, node.color.a],
159
+ offset + tileOffset,
160
+ );
161
+ //...increment the local offset by the size of our color vector
162
+ tileOffset += VEC4F_SIZE;
163
+
164
+ // write uv offset and scale
165
+ // location 4 are the uv offset and scale used to sample the texture atlas. these are in normalized texel coordinates.
166
+ // @location(4) uvOffsetAndScale: vec4<f32>,
167
+ array.set(
168
+ [
169
+ coord.uvOffset.x,
170
+ coord.uvOffset.y,
171
+ coord.uvScale.width,
172
+ coord.uvScale.height,
173
+ ],
174
+ offset + tileOffset,
175
+ );
176
+ tileOffset += VEC4F_SIZE;
177
+
178
+ const cropRatio = !coord.uvScaleCropped
179
+ ? { width: 1, height: 1 }
180
+ : {
181
+ width: coord.uvScaleCropped.width / coord.uvScale.width,
182
+ height: coord.uvScaleCropped.height / coord.uvScale.height,
183
+ };
184
+ // write crop offset and scale
185
+ // location 5 is the crop offset from center and scale. These are ratios applied to the unit quad.
186
+ // @location(5) cropOffsetAndScale: vec4<f32>,
187
+ array.set(
188
+ [
189
+ // convert the offset in world space to the offset in the local space of the quad
190
+ // this offset is applied to the unit quad _before_ the model matrix is applied
191
+ // we divide by 2 because we want the center of the remaining region and not the full shift.
192
+ // for example, if we crop the leftmost 90px of a 100px wide texture
193
+ // we want the offset to be 45px and not 90px
194
+ tile.atlasCoords.cropOffset.x /
195
+ 2 /
196
+ (tile.atlasCoords.originalSize.width || 1),
197
+ tile.atlasCoords.cropOffset.y /
198
+ 2 /
199
+ (tile.atlasCoords.originalSize.height || 1),
200
+ cropRatio.width,
201
+ cropRatio.height,
202
+ ],
203
+ offset + tileOffset,
204
+ );
205
+ tileOffset += VEC4F_SIZE;
206
+
207
+ // write atlas index
208
+ new DataView(array.buffer).setUint32(
209
+ array.byteOffset + (offset + tileOffset) * Float32Array.BYTES_PER_ELEMENT,
210
+ coord.atlasIndex,
211
+ true,
212
+ );
213
+ tileOffset += VEC4F_SIZE;
214
+ }
215
+
216
+ // Write our instance and return the number of sprites added to the buffer...
217
+ node.writeInstance?.(array, offset + tileOffset);
218
+ return node.tiles.length;
219
+ }
@@ -0,0 +1,403 @@
1
+ import { type Mat3, mat3 } from "wgpu-matrix";
2
+ import type { Color } from "../coreTypes/Color";
3
+ import type { Size } from "../coreTypes/Size";
4
+ import type { Vec2 } from "../coreTypes/Vec2";
5
+ import type { IShader } from "../shaders/IShader";
6
+ import type { Toodle } from "../Toodle";
7
+ import type { AssetManager, TextureId } from "../textures/AssetManager";
8
+ import type { AtlasCoords, TexelRegion } from "../textures/types";
9
+ import { assert } from "../utils/assert";
10
+ import type { Pool } from "../utils/pool";
11
+ import { type NodeOptions, SceneNode } from "./SceneNode";
12
+
13
+ const PRIMITIVE_TEXTURE = "__primitive__";
14
+ const RESERVED_PRIMITIVE_INDEX_START = 1000;
15
+ // this must match the circle index in the default fragment shader of quad.wgsl.ts
16
+ const CIRCLE_INDEX = 1001;
17
+
18
+ // a default region used for shapes
19
+ const DEFAULT_REGION: TexelRegion = {
20
+ x: 0,
21
+ y: 0,
22
+ width: 0,
23
+ height: 0,
24
+ };
25
+
26
+ /**
27
+ * A node in the scene graph that renders a textured quad.
28
+ *
29
+ * This is a base class and is fairly low level. You will probably want to interact with
30
+ * the wrapper class {@link Toodle.Quad} instead.
31
+ */
32
+ export class QuadNode extends SceneNode {
33
+ assetManager: AssetManager;
34
+
35
+ #color: Color;
36
+ #atlasCoords: AtlasCoords;
37
+ #region: TexelRegion;
38
+ #matrixPool: Pool<Mat3>;
39
+ #flip: Vec2;
40
+ /**
41
+ * The offset of the cropped texture from the original texture
42
+ * If uncropped, this will be 0,0
43
+ */
44
+ #cropOffset: Vec2;
45
+ /**
46
+ * The ratio of the cropped texture width and height to the original texture width and height
47
+ * If uncropped, this will be 1,1
48
+ */
49
+ #cropRatio: Size;
50
+ #atlasSize: Size;
51
+
52
+ #textureId: TextureId;
53
+ #writeInstance?: (array: Float32Array, offset: number) => void;
54
+
55
+ constructor(options: QuadOptions, matrixPool: Pool<Mat3>) {
56
+ assert(
57
+ options.shader,
58
+ "QuadNode requires a shader to be explicitly provided",
59
+ );
60
+ assert(
61
+ options.idealSize,
62
+ "QuadNode requires an ideal size to be explicitly provided",
63
+ );
64
+
65
+ assert(
66
+ options.atlasCoords,
67
+ "QuadNode requires atlas coords to be explicitly provided",
68
+ );
69
+
70
+ options.render ??= {
71
+ shader: options.shader,
72
+ writeInstance: writeQuadInstance,
73
+ };
74
+
75
+ super(options);
76
+
77
+ assert(options.assetManager, "QuadNode requires an asset manager");
78
+ this.assetManager = options.assetManager;
79
+
80
+ if (
81
+ options.atlasCoords &&
82
+ options.atlasCoords.atlasIndex >= RESERVED_PRIMITIVE_INDEX_START
83
+ ) {
84
+ this.#textureId = PRIMITIVE_TEXTURE;
85
+ this.#region = DEFAULT_REGION;
86
+ this.#atlasSize = DEFAULT_REGION;
87
+ } else {
88
+ assert(
89
+ options.textureId,
90
+ "QuadNode requires texture id to be explicitly provided",
91
+ );
92
+ this.#textureId = options.textureId;
93
+
94
+ assert(
95
+ options.region,
96
+ "QuadNode requires a region to be explicitly provided",
97
+ );
98
+ this.#region = options.region;
99
+
100
+ assert(
101
+ options.atlasSize,
102
+ "QuadNode requires atlas size to be explicitly provided",
103
+ );
104
+ this.#atlasSize = options.atlasSize;
105
+ }
106
+
107
+ this.#atlasCoords = options.atlasCoords;
108
+ this.#color = options.color ?? { r: 1, g: 1, b: 1, a: 1 };
109
+ this.#matrixPool = matrixPool;
110
+ this.#flip = { x: options.flipX ? -1 : 1, y: options.flipY ? -1 : 1 };
111
+ this.#cropOffset = options.cropOffset ?? { x: 0, y: 0 };
112
+ this.#cropRatio = !this.#atlasCoords.uvScaleCropped
113
+ ? { width: 1, height: 1 }
114
+ : {
115
+ width:
116
+ this.#atlasCoords.uvScaleCropped.width /
117
+ this.#atlasCoords.uvScale.width,
118
+ height:
119
+ this.#atlasCoords.uvScaleCropped.height /
120
+ this.#atlasCoords.uvScale.height,
121
+ };
122
+ this.#writeInstance = options.writeInstance;
123
+ }
124
+
125
+ /**
126
+ * The tint color of the quad.
127
+ * When drawing shapes, this will be the fill color.
128
+ * When drawing textures, this will be the color multiplier by default.
129
+ * You can also use this value in fragment shaders by referencing `vertex.engine_tint`
130
+ */
131
+ get color() {
132
+ return this.#color;
133
+ }
134
+
135
+ set color(value: Color) {
136
+ this.#color = value;
137
+ }
138
+
139
+ /**
140
+ * The size of the quad. See https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/quad-size-scale.html
141
+ */
142
+ get size() {
143
+ const size = super.size;
144
+ if (!size) {
145
+ throw new Error("QuadNode requires a size");
146
+ }
147
+ return size;
148
+ }
149
+
150
+ /**
151
+ * This is the final model matrix used to render the quad, which
152
+ * may differ from the matrix passed down to the node's children.
153
+ * Properties like `flipX` and `flipY` or `size` are applied here but not inherited by children.
154
+ */
155
+ get matrixWithSize() {
156
+ const matrix = mat3.clone(this.matrix, this.#matrixPool.get());
157
+ mat3.scale(
158
+ matrix,
159
+ [this.size.width * this.#flip.x, this.size.height * this.#flip.y],
160
+ matrix,
161
+ );
162
+
163
+ return matrix;
164
+ }
165
+
166
+ /**
167
+ * The atlas coordinates for the quad. These determine the region in the texture atlas
168
+ * that is sampled for rendering in normalized uv space.
169
+ */
170
+ get atlasCoords() {
171
+ return this.#atlasCoords;
172
+ }
173
+
174
+ /**
175
+ * A subregion of the texture to render.
176
+ * This is useful for rendering a single sprite from a spritesheet for instance.
177
+ * It defaults to the full texture.
178
+ */
179
+ get region() {
180
+ return this.#region;
181
+ }
182
+
183
+ get writeInstance() {
184
+ return this.#writeInstance;
185
+ }
186
+
187
+ /**
188
+ * Whether the image is mirrored horizontally.
189
+ *
190
+ * `true` means the image is mirrored (equivalent to a scale.x of -1),
191
+ * `false` means it is not mirrored.
192
+ */
193
+ get flipX(): boolean {
194
+ return this.#flip.x === -1;
195
+ }
196
+
197
+ /**
198
+ * Sets whether the image is mirrored horizontally.
199
+ *
200
+ * `true` mirrors the image (equivalent to a scale.x of -1),
201
+ * `false` restores normal orientation.
202
+ */
203
+ set flipX(value: boolean) {
204
+ this.#flip.x = value ? -1 : 1;
205
+ this.setDirty();
206
+ }
207
+
208
+ /**
209
+ * Whether the image is mirrored vertically.
210
+ *
211
+ * `true` means the image is mirrored (equivalent to a scale.y of -1),
212
+ * `false` means it is not mirrored.
213
+ */
214
+ get flipY(): boolean {
215
+ return this.#flip.y === -1;
216
+ }
217
+
218
+ /**
219
+ * Sets whether the image is mirrored vertically.
220
+ *
221
+ * `true` mirrors the image (equivalent to a scale.y of -1),
222
+ * `false` restores normal orientation.
223
+ */
224
+ set flipY(value: boolean) {
225
+ this.#flip.y = value ? -1 : 1;
226
+ this.setDirty();
227
+ }
228
+
229
+ /**
230
+ * The drawing offset of the texture.
231
+ * This can be used to offset the texture from the origin of the quad.
232
+ */
233
+ get cropOffset(): Vec2 {
234
+ return this.#cropOffset;
235
+ }
236
+
237
+ /**
238
+ * The drawing offset of the texture.
239
+ * This can be used to offset the texture from the origin of the quad.
240
+ */
241
+ set cropOffset(value: Vec2) {
242
+ this.#cropOffset = value;
243
+ }
244
+
245
+ get textureId() {
246
+ return this.#textureId;
247
+ }
248
+
249
+ /**
250
+ * Whether this quad is rendering a primitive shape like a line or a circle/rect.
251
+ */
252
+ get isPrimitive() {
253
+ return this.#textureId === PRIMITIVE_TEXTURE;
254
+ }
255
+
256
+ /**
257
+ * Whether this quad is rendering a circle.
258
+ */
259
+ get isCircle() {
260
+ return this.#atlasCoords.atlasIndex === CIRCLE_INDEX;
261
+ }
262
+
263
+ extra = {
264
+ /**
265
+ * Sets the atlas coords for the quad. This is for advanced use cases and by default these are
266
+ * set automatically to reference the right texture atlas region.
267
+ * @param value - The new atlas coords.
268
+ */
269
+ setAtlasCoords: (value: AtlasCoords) => {
270
+ this.#atlasCoords = value;
271
+ },
272
+
273
+ /**
274
+ * Returns the crop ratio for the quad. This is the relative difference in size
275
+ * between the cropped and uncropped texture, and will be 1 if the quad has no transparent pixels
276
+ * or if it is loaded without cropping..
277
+ */
278
+ cropRatio: () => {
279
+ return this.#cropRatio;
280
+ },
281
+
282
+ /**
283
+ * Returns the size of the texture atlas in texels, by default this is 4096x4096
284
+ */
285
+ atlasSize: () => {
286
+ return this.#atlasSize;
287
+ },
288
+ };
289
+ }
290
+
291
+ export type QuadOptions = NodeOptions & {
292
+ textureId?: TextureId;
293
+ /**
294
+ * A subregion of the texture to render.
295
+ * This is useful for rendering a single sprite from a spritesheet for instance.
296
+ * It defaults to the full texture.
297
+ */
298
+ region?: TexelRegion;
299
+ /**
300
+ * Atlas coordinates are almost always set by toodle and the asset manager.
301
+ * For advanced use cases, you can set these yourself to control what uvs are sampled
302
+ * from the texture atlas.
303
+ */
304
+ atlasCoords?: AtlasCoords;
305
+
306
+ assetManager?: AssetManager;
307
+
308
+ shader?: IShader;
309
+ writeInstance?: (array: Float32Array, offset: number) => void;
310
+ color?: Color;
311
+ /**
312
+ * flipX mirrors the image horizontally (equivalent to a scale.x multiplication
313
+ * by -1) but allows for independent scaling
314
+ */
315
+ flipX?: boolean;
316
+ /**
317
+ * flipY mirrors the image vertically (equivalent to a scale.y multiplication
318
+ * by -1) but allows for independent scaling
319
+ */
320
+ flipY?: boolean;
321
+ /**
322
+ * The offset of the cropped texture from the original texture
323
+ * If uncropped, this will be 0,0
324
+ */
325
+ cropOffset?: Vec2;
326
+
327
+ /**
328
+ * The size of the texture atlas in texels. This is almost always set by toodle.
329
+ */
330
+ atlasSize?: Size;
331
+
332
+ /**
333
+ * The matrix pool to use for the quad.
334
+ * This is used to avoid creating new matrices for each quad.
335
+ */
336
+ matrixPool?: Pool<Mat3>;
337
+ };
338
+
339
+ function writeQuadInstance(
340
+ node: SceneNode,
341
+ array: Float32Array,
342
+ offset: number,
343
+ ) {
344
+ if (!(node instanceof QuadNode)) {
345
+ throw new Error("QuadNode.writeInstance can only be called on QuadNodes");
346
+ }
347
+
348
+ array.set(node.matrixWithSize, offset);
349
+
350
+ array.set(
351
+ [node.color.r, node.color.g, node.color.b, node.color.a],
352
+ offset + 12,
353
+ );
354
+
355
+ const region = node.region;
356
+ if (node.textureId === PRIMITIVE_TEXTURE) {
357
+ array.set(
358
+ [
359
+ node.atlasCoords.uvOffset.x,
360
+ node.atlasCoords.uvOffset.y,
361
+ node.atlasCoords.uvScale.width,
362
+ node.atlasCoords.uvScale.height,
363
+ ],
364
+ offset + 16,
365
+ );
366
+ } else {
367
+ const atlasSize = node.extra.atlasSize();
368
+ array.set(
369
+ [
370
+ node.atlasCoords.uvOffset.x + region.x / atlasSize.width,
371
+ node.atlasCoords.uvOffset.y + region.y / atlasSize.height,
372
+ region.width / atlasSize.width,
373
+ region.height / atlasSize.height,
374
+ ],
375
+ offset + 16,
376
+ );
377
+ }
378
+
379
+ array.set(
380
+ [
381
+ // convert the offset in world space to the offset in the local space of the quad
382
+ // this offset is applied to the unit quad _before_ the model matrix is applied
383
+ // we divide by 2 because we want the center of the remaining region and not the full shift.
384
+ // for example, if we crop the leftmost 90px of a 100px wide texture
385
+ // we want the offset to be 45px and not 90px
386
+ node.cropOffset.x / 2 / (node.atlasCoords.originalSize.width || 1),
387
+ node.cropOffset.y / 2 / (node.atlasCoords.originalSize.height || 1),
388
+ node.extra.cropRatio().width,
389
+ node.extra.cropRatio().height,
390
+ ],
391
+ offset + 20,
392
+ );
393
+
394
+ new DataView(array.buffer).setUint32(
395
+ array.byteOffset + (offset + 24) * Float32Array.BYTES_PER_ELEMENT,
396
+ node.atlasCoords.atlasIndex,
397
+ true,
398
+ );
399
+
400
+ node.writeInstance?.(array, offset + 28);
401
+
402
+ return 1;
403
+ }
@@ -0,0 +1,12 @@
1
+ import type { IShader } from "../shaders/IShader";
2
+ import type { SceneNode } from "./SceneNode";
3
+
4
+ export type RenderComponent = {
5
+ shader: IShader;
6
+ data?: Float32Array;
7
+
8
+ /**
9
+ * Write cpu instance data to the buffer. Returns number of instances written
10
+ */
11
+ writeInstance: (node: SceneNode, dst: Float32Array, offset: number) => number;
12
+ };