@carbonenginejs/runtime-resource 0.12.2 → 0.14.0
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.
- package/README.md +21 -0
- package/dist/CjsResMan.js +393 -29
- package/dist/CjsResMan.js.map +1 -1
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js +165 -118
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -1
- package/dist/format/carbonEffect/buildCarbonEffectContainer.js +182 -0
- package/dist/format/carbonEffect/buildCarbonEffectContainer.js.map +1 -0
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js +7 -113
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectRecords.js +258 -66
- package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectResourceTransform.js +197 -0
- package/dist/format/carbonEffect/carbonEffectResourceTransform.js.map +1 -0
- package/dist/format/effect/effectBodyInventory.js +146 -0
- package/dist/format/effect/effectBodyInventory.js.map +1 -0
- package/dist/format/effect/effectPermutationGraph.js +13 -13
- package/dist/format/effect/effectPermutationGraph.js.map +1 -1
- package/dist/format/index.js +4 -4
- package/dist/formats/black/CjsBlackFormat.js +19 -1
- package/dist/formats/black/CjsBlackFormat.js.map +1 -1
- package/dist/formats/bnk/CjsBnkFormat.js +28 -9
- package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
- package/dist/formats/bnk/core/busNodes.js +252 -0
- package/dist/formats/bnk/core/busNodes.js.map +1 -0
- package/dist/formats/bnk/core/effectNodes.js +147 -0
- package/dist/formats/bnk/core/effectNodes.js.map +1 -0
- package/dist/formats/bnk/core/eventAction.js +135 -24
- package/dist/formats/bnk/core/eventAction.js.map +1 -1
- package/dist/formats/bnk/core/globalSettings.js +215 -0
- package/dist/formats/bnk/core/globalSettings.js.map +1 -0
- package/dist/formats/bnk/core/helpers.js +37 -5
- package/dist/formats/bnk/core/helpers.js.map +1 -1
- package/dist/formats/bnk/core/musicNodes.js +43 -19
- package/dist/formats/bnk/core/musicNodes.js.map +1 -1
- package/dist/formats/bnk/core/nodeBase.js +28 -7
- package/dist/formats/bnk/core/nodeBase.js.map +1 -1
- package/dist/formats/dds/core/helpers.js +40 -1
- package/dist/formats/dds/core/helpers.js.map +1 -1
- package/dist/formats/dxbc/CjsDxbcFormat.js +45 -0
- package/dist/formats/dxbc/CjsDxbcFormat.js.map +1 -1
- package/dist/formats/dxbc/core/disassemble.js +240 -0
- package/dist/formats/dxbc/core/disassemble.js.map +1 -0
- package/dist/formats/gltf/CjsGltfFormat.js +1 -39
- package/dist/formats/gltf/CjsGltfFormat.js.map +1 -1
- package/dist/formats/gltf/core/helpers.js +1 -21
- package/dist/formats/gltf/core/helpers.js.map +1 -1
- package/dist/formats/hlsl/CjsHlslFormat.js +0 -21
- package/dist/formats/hlsl/CjsHlslFormat.js.map +1 -1
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +118 -49
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -1
- package/dist/formats/hlsl/core/detailMapFamily.js +128 -0
- package/dist/formats/hlsl/core/detailMapFamily.js.map +1 -0
- package/dist/formats/hlsl/core/localLightFamily.js +133 -0
- package/dist/formats/hlsl/core/localLightFamily.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +79 -73
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +8 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js.map +1 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js +11 -691
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js.map +1 -1
- package/dist/formats/index.js +4 -2
- package/dist/formats/index.js.map +1 -1
- package/dist/formats/obj/CjsObjFormat.js +1 -22
- package/dist/formats/obj/CjsObjFormat.js.map +1 -1
- package/dist/formats/obj/core/helpers.js +1 -21
- package/dist/formats/obj/core/helpers.js.map +1 -1
- package/dist/formats/pickle/CjsPickleFormat.js +214 -0
- package/dist/formats/pickle/CjsPickleFormat.js.map +1 -0
- package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js +551 -0
- package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js.map +1 -0
- package/dist/formats/pickle/index.js +2 -0
- package/dist/formats/pickle/index.js.map +1 -0
- package/dist/formats/red/core/redGraph.js +11 -8
- package/dist/formats/red/core/redGraph.js.map +1 -1
- package/dist/formats/stl/CjsStlFormat.js +1 -46
- package/dist/formats/stl/CjsStlFormat.js.map +1 -1
- package/dist/formats/stl/core/helpers.js +1 -21
- package/dist/formats/stl/core/helpers.js.map +1 -1
- package/dist/formats/webgl/CjsWebglFormat.js +33 -55
- package/dist/formats/webgl/CjsWebglFormat.js.map +1 -1
- package/dist/formats/webgl/core/buildGlslEffectContainer.js +70 -0
- package/dist/formats/webgl/core/buildGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgl/core/effectPackage.js +216 -108
- package/dist/formats/webgl/core/effectPackage.js.map +1 -1
- package/dist/formats/webgl/core/errors.js +1 -1
- package/dist/formats/webgl/core/errors.js.map +1 -1
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +166 -24
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
- package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +63 -5
- package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -1
- package/dist/formats/webgl/core/glsl/packedLightFixups.js +98 -0
- package/dist/formats/webgl/core/glsl/packedLightFixups.js.map +1 -0
- package/dist/formats/webgl/core/glslBackendBlock.js +552 -0
- package/dist/formats/webgl/core/glslBackendBlock.js.map +1 -0
- package/dist/formats/webgl/core/glslBackendBodySet.js +243 -0
- package/dist/formats/webgl/core/glslBackendBodySet.js.map +1 -0
- package/dist/formats/webgl/core/{cewgCompleteness.js → glslEffectCompleteness.js} +12 -8
- package/dist/formats/webgl/core/glslEffectCompleteness.js.map +1 -0
- package/dist/formats/webgl/core/helpers.js +33 -172
- package/dist/formats/webgl/core/helpers.js.map +1 -1
- package/dist/formats/webgl/core/inspectGlslEffectContainer.js +122 -0
- package/dist/formats/webgl/core/inspectGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgl/core/readGlslEffectContainer.js +249 -0
- package/dist/formats/webgl/core/readGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgpu/CjsWebgpuFormat.js +15 -15
- package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +37 -145
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -1
- package/dist/formats/webgpu/core/{cewgpu/CewgpuContainer.js → carbonWebgpu/CarbonWebgpuContainer.js} +13 -27
- package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js.map +1 -0
- package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/containerViews.js +1 -1
- package/dist/formats/webgpu/core/carbonWebgpu/containerViews.js.map +1 -0
- package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/validateContainer.js +4 -4
- package/dist/formats/webgpu/core/carbonWebgpu/validateContainer.js.map +1 -0
- package/dist/formats/webgpu/core/effectBackendBodySet.js +18 -18
- package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
- package/dist/formats/webgpu/core/errors.js +1 -1
- package/dist/formats/webgpu/core/errors.js.map +1 -1
- package/dist/formats/webgpu/core/helpers.js +22 -22
- package/dist/formats/webgpu/core/helpers.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffect.js +11 -15
- package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffectSelection.js +1 -1
- package/dist/formats/webgpu/core/packageEffectSelection.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +23 -23
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +6 -6
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
- package/dist/formats/yaml/CjsYamlFormat.js +3 -3
- package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
- package/dist/formats/yaml/core/CjsYamlReader.js +4 -6
- package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
- package/dist/formats/yaml/core/helpers.js +27 -1
- package/dist/formats/yaml/core/helpers.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/resource/CjsLoadingObject.js +19 -0
- package/dist/resource/CjsLoadingObject.js.map +1 -0
- package/dist/resource/CjsResource.js +4 -0
- package/dist/resource/CjsResource.js.map +1 -1
- package/dist/resource/ResourceHandlerMode.js +14 -0
- package/dist/resource/ResourceHandlerMode.js.map +1 -0
- package/dist/resource/index.js +2 -0
- package/dist/resource/index.js.map +1 -1
- package/dist/resource/shader/Tr2EffectRes.js +118 -213
- package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
- package/dist/resource/shader/Tr2Shader.js +37 -15
- package/dist/resource/shader/Tr2Shader.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectConstant.js +37 -29
- package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDescription.js +39 -34
- package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js +51 -30
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +45 -25
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectResource.js +51 -17
- package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js +219 -88
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js +28 -18
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2Pass.js +96 -39
- package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
- package/dist/resource/shader/reflection/carbonRecordFields.js +159 -0
- package/dist/resource/shader/reflection/carbonRecordFields.js.map +1 -0
- package/dist/resource/shader/reflection/shaderStage.js +22 -0
- package/dist/resource/shader/reflection/shaderStage.js.map +1 -0
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js +68 -10
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
- package/dist/worker/CjsResManMainThreadLoader.js +9 -7
- package/dist/worker/CjsResManMainThreadLoader.js.map +1 -1
- package/dist/worker/CjsResManWorker.js +5 -4
- package/dist/worker/CjsResManWorker.js.map +1 -1
- package/dist/worker/CjsResManWorkerLoader.js +9 -6
- package/dist/worker/CjsResManWorkerLoader.js.map +1 -1
- package/docs/README.md +2 -2
- package/docs/architecture.md +12 -3
- package/docs/concepts/resource-lifecycle.md +9 -8
- package/docs/concepts/shader-resource-model.md +14 -17
- package/docs/concepts/writing-an-engine-adapter.md +1 -1
- package/docs/formats/README.md +4 -2
- package/docs/formats/carbon-effect-container.md +127 -26
- package/docs/formats/dxbc/architecture.md +1 -1
- package/docs/formats/dxbc/reference/api.md +28 -0
- package/docs/formats/hlsl/README.md +3 -3
- package/docs/formats/hlsl/architecture.md +8 -9
- package/docs/formats/hlsl/guides/hydrating-json-output.md +3 -5
- package/docs/formats/hlsl/guides/reading-effects.md +5 -1
- package/docs/formats/hlsl/reference/advanced-analysis.md +20 -25
- package/docs/formats/hlsl/reference/api.md +0 -7
- package/docs/formats/hlsl/reference/json-graph.md +1 -4
- package/docs/formats/pickle.md +82 -0
- package/docs/formats/webgl/README.md +71 -13
- package/docs/formats/webgl/architecture.md +16 -17
- package/docs/formats/webgl/carbon-constant-layouts.md +3 -3
- package/docs/formats/webgl/decl-io.md +3 -3
- package/docs/formats/webgl/memory-structured.md +27 -8
- package/docs/formats/webgl/texture-sample.md +1 -1
- package/docs/formats/webgpu/README.md +3 -3
- package/docs/formats/webgpu/architecture.md +5 -6
- package/docs/formats/webgpu/formats/{cewgpu.md → carbon-webgpu.md} +10 -11
- package/docs/formats/webgpu/guides/effect-packaging.md +6 -8
- package/docs/formats/webgpu/reference/api.md +11 -12
- package/docs/formats/webgpu/reference/wgsl-compatibility.md +11 -8
- package/docs/formats/wwise.md +63 -2
- package/docs/reference/classes/core.md +10 -0
- package/docs/reference/classes/formats.md +40 -48
- package/docs/reference/classes/resources.md +2 -2
- package/docs/reference/queues.md +88 -4
- package/docs/reference/workers.md +7 -0
- package/package.json +61 -61
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +0 -372
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +0 -1
- package/dist/format/effect/effectReflectionPackage.js +0 -636
- package/dist/format/effect/effectReflectionPackage.js.map +0 -1
- package/dist/formats/hlsl/core/HlslReader.js +0 -16
- package/dist/formats/hlsl/core/HlslReader.js.map +0 -1
- package/dist/formats/hlsl/core/portableReflection.js +0 -848
- package/dist/formats/hlsl/core/portableReflection.js.map +0 -1
- package/dist/formats/hlsl/portable.js +0 -2
- package/dist/formats/hlsl/portable.js.map +0 -1
- package/dist/formats/webgl/core/cewg/CewgPackage.js +0 -340
- package/dist/formats/webgl/core/cewg/CewgPackage.js.map +0 -1
- package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js +0 -104
- package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js.map +0 -1
- package/dist/formats/webgl/core/cewg/binary.js +0 -19
- package/dist/formats/webgl/core/cewg/binary.js.map +0 -1
- package/dist/formats/webgl/core/cewgCompleteness.js.map +0 -1
- package/dist/formats/webgl/core/effectPackageValidation.js +0 -331
- package/dist/formats/webgl/core/effectPackageValidation.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +0 -1
- package/dist/resource/shader/portable.js +0 -33
- package/dist/resource/shader/portable.js.map +0 -1
- package/docs/formats/hlsl/reference/portable-reflection.md +0 -141
- package/docs/formats/webgl/effect-reflection.md +0 -127
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CjsYamlFormat } from '../../yaml/CjsYamlFormat.js';
|
|
2
|
+
import { isYamlSourceInput, toYamlSourceText } from '../../yaml/core/helpers.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Keys added by authoring tools are prefixed with a double underscore and are
|
|
@@ -14,24 +15,26 @@ function isStrippedKey(key) {
|
|
|
14
15
|
/**
|
|
15
16
|
* Parses Red input into a plain object graph.
|
|
16
17
|
*
|
|
17
|
-
* Accepts an already-parsed object (returned as-is)
|
|
18
|
-
* anchors/aliases resolve to shared object identities, which
|
|
19
|
-
* to rebuild the Red reference graph.
|
|
18
|
+
* Accepts an already-parsed object (returned as-is), a YAML string, or strict
|
|
19
|
+
* UTF-8 bytes. YAML anchors/aliases resolve to shared object identities, which
|
|
20
|
+
* the reader uses to rebuild the Red reference graph.
|
|
20
21
|
*
|
|
21
|
-
* @param {unknown} input
|
|
22
|
+
* @param {unknown} input Parsed Red object, YAML string, or UTF-8 bytes.
|
|
22
23
|
* @param {object} [options] `options.parse(text)` overrides the built-in parser
|
|
23
24
|
* @param {string} [readerName]
|
|
24
25
|
* @returns {object} parsed Red object graph
|
|
25
26
|
*/
|
|
26
27
|
function parseRed(input, options = {}, readerName = "CjsRedFormat") {
|
|
27
|
-
if (input
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (isYamlSourceInput(input)) {
|
|
29
|
+
if (typeof options.parse === "function") {
|
|
30
|
+
return options.parse(toYamlSourceText(input, readerName));
|
|
31
|
+
}
|
|
30
32
|
return CjsYamlFormat.readRaw(input, {
|
|
31
33
|
tagPolicy: "reject"
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
|
|
36
|
+
if (input && typeof input === "object") return input;
|
|
37
|
+
throw new TypeError(`${readerName}: input must be a parsed Red object, YAML string, or byte buffer.`);
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redGraph.js","sources":["../../../../../src/formats/red/core/redGraph.js"],"sourcesContent":["import CjsYamlFormat from \"../../yaml/index.js\";\n\n/**\n * Keys added by authoring tools are prefixed with a double underscore and are\n * not part of the Red data. They can carry environment-specific information, so\n * they are stripped on every read and never emitted.\n * @param {string} key\n * @returns {boolean}\n */\nexport function isStrippedKey(key)\n{\n return typeof key === \"string\" && key.length > 1 && key[0] === \"_\" && key[1] === \"_\";\n}\n\n/**\n * Parses Red input into a plain object graph.\n *\n * Accepts an already-parsed object (returned as-is)
|
|
1
|
+
{"version":3,"file":"redGraph.js","sources":["../../../../../src/formats/red/core/redGraph.js"],"sourcesContent":["import CjsYamlFormat from \"../../yaml/index.js\";\nimport {\n isYamlSourceInput,\n toYamlSourceText\n} from \"../../yaml/core/helpers.js\";\n\n/**\n * Keys added by authoring tools are prefixed with a double underscore and are\n * not part of the Red data. They can carry environment-specific information, so\n * they are stripped on every read and never emitted.\n * @param {string} key\n * @returns {boolean}\n */\nexport function isStrippedKey(key)\n{\n return typeof key === \"string\" && key.length > 1 && key[0] === \"_\" && key[1] === \"_\";\n}\n\n/**\n * Parses Red input into a plain object graph.\n *\n * Accepts an already-parsed object (returned as-is), a YAML string, or strict\n * UTF-8 bytes. YAML anchors/aliases resolve to shared object identities, which\n * the reader uses to rebuild the Red reference graph.\n *\n * @param {unknown} input Parsed Red object, YAML string, or UTF-8 bytes.\n * @param {object} [options] `options.parse(text)` overrides the built-in parser\n * @param {string} [readerName]\n * @returns {object} parsed Red object graph\n */\nexport function parseRed(input, options = {}, readerName = \"CjsRedFormat\")\n{\n if (isYamlSourceInput(input))\n {\n if (typeof options.parse === \"function\")\n {\n return options.parse(toYamlSourceText(input, readerName));\n }\n return CjsYamlFormat.readRaw(input, { tagPolicy: \"reject\" });\n }\n\n if (input && typeof input === \"object\") return input;\n\n throw new TypeError(`${readerName}: input must be a parsed Red object, YAML string, or byte buffer.`);\n}\n\n/**\n * A \"typed table\" is Red's compact columnar encoding: a `structure` array of\n * `[name, typeCode, byteOffset]` columns plus an `items` array where each row\n * is one record aligned to those columns. Curve `keys`, effect `options`, and\n * `samplerOverrides` all use this shape.\n * @param {*} node\n * @returns {boolean}\n */\nexport function isTypedTable(node)\n{\n return Boolean(\n node &&\n typeof node === \"object\" &&\n !Array.isArray(node) &&\n Array.isArray(node.structure) &&\n Array.isArray(node.items)\n );\n}\n\n/**\n * Decodes a typed table into an array of row objects keyed by column name.\n * @param {object} node typed table (`{ structure, items }`)\n * @returns {Array<object>}\n */\nexport function decodeTypedTable(node)\n{\n const columns = node.structure.map(column => (Array.isArray(column) ? column[0] : column && column.name));\n\n return node.items.map(row =>\n {\n const record = {};\n const cells = Array.isArray(row) ? row : [ row ];\n for (let i = 0; i < columns.length; i++)\n {\n if (columns[i] === undefined || columns[i] === null) continue;\n record[columns[i]] = cells[i];\n }\n return record;\n });\n}\n\n/**\n * Red `structure` type codes (informational). The YAML export already carries\n * decoded JS values, so decoding keys on column names, not these codes.\n */\nexport const RED_TYPE_CODES = Object.freeze({\n 4: \"float32\",\n 5: \"string\",\n 8: \"uint8\",\n 9: \"uint16\",\n 10: \"uint32\"\n});\n"],"names":["isStrippedKey","key","length","parseRed","input","options","readerName","isYamlSourceInput","parse","toYamlSourceText","CjsYamlFormat","readRaw","tagPolicy","TypeError","isTypedTable","node","Boolean","Array","isArray","structure","items","decodeTypedTable","columns","map","column","name","row","record","cells","i","undefined"],"mappings":";;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAaA,CAACC,GAAG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,MAAM,IAAKP,KAAK,CAACC,OAAO,CAACM,MAAM,CAAC,GAAGA,MAAM,CAAC,CAAC,CAAC,GAAGA,MAAM,IAAIA,MAAM,CAACC,IAAK,CAAC;AAEzG,EAAA,OAAOV,IAAI,CAACK,KAAK,CAACG,GAAG,CAACG,GAAG,IACzB;IACI,MAAMC,MAAM,GAAG,EAAE;AACjB,IAAA,MAAMC,KAAK,GAAGX,KAAK,CAACC,OAAO,CAACQ,GAAG,CAAC,GAAGA,GAAG,GAAG,CAAEA,GAAG,CAAE;AAChD,IAAA,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGP,OAAO,CAACpB,MAAM,EAAE2B,CAAC,EAAE,EACvC;AACI,MAAA,IAAIP,OAAO,CAACO,CAAC,CAAC,KAAKC,SAAS,IAAIR,OAAO,CAACO,CAAC,CAAC,KAAK,IAAI,EAAE;MACrDF,MAAM,CAACL,OAAO,CAACO,CAAC,CAAC,CAAC,GAAGD,KAAK,CAACC,CAAC,CAAC;AACjC,IAAA;AACA,IAAA,OAAOF,MAAM;AACjB,EAAA,CAAC,CAAC;AACN;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_VALUES, normalizeValues, validateClassKey, validateClass, readWithValues, writeWithValues, inspectWithValues, toJsonValue,
|
|
1
|
+
import { DEFAULT_VALUES, normalizeValues, validateClassKey, validateClass, readWithValues, writeWithValues, inspectWithValues, toJsonValue, OUTPUT_CMF, OUTPUT_GR2, OUTPUT_SHARED, OUTPUT_STL_JSON, OUTPUT_JSON, CLASS_KEYS } from './core/helpers.js';
|
|
2
2
|
import { isStl, isBinaryStl } from './core/stl.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -278,51 +278,6 @@ class CjsStlFormat {
|
|
|
278
278
|
return toJsonValue(value);
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
/**
|
|
282
|
-
* Node-only convenience: reads an STL file from disk.
|
|
283
|
-
*
|
|
284
|
-
* @param {string} path Path to an STL file.
|
|
285
|
-
* @param {object} [options] Format values.
|
|
286
|
-
* @returns {Promise<object>} The shared CarbonEngineJS JSON mesh schema.
|
|
287
|
-
*/
|
|
288
|
-
static async readFile(path, options = {}) {
|
|
289
|
-
if (typeof path !== "string" || !path) {
|
|
290
|
-
throw new TypeError(`${FORMAT_NAME}: readFile path must be a non-empty string`);
|
|
291
|
-
}
|
|
292
|
-
const {
|
|
293
|
-
readFile
|
|
294
|
-
} = await importNodeModule("node:fs/promises");
|
|
295
|
-
const input = await readFile(path);
|
|
296
|
-
return CjsStlFormat.read(input, {
|
|
297
|
-
source: path,
|
|
298
|
-
...options
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Node-only convenience: writes an STL file to disk.
|
|
304
|
-
*
|
|
305
|
-
* The file is encoded entirely in memory before the Node-only filesystem
|
|
306
|
-
* write starts. Browser bundles do not include the filesystem module.
|
|
307
|
-
*
|
|
308
|
-
* @param {string} path Path to write.
|
|
309
|
-
* @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.
|
|
310
|
-
* @param {CjsStlFormatOptions} [options={}] Writer values.
|
|
311
|
-
* @returns {Promise<string>} The written path.
|
|
312
|
-
* @throws {TypeError|RangeError|Error} If the path, geometry, topology, or options are invalid, or writing fails.
|
|
313
|
-
*/
|
|
314
|
-
static async writeFile(path, input, options = {}) {
|
|
315
|
-
if (typeof path !== "string" || !path) {
|
|
316
|
-
throw new TypeError(`${FORMAT_NAME}: writeFile path must be a non-empty string`);
|
|
317
|
-
}
|
|
318
|
-
const {
|
|
319
|
-
writeFile
|
|
320
|
-
} = await importNodeModule("node:fs/promises");
|
|
321
|
-
const output = CjsStlFormat.write(input, options);
|
|
322
|
-
await writeFile(path, output);
|
|
323
|
-
return path;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
281
|
/**
|
|
327
282
|
* Cheap sniff for STL-like input.
|
|
328
283
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CjsStlFormat.js","sources":["../../../../src/formats/stl/CjsStlFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing STL format class.\n *\n * Keep this file small and reviewable: STL parsing, writing, printability\n * inspection, option normalization, and JSON hydration live under src/core.\n */\n\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_CMF,\n OUTPUT_GR2,\n OUTPUT_JSON,\n OUTPUT_SHARED,\n OUTPUT_STL_JSON,\n importNodeModule,\n inspectWithValues,\n isBinaryStl,\n isStl,\n normalizeValues,\n readWithValues,\n toJsonValue,\n validateClass,\n validateClassKey,\n writeWithValues\n} from \"./core/helpers.js\";\n\nconst FORMAT_NAME = \"CjsStlFormat\";\n\n/**\n * Shared mesh accepted by the STL writer. STL exports only `vertex.position`\n * and triangular `indices[].faces`; all other shared channels are ignored.\n *\n * @typedef {object} CjsStlSharedMesh\n * @property {string} [name] Diagnostic mesh name; `solidName` controls the STL header.\n * @property {{position: ArrayLike<number>, normal?: ArrayLike<number>}} vertex Shared vertex channels.\n * @property {Array<{name?: string, faces: ArrayLike<number>}>} indices Triangle index groups.\n */\n\n/**\n * Shared geometry root accepted by the STL writer.\n *\n * @typedef {object} CjsStlSharedRoot\n * @property {Array<CjsStlSharedMesh>} meshes Meshes flattened into one STL solid.\n * @property {string} [grannyFileSource] Optional source label used by inspection.\n */\n\n/**\n * Reusable STL read, write, and inspection options.\n *\n * @typedef {object} CjsStlFormatOptions\n * @property {\"shared\"|\"stlJson\"|\"json\"|\"gr2\"|\"cmf\"} [emit=\"stlJson\"] Read output contract.\n * @property {string} [source=\"memory\"] Source label stored in read/inspection output.\n * @property {boolean} [binary=true] Whether writes return binary bytes instead of ASCII text.\n * @property {string} [solidName=\"carbonenginejs\"] Sanitized ASCII solid name and binary header label.\n * @property {number} [scale=1] Positive finite multiplier applied to exported positions.\n * @property {boolean} [recalculateNormals=true] Derive facet normals from winding instead of vertex normals.\n * @property {boolean} [weldVertices=false] Weld equal positions while reading STL.\n * @property {number} [weldTolerance=1e-5] Non-negative read/inspection position tolerance.\n * @property {boolean} [skipDegenerate=true] Omit degenerate shared triangles during writes.\n * @property {boolean} [requireWatertight=false] Reject writes with printability topology issues.\n * @property {Record<string, Function>} [classes] Caller constructors used for read hydration.\n */\n\n/**\n * CarbonEngineJS-facing STL format surface.\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * STL is a triangle-only import/export format; the JSON contract is the shared\n * CarbonEngineJS mesh schema.\n */\nexport class CjsStlFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n #binary = DEFAULT_VALUES.binary;\n #solidName = DEFAULT_VALUES.solidName;\n #scale = DEFAULT_VALUES.scale;\n #recalculateNormals = DEFAULT_VALUES.recalculateNormals;\n #weldVertices = DEFAULT_VALUES.weldVertices;\n #weldTolerance = DEFAULT_VALUES.weldTolerance;\n #skipDegenerate = DEFAULT_VALUES.skipDegenerate;\n #requireWatertight = DEFAULT_VALUES.requireWatertight;\n #classes = DEFAULT_VALUES.classes;\n\n /**\n * Create a reusable format profile.\n *\n * The instance stores only normalized options; each `Read`, `Write`, or\n * `Inspect` call may provide non-mutating overrides.\n *\n * @param {CjsStlFormatOptions} [options={}] Default format values.\n * @throws {TypeError} If an option, output mode, numeric value, or class map is invalid.\n */\n constructor(options = {})\n {\n this.SetValues(options);\n }\n\n /**\n * Set format values for this reusable profile.\n *\n * @param {CjsStlFormatOptions} [options={}] Values to merge into the profile.\n * @returns {CjsStlFormat} This format profile.\n * @throws {TypeError} If an option, output mode, numeric value, or class map is invalid.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\n this.#binary = values.binary;\n this.#solidName = values.solidName;\n this.#scale = values.scale;\n this.#recalculateNormals = values.recalculateNormals;\n this.#weldVertices = values.weldVertices;\n this.#weldTolerance = values.weldTolerance;\n this.#skipDegenerate = values.skipDegenerate;\n this.#requireWatertight = values.requireWatertight;\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 {CjsStlFormatOptions} [options={}] Optional values to merge into a copy.\n * @returns {CjsStlFormatOptions} A validated copy of the effective values.\n * @throws {TypeError} If an override is invalid.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n source: this.#source,\n binary: this.#binary,\n solidName: this.#solidName,\n scale: this.#scale,\n recalculateNormals: this.#recalculateNormals,\n weldVertices: this.#weldVertices,\n weldTolerance: this.#weldTolerance,\n skipDegenerate: this.#skipDegenerate,\n requireWatertight: this.#requireWatertight,\n classes: this.#classes\n }, options, FORMAT_NAME);\n }\n\n /**\n * Set multiple node-class constructors for this profile.\n *\n * @param {object} [classes] Map of node class keys to constructors.\n * @returns {CjsStlFormat} This format profile.\n */\n SetClasses(classes = {})\n {\n return this.SetValues({ classes });\n }\n\n /**\n * Set one node-class 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 {CjsStlFormat} This format profile.\n */\n SetClass(type, Class)\n {\n if (Class === null || Class === undefined)\n {\n validateClassKey(type, FORMAT_NAME);\n const classes = { ...this.#classes };\n delete classes[type];\n this.#classes = classes;\n return this;\n }\n\n validateClass(type, Class, FORMAT_NAME);\n return this.SetValues({ classes: { [type]: Class } });\n }\n\n /**\n * Get a configured node-class constructor.\n *\n * @param {string} type Node class key.\n * @returns {Function|undefined} The registered constructor, if any.\n */\n GetClass(type)\n {\n validateClassKey(type, FORMAT_NAME);\n return this.#classes[type];\n }\n\n /**\n * Whether this format profile has a constructor registered for a node class key.\n *\n * @param {string} type Node class key.\n * @returns {boolean} True when a constructor is registered.\n */\n HasClass(type)\n {\n return !!this.GetClass(type);\n }\n\n /**\n * Read STL text/bytes with this profile's values.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} The shared CarbonEngineJS JSON mesh schema.\n */\n Read(input, options = {})\n {\n return readWithValues(this, input, this.GetValues(options));\n }\n\n /**\n * Write shared JSON geometry as STL with this profile's values.\n *\n * Multiple meshes and index groups are flattened in encounter order because\n * STL has no portable material or scene hierarchy. Degenerate triangles are\n * skipped by default. Binary output validates that every coordinate is\n * representable as float32 rather than silently writing infinities.\n *\n * @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.\n * @param {CjsStlFormatOptions} [options={}] Per-call writer overrides.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n * @throws {TypeError|RangeError|Error} If geometry, indices, coordinates, topology, or options are invalid.\n */\n Write(input, options = {})\n {\n return writeWithValues(input, this.GetValues(options));\n }\n\n /**\n * Inspect STL text/bytes or shared JSON geometry for printability blockers.\n *\n * @param {any} input STL text/bytes or shared JSON root/mesh.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain printability report.\n */\n Inspect(input, options = {})\n {\n return inspectWithValues(input, this.GetValues(options));\n }\n\n /**\n * Convert format output to JSON-compatible data.\n *\n * @param {any} 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 {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} [options] Format values.\n * @returns {object} The shared CarbonEngineJS JSON mesh schema.\n */\n static read(input, options = {})\n {\n return readWithValues(CjsStlFormat, input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot write.\n *\n * The call is one-shot and does not mutate `input`. Multiple meshes and\n * index groups are flattened into a single STL solid in encounter order.\n *\n * @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.\n * @param {CjsStlFormatOptions} [options={}] Writer values.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n * @throws {TypeError|RangeError|Error} If geometry, indices, coordinates, topology, or options are invalid.\n */\n static write(input, options = {})\n {\n return writeWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {any} input STL text/bytes or shared JSON root/mesh.\n * @param {object} [options] Format values.\n * @returns {object} Plain printability report.\n */\n static inspect(input, options = {})\n {\n return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} 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 /**\n * Node-only convenience: reads an STL file from disk.\n *\n * @param {string} path Path to an STL file.\n * @param {object} [options] Format values.\n * @returns {Promise<object>} The shared CarbonEngineJS JSON mesh schema.\n */\n static async readFile(path, options = {})\n {\n if (typeof path !== \"string\" || !path)\n {\n throw new TypeError(`${FORMAT_NAME}: readFile path must be a non-empty string`);\n }\n\n const { readFile } = await importNodeModule(\"node:fs/promises\");\n const input = await readFile(path);\n return CjsStlFormat.read(input, { source: path, ...options });\n }\n\n /**\n * Node-only convenience: writes an STL file to disk.\n *\n * The file is encoded entirely in memory before the Node-only filesystem\n * write starts. Browser bundles do not include the filesystem module.\n *\n * @param {string} path Path to write.\n * @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.\n * @param {CjsStlFormatOptions} [options={}] Writer values.\n * @returns {Promise<string>} The written path.\n * @throws {TypeError|RangeError|Error} If the path, geometry, topology, or options are invalid, or writing fails.\n */\n static async writeFile(path, input, options = {})\n {\n if (typeof path !== \"string\" || !path)\n {\n throw new TypeError(`${FORMAT_NAME}: writeFile path must be a non-empty string`);\n }\n\n const { writeFile } = await importNodeModule(\"node:fs/promises\");\n const output = CjsStlFormat.write(input, options);\n await writeFile(path, output);\n return path;\n }\n\n /**\n * Cheap sniff for STL-like input.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input Candidate STL input.\n * @returns {boolean} True when input looks like STL.\n */\n static isStl(input)\n {\n return isStl(input);\n }\n\n /**\n * Check whether byte-like input has an exact binary STL layout.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input Candidate STL input.\n * @returns {boolean} True when input is binary STL bytes.\n */\n static isBinaryStl(input)\n {\n return isBinaryStl(input);\n }\n\n /**\n * Emit targets for this format (canonical frozen enum).\n */\n static Output = Object.freeze({\n JSON: OUTPUT_JSON,\n STL_JSON: OUTPUT_STL_JSON,\n SHARED: OUTPUT_SHARED,\n GR2: OUTPUT_GR2,\n CMF: OUTPUT_CMF\n });\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"geometry\" ]);\n static mediaTypes = Object.freeze([ \"geometry\" ]);\n static inputTypes = Object.freeze([ \"stl\" ]);\n static outputTypes = Object.freeze([ OUTPUT_SHARED, OUTPUT_GR2, OUTPUT_CMF ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_STL_JSON ]);\n\n}\n\nexport default CjsStlFormat;\n"],"names":["FORMAT_NAME","CjsStlFormat","DEFAULT_VALUES","emit","source","binary","solidName","scale","recalculateNormals","weldVertices","weldTolerance","skipDegenerate","requireWatertight","classes","constructor","options","SetValues","values","normalizeValues","GetValues","SetClasses","SetClass","type","Class","undefined","validateClassKey","validateClass","GetClass","HasClass","Read","input","readWithValues","Write","writeWithValues","Inspect","inspectWithValues","ToJSON","value","toJsonValue","read","write","inspect","toJSON","readFile","path","TypeError","importNodeModule","writeFile","output","isStl","isBinaryStl","Output","Object","freeze","JSON","OUTPUT_JSON","STL_JSON","OUTPUT_STL_JSON","SHARED","OUTPUT_SHARED","GR2","OUTPUT_GR2","CMF","OUTPUT_CMF","CLASS_KEYS","mediaTypes","inputTypes","outputTypes","debugOutputTypes"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAsBA,MAAMA,WAAW,GAAG,cAAc;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AAC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OAAOmB,KAAK,CAACnB,KAAK,CAAC;AACvB,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;EACI,OAAOoB,WAAWA,CAACpB,KAAK,EACxB;IACI,OAAOoB,WAAW,CAACpB,KAAK,CAAC;AAC7B,EAAA;;AAEA;AACJ;AACA;AACI,EAAA,OAAOqB,MAAM,GAAGC,MAAM,CAACC,MAAM,CAAC;AAC1BC,IAAAA,IAAI,EAAEC,WAAW;AACjBC,IAAAA,QAAQ,EAAEC,eAAe;AACzBC,IAAAA,MAAM,EAAEC,aAAa;AACrBC,IAAAA,GAAG,EAAEC,UAAU;AACfC,IAAAA,GAAG,EAAEC;AACT,GAAC,CAAC;EACF,OAAOC,UAAU,GAAGA,UAAU;EAC9B,OAAO1C,IAAI,GAAG8B,MAAM,CAACC,MAAM,CAAC,CAAE,UAAU,CAAE,CAAC;EAC3C,OAAOY,UAAU,GAAGb,MAAM,CAACC,MAAM,CAAC,CAAE,UAAU,CAAE,CAAC;EACjD,OAAOa,UAAU,GAAGd,MAAM,CAACC,MAAM,CAAC,CAAE,KAAK,CAAE,CAAC;AAC5C,EAAA,OAAOc,WAAW,GAAGf,MAAM,CAACC,MAAM,CAAC,CAAEM,aAAa,EAAEE,UAAU,EAAEE,UAAU,CAAE,CAAC;EAC7E,OAAOK,gBAAgB,GAAGhB,MAAM,CAACC,MAAM,CAAC,CAAEE,WAAW,EAAEE,eAAe,CAAE,CAAC;AAE7E;;;;"}
|
|
1
|
+
{"version":3,"file":"CjsStlFormat.js","sources":["../../../../src/formats/stl/CjsStlFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing STL format class.\n *\n * Keep this file small and reviewable: STL parsing, writing, printability\n * inspection, option normalization, and JSON hydration live under src/core.\n */\n\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_CMF,\n OUTPUT_GR2,\n OUTPUT_JSON,\n OUTPUT_SHARED,\n OUTPUT_STL_JSON,\n inspectWithValues,\n isBinaryStl,\n isStl,\n normalizeValues,\n readWithValues,\n toJsonValue,\n validateClass,\n validateClassKey,\n writeWithValues\n} from \"./core/helpers.js\";\n\nconst FORMAT_NAME = \"CjsStlFormat\";\n\n/**\n * Shared mesh accepted by the STL writer. STL exports only `vertex.position`\n * and triangular `indices[].faces`; all other shared channels are ignored.\n *\n * @typedef {object} CjsStlSharedMesh\n * @property {string} [name] Diagnostic mesh name; `solidName` controls the STL header.\n * @property {{position: ArrayLike<number>, normal?: ArrayLike<number>}} vertex Shared vertex channels.\n * @property {Array<{name?: string, faces: ArrayLike<number>}>} indices Triangle index groups.\n */\n\n/**\n * Shared geometry root accepted by the STL writer.\n *\n * @typedef {object} CjsStlSharedRoot\n * @property {Array<CjsStlSharedMesh>} meshes Meshes flattened into one STL solid.\n * @property {string} [grannyFileSource] Optional source label used by inspection.\n */\n\n/**\n * Reusable STL read, write, and inspection options.\n *\n * @typedef {object} CjsStlFormatOptions\n * @property {\"shared\"|\"stlJson\"|\"json\"|\"gr2\"|\"cmf\"} [emit=\"stlJson\"] Read output contract.\n * @property {string} [source=\"memory\"] Source label stored in read/inspection output.\n * @property {boolean} [binary=true] Whether writes return binary bytes instead of ASCII text.\n * @property {string} [solidName=\"carbonenginejs\"] Sanitized ASCII solid name and binary header label.\n * @property {number} [scale=1] Positive finite multiplier applied to exported positions.\n * @property {boolean} [recalculateNormals=true] Derive facet normals from winding instead of vertex normals.\n * @property {boolean} [weldVertices=false] Weld equal positions while reading STL.\n * @property {number} [weldTolerance=1e-5] Non-negative read/inspection position tolerance.\n * @property {boolean} [skipDegenerate=true] Omit degenerate shared triangles during writes.\n * @property {boolean} [requireWatertight=false] Reject writes with printability topology issues.\n * @property {Record<string, Function>} [classes] Caller constructors used for read hydration.\n */\n\n/**\n * CarbonEngineJS-facing STL format surface.\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * STL is a triangle-only import/export format; the JSON contract is the shared\n * CarbonEngineJS mesh schema.\n */\nexport class CjsStlFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n #binary = DEFAULT_VALUES.binary;\n #solidName = DEFAULT_VALUES.solidName;\n #scale = DEFAULT_VALUES.scale;\n #recalculateNormals = DEFAULT_VALUES.recalculateNormals;\n #weldVertices = DEFAULT_VALUES.weldVertices;\n #weldTolerance = DEFAULT_VALUES.weldTolerance;\n #skipDegenerate = DEFAULT_VALUES.skipDegenerate;\n #requireWatertight = DEFAULT_VALUES.requireWatertight;\n #classes = DEFAULT_VALUES.classes;\n\n /**\n * Create a reusable format profile.\n *\n * The instance stores only normalized options; each `Read`, `Write`, or\n * `Inspect` call may provide non-mutating overrides.\n *\n * @param {CjsStlFormatOptions} [options={}] Default format values.\n * @throws {TypeError} If an option, output mode, numeric value, or class map is invalid.\n */\n constructor(options = {})\n {\n this.SetValues(options);\n }\n\n /**\n * Set format values for this reusable profile.\n *\n * @param {CjsStlFormatOptions} [options={}] Values to merge into the profile.\n * @returns {CjsStlFormat} This format profile.\n * @throws {TypeError} If an option, output mode, numeric value, or class map is invalid.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\n this.#binary = values.binary;\n this.#solidName = values.solidName;\n this.#scale = values.scale;\n this.#recalculateNormals = values.recalculateNormals;\n this.#weldVertices = values.weldVertices;\n this.#weldTolerance = values.weldTolerance;\n this.#skipDegenerate = values.skipDegenerate;\n this.#requireWatertight = values.requireWatertight;\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 {CjsStlFormatOptions} [options={}] Optional values to merge into a copy.\n * @returns {CjsStlFormatOptions} A validated copy of the effective values.\n * @throws {TypeError} If an override is invalid.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n source: this.#source,\n binary: this.#binary,\n solidName: this.#solidName,\n scale: this.#scale,\n recalculateNormals: this.#recalculateNormals,\n weldVertices: this.#weldVertices,\n weldTolerance: this.#weldTolerance,\n skipDegenerate: this.#skipDegenerate,\n requireWatertight: this.#requireWatertight,\n classes: this.#classes\n }, options, FORMAT_NAME);\n }\n\n /**\n * Set multiple node-class constructors for this profile.\n *\n * @param {object} [classes] Map of node class keys to constructors.\n * @returns {CjsStlFormat} This format profile.\n */\n SetClasses(classes = {})\n {\n return this.SetValues({ classes });\n }\n\n /**\n * Set one node-class 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 {CjsStlFormat} This format profile.\n */\n SetClass(type, Class)\n {\n if (Class === null || Class === undefined)\n {\n validateClassKey(type, FORMAT_NAME);\n const classes = { ...this.#classes };\n delete classes[type];\n this.#classes = classes;\n return this;\n }\n\n validateClass(type, Class, FORMAT_NAME);\n return this.SetValues({ classes: { [type]: Class } });\n }\n\n /**\n * Get a configured node-class constructor.\n *\n * @param {string} type Node class key.\n * @returns {Function|undefined} The registered constructor, if any.\n */\n GetClass(type)\n {\n validateClassKey(type, FORMAT_NAME);\n return this.#classes[type];\n }\n\n /**\n * Whether this format profile has a constructor registered for a node class key.\n *\n * @param {string} type Node class key.\n * @returns {boolean} True when a constructor is registered.\n */\n HasClass(type)\n {\n return !!this.GetClass(type);\n }\n\n /**\n * Read STL text/bytes with this profile's values.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} The shared CarbonEngineJS JSON mesh schema.\n */\n Read(input, options = {})\n {\n return readWithValues(this, input, this.GetValues(options));\n }\n\n /**\n * Write shared JSON geometry as STL with this profile's values.\n *\n * Multiple meshes and index groups are flattened in encounter order because\n * STL has no portable material or scene hierarchy. Degenerate triangles are\n * skipped by default. Binary output validates that every coordinate is\n * representable as float32 rather than silently writing infinities.\n *\n * @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.\n * @param {CjsStlFormatOptions} [options={}] Per-call writer overrides.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n * @throws {TypeError|RangeError|Error} If geometry, indices, coordinates, topology, or options are invalid.\n */\n Write(input, options = {})\n {\n return writeWithValues(input, this.GetValues(options));\n }\n\n /**\n * Inspect STL text/bytes or shared JSON geometry for printability blockers.\n *\n * @param {any} input STL text/bytes or shared JSON root/mesh.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain printability report.\n */\n Inspect(input, options = {})\n {\n return inspectWithValues(input, this.GetValues(options));\n }\n\n /**\n * Convert format output to JSON-compatible data.\n *\n * @param {any} 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 {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} [options] Format values.\n * @returns {object} The shared CarbonEngineJS JSON mesh schema.\n */\n static read(input, options = {})\n {\n return readWithValues(CjsStlFormat, input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot write.\n *\n * The call is one-shot and does not mutate `input`. Multiple meshes and\n * index groups are flattened into a single STL solid in encounter order.\n *\n * @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.\n * @param {CjsStlFormatOptions} [options={}] Writer values.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n * @throws {TypeError|RangeError|Error} If geometry, indices, coordinates, topology, or options are invalid.\n */\n static write(input, options = {})\n {\n return writeWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {any} input STL text/bytes or shared JSON root/mesh.\n * @param {object} [options] Format values.\n * @returns {object} Plain printability report.\n */\n static inspect(input, options = {})\n {\n return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} 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 /**\n * Cheap sniff for STL-like input.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input Candidate STL input.\n * @returns {boolean} True when input looks like STL.\n */\n static isStl(input)\n {\n return isStl(input);\n }\n\n /**\n * Check whether byte-like input has an exact binary STL layout.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input Candidate STL input.\n * @returns {boolean} True when input is binary STL bytes.\n */\n static isBinaryStl(input)\n {\n return isBinaryStl(input);\n }\n\n /**\n * Emit targets for this format (canonical frozen enum).\n */\n static Output = Object.freeze({\n JSON: OUTPUT_JSON,\n STL_JSON: OUTPUT_STL_JSON,\n SHARED: OUTPUT_SHARED,\n GR2: OUTPUT_GR2,\n CMF: OUTPUT_CMF\n });\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"geometry\" ]);\n static mediaTypes = Object.freeze([ \"geometry\" ]);\n static inputTypes = Object.freeze([ \"stl\" ]);\n static outputTypes = Object.freeze([ OUTPUT_SHARED, OUTPUT_GR2, OUTPUT_CMF ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_STL_JSON ]);\n\n}\n\nexport default CjsStlFormat;\n"],"names":["FORMAT_NAME","CjsStlFormat","DEFAULT_VALUES","emit","source","binary","solidName","scale","recalculateNormals","weldVertices","weldTolerance","skipDegenerate","requireWatertight","classes","constructor","options","SetValues","values","normalizeValues","GetValues","SetClasses","SetClass","type","Class","undefined","validateClassKey","validateClass","GetClass","HasClass","Read","input","readWithValues","Write","writeWithValues","Inspect","inspectWithValues","ToJSON","value","toJsonValue","read","write","inspect","toJSON","isStl","isBinaryStl","Output","Object","freeze","JSON","OUTPUT_JSON","STL_JSON","OUTPUT_STL_JSON","SHARED","OUTPUT_SHARED","GR2","OUTPUT_GR2","CMF","OUTPUT_CMF","CLASS_KEYS","mediaTypes","inputTypes","outputTypes","debugOutputTypes"],"mappings":";;;AAAA;AACA;AACA;AACA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
* Imports a Node built-in module without exposing the specifier to any
|
|
242
|
-
* bundler's static import graph.
|
|
243
|
-
*
|
|
244
|
-
* `await import("node:fs/promises")` written as a literal is resolved
|
|
245
|
-
* eagerly by webpack/Rollup/esbuild alike when they walk the module
|
|
246
|
-
* graph, breaking browser builds even though this path only ever runs
|
|
247
|
-
* under Node (readFile/writeFile are Node-only conveniences). Building
|
|
248
|
-
* the specifier inside a `Function` body hides it from every bundler's
|
|
249
|
-
* static analysis - it only exists at runtime, in the Node process that
|
|
250
|
-
* actually calls readFile/writeFile.
|
|
251
|
-
*
|
|
252
|
-
* @param {string} specifier Node built-in module specifier, e.g. "node:fs/promises".
|
|
253
|
-
* @returns {Promise<any>} The imported module namespace.
|
|
254
|
-
*/
|
|
255
|
-
function importNodeModule(specifier) {
|
|
256
|
-
// eslint-disable-next-line no-new-func
|
|
257
|
-
return new Function("s", "return import(s)")(specifier);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export { CLASS_KEYS, DEFAULT_VALUES, GR2_CLASS_KEYS, OUTPUT_CMF, OUTPUT_GR2, OUTPUT_JSON, OUTPUT_SHARED, OUTPUT_STL_JSON, importNodeModule, inspectWithValues, normalizeValues, readWithValues, toJsonValue, validateClass, validateClassKey, writeWithValues };
|
|
240
|
+
export { CLASS_KEYS, DEFAULT_VALUES, GR2_CLASS_KEYS, OUTPUT_CMF, OUTPUT_GR2, OUTPUT_JSON, OUTPUT_SHARED, OUTPUT_STL_JSON, inspectWithValues, normalizeValues, readWithValues, toJsonValue, validateClass, validateClassKey, writeWithValues };
|
|
261
241
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../../../../../src/formats/stl/core/helpers.js"],"sourcesContent":["/**\n * Internal pipeline glue for CjsStlFormat.\n */\n\nimport { hydrateJson } from \"./json.js\";\nimport { buildCmfFromShared, CMF_CLASS_KEYS, hydrateCmf } from \"./targets.js\";\nimport {\n inspectTriangles,\n isBinaryStl,\n isStl,\n jsonToTriangles,\n parseStl,\n toText,\n trianglesFromInput,\n trianglesToJson,\n writeAsciiStl,\n writeBinaryStl\n} from \"./stl.js\";\n\nexport const GR2_CLASS_KEYS = Object.freeze([\n \"Root\",\n \"Mesh\",\n \"BoneBinding\",\n \"IndexGroup\",\n \"MorphTarget\",\n \"Model\",\n \"Skeleton\",\n \"Bone\",\n \"Animation\",\n \"TrackGroup\",\n \"TransformTrack\",\n \"Curve\"\n]);\n\nexport const CLASS_KEYS = Object.freeze(Array.from(new Set([\n ...GR2_CLASS_KEYS,\n ...CMF_CLASS_KEYS\n])));\n\nexport { isBinaryStl, isStl, toText };\n\nexport const OUTPUT_JSON = \"json\";\nexport const OUTPUT_STL_JSON = \"stlJson\";\nexport const OUTPUT_SHARED = \"shared\";\nexport const OUTPUT_GR2 = \"gr2\";\nexport const OUTPUT_CMF = \"cmf\";\n\nexport const DEFAULT_VALUES = Object.freeze({\n emit: OUTPUT_STL_JSON,\n source: \"memory\",\n binary: true,\n solidName: \"carbonenginejs\",\n scale: 1,\n recalculateNormals: true,\n weldVertices: false,\n weldTolerance: 1e-5,\n skipDegenerate: true,\n requireWatertight: false,\n classes: Object.freeze({})\n});\n\nconst OPTION_KEYS = new Set([\n \"emit\",\n \"source\",\n \"binary\",\n \"solidName\",\n \"scale\",\n \"recalculateNormals\",\n \"weldVertices\",\n \"weldTolerance\",\n \"skipDegenerate\",\n \"requireWatertight\",\n \"classes\"\n]);\n\nfunction validateBoolean(name, value, readerName)\n{\n if (typeof value === \"boolean\") return value;\n throw new TypeError(`${readerName}: ${name} must be true or false`);\n}\n\nfunction validateNumber(name, value, readerName, { minExclusive = null, minInclusive = null } = {})\n{\n if (typeof value !== \"number\" || !Number.isFinite(value))\n {\n throw new TypeError(`${readerName}: ${name} must be a finite number`);\n }\n if (minExclusive !== null && value <= minExclusive)\n {\n throw new TypeError(`${readerName}: ${name} must be greater than ${minExclusive}`);\n }\n if (minInclusive !== null && value < minInclusive)\n {\n throw new TypeError(`${readerName}: ${name} must be at least ${minInclusive}`);\n }\n return value;\n}\n\n/**\n * Validate a `classes` node key against {@link CLASS_KEYS}.\n *\n * @param {string} key Candidate node key.\n * @param {string} [readerName] Format name used in thrown errors.\n */\nexport function validateClassKey(key, readerName = \"CjsStlFormat\")\n{\n if (!CLASS_KEYS.includes(key))\n {\n throw new Error(`${readerName}: unknown class key ${JSON.stringify(key)}; expected one of ${CLASS_KEYS.join(\", \")}`);\n }\n}\n\n/**\n * Validate a single `classes` entry.\n *\n * @param {string} key Node key.\n * @param {Function} Class Candidate constructor.\n * @param {string} [readerName] Format name used in thrown errors.\n */\nexport function validateClass(key, Class, readerName = \"CjsStlFormat\")\n{\n validateClassKey(key, readerName);\n if (typeof Class !== \"function\")\n {\n throw new TypeError(`${readerName}: class ${JSON.stringify(key)} must be a constructor`);\n }\n}\n\nfunction mergeClasses(base, classes, readerName)\n{\n if (!classes || typeof classes !== \"object\")\n {\n throw new TypeError(`${readerName}: classes option must be an object`);\n }\n\n const next = { ...base };\n for (const [ key, Class ] of Object.entries(classes))\n {\n if (Class === null || Class === undefined)\n {\n delete next[key];\n continue;\n }\n validateClass(key, Class, readerName);\n next[key] = Class;\n }\n return next;\n}\n\nfunction sanitizeName(value)\n{\n if (typeof value !== \"string\" || !value.trim()) return DEFAULT_VALUES.solidName;\n return value.trim();\n}\n\n/**\n * Merge format values over a base set and validate them.\n *\n * @param {object} base Current values.\n * @param {object} [options] Values to merge in.\n * @param {string} [readerName] Format name used in error messages.\n * @returns {object} A validated copy of the merged values.\n */\nexport function normalizeValues(base, options = {}, readerName = \"CjsStlFormat\")\n{\n if (!options || typeof options !== \"object\")\n {\n throw new TypeError(`${readerName}: options must be an object`);\n }\n for (const key of Object.keys(options))\n {\n if (!OPTION_KEYS.has(key))\n {\n throw new TypeError(`${readerName}: unknown option ${JSON.stringify(key)}`);\n }\n }\n\n const values = { ...base, ...options };\n const emit = normalizeEmit(values.emit, readerName);\n const classes = Object.prototype.hasOwnProperty.call(options, \"classes\")\n ? mergeClasses(base.classes || {}, options.classes, readerName)\n : { ...(base.classes || {}) };\n if ((emit === OUTPUT_GR2 || emit === OUTPUT_CMF) && !hasClasses(classes))\n {\n throw new TypeError(`${readerName}: emit \"${emit}\" requires explicit classes`);\n }\n if (typeof values.source !== \"string\" || !values.source)\n {\n values.source = DEFAULT_VALUES.source;\n }\n\n return {\n emit,\n source: values.source,\n binary: validateBoolean(\"binary\", values.binary, readerName),\n solidName: sanitizeName(values.solidName),\n scale: validateNumber(\"scale\", values.scale, readerName, { minExclusive: 0 }),\n recalculateNormals: validateBoolean(\"recalculateNormals\", values.recalculateNormals, readerName),\n weldVertices: validateBoolean(\"weldVertices\", values.weldVertices, readerName),\n weldTolerance: validateNumber(\"weldTolerance\", values.weldTolerance, readerName, { minInclusive: 0 }),\n skipDegenerate: validateBoolean(\"skipDegenerate\", values.skipDegenerate, readerName),\n requireWatertight: validateBoolean(\"requireWatertight\", values.requireWatertight, readerName),\n classes\n };\n}\n\nfunction normalizeEmit(emit, readerName)\n{\n if (emit === undefined || emit === null || emit === OUTPUT_JSON || emit === OUTPUT_STL_JSON || emit === OUTPUT_SHARED)\n {\n return OUTPUT_STL_JSON;\n }\n if (emit === OUTPUT_GR2 || emit === OUTPUT_CMF) return emit;\n throw new TypeError(`${readerName}: emit must be \"${OUTPUT_SHARED}\", \"${OUTPUT_STL_JSON}\", \"${OUTPUT_GR2}\", or \"${OUTPUT_CMF}\", got ${JSON.stringify(emit)}`);\n}\n\nfunction hasClasses(classes)\n{\n return !!classes && Object.values(classes).some((Class) => typeof Class === \"function\");\n}\n\n/**\n * Read STL text/bytes and return the shared JSON schema.\n *\n * @param {object|Function} format Format instance or constructor.\n * @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} values Normalized format values.\n * @returns {object} Shared JSON graph.\n */\nexport function readWithValues(format, input, values)\n{\n void format;\n const parsed = parseStl(input);\n const json = trianglesToJson(parsed.triangles, values, parsed);\n if (values.emit === OUTPUT_CMF) return hydrateCmf(buildCmfFromShared(json), values.classes, { source: values.source });\n return hydrateJson(json, { classes: values.classes, source: values.source });\n}\n\n/**\n * Write the shared JSON geometry schema to STL.\n * The input is read-only. Meshes and index groups are flattened by\n * {@link jsonToTriangles}; optional topology enforcement runs against that\n * exact scaled triangle stream before encoding begins.\n *\n * @param {object} input Shared JSON root or mesh.\n * @param {object} values Normalized format values.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n * @throws {TypeError|RangeError|Error} If geometry, numeric values, indices, topology, or binary range are invalid.\n */\nexport function writeWithValues(input, values)\n{\n const triangles = jsonToTriangles(input, values);\n if (!triangles.length)\n {\n throw new Error(\"CjsStlFormat: write input did not produce any triangles\");\n }\n\n if (values.requireWatertight)\n {\n const report = inspectTriangles(triangles, values, { format: \"json\", source: input.grannyFileSource || values.source });\n if (!report.printable)\n {\n throw new Error(`CjsStlFormat: requireWatertight failed (${report.issues.map(issue => issue.key).join(\", \")})`);\n }\n }\n\n return values.binary\n ? writeBinaryStl(triangles, values.solidName)\n : writeAsciiStl(triangles, values.solidName);\n}\n\n/**\n * Inspect STL or shared JSON geometry without class hydration.\n *\n * @param {any} input STL text/bytes or shared JSON.\n * @param {object} values Normalized format values.\n * @returns {object} Plain printability report.\n */\nexport function inspectWithValues(input, values)\n{\n const source = trianglesFromInput(input, values);\n return inspectTriangles(source.triangles, values, source);\n}\n\n/**\n * Convert format output to plain JSON-compatible data.\n *\n * @param {any} value Format output.\n * @returns {any} JSON-compatible value.\n */\nexport function toJsonValue(value)\n{\n if (value === null || value === undefined) return value;\n if (typeof value !== \"object\") return value;\n\n if (typeof value.toJSON === \"function\")\n {\n const next = value.toJSON();\n if (next !== value) return toJsonValue(next);\n }\n\n if (Array.isArray(value)) return value.map(toJsonValue);\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) return Array.from(value);\n\n const out = {};\n for (const key of Object.keys(value))\n {\n out[key] = toJsonValue(value[key]);\n }\n return out;\n}\n\n/**\n * Imports a Node built-in module without exposing the specifier to any\n * bundler's static import graph.\n *\n * `await import(\"node:fs/promises\")` written as a literal is resolved\n * eagerly by webpack/Rollup/esbuild alike when they walk the module\n * graph, breaking browser builds even though this path only ever runs\n * under Node (readFile/writeFile are Node-only conveniences). Building\n * the specifier inside a `Function` body hides it from every bundler's\n * static analysis - it only exists at runtime, in the Node process that\n * actually calls readFile/writeFile.\n *\n * @param {string} specifier Node built-in module specifier, e.g. \"node:fs/promises\".\n * @returns {Promise<any>} The imported module namespace.\n */\nexport function importNodeModule(specifier)\n{\n // eslint-disable-next-line no-new-func\n return new Function(\"s\", \"return import(s)\")(specifier);\n}\n"],"names":["GR2_CLASS_KEYS","Object","freeze","CLASS_KEYS","Array","from","Set","CMF_CLASS_KEYS","OUTPUT_JSON","OUTPUT_STL_JSON","OUTPUT_SHARED","OUTPUT_GR2","OUTPUT_CMF","DEFAULT_VALUES","emit","source","binary","solidName","scale","recalculateNormals","weldVertices","weldTolerance","skipDegenerate","requireWatertight","classes","OPTION_KEYS","validateBoolean","name","value","readerName","TypeError","validateNumber","minExclusive","minInclusive","Number","isFinite","validateClassKey","key","includes","Error","JSON","stringify","join","validateClass","Class","mergeClasses","base","next","entries","undefined","sanitizeName","trim","normalizeValues","options","keys","has","values","normalizeEmit","prototype","hasOwnProperty","call","hasClasses","some","readWithValues","format","input","parsed","parseStl","json","trianglesToJson","triangles","hydrateCmf","buildCmfFromShared","hydrateJson","writeWithValues","jsonToTriangles","length","report","inspectTriangles","grannyFileSource","printable","issues","map","issue","writeBinaryStl","writeAsciiStl","inspectWithValues","trianglesFromInput","toJsonValue","toJSON","isArray","ArrayBuffer","isView","DataView","out","importNodeModule","specifier","Function"],"mappings":";;;;;AAAA;AACA;AACA;;AAiBO,MAAMA,cAAc,GAAGC,MAAM,CAACC,MAAM,CAAC,CACxC,MAAM,EACN,MAAM,EACN,aAAa,EACb,YAAY,EACZ,aAAa,EACb,OAAO,EACP,UAAU,EAC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AGnB,KAAK,CAAC6D,MAAM,EAAE;IAC3B,IAAI1C,IAAI,KAAKnB,KAAK,EAAE,OAAO4D,WAAW,CAACzC,IAAI,CAAC;AAChD,EAAA;AAEA,EAAA,IAAI3C,KAAK,CAACsF,OAAO,CAAC9D,KAAK,CAAC,EAAE,OAAOA,KAAK,CAACsD,GAAG,CAACM,WAAW,CAAC;AACvD,EAAA,IAAIG,WAAW,CAACC,MAAM,CAAChE,KAAK,CAAC,IAAI,EAAEA,KAAK,YAAYiE,QAAQ,CAAC,EAAE,OAAOzF,KAAK,CAACC,IAAI,CAACuB,KAAK,CAAC;EAEvF,MAAMkE,GAAG,GAAG,EAAE;EACd,KAAK,MAAMzD,GAAG,IAAIpC,MAAM,CAACqD,IAAI,CAAC1B,KAAK,CAAC,EACpC;IACIkE,GAAG,CAACzD,GAAG,CAAC,GAAGmD,WAAW,CAAC5D,KAAK,CAACS,GAAG,CAAC,CAAC;AACtC,EAAA;AACA,EAAA,OAAOyD,GAAG;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAACC,SAAS,EAC1C;AACI;EACA,OAAO,IAAIC,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAACD,SAAS,CAAC;AAC3D;;;;"}
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../../../../src/formats/stl/core/helpers.js"],"sourcesContent":["/**\n * Internal pipeline glue for CjsStlFormat.\n */\n\nimport { hydrateJson } from \"./json.js\";\nimport { buildCmfFromShared, CMF_CLASS_KEYS, hydrateCmf } from \"./targets.js\";\nimport {\n inspectTriangles,\n isBinaryStl,\n isStl,\n jsonToTriangles,\n parseStl,\n toText,\n trianglesFromInput,\n trianglesToJson,\n writeAsciiStl,\n writeBinaryStl\n} from \"./stl.js\";\n\nexport const GR2_CLASS_KEYS = Object.freeze([\n \"Root\",\n \"Mesh\",\n \"BoneBinding\",\n \"IndexGroup\",\n \"MorphTarget\",\n \"Model\",\n \"Skeleton\",\n \"Bone\",\n \"Animation\",\n \"TrackGroup\",\n \"TransformTrack\",\n \"Curve\"\n]);\n\nexport const CLASS_KEYS = Object.freeze(Array.from(new Set([\n ...GR2_CLASS_KEYS,\n ...CMF_CLASS_KEYS\n])));\n\nexport { isBinaryStl, isStl, toText };\n\nexport const OUTPUT_JSON = \"json\";\nexport const OUTPUT_STL_JSON = \"stlJson\";\nexport const OUTPUT_SHARED = \"shared\";\nexport const OUTPUT_GR2 = \"gr2\";\nexport const OUTPUT_CMF = \"cmf\";\n\nexport const DEFAULT_VALUES = Object.freeze({\n emit: OUTPUT_STL_JSON,\n source: \"memory\",\n binary: true,\n solidName: \"carbonenginejs\",\n scale: 1,\n recalculateNormals: true,\n weldVertices: false,\n weldTolerance: 1e-5,\n skipDegenerate: true,\n requireWatertight: false,\n classes: Object.freeze({})\n});\n\nconst OPTION_KEYS = new Set([\n \"emit\",\n \"source\",\n \"binary\",\n \"solidName\",\n \"scale\",\n \"recalculateNormals\",\n \"weldVertices\",\n \"weldTolerance\",\n \"skipDegenerate\",\n \"requireWatertight\",\n \"classes\"\n]);\n\nfunction validateBoolean(name, value, readerName)\n{\n if (typeof value === \"boolean\") return value;\n throw new TypeError(`${readerName}: ${name} must be true or false`);\n}\n\nfunction validateNumber(name, value, readerName, { minExclusive = null, minInclusive = null } = {})\n{\n if (typeof value !== \"number\" || !Number.isFinite(value))\n {\n throw new TypeError(`${readerName}: ${name} must be a finite number`);\n }\n if (minExclusive !== null && value <= minExclusive)\n {\n throw new TypeError(`${readerName}: ${name} must be greater than ${minExclusive}`);\n }\n if (minInclusive !== null && value < minInclusive)\n {\n throw new TypeError(`${readerName}: ${name} must be at least ${minInclusive}`);\n }\n return value;\n}\n\n/**\n * Validate a `classes` node key against {@link CLASS_KEYS}.\n *\n * @param {string} key Candidate node key.\n * @param {string} [readerName] Format name used in thrown errors.\n */\nexport function validateClassKey(key, readerName = \"CjsStlFormat\")\n{\n if (!CLASS_KEYS.includes(key))\n {\n throw new Error(`${readerName}: unknown class key ${JSON.stringify(key)}; expected one of ${CLASS_KEYS.join(\", \")}`);\n }\n}\n\n/**\n * Validate a single `classes` entry.\n *\n * @param {string} key Node key.\n * @param {Function} Class Candidate constructor.\n * @param {string} [readerName] Format name used in thrown errors.\n */\nexport function validateClass(key, Class, readerName = \"CjsStlFormat\")\n{\n validateClassKey(key, readerName);\n if (typeof Class !== \"function\")\n {\n throw new TypeError(`${readerName}: class ${JSON.stringify(key)} must be a constructor`);\n }\n}\n\nfunction mergeClasses(base, classes, readerName)\n{\n if (!classes || typeof classes !== \"object\")\n {\n throw new TypeError(`${readerName}: classes option must be an object`);\n }\n\n const next = { ...base };\n for (const [ key, Class ] of Object.entries(classes))\n {\n if (Class === null || Class === undefined)\n {\n delete next[key];\n continue;\n }\n validateClass(key, Class, readerName);\n next[key] = Class;\n }\n return next;\n}\n\nfunction sanitizeName(value)\n{\n if (typeof value !== \"string\" || !value.trim()) return DEFAULT_VALUES.solidName;\n return value.trim();\n}\n\n/**\n * Merge format values over a base set and validate them.\n *\n * @param {object} base Current values.\n * @param {object} [options] Values to merge in.\n * @param {string} [readerName] Format name used in error messages.\n * @returns {object} A validated copy of the merged values.\n */\nexport function normalizeValues(base, options = {}, readerName = \"CjsStlFormat\")\n{\n if (!options || typeof options !== \"object\")\n {\n throw new TypeError(`${readerName}: options must be an object`);\n }\n for (const key of Object.keys(options))\n {\n if (!OPTION_KEYS.has(key))\n {\n throw new TypeError(`${readerName}: unknown option ${JSON.stringify(key)}`);\n }\n }\n\n const values = { ...base, ...options };\n const emit = normalizeEmit(values.emit, readerName);\n const classes = Object.prototype.hasOwnProperty.call(options, \"classes\")\n ? mergeClasses(base.classes || {}, options.classes, readerName)\n : { ...(base.classes || {}) };\n if ((emit === OUTPUT_GR2 || emit === OUTPUT_CMF) && !hasClasses(classes))\n {\n throw new TypeError(`${readerName}: emit \"${emit}\" requires explicit classes`);\n }\n if (typeof values.source !== \"string\" || !values.source)\n {\n values.source = DEFAULT_VALUES.source;\n }\n\n return {\n emit,\n source: values.source,\n binary: validateBoolean(\"binary\", values.binary, readerName),\n solidName: sanitizeName(values.solidName),\n scale: validateNumber(\"scale\", values.scale, readerName, { minExclusive: 0 }),\n recalculateNormals: validateBoolean(\"recalculateNormals\", values.recalculateNormals, readerName),\n weldVertices: validateBoolean(\"weldVertices\", values.weldVertices, readerName),\n weldTolerance: validateNumber(\"weldTolerance\", values.weldTolerance, readerName, { minInclusive: 0 }),\n skipDegenerate: validateBoolean(\"skipDegenerate\", values.skipDegenerate, readerName),\n requireWatertight: validateBoolean(\"requireWatertight\", values.requireWatertight, readerName),\n classes\n };\n}\n\nfunction normalizeEmit(emit, readerName)\n{\n if (emit === undefined || emit === null || emit === OUTPUT_JSON || emit === OUTPUT_STL_JSON || emit === OUTPUT_SHARED)\n {\n return OUTPUT_STL_JSON;\n }\n if (emit === OUTPUT_GR2 || emit === OUTPUT_CMF) return emit;\n throw new TypeError(`${readerName}: emit must be \"${OUTPUT_SHARED}\", \"${OUTPUT_STL_JSON}\", \"${OUTPUT_GR2}\", or \"${OUTPUT_CMF}\", got ${JSON.stringify(emit)}`);\n}\n\nfunction hasClasses(classes)\n{\n return !!classes && Object.values(classes).some((Class) => typeof Class === \"function\");\n}\n\n/**\n * Read STL text/bytes and return the shared JSON schema.\n *\n * @param {object|Function} format Format instance or constructor.\n * @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} values Normalized format values.\n * @returns {object} Shared JSON graph.\n */\nexport function readWithValues(format, input, values)\n{\n void format;\n const parsed = parseStl(input);\n const json = trianglesToJson(parsed.triangles, values, parsed);\n if (values.emit === OUTPUT_CMF) return hydrateCmf(buildCmfFromShared(json), values.classes, { source: values.source });\n return hydrateJson(json, { classes: values.classes, source: values.source });\n}\n\n/**\n * Write the shared JSON geometry schema to STL.\n * The input is read-only. Meshes and index groups are flattened by\n * {@link jsonToTriangles}; optional topology enforcement runs against that\n * exact scaled triangle stream before encoding begins.\n *\n * @param {object} input Shared JSON root or mesh.\n * @param {object} values Normalized format values.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n * @throws {TypeError|RangeError|Error} If geometry, numeric values, indices, topology, or binary range are invalid.\n */\nexport function writeWithValues(input, values)\n{\n const triangles = jsonToTriangles(input, values);\n if (!triangles.length)\n {\n throw new Error(\"CjsStlFormat: write input did not produce any triangles\");\n }\n\n if (values.requireWatertight)\n {\n const report = inspectTriangles(triangles, values, { format: \"json\", source: input.grannyFileSource || values.source });\n if (!report.printable)\n {\n throw new Error(`CjsStlFormat: requireWatertight failed (${report.issues.map(issue => issue.key).join(\", \")})`);\n }\n }\n\n return values.binary\n ? writeBinaryStl(triangles, values.solidName)\n : writeAsciiStl(triangles, values.solidName);\n}\n\n/**\n * Inspect STL or shared JSON geometry without class hydration.\n *\n * @param {any} input STL text/bytes or shared JSON.\n * @param {object} values Normalized format values.\n * @returns {object} Plain printability report.\n */\nexport function inspectWithValues(input, values)\n{\n const source = trianglesFromInput(input, values);\n return inspectTriangles(source.triangles, values, source);\n}\n\n/**\n * Convert format output to plain JSON-compatible data.\n *\n * @param {any} value Format output.\n * @returns {any} JSON-compatible value.\n */\nexport function toJsonValue(value)\n{\n if (value === null || value === undefined) return value;\n if (typeof value !== \"object\") return value;\n\n if (typeof value.toJSON === \"function\")\n {\n const next = value.toJSON();\n if (next !== value) return toJsonValue(next);\n }\n\n if (Array.isArray(value)) return value.map(toJsonValue);\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) return Array.from(value);\n\n const out = {};\n for (const key of Object.keys(value))\n {\n out[key] = toJsonValue(value[key]);\n }\n return out;\n}\n\n"],"names":["GR2_CLASS_KEYS","Object","freeze","CLASS_KEYS","Array","from","Set","CMF_CLASS_KEYS","OUTPUT_JSON","OUTPUT_STL_JSON","OUTPUT_SHARED","OUTPUT_GR2","OUTPUT_CMF","DEFAULT_VALUES","emit","source","binary","solidName","scale","recalculateNormals","weldVertices","weldTolerance","skipDegenerate","requireWatertight","classes","OPTION_KEYS","validateBoolean","name","value","readerName","TypeError","validateNumber","minExclusive","minInclusive","Number","isFinite","validateClassKey","key","includes","Error","JSON","stringify","join","validateClass","Class","mergeClasses","base","next","entries","undefined","sanitizeName","trim","normalizeValues","options","keys","has","values","normalizeEmit","prototype","hasOwnProperty","call","hasClasses","some","readWithValues","format","input","parsed","parseStl","json","trianglesToJson","triangles","hydrateCmf","buildCmfFromShared","hydrateJson","writeWithValues","jsonToTriangles","length","report","inspectTriangles","grannyFileSource","printable","issues","map","issue","writeBinaryStl","writeAsciiStl","inspectWithValues","trianglesFromInput","toJsonValue","toJSON","isArray","ArrayBuffer","isView","DataView","out"],"mappings":";;;;;AAAA;AACA;AACA;;AAiBO,MAAMA,cAAc,GAAGC,MAAM,CAACC,MAAM,CAAC,CACxC,MAAM,EACN,MAAM,EACN,aAAa,EACb,YAAY,EACZ,aAAa,EACb,OAAO,EACP,UAAU,EACV,MAAM,EACN,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,OAAO,CACV;AAEM,MAAMC,UAAU,GAAGF,MAAM,CAACC,MAAM,CAACE,KAAK,CAACC,IAAI,CAAC,IAAIC,GAAG,CAAC,CACvD,GAAGN,cAAc,EACjB,GAAGO,cAAc,CACpB,CAAC,CAAC;AAII,MAAMC,WAAW,GAAG;AACpB,MAAMC,eAAe,GAAG;AACxB,MAAMC,aAAa,GAAG;AACtB,MAAMC,UAAU,GAAG;AACnB,MAAMC,UAAU,GAAG;MAEbC,cAAc,GAAGZ,MAAM,CAACC,MAAM,CAAC;AACxCY,EAAAA,IAAI,EAAEL,eAAe;AACrBM,EAAAA,MAAM,EAAE,QAAQ;AAChBC,EAAAA,MAAM,EAAE,IAAI;AACZC,EAAAA,SAAS,EAAE,gBAAgB;AAC3BC,EAAAA,KAAK,EAAE,CAAC;AACRC,EAAAA,kBAAkB,EAAE,IAAI;AACxBC,EAAAA,YAAY,EAAE,KAAK;AACnB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;;;"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { DEFAULT_VALUES, normalizeValues,
|
|
1
|
+
import { DEFAULT_VALUES, normalizeValues, emitGlslWithOptions, toJsonValue, isWebglEffectContainer, OUTPUT_JSON } from './core/helpers.js';
|
|
2
2
|
import { buildEffectPackage } from './core/effectPackage.js';
|
|
3
|
+
import { readGlslEffectContainer } from './core/readGlslEffectContainer.js';
|
|
4
|
+
import { inspectGlslEffectContainer } from './core/inspectGlslEffectContainer.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Exposed CarbonEngineJS-facing WebGL format class.
|
|
6
8
|
*
|
|
7
|
-
* Keep this file small and reviewable:
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* paths live in src/core/helpers.js.
|
|
9
|
+
* Keep this file small and reviewable: container decoding lives in
|
|
10
|
+
* core/readGlslEffectContainer.js, summarising in
|
|
11
|
+
* core/inspectGlslEffectContainer.js, the DXBC-to-GLSL ES 3.00 emitter under
|
|
12
|
+
* core/glsl, and option normalization in core/helpers.js.
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
const FORMAT_NAME = "CjsWebglFormat";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
|
-
* CarbonEngineJS-facing format surface for `.
|
|
18
|
+
* CarbonEngineJS-facing format surface for `.carbonwebgl` WebGL shader packages, and
|
|
18
19
|
* a DXBC -> GLSL ES 3.00 emitter for the WebGL2 vertex/pixel/map-style-compute
|
|
19
20
|
* stages ccpwgl targets.
|
|
20
21
|
*
|
|
21
|
-
* The Cjs prefix marks this as a JavaScript format/construction boundary.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* translates one DXBC vertex/pixel/map-style-compute stage to GLSL ES 3.00.
|
|
22
|
+
* The Cjs prefix marks this as a JavaScript format/construction boundary. A
|
|
23
|
+
* WebGL effect is a stock Carbon effect container whose stored programs are
|
|
24
|
+
* GLSL ES 3.00 - the same file shape Carbon ships for its own backends, and the
|
|
25
|
+
* same one WebGPU emits with WGSL. `Read` decodes one into stage and shader
|
|
26
|
+
* records; `Inspect` is a cheap structural summary; `BuildEffect` translates a
|
|
27
|
+
* compiled Tr2 effect into one; `EmitGlsl` translates a single DXBC stage.
|
|
28
28
|
*/
|
|
29
29
|
class CjsWebglFormat {
|
|
30
30
|
#emit = DEFAULT_VALUES.emit;
|
|
@@ -66,35 +66,25 @@ class CjsWebglFormat {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* Decode an effect container into stage and shader records.
|
|
70
70
|
*
|
|
71
|
-
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input
|
|
71
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container bytes.
|
|
72
72
|
* @param {object} [options] Per-call value overrides.
|
|
73
|
-
* @returns {object}
|
|
73
|
+
* @returns {object} Stage graph in the completeness rules' vocabulary.
|
|
74
74
|
*/
|
|
75
75
|
Read(input, options = {}) {
|
|
76
|
-
return
|
|
76
|
+
return readGlslEffectContainer(input, this.GetValues(options));
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
80
|
+
* Summarise an effect container without decoding every body's records.
|
|
81
81
|
*
|
|
82
|
-
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input
|
|
82
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container bytes.
|
|
83
83
|
* @param {object} [options] Per-call value overrides.
|
|
84
84
|
* @returns {object} Plain summary data.
|
|
85
85
|
*/
|
|
86
86
|
Inspect(input, options = {}) {
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Assembles a CEWG package from ordered chunk payloads.
|
|
92
|
-
*
|
|
93
|
-
* @param {Array<[string, string|object|Uint8Array|ArrayBuffer|ArrayBufferView]>} chunks Ordered package chunks.
|
|
94
|
-
* @returns {Uint8Array} Package bytes.
|
|
95
|
-
*/
|
|
96
|
-
Build(chunks) {
|
|
97
|
-
return buildPackage(chunks);
|
|
87
|
+
return inspectGlslEffectContainer(input, this.GetValues(options));
|
|
98
88
|
}
|
|
99
89
|
|
|
100
90
|
/**
|
|
@@ -109,7 +99,7 @@ class CjsWebglFormat {
|
|
|
109
99
|
}
|
|
110
100
|
|
|
111
101
|
/**
|
|
112
|
-
* Builds a complete
|
|
102
|
+
* Builds a complete effect container from compiled Tr2 effect bytes.
|
|
113
103
|
*
|
|
114
104
|
* @param {Uint8Array|ArrayBuffer|ArrayBufferView} input Compiled effect bytes.
|
|
115
105
|
* @param {object} [options] Selection, provenance, and emitter policy.
|
|
@@ -133,42 +123,32 @@ class CjsWebglFormat {
|
|
|
133
123
|
* Static payload sniff. Static methods use camelCase by convention.
|
|
134
124
|
*
|
|
135
125
|
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate bytes.
|
|
136
|
-
* @returns {boolean} True when the payload
|
|
126
|
+
* @returns {boolean} True when the payload has the container shape.
|
|
137
127
|
*/
|
|
138
|
-
static
|
|
139
|
-
return
|
|
128
|
+
static isWebglEffectContainer(input) {
|
|
129
|
+
return isWebglEffectContainer(input);
|
|
140
130
|
}
|
|
141
131
|
|
|
142
132
|
/**
|
|
143
|
-
* Static one-shot
|
|
133
|
+
* Static one-shot container decode.
|
|
144
134
|
*
|
|
145
|
-
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input
|
|
135
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container bytes.
|
|
146
136
|
* @param {object} [options] Format values.
|
|
147
|
-
* @returns {object}
|
|
137
|
+
* @returns {object} Stage graph in the completeness rules' vocabulary.
|
|
148
138
|
*/
|
|
149
139
|
static read(input, options = {}) {
|
|
150
|
-
return
|
|
140
|
+
return readGlslEffectContainer(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));
|
|
151
141
|
}
|
|
152
142
|
|
|
153
143
|
/**
|
|
154
144
|
* Static one-shot inspection.
|
|
155
145
|
*
|
|
156
|
-
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input
|
|
146
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container bytes.
|
|
157
147
|
* @param {object} [options] Format values.
|
|
158
148
|
* @returns {object} Plain summary data.
|
|
159
149
|
*/
|
|
160
150
|
static inspect(input, options = {}) {
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Static one-shot package build.
|
|
166
|
-
*
|
|
167
|
-
* @param {Array<[string, string|object|Uint8Array|ArrayBuffer|ArrayBufferView]>} chunks Ordered package chunks.
|
|
168
|
-
* @returns {Uint8Array} Package bytes.
|
|
169
|
-
*/
|
|
170
|
-
static build(chunks) {
|
|
171
|
-
return buildPackage(chunks);
|
|
151
|
+
return inspectGlslEffectContainer(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));
|
|
172
152
|
}
|
|
173
153
|
|
|
174
154
|
/**
|
|
@@ -188,7 +168,7 @@ class CjsWebglFormat {
|
|
|
188
168
|
}
|
|
189
169
|
|
|
190
170
|
/**
|
|
191
|
-
* Static whole-effect
|
|
171
|
+
* Static whole-effect container builder.
|
|
192
172
|
*
|
|
193
173
|
* @param {Uint8Array|ArrayBuffer|ArrayBufferView} input Compiled effect bytes.
|
|
194
174
|
* @param {object} [options] Selection, provenance, and emitter policy.
|
|
@@ -208,12 +188,10 @@ class CjsWebglFormat {
|
|
|
208
188
|
return toJsonValue(value);
|
|
209
189
|
}
|
|
210
190
|
static OUTPUT_JSON = OUTPUT_JSON;
|
|
211
|
-
static OUTPUT_RAW = OUTPUT_RAW;
|
|
212
191
|
static type = Object.freeze(["shader"]);
|
|
213
192
|
static mediaTypes = Object.freeze(["shader"]);
|
|
214
|
-
static inputTypes = Object.freeze(["
|
|
193
|
+
static inputTypes = Object.freeze(["carbonwebgl"]);
|
|
215
194
|
static outputTypes = Object.freeze([OUTPUT_JSON]);
|
|
216
|
-
static debugOutputTypes = Object.freeze([OUTPUT_RAW]);
|
|
217
195
|
static packageVersion = "0.2.0";
|
|
218
196
|
}
|
|
219
197
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CjsWebglFormat.js","sources":["../../../../src/formats/webgl/CjsWebglFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing WebGL format class.\n *\n * Keep this file small and reviewable: CEWG container parsing lives under\n * src/core/cewg (internal parsing machinery, not part of this package's\n * public surface); the DXBC-to-GLSL ES 3.00 emitter lives under\n * src/core/glsl; input/option normalization and the shared read/build/emit\n * paths live in src/core/helpers.js.\n */\n\nimport {\n DEFAULT_VALUES,\n OUTPUT_JSON,\n OUTPUT_RAW,\n buildPackage,\n emitGlslWithOptions,\n inspectWithValues,\n isCewg,\n normalizeValues,\n readWithValues,\n toJsonValue\n} from \"./core/helpers.js\";\nimport { buildEffectPackage } from \"./core/effectPackage.js\";\n\nconst FORMAT_NAME = \"CjsWebglFormat\";\n\n/**\n * CarbonEngineJS-facing format surface for `.cewg` WebGL shader packages, and\n * a DXBC -> GLSL ES 3.00 emitter for the WebGL2 vertex/pixel/map-style-compute\n * stages ccpwgl targets.\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * CEWG is a CarbonEngineJS-invented container format (flat four-byte-tagged\n * chunks: `INFO`/`META`/`GLSL`/...), not a Microsoft or CCP one. `Read`\n * parses a package to plain JSON by default (`emit: \"raw\"` exposes the live\n * `CewgPackage` instance instead); `Inspect` is a cheap chunk/shader-count\n * summary; `Build` assembles package bytes from chunk payloads; `EmitGlsl`\n * translates one DXBC vertex/pixel/map-style-compute stage to GLSL ES 3.00.\n */\nexport class CjsWebglFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n\n /**\n * Create a reusable format profile.\n *\n * @param {object} [options] Default format 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 {CjsWebglFormat} This format profile.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\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 source: this.#source\n }, options, FORMAT_NAME);\n }\n\n /**\n * Read a CEWG package with this profile's values.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input CEWG package bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain JSON data, or the raw CewgPackage instance when emit is \"raw\".\n */\n Read(input, options = {})\n {\n return readWithValues(input, this.GetValues(options));\n }\n\n /**\n * Inspect a CEWG package without building the full JSON shape.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input CEWG package bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain summary data.\n */\n Inspect(input, options = {})\n {\n return inspectWithValues(input, this.GetValues(options));\n }\n\n /**\n * Assembles a CEWG package from ordered chunk payloads.\n *\n * @param {Array<[string, string|object|Uint8Array|ArrayBuffer|ArrayBufferView]>} chunks Ordered package chunks.\n * @returns {Uint8Array} Package bytes.\n */\n Build(chunks)\n {\n return buildPackage(chunks);\n }\n\n /**\n * Translates one DXBC vertex/pixel/map-style-compute stage into GLSL ES 3.00.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} dxbcBytes DXBC container bytes.\n * @param {object} [options] Combined ccpwgl-profile/emit options. See {@link CjsWebglFormat.emitGlsl}.\n * @returns {object} GLSL text plus the IO contract the packaging layer records.\n */\n EmitGlsl(dxbcBytes, options = {})\n {\n return emitGlslWithOptions(dxbcBytes, options);\n }\n\n /**\n * Builds a complete CEWG package from compiled Tr2 effect bytes.\n *\n * @param {Uint8Array|ArrayBuffer|ArrayBufferView} input Compiled effect bytes.\n * @param {object} [options] Selection, provenance, and emitter policy.\n * @returns {object} Package bytes plus inspection and qualification records.\n */\n BuildEffect(input, options = {})\n {\n return buildEffectPackage(input, options);\n }\n\n /**\n * Instance JSON-compatible conversion.\n *\n * @param {any} 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 payload sniff. Static methods use camelCase by convention.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate bytes.\n * @returns {boolean} True when the payload starts with the CEWG magic.\n */\n static isCewg(input)\n {\n return isCewg(input);\n }\n\n /**\n * Static one-shot read.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input CEWG package bytes.\n * @param {object} [options] Format values.\n * @returns {object} Plain JSON data, or the raw CewgPackage instance when emit is \"raw\".\n */\n static read(input, options = {})\n {\n return readWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input CEWG package bytes.\n * @param {object} [options] Format values.\n * @returns {object} Plain summary data.\n */\n static inspect(input, options = {})\n {\n return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot package build.\n *\n * @param {Array<[string, string|object|Uint8Array|ArrayBuffer|ArrayBufferView]>} chunks Ordered package chunks.\n * @returns {Uint8Array} Package bytes.\n */\n static build(chunks)\n {\n return buildPackage(chunks);\n }\n\n /**\n * Static one-shot DXBC-to-GLSL emission.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} dxbcBytes DXBC container bytes.\n * @param {object} [options] Combined ccpwgl-profile/emit options: `constantBufferStyle`\n * (`\"array\"` (default) uniform `vec4[]` for ccpwgl's uniform4fv path, or `\"std140\"`),\n * `pixelConstantBufferRemap` (default `{ 0: 7 }`, pixel-stage cb slot renames),\n * `samplerName(register, stageName)` (naming function), `vertexStructuredCapacity`\n * (default 69, bone-array element capacity), `dataTextureWidth` (default 2048),\n * `pairVaryings` (per-call varying zero-fill list), `source` (per-call error-detail name).\n * @returns {object} GLSL text plus the IO contract the packaging layer records.\n */\n static emitGlsl(dxbcBytes, options = {})\n {\n return emitGlslWithOptions(dxbcBytes, options);\n }\n\n /**\n * Static whole-effect CEWG builder.\n *\n * @param {Uint8Array|ArrayBuffer|ArrayBufferView} input Compiled effect bytes.\n * @param {object} [options] Selection, provenance, and emitter policy.\n * @returns {object} Package bytes plus inspection and qualification records.\n */\n static buildEffect(input, options = {})\n {\n return buildEffectPackage(input, options);\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} 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_RAW = OUTPUT_RAW;\n static type = Object.freeze([ \"shader\" ]);\n static mediaTypes = Object.freeze([ \"shader\" ]);\n static inputTypes = Object.freeze([ \"cewg\" ]);\n static outputTypes = Object.freeze([ OUTPUT_JSON ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_RAW ]);\n static packageVersion = \"0.2.0\";\n\n}\n\nexport default CjsWebglFormat;\n"],"names":["FORMAT_NAME","CjsWebglFormat","DEFAULT_VALUES","emit","source","constructor","options","SetValues","values","normalizeValues","GetValues","Read","input","readWithValues","Inspect","inspectWithValues","Build","chunks","buildPackage","EmitGlsl","dxbcBytes","emitGlslWithOptions","BuildEffect","buildEffectPackage","ToJSON","value","toJsonValue","isCewg","read","inspect","build","emitGlsl","buildEffect","toJSON","OUTPUT_JSON","OUTPUT_RAW","type","Object","freeze","mediaTypes","inputTypes","outputTypes","debugOutputTypes","packageVersion"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgBA,MAAMA,WAAW,GAAG,gBAAgB;;AAEp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b,MAAM,EACnB;IACI,OAAOC,YAAY,CAACD,MAAM,CAAC;AAC/B,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACI,OAAOc,QAAQA,CAACX,SAAS,EAAEd,OAAO,GAAG,EAAE,EACvC;AACI,IAAA,OAAOe,mBAAmB,CAACD,SAAS,EAAEd,OAAO,CAAC;AAClD,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACA;EACI,OAAO0B,WAAWA,CAACpB,KAAK,EAAEN,OAAO,GAAG,EAAE,EACtC;AACI,IAAA,OAAOiB,kBAAkB,CAACX,KAAK,EAAEN,OAAO,CAAC;AAC7C,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;EACI,OAAO2B,MAAMA,CAACR,KAAK,EACnB;IACI,OAAOC,WAAW,CAACD,KAAK,CAAC;AAC7B,EAAA;EAEA,OAAOS,WAAW,GAAGA,WAAW;EAChC,OAAOC,UAAU,GAAGA,UAAU;EAC9B,OAAOC,IAAI,GAAGC,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,CAAE,CAAC;EACzC,OAAOC,UAAU,GAAGF,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,CAAE,CAAC;EAC/C,OAAOE,UAAU,GAAGH,MAAM,CAACC,MAAM,CAAC,CAAE,MAAM,CAAE,CAAC;EAC7C,OAAOG,WAAW,GAAGJ,MAAM,CAACC,MAAM,CAAC,CAAEJ,WAAW,CAAE,CAAC;EACnD,OAAOQ,gBAAgB,GAAGL,MAAM,CAACC,MAAM,CAAC,CAAEH,UAAU,CAAE,CAAC;EACvD,OAAOQ,cAAc,GAAG,OAAO;AAEnC;;;;"}
|
|
1
|
+
{"version":3,"file":"CjsWebglFormat.js","sources":["../../../../src/formats/webgl/CjsWebglFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing WebGL format class.\n *\n * Keep this file small and reviewable: container decoding lives in\n * core/readGlslEffectContainer.js, summarising in\n * core/inspectGlslEffectContainer.js, the DXBC-to-GLSL ES 3.00 emitter under\n * core/glsl, and option normalization in core/helpers.js.\n */\n\nimport {\n DEFAULT_VALUES,\n OUTPUT_JSON,\n emitGlslWithOptions,\n isWebglEffectContainer,\n normalizeValues,\n toJsonValue\n} from \"./core/helpers.js\";\nimport { buildEffectPackage } from \"./core/effectPackage.js\";\nimport { readGlslEffectContainer } from \"./core/readGlslEffectContainer.js\";\nimport { inspectGlslEffectContainer } from \"./core/inspectGlslEffectContainer.js\";\n\nconst FORMAT_NAME = \"CjsWebglFormat\";\n\n/**\n * CarbonEngineJS-facing format surface for `.carbonwebgl` WebGL shader packages, and\n * a DXBC -> GLSL ES 3.00 emitter for the WebGL2 vertex/pixel/map-style-compute\n * stages ccpwgl targets.\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary. A\n * WebGL effect is a stock Carbon effect container whose stored programs are\n * GLSL ES 3.00 - the same file shape Carbon ships for its own backends, and the\n * same one WebGPU emits with WGSL. `Read` decodes one into stage and shader\n * records; `Inspect` is a cheap structural summary; `BuildEffect` translates a\n * compiled Tr2 effect into one; `EmitGlsl` translates a single DXBC stage.\n */\nexport class CjsWebglFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n\n /**\n * Create a reusable format profile.\n *\n * @param {object} [options] Default format 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 {CjsWebglFormat} This format profile.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\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 source: this.#source\n }, options, FORMAT_NAME);\n }\n\n /**\n * Decode an effect container into stage and shader records.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Stage graph in the completeness rules' vocabulary.\n */\n Read(input, options = {})\n {\n return readGlslEffectContainer(input, this.GetValues(options));\n }\n\n /**\n * Summarise an effect container without decoding every body's records.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain summary data.\n */\n Inspect(input, options = {})\n {\n return inspectGlslEffectContainer(input, this.GetValues(options));\n }\n\n /**\n * Translates one DXBC vertex/pixel/map-style-compute stage into GLSL ES 3.00.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} dxbcBytes DXBC container bytes.\n * @param {object} [options] Combined ccpwgl-profile/emit options. See {@link CjsWebglFormat.emitGlsl}.\n * @returns {object} GLSL text plus the IO contract the packaging layer records.\n */\n EmitGlsl(dxbcBytes, options = {})\n {\n return emitGlslWithOptions(dxbcBytes, options);\n }\n\n /**\n * Builds a complete effect container from compiled Tr2 effect bytes.\n *\n * @param {Uint8Array|ArrayBuffer|ArrayBufferView} input Compiled effect bytes.\n * @param {object} [options] Selection, provenance, and emitter policy.\n * @returns {object} Package bytes plus inspection and qualification records.\n */\n BuildEffect(input, options = {})\n {\n return buildEffectPackage(input, options);\n }\n\n /**\n * Instance JSON-compatible conversion.\n *\n * @param {any} 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 payload sniff. Static methods use camelCase by convention.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate bytes.\n * @returns {boolean} True when the payload has the container shape.\n */\n static isWebglEffectContainer(input)\n {\n return isWebglEffectContainer(input);\n }\n\n /**\n * Static one-shot container decode.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container bytes.\n * @param {object} [options] Format values.\n * @returns {object} Stage graph in the completeness rules' vocabulary.\n */\n static read(input, options = {})\n {\n return readGlslEffectContainer(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container bytes.\n * @param {object} [options] Format values.\n * @returns {object} Plain summary data.\n */\n static inspect(input, options = {})\n {\n return inspectGlslEffectContainer(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot DXBC-to-GLSL emission.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} dxbcBytes DXBC container bytes.\n * @param {object} [options] Combined ccpwgl-profile/emit options: `constantBufferStyle`\n * (`\"array\"` (default) uniform `vec4[]` for ccpwgl's uniform4fv path, or `\"std140\"`),\n * `pixelConstantBufferRemap` (default `{ 0: 7 }`, pixel-stage cb slot renames),\n * `samplerName(register, stageName)` (naming function), `vertexStructuredCapacity`\n * (default 69, bone-array element capacity), `dataTextureWidth` (default 2048),\n * `pairVaryings` (per-call varying zero-fill list), `source` (per-call error-detail name).\n * @returns {object} GLSL text plus the IO contract the packaging layer records.\n */\n static emitGlsl(dxbcBytes, options = {})\n {\n return emitGlslWithOptions(dxbcBytes, options);\n }\n\n /**\n * Static whole-effect container builder.\n *\n * @param {Uint8Array|ArrayBuffer|ArrayBufferView} input Compiled effect bytes.\n * @param {object} [options] Selection, provenance, and emitter policy.\n * @returns {object} Package bytes plus inspection and qualification records.\n */\n static buildEffect(input, options = {})\n {\n return buildEffectPackage(input, options);\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} 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 type = Object.freeze([ \"shader\" ]);\n static mediaTypes = Object.freeze([ \"shader\" ]);\n static inputTypes = Object.freeze([ \"carbonwebgl\" ]);\n static outputTypes = Object.freeze([ OUTPUT_JSON ]);\n static packageVersion = \"0.2.0\";\n\n}\n\nexport default CjsWebglFormat;\n"],"names":["FORMAT_NAME","CjsWebglFormat","DEFAULT_VALUES","emit","source","constructor","options","SetValues","values","normalizeValues","GetValues","Read","input","readGlslEffectContainer","Inspect","inspectGlslEffectContainer","EmitGlsl","dxbcBytes","emitGlslWithOptions","BuildEffect","buildEffectPackage","ToJSON","value","toJsonValue","isWebglEffectContainer","read","inspect","emitGlsl","buildEffect","toJSON","OUTPUT_JSON","type","Object","freeze","mediaTypes","inputTypes","outputTypes","packageVersion"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,MAAMA,WAAW,GAAG,gBAAgB;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,cAAc,CAC3B;AAEI,EAAA,KAAK,GAAGC,cAAc,CAACC,IAAI;AAC3B,EAAA,OAAO,GAAGD,cAAc,CAACE,MAAM;;AAE/B;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;AACI,IAAA,MAAME,MAAM,GAAGC,eAAe,CAAC,IAAI,CAACC,SAAS,EAAE,EAAEJ,OAAO,EAAEN,WAAW,CAAC;AAEtE,IAAA,IAAI,CAAC,KAAK,GAAGQ,MAAM,CAACL,IAAI;AACxB,IAAA,IAAI,CAAC,OAAO,GAAGK,MAAM,CAACJ,MAAM;AAE5B,IAAA,OAAO,IAAI;AACf,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACIM,EAAAA,SAASA,CAACJ,OAAO,GAAG,EAAE,EACtB;AACI,IAAA,OAAOG,eAAe,CAAC;AACnBN,MAAAA,IAAI,EAAE,IAAI,CAAC,KAAK;MAChBC,M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