@forgeax/engine-assets-runtime 0.0.0-dev.8d955ade1c79
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/LICENSE +202 -0
- package/README.md +491 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/__tests__/aabb.unit.test.d.ts +2 -0
- package/dist/__tests__/aabb.unit.test.d.ts.map +1 -0
- package/dist/__tests__/artifact-integrity.unit.test.d.ts +2 -0
- package/dist/__tests__/artifact-integrity.unit.test.d.ts.map +1 -0
- package/dist/__tests__/artifact-io.unit.test.d.ts +2 -0
- package/dist/__tests__/artifact-io.unit.test.d.ts.map +1 -0
- package/dist/__tests__/asset-evidence-sdk.integration.test.d.ts +2 -0
- package/dist/__tests__/asset-evidence-sdk.integration.test.d.ts.map +1 -0
- package/dist/__tests__/asset-evidence.unit.test.d.ts +2 -0
- package/dist/__tests__/asset-evidence.unit.test.d.ts.map +1 -0
- package/dist/__tests__/asset-kind.unit.test.d.ts +2 -0
- package/dist/__tests__/asset-kind.unit.test.d.ts.map +1 -0
- package/dist/__tests__/asset-registry-catalog-reconcile.integration.test.d.ts +2 -0
- package/dist/__tests__/asset-registry-catalog-reconcile.integration.test.d.ts.map +1 -0
- package/dist/__tests__/asset-registry-catalog-reconcile.unit.test.d.ts +2 -0
- package/dist/__tests__/asset-registry-catalog-reconcile.unit.test.d.ts.map +1 -0
- package/dist/__tests__/asset-registry-catalog.unit.test.d.ts +2 -0
- package/dist/__tests__/asset-registry-catalog.unit.test.d.ts.map +1 -0
- package/dist/__tests__/asset-registry.pack-cache.test.d.ts +2 -0
- package/dist/__tests__/asset-registry.pack-cache.test.d.ts.map +1 -0
- package/dist/__tests__/asset-registry.unit.test.d.ts +2 -0
- package/dist/__tests__/asset-registry.unit.test.d.ts.map +1 -0
- package/dist/__tests__/asset-runtime-error-code-owner.test-d.d.ts +2 -0
- package/dist/__tests__/asset-runtime-error-code-owner.test-d.d.ts.map +1 -0
- package/dist/__tests__/catalog-replica.unit.test.d.ts +2 -0
- package/dist/__tests__/catalog-replica.unit.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-source-v2.unit.test.d.ts +2 -0
- package/dist/__tests__/catalog-source-v2.unit.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-source.unit.test.d.ts +2 -0
- package/dist/__tests__/catalog-source.unit.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-subscription-order.unit.test.d.ts +2 -0
- package/dist/__tests__/catalog-subscription-order.unit.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-subscription.unit.test.d.ts +2 -0
- package/dist/__tests__/catalog-subscription.unit.test.d.ts.map +1 -0
- package/dist/__tests__/decode-image-bytes-pass-through.test.d.ts +2 -0
- package/dist/__tests__/decode-image-bytes-pass-through.test.d.ts.map +1 -0
- package/dist/__tests__/decode-image-bytes.browser.test.d.ts +2 -0
- package/dist/__tests__/decode-image-bytes.browser.test.d.ts.map +1 -0
- package/dist/__tests__/decode-image-bytes.test-d.d.ts +2 -0
- package/dist/__tests__/decode-image-bytes.test-d.d.ts.map +1 -0
- package/dist/__tests__/decode-image-bytes.test.d.ts +2 -0
- package/dist/__tests__/decode-image-bytes.test.d.ts.map +1 -0
- package/dist/__tests__/decode-image-mime-owner.test.d.ts +2 -0
- package/dist/__tests__/decode-image-mime-owner.test.d.ts.map +1 -0
- package/dist/__tests__/dynamic-texture-store.unit.test.d.ts +2 -0
- package/dist/__tests__/dynamic-texture-store.unit.test.d.ts.map +1 -0
- package/dist/__tests__/errors-asset.unit.test.d.ts +2 -0
- package/dist/__tests__/errors-asset.unit.test.d.ts.map +1 -0
- package/dist/__tests__/inline-pack-loaders.unit.test.d.ts +2 -0
- package/dist/__tests__/inline-pack-loaders.unit.test.d.ts.map +1 -0
- package/dist/__tests__/instantiate-context.unit.test.d.ts +2 -0
- package/dist/__tests__/instantiate-context.unit.test.d.ts.map +1 -0
- package/dist/__tests__/instantiate-publication-fence.unit.test.d.ts +2 -0
- package/dist/__tests__/instantiate-publication-fence.unit.test.d.ts.map +1 -0
- package/dist/__tests__/instantiate.unit.test.d.ts +2 -0
- package/dist/__tests__/instantiate.unit.test.d.ts.map +1 -0
- package/dist/__tests__/loader-input-contract.unit.test.d.ts +2 -0
- package/dist/__tests__/loader-input-contract.unit.test.d.ts.map +1 -0
- package/dist/__tests__/loader-registry.unit.test.d.ts +2 -0
- package/dist/__tests__/loader-registry.unit.test.d.ts.map +1 -0
- package/dist/__tests__/material-dependency-invalidation.unit.test.d.ts +2 -0
- package/dist/__tests__/material-dependency-invalidation.unit.test.d.ts.map +1 -0
- package/dist/__tests__/material-generation-cache.unit.test.d.ts +2 -0
- package/dist/__tests__/material-generation-cache.unit.test.d.ts.map +1 -0
- package/dist/__tests__/material-load-consumer.test-d.d.ts +2 -0
- package/dist/__tests__/material-load-consumer.test-d.d.ts.map +1 -0
- package/dist/__tests__/material-ready.integration.test.d.ts +2 -0
- package/dist/__tests__/material-ready.integration.test.d.ts.map +1 -0
- package/dist/__tests__/material-stale-generation.unit.test.d.ts +2 -0
- package/dist/__tests__/material-stale-generation.unit.test.d.ts.map +1 -0
- package/dist/__tests__/mesh-bin-morph-v3.test.d.ts +2 -0
- package/dist/__tests__/mesh-bin-morph-v3.test.d.ts.map +1 -0
- package/dist/__tests__/mesh-bin.unit.test.d.ts +2 -0
- package/dist/__tests__/mesh-bin.unit.test.d.ts.map +1 -0
- package/dist/__tests__/mipmap-generator.unit.test.d.ts +2 -0
- package/dist/__tests__/mipmap-generator.unit.test.d.ts.map +1 -0
- package/dist/__tests__/pack-artifact-transcode-model-owner.test.d.ts +2 -0
- package/dist/__tests__/pack-artifact-transcode-model-owner.test.d.ts.map +1 -0
- package/dist/__tests__/pack-basis-load.integration.test.d.ts +2 -0
- package/dist/__tests__/pack-basis-load.integration.test.d.ts.map +1 -0
- package/dist/__tests__/payload-validate.unit.test.d.ts +2 -0
- package/dist/__tests__/payload-validate.unit.test.d.ts.map +1 -0
- package/dist/__tests__/plugin.test.d.ts +2 -0
- package/dist/__tests__/plugin.test.d.ts.map +1 -0
- package/dist/__tests__/registry-concurrency.bench.test.d.ts +2 -0
- package/dist/__tests__/registry-concurrency.bench.test.d.ts.map +1 -0
- package/dist/__tests__/registry-failure-retry.integration.test.d.ts +2 -0
- package/dist/__tests__/registry-failure-retry.integration.test.d.ts.map +1 -0
- package/dist/__tests__/registry-load-graph.integration.test.d.ts +2 -0
- package/dist/__tests__/registry-load-graph.integration.test.d.ts.map +1 -0
- package/dist/__tests__/registry-load-state.unit.test.d.ts +2 -0
- package/dist/__tests__/registry-load-state.unit.test.d.ts.map +1 -0
- package/dist/__tests__/registry-package-cache.unit.test.d.ts +2 -0
- package/dist/__tests__/registry-package-cache.unit.test.d.ts.map +1 -0
- package/dist/__tests__/registry-public-ready.unit.test.d.ts +2 -0
- package/dist/__tests__/registry-public-ready.unit.test.d.ts.map +1 -0
- package/dist/__tests__/resolve-asset-handle.unit.test.d.ts +2 -0
- package/dist/__tests__/resolve-asset-handle.unit.test.d.ts.map +1 -0
- package/dist/__tests__/scene-handle-fields.unit.test.d.ts +2 -0
- package/dist/__tests__/scene-handle-fields.unit.test.d.ts.map +1 -0
- package/dist/__tests__/scene-payload.unit.test.d.ts +2 -0
- package/dist/__tests__/scene-payload.unit.test.d.ts.map +1 -0
- package/dist/__tests__/scene-publication-fence.test.d.ts +2 -0
- package/dist/__tests__/scene-publication-fence.test.d.ts.map +1 -0
- package/dist/__tests__/scriptable-pack-public-surface.test-d.d.ts +2 -0
- package/dist/__tests__/scriptable-pack-public-surface.test-d.d.ts.map +1 -0
- package/dist/__tests__/static-rig.integration.test.d.ts +2 -0
- package/dist/__tests__/static-rig.integration.test.d.ts.map +1 -0
- package/dist/__tests__/validate-material.unit.test.d.ts +2 -0
- package/dist/__tests__/validate-material.unit.test.d.ts.map +1 -0
- package/dist/__tests__/video-pack-loader.integration.test.d.ts +2 -0
- package/dist/__tests__/video-pack-loader.integration.test.d.ts.map +1 -0
- package/dist/aabb.d.ts +3 -0
- package/dist/aabb.d.ts.map +1 -0
- package/dist/asset-kind.d.ts +4 -0
- package/dist/asset-kind.d.ts.map +1 -0
- package/dist/asset-registry.d.ts +554 -0
- package/dist/asset-registry.d.ts.map +1 -0
- package/dist/builtin-asset-registry.d.ts +22 -0
- package/dist/builtin-asset-registry.d.ts.map +1 -0
- package/dist/catalog-source.d.ts +24 -0
- package/dist/catalog-source.d.ts.map +1 -0
- package/dist/decode-image-bytes.d.ts +57 -0
- package/dist/decode-image-bytes.d.ts.map +1 -0
- package/dist/dynamic-texture-store.d.ts +89 -0
- package/dist/dynamic-texture-store.d.ts.map +1 -0
- package/dist/errors/asset.d.ts +201 -0
- package/dist/errors/asset.d.ts.map +1 -0
- package/dist/handles.d.ts +143 -0
- package/dist/handles.d.ts.map +1 -0
- package/dist/image-error.d.ts +6 -0
- package/dist/image-error.d.ts.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +8359 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal/artifact-cache.d.ts +17 -0
- package/dist/internal/artifact-cache.d.ts.map +1 -0
- package/dist/internal/asset-graph.d.ts +70 -0
- package/dist/internal/asset-graph.d.ts.map +1 -0
- package/dist/internal/catalog-session.d.ts +60 -0
- package/dist/internal/catalog-session.d.ts.map +1 -0
- package/dist/internal/decoder-registry.d.ts +19 -0
- package/dist/internal/decoder-registry.d.ts.map +1 -0
- package/dist/internal/immutable-payload.d.ts +9 -0
- package/dist/internal/immutable-payload.d.ts.map +1 -0
- package/dist/internal/load-asset.d.ts +31 -0
- package/dist/internal/load-asset.d.ts.map +1 -0
- package/dist/internal/pack-reader.d.ts +18 -0
- package/dist/internal/pack-reader.d.ts.map +1 -0
- package/dist/internal/validate-runtime-row.d.ts +7 -0
- package/dist/internal/validate-runtime-row.d.ts.map +1 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.mjs +329 -0
- package/dist/internal.mjs.map +1 -0
- package/dist/loader-registry.d.ts +63 -0
- package/dist/loader-registry.d.ts.map +1 -0
- package/dist/loaders/inline-pack.d.ts +72 -0
- package/dist/loaders/inline-pack.d.ts.map +1 -0
- package/dist/loaders/mesh-bin.d.ts +21 -0
- package/dist/loaders/mesh-bin.d.ts.map +1 -0
- package/dist/loaders/pack-artifact.d.ts +20 -0
- package/dist/loaders/pack-artifact.d.ts.map +1 -0
- package/dist/material/dependency-graph.d.ts +9 -0
- package/dist/material/dependency-graph.d.ts.map +1 -0
- package/dist/material/generation-cache.d.ts +24 -0
- package/dist/material/generation-cache.d.ts.map +1 -0
- package/dist/material/inspection.d.ts +24 -0
- package/dist/material/inspection.d.ts.map +1 -0
- package/dist/material/loader.d.ts +59 -0
- package/dist/material/loader.d.ts.map +1 -0
- package/dist/material/runtime-shader.d.ts +14 -0
- package/dist/material/runtime-shader.d.ts.map +1 -0
- package/dist/mesh-bin.d.ts +3 -0
- package/dist/mesh-bin.d.ts.map +1 -0
- package/dist/mipmap-generator.d.ts +132 -0
- package/dist/mipmap-generator.d.ts.map +1 -0
- package/dist/payload-validate.d.ts +60 -0
- package/dist/payload-validate.d.ts.map +1 -0
- package/dist/plugin.d.ts +16 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/registry/artifact-io.d.ts +16 -0
- package/dist/registry/artifact-io.d.ts.map +1 -0
- package/dist/registry/asset-evidence.d.ts +13 -0
- package/dist/registry/asset-evidence.d.ts.map +1 -0
- package/dist/registry/catalog-state.d.ts +47 -0
- package/dist/registry/catalog-state.d.ts.map +1 -0
- package/dist/registry/catalog.d.ts +48 -0
- package/dist/registry/catalog.d.ts.map +1 -0
- package/dist/registry/instantiate.d.ts +153 -0
- package/dist/registry/instantiate.d.ts.map +1 -0
- package/dist/registry/load-by-guid.d.ts +247 -0
- package/dist/registry/load-by-guid.d.ts.map +1 -0
- package/dist/registry/load-state.d.ts +26 -0
- package/dist/registry/load-state.d.ts.map +1 -0
- package/dist/registry/runtime-projection.d.ts +16 -0
- package/dist/registry/runtime-projection.d.ts.map +1 -0
- package/dist/registry/scene-publication-fence.d.ts +38 -0
- package/dist/registry/scene-publication-fence.d.ts.map +1 -0
- package/dist/registry/validate-material.d.ts +77 -0
- package/dist/registry/validate-material.d.ts.map +1 -0
- package/dist/resolve-asset-handle.d.ts +43 -0
- package/dist/resolve-asset-handle.d.ts.map +1 -0
- package/dist/resolve-tileset-runtime.d.ts +23 -0
- package/dist/resolve-tileset-runtime.d.ts.map +1 -0
- package/dist/scene-handle-fields.d.ts +88 -0
- package/dist/scene-handle-fields.d.ts.map +1 -0
- package/dist/scene-payload.d.ts +15 -0
- package/dist/scene-payload.d.ts.map +1 -0
- package/dist/wire-default-loaders.d.ts +29 -0
- package/dist/wire-default-loaders.d.ts.map +1 -0
- package/package.json +76 -0
- package/src/__tests__/aabb.unit.test.ts +97 -0
- package/src/__tests__/artifact-integrity.unit.test.ts +99 -0
- package/src/__tests__/artifact-io.unit.test.ts +127 -0
- package/src/__tests__/asset-evidence-sdk.integration.test.ts +32 -0
- package/src/__tests__/asset-evidence.unit.test.ts +32 -0
- package/src/__tests__/asset-kind.unit.test.ts +14 -0
- package/src/__tests__/asset-registry-catalog-reconcile.integration.test.ts +74 -0
- package/src/__tests__/asset-registry-catalog-reconcile.unit.test.ts +89 -0
- package/src/__tests__/asset-registry-catalog.unit.test.ts +170 -0
- package/src/__tests__/asset-registry.pack-cache.test.ts +96 -0
- package/src/__tests__/asset-registry.unit.test.ts +511 -0
- package/src/__tests__/asset-runtime-error-code-owner.test-d.ts +63 -0
- package/src/__tests__/catalog-replica.unit.test.ts +196 -0
- package/src/__tests__/catalog-source-v2.unit.test.ts +158 -0
- package/src/__tests__/catalog-source.unit.test.ts +126 -0
- package/src/__tests__/catalog-subscription-order.unit.test.ts +65 -0
- package/src/__tests__/catalog-subscription.unit.test.ts +28 -0
- package/src/__tests__/decode-image-bytes-pass-through.test.ts +34 -0
- package/src/__tests__/decode-image-bytes.browser.test.ts +102 -0
- package/src/__tests__/decode-image-bytes.test-d.ts +108 -0
- package/src/__tests__/decode-image-bytes.test.ts +90 -0
- package/src/__tests__/decode-image-mime-owner.test.ts +38 -0
- package/src/__tests__/dynamic-texture-store.unit.test.ts +115 -0
- package/src/__tests__/errors-asset.unit.test.ts +92 -0
- package/src/__tests__/inline-pack-loaders.unit.test.ts +548 -0
- package/src/__tests__/instantiate-context.unit.test.ts +65 -0
- package/src/__tests__/instantiate-publication-fence.unit.test.ts +158 -0
- package/src/__tests__/instantiate.unit.test.ts +684 -0
- package/src/__tests__/loader-input-contract.unit.test.ts +89 -0
- package/src/__tests__/loader-registry.unit.test.ts +101 -0
- package/src/__tests__/material-dependency-invalidation.unit.test.ts +14 -0
- package/src/__tests__/material-generation-cache.unit.test.ts +46 -0
- package/src/__tests__/material-load-consumer.test-d.ts +42 -0
- package/src/__tests__/material-ready.integration.test.ts +508 -0
- package/src/__tests__/material-stale-generation.unit.test.ts +147 -0
- package/src/__tests__/mesh-bin-morph-v3.test.ts +22 -0
- package/src/__tests__/mesh-bin.unit.test.ts +152 -0
- package/src/__tests__/mipmap-generator.unit.test.ts +202 -0
- package/src/__tests__/pack-artifact-transcode-model-owner.test.ts +32 -0
- package/src/__tests__/pack-basis-load.integration.test.ts +168 -0
- package/src/__tests__/payload-validate.unit.test.ts +285 -0
- package/src/__tests__/plugin.test.ts +55 -0
- package/src/__tests__/registry-concurrency.bench.test.ts +40 -0
- package/src/__tests__/registry-failure-retry.integration.test.ts +69 -0
- package/src/__tests__/registry-load-graph.integration.test.ts +246 -0
- package/src/__tests__/registry-load-state.unit.test.ts +35 -0
- package/src/__tests__/registry-package-cache.unit.test.ts +53 -0
- package/src/__tests__/registry-public-ready.unit.test.ts +38 -0
- package/src/__tests__/resolve-asset-handle.unit.test.ts +238 -0
- package/src/__tests__/scene-handle-fields.unit.test.ts +129 -0
- package/src/__tests__/scene-payload.unit.test.ts +151 -0
- package/src/__tests__/scene-publication-fence.test.ts +129 -0
- package/src/__tests__/scriptable-pack-public-surface.test-d.ts +27 -0
- package/src/__tests__/static-rig.integration.test.ts +8 -0
- package/src/__tests__/validate-material.unit.test.ts +359 -0
- package/src/__tests__/video-pack-loader.integration.test.ts +83 -0
- package/src/aabb.ts +107 -0
- package/src/asset-kind.ts +6 -0
- package/src/asset-registry.ts +2045 -0
- package/src/builtin-asset-registry.ts +164 -0
- package/src/catalog-source.ts +89 -0
- package/src/decode-image-bytes.ts +126 -0
- package/src/dynamic-texture-store.ts +234 -0
- package/src/errors/asset.ts +347 -0
- package/src/handles.ts +186 -0
- package/src/image-error.ts +45 -0
- package/src/index.ts +189 -0
- package/src/internal/artifact-cache.ts +65 -0
- package/src/internal/asset-graph.ts +420 -0
- package/src/internal/catalog-session.ts +345 -0
- package/src/internal/decoder-registry.ts +175 -0
- package/src/internal/immutable-payload.ts +20 -0
- package/src/internal/load-asset.ts +254 -0
- package/src/internal/pack-reader.ts +183 -0
- package/src/internal/validate-runtime-row.ts +51 -0
- package/src/internal.ts +6 -0
- package/src/loader-registry.ts +157 -0
- package/src/loaders/inline-pack.ts +837 -0
- package/src/loaders/mesh-bin.ts +304 -0
- package/src/loaders/pack-artifact.ts +665 -0
- package/src/material/dependency-graph.ts +46 -0
- package/src/material/generation-cache.ts +177 -0
- package/src/material/inspection.ts +46 -0
- package/src/material/loader.ts +326 -0
- package/src/material/runtime-shader.ts +133 -0
- package/src/mesh-bin.ts +5 -0
- package/src/mipmap-generator.ts +450 -0
- package/src/payload-validate.ts +573 -0
- package/src/plugin.ts +48 -0
- package/src/registry/artifact-io.ts +259 -0
- package/src/registry/asset-evidence.ts +51 -0
- package/src/registry/catalog-state.ts +409 -0
- package/src/registry/catalog.ts +369 -0
- package/src/registry/instantiate.ts +1056 -0
- package/src/registry/load-by-guid.ts +1657 -0
- package/src/registry/load-state.ts +115 -0
- package/src/registry/runtime-projection.ts +63 -0
- package/src/registry/scene-publication-fence.ts +256 -0
- package/src/registry/validate-material.ts +385 -0
- package/src/resolve-asset-handle.ts +147 -0
- package/src/resolve-tileset-runtime.ts +72 -0
- package/src/scene-handle-fields.ts +221 -0
- package/src/scene-payload.ts +207 -0
- package/src/wire-default-loaders.ts +79 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deriveVertexLayoutProjectionFromMask,
|
|
3
|
+
type VertexLayoutProjection,
|
|
4
|
+
} from '@forgeax/engine-geometry';
|
|
5
|
+
import {
|
|
6
|
+
decodeMeshBinHeader,
|
|
7
|
+
MESH_BIN_HEADER_V4_BYTES,
|
|
8
|
+
type MeshBinHeaderV4,
|
|
9
|
+
} from '@forgeax/engine-pack';
|
|
10
|
+
import { err, ok, type Result, type VertexAttributeMap } from '@forgeax/engine-types';
|
|
11
|
+
import { MeshBinAssetError } from '../errors/asset';
|
|
12
|
+
|
|
13
|
+
export interface UnpackedMeshBin {
|
|
14
|
+
readonly version: 4;
|
|
15
|
+
readonly projection: VertexLayoutProjection;
|
|
16
|
+
readonly vertices: Float32Array;
|
|
17
|
+
readonly attributes: VertexAttributeMap;
|
|
18
|
+
readonly indices?: Uint16Array | Uint32Array;
|
|
19
|
+
readonly submeshes: ReadonlyArray<Record<string, unknown>>;
|
|
20
|
+
readonly materialSlots: readonly {
|
|
21
|
+
readonly slotName: string;
|
|
22
|
+
readonly sourceKey?: string;
|
|
23
|
+
readonly defaultMaterialRef?: number;
|
|
24
|
+
}[];
|
|
25
|
+
readonly aabb?: Float32Array;
|
|
26
|
+
readonly morphTargets?: ReadonlyArray<Record<string, Float32Array>>;
|
|
27
|
+
readonly morphWeights?: Float32Array;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function fail(
|
|
31
|
+
sourceKey: string,
|
|
32
|
+
expected: string,
|
|
33
|
+
actual: string,
|
|
34
|
+
header?: Partial<MeshBinHeaderV4>,
|
|
35
|
+
reason: import('@forgeax/engine-types').AssetMeshBinContractViolationReason = 'header-invalid',
|
|
36
|
+
expectedFacts?: import('@forgeax/engine-types').AssetMeshBinContractFacts,
|
|
37
|
+
actualFacts?: import('@forgeax/engine-types').AssetMeshBinContractFacts,
|
|
38
|
+
): Result<UnpackedMeshBin, MeshBinAssetError> {
|
|
39
|
+
return err(
|
|
40
|
+
new MeshBinAssetError({
|
|
41
|
+
sourceKey,
|
|
42
|
+
expected,
|
|
43
|
+
actual,
|
|
44
|
+
...(header === undefined ? {} : { header }),
|
|
45
|
+
reason,
|
|
46
|
+
...(expectedFacts === undefined ? {} : { expectedFacts }),
|
|
47
|
+
...(actualFacts === undefined ? {} : { actualFacts }),
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function copyAttributes(
|
|
53
|
+
source: Float32Array,
|
|
54
|
+
header: MeshBinHeaderV4,
|
|
55
|
+
projection: VertexLayoutProjection,
|
|
56
|
+
): VertexAttributeMap {
|
|
57
|
+
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
58
|
+
const attributes: Record<string, Float32Array | Uint16Array> = {};
|
|
59
|
+
for (const entry of projection.attributes) {
|
|
60
|
+
const components = entry.byteLength / (entry.format === 'uint16x4' ? 2 : 4);
|
|
61
|
+
const target =
|
|
62
|
+
entry.format === 'uint16x4'
|
|
63
|
+
? new Uint16Array(header.vertexCount * components)
|
|
64
|
+
: new Float32Array(header.vertexCount * components);
|
|
65
|
+
for (let vertex = 0; vertex < header.vertexCount; vertex++) {
|
|
66
|
+
for (let component = 0; component < components; component++) {
|
|
67
|
+
const offset =
|
|
68
|
+
vertex * header.stride + entry.offset + component * (entry.format === 'uint16x4' ? 2 : 4);
|
|
69
|
+
if (target instanceof Uint16Array)
|
|
70
|
+
target[vertex * components + component] = view.getUint16(offset, true);
|
|
71
|
+
else target[vertex * components + component] = view.getFloat32(offset, true);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
attributes[entry.key] = target;
|
|
75
|
+
}
|
|
76
|
+
return attributes as VertexAttributeMap;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function unpackMeshBinV4(
|
|
80
|
+
bytes: Uint8Array,
|
|
81
|
+
sourceKey: string,
|
|
82
|
+
): Result<UnpackedMeshBin, MeshBinAssetError> {
|
|
83
|
+
const headerResult = decodeMeshBinHeader(bytes, sourceKey);
|
|
84
|
+
if (!headerResult.ok) {
|
|
85
|
+
const reason =
|
|
86
|
+
headerResult.error.code === 'mesh-bin-header-truncated'
|
|
87
|
+
? 'header-truncated'
|
|
88
|
+
: headerResult.error.code === 'mesh-bin-version-unsupported'
|
|
89
|
+
? 'version-unsupported'
|
|
90
|
+
: 'header-invalid';
|
|
91
|
+
const actualFacts = {
|
|
92
|
+
byteLength: bytes.byteLength,
|
|
93
|
+
...(bytes.byteLength >= 4
|
|
94
|
+
? {
|
|
95
|
+
version: new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(
|
|
96
|
+
0,
|
|
97
|
+
true,
|
|
98
|
+
),
|
|
99
|
+
}
|
|
100
|
+
: {}),
|
|
101
|
+
};
|
|
102
|
+
return fail(
|
|
103
|
+
sourceKey,
|
|
104
|
+
headerResult.error.expected,
|
|
105
|
+
headerResult.error.actual,
|
|
106
|
+
undefined,
|
|
107
|
+
reason,
|
|
108
|
+
reason === 'header-truncated'
|
|
109
|
+
? { field: 'byteLength', byteLength: MESH_BIN_HEADER_V4_BYTES }
|
|
110
|
+
: reason === 'version-unsupported'
|
|
111
|
+
? { field: 'version', version: 4 }
|
|
112
|
+
: undefined,
|
|
113
|
+
actualFacts,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const header = headerResult.value;
|
|
117
|
+
const projectionResult = deriveVertexLayoutProjectionFromMask(header.mask);
|
|
118
|
+
if (!projectionResult.ok) {
|
|
119
|
+
return fail(
|
|
120
|
+
sourceKey,
|
|
121
|
+
projectionResult.error.expected,
|
|
122
|
+
`mask=${header.mask}`,
|
|
123
|
+
header,
|
|
124
|
+
'projection-mismatch',
|
|
125
|
+
{
|
|
126
|
+
field: 'mask',
|
|
127
|
+
mask: projectionResult.error.detail.knownMask,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
field: 'mask',
|
|
131
|
+
mask: header.mask,
|
|
132
|
+
projectionVersion: header.projectionVersion,
|
|
133
|
+
stride: header.stride,
|
|
134
|
+
digest: header.digest,
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const projection = projectionResult.value;
|
|
139
|
+
if (
|
|
140
|
+
projection.schemaVersion !== header.projectionVersion ||
|
|
141
|
+
projection.arrayStride !== header.stride ||
|
|
142
|
+
projection.digest !== header.digest
|
|
143
|
+
) {
|
|
144
|
+
return fail(
|
|
145
|
+
sourceKey,
|
|
146
|
+
'wire projection version, mask, stride, and digest to match geometry projection',
|
|
147
|
+
`projection=${projection.schemaVersion}/${projection.arrayStride}/${projection.digest}; wire=${header.projectionVersion}/${header.stride}/${header.digest}`,
|
|
148
|
+
header,
|
|
149
|
+
'projection-mismatch',
|
|
150
|
+
{
|
|
151
|
+
field: 'projectionVersion',
|
|
152
|
+
projectionVersion: projection.schemaVersion,
|
|
153
|
+
mask: projection.mask,
|
|
154
|
+
stride: projection.arrayStride,
|
|
155
|
+
digest: projection.digest,
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const payloadBytes = header.vertexBytes + header.indexBytes + header.jsonBytes;
|
|
160
|
+
if (MESH_BIN_HEADER_V4_BYTES + payloadBytes !== bytes.byteLength) {
|
|
161
|
+
return fail(
|
|
162
|
+
sourceKey,
|
|
163
|
+
`exactly ${MESH_BIN_HEADER_V4_BYTES + payloadBytes} bytes`,
|
|
164
|
+
`${bytes.byteLength} bytes`,
|
|
165
|
+
header,
|
|
166
|
+
'payload-length-mismatch',
|
|
167
|
+
{ field: 'byteLength', byteLength: MESH_BIN_HEADER_V4_BYTES + payloadBytes },
|
|
168
|
+
{
|
|
169
|
+
field: 'byteLength',
|
|
170
|
+
byteLength: bytes.byteLength,
|
|
171
|
+
vertexBytes: header.vertexBytes,
|
|
172
|
+
indexBytes: header.indexBytes,
|
|
173
|
+
jsonBytes: header.jsonBytes,
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
let offset = MESH_BIN_HEADER_V4_BYTES;
|
|
178
|
+
const vertexBytes = bytes.subarray(offset, offset + header.vertexBytes);
|
|
179
|
+
const vertices = new Float32Array(vertexBytes.byteLength / 4);
|
|
180
|
+
new Uint8Array(vertices.buffer).set(vertexBytes);
|
|
181
|
+
offset += header.vertexBytes;
|
|
182
|
+
let indices: Uint16Array | Uint32Array | undefined;
|
|
183
|
+
if (header.indexCount > 0) {
|
|
184
|
+
const indexBytes = bytes.subarray(offset, offset + header.indexBytes);
|
|
185
|
+
if (header.indexWidth === 2) {
|
|
186
|
+
indices = new Uint16Array(header.indexCount);
|
|
187
|
+
new Uint8Array(indices.buffer).set(indexBytes);
|
|
188
|
+
} else {
|
|
189
|
+
indices = new Uint32Array(header.indexCount);
|
|
190
|
+
new Uint8Array(indices.buffer).set(indexBytes);
|
|
191
|
+
}
|
|
192
|
+
offset += header.indexBytes;
|
|
193
|
+
}
|
|
194
|
+
const jsonBytes = bytes.subarray(offset, offset + header.jsonBytes);
|
|
195
|
+
let meta: {
|
|
196
|
+
submeshes?: ReadonlyArray<Record<string, unknown>>;
|
|
197
|
+
materialSlots?: readonly {
|
|
198
|
+
readonly slotName: string;
|
|
199
|
+
readonly sourceKey?: string;
|
|
200
|
+
readonly defaultMaterialRef?: number;
|
|
201
|
+
}[];
|
|
202
|
+
aabb?: readonly number[];
|
|
203
|
+
morphTargets?: ReadonlyArray<Record<string, readonly number[]>>;
|
|
204
|
+
morphWeights?: readonly number[];
|
|
205
|
+
};
|
|
206
|
+
try {
|
|
207
|
+
meta = JSON.parse(new TextDecoder().decode(jsonBytes)) as typeof meta;
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return fail(
|
|
210
|
+
sourceKey,
|
|
211
|
+
'valid mesh-bin v4 JSON metadata',
|
|
212
|
+
error instanceof Error ? error.message : String(error),
|
|
213
|
+
header,
|
|
214
|
+
'metadata-invalid',
|
|
215
|
+
{ field: 'metadata' },
|
|
216
|
+
{ field: 'metadata' },
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
if (
|
|
220
|
+
!Array.isArray(meta.submeshes) ||
|
|
221
|
+
meta.submeshes.length === 0 ||
|
|
222
|
+
!Array.isArray(meta.materialSlots)
|
|
223
|
+
) {
|
|
224
|
+
return fail(
|
|
225
|
+
sourceKey,
|
|
226
|
+
'non-empty submeshes and materialSlots metadata',
|
|
227
|
+
'metadata table missing',
|
|
228
|
+
header,
|
|
229
|
+
'metadata-invalid',
|
|
230
|
+
{ field: 'metadata' },
|
|
231
|
+
{ field: 'metadata' },
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
const attributes = copyAttributes(vertices, header, projection);
|
|
235
|
+
for (const attribute of projection.attributes) {
|
|
236
|
+
const value = attributes[attribute.key];
|
|
237
|
+
if (value === undefined)
|
|
238
|
+
return fail(
|
|
239
|
+
sourceKey,
|
|
240
|
+
`decoded ${attribute.key} attribute`,
|
|
241
|
+
'attribute missing',
|
|
242
|
+
header,
|
|
243
|
+
'attribute-invalid',
|
|
244
|
+
{
|
|
245
|
+
field: 'attribute',
|
|
246
|
+
attribute: attribute.key,
|
|
247
|
+
expectedLength:
|
|
248
|
+
header.vertexCount * (attribute.byteLength / (attribute.format === 'uint16x4' ? 2 : 4)),
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
field: 'attribute',
|
|
252
|
+
attribute: attribute.key,
|
|
253
|
+
mask: header.mask,
|
|
254
|
+
stride: header.stride,
|
|
255
|
+
vertexCount: header.vertexCount,
|
|
256
|
+
},
|
|
257
|
+
);
|
|
258
|
+
if (value instanceof ArrayBuffer) continue;
|
|
259
|
+
for (const component of value) {
|
|
260
|
+
if (!Number.isFinite(component))
|
|
261
|
+
return fail(
|
|
262
|
+
sourceKey,
|
|
263
|
+
'finite vertex payload',
|
|
264
|
+
`non-finite ${attribute.key}`,
|
|
265
|
+
header,
|
|
266
|
+
'payload-non-finite',
|
|
267
|
+
{ field: 'attribute', attribute: attribute.key },
|
|
268
|
+
{
|
|
269
|
+
field: 'attribute',
|
|
270
|
+
attribute: attribute.key,
|
|
271
|
+
mask: header.mask,
|
|
272
|
+
stride: header.stride,
|
|
273
|
+
vertexCount: header.vertexCount,
|
|
274
|
+
elementIndex: [...value].findIndex((component) => !Number.isFinite(component)),
|
|
275
|
+
actualValue: Number.isNaN(component)
|
|
276
|
+
? 'nan'
|
|
277
|
+
: component === Number.POSITIVE_INFINITY
|
|
278
|
+
? 'positive-infinity'
|
|
279
|
+
: 'negative-infinity',
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const morphTargets = meta.morphTargets?.map((target) =>
|
|
285
|
+
Object.fromEntries(
|
|
286
|
+
Object.entries(target).map(([key, value]) => [key, new Float32Array(value)]),
|
|
287
|
+
),
|
|
288
|
+
);
|
|
289
|
+
const mesh: UnpackedMeshBin = {
|
|
290
|
+
version: 4,
|
|
291
|
+
projection,
|
|
292
|
+
vertices,
|
|
293
|
+
attributes,
|
|
294
|
+
...(indices === undefined ? {} : { indices }),
|
|
295
|
+
submeshes: meta.submeshes,
|
|
296
|
+
materialSlots: meta.materialSlots,
|
|
297
|
+
...(meta.aabb === undefined ? {} : { aabb: new Float32Array(meta.aabb) }),
|
|
298
|
+
...(morphTargets === undefined ? {} : { morphTargets }),
|
|
299
|
+
...(meta.morphWeights === undefined
|
|
300
|
+
? {}
|
|
301
|
+
: { morphWeights: new Float32Array(meta.morphWeights) }),
|
|
302
|
+
};
|
|
303
|
+
return ok(mesh);
|
|
304
|
+
}
|