@carbonenginejs/runtime-resource 0.1.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/FORMAT-PROVENANCE.md +135 -0
- package/LICENSE +21 -0
- package/NOTICE +29 -0
- package/README.md +241 -0
- package/dist/CjsMotherLode.js +56 -0
- package/dist/CjsMotherLode.js.map +1 -0
- package/dist/CjsResMan.js +740 -0
- package/dist/CjsResMan.js.map +1 -0
- package/dist/CjsResManQueue.js +214 -0
- package/dist/CjsResManQueue.js.map +1 -0
- package/dist/CjsResource.js +366 -0
- package/dist/CjsResource.js.map +1 -0
- package/dist/CjsResourceSource.js +59 -0
- package/dist/CjsResourceSource.js.map +1 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/dist/format/CjsFormat.js +178 -0
- package/dist/format/CjsFormat.js.map +1 -0
- package/dist/format/CjsResourceProbe.js +269 -0
- package/dist/format/CjsResourceProbe.js.map +1 -0
- package/dist/format/payloadContract.js +173 -0
- package/dist/format/payloadContract.js.map +1 -0
- package/dist/formats/black/CjsBlackFormat.js +272 -0
- package/dist/formats/black/CjsBlackFormat.js.map +1 -0
- package/dist/formats/black/core/CjsBlackBinaryReader.js +153 -0
- package/dist/formats/black/core/CjsBlackBinaryReader.js.map +1 -0
- package/dist/formats/black/core/CjsBlackPropertyReaders.js +382 -0
- package/dist/formats/black/core/CjsBlackPropertyReaders.js.map +1 -0
- package/dist/formats/black/core/CjsBlackReader.js +760 -0
- package/dist/formats/black/core/CjsBlackReader.js.map +1 -0
- package/dist/formats/black/core/CjsBlackSchemaRegistry.js +433 -0
- package/dist/formats/black/core/CjsBlackSchemaRegistry.js.map +1 -0
- package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js +4 -0
- package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js.map +1 -0
- package/dist/formats/black/core/blackConstants.js +7 -0
- package/dist/formats/black/core/blackConstants.js.map +1 -0
- package/dist/formats/black/core/blackDefinitions.js +10 -0
- package/dist/formats/black/core/blackDefinitions.js.map +1 -0
- package/dist/formats/black/core/blackEnums.js +6 -0
- package/dist/formats/black/core/blackEnums.js.map +1 -0
- package/dist/formats/black/core/blackSchema.js +3 -0
- package/dist/formats/black/core/blackSchema.js.map +1 -0
- package/dist/formats/black/core/blackVersion.js +22 -0
- package/dist/formats/black/core/blackVersion.js.map +1 -0
- package/dist/formats/black/core/helpers.js +182 -0
- package/dist/formats/black/core/helpers.js.map +1 -0
- package/dist/formats/black/core/schema.js +4 -0
- package/dist/formats/black/core/schema.js.map +1 -0
- package/dist/formats/black/index.js +2 -0
- package/dist/formats/black/index.js.map +1 -0
- package/dist/formats/bnk/CjsBnkFormat.js +245 -0
- package/dist/formats/bnk/CjsBnkFormat.js.map +1 -0
- package/dist/formats/bnk/core/helpers.js +354 -0
- package/dist/formats/bnk/core/helpers.js.map +1 -0
- package/dist/formats/bnk/core/soundbanksInfo.js +246 -0
- package/dist/formats/bnk/core/soundbanksInfo.js.map +1 -0
- package/dist/formats/bnk/index.js +3 -0
- package/dist/formats/bnk/index.js.map +1 -0
- package/dist/formats/cmf/CjsCmfFormat.js +491 -0
- package/dist/formats/cmf/CjsCmfFormat.js.map +1 -0
- package/dist/formats/cmf/core/binary.js +118 -0
- package/dist/formats/cmf/core/binary.js.map +1 -0
- package/dist/formats/cmf/core/buffers.js +233 -0
- package/dist/formats/cmf/core/buffers.js.map +1 -0
- package/dist/formats/cmf/core/constants.js +47 -0
- package/dist/formats/cmf/core/constants.js.map +1 -0
- package/dist/formats/cmf/core/gr2Anim.js +453 -0
- package/dist/formats/cmf/core/gr2Anim.js.map +1 -0
- package/dist/formats/cmf/core/helpers.js +287 -0
- package/dist/formats/cmf/core/helpers.js.map +1 -0
- package/dist/formats/cmf/core/pack.js +276 -0
- package/dist/formats/cmf/core/pack.js.map +1 -0
- package/dist/formats/cmf/core/schema.js +364 -0
- package/dist/formats/cmf/core/schema.js.map +1 -0
- package/dist/formats/cmf/core/shared.js +268 -0
- package/dist/formats/cmf/core/shared.js.map +1 -0
- package/dist/formats/cmf/core/writer.js +517 -0
- package/dist/formats/cmf/core/writer.js.map +1 -0
- package/dist/formats/cmf/index.js +2 -0
- package/dist/formats/cmf/index.js.map +1 -0
- package/dist/formats/dds/CjsDdsFormat.js +187 -0
- package/dist/formats/dds/CjsDdsFormat.js.map +1 -0
- package/dist/formats/dds/core/helpers.js +812 -0
- package/dist/formats/dds/core/helpers.js.map +1 -0
- package/dist/formats/dds/index.js +2 -0
- package/dist/formats/dds/index.js.map +1 -0
- package/dist/formats/fbx/CjsFbxFormat.js +260 -0
- package/dist/formats/fbx/CjsFbxFormat.js.map +1 -0
- package/dist/formats/fbx/core/helpers.js +3901 -0
- package/dist/formats/fbx/core/helpers.js.map +1 -0
- package/dist/formats/fbx/index.js +2 -0
- package/dist/formats/fbx/index.js.map +1 -0
- package/dist/formats/flac/CjsFlacFormat.js +81 -0
- package/dist/formats/flac/CjsFlacFormat.js.map +1 -0
- package/dist/formats/flac/core/helpers.js +295 -0
- package/dist/formats/flac/core/helpers.js.map +1 -0
- package/dist/formats/flac/index.js +2 -0
- package/dist/formats/flac/index.js.map +1 -0
- package/dist/formats/gif/CjsGifFormat.js +81 -0
- package/dist/formats/gif/CjsGifFormat.js.map +1 -0
- package/dist/formats/gif/core/helpers.js +360 -0
- package/dist/formats/gif/core/helpers.js.map +1 -0
- package/dist/formats/gif/index.js +2 -0
- package/dist/formats/gif/index.js.map +1 -0
- package/dist/formats/gltf/CjsGltfFormat.js +284 -0
- package/dist/formats/gltf/CjsGltfFormat.js.map +1 -0
- package/dist/formats/gltf/core/helpers.js +292 -0
- package/dist/formats/gltf/core/helpers.js.map +1 -0
- package/dist/formats/gltf/core/json.js +79 -0
- package/dist/formats/gltf/core/json.js.map +1 -0
- package/dist/formats/gltf/core/parser.js +666 -0
- package/dist/formats/gltf/core/parser.js.map +1 -0
- package/dist/formats/gltf/core/targets.js +163 -0
- package/dist/formats/gltf/core/targets.js.map +1 -0
- package/dist/formats/gltf/index.js +2 -0
- package/dist/formats/gltf/index.js.map +1 -0
- package/dist/formats/index.js +23 -0
- package/dist/formats/index.js.map +1 -0
- package/dist/formats/jpeg/CjsJpegFormat.js +200 -0
- package/dist/formats/jpeg/CjsJpegFormat.js.map +1 -0
- package/dist/formats/jpeg/core/helpers.js +350 -0
- package/dist/formats/jpeg/core/helpers.js.map +1 -0
- package/dist/formats/jpeg/core/jpeg.js +377 -0
- package/dist/formats/jpeg/core/jpeg.js.map +1 -0
- package/dist/formats/jpeg/index.js +2 -0
- package/dist/formats/jpeg/index.js.map +1 -0
- package/dist/formats/mp3/CjsMp3Format.js +186 -0
- package/dist/formats/mp3/CjsMp3Format.js.map +1 -0
- package/dist/formats/mp3/core/helpers.js +338 -0
- package/dist/formats/mp3/core/helpers.js.map +1 -0
- package/dist/formats/mp3/index.js +2 -0
- package/dist/formats/mp3/index.js.map +1 -0
- package/dist/formats/mp4/CjsMp4Format.js +185 -0
- package/dist/formats/mp4/CjsMp4Format.js.map +1 -0
- package/dist/formats/mp4/core/helpers.js +449 -0
- package/dist/formats/mp4/core/helpers.js.map +1 -0
- package/dist/formats/mp4/index.js +2 -0
- package/dist/formats/mp4/index.js.map +1 -0
- package/dist/formats/obj/CjsObjFormat.js +247 -0
- package/dist/formats/obj/CjsObjFormat.js.map +1 -0
- package/dist/formats/obj/core/helpers.js +573 -0
- package/dist/formats/obj/core/helpers.js.map +1 -0
- package/dist/formats/obj/core/json.js +64 -0
- package/dist/formats/obj/core/json.js.map +1 -0
- package/dist/formats/obj/core/parser.js +321 -0
- package/dist/formats/obj/core/parser.js.map +1 -0
- package/dist/formats/obj/index.js +2 -0
- package/dist/formats/obj/index.js.map +1 -0
- package/dist/formats/ogg/CjsOggFormat.js +82 -0
- package/dist/formats/ogg/CjsOggFormat.js.map +1 -0
- package/dist/formats/ogg/core/helpers.js +387 -0
- package/dist/formats/ogg/core/helpers.js.map +1 -0
- package/dist/formats/ogg/core/imdct.js +178 -0
- package/dist/formats/ogg/core/imdct.js.map +1 -0
- package/dist/formats/ogg/core/vorbis.js +999 -0
- package/dist/formats/ogg/core/vorbis.js.map +1 -0
- package/dist/formats/ogg/index.js +2 -0
- package/dist/formats/ogg/index.js.map +1 -0
- package/dist/formats/png/CjsPngFormat.js +189 -0
- package/dist/formats/png/CjsPngFormat.js.map +1 -0
- package/dist/formats/png/core/helpers.js +583 -0
- package/dist/formats/png/core/helpers.js.map +1 -0
- package/dist/formats/png/index.js +2 -0
- package/dist/formats/png/index.js.map +1 -0
- package/dist/formats/red/CjsRedFormat.js +247 -0
- package/dist/formats/red/CjsRedFormat.js.map +1 -0
- package/dist/formats/red/core/CjsRedReader.js +201 -0
- package/dist/formats/red/core/CjsRedReader.js.map +1 -0
- package/dist/formats/red/core/blackDefinitions.js +3 -0
- package/dist/formats/red/core/blackDefinitions.js.map +1 -0
- package/dist/formats/red/core/helpers.js +136 -0
- package/dist/formats/red/core/helpers.js.map +1 -0
- package/dist/formats/red/core/redGraph.js +68 -0
- package/dist/formats/red/core/redGraph.js.map +1 -0
- package/dist/formats/red/core/schema.js +4 -0
- package/dist/formats/red/core/schema.js.map +1 -0
- package/dist/formats/red/index.js +2 -0
- package/dist/formats/red/index.js.map +1 -0
- package/dist/formats/stl/CjsStlFormat.js +304 -0
- package/dist/formats/stl/CjsStlFormat.js.map +1 -0
- package/dist/formats/stl/core/helpers.js +257 -0
- package/dist/formats/stl/core/helpers.js.map +1 -0
- package/dist/formats/stl/core/json.js +51 -0
- package/dist/formats/stl/core/json.js.map +1 -0
- package/dist/formats/stl/core/stl.js +544 -0
- package/dist/formats/stl/core/stl.js.map +1 -0
- package/dist/formats/stl/core/targets.js +163 -0
- package/dist/formats/stl/core/targets.js.map +1 -0
- package/dist/formats/stl/index.js +2 -0
- package/dist/formats/stl/index.js.map +1 -0
- package/dist/formats/tga/CjsTgaFormat.js +186 -0
- package/dist/formats/tga/CjsTgaFormat.js.map +1 -0
- package/dist/formats/tga/core/helpers.js +446 -0
- package/dist/formats/tga/core/helpers.js.map +1 -0
- package/dist/formats/tga/index.js +2 -0
- package/dist/formats/tga/index.js.map +1 -0
- package/dist/formats/wav/CjsWavFormat.js +186 -0
- package/dist/formats/wav/CjsWavFormat.js.map +1 -0
- package/dist/formats/wav/core/helpers.js +328 -0
- package/dist/formats/wav/core/helpers.js.map +1 -0
- package/dist/formats/wav/index.js +2 -0
- package/dist/formats/wav/index.js.map +1 -0
- package/dist/formats/webm/CjsWebmFormat.js +185 -0
- package/dist/formats/webm/CjsWebmFormat.js.map +1 -0
- package/dist/formats/webm/core/helpers.js +537 -0
- package/dist/formats/webm/core/helpers.js.map +1 -0
- package/dist/formats/webm/index.js +2 -0
- package/dist/formats/webm/index.js.map +1 -0
- package/dist/formats/webp/CjsWebpFormat.js +80 -0
- package/dist/formats/webp/CjsWebpFormat.js.map +1 -0
- package/dist/formats/webp/core/helpers.js +214 -0
- package/dist/formats/webp/core/helpers.js.map +1 -0
- package/dist/formats/webp/index.js +2 -0
- package/dist/formats/webp/index.js.map +1 -0
- package/dist/formats/wem/CjsWemFormat.js +197 -0
- package/dist/formats/wem/CjsWemFormat.js.map +1 -0
- package/dist/formats/wem/core/bitStream.js +259 -0
- package/dist/formats/wem/core/bitStream.js.map +1 -0
- package/dist/formats/wem/core/codebookLibrary.js +164 -0
- package/dist/formats/wem/core/codebookLibrary.js.map +1 -0
- package/dist/formats/wem/core/helpers.js +336 -0
- package/dist/formats/wem/core/helpers.js.map +1 -0
- package/dist/formats/wem/core/packedCodebooksAotuv603.js +30 -0
- package/dist/formats/wem/core/packedCodebooksAotuv603.js.map +1 -0
- package/dist/formats/wem/core/wemToOgg.js +485 -0
- package/dist/formats/wem/core/wemToOgg.js.map +1 -0
- package/dist/formats/wem/index.js +2 -0
- package/dist/formats/wem/index.js.map +1 -0
- package/dist/formats/yaml/CjsYamlFormat.js +77 -0
- package/dist/formats/yaml/CjsYamlFormat.js.map +1 -0
- package/dist/formats/yaml/core/CjsYamlReader.js +304 -0
- package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -0
- package/dist/formats/yaml/core/helpers.js +160 -0
- package/dist/formats/yaml/core/helpers.js.map +1 -0
- package/dist/formats/yaml/index.js +2 -0
- package/dist/formats/yaml/index.js.map +1 -0
- package/dist/generated/resources/AudioGeometryResData.js +47 -0
- package/dist/generated/resources/AudioGeometryResData.js.map +1 -0
- package/dist/generated/resources/CmfVertexReader.js +46 -0
- package/dist/generated/resources/CmfVertexReader.js.map +1 -0
- package/dist/generated/resources/GStateBindingCallbackData.js +31 -0
- package/dist/generated/resources/GStateBindingCallbackData.js.map +1 -0
- package/dist/generated/resources/MeshDecalData.js +37 -0
- package/dist/generated/resources/MeshDecalData.js.map +1 -0
- package/dist/generated/resources/MeshDecalLodData.js +34 -0
- package/dist/generated/resources/MeshDecalLodData.js.map +1 -0
- package/dist/generated/resources/Tr2AsyncSave.js +46 -0
- package/dist/generated/resources/Tr2AsyncSave.js.map +1 -0
- package/dist/generated/resources/Tr2CmfContents.js +37 -0
- package/dist/generated/resources/Tr2CmfContents.js.map +1 -0
- package/dist/generated/resources/Tr2GrannyIntersectionResult.js +58 -0
- package/dist/generated/resources/Tr2GrannyIntersectionResult.js.map +1 -0
- package/dist/generated/resources/Tr2LoadPrepareFence.js +37 -0
- package/dist/generated/resources/Tr2LoadPrepareFence.js.map +1 -0
- package/dist/generated/resources/Tr2MaterialArea.js +34 -0
- package/dist/generated/resources/Tr2MaterialArea.js.map +1 -0
- package/dist/generated/resources/Tr2MaterialMesh.js +31 -0
- package/dist/generated/resources/Tr2MaterialMesh.js.map +1 -0
- package/dist/generated/resources/Tr2MaterialRes.js +34 -0
- package/dist/generated/resources/Tr2MaterialRes.js.map +1 -0
- package/dist/generated/resources/Tr2ShaderPermutation.js +43 -0
- package/dist/generated/resources/Tr2ShaderPermutation.js.map +1 -0
- package/dist/generated/resources/Tr2TextureLodManager.js +60 -0
- package/dist/generated/resources/Tr2TextureLodManager.js.map +1 -0
- package/dist/generated/resources/Tr2TextureLodUpdateRequest.js +37 -0
- package/dist/generated/resources/Tr2TextureLodUpdateRequest.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePackChannel.js +37 -0
- package/dist/generated/resources/Tr2TexturePackChannel.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipeline.js +44 -0
- package/dist/generated/resources/Tr2TexturePipeline.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineParams.js +34 -0
- package/dist/generated/resources/Tr2TexturePipelineParams.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineStepCompress.js +40 -0
- package/dist/generated/resources/Tr2TexturePipelineStepCompress.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineStepLimitSize.js +34 -0
- package/dist/generated/resources/Tr2TexturePipelineStepLimitSize.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineStepLoad.js +31 -0
- package/dist/generated/resources/Tr2TexturePipelineStepLoad.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineStepPack.js +43 -0
- package/dist/generated/resources/Tr2TexturePipelineStepPack.js.map +1 -0
- package/dist/generated/resources/TriGeometryResAreaData.js +59 -0
- package/dist/generated/resources/TriGeometryResAreaData.js.map +1 -0
- package/dist/generated/resources/TriGeometryResJointData.js +38 -0
- package/dist/generated/resources/TriGeometryResJointData.js.map +1 -0
- package/dist/generated/resources/TriGeometryResLodData.js +88 -0
- package/dist/generated/resources/TriGeometryResLodData.js.map +1 -0
- package/dist/generated/resources/TriGeometryResMeshData.js +63 -0
- package/dist/generated/resources/TriGeometryResMeshData.js.map +1 -0
- package/dist/generated/resources/TriGeometryResSkeletonData.js +34 -0
- package/dist/generated/resources/TriGeometryResSkeletonData.js.map +1 -0
- package/dist/generated/resources/TriJointBinding.js +38 -0
- package/dist/generated/resources/TriJointBinding.js.map +1 -0
- package/dist/generated/resources/TriMorphTargetGeometryConstants.js +46 -0
- package/dist/generated/resources/TriMorphTargetGeometryConstants.js.map +1 -0
- package/dist/generated/resources/TriRtGeometryConstants.js +88 -0
- package/dist/generated/resources/TriRtGeometryConstants.js.map +1 -0
- package/dist/generated/resources/enums.js +18 -0
- package/dist/generated/resources/enums.js.map +1 -0
- package/dist/generated/resources/index.js +32 -0
- package/dist/generated/resources/index.js.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/resourcePath.js +18 -0
- package/dist/resourcePath.js.map +1 -0
- package/dist/resourceStates.js +9 -0
- package/dist/resourceStates.js.map +1 -0
- package/dist/resources/Tr2EffectRes.js +71 -0
- package/dist/resources/Tr2EffectRes.js.map +1 -0
- package/dist/resources/Tr2GrannyStateRes.js +44 -0
- package/dist/resources/Tr2GrannyStateRes.js.map +1 -0
- package/dist/resources/Tr2ImageRes.js +114 -0
- package/dist/resources/Tr2ImageRes.js.map +1 -0
- package/dist/resources/Tr2LightProfileRes.js +40 -0
- package/dist/resources/Tr2LightProfileRes.js.map +1 -0
- package/dist/resources/TriGeometryRes.js +216 -0
- package/dist/resources/TriGeometryRes.js.map +1 -0
- package/dist/resources/TriGrannyRes.js +43 -0
- package/dist/resources/TriGrannyRes.js.map +1 -0
- package/dist/resources/TriTextureRes.js +304 -0
- package/dist/resources/TriTextureRes.js.map +1 -0
- package/dist/resources/resourceBoundary.js +47 -0
- package/dist/resources/resourceBoundary.js.map +1 -0
- package/dist/texture/CjsTextureArrayRes.js +406 -0
- package/dist/texture/CjsTextureArrayRes.js.map +1 -0
- package/dist/texture/CjsTextureParameterProxy.js +133 -0
- package/dist/texture/CjsTextureParameterProxy.js.map +1 -0
- package/format-notices/black/LICENSE +21 -0
- package/format-notices/black/NOTICE +47 -0
- package/format-notices/bnk/LICENSE +21 -0
- package/format-notices/bnk/NOTICE +17 -0
- package/format-notices/cmf/LICENSE +21 -0
- package/format-notices/cmf/NOTICE +36 -0
- package/format-notices/dds/LICENSE +21 -0
- package/format-notices/dds/NOTICE +14 -0
- package/format-notices/fbx/LICENSE +21 -0
- package/format-notices/fbx/NOTICE +14 -0
- package/format-notices/flac/LICENSE +21 -0
- package/format-notices/flac/NOTICE +14 -0
- package/format-notices/gif/LICENSE +21 -0
- package/format-notices/gif/NOTICE +14 -0
- package/format-notices/gltf/LICENSE +21 -0
- package/format-notices/gltf/NOTICE +27 -0
- package/format-notices/jpeg/LICENSE +21 -0
- package/format-notices/jpeg/NOTICE +14 -0
- package/format-notices/mp3/LICENSE +21 -0
- package/format-notices/mp3/NOTICE +14 -0
- package/format-notices/mp4/LICENSE +21 -0
- package/format-notices/mp4/NOTICE +14 -0
- package/format-notices/obj/LICENSE +21 -0
- package/format-notices/obj/NOTICE +26 -0
- package/format-notices/ogg/LICENSE +21 -0
- package/format-notices/ogg/NOTICE +28 -0
- package/format-notices/png/LICENSE +21 -0
- package/format-notices/png/NOTICE +14 -0
- package/format-notices/red/LICENSE +21 -0
- package/format-notices/red/NOTICE +31 -0
- package/format-notices/stl/LICENSE +21 -0
- package/format-notices/stl/NOTICE +21 -0
- package/format-notices/tga/LICENSE +21 -0
- package/format-notices/tga/NOTICE +14 -0
- package/format-notices/wav/LICENSE +21 -0
- package/format-notices/wav/NOTICE +14 -0
- package/format-notices/webm/LICENSE +21 -0
- package/format-notices/webm/NOTICE +14 -0
- package/format-notices/webp/LICENSE +21 -0
- package/format-notices/webp/NOTICE +14 -0
- package/format-notices/wem/LICENSE +57 -0
- package/format-notices/wem/NOTICE +33 -0
- package/format-notices/yaml/LICENSE +21 -0
- package/format-notices/yaml/NOTICE +44 -0
- package/package.json +51 -0
- package/resource-lifecycle.md +487 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { DEFAULT_VALUES, normalizeValues, validateClassKey, validateClass, readWithValues, inspectWithValues, toJsonValue, importNodeModule, OUTPUT_JSON, OUTPUT_GLTF_JSON, OUTPUT_SHARED, OUTPUT_GR2, OUTPUT_CMF, CLASS_KEYS } from './core/helpers.js';
|
|
2
|
+
import { isGlb, toBytes } from './core/parser.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Exposed CarbonEngineJS-facing glTF/GLB format class.
|
|
6
|
+
*
|
|
7
|
+
* Keep this file small and reviewable: glTF parsing, accessor decoding,
|
|
8
|
+
* mesh conversion, skin conversion, animation conversion, and geometry helper
|
|
9
|
+
* glue live under src/core.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const FORMAT_NAME = "CjsGltfFormat";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* CarbonEngineJS-facing glTF/GLB format surface.
|
|
16
|
+
*
|
|
17
|
+
* The Cjs prefix marks this as a JavaScript format/construction boundary.
|
|
18
|
+
* glTF is the import source; the public read contract is the shared
|
|
19
|
+
* CarbonEngineJS JSON mesh, skeleton, and animation schema.
|
|
20
|
+
*/
|
|
21
|
+
class CjsGltfFormat {
|
|
22
|
+
#emit = DEFAULT_VALUES.emit;
|
|
23
|
+
#source = DEFAULT_VALUES.source;
|
|
24
|
+
#buffers = DEFAULT_VALUES.buffers;
|
|
25
|
+
#packTangents = DEFAULT_VALUES.packTangents;
|
|
26
|
+
#uvHandedness = DEFAULT_VALUES.uvHandedness;
|
|
27
|
+
#rebuildMissingNormals = DEFAULT_VALUES.rebuildMissingNormals;
|
|
28
|
+
#rebuildMissingTangents = DEFAULT_VALUES.rebuildMissingTangents;
|
|
29
|
+
#rebuildMissingBiNormals = DEFAULT_VALUES.rebuildMissingBiNormals;
|
|
30
|
+
#classes = DEFAULT_VALUES.classes;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a reusable format profile.
|
|
34
|
+
*
|
|
35
|
+
* @param {object} [options] Default format values.
|
|
36
|
+
*/
|
|
37
|
+
constructor(options = {}) {
|
|
38
|
+
this.SetValues(options);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Set format values for this reusable profile.
|
|
43
|
+
*
|
|
44
|
+
* @param {object} [options] Values to merge into the profile.
|
|
45
|
+
* @returns {CjsGltfFormat} This format profile.
|
|
46
|
+
*/
|
|
47
|
+
SetValues(options = {}) {
|
|
48
|
+
const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);
|
|
49
|
+
this.#emit = values.emit;
|
|
50
|
+
this.#source = values.source;
|
|
51
|
+
this.#buffers = values.buffers;
|
|
52
|
+
this.#packTangents = values.packTangents;
|
|
53
|
+
this.#uvHandedness = values.uvHandedness;
|
|
54
|
+
this.#rebuildMissingNormals = values.rebuildMissingNormals;
|
|
55
|
+
this.#rebuildMissingTangents = values.rebuildMissingTangents;
|
|
56
|
+
this.#rebuildMissingBiNormals = values.rebuildMissingBiNormals;
|
|
57
|
+
this.#classes = values.classes;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get this profile's current values, optionally with per-call overrides.
|
|
63
|
+
*
|
|
64
|
+
* @param {object} [options] Optional values to merge into a copy.
|
|
65
|
+
* @returns {object} A copy of the effective values.
|
|
66
|
+
*/
|
|
67
|
+
GetValues(options = {}) {
|
|
68
|
+
return normalizeValues({
|
|
69
|
+
emit: this.#emit,
|
|
70
|
+
source: this.#source,
|
|
71
|
+
buffers: this.#buffers,
|
|
72
|
+
packTangents: this.#packTangents,
|
|
73
|
+
uvHandedness: this.#uvHandedness,
|
|
74
|
+
rebuildMissingNormals: this.#rebuildMissingNormals,
|
|
75
|
+
rebuildMissingTangents: this.#rebuildMissingTangents,
|
|
76
|
+
rebuildMissingBiNormals: this.#rebuildMissingBiNormals,
|
|
77
|
+
classes: this.#classes
|
|
78
|
+
}, options, FORMAT_NAME);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Set multiple node-class constructors for this profile.
|
|
83
|
+
*
|
|
84
|
+
* @param {object} [classes] Map of node class keys to constructors.
|
|
85
|
+
* @returns {CjsGltfFormat} This format profile.
|
|
86
|
+
*/
|
|
87
|
+
SetClasses(classes = {}) {
|
|
88
|
+
return this.SetValues({
|
|
89
|
+
classes
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Set one node-class constructor for this profile.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} type Node class key.
|
|
97
|
+
* @param {Function|null|undefined} Class Constructor to use, or nullish to delete.
|
|
98
|
+
* @returns {CjsGltfFormat} This format profile.
|
|
99
|
+
*/
|
|
100
|
+
SetClass(type, Class) {
|
|
101
|
+
if (Class === null || Class === undefined) {
|
|
102
|
+
validateClassKey(type, FORMAT_NAME);
|
|
103
|
+
const classes = {
|
|
104
|
+
...this.#classes
|
|
105
|
+
};
|
|
106
|
+
delete classes[type];
|
|
107
|
+
this.#classes = classes;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
validateClass(type, Class, FORMAT_NAME);
|
|
111
|
+
return this.SetValues({
|
|
112
|
+
classes: {
|
|
113
|
+
[type]: Class
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get a configured node-class constructor.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} type Node class key.
|
|
122
|
+
* @returns {Function|undefined} The registered constructor, if any.
|
|
123
|
+
*/
|
|
124
|
+
GetClass(type) {
|
|
125
|
+
validateClassKey(type, FORMAT_NAME);
|
|
126
|
+
return this.#classes[type];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Whether this format profile has a constructor registered for a node key.
|
|
131
|
+
*
|
|
132
|
+
* @param {string} type Node class key.
|
|
133
|
+
* @returns {boolean} True when a constructor is registered.
|
|
134
|
+
*/
|
|
135
|
+
HasClass(type) {
|
|
136
|
+
return !!this.GetClass(type);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Read glTF/GLB data with this profile's values.
|
|
141
|
+
*
|
|
142
|
+
* @param {object|string|Uint8Array|ArrayBuffer|DataView} input glTF object, JSON text/bytes, or GLB bytes.
|
|
143
|
+
* @param {object} [options] Per-call value overrides.
|
|
144
|
+
* @returns {object} The shared CarbonEngineJS JSON geometry schema.
|
|
145
|
+
*/
|
|
146
|
+
Read(input, options = {}) {
|
|
147
|
+
return readWithValues(this, input, this.GetValues(options));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Inspect glTF/GLB data without hydrating classes.
|
|
152
|
+
*
|
|
153
|
+
* @param {object|string|Uint8Array|ArrayBuffer|DataView} input glTF object, JSON text/bytes, or GLB bytes.
|
|
154
|
+
* @param {object} [options] Per-call value overrides.
|
|
155
|
+
* @returns {object} Plain summary data.
|
|
156
|
+
*/
|
|
157
|
+
Inspect(input, options = {}) {
|
|
158
|
+
return inspectWithValues(input, this.GetValues(options));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Convert format output to JSON-compatible data.
|
|
163
|
+
*
|
|
164
|
+
* @param {any} value Format output to convert.
|
|
165
|
+
* @returns {any} Plain JSON-compatible data.
|
|
166
|
+
*/
|
|
167
|
+
ToJSON(value) {
|
|
168
|
+
return toJsonValue(value);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Static one-shot read. Static methods use camelCase by convention.
|
|
173
|
+
*
|
|
174
|
+
* @param {object|string|Uint8Array|ArrayBuffer|DataView} input glTF object, JSON text/bytes, or GLB bytes.
|
|
175
|
+
* @param {object} [options] Format values.
|
|
176
|
+
* @returns {object} The shared CarbonEngineJS JSON geometry schema.
|
|
177
|
+
*/
|
|
178
|
+
static read(input, options = {}) {
|
|
179
|
+
return readWithValues(CjsGltfFormat, input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Static one-shot inspection.
|
|
184
|
+
*
|
|
185
|
+
* @param {object|string|Uint8Array|ArrayBuffer|DataView} input glTF object, JSON text/bytes, or GLB bytes.
|
|
186
|
+
* @param {object} [options] Format values.
|
|
187
|
+
* @returns {object} Plain summary data.
|
|
188
|
+
*/
|
|
189
|
+
static inspect(input, options = {}) {
|
|
190
|
+
return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Static JSON-compatible conversion.
|
|
195
|
+
*
|
|
196
|
+
* @param {any} value Format output to convert.
|
|
197
|
+
* @returns {any} Plain JSON-compatible data.
|
|
198
|
+
*/
|
|
199
|
+
static toJSON(value) {
|
|
200
|
+
return toJsonValue(value);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Node-only convenience: reads a glTF or GLB file from disk.
|
|
205
|
+
*
|
|
206
|
+
* External `.bin` buffers referenced by relative URI are loaded beside the
|
|
207
|
+
* `.gltf` file. GLB binary chunks are handled directly.
|
|
208
|
+
*
|
|
209
|
+
* @param {string} path Path to a `.gltf` or `.glb` file.
|
|
210
|
+
* @param {object} [options] Format values.
|
|
211
|
+
* @returns {Promise<object>} The shared CarbonEngineJS JSON geometry schema.
|
|
212
|
+
*/
|
|
213
|
+
static async readFile(path, options = {}) {
|
|
214
|
+
if (typeof path !== "string" || !path) {
|
|
215
|
+
throw new TypeError(`${FORMAT_NAME}: readFile path must be a non-empty string`);
|
|
216
|
+
}
|
|
217
|
+
const fs = await importNodeModule("node:fs/promises"),
|
|
218
|
+
pathModule = await importNodeModule("node:path"),
|
|
219
|
+
input = await fs.readFile(path);
|
|
220
|
+
if (isGlb(input)) {
|
|
221
|
+
return CjsGltfFormat.read(input, {
|
|
222
|
+
source: path,
|
|
223
|
+
...options
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const text = new TextDecoder().decode(input),
|
|
227
|
+
gltf = JSON.parse(text),
|
|
228
|
+
buffers = {};
|
|
229
|
+
for (const buffer of gltf.buffers || []) {
|
|
230
|
+
if (!buffer.uri || buffer.uri.startsWith("data:")) continue;
|
|
231
|
+
const uri = decodeURIComponent(buffer.uri);
|
|
232
|
+
buffers[buffer.uri] = await fs.readFile(pathModule.resolve(pathModule.dirname(path), uri));
|
|
233
|
+
}
|
|
234
|
+
return CjsGltfFormat.read(gltf, {
|
|
235
|
+
source: path,
|
|
236
|
+
buffers,
|
|
237
|
+
...options
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Cheap payload sniff for GLB bytes.
|
|
243
|
+
*
|
|
244
|
+
* @param {Uint8Array|ArrayBuffer|DataView} input Candidate bytes.
|
|
245
|
+
* @returns {boolean} True when the payload starts with GLB magic.
|
|
246
|
+
*/
|
|
247
|
+
static isGlb(input) {
|
|
248
|
+
return isGlb(input);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Cheap object/text/bytes sniff for glTF-like assets.
|
|
253
|
+
*
|
|
254
|
+
* @param {object|string|Uint8Array|ArrayBuffer|DataView} input Candidate glTF data.
|
|
255
|
+
* @returns {boolean} True when the input looks like glTF 2.x or GLB.
|
|
256
|
+
*/
|
|
257
|
+
static isGltf(input) {
|
|
258
|
+
try {
|
|
259
|
+
if (isGlb(input)) return true;
|
|
260
|
+
if (input && typeof input === "object" && !ArrayBuffer.isView(input) && !(input instanceof ArrayBuffer)) {
|
|
261
|
+
return !!(input.asset && String(input.asset.version || "").startsWith("2"));
|
|
262
|
+
}
|
|
263
|
+
const text = typeof input === "string" ? input : new TextDecoder().decode(toBytes(input));
|
|
264
|
+
const json = JSON.parse(text);
|
|
265
|
+
return !!(json.asset && String(json.asset.version || "").startsWith("2"));
|
|
266
|
+
} catch {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
static OUTPUT_JSON = OUTPUT_JSON;
|
|
271
|
+
static OUTPUT_GLTF_JSON = OUTPUT_GLTF_JSON;
|
|
272
|
+
static OUTPUT_SHARED = OUTPUT_SHARED;
|
|
273
|
+
static OUTPUT_GR2 = OUTPUT_GR2;
|
|
274
|
+
static OUTPUT_CMF = OUTPUT_CMF;
|
|
275
|
+
static CLASS_KEYS = CLASS_KEYS;
|
|
276
|
+
static type = Object.freeze(["geometry"]);
|
|
277
|
+
static mediaTypes = Object.freeze(["geometry"]);
|
|
278
|
+
static inputTypes = Object.freeze(["gltf", "glb"]);
|
|
279
|
+
static outputTypes = Object.freeze([OUTPUT_SHARED, OUTPUT_GR2, OUTPUT_CMF]);
|
|
280
|
+
static debugOutputTypes = Object.freeze([OUTPUT_JSON, OUTPUT_GLTF_JSON]);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export { CjsGltfFormat, CjsGltfFormat as default };
|
|
284
|
+
//# sourceMappingURL=CjsGltfFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CjsGltfFormat.js","sources":["../../../../src/formats/gltf/CjsGltfFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing glTF/GLB format class.\n *\n * Keep this file small and reviewable: glTF parsing, accessor decoding,\n * mesh conversion, skin conversion, animation conversion, and geometry helper\n * glue live under src/core.\n */\n\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_CMF,\n OUTPUT_GLTF_JSON,\n OUTPUT_GR2,\n OUTPUT_JSON,\n OUTPUT_SHARED,\n importNodeModule,\n inspectWithValues,\n isGlb,\n normalizeValues,\n readWithValues,\n toBytes,\n toJsonValue,\n validateClass,\n validateClassKey\n} from \"./core/helpers.js\";\n\nconst FORMAT_NAME = \"CjsGltfFormat\";\n\n/**\n * CarbonEngineJS-facing glTF/GLB format surface.\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * glTF is the import source; the public read contract is the shared\n * CarbonEngineJS JSON mesh, skeleton, and animation schema.\n */\nexport class CjsGltfFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n #buffers = DEFAULT_VALUES.buffers;\n #packTangents = DEFAULT_VALUES.packTangents;\n #uvHandedness = DEFAULT_VALUES.uvHandedness;\n #rebuildMissingNormals = DEFAULT_VALUES.rebuildMissingNormals;\n #rebuildMissingTangents = DEFAULT_VALUES.rebuildMissingTangents;\n #rebuildMissingBiNormals = DEFAULT_VALUES.rebuildMissingBiNormals;\n #classes = DEFAULT_VALUES.classes;\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 {CjsGltfFormat} 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 this.#buffers = values.buffers;\n this.#packTangents = values.packTangents;\n this.#uvHandedness = values.uvHandedness;\n this.#rebuildMissingNormals = values.rebuildMissingNormals;\n this.#rebuildMissingTangents = values.rebuildMissingTangents;\n this.#rebuildMissingBiNormals = values.rebuildMissingBiNormals;\n this.#classes = values.classes;\n\n return this;\n }\n\n /**\n * Get this profile's current values, optionally with per-call overrides.\n *\n * @param {object} [options] Optional values to merge into a copy.\n * @returns {object} A copy of the effective values.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n source: this.#source,\n buffers: this.#buffers,\n packTangents: this.#packTangents,\n uvHandedness: this.#uvHandedness,\n rebuildMissingNormals: this.#rebuildMissingNormals,\n rebuildMissingTangents: this.#rebuildMissingTangents,\n rebuildMissingBiNormals: this.#rebuildMissingBiNormals,\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 {CjsGltfFormat} 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 {CjsGltfFormat} 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 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 glTF/GLB data with this profile's values.\n *\n * @param {object|string|Uint8Array|ArrayBuffer|DataView} input glTF object, JSON text/bytes, or GLB bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} The shared CarbonEngineJS JSON geometry schema.\n */\n Read(input, options = {})\n {\n return readWithValues(this, input, this.GetValues(options));\n }\n\n /**\n * Inspect glTF/GLB data without hydrating classes.\n *\n * @param {object|string|Uint8Array|ArrayBuffer|DataView} input glTF object, JSON text/bytes, or GLB 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 * 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 {object|string|Uint8Array|ArrayBuffer|DataView} input glTF object, JSON text/bytes, or GLB bytes.\n * @param {object} [options] Format values.\n * @returns {object} The shared CarbonEngineJS JSON geometry schema.\n */\n static read(input, options = {})\n {\n return readWithValues(CjsGltfFormat, input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {object|string|Uint8Array|ArrayBuffer|DataView} input glTF object, JSON text/bytes, or GLB 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 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 a glTF or GLB file from disk.\n *\n * External `.bin` buffers referenced by relative URI are loaded beside the\n * `.gltf` file. GLB binary chunks are handled directly.\n *\n * @param {string} path Path to a `.gltf` or `.glb` file.\n * @param {object} [options] Format values.\n * @returns {Promise<object>} The shared CarbonEngineJS JSON geometry 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\n fs = await importNodeModule(\"node:fs/promises\"),\n pathModule = await importNodeModule(\"node:path\"),\n input = await fs.readFile(path);\n\n if (isGlb(input))\n {\n return CjsGltfFormat.read(input, { source: path, ...options });\n }\n\n const\n text = new TextDecoder().decode(input),\n gltf = JSON.parse(text),\n buffers = {};\n\n for (const buffer of gltf.buffers || [])\n {\n if (!buffer.uri || buffer.uri.startsWith(\"data:\")) continue;\n const uri = decodeURIComponent(buffer.uri);\n buffers[buffer.uri] = await fs.readFile(pathModule.resolve(pathModule.dirname(path), uri));\n }\n\n return CjsGltfFormat.read(gltf, { source: path, buffers, ...options });\n }\n\n /**\n * Cheap payload sniff for GLB bytes.\n *\n * @param {Uint8Array|ArrayBuffer|DataView} input Candidate bytes.\n * @returns {boolean} True when the payload starts with GLB magic.\n */\n static isGlb(input)\n {\n return isGlb(input);\n }\n\n /**\n * Cheap object/text/bytes sniff for glTF-like assets.\n *\n * @param {object|string|Uint8Array|ArrayBuffer|DataView} input Candidate glTF data.\n * @returns {boolean} True when the input looks like glTF 2.x or GLB.\n */\n static isGltf(input)\n {\n try\n {\n if (isGlb(input)) return true;\n if (input && typeof input === \"object\" && !ArrayBuffer.isView(input) && !(input instanceof ArrayBuffer))\n {\n return !!(input.asset && String(input.asset.version || \"\").startsWith(\"2\"));\n }\n const text = typeof input === \"string\" ? input : new TextDecoder().decode(toBytes(input));\n const json = JSON.parse(text);\n return !!(json.asset && String(json.asset.version || \"\").startsWith(\"2\"));\n }\n catch\n {\n return false;\n }\n }\n\n static OUTPUT_JSON = OUTPUT_JSON;\n static OUTPUT_GLTF_JSON = OUTPUT_GLTF_JSON;\n static OUTPUT_SHARED = OUTPUT_SHARED;\n static OUTPUT_GR2 = OUTPUT_GR2;\n static OUTPUT_CMF = OUTPUT_CMF;\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"geometry\" ]);\n static mediaTypes = Object.freeze([ \"geometry\" ]);\n static inputTypes = Object.freeze([ \"gltf\", \"glb\" ]);\n static outputTypes = Object.freeze([ OUTPUT_SHARED, OUTPUT_GR2, OUTPUT_CMF ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_GLTF_JSON ]);\n\n}\n\nexport default CjsGltfFormat;\n"],"names":["FORMAT_NAME","CjsGltfFormat","DEFAULT_VALUES","emit","source","buffers","packTangents","uvHandedness","rebuildMissingNormals","rebuildMissingTangents","rebuildMissingBiNormals","classes","constructor","options","SetValues","values","normalizeValues","GetValues","SetClasses","SetClass","type","Class","undefined","validateClassKey","validateClass","GetClass","HasClass","Read","input","readWithValues","Inspect","inspectWithValues","ToJSON","value","toJsonValue","read","inspect","toJSON","readFile","path","TypeError","fs","importNodeModule","pathModule","isGlb","text","TextDecoder","decode","gltf","JSON","parse","buffer","uri","startsWith","decodeURIComponent","resolve","dirname","isGltf","ArrayBuffer","isView","asset","String","version","toBytes","json","OUTPUT_JSON","OUTPUT_GLTF_JSON","OUTPUT_SHARED","OUTPUT_GR2","OU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
import { CLASS_KEYS as CLASS_KEYS$1, hydrateJson } from './json.js';
|
|
2
|
+
import { CMF_CLASS_KEYS, hydrateCmf, buildCmfFromShared } from './targets.js';
|
|
3
|
+
import { parseInput, parseGltfToJson, inspectGltf } from './parser.js';
|
|
4
|
+
export { isGlb, toBytes } from './parser.js';
|
|
5
|
+
import { generateNormals, generateTangents, generateBiNormals } from '@carbonenginejs/core-math/mesh';
|
|
6
|
+
import { packTangentFrames } from '@carbonenginejs/core-math/tangent';
|
|
7
|
+
import { normalize, cross } from '@carbonenginejs/core-math/vec3';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal read-pipeline glue for CjsGltfFormat.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const CLASS_KEYS = Object.freeze(Array.from(new Set([...CLASS_KEYS$1, ...CMF_CLASS_KEYS])));
|
|
14
|
+
const OUTPUT_JSON = "json";
|
|
15
|
+
const OUTPUT_GLTF_JSON = "gltfJson";
|
|
16
|
+
const OUTPUT_SHARED = "shared";
|
|
17
|
+
const OUTPUT_GR2 = "gr2";
|
|
18
|
+
const OUTPUT_CMF = "cmf";
|
|
19
|
+
const DEFAULT_VALUES = Object.freeze({
|
|
20
|
+
emit: OUTPUT_GLTF_JSON,
|
|
21
|
+
source: "memory",
|
|
22
|
+
buffers: null,
|
|
23
|
+
packTangents: false,
|
|
24
|
+
uvHandedness: "right",
|
|
25
|
+
rebuildMissingNormals: false,
|
|
26
|
+
rebuildMissingTangents: false,
|
|
27
|
+
rebuildMissingBiNormals: false,
|
|
28
|
+
classes: Object.freeze({})
|
|
29
|
+
});
|
|
30
|
+
const OPTION_KEYS = new Set(["emit", "source", "buffers", "packTangents", "uvHandedness", "rebuildMissingNormals", "rebuildMissingTangents", "rebuildMissingBiNormals", "classes"]);
|
|
31
|
+
function validateClassKey(key, readerName = "CjsGltfFormat") {
|
|
32
|
+
if (!CLASS_KEYS.includes(key)) {
|
|
33
|
+
throw new Error(`${readerName}: unknown class key ${JSON.stringify(key)}; expected one of ${CLASS_KEYS.join(", ")}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function validateClass(key, Class, readerName = "CjsGltfFormat") {
|
|
37
|
+
validateClassKey(key, readerName);
|
|
38
|
+
if (typeof Class !== "function") {
|
|
39
|
+
throw new TypeError(`${readerName}: class ${JSON.stringify(key)} must be a constructor`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function mergeClasses(base, classes, readerName) {
|
|
43
|
+
if (!classes || typeof classes !== "object") {
|
|
44
|
+
throw new TypeError(`${readerName}: classes option must be an object`);
|
|
45
|
+
}
|
|
46
|
+
const next = {
|
|
47
|
+
...base
|
|
48
|
+
};
|
|
49
|
+
for (const [key, Class] of Object.entries(classes)) {
|
|
50
|
+
if (Class === null || Class === undefined) {
|
|
51
|
+
delete next[key];
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
validateClass(key, Class, readerName);
|
|
55
|
+
next[key] = Class;
|
|
56
|
+
}
|
|
57
|
+
return next;
|
|
58
|
+
}
|
|
59
|
+
function validateRule(name, value, readerName) {
|
|
60
|
+
if (typeof value === "boolean" || typeof value === "function") return value;
|
|
61
|
+
throw new TypeError(`${readerName}: ${name} must be true, false, or a function`);
|
|
62
|
+
}
|
|
63
|
+
function normalizeUvHandedness(value, readerName) {
|
|
64
|
+
if (value === undefined || value === null) return DEFAULT_VALUES.uvHandedness;
|
|
65
|
+
if (value === "right" || value === 1 || value === "positive") return "right";
|
|
66
|
+
if (value === "left" || value === -1 || value === "negative") return "left";
|
|
67
|
+
throw new TypeError(`${readerName}: uvHandedness must be "right" or "left"`);
|
|
68
|
+
}
|
|
69
|
+
function normalizeValues(base, options = {}, readerName = "CjsGltfFormat") {
|
|
70
|
+
if (!options || typeof options !== "object") {
|
|
71
|
+
throw new TypeError(`${readerName}: options must be an object`);
|
|
72
|
+
}
|
|
73
|
+
for (const key of Object.keys(options)) {
|
|
74
|
+
if (!OPTION_KEYS.has(key)) {
|
|
75
|
+
throw new TypeError(`${readerName}: unknown option ${JSON.stringify(key)}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const values = {
|
|
79
|
+
...base,
|
|
80
|
+
...options
|
|
81
|
+
};
|
|
82
|
+
const emit = normalizeEmit(values.emit, readerName);
|
|
83
|
+
const classes = Object.prototype.hasOwnProperty.call(options, "classes") ? mergeClasses(base.classes || {}, options.classes, readerName) : {
|
|
84
|
+
...(base.classes || {})
|
|
85
|
+
};
|
|
86
|
+
if ((emit === OUTPUT_GR2 || emit === OUTPUT_CMF) && !hasClasses(classes)) {
|
|
87
|
+
throw new TypeError(`${readerName}: emit "${emit}" requires explicit classes`);
|
|
88
|
+
}
|
|
89
|
+
if (typeof values.source !== "string" || !values.source) {
|
|
90
|
+
values.source = DEFAULT_VALUES.source;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
emit,
|
|
94
|
+
source: values.source,
|
|
95
|
+
buffers: values.buffers || null,
|
|
96
|
+
packTangents: validateRule("packTangents", values.packTangents, readerName),
|
|
97
|
+
uvHandedness: normalizeUvHandedness(values.uvHandedness, readerName),
|
|
98
|
+
rebuildMissingNormals: validateRule("rebuildMissingNormals", values.rebuildMissingNormals, readerName),
|
|
99
|
+
rebuildMissingTangents: validateRule("rebuildMissingTangents", values.rebuildMissingTangents, readerName),
|
|
100
|
+
rebuildMissingBiNormals: validateRule("rebuildMissingBiNormals", values.rebuildMissingBiNormals, readerName),
|
|
101
|
+
classes
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function normalizeEmit(emit, readerName) {
|
|
105
|
+
if (emit === undefined || emit === null || emit === OUTPUT_JSON || emit === OUTPUT_GLTF_JSON || emit === OUTPUT_SHARED) {
|
|
106
|
+
return OUTPUT_GLTF_JSON;
|
|
107
|
+
}
|
|
108
|
+
if (emit === OUTPUT_GR2 || emit === OUTPUT_CMF) return emit;
|
|
109
|
+
throw new TypeError(`${readerName}: emit must be "${OUTPUT_SHARED}", "${OUTPUT_GLTF_JSON}", "${OUTPUT_GR2}", or "${OUTPUT_CMF}", got ${JSON.stringify(emit)}`);
|
|
110
|
+
}
|
|
111
|
+
function hasClasses(classes) {
|
|
112
|
+
return !!classes && Object.values(classes).some(Class => typeof Class === "function");
|
|
113
|
+
}
|
|
114
|
+
function hasVertexChannel(mesh, channel) {
|
|
115
|
+
const value = mesh && mesh.vertex && mesh.vertex[channel];
|
|
116
|
+
return !!value && value.length > 0;
|
|
117
|
+
}
|
|
118
|
+
function requireVertexChannel(mesh, meshIndex, channel, feature) {
|
|
119
|
+
const value = mesh && mesh.vertex && mesh.vertex[channel];
|
|
120
|
+
if (!value || value.length === 0) {
|
|
121
|
+
const name = mesh && mesh.name ? JSON.stringify(mesh.name) : `#${meshIndex}`;
|
|
122
|
+
throw new Error(`CjsGltfFormat: ${feature} requires mesh.vertex.${channel} for mesh ${name}`);
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
function triangleFaces(mesh, meshIndex, feature) {
|
|
127
|
+
const faces = [];
|
|
128
|
+
for (const group of mesh.indices || []) {
|
|
129
|
+
if (group && group.faces) faces.push(...group.faces);
|
|
130
|
+
}
|
|
131
|
+
if (faces.length === 0) {
|
|
132
|
+
const name = mesh && mesh.name ? JSON.stringify(mesh.name) : `#${meshIndex}`;
|
|
133
|
+
throw new Error(`CjsGltfFormat: ${feature} requires triangle indices for mesh ${name}`);
|
|
134
|
+
}
|
|
135
|
+
return faces;
|
|
136
|
+
}
|
|
137
|
+
function shouldApplyMeshRule(format, rule, context) {
|
|
138
|
+
if (typeof rule === "function") {
|
|
139
|
+
const result = rule({
|
|
140
|
+
format,
|
|
141
|
+
reader: format,
|
|
142
|
+
...context
|
|
143
|
+
});
|
|
144
|
+
if (typeof result !== "boolean") {
|
|
145
|
+
throw new TypeError(`CjsGltfFormat: ${context.feature} rule must return true or false`);
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
return rule;
|
|
150
|
+
}
|
|
151
|
+
function vertexCount(mesh) {
|
|
152
|
+
return mesh.vertex.position.length / 3;
|
|
153
|
+
}
|
|
154
|
+
function tangentXyz(mesh) {
|
|
155
|
+
const tangent = requireVertexChannel(mesh, 0, "tangent", "tangent conversion"),
|
|
156
|
+
count = vertexCount(mesh),
|
|
157
|
+
width = tangent.length / count;
|
|
158
|
+
if (width === 3) return tangent.slice();
|
|
159
|
+
if (width !== 4) throw new Error("CjsGltfFormat: tangent channel must have 3 or 4 components per vertex");
|
|
160
|
+
const out = new Array(count * 3);
|
|
161
|
+
for (let i = 0, o = 0; i < tangent.length; i += 4, o += 3) {
|
|
162
|
+
out[o] = tangent[i];
|
|
163
|
+
out[o + 1] = tangent[i + 1];
|
|
164
|
+
out[o + 2] = tangent[i + 2];
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
function generatedBiNormalsForMesh(mesh, values) {
|
|
169
|
+
const normals = requireVertexChannel(mesh, 0, "normal", "binormal generation"),
|
|
170
|
+
tangent = requireVertexChannel(mesh, 0, "tangent", "binormal generation"),
|
|
171
|
+
count = vertexCount(mesh),
|
|
172
|
+
width = tangent.length / count;
|
|
173
|
+
if (width === 3) {
|
|
174
|
+
return generateBiNormals(normals, tangent, {
|
|
175
|
+
uvHandedness: values.uvHandedness
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (width !== 4) throw new Error("CjsGltfFormat: tangent channel must have 3 or 4 components per vertex");
|
|
179
|
+
const out = new Array(count * 3);
|
|
180
|
+
for (let i = 0, o = 0; i < tangent.length; i += 4, o += 3) {
|
|
181
|
+
const b = normalize([0, 0, 0], cross([0, 0, 0], [normals[o], normals[o + 1], normals[o + 2]], [tangent[i], tangent[i + 1], tangent[i + 2]]));
|
|
182
|
+
const sign = tangent[i + 3] < 0 ? -1 : 1;
|
|
183
|
+
out[o] = b[0] * sign;
|
|
184
|
+
out[o + 1] = b[1] * sign;
|
|
185
|
+
out[o + 2] = b[2] * sign;
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
function rebuildMissingMeshData(format, json, values) {
|
|
190
|
+
for (let meshIndex = 0; meshIndex < json.meshes.length; meshIndex++) {
|
|
191
|
+
const mesh = json.meshes[meshIndex],
|
|
192
|
+
common = {
|
|
193
|
+
options: values,
|
|
194
|
+
raw: null,
|
|
195
|
+
json,
|
|
196
|
+
mesh,
|
|
197
|
+
meshIndex
|
|
198
|
+
},
|
|
199
|
+
shouldPackTangents = shouldApplyMeshRule(format, values.packTangents, {
|
|
200
|
+
...common,
|
|
201
|
+
feature: "packTangents",
|
|
202
|
+
channel: "tangent"
|
|
203
|
+
});
|
|
204
|
+
if (!hasVertexChannel(mesh, "normal") && (shouldApplyMeshRule(format, values.rebuildMissingNormals, {
|
|
205
|
+
...common,
|
|
206
|
+
feature: "rebuildMissingNormals",
|
|
207
|
+
channel: "normal"
|
|
208
|
+
}) || shouldPackTangents)) {
|
|
209
|
+
mesh.vertex.normal = generateNormals(requireVertexChannel(mesh, meshIndex, "position", "rebuildMissingNormals"), triangleFaces(mesh, meshIndex, "rebuildMissingNormals"));
|
|
210
|
+
}
|
|
211
|
+
if (!hasVertexChannel(mesh, "tangent") && (shouldApplyMeshRule(format, values.rebuildMissingTangents, {
|
|
212
|
+
...common,
|
|
213
|
+
feature: "rebuildMissingTangents",
|
|
214
|
+
channel: "tangent"
|
|
215
|
+
}) || shouldPackTangents)) {
|
|
216
|
+
mesh.vertex.tangent = generateTangents(requireVertexChannel(mesh, meshIndex, "position", "rebuildMissingTangents"), requireVertexChannel(mesh, meshIndex, "normal", "rebuildMissingTangents"), requireVertexChannel(mesh, meshIndex, "texcoord0", "rebuildMissingTangents"), triangleFaces(mesh, meshIndex, "rebuildMissingTangents"));
|
|
217
|
+
}
|
|
218
|
+
if (!hasVertexChannel(mesh, "binormal") && (shouldApplyMeshRule(format, values.rebuildMissingBiNormals, {
|
|
219
|
+
...common,
|
|
220
|
+
feature: "rebuildMissingBiNormals",
|
|
221
|
+
channel: "binormal"
|
|
222
|
+
}) || shouldPackTangents)) {
|
|
223
|
+
mesh.vertex.binormal = generatedBiNormalsForMesh(mesh, values);
|
|
224
|
+
}
|
|
225
|
+
if (shouldPackTangents) {
|
|
226
|
+
mesh.vertex.tangent = packTangentFrames(requireVertexChannel(mesh, meshIndex, "normal", "packTangents"), tangentXyz(mesh), requireVertexChannel(mesh, meshIndex, "binormal", "packTangents"));
|
|
227
|
+
mesh.vertex.normal = [];
|
|
228
|
+
mesh.vertex.binormal = [];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function readWithValues(format, input, values) {
|
|
233
|
+
const parsed = parseInput(input);
|
|
234
|
+
const json = parseGltfToJson(parsed.gltf, {
|
|
235
|
+
binaryChunk: parsed.binaryChunk,
|
|
236
|
+
source: values.source,
|
|
237
|
+
buffers: values.buffers
|
|
238
|
+
});
|
|
239
|
+
rebuildMissingMeshData(format, json, values);
|
|
240
|
+
if (values.emit === OUTPUT_CMF) return hydrateCmf(buildCmfFromShared(json), values.classes, {
|
|
241
|
+
source: values.source
|
|
242
|
+
});
|
|
243
|
+
return hydrateJson(json, {
|
|
244
|
+
classes: values.classes,
|
|
245
|
+
source: values.source
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function inspectWithValues(input, values) {
|
|
249
|
+
const parsed = parseInput(input);
|
|
250
|
+
return inspectGltf(parsed.gltf, {
|
|
251
|
+
format: parsed.format,
|
|
252
|
+
source: values.source
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function toJsonValue(value) {
|
|
256
|
+
if (value === null || value === undefined) return value;
|
|
257
|
+
if (typeof value !== "object") return value;
|
|
258
|
+
if (typeof value.toJSON === "function") {
|
|
259
|
+
const next = value.toJSON();
|
|
260
|
+
if (next !== value) return toJsonValue(next);
|
|
261
|
+
}
|
|
262
|
+
if (Array.isArray(value)) return value.map(toJsonValue);
|
|
263
|
+
if (ArrayBuffer.isView(value) && !(value instanceof DataView)) return Array.from(value);
|
|
264
|
+
const out = {};
|
|
265
|
+
for (const key of Object.keys(value)) {
|
|
266
|
+
out[key] = toJsonValue(value[key]);
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Imports a Node built-in module without exposing the specifier to any
|
|
273
|
+
* bundler's static import graph.
|
|
274
|
+
*
|
|
275
|
+
* `await import("node:fs/promises")` written as a literal is resolved
|
|
276
|
+
* eagerly by webpack/Rollup/esbuild alike when they walk the module
|
|
277
|
+
* graph, breaking browser builds even though this path only ever runs
|
|
278
|
+
* under Node (readFile is a Node-only convenience). Building the
|
|
279
|
+
* specifier inside a `Function` body hides it from every bundler's
|
|
280
|
+
* static analysis - it only exists at runtime, in the Node process that
|
|
281
|
+
* actually calls readFile.
|
|
282
|
+
*
|
|
283
|
+
* @param {string} specifier Node built-in module specifier, e.g. "node:fs/promises".
|
|
284
|
+
* @returns {Promise<any>} The imported module namespace.
|
|
285
|
+
*/
|
|
286
|
+
function importNodeModule(specifier) {
|
|
287
|
+
// eslint-disable-next-line no-new-func
|
|
288
|
+
return new Function("s", "return import(s)")(specifier);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export { CLASS_KEYS, DEFAULT_VALUES, OUTPUT_CMF, OUTPUT_GLTF_JSON, OUTPUT_GR2, OUTPUT_JSON, OUTPUT_SHARED, importNodeModule, inspectWithValues, normalizeValues, readWithValues, toJsonValue, validateClass, validateClassKey };
|
|
292
|
+
//# sourceMappingURL=helpers.js.map
|