@bloopjs/toodle 0.0.100 → 0.0.101

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 (192) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -4
  3. package/dist/docs/snippets/add-remove-children.d.ts +0 -1
  4. package/dist/docs/snippets/basic-quad.d.ts +0 -1
  5. package/dist/docs/snippets/filter-linear.d.ts +0 -1
  6. package/dist/docs/snippets/filter-nearest.d.ts +0 -1
  7. package/dist/docs/snippets/flipxy.d.ts +0 -1
  8. package/dist/docs/snippets/hello-text.d.ts +0 -1
  9. package/dist/docs/snippets/jumbo-textures.d.ts +0 -1
  10. package/dist/docs/snippets/layer.d.ts +0 -1
  11. package/dist/docs/snippets/layout-edges.d.ts +0 -1
  12. package/dist/docs/snippets/layout-screen-and-world-space.d.ts +0 -1
  13. package/dist/docs/snippets/postprocess.d.ts +0 -1
  14. package/dist/docs/snippets/quad-size-scale.d.ts +0 -1
  15. package/dist/docs/snippets/quickstart.d.ts +0 -1
  16. package/dist/docs/snippets/repeat-texture-loading.d.ts +0 -1
  17. package/dist/docs/snippets/screen-shaders.d.ts +0 -1
  18. package/dist/docs/snippets/shader-color-flash.d.ts +0 -1
  19. package/dist/docs/snippets/shader-default.d.ts +0 -1
  20. package/dist/docs/snippets/shader-fill.d.ts +0 -1
  21. package/dist/docs/snippets/shapes-line.d.ts +0 -1
  22. package/dist/docs/snippets/sprite-region.d.ts +0 -1
  23. package/dist/docs/snippets/text-alignment.d.ts +0 -1
  24. package/dist/docs/snippets/text-shrink-to-fit.d.ts +0 -1
  25. package/dist/docs/snippets/text-word-wrap.d.ts +0 -1
  26. package/dist/docs/snippets/texture-bundles-prebaked.d.ts +0 -1
  27. package/dist/docs/snippets/texture-bundles.d.ts +0 -1
  28. package/dist/docs/snippets/transforms.d.ts +0 -1
  29. package/dist/docs/snippets/transparent-cropping.d.ts +0 -1
  30. package/dist/examples/0-hello.d.ts +0 -1
  31. package/dist/examples/1-hello.d.ts +0 -1
  32. package/dist/examples/1-hello.d.ts.map +0 -1
  33. package/dist/examples/1-quad.d.ts +0 -1
  34. package/dist/examples/10-resize.d.ts +0 -1
  35. package/dist/examples/10-resize.d.ts.map +0 -1
  36. package/dist/examples/11-bundle-test.d.ts +0 -1
  37. package/dist/examples/11-bundle-test.d.ts.map +0 -1
  38. package/dist/examples/12-transparent-pixel-cropping.d.ts +0 -1
  39. package/dist/examples/12-transparent-pixel-cropping.d.ts.map +0 -1
  40. package/dist/examples/13-crop.d.ts +0 -1
  41. package/dist/examples/13-crop.d.ts.map +0 -1
  42. package/dist/examples/14-bundle-bench.d.ts +0 -1
  43. package/dist/examples/14-bundle-bench.d.ts.map +0 -1
  44. package/dist/examples/15-text-layer.d.ts +0 -1
  45. package/dist/examples/15-text-layer.d.ts.map +0 -1
  46. package/dist/examples/16-jumbo-texture.d.ts +0 -1
  47. package/dist/examples/16-jumbo-textures.d.ts +0 -1
  48. package/dist/examples/16-screen-shader.d.ts +0 -1
  49. package/dist/examples/16-screen-shader.d.ts.map +0 -1
  50. package/dist/examples/17-lighting.d.ts +0 -1
  51. package/dist/examples/17-lighting.d.ts.map +0 -1
  52. package/dist/examples/17-translations.d.ts +0 -1
  53. package/dist/examples/18-blur.d.ts +0 -1
  54. package/dist/examples/19-postprocess.d.ts +0 -1
  55. package/dist/examples/19-screenshader.d.ts +0 -1
  56. package/dist/examples/2-shapes.d.ts +0 -1
  57. package/dist/examples/2-shapes.d.ts.map +0 -1
  58. package/dist/examples/3-shader.d.ts +0 -1
  59. package/dist/examples/3-shader.d.ts.map +0 -1
  60. package/dist/examples/4-shader-bench.d.ts +0 -1
  61. package/dist/examples/4-shader-bench.d.ts.map +0 -1
  62. package/dist/examples/5-z.d.ts +0 -1
  63. package/dist/examples/5-z.d.ts.map +0 -1
  64. package/dist/examples/6-atlas.d.ts +0 -1
  65. package/dist/examples/6-atlas.d.ts.map +0 -1
  66. package/dist/examples/7-text.d.ts +0 -1
  67. package/dist/examples/7-text.d.ts.map +0 -1
  68. package/dist/examples/8-text-bench.d.ts +0 -1
  69. package/dist/examples/8-text-bench.d.ts.map +0 -1
  70. package/dist/examples/9-alignment.d.ts +0 -1
  71. package/dist/examples/9-alignment.d.ts.map +0 -1
  72. package/dist/examples/main.d.ts +0 -1
  73. package/dist/examples/main.d.ts.map +0 -1
  74. package/dist/examples/util.d.ts +0 -82
  75. package/dist/examples/util.d.ts.map +0 -1
  76. package/dist/postprocess.d.ts +0 -10
  77. package/dist/postprocess.d.ts.map +0 -1
  78. package/dist/src/Toodle.d.ts +0 -303
  79. package/dist/src/Toodle.d.ts.map +0 -1
  80. package/dist/src/colors/mod.d.ts +0 -871
  81. package/dist/src/coreTypes/Color.d.ts +0 -6
  82. package/dist/src/coreTypes/Color.d.ts.map +0 -1
  83. package/dist/src/coreTypes/Point.d.ts +0 -7
  84. package/dist/src/coreTypes/Point.d.ts.map +0 -1
  85. package/dist/src/coreTypes/Size.d.ts +0 -4
  86. package/dist/src/coreTypes/Size.d.ts.map +0 -1
  87. package/dist/src/coreTypes/Transform.d.ts +0 -15
  88. package/dist/src/coreTypes/Transform.d.ts.map +0 -1
  89. package/dist/src/coreTypes/Vec2.d.ts +0 -7
  90. package/dist/src/coreTypes/Vec2.d.ts.map +0 -1
  91. package/dist/src/coreTypes/mod.d.ts +0 -5
  92. package/dist/src/coreTypes/mod.d.ts.map +0 -1
  93. package/dist/src/limits.d.ts +0 -22
  94. package/dist/src/limits.d.ts.map +0 -1
  95. package/dist/src/math/angle.d.ts +0 -12
  96. package/dist/src/math/angle.d.ts.map +0 -1
  97. package/dist/src/math/matrix.d.ts +0 -25
  98. package/dist/src/math/matrix.d.ts.map +0 -1
  99. package/dist/src/math/mod.d.ts +0 -2
  100. package/dist/src/math/mod.d.ts.map +0 -1
  101. package/dist/src/mod.d.ts +0 -16
  102. package/dist/src/mod.d.ts.map +0 -1
  103. package/dist/src/postprocess.d.ts +0 -10
  104. package/dist/src/postprocess.d.ts.map +0 -1
  105. package/dist/src/scene/Batcher.d.ts +0 -19
  106. package/dist/src/scene/Batcher.d.ts.map +0 -1
  107. package/dist/src/scene/Camera.d.ts +0 -15
  108. package/dist/src/scene/Camera.d.ts.map +0 -1
  109. package/dist/src/scene/JumboQuadNode.d.ts +0 -28
  110. package/dist/src/scene/QuadNode.d.ts +0 -158
  111. package/dist/src/scene/QuadNode.d.ts.map +0 -1
  112. package/dist/src/scene/RenderComponent.d.ts +0 -10
  113. package/dist/src/scene/RenderComponent.d.ts.map +0 -1
  114. package/dist/src/scene/SceneNode.d.ts +0 -299
  115. package/dist/src/scene/SceneNode.d.ts.map +0 -1
  116. package/dist/src/scene/mod.d.ts +0 -4
  117. package/dist/src/scene/mod.d.ts.map +0 -1
  118. package/dist/src/screen/mod.d.ts +0 -1
  119. package/dist/src/screen/mod.d.ts.map +0 -1
  120. package/dist/src/screen/resolution.d.ts +0 -4
  121. package/dist/src/screen/resolution.d.ts.map +0 -1
  122. package/dist/src/shaders/EngineUniform.d.ts +0 -8
  123. package/dist/src/shaders/EngineUniform.d.ts.map +0 -1
  124. package/dist/src/shaders/IShader.d.ts +0 -14
  125. package/dist/src/shaders/IShader.d.ts.map +0 -1
  126. package/dist/src/shaders/QuadShader.d.ts +0 -17
  127. package/dist/src/shaders/QuadShader.d.ts.map +0 -1
  128. package/dist/src/shaders/ShaderDescriptor.d.ts +0 -6
  129. package/dist/src/shaders/ShaderDescriptor.d.ts.map +0 -1
  130. package/dist/src/shaders/mod.d.ts +0 -5
  131. package/dist/src/shaders/mod.d.ts.map +0 -1
  132. package/dist/src/shaders/parser.d.ts +0 -7
  133. package/dist/src/shaders/parser.d.ts.map +0 -1
  134. package/dist/src/shaders/postprocess/blur.d.ts +0 -2
  135. package/dist/src/shaders/postprocess/mod.d.ts +0 -16
  136. package/dist/src/shaders/postprocess/postprocess.d.ts +0 -8
  137. package/dist/src/shaders/postprocess/util.d.ts +0 -2
  138. package/dist/src/shaders/samplers.d.ts +0 -2
  139. package/dist/src/shaders/samplers.d.ts.map +0 -1
  140. package/dist/src/shaders/wgsl/example.wgsl.d.ts +0 -2
  141. package/dist/src/shaders/wgsl/example.wgsl.d.ts.map +0 -1
  142. package/dist/src/shaders/wgsl/hello.wgsl.d.ts +0 -2
  143. package/dist/src/shaders/wgsl/hello.wgsl.d.ts.map +0 -1
  144. package/dist/src/shaders/wgsl/helloInstanced.wgsl.d.ts +0 -2
  145. package/dist/src/shaders/wgsl/helloInstanced.wgsl.d.ts.map +0 -1
  146. package/dist/src/shaders/wgsl/quad.wgsl.d.ts +0 -2
  147. package/dist/src/shaders/wgsl/quad.wgsl.d.ts.map +0 -1
  148. package/dist/src/text/FontPipeline.d.ts +0 -13
  149. package/dist/src/text/FontPipeline.d.ts.map +0 -1
  150. package/dist/src/text/MsdfFont.d.ts +0 -81
  151. package/dist/src/text/MsdfFont.d.ts.map +0 -1
  152. package/dist/src/text/TextFormatting.d.ts +0 -18
  153. package/dist/src/text/TextFormatting.d.ts.map +0 -1
  154. package/dist/src/text/TextNode.d.ts +0 -18
  155. package/dist/src/text/TextNode.d.ts.map +0 -1
  156. package/dist/src/text/TextShader.d.ts +0 -14
  157. package/dist/src/text/TextShader.d.ts.map +0 -1
  158. package/dist/src/text/mod.d.ts +0 -3
  159. package/dist/src/text/mod.d.ts.map +0 -1
  160. package/dist/src/text/shaping.d.ts +0 -38
  161. package/dist/src/text/shaping.d.ts.map +0 -1
  162. package/dist/src/text/text.wgsl.d.ts +0 -2
  163. package/dist/src/text/text.wgsl.d.ts.map +0 -1
  164. package/dist/src/textures/AssetManager.d.ts +0 -181
  165. package/dist/src/textures/AssetManager.d.ts.map +0 -1
  166. package/dist/src/textures/NewTextureComputeShader.d.ts +0 -28
  167. package/dist/src/textures/TextureComputeShader.d.ts +0 -20
  168. package/dist/src/textures/TextureComputeShader.d.ts.map +0 -1
  169. package/dist/src/textures/crop.wgsl.d.ts +0 -2
  170. package/dist/src/textures/mod.d.ts +0 -1
  171. package/dist/src/textures/mod.d.ts.map +0 -1
  172. package/dist/src/textures/pixel-scraping.wgsl.d.ts +0 -2
  173. package/dist/src/textures/pixel-scraping.wgsl.d.ts.map +0 -1
  174. package/dist/src/textures/texture-processing.wgsl.d.ts +0 -2
  175. package/dist/src/textures/types.d.ts +0 -176
  176. package/dist/src/textures/types.d.ts.map +0 -1
  177. package/dist/src/textures/util.d.ts +0 -7
  178. package/dist/src/textures/util.d.ts.map +0 -1
  179. package/dist/src/utils/assert.d.ts +0 -1
  180. package/dist/src/utils/assert.d.ts.map +0 -1
  181. package/dist/src/utils/boilerplate.d.ts +0 -10
  182. package/dist/src/utils/boilerplate.d.ts.map +0 -1
  183. package/dist/src/utils/error.d.ts +0 -7
  184. package/dist/src/utils/error.d.ts.map +0 -1
  185. package/dist/src/utils/mod.d.ts +0 -2
  186. package/dist/src/utils/mod.d.ts.map +0 -1
  187. package/dist/src/utils/pool.d.ts +0 -22
  188. package/dist/src/utils/pool.d.ts.map +0 -1
  189. package/dist/test/math/matrix.test.d.ts +0 -1
  190. package/dist/test/scene/Batcher.test.d.ts +0 -1
  191. package/dist/test/scene/SceneNode.test.d.ts +0 -1
  192. package/dist/test/shader/parser.test.d.ts +0 -1
