@carbonenginejs/runtime-utils 0.1.1 → 0.1.3

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 (104) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +23 -23
  3. package/README.md +69 -69
  4. package/THIRD-PARTY-NOTICES.md +64 -64
  5. package/docs/README.md +74 -73
  6. package/docs/architecture.md +101 -101
  7. package/docs/concepts/foundation-consolidation.md +85 -85
  8. package/docs/concepts/model-lifecycle.md +111 -0
  9. package/docs/const-kb.md +85 -87
  10. package/docs/core-types/DECORATOR-TODOS.md +25 -25
  11. package/docs/core-types/README.md +229 -168
  12. package/docs/reference/api.md +105 -102
  13. package/docs/reference/classes/README.md +135 -135
  14. package/package.json +139 -139
  15. package/src/arrays.js +5 -5
  16. package/src/audio/audioFormats.js +34 -34
  17. package/src/audio/index.js +1 -1
  18. package/src/box3.js +331 -331
  19. package/src/bytes.js +56 -56
  20. package/src/compression.js +56 -56
  21. package/src/constants/index.js +7 -7
  22. package/src/constants/trinity.js +13 -13
  23. package/src/constants.js +15 -15
  24. package/src/curve.js +79 -79
  25. package/src/d3d/dxgiFormats.js +46 -46
  26. package/src/d3d/index.js +2 -2
  27. package/src/d3d/primitiveTopology.js +11 -11
  28. package/src/document/CjsCarbonDocument.js +212 -212
  29. package/src/document/CjsClassRegistry.js +373 -373
  30. package/src/document/CjsDocumentDehydrator.js +142 -142
  31. package/src/document/CjsDocumentHydrator.js +156 -156
  32. package/src/document/CjsStructRegistry.js +348 -348
  33. package/src/document/hydrationAdapter.js +129 -129
  34. package/src/document/index.js +6 -6
  35. package/src/errors/CjsError.js +286 -286
  36. package/src/errors/index.js +5 -5
  37. package/src/geometry/box.js +22 -22
  38. package/src/geometry/cylinder.js +22 -22
  39. package/src/geometry/helpers/earcut.js +1 -1
  40. package/src/geometry/helpers/misc.js +3 -3
  41. package/src/geometry/index.js +8 -8
  42. package/src/geometry/json.js +67 -67
  43. package/src/geometry/lathe.js +44 -44
  44. package/src/geometry/plane.js +14 -14
  45. package/src/geometry/shape.js +4 -4
  46. package/src/geometry/sphere.js +24 -24
  47. package/src/geometry/torus.js +14 -14
  48. package/src/graphics/colorSpaces.js +22 -22
  49. package/src/graphics/index.js +4 -4
  50. package/src/graphics/pixelFormats.js +158 -158
  51. package/src/graphics/textureDimensions.js +22 -22
  52. package/src/graphics/trinityEnums.js +87 -87
  53. package/src/index.js +62 -62
  54. package/src/is.js +108 -46
  55. package/src/json.js +23 -23
  56. package/src/lifecycle/CjsLifecycleState.js +77 -77
  57. package/src/lifecycle/index.js +1 -1
  58. package/src/lne3.js +70 -70
  59. package/src/lookup.js +48 -48
  60. package/src/mat3.js +51 -51
  61. package/src/mat4.js +699 -699
  62. package/src/math/index.js +25 -25
  63. package/src/math/scalar.js +63 -63
  64. package/src/media/index.js +1 -1
  65. package/src/media/mediaTypes.js +50 -50
  66. package/src/mesh.js +424 -424
  67. package/src/model/CjsEventEmitter.js +333 -333
  68. package/src/model/CjsModel.js +1589 -1544
  69. package/src/model/CjsModelState.js +72 -72
  70. package/src/model/index.js +4 -4
  71. package/src/model/sourceRecordUtils.js +54 -54
  72. package/src/noise.js +310 -310
  73. package/src/num.js +827 -827
  74. package/src/object.js +39 -39
  75. package/src/path.js +53 -53
  76. package/src/pln.js +125 -125
  77. package/src/pool.js +9 -9
  78. package/src/quat.js +144 -144
  79. package/src/ray3.js +188 -188
  80. package/src/renderContext/formats.js +145 -145
  81. package/src/renderContext/index.js +5 -5
  82. package/src/renderContext/presentation.js +125 -125
  83. package/src/renderContext/resources.js +27 -27
  84. package/src/renderContext/upscaling.js +22 -22
  85. package/src/renderContext/window.js +20 -20
  86. package/src/runtime/CjsRuntimeState.js +50 -50
  87. package/src/schema/CjsSchema.js +555 -318
  88. package/src/schema/index.js +4 -4
  89. package/src/shader/index.js +1 -1
  90. package/src/shader/shaderStages.js +37 -37
  91. package/src/sph3.js +181 -181
  92. package/src/tangent.js +288 -288
  93. package/src/text.js +40 -40
  94. package/src/tri3.js +98 -98
  95. package/src/types/carbonTypes.js +635 -635
  96. package/src/types/index.js +2 -2
  97. package/src/utils.js +58 -58
  98. package/src/validation.js +46 -46
  99. package/src/vec2.js +229 -229
  100. package/src/vec3.js +1188 -1172
  101. package/src/vec4.js +347 -347
  102. package/src/vertex.js +108 -108
  103. package/src/webgpu/index.js +1 -1
  104. package/src/webgpu/textureFormats.js +121 -121
