@carbonenginejs/runtime-resource 0.11.1 → 0.12.1

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 (211) hide show
  1. package/dist/CjsResMan.js +4 -4
  2. package/dist/CjsResMan.js.map +1 -1
  3. package/dist/_virtual/_rollupPluginBabelHelpers.js +1 -4
  4. package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  5. package/dist/format/CjsByteReader.js +310 -0
  6. package/dist/format/CjsByteReader.js.map +1 -0
  7. package/dist/format/CjsByteWriter.js +242 -0
  8. package/dist/format/CjsByteWriter.js.map +1 -0
  9. package/dist/format/CjsFormatError.js +41 -0
  10. package/dist/format/CjsFormatError.js.map +1 -0
  11. package/dist/format/CjsStringTable.js +268 -0
  12. package/dist/format/CjsStringTable.js.map +1 -0
  13. package/dist/format/carbonEffect/CjsCarbonEffectReader.js +361 -0
  14. package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -0
  15. package/dist/format/carbonEffect/CjsCarbonEffectWriter.js +373 -0
  16. package/dist/format/carbonEffect/CjsCarbonEffectWriter.js.map +1 -0
  17. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +372 -0
  18. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +1 -0
  19. package/dist/format/carbonEffect/carbonEffectBackendBlock.js +427 -0
  20. package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -0
  21. package/dist/format/carbonEffect/carbonEffectRecords.js +955 -0
  22. package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -0
  23. package/dist/format/compareUtf8.js +36 -0
  24. package/dist/format/compareUtf8.js.map +1 -0
  25. package/dist/format/index.js +11 -0
  26. package/dist/format/index.js.map +1 -0
  27. package/dist/formats/bnk/CjsBnkFormat.js +18 -2
  28. package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
  29. package/dist/formats/bnk/core/eventAction.js +305 -0
  30. package/dist/formats/bnk/core/eventAction.js.map +1 -0
  31. package/dist/formats/bnk/core/graph.js +3 -6
  32. package/dist/formats/bnk/core/graph.js.map +1 -1
  33. package/dist/formats/bnk/core/helpers.js +62 -11
  34. package/dist/formats/bnk/core/helpers.js.map +1 -1
  35. package/dist/formats/bnk/core/nodeBase.js +532 -0
  36. package/dist/formats/bnk/core/nodeBase.js.map +1 -0
  37. package/dist/formats/bnk/core/sfxNodes.js +632 -0
  38. package/dist/formats/bnk/core/sfxNodes.js.map +1 -0
  39. package/dist/formats/bnk/core/soundbanksInfo.js +59 -51
  40. package/dist/formats/bnk/core/soundbanksInfo.js.map +1 -1
  41. package/dist/formats/gr2/CjsGr2Format.js +256 -13
  42. package/dist/formats/gr2/CjsGr2Format.js.map +1 -1
  43. package/dist/formats/gr2/core/helpers.js +15 -15
  44. package/dist/formats/gr2/core/helpers.js.map +1 -1
  45. package/dist/formats/gr2/core/json.js +1 -1
  46. package/dist/formats/gr2/core/json.js.map +1 -1
  47. package/dist/formats/gr2/core/targets.js +1 -1
  48. package/dist/formats/gr2/core/targets.js.map +1 -1
  49. package/dist/formats/gr2/index.js +0 -1
  50. package/dist/formats/gr2/index.js.map +1 -1
  51. package/dist/formats/hlsl/core/HlslReader.js +7 -257
  52. package/dist/formats/hlsl/core/HlslReader.js.map +1 -1
  53. package/dist/formats/hlsl/core/analysis.js +1 -1
  54. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +781 -0
  55. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -0
  56. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +21 -1
  57. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
  58. package/dist/formats/hlsl/index.js +1 -0
  59. package/dist/formats/hlsl/index.js.map +1 -1
  60. package/dist/formats/index.js +3 -6
  61. package/dist/formats/index.js.map +1 -1
  62. package/dist/formats/webgl/core/cewg/CewgPackage.js +2 -1
  63. package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -1
  64. package/dist/formats/webgl/core/cewg/binary.js +11 -93
  65. package/dist/formats/webgl/core/cewg/binary.js.map +1 -1
  66. package/dist/formats/webgl/core/effectPackage.js +4 -1
  67. package/dist/formats/webgl/core/effectPackage.js.map +1 -1
  68. package/dist/formats/webgl/core/errors.js +3 -3
  69. package/dist/formats/webgl/core/errors.js.map +1 -1
  70. package/dist/formats/webgpu/CjsWebgpuFormat.js +4 -23
  71. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
  72. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +197 -0
  73. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -0
  74. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js +368 -0
  75. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +1 -0
  76. package/dist/formats/webgpu/core/cewgpu/containerViews.js +355 -0
  77. package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +1 -0
  78. package/dist/formats/webgpu/core/cewgpu/validateContainer.js +90 -0
  79. package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +1 -0
  80. package/dist/formats/webgpu/core/effectBackendBodySet.js +21 -20
  81. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
  82. package/dist/formats/webgpu/core/helpers.js +87 -92
  83. package/dist/formats/webgpu/core/helpers.js.map +1 -1
  84. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +14 -13
  85. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -1
  86. package/dist/formats/webgpu/core/ir/inferValueTypes.js +10 -8
  87. package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -1
  88. package/dist/formats/webgpu/core/packageEffect.js +94 -9
  89. package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
  90. package/dist/formats/webgpu/core/packageMetadata.js +10 -1
  91. package/dist/formats/webgpu/core/packageMetadata.js.map +1 -1
  92. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +17 -15
  93. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
  94. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +13 -12
  95. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -1
  96. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +9 -8
  97. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
  98. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +23 -22
  99. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -1
  100. package/dist/formats/webgpu/core/wgsl/selectionPlans.js +46 -44
  101. package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -1
  102. package/dist/resource/CjsResource.js +700 -684
  103. package/dist/resource/CjsResource.js.map +1 -1
  104. package/dist/resource/Tr2LightProfileRes.js +18 -27
  105. package/dist/resource/Tr2LightProfileRes.js.map +1 -1
  106. package/dist/resource/audio/CjsAudioBufferRes.js +2 -2
  107. package/dist/resource/audio/CjsAudioBufferRes.js.map +1 -1
  108. package/dist/resource/audio/CjsAudioRes.js +2 -2
  109. package/dist/resource/audio/CjsAudioRes.js.map +1 -1
  110. package/dist/resource/geometry/TriGeometryRes.js +605 -586
  111. package/dist/resource/geometry/TriGeometryRes.js.map +1 -1
  112. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js +21 -30
  113. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js.map +1 -1
  114. package/dist/resource/geometry/granny/TriGrannyRes.js +21 -30
  115. package/dist/resource/geometry/granny/TriGrannyRes.js.map +1 -1
  116. package/dist/resource/shader/Tr2EffectRes.js +9 -7
  117. package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
  118. package/dist/resource/shader/Tr2MaterialArea.js +5 -3
  119. package/dist/resource/shader/Tr2MaterialArea.js.map +1 -1
  120. package/dist/resource/shader/Tr2MaterialMesh.js +4 -2
  121. package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -1
  122. package/dist/resource/shader/Tr2MaterialRes.js +5 -3
  123. package/dist/resource/shader/Tr2MaterialRes.js.map +1 -1
  124. package/dist/resource/shader/Tr2Shader.js +26 -21
  125. package/dist/resource/shader/Tr2Shader.js.map +1 -1
  126. package/dist/resource/shader/Tr2ShaderPermutation.js +8 -6
  127. package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -1
  128. package/dist/resource/shader/reflection/Tr2EffectDefine.js +5 -3
  129. package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -1
  130. package/dist/resource/shader/reflection/Tr2EffectDescription.js +5 -3
  131. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
  132. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +17 -15
  133. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
  134. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +11 -9
  135. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
  136. package/dist/resource/shader/reflection/Tr2EffectResource.js +8 -6
  137. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
  138. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +15 -13
  139. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  140. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +7 -5
  141. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
  142. package/dist/resource/shader/reflection/Tr2Pass.js +11 -9
  143. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
  144. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +8 -6
  145. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
  146. package/dist/resource/texture/CjsTextureArrayRes.js +400 -411
  147. package/dist/resource/texture/CjsTextureArrayRes.js.map +1 -1
  148. package/dist/resource/texture/Tr2ImageRes.js +99 -95
  149. package/dist/resource/texture/Tr2ImageRes.js.map +1 -1
  150. package/dist/resource/texture/TriTextureRes.js +312 -273
  151. package/dist/resource/texture/TriTextureRes.js.map +1 -1
  152. package/docs/README.md +13 -1
  153. package/docs/architecture.md +3 -3
  154. package/docs/concepts/resource-lifecycle.md +9 -2
  155. package/docs/concepts/shader-resource-model.md +114 -0
  156. package/docs/concepts/writing-an-engine-adapter.md +115 -0
  157. package/docs/formats/README.md +24 -1
  158. package/docs/formats/carbon-effect-container.md +452 -0
  159. package/docs/formats/dxbc/README.md +68 -0
  160. package/docs/formats/dxbc/architecture.md +80 -0
  161. package/docs/formats/dxbc/reference/api.md +77 -0
  162. package/docs/formats/dxbc/reference/classes/README.md +9 -0
  163. package/docs/formats/dxbc/reference/decoded-output.md +122 -0
  164. package/docs/formats/gr2.md +3 -4
  165. package/docs/formats/hlsl/README.md +54 -0
  166. package/docs/formats/hlsl/architecture.md +67 -0
  167. package/docs/formats/hlsl/guides/hydrating-json-output.md +62 -0
  168. package/docs/formats/hlsl/guides/reading-effects.md +64 -0
  169. package/docs/formats/hlsl/reference/advanced-analysis.md +66 -0
  170. package/docs/formats/hlsl/reference/api.md +98 -0
  171. package/docs/formats/hlsl/reference/classes/README.md +11 -0
  172. package/docs/formats/hlsl/reference/json-graph.md +100 -0
  173. package/docs/formats/hlsl/reference/portable-reflection.md +141 -0
  174. package/docs/formats/provenance.md +32 -17
  175. package/docs/formats/webgl/README.md +57 -0
  176. package/docs/formats/webgl/architecture.md +70 -0
  177. package/docs/formats/webgl/carbon-constant-layouts.md +326 -0
  178. package/docs/formats/webgl/decl-io.md +1234 -0
  179. package/docs/formats/webgl/effect-reflection.md +127 -0
  180. package/docs/formats/webgl/memory-structured.md +871 -0
  181. package/docs/formats/webgl/reference/classes/README.md +9 -0
  182. package/docs/formats/webgl/texture-sample.md +964 -0
  183. package/docs/formats/webgpu/README.md +84 -0
  184. package/docs/formats/webgpu/architecture.md +96 -0
  185. package/docs/formats/webgpu/formats/cewgpu.md +216 -0
  186. package/docs/formats/webgpu/guides/effect-packaging.md +191 -0
  187. package/docs/formats/webgpu/reference/api.md +197 -0
  188. package/docs/formats/webgpu/reference/classes/README.md +9 -0
  189. package/docs/formats/webgpu/reference/wgsl-compatibility.md +1543 -0
  190. package/docs/formats/wwise.md +45 -4
  191. package/docs/reference/classes/core.md +80 -0
  192. package/docs/reference/classes/formats.md +24 -34
  193. package/docs/reference/events.md +25 -0
  194. package/docs/reference/motherlode-cache.md +22 -8
  195. package/docs/reference/workers.md +5 -5
  196. package/docs/roadmap.md +61 -41
  197. package/format-notices/bnk/NOTICE +5 -4
  198. package/format-notices/webgl/NOTICE +1 -1
  199. package/package.json +2 -1
  200. package/dist/formats/gr2/core/CjsFormatGr2.js +0 -273
  201. package/dist/formats/gr2/core/CjsFormatGr2.js.map +0 -1
  202. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +0 -415
  203. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +0 -1
  204. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +0 -100
  205. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +0 -1
  206. package/dist/formats/webgpu/core/cewgpu/binary.js +0 -93
  207. package/dist/formats/webgpu/core/cewgpu/binary.js.map +0 -1
  208. package/dist/formats/webgpu/core/cewgpu/tags.js +0 -17
  209. package/dist/formats/webgpu/core/cewgpu/tags.js.map +0 -1
  210. package/dist/formats/webgpu/core/effectPackageValidation.js +0 -1078
  211. package/dist/formats/webgpu/core/effectPackageValidation.js.map +0 -1