@@ -1,18 +0,0 @@
1
- import type { Color } from "../coreTypes/Color";
2
- import { type NodeOptions, SceneNode } from "../scene/SceneNode";
3
- import type { MsdfFont } from "./MsdfFont";
4
- import type { TextFormatting } from "./TextFormatting";
5
- import type { TextShader } from "./TextShader";
6
- export declare const DEFAULT_FONT_SIZE = 14;
7
- export declare class TextNode extends SceneNode {
8
- #private;
9
- constructor(shader: TextShader, text: string, opts?: TextOptions);
10
- get text(): string;
11
- get formatting(): TextFormatting;
12
- get font(): MsdfFont;
13
- set text(text: string);
14
- get tint(): Color;
15
- set tint(tint: Color);
16
- set formatting(formatting: TextFormatting);
17
- }
18
- export type TextOptions = Omit<NodeOptions, "render"> & TextFormatting;
@@ -1 +0,0 @@
1
- {"version":3,"file":"TextNode.d.ts","sourceRoot":"","sources":["../../../src/text/TextNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,qBAAa,QAAS,SAAQ,SAAS;;gBAKzB,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB;IAgCpE,IAAI,IAAI,IAYO,MAAM,CAVpB;IAED,IAAI,UAAU,IAyBa,cAAc,CAvBxC;IAED,IAAI,IAAI,aAEP;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAMpB;IAED,IAAI,IAAI,IAIO,KAAK,CAFnB;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAGnB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,cAAc,EAGxC;CACF;AAED,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,cAAc,CAAC"}
@@ -1,14 +0,0 @@
1
- import type { SceneNode } from "../scene/SceneNode";
2
- import type { EngineUniform } from "../shaders/EngineUniform";
3
- import type { IShader } from "../shaders/IShader";
4
- import type { FontPipeline } from "./FontPipeline";
5
- import type { MsdfFont } from "./MsdfFont";
6
- export declare class TextShader implements IShader {
7
- #private;
8
- constructor(device: GPUDevice, pipeline: FontPipeline, font: MsdfFont, colorFormat: GPUTextureFormat, instanceCount: number);
9
- startFrame(device: GPUDevice, uniform: EngineUniform): void;
10
- processBatch(renderPass: GPURenderPassEncoder, nodes: SceneNode[]): number;
11
- endFrame(): void;
12
- get font(): MsdfFont;
13
- get maxCharCount(): number;
14
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"TextShader.d.ts","sourceRoot":"","sources":["../../../src/text/TextShader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAY3C,qBAAa,UAAW,YAAW,OAAO;;gBAetC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,gBAAgB,EAC7B,aAAa,EAAE,MAAM;IAoEvB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAU3D,YAAY,CAAC,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM;IAiG1E,QAAQ,IAAI,IAAI;IAIhB,IAAI,IAAI,aAEP;IAED,IAAI,YAAY,WAEf;CACF"}
@@ -1,3 +0,0 @@
1
- export type { TextOptions } from "./TextNode";
2
- export { TextNode } from "./TextNode";
3
- export { TextShader } from "./TextShader";
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/text/mod.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -1,38 +0,0 @@
1
- import type { Size } from "../coreTypes/Size";
2
- import { type MsdfChar, type MsdfFont } from "./MsdfFont";
3
- import type { TextFormatting, WordWrapOptions } from "./TextFormatting";
4
- export interface MsdfTextMeasurements {
5
- /** The width of the text block in em units. */
6
- width: number;
7
- /** The height of the text block in em units. */
8
- height: number;
9
- /** The width of each line in em units. */
10
- lineWidths: number[];
11
- /** The number of lines in the text block. */
12
- lineCount: number;
13
- /** The number of characters printed in the text block. */
14
- printedCharCount: number;
15
- /** All words in the text block */
16
- words: Word[];
17
- }
18
- export type Glyph = {
19
- char: MsdfChar;
20
- offset: [number, number];
21
- line: number;
22
- };
23
- export type Word = {
24
- glyphs: Glyph[];
25
- width: number;
26
- startX: number;
27
- startY: number;
28
- };
29
- export declare function shapeText(font: MsdfFont, text: string, blockSize: Size, fontSize: number, formatting: TextFormatting, textArray: Float32Array, initialFloatOffset?: number, debug?: boolean): void;
30
- /**
31
- * Measure the text and return measurements for block + each glyph.
32
- * @param font - The font to use.
33
- * @param text - The text to measure
34
- * @param wordWrap - Maximum word length before word wrapping
35
- * @returns The measurements of the text in em units.
36
- */
37
- export declare function measureText(font: MsdfFont, text: string, wordWrap?: WordWrapOptions): MsdfTextMeasurements;
38
- export declare function findLargestFontSize(font: MsdfFont, text: string, size: Size, formatting: TextFormatting): number | undefined;
@@ -1 +0,0 @@
1
- {"version":3,"file":"shaping.d.ts","sourceRoot":"","sources":["../../../src/text/shaping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAsB,MAAM,YAAY,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AASxE,MAAM,WAAW,oBAAoB;IACnC,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,gBAAgB,EAAE,MAAM,CAAC;IAEzB,kCAAkC;IAClC,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,SAAS,CACvB,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,IAAI,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,YAAY,EACvB,kBAAkB,SAAI,EACtB,KAAK,UAAQ,QAgEd;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,eAAe,GACzB,oBAAoB,CA+GtB;AACD,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,cAAc,GACzB,MAAM,GAAG,SAAS,CAqCpB"}
@@ -1,2 +0,0 @@
1
- declare const _default: "\n// Adapted from: https://webgpu.github.io/webgpu-samples/?sample=textRenderingMsdf\n\n// Quad vertex positions for a character\nconst pos = array(\n vec2f(0, -1),\n vec2f(1, -1),\n vec2f(0, 0),\n vec2f(1, 0),\n);\n\n// Debug colors for visualization\nconst debugColors = array(\n vec4f(1, 0, 0, 1),\n vec4f(0, 1, 0, 1),\n vec4f(0, 0, 1, 1),\n vec4f(1, 1, 1, 1),\n);\n\n// Vertex input from GPU\nstruct VertexInput {\n @builtin(vertex_index) vertex: u32,\n @builtin(instance_index) instance: u32,\n};\n\n// Output from vertex shader to fragment shader\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) texcoord: vec2f,\n @location(1) debugColor: vec4f,\n @location(2) @interpolate(flat) instanceIndex: u32,\n};\n\n// Metadata for a single character glyph\nstruct Char {\n texOffset: vec2f, // Offset to top-left in MSDF texture (pixels)\n texExtent: vec2f, // Size in texture (pixels)\n size: vec2f, // Glyph size in ems\n offset: vec2f, // Position offset in ems\n};\n\n// Metadata for a text block\nstruct TextBlockDescriptor {\n transform: mat3x3f, // Text transform matrix (model matrix)\n color: vec4f, // Text color\n fontSize: f32, // Font size\n blockWidth: f32, // Total width of text block\n blockHeight: f32, // Total height of text block\n bufferPosition: f32 // Index and length in textBuffer\n};\n\n// Font bindings\n@group(0) @binding(0) var fontTexture: texture_2d<f32>;\n@group(0) @binding(1) var fontSampler: sampler;\n@group(0) @binding(2) var<storage> chars: array<Char>;\n@group(0) @binding(3) var<uniform> fontData: vec4f; // Contains line height (x)\n\n// Text bindings\n@group(1) @binding(0) var<storage> texts: array<TextBlockDescriptor>;\n@group(1) @binding(1) var<storage> textBuffer: array<vec4f>; // Each vec4: xy = glyph pos, z = char index\n\n// Global uniforms\n@group(2) @binding(0) var<uniform> viewProjectionMatrix: mat3x3f;\n\n// Vertex shader\n@vertex\nfn vertexMain(input: VertexInput) -> VertexOutput {\n // Because the instance index is used for character indexing, we are\n // overloading the vertex index to store the instance of the text metadata.\n //\n // I.e...\n // Vertex 0-4 = Instance 0, Vertex 0-4\n // Vertex 4-8 = Instance 1, Vertex 0-4\n // Vertex 8-12 = Instance 2, Vertex 0-4\n let vertexIndex = input.vertex % 4;\n let textIndex = input.vertex / 4;\n\n let text = texts[textIndex];\n let textElement = textBuffer[u32(text.bufferPosition) + input.instance];\n let char = chars[u32(textElement.z)];\n\n let lineHeight = fontData.x;\n let textWidth = text.blockWidth;\n let textHeight = text.blockHeight;\n\n // Center text vertically; origin is mid-height\n let offset = vec2f(0, -textHeight / 2);\n\n // Glyph position in ems (quad pos * size + per-char offset)\n let emPos = pos[vertexIndex] * char.size + char.offset + textElement.xy - offset;\n let charPos = emPos * (text.fontSize / lineHeight);\n\n var output: VertexOutput;\n let transformedPosition = viewProjectionMatrix * text.transform * vec3f(charPos, 1);\n\n output.position = vec4f(transformedPosition, 1);\n output.texcoord = pos[vertexIndex] * vec2f(1, -1);\n output.texcoord *= char.texExtent;\n output.texcoord += char.texOffset;\n output.debugColor = debugColors[vertexIndex];\n output.instanceIndex = textIndex;\n return output;\n\n // To debug - hardcode quad in bottom right quarter of the screen:\n // output.position = vec4f(pos[input.vertex], 0, 1);\n}\n\n// Signed distance function sampling for MSDF font rendering\nfn sampleMsdf(texcoord: vec2f) -> f32 {\n let c = textureSample(fontTexture, fontSampler, texcoord);\n return max(min(c.r, c.g), min(max(c.r, c.g), c.b));\n}\n\n// Fragment shader\n// Anti-aliasing technique by Paul Houx\n// more details here:\n// https://github.com/Chlumsky/msdfgen/issues/22#issuecomment-234958005\n@fragment\nfn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n let text = texts[input.instanceIndex];\n\n // pxRange (AKA distanceRange) comes from the msdfgen tool.\n let pxRange = 4.0;\n let texSize = vec2f(textureDimensions(fontTexture, 0));\n\n let dx = texSize.x * length(vec2f(dpdxFine(input.texcoord.x), dpdyFine(input.texcoord.x)));\n let dy = texSize.y * length(vec2f(dpdxFine(input.texcoord.y), dpdyFine(input.texcoord.y)));\n\n let toPixels = pxRange * inverseSqrt(dx * dx + dy * dy);\n let sigDist = sampleMsdf(input.texcoord) - 0.5;\n let pxDist = sigDist * toPixels;\n\n let edgeWidth = 0.5;\n let alpha = smoothstep(-edgeWidth, edgeWidth, pxDist);\n\n if (alpha < 0.001) {\n discard;\n }\n\n let msdfColor = vec4f(text.color.rgb, text.color.a * alpha);\n return msdfColor;\n\n // Debug options:\n // return text.color;\n // return input.debugColor;\n // return vec4f(1, 0, 1, 1); // hardcoded magenta\n // return textureSample(fontTexture, fontSampler, input.texcoord);\n}\n";
2
- export default _default;
@@ -1 +0,0 @@
1
- {"version":3,"file":"text.wgsl.d.ts","sourceRoot":"","sources":["../../../src/text/text.wgsl.ts"],"names":[],"mappings":";AAAA,wBAoJE"}
@@ -1,181 +0,0 @@
1
- import type { Size } from "../coreTypes/Size";
2
- import type { Vec2 } from "../coreTypes/Vec2";
3
- import type { Limits } from "../limits";
4
- import { QuadNode } from "../scene/QuadNode";
5
- import type { SceneNode } from "../scene/SceneNode";
6
- import { TextShader } from "../text/TextShader";
7
- import type { AtlasBundleOpts, AtlasCoords, CpuTextureAtlas, TextureBundleOpts } from "./types";
8
- export type TextureId = string;
9
- export type BundleId = string;
10
- export type FontId = string;
11
- export declare class AssetManager {
12
- #private;
13
- readonly textureAtlas: GPUTexture;
14
- constructor(device: GPUDevice, presentationFormat: GPUTextureFormat, limits: Limits, format?: "rgba8unorm" | "rg8unorm");
15
- /**
16
- * True dimensions of a loaded texture, prior to any transparent pixel cropping.
17
- *
18
- * @param id - The id of the texture to get the size of
19
- * @returns The size of the texture
20
- */
21
- getSize(id: TextureId): Size;
22
- /**
23
- * Dimensions of a loaded texture, cropped to a minimal bounding box.
24
- *
25
- * @param id - The id of the texture to get the size of
26
- * @returns The size of the texture
27
- */
28
- getCroppedSize(id: TextureId): Size;
29
- /**
30
- * Whether the texture has been cropped for extra transparency.
31
- *
32
- * @param id - The id of the texture to be checked
33
- * @returns Whether the image has been cropped (i.e. if it has uvScaledCropped)
34
- */
35
- isCropped(id: TextureId): boolean;
36
- /**
37
- * A read-only map of all currently loaded textures.
38
- */
39
- get textures(): Map<string, AtlasCoords[]>;
40
- /**
41
- * A read-only array of all currently loaded texture ids.
42
- */
43
- get textureIds(): string[];
44
- /**
45
- * Debug method to load a set of textures from a record of URLS.
46
- *
47
- * @param textures Collection of strings and URLs representing the texture name and target file
48
- * @param options LoadingOptions used to modify the loading process
49
- *
50
- * Note: this will consume one texture atlas per texture.
51
- * For more efficient loading of multiple textures, consider {@link loadBundle}
52
- *
53
- * @example
54
- *
55
- * await toodle.assets.loadTextures({
56
- * "myImage": new URL("assets/image.png", "https://mywebsite.com"),
57
- * });
58
- *
59
- * @deprecated use {@link registerBundle} instead. or {@link loadTexture} for debugging
60
- */
61
- loadTextures(opts: TextureBundleOpts["textures"]): Promise<void>;
62
- /**
63
- * Debug method to load a single texture.
64
- *
65
- * @param id ID used to name the texture
66
- * @param url URL or ImageBitmap target for the image
67
- * @param options LoadingOptions used to modify the loading process
68
- *
69
- * Note: this will consume one texture atlas per texture.
70
- * For more efficient loading of multiple textures, consider {@link loadBundle}
71
- */
72
- loadTexture(id: TextureId, url: URL | ImageBitmap, options?: Partial<TextureBundleOpts>): Promise<{
73
- id: string;
74
- coords: AtlasCoords;
75
- }>;
76
- /**
77
- * Register a bundle of textures.
78
- *
79
- * @param bundleId ID used to name the bundle
80
- * @param bundle Collection of strings and URLs representing the texture name and target file
81
- * @param options LoadingOptions used to modify the loading process
82
- *
83
- * See: https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/texture-bundles.html
84
- */
85
- registerBundle(bundleId: BundleId, opts: TextureBundleOpts | AtlasBundleOpts): Promise<BundleId>;
86
- /**
87
- * Load a bundle of textures to the gpu
88
- *
89
- * See: https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/texture-bundles.html
90
- */
91
- loadBundle(bundleId: BundleId): Promise<void>;
92
- /**
93
- * Unload a bundle of textures from the gpu - this marks the gpu-side texture atlas
94
- * as available for future texture loading.
95
- *
96
- * @param bundleId - The id of the bundle to unload
97
- */
98
- unloadBundle(bundleId: BundleId): Promise<void>;
99
- /**
100
- * Load a font to the gpu
101
- *
102
- * @param id - The id of the font to load
103
- * @param url - The url of the font to load
104
- * @param fallbackCharacter - The character to use as a fallback if the font does not contain a character to be rendererd
105
- */
106
- loadFont(id: string, url: URL, fallbackCharacter?: string): Promise<string>;
107
- getFont(id: string): TextShader;
108
- validateTextureReference(node: SceneNode | QuadNode): void;
109
- /**
110
- * Advanced and niche features
111
- */
112
- extra: {
113
- getRegisteredBundleIds: () => string[];
114
- getLoadedBundleIds: () => string[];
115
- /**
116
- * Set the atlas coordinates for a texture.
117
- *
118
- * This should not be necessary for most use cases. This allows for UV precision
119
- *
120
- * @param id - The id of the texture to set the atlas coordinates for
121
- * @param coords - The atlas coordinates to set
122
- */
123
- setAtlasCoords: (id: TextureId, coords: AtlasCoords) => void;
124
- /**
125
- * Get the atlas coordinates for a texture.
126
- *
127
- * @param id - The id of the texture to get the atlas coordinates for
128
- * @returns An array of the atlas coordinates for the texture
129
- */
130
- getAtlasCoords: (id: TextureId) => AtlasCoords[];
131
- /**
132
- * Get the texture default offset
133
- *
134
- * @param id - The id of the texture to get the atlas coordinates for
135
- * @returns Point of the texture's associated X,Y offset
136
- */
137
- getTextureOffset: (id: TextureId) => Vec2;
138
- /**
139
- * Get diagnostics on texture atlas usage
140
- *
141
- * @returns Usage stats for texture atlases
142
- */
143
- getAtlasUsage: () => {
144
- /**
145
- * The number of texture atlases that are currently unused
146
- * and available to load textures into.
147
- */
148
- available: number;
149
- /**
150
- * The number of texture atlases that are currently in use.
151
- */
152
- used: number;
153
- /**
154
- * The total number of texture atlases that can be loaded.
155
- */
156
- total: number;
157
- };
158
- /**
159
- * Consume the next available atlas index.
160
- *
161
- */
162
- nextAvailableAtlasIndex: () => number;
163
- /**
164
- * Load a texture atlas from a CpuTextureAtlas.
165
- *
166
- * @param atlas - The texture atlas to load
167
- * @returns The index of the atlas
168
- */
169
- loadAtlas: (atlas: CpuTextureAtlas) => Promise<number>;
170
- /**
171
- * Unload an atlas from the texture atlas.
172
- *
173
- * @param atlasIndex - The index of the atlas to unload
174
- */
175
- unloadAtlas: (atlasIndex: number) => Promise<void>;
176
- };
177
- /**
178
- * Destroy the texture atlas. This should free up ~4gb of gpu memory (and make all draw calls fail)
179
- */
180
- destroy(): void;
181
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"AssetManager.d.ts","sourceRoot":"","sources":["../../../src/textures/AssetManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,eAAe,EAEf,iBAAiB,EAGlB,MAAM,SAAS,CAAC;AAGjB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAC/B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAQ5B,qBAAa,YAAY;;IACvB,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;gBAYhC,MAAM,EAAE,SAAS,EACjB,kBAAkB,EAAE,gBAAgB,EACpC,MAAM,EAAE,MAAM;IAwBhB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAS5B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAWnC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO;IAUjC;;OAEG;IACH,IAAI,QAAQ,+BAEX;IAED;;OAEG;IACH,IAAI,UAAU,aAEb;IAED;;;;;;;;;;;;;;OAcG;IACG,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtE;;;;;;;;;OASG;IACG,WAAW,CACf,EAAE,EAAE,SAAS,EACb,GAAG,EAAE,GAAG,GAAG,WAAW,EACtB,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;;;;IAwCtC;;;;;;;;OAQG;IACG,cAAc,CAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,iBAAiB,GAAG,eAAe,GACxC,OAAO,CAAC,QAAQ,CAAC;IAapB;;;;OAIG;IACG,UAAU,CAAC,QAAQ,EAAE,QAAQ;IAmBnC;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,QAAQ;IAqBrC;;;;;;OAMG;IACG,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,SAAM;IAqB5D,OAAO,CAAC,EAAE,EAAE,MAAM;IASlB,wBAAwB,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ;IAiLnD;;OAEG;IACH,KAAK;sCAEyB,MAAM,EAAE;kCAKZ,MAAM,EAAE;QAMhC;;;;;;;WAOG;6BACkB,SAAS,UAAU,WAAW;QAWnD;;;;;WAKG;6BACkB,SAAS,KAAG,WAAW,EAAE;QAS9C;;;;;WAKG;+BACoB,SAAS,KAAG,IAAI;QAUvC;;;;WAIG;;YAGC;;;eAGG;;YAEH;;eAEG;;YAEH;;eAEG;;;QAKP;;;WAGG;;QAWH;;;;;WAKG;2BACsB,eAAe;QAsBxC;;;;WAIG;kCAC6B,MAAM;MActC;IAmCF;;OAEG;IACH,OAAO;CAGR"}
@@ -1,28 +0,0 @@
1
- import type { Point } from "../coreTypes/Point";
2
- import type { Size } from "../coreTypes/Size";
3
- import { OneOrMany } from "../utils/one_or_many";
4
- /**
5
- * A GPU-based texture processor that uses compute shaders to:
6
- * 1. Find the non-transparent bounding box in a texture.
7
- * 2. Crop the texture to that bounding box.
8
- * 3. Create a fallback texture if no non-transparent pixels are found.
9
- * 4. Slice a target texture that exceeds normal atlas bounds into subsections for packing.
10
- */
11
- export declare class TextureComputeShader {
12
- #private;
13
- constructor(device: GPUDevice, cropPipeline: GPUComputePipeline, boundPipeline: GPUComputePipeline, missingTexturePipeline: GPUComputePipeline);
14
- /**
15
- * Factory method to initialize pipelines and return an instance of TextureComputeShader.
16
- */
17
- static create(device: GPUDevice): TextureComputeShader;
18
- /**
19
- * Main entry point to tile an extra large texture into atlas ready chunks.
20
- * Returns a TextureWrapper with all the constituent parts.
21
- */
22
- tileImage(texture: GPUTexture, original: ImageWithMetaData, maxTextureSize: number, layer: number, position?: Point): Promise<OneOrMany<ImageWithMetaData>>;
23
- /**
24
- * Main entry point to crop transparency from a texture.
25
- * Returns a cropped ImageBitmap and metadata.
26
- */
27
- cropTransparency(texture: GPUTexture, imageSize: Size, layer: number, origin?: Point): Promise<ImageWithMetaData>;
28
- }
@@ -1,20 +0,0 @@
1
- import type { TextureWithMetadata } from "./types";
2
- /**
3
- * A GPU-based texture processor that uses compute shaders to:
4
- * 1. Find the non-transparent bounding box in a texture.
5
- * 2. Crop the texture to that bounding box.
6
- * 3. Create a fallback texture if no non-transparent pixels are found.
7
- */
8
- export declare class TextureComputeShader {
9
- #private;
10
- constructor(device: GPUDevice, cropPipeline: GPUComputePipeline, boundPipeline: GPUComputePipeline, missingTexturePipeline: GPUComputePipeline);
11
- /**
12
- * Factory method to initialize pipelines and return an instance of TextureComputeShader.
13
- */
14
- static create(device: GPUDevice): TextureComputeShader;
15
- /**
16
- * Main entry point to process a texture.
17
- * Returns a cropped ImageBitmap and metadata.
18
- */
19
- processTexture(textureWrapper: TextureWithMetadata): Promise<TextureWithMetadata>;
20
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"TextureComputeShader.d.ts","sourceRoot":"","sources":["../../../src/textures/TextureComputeShader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAwBnD;;;;;GAKG;AACH,qBAAa,oBAAoB;;gBAQ7B,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,kBAAkB,EAChC,aAAa,EAAE,kBAAkB,EACjC,sBAAsB,EAAE,kBAAkB;IAiB5C;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS;IAU/B;;;OAGG;IACG,cAAc,CAClB,cAAc,EAAE,mBAAmB,GAClC,OAAO,CAAC,mBAAmB,CAAC;CAwQhC"}
@@ -1,2 +0,0 @@
1
- declare const _default: "\n// Input texture from which cropped data is read\n@group(0) @binding(0)\nvar input_texture_crop: texture_2d<f32>;\n\n// Output texture where cropped image is written\n@group(0) @binding(1)\nvar output_texture: texture_storage_2d<rgba8unorm, write>;\n\n// Bounding box passed in as a uniform (not atomic anymore)\nstruct bounding_box_uniform {\n min_x: u32,\n min_y: u32,\n max_x: u32,\n max_y: u32,\n layer: u32,\n};\n\n@group(0) @binding(2)\nvar<uniform> bounds_uniform: bounding_box_uniform;\n\n// Compute shader to crop the input texture to the bounding box and output it\n@compute @workgroup_size(8, 8)\nfn crop_and_output(@builtin(global_invocation_id) gid: vec3<u32>) {\n let size = textureDimensions(input_texture_crop).xy;\n\n let crop_width = bounds_uniform.max_x - bounds_uniform.min_x + 1u;\n let crop_height = bounds_uniform.max_y - bounds_uniform.min_y + 1u;\n\n if (gid.x >= crop_width || gid.y >= crop_height) {\n return;\n }\n\n let src_coord = vec2<i32>(\n i32(bounds_uniform.min_x + gid.x),\n i32(bounds_uniform.min_y + gid.y)\n );\n\n let dst_coord = vec2<i32>(i32(gid.x), i32(gid.y));\n let pixel = textureLoad(input_texture_crop, src_coord, 0);\n textureStore(output_texture, dst_coord, pixel);\n}\n";
2
- export default _default;
@@ -1 +0,0 @@
1
- export type * from "./types";
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/textures/mod.ts"],"names":[],"mappings":"AAAA,mBAAmB,SAAS,CAAC"}
@@ -1,2 +0,0 @@
1
- declare const _default: "\n// ==============================\n// === BOUNDING BOX PASS =======\n// ==============================\n\n// Input texture from which to compute the non-transparent bounding box\n@group(0) @binding(0)\nvar input_texture: texture_2d<f32>;\n\n// Atomic bounding box storage structure\nstruct bounding_box_atomic {\n min_x: atomic<u32>,\n min_y: atomic<u32>,\n max_x: atomic<u32>,\n max_y: atomic<u32>,\n};\n\n// Storage buffer to hold atomic bounding box updates\n@group(0) @binding(1)\nvar<storage, read_write> bounds: bounding_box_atomic;\n\n// Compute shader to find the bounding box of non-transparent pixels\n@compute @workgroup_size(8, 8)\nfn find_bounds(@builtin(global_invocation_id) gid: vec3<u32>) {\n let size = textureDimensions(input_texture).xy;\n if (gid.x >= size.x || gid.y >= size.y) {\n return;\n }\n\n let pixel = textureLoad(input_texture, vec2<i32>(gid.xy), 0);\n if (pixel.a > 0.0) {\n atomicMin(&bounds.min_x, gid.x);\n atomicMin(&bounds.min_y, gid.y);\n atomicMax(&bounds.max_x, gid.x);\n atomicMax(&bounds.max_y, gid.y);\n }\n}\n\n// ==============================\n// === CROP + OUTPUT PASS ======\n// ==============================\n\n// Input texture from which cropped data is read\n@group(0) @binding(0)\nvar input_texture_crop: texture_2d<f32>;\n\n// Output texture where cropped image is written\n@group(0) @binding(1)\nvar output_texture: texture_storage_2d<rgba8unorm, write>;\n\n// Bounding box passed in as a uniform (not atomic anymore)\nstruct bounding_box_uniform {\n min_x: u32,\n min_y: u32,\n max_x: u32,\n max_y: u32,\n};\n\n@group(0) @binding(2)\nvar<uniform> bounds_uniform: bounding_box_uniform;\n\n// Struct to store both original and cropped texture dimensions\nstruct image_dimensions {\n original_width: u32,\n original_height: u32,\n cropped_width: u32,\n cropped_height: u32,\n};\n\n// Storage buffer to output the result dimensions\n@group(0) @binding(3)\nvar<storage, read_write> dimensions_out: image_dimensions;\n\n// Compute shader to crop the input texture to the bounding box and output it\n@compute @workgroup_size(8, 8)\nfn crop_and_output(@builtin(global_invocation_id) gid: vec3<u32>) {\n let size = textureDimensions(input_texture_crop).xy;\n\n let crop_width = bounds_uniform.max_x - bounds_uniform.min_x + 1u;\n let crop_height = bounds_uniform.max_y - bounds_uniform.min_y + 1u;\n\n if (gid.x >= crop_width || gid.y >= crop_height) {\n return;\n }\n\n let src_coord = vec2<i32>(\n i32(bounds_uniform.min_x + gid.x),\n i32(bounds_uniform.min_y + gid.y)\n );\n\n let dst_coord = vec2<i32>(i32(gid.x), i32(gid.y));\n let pixel = textureLoad(input_texture_crop, src_coord, 0);\n textureStore(output_texture, dst_coord, pixel);\n\n // Output dimensions from workgroup (0,0) only\n if (gid.x == 0u && gid.y == 0u) {\n dimensions_out.original_width = size.x;\n dimensions_out.original_height = size.y;\n dimensions_out.cropped_width = crop_width;\n dimensions_out.cropped_height = crop_height;\n }\n}\n\n// ==============================\n// === MISSING TEXTURE FILL ====\n// ==============================\n\n// Output texture to draw a fallback checkerboard\n@group(0) @binding(0)\nvar checker_texture: texture_storage_2d<rgba8unorm, write>;\n\n// Compute shader to fill a texture with a purple & green checkerboard\n@compute @workgroup_size(8, 8)\nfn missing_texture(@builtin(global_invocation_id) id: vec3<u32>) {\n let size = textureDimensions(checker_texture);\n if (id.x >= size.x || id.y >= size.y) {\n return;\n }\n\n let checker_size = 25u;\n let on_color = ((id.x / checker_size + id.y / checker_size) % 2u) == 0u;\n\n let color = select(\n vec4<f32>(0.5, 0.0, 0.5, 1.0), // Purple\n vec4<f32>(0.0, 1.0, 0.0, 1.0), // Green\n on_color\n );\n\n textureStore(checker_texture, vec2<i32>(id.xy), color);\n}\n";
2
- export default _default;
@@ -1 +0,0 @@
1
- {"version":3,"file":"pixel-scraping.wgsl.d.ts","sourceRoot":"","sources":["../../../src/textures/pixel-scraping.wgsl.ts"],"names":[],"mappings":";AAAA,wBAkIE"}
@@ -1,2 +0,0 @@
1
- declare const _default: "\n// ==============================\n// === BOUNDING BOX PASS =======\n// ==============================\n\n// Input texture from which to compute the non-transparent bounding box\n@group(0) @binding(0)\nvar input_texture: texture_2d_array<f32>;\n\n// Atomic bounding box storage structure\nstruct bounding_box_atomic {\n min_x: atomic<u32>,\n min_y: atomic<u32>,\n max_x: atomic<u32>,\n max_y: atomic<u32>,\n layer: u32,\n};\n\n// Storage buffer to hold atomic bounding box updates\n@group(0) @binding(1)\nvar<storage, read_write> bounds: bounding_box_atomic;\n\n// Uniform buffer for the sub area of the texture to check\nstruct check_area{\n origin: vec2<u32>,\n size: vec2<u32>,\n}\n@group(0) @binding(2)\nvar<uniform> to_check_area: check_area;\n\n// Compute shader to find the bounding box of non-transparent pixels\n@compute @workgroup_size(8, 8)\nfn find_bounds(@builtin(global_invocation_id) gid: vec3<u32>) {\n let size = to_check_area.size.xy;\n let origin = to_check_area.origin.xy;\n \n if (gid.x >= size.x || gid.y >= size.y) {\n return;\n }\n\n let pixel = textureLoad(input_texture, vec2<i32>(gid.xy + origin.xy), bounds.layer, 0);\n if (pixel.a > 0.0) {\n atomicMin(&bounds.min_x, gid.x + origin.x);\n atomicMin(&bounds.min_y, gid.y + origin.y);\n atomicMax(&bounds.max_x, gid.x + origin.x);\n atomicMax(&bounds.max_y, gid.y + origin.y);\n }\n}\n\n// ==============================\n// === CROP + OUTPUT PASS ======\n// ==============================\n\n// Input texture from which cropped data is read\n@group(0) @binding(0)\nvar input_texture_crop: texture_2d<f32>;\n\n// Output texture where cropped image is written\n@group(0) @binding(1)\nvar output_texture: texture_storage_2d<rgba8unorm, write>;\n\n// Bounding box passed in as a uniform (not atomic anymore)\nstruct bounding_box_uniform {\n min_x: u32,\n min_y: u32,\n max_x: u32,\n max_y: u32,\n layer: u32,\n};\n\n@group(0) @binding(2)\nvar<uniform> bounds_uniform: bounding_box_uniform;\n\n// Compute shader to crop the input texture to the bounding box and output it\n@compute @workgroup_size(8, 8)\nfn crop_and_output(@builtin(global_invocation_id) gid: vec3<u32>) {\n let size = textureDimensions(input_texture_crop).xy;\n\n let crop_width = bounds_uniform.max_x - bounds_uniform.min_x + 1u;\n let crop_height = bounds_uniform.max_y - bounds_uniform.min_y + 1u;\n\n if (gid.x >= crop_width || gid.y >= crop_height) {\n return;\n }\n\n let src_coord = vec2<i32>(\n i32(bounds_uniform.min_x + gid.x),\n i32(bounds_uniform.min_y + gid.y)\n );\n\n let dst_coord = vec2<i32>(i32(gid.x), i32(gid.y));\n let pixel = textureLoad(input_texture_crop, src_coord, 0);\n textureStore(output_texture, dst_coord, pixel);\n}\n\n// ==============================\n// === MISSING TEXTURE FILL ====\n// ==============================\n\n// Output texture to draw a fallback checkerboard\n@group(0) @binding(0)\nvar checker_texture: texture_storage_2d<rgba8unorm, write>;\n\n// Compute shader to fill a texture with a purple & green checkerboard\n@compute @workgroup_size(8, 8)\nfn missing_texture(@builtin(global_invocation_id) id: vec3<u32>) {\n let size = textureDimensions(checker_texture);\n if (id.x >= size.x || id.y >= size.y) {\n return;\n }\n\n let checker_size = 25u;\n let on_color = ((id.x / checker_size + id.y / checker_size) % 2u) == 0u;\n\n let color = select(\n vec4<f32>(0.5, 0.0, 0.5, 1.0), // Purple\n vec4<f32>(0.0, 1.0, 0.0, 1.0), // Green\n on_color\n );\n\n textureStore(checker_texture, vec2<i32>(id.xy), color);\n}\n";
2
- export default _default;
@@ -1,176 +0,0 @@
1
- import type { Size, Vec2 } from "../coreTypes/mod";
2
- export type AtlasCoords = TextureRegion & {
3
- atlasIndex: number;
4
- };
5
- /**
6
- * A TextureRegion is a region of the texture atlas in normalized texels.
7
- *
8
- * It is a combination of a UvRegion and a cropOffset.
9
- */
10
- export type TextureRegion = UvRegion & {
11
- /** the offset from the top left of the texture in texels to begin drawing */
12
- cropOffset: Vec2;
13
- /** the original size of the texture in texels */
14
- originalSize: Size;
15
- };
16
- /**
17
- * A UvRegion is a region of the texture atlas in normalized texels.
18
- */
19
- export type UvRegion = {
20
- /**
21
- * The offset of the UVs in normalized atlas texels. Relative to the un-cropped texture.
22
- *
23
- * @example
24
- *
25
- * { x: 10 / 4096, y: 10 / 4096 }
26
- */
27
- uvOffset: Vec2;
28
- /**
29
- * The scale of the UVs in normalized texels. Derived from the width and height of the un-cropped texture.
30
- *
31
- * @example
32
- *
33
- * { width: 1 / 4096, height: 1 / 4096 }
34
- */
35
- uvScale: Size;
36
- /**
37
- * The scale of the UVs in normalized texels. Derived from the width and height of the cropped texture.
38
- *
39
- * @example
40
- *
41
- * { width: 1 / 4096, height: 1 / 4096 }
42
- */
43
- uvScaleCropped?: Size;
44
- };
45
- /**
46
- * A CpuTextureAtlas is a texture atlas that has been loaded into memory.
47
- *
48
- * It contains the texture and a map of texture ids to TextureRegions.
49
- */
50
- export type CpuTextureAtlas = {
51
- texture: ImageBitmap;
52
- rg8Bytes?: Uint8Array<ArrayBuffer>;
53
- textureRegions: Map<string, TextureRegion>;
54
- width: number;
55
- height: number;
56
- };
57
- /**
58
- * A TextureWithMetadata is a texture that has been loaded into the gpu.
59
- *
60
- * It contains the gpu texture data and a cropOffset and originalSize for use with cropped textures.
61
- */
62
- export type TextureWithMetadata = {
63
- texture: GPUTexture;
64
- /** crop offset from center in texel units */
65
- cropOffset: Vec2;
66
- /** original size in texel units before cropping */
67
- originalSize: Size;
68
- };
69
- /** A definition for a pre-baked texture atlas */
70
- export type AtlasDef = {
71
- /** The url of the atlas png file, if empty the png is assumed to be next to the json file */
72
- png?: URL;
73
- /** The url of the atlas json file, if empty the json is assumed to be next to the png file */
74
- json: URL;
75
- } | {
76
- /** The url of the atlas png file, if empty the png is assumed to be next to the json file */
77
- png: URL;
78
- /** The url of the atlas json file, if empty the json is assumed to be next to the png file */
79
- json?: URL;
80
- };
81
- /** Bundle options for registering multiple individual textures */
82
- export type TextureBundleOpts = {
83
- /**
84
- * A record of texture ids and URLs.
85
- * ids must be unique within a bundle
86
- *
87
- */
88
- textures: Record<string, URL>;
89
- /**
90
- * Whether the image should be cropped down to the minimal bounding box for non-transparent pixels.
91
- *
92
- * See [Transparent Pixel Cropping](https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/transparent-cropping.html) for more information.
93
- */
94
- cropTransparentPixels?: boolean;
95
- /**
96
- * Whether the bundle should be loaded automatically on registration
97
- */
98
- autoLoad?: boolean;
99
- };
100
- /** Bundle options for registering pre-generated texture atlases */
101
- export type AtlasBundleOpts = {
102
- /**
103
- * atlas definitions as pregenerated by a texture packer like https://github.com/pixijs/assetpack
104
- *
105
- * @example
106
- *
107
- * [
108
- * {
109
- * json: new URL('https://example.com/atlas.json'),
110
- * },
111
- * {
112
- * png: new URL('https://example.com/atlas.png'),
113
- * },
114
- * {
115
- * json: new URL('https://example.com/metadata/atlas.json'),
116
- * png: new URL('https://example.com/images/atlas.png'),
117
- * },
118
- * ]
119
- */
120
- atlases: AtlasDef[];
121
- /**
122
- * Whether the bundle should be loaded automatically on registration
123
- */
124
- autoLoad?: boolean;
125
- /**
126
- * If true, png urls will be ignored and the texture path will be inferred to be next to the json file
127
- * with a .rg8.gz extension.
128
- */
129
- rg8?: boolean;
130
- };
131
- /**
132
- * A texel region defines a subregion of an individual texture in texel units.
133
- *
134
- * (0,0) is the top left corner of the original texture.
135
- * (width, height) is the bottom right corner of the original texture.
136
- *
137
- * @example
138
- * This is useful for something like spritesheet animations,
139
- * for eg a 3-frame pose of a 32x32 character sprite might be 96x32 texels, and the animation could
140
- * be done by alternating between:
141
- *
142
- * { x: 0, y: 0, width: 32, height: 32 }
143
- * { x: 32, y: 0, width: 32, height: 32 }
144
- * { x: 64, y: 0, width: 32, height: 32 }
145
- *
146
- */
147
- export type TexelRegion = {
148
- x: number;
149
- y: number;
150
- width: number;
151
- height: number;
152
- };
153
- /** A region specification from a pixi.js spritesheet or atlas paced with assetPack */
154
- export type PixiRegion = {
155
- /** the position and size of the cropped region in the atlas, measured in texels*/
156
- frame: {
157
- x: number;
158
- y: number;
159
- w: number;
160
- h: number;
161
- };
162
- rotated: boolean;
163
- trimmed: boolean;
164
- /** the original size of the texture in texels */
165
- sourceSize: {
166
- w: number;
167
- h: number;
168
- };
169
- /** the position and size of the cropped region of the texture prior to packing in the atlas, measured in texels */
170
- spriteSourceSize: {
171
- x: number;
172
- y: number;
173
- w: number;
174
- h: number;
175
- };
176
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/textures/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG;IACxC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG;IACrC,6EAA6E;IAC7E,UAAU,EAAE,IAAI,CAAC;IACjB,iDAAiD;IACjD,YAAY,EAAE,IAAI,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;;;;;OAMG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf;;;;;;OAMG;IACH,OAAO,EAAE,IAAI,CAAC;IACd;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,IAAI,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,UAAU,CAAC;IACpB,6CAA6C;IAC7C,UAAU,EAAE,IAAI,CAAC;IACjB,mDAAmD;IACnD,YAAY,EAAE,IAAI,CAAC;CACpB,CAAC;AAEF,iDAAiD;AACjD,MAAM,MAAM,QAAQ,GAChB;IACE,6FAA6F;IAC7F,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,8FAA8F;IAC9F,IAAI,EAAE,GAAG,CAAC;CACX,GACD;IACE,6FAA6F;IAC7F,GAAG,EAAE,GAAG,CAAC;IACT,8FAA8F;IAC9F,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,CAAC;AAEN,kEAAkE;AAClE,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE9B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,EAAE,QAAQ,EAAE,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,sFAAsF;AACtF,MAAM,MAAM,UAAU,GAAG;IACvB,kFAAkF;IAClF,KAAK,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,UAAU,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACrC,mHAAmH;IACnH,gBAAgB,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE,CAAC"}
@@ -1,7 +0,0 @@
1
- import type { CpuTextureAtlas, TextureWithMetadata } from "./types";
2
- export declare function getBitmapFromUrl(url: URL): Promise<ImageBitmap>;
3
- export declare function loadZip(zipUrl: URL): Promise<{
4
- path: string;
5
- bitmap: ImageBitmap;
6
- }[]>;
7
- export declare function packBitmapsToAtlas(images: Map<string, TextureWithMetadata>, textureSize: number, device: GPUDevice): Promise<CpuTextureAtlas[]>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/textures/util.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EAEf,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CASrE;AAmED,wBAAsB,OAAO,CAC3B,MAAM,EAAE,GAAG,GACV,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,EAAE,CAAC,CAsBlD;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACxC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,eAAe,EAAE,CAAC,CA8G5B"}
@@ -1 +0,0 @@
1
- export declare function assert(condition: any, message: string): asserts condition;
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/utils/assert.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAIzE"}
@@ -1,10 +0,0 @@
1
- import type { ShaderDescriptor } from "../shaders/ShaderDescriptor";
2
- export declare function initGpu(canvas: HTMLCanvasElement, onUncapturedError?: (e: GPUUncapturedErrorEvent) => void): Promise<{
3
- device: GPUDevice;
4
- context: GPUCanvasContext;
5
- presentationFormat: GPUTextureFormat;
6
- }>;
7
- export declare function getGpuPipelineDescriptor(shaderDescriptor: ShaderDescriptor, module: GPUShaderModule, presentationFormat: GPUTextureFormat, blend?: GPUBlendState): Omit<GPURenderPipelineDescriptor, "layout">;
8
- export declare function setVertexInstanceBufferLayout(pipeline: Omit<GPURenderPipelineDescriptor, "layout">, bufferLayout: GPUVertexBufferLayout): Omit<GPURenderPipelineDescriptor, "layout">;
9
- export declare function attachVertexInstanceBuffer(renderPass: GPURenderPassEncoder, instanceBuffer: GPUBuffer): void;
10
- export declare function createGpuPipeline(device: GPUDevice, shaderDescriptor: ShaderDescriptor, pipelineDescriptor: Omit<GPURenderPipelineDescriptor, "layout">): GPURenderPipeline;
@@ -1 +0,0 @@
1
- {"version":3,"file":"boilerplate.d.ts","sourceRoot":"","sources":["../../../src/utils/boilerplate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAKpE,wBAAsB,OAAO,CAC3B,MAAM,EAAE,iBAAiB,EACzB,iBAAiB,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,KAAK,IAAI;;;;GAgCzD;AAED,wBAAgB,wBAAwB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,MAAM,EAAE,eAAe,EACvB,kBAAkB,EAAE,gBAAgB,EACpC,KAAK,CAAC,EAAE,aAAa,GACpB,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAuB7C;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAC,EACrD,YAAY,EAAE,qBAAqB,GAClC,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAG7C;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,oBAAoB,EAChC,cAAc,EAAE,SAAS,QAG1B;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,EACjB,gBAAgB,EAAE,gBAAgB,EAClC,kBAAkB,EAAE,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAC,GAC9D,iBAAiB,CAenB"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Useful for warning in a function run every frame if you only want to warn once
3
- *
4
- * @param key a unique key to tag the warning
5
- * @param msg message to console.warn
6
- */
7
- export declare function warnOnce(key: string, msg?: string): void;
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,QAMjD"}
@@ -1,2 +0,0 @@
1
- export * from "./assert";
2
- export * from "./pool";
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/utils/mod.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}