package/src/vertex.js CHANGED
@@ -1,108 +1,108 @@
1
- /**
2
- * Legacy vertex helper container backed by the shared mesh/tangent math.
3
- *
4
- * The previous ccpwgl implementation is intentionally not preserved here:
5
- * normal/tangent generation now delegates to the same helpers used by the GR2,
6
- * OBJ, glTF, and STL format packages.
7
- */
8
-
9
- import {
10
- generateBiNormals,
11
- generateNormals,
12
- generateTangentFrames,
13
- generateTangents
14
- } from "./mesh.js";
15
- import { packTangentFrames } from "./tangent.js";
16
-
17
- function facesForAreas(indices, areas)
18
- {
19
- if (!areas || areas.length === 0) return Array.from(indices);
20
-
21
- const faces = [];
22
- for (const area of areas)
23
- {
24
- const
25
- start = area.start || 0,
26
- count = area.count === undefined ? indices.length - start : area.count;
27
-
28
- for (let i = start; i < start + count; i++)
29
- {
30
- faces.push(indices[i]);
31
- }
32
- }
33
- return faces;
34
- }
35
-
36
- /**
37
- * Calculate area-weighted vertex normals.
38
- *
39
- * @param {ArrayLike<number>} indices Flat triangle indices.
40
- * @param {ArrayLike<number>} positions Flat xyz positions.
41
- * @returns {number[]} Flat xyz normals.
42
- */
43
- export function calculateNormals(indices, positions)
44
- {
45
- return generateNormals(positions, indices);
46
- }
47
-
48
- /**
49
- * Calculate xyz tangents from positions, normals, UVs, and triangle indices.
50
- *
51
- * @param {ArrayLike<number>} indices Flat triangle indices.
52
- * @param {ArrayLike<number>} positions Flat xyz positions.
53
- * @param {ArrayLike<number>} uvs Flat uv coordinates.
54
- * @param {Array<object>} [areas] Optional index ranges to use.
55
- * @param {ArrayLike<number>} [normals] Flat xyz normals; generated when absent.
56
- * @returns {number[]} Flat xyz tangents.
57
- */
58
- export function calculateTangents(indices, positions, uvs, areas, normals)
59
- {
60
- const faces = facesForAreas(indices, areas);
61
- return generateTangents(
62
- positions,
63
- normals && normals.length ? normals : generateNormals(positions, faces),
64
- uvs,
65
- faces
66
- );
67
- }
68
-
69
- /**
70
- * Calculate xyz binormals from normals and tangents.
71
- *
72
- * @param {ArrayLike<number>} normals Flat xyz normals.
73
- * @param {ArrayLike<number>} tangents Flat xyz tangents.
74
- * @param {object} [options] Generation options.
75
- * @returns {number[]} Flat xyz binormals.
76
- */
77
- export function calculateBiNormals(normals, tangents, options)
78
- {
79
- return generateBiNormals(normals, tangents, options);
80
- }
81
-
82
- /**
83
- * Calculate GR2-style packed tangent frames.
84
- *
85
- * @param {ArrayLike<number>} indices Flat triangle indices.
86
- * @param {ArrayLike<number>} positions Flat xyz positions.
87
- * @param {ArrayLike<number>} uvs Flat uv coordinates.
88
- * @param {Array<object>} [areas] Optional index ranges to use.
89
- * @param {ArrayLike<number>} [normals] Flat xyz normals; generated when absent.
90
- * @param {object} [options] Generation options.
91
- * @returns {number[]} Flat xyzw packed tangent-frame values.
92
- */
93
- export function calculatePackedTangents(indices, positions, uvs, areas, normals, options)
94
- {
95
- const
96
- faces = facesForAreas(indices, areas),
97
- normalValues = normals && normals.length ? normals : generateNormals(positions, faces),
98
- frame = generateTangentFrames(positions, normalValues, uvs, faces, options);
99
-
100
- return packTangentFrames(normalValues, frame.tangents, frame.binormals);
101
- }
102
-
103
- export const vertex = Object.freeze({
104
- calculateNormals,
105
- calculateTangents,
106
- calculateBiNormals,
107
- calculatePackedTangents
108
- });
1
+ /**
2
+ * Legacy vertex helper container backed by the shared mesh/tangent math.
3
+ *
4
+ * The previous ccpwgl implementation is intentionally not preserved here:
5
+ * normal/tangent generation now delegates to the same helpers used by the GR2,
6
+ * OBJ, glTF, and STL format packages.
7
+ */
8
+
9
+ import {
10
+ generateBiNormals,
11
+ generateNormals,
12
+ generateTangentFrames,
13
+ generateTangents
14
+ } from "./mesh.js";
15
+ import { packTangentFrames } from "./tangent.js";
16
+
17
+ function facesForAreas(indices, areas)
18
+ {
19
+ if (!areas || areas.length === 0) return Array.from(indices);
20
+
21
+ const faces = [];
22
+ for (const area of areas)
23
+ {
24
+ const
25
+ start = area.start || 0,
26
+ count = area.count === undefined ? indices.length - start : area.count;
27
+
28
+ for (let i = start; i < start + count; i++)
29
+ {
30
+ faces.push(indices[i]);
31
+ }
32
+ }
33
+ return faces;
34
+ }
35
+
36
+ /**
37
+ * Calculate area-weighted vertex normals.
38
+ *
39
+ * @param {ArrayLike<number>} indices Flat triangle indices.
40
+ * @param {ArrayLike<number>} positions Flat xyz positions.
41
+ * @returns {number[]} Flat xyz normals.
42
+ */
43
+ export function calculateNormals(indices, positions)
44
+ {
45
+ return generateNormals(positions, indices);
46
+ }
47
+
48
+ /**
49
+ * Calculate xyz tangents from positions, normals, UVs, and triangle indices.
50
+ *
51
+ * @param {ArrayLike<number>} indices Flat triangle indices.
52
+ * @param {ArrayLike<number>} positions Flat xyz positions.
53
+ * @param {ArrayLike<number>} uvs Flat uv coordinates.
54
+ * @param {Array<object>} [areas] Optional index ranges to use.
55
+ * @param {ArrayLike<number>} [normals] Flat xyz normals; generated when absent.
56
+ * @returns {number[]} Flat xyz tangents.
57
+ */
58
+ export function calculateTangents(indices, positions, uvs, areas, normals)
59
+ {
60
+ const faces = facesForAreas(indices, areas);
61
+ return generateTangents(
62
+ positions,
63
+ normals && normals.length ? normals : generateNormals(positions, faces),
64
+ uvs,
65
+ faces
66
+ );
67
+ }
68
+
69
+ /**
70
+ * Calculate xyz binormals from normals and tangents.
71
+ *
72
+ * @param {ArrayLike<number>} normals Flat xyz normals.
73
+ * @param {ArrayLike<number>} tangents Flat xyz tangents.
74
+ * @param {object} [options] Generation options.
75
+ * @returns {number[]} Flat xyz binormals.
76
+ */
77
+ export function calculateBiNormals(normals, tangents, options)
78
+ {
79
+ return generateBiNormals(normals, tangents, options);
80
+ }
81
+
82
+ /**
83
+ * Calculate GR2-style packed tangent frames.
84
+ *
85
+ * @param {ArrayLike<number>} indices Flat triangle indices.
86
+ * @param {ArrayLike<number>} positions Flat xyz positions.
87
+ * @param {ArrayLike<number>} uvs Flat uv coordinates.
88
+ * @param {Array<object>} [areas] Optional index ranges to use.
89
+ * @param {ArrayLike<number>} [normals] Flat xyz normals; generated when absent.
90
+ * @param {object} [options] Generation options.
91
+ * @returns {number[]} Flat xyzw packed tangent-frame values.
92
+ */
93
+ export function calculatePackedTangents(indices, positions, uvs, areas, normals, options)
94
+ {
95
+ const
96
+ faces = facesForAreas(indices, areas),
97
+ normalValues = normals && normals.length ? normals : generateNormals(positions, faces),
98
+ frame = generateTangentFrames(positions, normalValues, uvs, faces, options);
99
+
100
+ return packTangentFrames(normalValues, frame.tangents, frame.binormals);
101
+ }
102
+
103
+ export const vertex = Object.freeze({
104
+ calculateNormals,
105
+ calculateTangents,
106
+ calculateBiNormals,
107
+ calculatePackedTangents
108
+ });
@@ -1 +1 @@
1
- export * from "./textureFormats.js";
1
+ export * from "./textureFormats.js";
@@ -1,121 +1,121 @@
1
- import { PixelFormat } from "../graphics/pixelFormats.js";
2
- import { DxgiFormat } from "../d3d/dxgiFormats.js";
3
-
4
- /**
5
- * WebGPU texture format tokens mirrored as stable strings.
6
- */
7
- export const GpuTextureFormat = Object.freeze({
8
- R8_UNORM: "r8unorm",
9
- RG8_UNORM: "rg8unorm",
10
- RGBA8_UNORM: "rgba8unorm",
11
- RGBA8_UNORM_SRGB: "rgba8unorm-srgb",
12
- BGRA8_UNORM: "bgra8unorm",
13
- BGRA8_UNORM_SRGB: "bgra8unorm-srgb",
14
- R16_FLOAT: "r16float",
15
- RG16_FLOAT: "rg16float",
16
- RGBA16_FLOAT: "rgba16float",
17
- R32_FLOAT: "r32float",
18
- RG32_FLOAT: "rg32float",
19
- RGBA32_FLOAT: "rgba32float",
20
- BC1_RGBA_UNORM: "bc1-rgba-unorm",
21
- BC1_RGBA_UNORM_SRGB: "bc1-rgba-unorm-srgb",
22
- BC2_RGBA_UNORM: "bc2-rgba-unorm",
23
- BC2_RGBA_UNORM_SRGB: "bc2-rgba-unorm-srgb",
24
- BC3_RGBA_UNORM: "bc3-rgba-unorm",
25
- BC3_RGBA_UNORM_SRGB: "bc3-rgba-unorm-srgb",
26
- BC4_R_UNORM: "bc4-r-unorm",
27
- BC4_R_SNORM: "bc4-r-snorm",
28
- BC5_RG_UNORM: "bc5-rg-unorm",
29
- BC5_RG_SNORM: "bc5-rg-snorm",
30
- BC6H_RGB_UFLOAT: "bc6h-rgb-ufloat",
31
- BC6H_RGB_FLOAT: "bc6h-rgb-float",
32
- BC7_RGBA_UNORM: "bc7-rgba-unorm",
33
- BC7_RGBA_UNORM_SRGB: "bc7-rgba-unorm-srgb"
34
- });
35
-
36
- /**
37
- * Map canonical CarbonEngineJS pixel formats to WebGPU texture format strings.
38
- */
39
- export const PixelFormatToWebGpu = Object.freeze({
40
- [PixelFormat.R8_UNORM]: GpuTextureFormat.R8_UNORM,
41
- [PixelFormat.RG8_UNORM]: GpuTextureFormat.RG8_UNORM,
42
- [PixelFormat.RGBA8_UNORM]: GpuTextureFormat.RGBA8_UNORM,
43
- [PixelFormat.RGBA8_UNORM_SRGB]: GpuTextureFormat.RGBA8_UNORM_SRGB,
44
- [PixelFormat.BGRA8_UNORM]: GpuTextureFormat.BGRA8_UNORM,
45
- [PixelFormat.BGRA8_UNORM_SRGB]: GpuTextureFormat.BGRA8_UNORM_SRGB,
46
- [PixelFormat.R16_FLOAT]: GpuTextureFormat.R16_FLOAT,
47
- [PixelFormat.RG16_FLOAT]: GpuTextureFormat.RG16_FLOAT,
48
- [PixelFormat.RGBA16_FLOAT]: GpuTextureFormat.RGBA16_FLOAT,
49
- [PixelFormat.R32_FLOAT]: GpuTextureFormat.R32_FLOAT,
50
- [PixelFormat.RG32_FLOAT]: GpuTextureFormat.RG32_FLOAT,
51
- [PixelFormat.RGBA32_FLOAT]: GpuTextureFormat.RGBA32_FLOAT,
52
- [PixelFormat.BC1_RGBA_UNORM]: GpuTextureFormat.BC1_RGBA_UNORM,
53
- [PixelFormat.BC1_RGBA_UNORM_SRGB]: GpuTextureFormat.BC1_RGBA_UNORM_SRGB,
54
- [PixelFormat.BC2_RGBA_UNORM]: GpuTextureFormat.BC2_RGBA_UNORM,
55
- [PixelFormat.BC2_RGBA_UNORM_SRGB]: GpuTextureFormat.BC2_RGBA_UNORM_SRGB,
56
- [PixelFormat.BC3_RGBA_UNORM]: GpuTextureFormat.BC3_RGBA_UNORM,
57
- [PixelFormat.BC3_RGBA_UNORM_SRGB]: GpuTextureFormat.BC3_RGBA_UNORM_SRGB,
58
- [PixelFormat.BC4_R_UNORM]: GpuTextureFormat.BC4_R_UNORM,
59
- [PixelFormat.BC4_R_SNORM]: GpuTextureFormat.BC4_R_SNORM,
60
- [PixelFormat.BC5_RG_UNORM]: GpuTextureFormat.BC5_RG_UNORM,
61
- [PixelFormat.BC5_RG_SNORM]: GpuTextureFormat.BC5_RG_SNORM,
62
- [PixelFormat.BC6H_RGB_UFLOAT]: GpuTextureFormat.BC6H_RGB_UFLOAT,
63
- [PixelFormat.BC6H_RGB_FLOAT]: GpuTextureFormat.BC6H_RGB_FLOAT,
64
- [PixelFormat.BC7_RGBA_UNORM]: GpuTextureFormat.BC7_RGBA_UNORM,
65
- [PixelFormat.BC7_RGBA_UNORM_SRGB]: GpuTextureFormat.BC7_RGBA_UNORM_SRGB
66
- });
67
-
68
- /**
69
- * Map selected DXGI formats to canonical CarbonEngineJS pixel formats.
70
- */
71
- export const DxgiFormatToPixelFormat = Object.freeze({
72
- [DxgiFormat.R32G32B32A32_FLOAT]: PixelFormat.RGBA32_FLOAT,
73
- [DxgiFormat.R32G32_FLOAT]: PixelFormat.RG32_FLOAT,
74
- [DxgiFormat.R32_FLOAT]: PixelFormat.R32_FLOAT,
75
- [DxgiFormat.R16G16B16A16_FLOAT]: PixelFormat.RGBA16_FLOAT,
76
- [DxgiFormat.R8G8_UNORM]: PixelFormat.RG8_UNORM,
77
- [DxgiFormat.R8G8B8A8_UNORM]: PixelFormat.RGBA8_UNORM,
78
- [DxgiFormat.R8G8B8A8_UNORM_SRGB]: PixelFormat.RGBA8_UNORM_SRGB,
79
- [DxgiFormat.R16_FLOAT]: PixelFormat.R16_FLOAT,
80
- [DxgiFormat.R8_UNORM]: PixelFormat.R8_UNORM,
81
- [DxgiFormat.BC1_UNORM]: PixelFormat.BC1_RGBA_UNORM,
82
- [DxgiFormat.BC1_UNORM_SRGB]: PixelFormat.BC1_RGBA_UNORM_SRGB,
83
- [DxgiFormat.BC2_UNORM]: PixelFormat.BC2_RGBA_UNORM,
84
- [DxgiFormat.BC2_UNORM_SRGB]: PixelFormat.BC2_RGBA_UNORM_SRGB,
85
- [DxgiFormat.BC3_UNORM]: PixelFormat.BC3_RGBA_UNORM,
86
- [DxgiFormat.BC3_UNORM_SRGB]: PixelFormat.BC3_RGBA_UNORM_SRGB,
87
- [DxgiFormat.BC4_UNORM]: PixelFormat.BC4_R_UNORM,
88
- [DxgiFormat.BC4_SNORM]: PixelFormat.BC4_R_SNORM,
89
- [DxgiFormat.BC5_UNORM]: PixelFormat.BC5_RG_UNORM,
90
- [DxgiFormat.BC5_SNORM]: PixelFormat.BC5_RG_SNORM,
91
- [DxgiFormat.B8G8R8A8_UNORM]: PixelFormat.BGRA8_UNORM,
92
- [DxgiFormat.B8G8R8X8_UNORM]: PixelFormat.BGRX8_UNORM,
93
- [DxgiFormat.B8G8R8A8_UNORM_SRGB]: PixelFormat.BGRA8_UNORM_SRGB,
94
- [DxgiFormat.B8G8R8X8_UNORM_SRGB]: PixelFormat.BGRX8_UNORM_SRGB,
95
- [DxgiFormat.BC6H_UF16]: PixelFormat.BC6H_RGB_UFLOAT,
96
- [DxgiFormat.BC6H_SF16]: PixelFormat.BC6H_RGB_FLOAT,
97
- [DxgiFormat.BC7_UNORM]: PixelFormat.BC7_RGBA_UNORM,
98
- [DxgiFormat.BC7_UNORM_SRGB]: PixelFormat.BC7_RGBA_UNORM_SRGB
99
- });
100
-
101
- /**
102
- * Convert a pixel format token to a WebGPU texture format token.
103
- *
104
- * @param {string} format Pixel format token.
105
- * @returns {string} WebGPU texture format token or empty string.
106
- */
107
- export function toWebGpuTextureFormat(format)
108
- {
109
- return PixelFormatToWebGpu[format] || "";
110
- }
111
-
112
- /**
113
- * Convert a DXGI numeric format to a pixel format token.
114
- *
115
- * @param {number} format DXGI_FORMAT numeric value.
116
- * @returns {string} Pixel format token or unknown.
117
- */
118
- export function dxgiToPixelFormat(format)
119
- {
120
- return DxgiFormatToPixelFormat[format] || PixelFormat.UNKNOWN;
121
- }
1
+ import { PixelFormat } from "../graphics/pixelFormats.js";
2
+ import { DxgiFormat } from "../d3d/dxgiFormats.js";
3
+
4
+ /**
5
+ * WebGPU texture format tokens mirrored as stable strings.
6
+ */
7
+ export const GpuTextureFormat = Object.freeze({
8
+ R8_UNORM: "r8unorm",
9
+ RG8_UNORM: "rg8unorm",
10
+ RGBA8_UNORM: "rgba8unorm",
11
+ RGBA8_UNORM_SRGB: "rgba8unorm-srgb",
12
+ BGRA8_UNORM: "bgra8unorm",
13
+ BGRA8_UNORM_SRGB: "bgra8unorm-srgb",
14
+ R16_FLOAT: "r16float",
15
+ RG16_FLOAT: "rg16float",
16
+ RGBA16_FLOAT: "rgba16float",
17
+ R32_FLOAT: "r32float",
18
+ RG32_FLOAT: "rg32float",
19
+ RGBA32_FLOAT: "rgba32float",
20
+ BC1_RGBA_UNORM: "bc1-rgba-unorm",
21
+ BC1_RGBA_UNORM_SRGB: "bc1-rgba-unorm-srgb",
22
+ BC2_RGBA_UNORM: "bc2-rgba-unorm",
23
+ BC2_RGBA_UNORM_SRGB: "bc2-rgba-unorm-srgb",
24
+ BC3_RGBA_UNORM: "bc3-rgba-unorm",
25
+ BC3_RGBA_UNORM_SRGB: "bc3-rgba-unorm-srgb",
26
+ BC4_R_UNORM: "bc4-r-unorm",
27
+ BC4_R_SNORM: "bc4-r-snorm",
28
+ BC5_RG_UNORM: "bc5-rg-unorm",
29
+ BC5_RG_SNORM: "bc5-rg-snorm",
30
+ BC6H_RGB_UFLOAT: "bc6h-rgb-ufloat",
31
+ BC6H_RGB_FLOAT: "bc6h-rgb-float",
32
+ BC7_RGBA_UNORM: "bc7-rgba-unorm",
33
+ BC7_RGBA_UNORM_SRGB: "bc7-rgba-unorm-srgb"
34
+ });
35
+
36
+ /**
37
+ * Map canonical CarbonEngineJS pixel formats to WebGPU texture format strings.
38
+ */
39
+ export const PixelFormatToWebGpu = Object.freeze({
40
+ [PixelFormat.R8_UNORM]: GpuTextureFormat.R8_UNORM,
41
+ [PixelFormat.RG8_UNORM]: GpuTextureFormat.RG8_UNORM,
42
+ [PixelFormat.RGBA8_UNORM]: GpuTextureFormat.RGBA8_UNORM,
43
+ [PixelFormat.RGBA8_UNORM_SRGB]: GpuTextureFormat.RGBA8_UNORM_SRGB,
44
+ [PixelFormat.BGRA8_UNORM]: GpuTextureFormat.BGRA8_UNORM,
45
+ [PixelFormat.BGRA8_UNORM_SRGB]: GpuTextureFormat.BGRA8_UNORM_SRGB,
46
+ [PixelFormat.R16_FLOAT]: GpuTextureFormat.R16_FLOAT,
47
+ [PixelFormat.RG16_FLOAT]: GpuTextureFormat.RG16_FLOAT,
48
+ [PixelFormat.RGBA16_FLOAT]: GpuTextureFormat.RGBA16_FLOAT,
49
+ [PixelFormat.R32_FLOAT]: GpuTextureFormat.R32_FLOAT,
50
+ [PixelFormat.RG32_FLOAT]: GpuTextureFormat.RG32_FLOAT,
51
+ [PixelFormat.RGBA32_FLOAT]: GpuTextureFormat.RGBA32_FLOAT,
52
+ [PixelFormat.BC1_RGBA_UNORM]: GpuTextureFormat.BC1_RGBA_UNORM,
53
+ [PixelFormat.BC1_RGBA_UNORM_SRGB]: GpuTextureFormat.BC1_RGBA_UNORM_SRGB,
54
+ [PixelFormat.BC2_RGBA_UNORM]: GpuTextureFormat.BC2_RGBA_UNORM,
55
+ [PixelFormat.BC2_RGBA_UNORM_SRGB]: GpuTextureFormat.BC2_RGBA_UNORM_SRGB,
56
+ [PixelFormat.BC3_RGBA_UNORM]: GpuTextureFormat.BC3_RGBA_UNORM,
57
+ [PixelFormat.BC3_RGBA_UNORM_SRGB]: GpuTextureFormat.BC3_RGBA_UNORM_SRGB,
58
+ [PixelFormat.BC4_R_UNORM]: GpuTextureFormat.BC4_R_UNORM,
59
+ [PixelFormat.BC4_R_SNORM]: GpuTextureFormat.BC4_R_SNORM,
60
+ [PixelFormat.BC5_RG_UNORM]: GpuTextureFormat.BC5_RG_UNORM,
61
+ [PixelFormat.BC5_RG_SNORM]: GpuTextureFormat.BC5_RG_SNORM,
62
+ [PixelFormat.BC6H_RGB_UFLOAT]: GpuTextureFormat.BC6H_RGB_UFLOAT,
63
+ [PixelFormat.BC6H_RGB_FLOAT]: GpuTextureFormat.BC6H_RGB_FLOAT,
64
+ [PixelFormat.BC7_RGBA_UNORM]: GpuTextureFormat.BC7_RGBA_UNORM,
65
+ [PixelFormat.BC7_RGBA_UNORM_SRGB]: GpuTextureFormat.BC7_RGBA_UNORM_SRGB
66
+ });
67
+
68
+ /**
69
+ * Map selected DXGI formats to canonical CarbonEngineJS pixel formats.
70
+ */
71
+ export const DxgiFormatToPixelFormat = Object.freeze({
72
+ [DxgiFormat.R32G32B32A32_FLOAT]: PixelFormat.RGBA32_FLOAT,
73
+ [DxgiFormat.R32G32_FLOAT]: PixelFormat.RG32_FLOAT,
74
+ [DxgiFormat.R32_FLOAT]: PixelFormat.R32_FLOAT,
75
+ [DxgiFormat.R16G16B16A16_FLOAT]: PixelFormat.RGBA16_FLOAT,
76
+ [DxgiFormat.R8G8_UNORM]: PixelFormat.RG8_UNORM,
77
+ [DxgiFormat.R8G8B8A8_UNORM]: PixelFormat.RGBA8_UNORM,
78
+ [DxgiFormat.R8G8B8A8_UNORM_SRGB]: PixelFormat.RGBA8_UNORM_SRGB,
79
+ [DxgiFormat.R16_FLOAT]: PixelFormat.R16_FLOAT,
80
+ [DxgiFormat.R8_UNORM]: PixelFormat.R8_UNORM,
81
+ [DxgiFormat.BC1_UNORM]: PixelFormat.BC1_RGBA_UNORM,
82
+ [DxgiFormat.BC1_UNORM_SRGB]: PixelFormat.BC1_RGBA_UNORM_SRGB,
83
+ [DxgiFormat.BC2_UNORM]: PixelFormat.BC2_RGBA_UNORM,
84
+ [DxgiFormat.BC2_UNORM_SRGB]: PixelFormat.BC2_RGBA_UNORM_SRGB,
85
+ [DxgiFormat.BC3_UNORM]: PixelFormat.BC3_RGBA_UNORM,
86
+ [DxgiFormat.BC3_UNORM_SRGB]: PixelFormat.BC3_RGBA_UNORM_SRGB,
87
+ [DxgiFormat.BC4_UNORM]: PixelFormat.BC4_R_UNORM,
88
+ [DxgiFormat.BC4_SNORM]: PixelFormat.BC4_R_SNORM,
89
+ [DxgiFormat.BC5_UNORM]: PixelFormat.BC5_RG_UNORM,
90
+ [DxgiFormat.BC5_SNORM]: PixelFormat.BC5_RG_SNORM,
91
+ [DxgiFormat.B8G8R8A8_UNORM]: PixelFormat.BGRA8_UNORM,
92
+ [DxgiFormat.B8G8R8X8_UNORM]: PixelFormat.BGRX8_UNORM,
93
+ [DxgiFormat.B8G8R8A8_UNORM_SRGB]: PixelFormat.BGRA8_UNORM_SRGB,
94
+ [DxgiFormat.B8G8R8X8_UNORM_SRGB]: PixelFormat.BGRX8_UNORM_SRGB,
95
+ [DxgiFormat.BC6H_UF16]: PixelFormat.BC6H_RGB_UFLOAT,
96
+ [DxgiFormat.BC6H_SF16]: PixelFormat.BC6H_RGB_FLOAT,
97
+ [DxgiFormat.BC7_UNORM]: PixelFormat.BC7_RGBA_UNORM,
98
+ [DxgiFormat.BC7_UNORM_SRGB]: PixelFormat.BC7_RGBA_UNORM_SRGB
99
+ });
100
+
101
+ /**
102
+ * Convert a pixel format token to a WebGPU texture format token.
103
+ *
104
+ * @param {string} format Pixel format token.
105
+ * @returns {string} WebGPU texture format token or empty string.
106
+ */
107
+ export function toWebGpuTextureFormat(format)
108
+ {
109
+ return PixelFormatToWebGpu[format] || "";
110
+ }
111
+
112
+ /**
113
+ * Convert a DXGI numeric format to a pixel format token.
114
+ *
115
+ * @param {number} format DXGI_FORMAT numeric value.
116
+ * @returns {string} Pixel format token or unknown.
117
+ */
118
+ export function dxgiToPixelFormat(format)
119
+ {
120
+ return DxgiFormatToPixelFormat[format] || PixelFormat.UNKNOWN;
121
+ }