@@ -1,273 +0,0 @@
1
- import { curves } from './curves.js';
2
- import { tangents } from './tangents.js';
3
- import { isGsfRaw, projectGsf, inspectGsfRaw } from './gsf.js';
4
- import { DEFAULT_VALUES, normalizeValues, validateClassKey, validateClass, readWithValues, readRawInput, inspectRawGr2Result, toJsonValue, OUTPUT_JSON, OUTPUT_GR2, OUTPUT_GR2_JSON, OUTPUT_CMF, OUTPUT_RAW, CLASS_KEYS } from './helpers.js';
5
-
6
- /**
7
- * Exposed CarbonEngineJS-facing GR2 format class.
8
- *
9
- * Keep this file small and reviewable: parsing, conversion, rebuild, and JSON
10
- * helper glue live in core/helpers.js.
11
- */
12
-
13
-
14
- /**
15
- * CarbonEngineJS-facing GR2 reader.
16
- *
17
- * The Cjs prefix marks this as a JavaScript format/construction boundary. It
18
- * can emit plain GR2 JSON data or hydrate caller-supplied CarbonEngineJS-style
19
- * classes without pretending those classes are the engine runtime itself.
20
- */
21
- class CjsFormatGr2 {
22
- #emit = DEFAULT_VALUES.emit;
23
- #decompressCurves = DEFAULT_VALUES.decompressCurves;
24
- #unpackTangents = DEFAULT_VALUES.unpackTangents;
25
- #rebuildMissingNormals = DEFAULT_VALUES.rebuildMissingNormals;
26
- #rebuildMissingTangents = DEFAULT_VALUES.rebuildMissingTangents;
27
- #rebuildMissingBiNormals = DEFAULT_VALUES.rebuildMissingBiNormals;
28
- #classes = {};
29
-
30
- /**
31
- * Create a reusable format profile.
32
- *
33
- * @param {object} [options] Default format/build values.
34
- */
35
- constructor(options = {}) {
36
- this.SetValues(options);
37
- }
38
-
39
- /**
40
- * Set format values for this reusable profile.
41
- *
42
- * @param {object} [options] Values to merge into the profile.
43
- * @returns {CjsFormatGr2} This format profile.
44
- */
45
- SetValues(options = {}) {
46
- const values = normalizeValues(this.GetValues(), options);
47
- this.#emit = values.emit;
48
- this.#decompressCurves = values.decompressCurves;
49
- this.#unpackTangents = values.unpackTangents;
50
- this.#rebuildMissingNormals = values.rebuildMissingNormals;
51
- this.#rebuildMissingTangents = values.rebuildMissingTangents;
52
- this.#rebuildMissingBiNormals = values.rebuildMissingBiNormals;
53
- this.#classes = values.classes;
54
- return this;
55
- }
56
-
57
- /**
58
- * Get this profile's current values, optionally with per-call overrides.
59
- *
60
- * @param {object} [options] Optional values to merge into a copy.
61
- * @returns {object} A copy of the effective values.
62
- */
63
- GetValues(options = {}) {
64
- return normalizeValues({
65
- emit: this.#emit,
66
- decompressCurves: this.#decompressCurves,
67
- unpackTangents: this.#unpackTangents,
68
- rebuildMissingNormals: this.#rebuildMissingNormals,
69
- rebuildMissingTangents: this.#rebuildMissingTangents,
70
- rebuildMissingBiNormals: this.#rebuildMissingBiNormals,
71
- classes: this.#classes
72
- }, options);
73
- }
74
-
75
- /**
76
- * Set multiple GR2 JSON node constructors for this profile.
77
- *
78
- * @param {object} [classes] Map of node class keys to constructors.
79
- * @returns {CjsFormatGr2} This format profile.
80
- */
81
- SetClasses(classes = {}) {
82
- return this.SetValues({
83
- classes
84
- });
85
- }
86
-
87
- /**
88
- * Set a GR2 JSON node constructor for this profile.
89
- *
90
- * @param {string} type Node class key.
91
- * @param {Function|null|undefined} Class Constructor to use, or nullish to delete.
92
- * @returns {CjsFormatGr2} This format profile.
93
- */
94
- SetClass(type, Class) {
95
- validateClassKey(type);
96
- if (Class === null || Class === undefined) {
97
- delete this.#classes[type];
98
- return this;
99
- }
100
- validateClass(type, Class);
101
- this.#classes = {
102
- ...this.#classes,
103
- [type]: Class
104
- };
105
- return this;
106
- }
107
-
108
- /**
109
- * Get a configured GR2 JSON node constructor.
110
- *
111
- * @param {string} type Node class key.
112
- * @returns {Function|undefined}
113
- */
114
- GetClass(type) {
115
- validateClassKey(type);
116
- return this.#classes[type];
117
- }
118
-
119
- /**
120
- * Whether this reader has a constructor for a GR2 JSON node key.
121
- *
122
- * @param {string} type Node class key.
123
- * @returns {boolean}
124
- */
125
- HasClass(type) {
126
- return !!this.GetClass(type);
127
- }
128
-
129
- /**
130
- * Parse a .gr2 buffer and return JSON by default, classes when configured,
131
- * or raw reflection data when `emit` is "raw".
132
- *
133
- * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.
134
- * @param {object} [options] Per-call values.
135
- * @returns {object}
136
- */
137
- Read(input, options = {}) {
138
- return readWithValues(this, input, this.GetValues(options));
139
- }
140
-
141
- /**
142
- * Parse a .gr2 buffer into the reflected Granny object graph.
143
- *
144
- * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.
145
- * @returns {object}
146
- */
147
- ReadRaw(input) {
148
- return readRawInput(input);
149
- }
150
-
151
- /**
152
- * Return a stable, lightweight summary for a GR2 buffer or raw result.
153
- *
154
- * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.
155
- * @returns {object}
156
- */
157
- Inspect(input) {
158
- return inspectRawGr2Result(this.ReadRaw(input));
159
- }
160
-
161
- /** Whether input is a Granny State document carried by the GR2 container. */
162
- IsGSF(input) {
163
- return isGsfRaw(this.ReadRaw(input));
164
- }
165
-
166
- /** Read the GState semantic projection, or raw reflected data with `emit: "raw"`. */
167
- ReadGSF(input, options = {}) {
168
- const raw = this.ReadRaw(input);
169
- return options.emit === "raw" ? raw : projectGsf(raw);
170
- }
171
-
172
- /** Inspect a GSF document and its referenced GR2 animations. */
173
- InspectGSF(input) {
174
- return inspectGsfRaw(this.ReadRaw(input));
175
- }
176
-
177
- /**
178
- * Convert format output to plain JSON-compatible data.
179
- *
180
- * @param {object} value Format output to convert.
181
- * @returns {any} Plain JSON-compatible data.
182
- */
183
- ToJSON(value) {
184
- return toJsonValue(value);
185
- }
186
-
187
- /**
188
- * Static one-shot read. Static methods use camelCase by convention.
189
- *
190
- * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.
191
- * @param {object} [options] Reader and post-processing values.
192
- * @returns {object}
193
- */
194
- static read(input, options = {}) {
195
- return readWithValues(CjsFormatGr2, input, normalizeValues(DEFAULT_VALUES, options));
196
- }
197
-
198
- /**
199
- * Static one-shot raw read.
200
- *
201
- * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.
202
- * @returns {object}
203
- */
204
- static readRaw(input) {
205
- return readRawInput(input);
206
- }
207
-
208
- /**
209
- * Static one-shot inspection.
210
- *
211
- * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.
212
- * @returns {object}
213
- */
214
- static inspect(input) {
215
- return inspectRawGr2Result(readRawInput(input));
216
- }
217
-
218
- /** Whether input is a Granny State document carried by the GR2 container. */
219
- static isGsf(input) {
220
- try {
221
- return isGsfRaw(readRawInput(input));
222
- } catch {
223
- return false;
224
- }
225
- }
226
-
227
- /** Read the GState semantic projection, or raw reflected data with `emit: "raw"`. */
228
- static readGsf(input, options = {}) {
229
- const raw = readRawInput(input);
230
- return options.emit === "raw" ? raw : projectGsf(raw);
231
- }
232
-
233
- /** Async one-shot GSF read for standard format API compatibility. */
234
- static readGsfAsync(input, options = {}) {
235
- return Promise.resolve(this.readGsf(input, options));
236
- }
237
-
238
- /** Inspect a GSF document and its referenced GR2 animations. */
239
- static inspectGsf(input) {
240
- return inspectGsfRaw(readRawInput(input));
241
- }
242
-
243
- /**
244
- * Static JSON-compatible conversion.
245
- *
246
- * @param {object} value Format output to convert.
247
- * @returns {any} Plain JSON-compatible data.
248
- */
249
- static toJSON(value) {
250
- return toJsonValue(value);
251
- }
252
- static OUTPUT_JSON = OUTPUT_JSON;
253
- static OUTPUT_GR2 = OUTPUT_GR2;
254
- static OUTPUT_GR2_JSON = OUTPUT_GR2_JSON;
255
- static OUTPUT_CMF = OUTPUT_CMF;
256
- static OUTPUT_RAW = OUTPUT_RAW;
257
- static CLASS_KEYS = CLASS_KEYS;
258
- static type = Object.freeze(["geometry"]);
259
- static mediaTypes = Object.freeze(["geometry"]);
260
- static inputTypes = Object.freeze(["gr2", "gsf"]);
261
- static outputTypes = Object.freeze([OUTPUT_GR2, OUTPUT_CMF]);
262
- static debugOutputTypes = Object.freeze([OUTPUT_JSON, OUTPUT_GR2_JSON, OUTPUT_RAW]);
263
- static curves = curves;
264
- static tangents = tangents;
265
- static gsf = Object.freeze({
266
- isRaw: isGsfRaw,
267
- project: projectGsf,
268
- inspectRaw: inspectGsfRaw
269
- });
270
- }
271
-
272
- export { CjsFormatGr2 };
273
- //# sourceMappingURL=CjsFormatGr2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CjsFormatGr2.js","sources":["../../../../../src/formats/gr2/core/CjsFormatGr2.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing GR2 format class.\n *\n * Keep this file small and reviewable: parsing, conversion, rebuild, and JSON\n * helper glue live in core/helpers.js.\n */\n\nimport { curves } from \"./curves.js\";\nimport { tangents } from \"./tangents.js\";\nimport { inspectGsfRaw, isGsfRaw, projectGsf } from \"./gsf.js\";\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_CMF,\n OUTPUT_GR2,\n OUTPUT_GR2_JSON,\n OUTPUT_JSON,\n OUTPUT_RAW,\n inspectRawGr2Result,\n normalizeValues,\n readRawInput,\n readWithValues,\n toJsonValue,\n validateClass,\n validateClassKey\n} from \"./helpers.js\";\n\n/**\n * CarbonEngineJS-facing GR2 reader.\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary. It\n * can emit plain GR2 JSON data or hydrate caller-supplied CarbonEngineJS-style\n * classes without pretending those classes are the engine runtime itself.\n */\nexport class CjsFormatGr2\n{\n\n #emit = DEFAULT_VALUES.emit;\n #decompressCurves = DEFAULT_VALUES.decompressCurves;\n #unpackTangents = DEFAULT_VALUES.unpackTangents;\n #rebuildMissingNormals = DEFAULT_VALUES.rebuildMissingNormals;\n #rebuildMissingTangents = DEFAULT_VALUES.rebuildMissingTangents;\n #rebuildMissingBiNormals = DEFAULT_VALUES.rebuildMissingBiNormals;\n #classes = {};\n\n /**\n * Create a reusable format profile.\n *\n * @param {object} [options] Default format/build values.\n */\n constructor(options = {})\n {\n this.SetValues(options);\n }\n\n /**\n * Set format values for this reusable profile.\n *\n * @param {object} [options] Values to merge into the profile.\n * @returns {CjsFormatGr2} This format profile.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options);\n\n this.#emit = values.emit;\n this.#decompressCurves = values.decompressCurves;\n this.#unpackTangents = values.unpackTangents;\n this.#rebuildMissingNormals = values.rebuildMissingNormals;\n this.#rebuildMissingTangents = values.rebuildMissingTangents;\n this.#rebuildMissingBiNormals = values.rebuildMissingBiNormals;\n this.#classes = values.classes;\n\n return this;\n }\n\n /**\n * Get this profile's current values, optionally with per-call overrides.\n *\n * @param {object} [options] Optional values to merge into a copy.\n * @returns {object} A copy of the effective values.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n decompressCurves: this.#decompressCurves,\n unpackTangents: this.#unpackTangents,\n rebuildMissingNormals: this.#rebuildMissingNormals,\n rebuildMissingTangents: this.#rebuildMissingTangents,\n rebuildMissingBiNormals: this.#rebuildMissingBiNormals,\n classes: this.#classes\n }, options);\n }\n\n /**\n * Set multiple GR2 JSON node constructors for this profile.\n *\n * @param {object} [classes] Map of node class keys to constructors.\n * @returns {CjsFormatGr2} This format profile.\n */\n SetClasses(classes = {})\n {\n return this.SetValues({ classes });\n }\n\n /**\n * Set a GR2 JSON node constructor for this profile.\n *\n * @param {string} type Node class key.\n * @param {Function|null|undefined} Class Constructor to use, or nullish to delete.\n * @returns {CjsFormatGr2} This format profile.\n */\n SetClass(type, Class)\n {\n validateClassKey(type);\n if (Class === null || Class === undefined)\n {\n delete this.#classes[type];\n return this;\n }\n\n validateClass(type, Class);\n this.#classes = { ...this.#classes, [type]: Class };\n return this;\n }\n\n /**\n * Get a configured GR2 JSON node constructor.\n *\n * @param {string} type Node class key.\n * @returns {Function|undefined}\n */\n GetClass(type)\n {\n validateClassKey(type);\n return this.#classes[type];\n }\n\n /**\n * Whether this reader has a constructor for a GR2 JSON node key.\n *\n * @param {string} type Node class key.\n * @returns {boolean}\n */\n HasClass(type)\n {\n return !!this.GetClass(type);\n }\n\n /**\n * Parse a .gr2 buffer and return JSON by default, classes when configured,\n * or raw reflection data when `emit` is \"raw\".\n *\n * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.\n * @param {object} [options] Per-call values.\n * @returns {object}\n */\n Read(input, options = {})\n {\n return readWithValues(this, input, this.GetValues(options));\n }\n\n /**\n * Parse a .gr2 buffer into the reflected Granny object graph.\n *\n * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.\n * @returns {object}\n */\n ReadRaw(input)\n {\n return readRawInput(input);\n }\n\n /**\n * Return a stable, lightweight summary for a GR2 buffer or raw result.\n *\n * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.\n * @returns {object}\n */\n Inspect(input)\n {\n return inspectRawGr2Result(this.ReadRaw(input));\n }\n\n /** Whether input is a Granny State document carried by the GR2 container. */\n IsGSF(input)\n {\n return isGsfRaw(this.ReadRaw(input));\n }\n\n /** Read the GState semantic projection, or raw reflected data with `emit: \"raw\"`. */\n ReadGSF(input, options = {})\n {\n const raw = this.ReadRaw(input);\n return options.emit === \"raw\" ? raw : projectGsf(raw);\n }\n\n /** Inspect a GSF document and its referenced GR2 animations. */\n InspectGSF(input)\n {\n return inspectGsfRaw(this.ReadRaw(input));\n }\n\n /**\n * Convert format output to plain JSON-compatible data.\n *\n * @param {object} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n ToJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Static one-shot read. Static methods use camelCase by convention.\n *\n * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.\n * @param {object} [options] Reader and post-processing values.\n * @returns {object}\n */\n static read(input, options = {})\n {\n return readWithValues(CjsFormatGr2, input, normalizeValues(DEFAULT_VALUES, options));\n }\n\n /**\n * Static one-shot raw read.\n *\n * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.\n * @returns {object}\n */\n static readRaw(input)\n {\n return readRawInput(input);\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {Uint8Array|Buffer|object} input Raw .gr2 bytes or an existing raw read result.\n * @returns {object}\n */\n static inspect(input)\n {\n return inspectRawGr2Result(readRawInput(input));\n }\n\n /** Whether input is a Granny State document carried by the GR2 container. */\n static isGsf(input)\n {\n try\n {\n return isGsfRaw(readRawInput(input));\n }\n catch\n {\n return false;\n }\n }\n\n /** Read the GState semantic projection, or raw reflected data with `emit: \"raw\"`. */\n static readGsf(input, options = {})\n {\n const raw = readRawInput(input);\n return options.emit === \"raw\" ? raw : projectGsf(raw);\n }\n\n /** Async one-shot GSF read for standard format API compatibility. */\n static readGsfAsync(input, options = {})\n {\n return Promise.resolve(this.readGsf(input, options));\n }\n\n /** Inspect a GSF document and its referenced GR2 animations. */\n static inspectGsf(input)\n {\n return inspectGsfRaw(readRawInput(input));\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {object} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n static toJSON(value)\n {\n return toJsonValue(value);\n }\n\n static OUTPUT_JSON = OUTPUT_JSON;\n static OUTPUT_GR2 = OUTPUT_GR2;\n static OUTPUT_GR2_JSON = OUTPUT_GR2_JSON;\n static OUTPUT_CMF = OUTPUT_CMF;\n static OUTPUT_RAW = OUTPUT_RAW;\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"geometry\" ]);\n static mediaTypes = Object.freeze([ \"geometry\" ]);\n static inputTypes = Object.freeze([ \"gr2\", \"gsf\" ]);\n static outputTypes = Object.freeze([ OUTPUT_GR2, OUTPUT_CMF ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_GR2_JSON, OUTPUT_RAW ]);\n static curves = curves;\n static tangents = tangents;\n static gsf = Object.freeze({ isRaw: isGsfRaw, project: projectGsf, inspectRaw: inspectGsfRaw });\n\n}\n\nexport default CjsFormatGr2;\n"],"names":["CjsFormatGr2","DEFAULT_VALUES","emit","decompressCurves","unpackTangents","rebuildMissingNormals","rebuildMissingTangents","rebuildMissingBiNormals","constructor","options","SetValues","values","normalizeValues","GetValues","classes","SetClasses","SetClass","type","Class","validateClassKey","undefined","validateClass","GetClass","HasClass","Read","input","readWithValues","ReadRaw","readRawInput","Inspect","inspectRawGr2Result","IsGSF","isGsfRaw","ReadGSF","raw","projectGsf","InspectGSF","inspectGsfRaw","ToJSON","value","toJsonValue","read","readRaw","inspect","isGsf","readGsf","readGsfAsync","Promise","resolve","inspectGsf","toJSON","OUTPUT_JSON","OUTPUT_GR2","OUTPUT_GR2_JSON","OUTPUT_CMF","OUTPUT_RAW","CLASS_KEYS","Object","freeze","mediaTypes","inputTypes","outputTypes","debugOutputTypes","curves","tangents","gsf","isRaw","project","inspectRaw"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,CACzB;AAEI,EAAA,KAAK,GAAGC,cAAc,CAACC,IAAI;AAC3B,EAAA,iBAAiB,GAAGD,cAAc,CAACE,gBAAgB;AACnD,EAAA,eAAe,GAAGF,cAAc,CAACG,cAAc;AAC/C,EAAA,sBAAsB,GAAGH,cAAc,CAACI,qBAAqB;AAC7D,EAAA,uBAAuB,GAAGJ,cAAc,CAACK,sBAAsB;AAC/D,EAAA,wBAAwB,GAAGL,cAAc,CAACM,uBAAuB;EACjE,QAAQ,GAAG,EAAE;;AAEb;AACJ;AACA;AACA;AACA;AACIC,EAAAA,WAAWA,CAACC,OAAO,GAAG,EAAE,EACxB;AACI,IAAA,IAAI,CAACC,SAAS,CAACD,OAAO,CAAC;AAC3B,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACIC,EAAAA,SAASA,CAACD,OAAO,GAAG,EAAE,EACtB;IACI,MAAME,MAAM,GAAGC,eAAe,CAAC,IAAI,CAACC,SAAS,EAAE,EAAEJ,OAAO,CAAC;AAEzD,IAAA,IAAI,CAAC,KAAK,GAAGE,MAAM,CAACT,IAAI;AACxB,IAAA,IAAI,CAAC,iBAAiB,GAAGS,MAAM,CAACR,gBAAgB;AAChD,IAAA,IAAI,CAAC,eAAe,GAAGQ,MAAM,CAACP,cAAc;AAC5C,IAAA,IAAI,CAAC,sBAAsB,GAAGO,MAAM,CAACN,qBAAqB;AAC1D,IAAA,IAAI,CAAC,uBAAuB,GAAGM,MAAM,CAACL,sBAAsB;AAC5D,IAAA,IAAI,CAAC,wBAAwB,GAAGK,MAAM,CAACJ,uBAAuB;AAC9D,IAAA,IAAI,CAAC,QAA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