@loaders.gl/scene 5.0.0-beta.2 → 5.0.0-beta.5
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/DRACO-README.md +1 -1
- package/GLTF-README.md +1 -1
- package/OBJ-README.md +1 -1
- package/README.md +6 -1
- package/THIRD-PARTY-NOTICES.md +6 -0
- package/dist/dist.dev.js +6557 -1363
- package/dist/dist.min.js +24 -16
- package/dist/draco/draco-javascript-loader-with-parser.d.ts +2 -2
- package/dist/draco/draco-loader-types.cjs +3 -3
- package/dist/draco/draco-loader-types.cjs.map +2 -2
- package/dist/draco/draco-loader-types.d.ts +1 -1
- package/dist/draco/draco-loader-types.d.ts.map +1 -1
- package/dist/draco/draco-loader-types.js +1 -1
- package/dist/draco/draco-loader-types.js.map +1 -1
- package/dist/draco/draco-loader.d.ts +2 -2
- package/dist/draco/draco-wasm-loader-with-parser.d.ts +2 -2
- package/dist/draco/draco3d-loader-with-parser.d.ts +2 -2
- package/dist/draco/lib/utils/version.cjs +1 -1
- package/dist/draco/lib/utils/version.js +1 -1
- package/dist/draco-worker-node.js +806 -158
- package/dist/draco-worker-node.js.map +4 -4
- package/dist/draco-worker.js +775 -158
- package/dist/draco-worker.js.map +4 -4
- package/dist/draco-writer-worker-node.cjs +2122 -219
- package/dist/draco-writer-worker-node.cjs.map +4 -4
- package/dist/draco-writer-worker.js +2053 -220
- package/dist/draco-writer-worker.js.map +4 -4
- package/dist/gltf/gltf-loader-types.cjs.map +2 -2
- package/dist/gltf/gltf-loader-types.d.ts +6 -0
- package/dist/gltf/gltf-loader-types.d.ts.map +1 -1
- package/dist/gltf/gltf-loader-types.js.map +1 -1
- package/dist/gltf/index.cjs +2 -0
- package/dist/gltf/index.cjs.map +2 -2
- package/dist/gltf/index.d.ts +2 -2
- package/dist/gltf/index.d.ts.map +1 -1
- package/dist/gltf/index.js +1 -1
- package/dist/gltf/index.js.map +1 -1
- package/dist/gltf/lib/api/gltf-extensions.cjs +7 -2
- package/dist/gltf/lib/api/gltf-extensions.cjs.map +2 -2
- package/dist/gltf/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/gltf/lib/api/gltf-extensions.js +7 -5
- package/dist/gltf/lib/api/gltf-extensions.js.map +1 -1
- package/dist/gltf/lib/extensions/EXT_texture_webp.cjs +1 -0
- package/dist/gltf/lib/extensions/EXT_texture_webp.cjs.map +2 -2
- package/dist/gltf/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/gltf/lib/extensions/EXT_texture_webp.js +3 -0
- package/dist/gltf/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/gltf/lib/extensions/KHR_accessor_float64.cjs +45 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.cjs.map +7 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.d.ts +6 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.d.ts.map +1 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.js +20 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.js.map +1 -0
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.cjs +23 -7
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.cjs.map +2 -2
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.d.ts +2 -1
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.d.ts.map +1 -1
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.js +21 -5
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.js.map +1 -1
- package/dist/gltf/lib/extensions/MSFT_texture_dds.cjs +64 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.cjs.map +7 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.d.ts +12 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.d.ts.map +1 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.js +39 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.js.map +1 -0
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.cjs +1 -1
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.cjs.map +2 -2
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.js +3 -1
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.js.map +1 -1
- package/dist/gltf/lib/parsers/parse-gltf.cjs +25 -0
- package/dist/gltf/lib/parsers/parse-gltf.cjs.map +2 -2
- package/dist/gltf/lib/parsers/parse-gltf.d.ts +2 -0
- package/dist/gltf/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/gltf/lib/parsers/parse-gltf.js +18 -0
- package/dist/gltf/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.cjs +22 -0
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.cjs.map +2 -2
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.d.ts +23 -0
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.js +22 -0
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.js.map +1 -1
- package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.cjs.map +1 -1
- package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.d.ts +1 -1
- package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-extension-schemas.cjs +8 -0
- package/dist/gltf/lib/types/gltf-extension-schemas.cjs.map +2 -2
- package/dist/gltf/lib/types/gltf-extension-schemas.d.ts +27 -0
- package/dist/gltf/lib/types/gltf-extension-schemas.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-extension-schemas.js +8 -1
- package/dist/gltf/lib/types/gltf-extension-schemas.js.map +1 -1
- package/dist/gltf/lib/types/gltf-json-schema.cjs.map +1 -1
- package/dist/gltf/lib/types/gltf-json-schema.d.ts +2 -2
- package/dist/gltf/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-texture-procedurals.cjs +19 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.cjs.map +7 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.d.ts +45 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.d.ts.map +1 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.js +5 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.js.map +1 -0
- package/dist/gltf/lib/types/gltf-types.cjs.map +1 -1
- package/dist/gltf/lib/types/gltf-types.d.ts +7 -0
- package/dist/gltf/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-version-zod-schemas.d.ts +34 -0
- package/dist/gltf/lib/types/gltf-version-zod-schemas.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-zod-schema.cjs +4 -1
- package/dist/gltf/lib/types/gltf-zod-schema.cjs.map +2 -2
- package/dist/gltf/lib/types/gltf-zod-schema.d.ts +56 -0
- package/dist/gltf/lib/types/gltf-zod-schema.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-zod-schema.js +6 -2
- package/dist/gltf/lib/types/gltf-zod-schema.js.map +1 -1
- package/dist/gltf/lib/utils/version.cjs +1 -1
- package/dist/gltf/lib/utils/version.js +1 -1
- package/dist/gltf/schema.cjs +3 -0
- package/dist/gltf/schema.cjs.map +2 -2
- package/dist/gltf/schema.d.ts +1 -0
- package/dist/gltf/schema.d.ts.map +1 -1
- package/dist/gltf/schema.js +1 -0
- package/dist/gltf/schema.js.map +1 -1
- package/dist/gltf-loader-types.cjs.map +2 -2
- package/dist/index.cjs +7 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/materialx/parse-materialx.cjs +61 -0
- package/dist/materialx/parse-materialx.cjs.map +7 -0
- package/dist/materialx/parse-materialx.d.ts +23 -0
- package/dist/materialx/parse-materialx.d.ts.map +1 -0
- package/dist/materialx/parse-materialx.js +39 -0
- package/dist/materialx/parse-materialx.js.map +1 -0
- package/dist/materialx/procedural-graph.cjs +77 -0
- package/dist/materialx/procedural-graph.cjs.map +7 -0
- package/dist/materialx/procedural-graph.d.ts +40 -0
- package/dist/materialx/procedural-graph.d.ts.map +1 -0
- package/dist/materialx/procedural-graph.js +59 -0
- package/dist/materialx/procedural-graph.js.map +1 -0
- package/dist/materialx-loader-types.cjs +57 -0
- package/dist/materialx-loader-types.cjs.map +7 -0
- package/dist/materialx-loader-types.d.ts +34 -0
- package/dist/materialx-loader-types.d.ts.map +1 -0
- package/dist/materialx-loader-types.js +20 -0
- package/dist/materialx-loader-types.js.map +1 -0
- package/dist/materialx-loader.cjs +40 -0
- package/dist/materialx-loader.cjs.map +7 -0
- package/dist/materialx-loader.d.ts +19 -0
- package/dist/materialx-loader.d.ts.map +1 -0
- package/dist/materialx-loader.js +14 -0
- package/dist/materialx-loader.js.map +1 -0
- package/dist/mtl-loader-types.cjs +1 -1
- package/dist/obj/mtl-loader-types.cjs +1 -1
- package/dist/obj/mtl-loader-types.js +1 -1
- package/dist/obj/obj-loader-types.cjs +3 -3
- package/dist/obj/obj-loader-types.cjs.map +2 -2
- package/dist/obj/obj-loader-types.d.ts +1 -1
- package/dist/obj/obj-loader-types.d.ts.map +1 -1
- package/dist/obj/obj-loader-types.js +2 -2
- package/dist/obj/obj-loader-types.js.map +1 -1
- package/dist/obj/obj-loader.cjs +5 -5
- package/dist/obj/obj-loader.cjs.map +2 -2
- package/dist/obj/obj-loader.d.ts +1 -1
- package/dist/obj/obj-loader.d.ts.map +1 -1
- package/dist/obj/obj-loader.js +1 -1
- package/dist/obj/obj-loader.js.map +1 -1
- package/dist/obj/obj-writer.cjs +1 -1
- package/dist/obj/obj-writer.js +1 -1
- package/dist/obj-loader-types.cjs +3 -3
- package/dist/obj-loader-types.cjs.map +2 -2
- package/dist/obj-loader.cjs +5 -5
- package/dist/obj-loader.cjs.map +2 -2
- package/dist/obj-worker.js +985 -368
- package/dist/obj-writer.cjs +1 -1
- package/dist/stl/parse-stl.cjs +100 -0
- package/dist/stl/parse-stl.cjs.map +7 -0
- package/dist/stl/parse-stl.d.ts +4 -0
- package/dist/stl/parse-stl.d.ts.map +1 -0
- package/dist/stl/parse-stl.js +84 -0
- package/dist/stl/parse-stl.js.map +1 -0
- package/dist/stl-loader-types.cjs +58 -0
- package/dist/stl-loader-types.cjs.map +7 -0
- package/dist/stl-loader-types.d.ts +32 -0
- package/dist/stl-loader-types.d.ts.map +1 -0
- package/dist/stl-loader-types.js +25 -0
- package/dist/stl-loader-types.js.map +1 -0
- package/dist/stl-loader.cjs +38 -0
- package/dist/stl-loader.cjs.map +7 -0
- package/dist/stl-loader.d.ts +17 -0
- package/dist/stl-loader.d.ts.map +1 -0
- package/dist/stl-loader.js +13 -0
- package/dist/stl-loader.js.map +1 -0
- package/dist/usd/index.cjs.map +1 -1
- package/dist/usd/index.d.ts +1 -1
- package/dist/usd/index.d.ts.map +1 -1
- package/dist/usd/lib/parse-usd.cjs +42 -5
- package/dist/usd/lib/parse-usd.cjs.map +2 -2
- package/dist/usd/lib/parse-usd.d.ts.map +1 -1
- package/dist/usd/lib/parse-usd.js +53 -6
- package/dist/usd/lib/parse-usd.js.map +1 -1
- package/dist/usd/lib/parse-usdc.cjs +187 -0
- package/dist/usd/lib/parse-usdc.cjs.map +7 -0
- package/dist/usd/lib/parse-usdc.d.ts +4 -0
- package/dist/usd/lib/parse-usdc.d.ts.map +1 -0
- package/dist/usd/lib/parse-usdc.js +176 -0
- package/dist/usd/lib/parse-usdc.js.map +1 -0
- package/dist/usd/lib/parse-usdz.cjs +22 -0
- package/dist/usd/lib/parse-usdz.cjs.map +2 -2
- package/dist/usd/lib/parse-usdz.d.ts.map +1 -1
- package/dist/usd/lib/parse-usdz.js +26 -0
- package/dist/usd/lib/parse-usdz.js.map +1 -1
- package/dist/usd/lib/usd-types.cjs.map +1 -1
- package/dist/usd/lib/usd-types.d.ts +14 -1
- package/dist/usd/lib/usd-types.d.ts.map +1 -1
- package/dist/usd/lib/usd-types.js +1 -1
- package/dist/usd/lib/usd-types.js.map +1 -1
- package/dist/usd/libs/README.md +27 -0
- package/dist/usd/libs/THREE-LICENSE +21 -0
- package/dist/usd/libs/usdc-parser.d.ts +78 -0
- package/dist/usd/libs/usdc-parser.d.ts.map +1 -0
- package/dist/usd/libs/usdc-parser.js +1669 -0
- package/dist/usd/libs/usdc-parser.js.map +1 -0
- package/dist/usd/usd-loader-types.cjs +4 -4
- package/dist/usd/usd-loader-types.cjs.map +2 -2
- package/dist/usd/usd-loader-types.d.ts +7 -7
- package/dist/usd/usd-loader-types.d.ts.map +1 -1
- package/dist/usd/usd-loader-types.js +6 -6
- package/dist/usd/usd-loader-types.js.map +1 -1
- package/dist/usd/usd-loader.cjs.map +1 -1
- package/dist/usd/usd-loader.d.ts +4 -4
- package/dist/usd/usd-loader.d.ts.map +1 -1
- package/dist/usd/usd-loader.js +2 -2
- package/dist/usd/usd-loader.js.map +1 -1
- package/dist/usd-loader-types.cjs +4 -4
- package/dist/usd-loader-types.cjs.map +2 -2
- package/dist/usd-loader.cjs.map +1 -1
- package/package.json +19 -7
- package/src/draco/draco-loader-types.ts +1 -1
- package/src/gltf/gltf-loader-types.ts +6 -0
- package/src/gltf/index.ts +4 -1
- package/src/gltf/lib/api/gltf-extensions.ts +7 -2
- package/src/gltf/lib/extensions/EXT_texture_webp.ts +3 -0
- package/src/gltf/lib/extensions/KHR_accessor_float64.ts +22 -0
- package/src/gltf/lib/extensions/KHR_gaussian_splatting.ts +31 -7
- package/src/gltf/lib/extensions/MSFT_texture_dds.ts +52 -0
- package/src/gltf/lib/extensions/utils/3d-tiles-utils.ts +5 -1
- package/src/gltf/lib/parsers/parse-gltf.ts +31 -0
- package/src/gltf/lib/types/gltf-additional-extension-schemas.ts +32 -0
- package/src/gltf/lib/types/gltf-ext-gaussian-splatting-schema.ts +1 -1
- package/src/gltf/lib/types/gltf-extension-schemas.ts +12 -0
- package/src/gltf/lib/types/gltf-json-schema.ts +2 -1
- package/src/gltf/lib/types/gltf-texture-procedurals.ts +67 -0
- package/src/gltf/lib/types/gltf-types.ts +8 -0
- package/src/gltf/lib/types/gltf-zod-schema.ts +7 -1
- package/src/gltf/schema.ts +1 -0
- package/src/index.ts +6 -1
- package/src/materialx/README.md +5 -0
- package/src/materialx/parse-materialx.ts +70 -0
- package/src/materialx/procedural-graph.ts +94 -0
- package/src/materialx-loader-types.ts +24 -0
- package/src/materialx-loader.ts +15 -0
- package/src/obj/obj-loader-types.ts +1 -1
- package/src/obj/obj-loader.ts +1 -1
- package/src/stl/parse-stl.ts +90 -0
- package/src/stl-loader-types.ts +28 -0
- package/src/stl-loader.ts +12 -0
- package/src/usd/index.ts +1 -0
- package/src/usd/lib/parse-usd.ts +68 -7
- package/src/usd/lib/parse-usdc.ts +188 -0
- package/src/usd/lib/parse-usdz.ts +28 -0
- package/src/usd/lib/usd-types.ts +16 -2
- package/src/usd/libs/README.md +27 -0
- package/src/usd/libs/THREE-LICENSE +21 -0
- package/src/usd/libs/usdc-parser.d.ts +18 -0
- package/src/usd/libs/usdc-parser.js +1669 -0
- package/src/usd/usd-loader-types.ts +5 -5
- package/src/usd/usd-loader.ts +2 -2
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
6
|
|
|
7
|
+
import {parseFromContext} from '@loaders.gl/core/loader-utils';
|
|
8
|
+
import type {LoaderContext} from '@loaders.gl/core/loader-utils';
|
|
7
9
|
import type {GLTF, GLTFMeshPrimitive} from '../types/gltf-json-schema';
|
|
8
10
|
import type {GLTFWithBuffers} from '../types/gltf-types';
|
|
9
11
|
import type {GLTFLoaderOptions} from '../../gltf-loader-types';
|
|
@@ -28,37 +30,59 @@ const REQUIRED_ATTRIBUTES = [
|
|
|
28
30
|
] as const;
|
|
29
31
|
|
|
30
32
|
/** Validates Gaussian splat primitives while preserving all source JSON. */
|
|
31
|
-
export async function decode(
|
|
33
|
+
export async function decode(
|
|
34
|
+
gltfData: GLTFWithBuffers,
|
|
35
|
+
options: GLTFLoaderOptions,
|
|
36
|
+
context?: LoaderContext
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
const loader = context?.loaders?.find(candidate => candidate.extensions?.includes('spz'));
|
|
32
39
|
const descriptors = getGaussianSplatPrimitives(gltfData);
|
|
33
40
|
const iterator = new GLTFIterator(gltfData);
|
|
34
41
|
for (const [meshIndex, mesh] of (gltfData.json.meshes || []).entries()) {
|
|
35
42
|
for (const [primitiveIndex, primitive] of mesh.primitives.entries()) {
|
|
36
43
|
const extension = primitive.extensions?.[name] as GLTF_KHR_gaussian_splatting | undefined;
|
|
37
44
|
if (!extension) continue;
|
|
45
|
+
const descriptor = descriptors.find(
|
|
46
|
+
item => item.meshIndex === meshIndex && item.primitiveIndex === primitiveIndex
|
|
47
|
+
);
|
|
48
|
+
const legacyColorSpace = options?.gltf?.legacyGaussianSplatColorSpace;
|
|
49
|
+
const normalizedExtension =
|
|
50
|
+
legacyColorSpace && extension.extensions?.[SPZ_COMPRESSION_EXTENSION_NAME]
|
|
51
|
+
? {
|
|
52
|
+
...extension,
|
|
53
|
+
kernel: extension.kernel ?? 'ellipse',
|
|
54
|
+
colorSpace: extension.colorSpace ?? legacyColorSpace
|
|
55
|
+
}
|
|
56
|
+
: extension;
|
|
57
|
+
if (descriptor) descriptor.extension = normalizedExtension;
|
|
38
58
|
validateGaussianSplatPrimitive(
|
|
39
59
|
gltfData.json,
|
|
40
60
|
primitive,
|
|
41
|
-
|
|
61
|
+
normalizedExtension,
|
|
42
62
|
meshIndex,
|
|
43
63
|
primitiveIndex,
|
|
44
64
|
iterator
|
|
45
65
|
);
|
|
46
66
|
const compression = extension.extensions?.[SPZ_COMPRESSION_EXTENSION_NAME];
|
|
47
67
|
if (compression) {
|
|
48
|
-
const descriptor = descriptors.find(
|
|
49
|
-
item => item.meshIndex === meshIndex && item.primitiveIndex === primitiveIndex
|
|
50
|
-
);
|
|
51
68
|
if (descriptor) {
|
|
52
69
|
const decoder = options?.gltf?.splatDecoder;
|
|
53
70
|
const bufferView = gltfData.json.bufferViews?.[compression.bufferView];
|
|
54
71
|
if (bufferView && gltfData.buffers[bufferView.buffer]) {
|
|
55
72
|
descriptor.compressedBytes = getBufferViewBytes(gltfData, compression.bufferView);
|
|
56
|
-
} else if (decoder) {
|
|
73
|
+
} else if (decoder || loader) {
|
|
57
74
|
throw new Error(
|
|
58
75
|
`KHR_gaussian_splatting: bufferView ${compression.bufferView} is not loaded for SPZ2 decoding.`
|
|
59
76
|
);
|
|
60
77
|
}
|
|
61
|
-
if (
|
|
78
|
+
if (loader && context && descriptor.compressedBytes) {
|
|
79
|
+
descriptor.decoded = await parseFromContext(
|
|
80
|
+
descriptor.compressedBytes.buffer as ArrayBuffer,
|
|
81
|
+
loader,
|
|
82
|
+
{...options, splats: {...options.splats, sourceCoordinateSystem: 'LUF'}},
|
|
83
|
+
context
|
|
84
|
+
);
|
|
85
|
+
} else if (decoder && descriptor.compressedBytes) {
|
|
62
86
|
descriptor.decoded = await decoder(descriptor.compressedBytes.buffer as ArrayBuffer, {
|
|
63
87
|
sourceCoordinateSystem: 'LUF'
|
|
64
88
|
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {GLTFLoaderOptions} from '../../gltf-loader-types';
|
|
6
|
+
import type {GLTFWithBuffers} from '../types/gltf-types';
|
|
7
|
+
import type {GLTF_MSFT_texture_dds} from '../types/gltf-json-schema';
|
|
8
|
+
import type {Loader, LoaderContext} from '@loaders.gl/core/loader-utils';
|
|
9
|
+
import {GLTFIterator} from '../api/gltf-iterator';
|
|
10
|
+
|
|
11
|
+
/** Name of the Microsoft DDS texture extension. */
|
|
12
|
+
export const name = 'MSFT_texture_dds';
|
|
13
|
+
|
|
14
|
+
/** Finds a DDS-capable loader supplied through the parent loader context. */
|
|
15
|
+
export function getDDSLoader(context?: LoaderContext): Loader | undefined {
|
|
16
|
+
return context?.loaders?.find(
|
|
17
|
+
loader => loader.extensions?.includes('dds') || loader.mimeTypes?.includes('image/vnd-ms.dds')
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Select DDS sources only when an application supplies a compatible loader. */
|
|
22
|
+
export function preprocess(
|
|
23
|
+
gltf: GLTFWithBuffers,
|
|
24
|
+
_options: GLTFLoaderOptions,
|
|
25
|
+
context?: LoaderContext
|
|
26
|
+
): void {
|
|
27
|
+
const iterator = new GLTFIterator(gltf);
|
|
28
|
+
if (!iterator.hasExtension(name)) return;
|
|
29
|
+
if (!getDDSLoader(context)) {
|
|
30
|
+
if (iterator.isExtensionRequired(name)) {
|
|
31
|
+
throw new Error('gltf: Required extension MSFT_texture_dds needs a DDS parser');
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const texture of iterator.textures) {
|
|
36
|
+
const extension = iterator.getExtension<GLTF_MSFT_texture_dds>(texture, name);
|
|
37
|
+
if (extension) texture.source = extension.source;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Remove DDS declarations only after image loading can identify the selected sources. */
|
|
42
|
+
export async function decode(
|
|
43
|
+
gltf: GLTFWithBuffers,
|
|
44
|
+
options: GLTFLoaderOptions,
|
|
45
|
+
context?: LoaderContext
|
|
46
|
+
): Promise<void> {
|
|
47
|
+
if (!getDDSLoader(context) || options.gltf?.loadImages === false) return;
|
|
48
|
+
const iterator = new GLTFIterator(gltf);
|
|
49
|
+
if (!iterator.hasExtension(name)) return;
|
|
50
|
+
for (const texture of iterator.textures) iterator.removeExtension(texture, name);
|
|
51
|
+
iterator.removeExtension(name);
|
|
52
|
+
}
|
|
@@ -197,7 +197,11 @@ export function getPrimitiveTextureData(
|
|
|
197
197
|
const mimeType = json.images?.[imageIndex]?.mimeType;
|
|
198
198
|
const parsedImage = scenegraph.gltf.images?.[imageIndex];
|
|
199
199
|
// Checking for width is to prevent handling Un-processed images (e.g. [analyze] stage, where loadImages option is set to false)
|
|
200
|
-
if (
|
|
200
|
+
if (
|
|
201
|
+
parsedImage &&
|
|
202
|
+
typeof parsedImage.width !== 'undefined' &&
|
|
203
|
+
!('compressed' in parsedImage && parsedImage.compressed)
|
|
204
|
+
) {
|
|
201
205
|
const textureData: number[] = [];
|
|
202
206
|
for (let index = 0; index < textureCoordinates.length; index += 2) {
|
|
203
207
|
const value = getImageValueByCoordinates(
|
|
@@ -21,6 +21,7 @@ import {canonicalizeUrl, resolveUrl} from '../gltf-utils/resolve-url';
|
|
|
21
21
|
import {findGLTFFileIndex, resolveGLTFFile} from '../gltf-utils/resolve-gltf-file';
|
|
22
22
|
import {getTypedArrayForBufferView} from '../gltf-utils/get-typed-array';
|
|
23
23
|
import {preprocessExtensions, decodeExtensions} from '../api/gltf-extensions';
|
|
24
|
+
import {getDDSLoader} from '../extensions/MSFT_texture_dds';
|
|
24
25
|
import {normalizeGLTFV1WithDeferredBuffers} from '../api/normalize-gltf-v1';
|
|
25
26
|
|
|
26
27
|
/** */
|
|
@@ -42,6 +43,8 @@ export type ParseGLTFOptions = ParseGLBOptions & {
|
|
|
42
43
|
loadExternalAssets?: boolean;
|
|
43
44
|
/** Decompress Draco, `EXT_meshopt_compression`, and `KHR_meshopt_compression` data. @default true */
|
|
44
45
|
decompressMeshes?: boolean;
|
|
46
|
+
/** Interpret missing metadata in legacy SPZ2 Gaussian primitives using this assumed color space. */
|
|
47
|
+
legacyGaussianSplatColorSpace?: 'srgb_rec709_display' | 'lin_rec709_display';
|
|
45
48
|
/** Optional decoder for embedded SPZ2 Gaussian payloads; bytes are explicitly in LUF coordinates. */
|
|
46
49
|
splatDecoder?: (
|
|
47
50
|
data: ArrayBuffer,
|
|
@@ -542,6 +545,34 @@ async function loadImage(
|
|
|
542
545
|
|
|
543
546
|
const gltfOptions = getGLTFImageOptions(options, image.mimeType);
|
|
544
547
|
|
|
548
|
+
const ddsLoader = getDDSLoader(context);
|
|
549
|
+
const ddsSelected = Boolean(
|
|
550
|
+
ddsLoader &&
|
|
551
|
+
!options.gltf?.excludeExtensions?.includes('MSFT_texture_dds') &&
|
|
552
|
+
gltf.json.textures?.some(
|
|
553
|
+
texture =>
|
|
554
|
+
texture.source === index && texture.extensions?.MSFT_texture_dds?.source === index
|
|
555
|
+
)
|
|
556
|
+
);
|
|
557
|
+
if (ddsSelected) {
|
|
558
|
+
const levels = (await parseFromContext(
|
|
559
|
+
arrayBuffer,
|
|
560
|
+
ddsLoader!,
|
|
561
|
+
options,
|
|
562
|
+
context
|
|
563
|
+
)) as TextureLevel[];
|
|
564
|
+
assert(levels.length > 0, 'MSFT_texture_dds parser returned no texture levels');
|
|
565
|
+
gltf.images = gltf.images || [];
|
|
566
|
+
gltf.images[index] = {
|
|
567
|
+
compressed: true,
|
|
568
|
+
mipmaps: true,
|
|
569
|
+
width: levels[0].width,
|
|
570
|
+
height: levels[0].height,
|
|
571
|
+
data: levels
|
|
572
|
+
};
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
|
|
545
576
|
// Call `parse`
|
|
546
577
|
let parsedImage = (await parseFromContext(
|
|
547
578
|
arrayBuffer,
|
|
@@ -125,3 +125,35 @@ export type GLTF_KHR_xmp_json_ld = z.infer<typeof GLTFKHRXMPJSONLDSchema>;
|
|
|
125
125
|
export type GLTFXMPPacket = z.infer<typeof GLTFKHRXMPPacketSchema>;
|
|
126
126
|
/** Reference to a shared XMP metadata packet. */
|
|
127
127
|
export type GLTF_KHR_xmp_json_ld_reference = z.infer<typeof GLTFKHRXMPJSONLDReferenceSchema>;
|
|
128
|
+
|
|
129
|
+
/** Permissive declaration for the KHR emissive-strength material extension. */
|
|
130
|
+
export const GLTFKHRMaterialsEmissiveStrengthSchema = z.looseObject({
|
|
131
|
+
...propertyShape,
|
|
132
|
+
/** Unitless multiplier; defaults to one when omitted. */
|
|
133
|
+
emissiveStrength: z.number().nonnegative().optional()
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
/** Authored KHR emissive-strength material declaration. */
|
|
137
|
+
export type GLTF_KHR_materials_emissive_strength = z.infer<
|
|
138
|
+
typeof GLTFKHRMaterialsEmissiveStrengthSchema
|
|
139
|
+
>;
|
|
140
|
+
|
|
141
|
+
/** Permissive FB scene geometry summary in static scene coordinates. */
|
|
142
|
+
export const GLTFFBGeometryMetadataSchema = z.looseObject({
|
|
143
|
+
...propertyShape,
|
|
144
|
+
/** Authored count of vertices. */
|
|
145
|
+
vertexCount: z.number().nonnegative().optional(),
|
|
146
|
+
/** Authored count of primitives. */
|
|
147
|
+
primitiveCount: z.number().nonnegative().optional(),
|
|
148
|
+
/** Static scene-space bounding box. */
|
|
149
|
+
sceneBounds: z
|
|
150
|
+
.looseObject({
|
|
151
|
+
...propertyShape,
|
|
152
|
+
min: z.array(z.number()).length(3),
|
|
153
|
+
max: z.array(z.number()).length(3)
|
|
154
|
+
})
|
|
155
|
+
.optional()
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/** Authored FB scene geometry summary. */
|
|
159
|
+
export type GLTF_FB_geometry_metadata = z.infer<typeof GLTFFBGeometryMetadataSchema>;
|
|
@@ -41,6 +41,6 @@ export type GLTFGaussianSplatPrimitive = {
|
|
|
41
41
|
compressedBufferView?: number;
|
|
42
42
|
/** Preserved compressed SPZ2 bytes for native or GPU decoders. */
|
|
43
43
|
compressedBytes?: Uint8Array;
|
|
44
|
-
/** Result returned by an injected
|
|
44
|
+
/** Result returned by an injected SPZ loader or legacy decoder, when supplied. */
|
|
45
45
|
decoded?: unknown;
|
|
46
46
|
};
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
GLTFKHRNodeVisibilitySchema,
|
|
12
12
|
GLTFKHRNodeSelectabilitySchema,
|
|
13
13
|
GLTFKHRNodeHoverabilitySchema,
|
|
14
|
+
GLTFKHRMaterialsEmissiveStrengthSchema,
|
|
15
|
+
GLTFFBGeometryMetadataSchema,
|
|
14
16
|
GLTFKHRXMPJSONLDSchema,
|
|
15
17
|
GLTFKHRXMPJSONLDReferenceSchema
|
|
16
18
|
} from './gltf-additional-extension-schemas';
|
|
@@ -26,6 +28,12 @@ export const GLTFPropertyExtensionsSchema = z.looseObject({
|
|
|
26
28
|
KHR_xmp_json_ld: GLTFKHRXMPJSONLDReferenceSchema.optional()
|
|
27
29
|
});
|
|
28
30
|
|
|
31
|
+
/** Permissive material extension map. */
|
|
32
|
+
export const GLTFMaterialExtensionsSchema = GLTFPropertyExtensionsSchema.extend({
|
|
33
|
+
/** Emissive intensity multiplier. */
|
|
34
|
+
KHR_materials_emissive_strength: GLTFKHRMaterialsEmissiveStrengthSchema.optional()
|
|
35
|
+
});
|
|
36
|
+
|
|
29
37
|
/** Permissive document-level extension map. */
|
|
30
38
|
export const GLTFRootExtensionsSchema = z.looseObject({
|
|
31
39
|
/** Shared material variant declarations. */
|
|
@@ -56,6 +64,8 @@ export const GLTFNodeExtensionsSchema = GLTFPropertyExtensionsSchema.extend({
|
|
|
56
64
|
|
|
57
65
|
/** Permissive scene-level extension map. */
|
|
58
66
|
export const GLTFSceneExtensionsSchema = GLTFPropertyExtensionsSchema.extend({
|
|
67
|
+
/** Authored static geometry summary. */
|
|
68
|
+
FB_geometry_metadata: GLTFFBGeometryMetadataSchema.optional(),
|
|
59
69
|
/** Attached global KHR audio emitters. */
|
|
60
70
|
KHR_audio_emitter: GLTFKHRAudioAttachmentSchema.optional()
|
|
61
71
|
});
|
|
@@ -74,6 +84,8 @@ export const GLTFAnimationTargetExtensionsSchema = z.looseObject({
|
|
|
74
84
|
|
|
75
85
|
/** Typed document-level extensions with arbitrary additional extension names. */
|
|
76
86
|
export type GLTFRootExtensions = z.infer<typeof GLTFRootExtensionsSchema>;
|
|
87
|
+
/** Typed material extensions with arbitrary additional extension names. */
|
|
88
|
+
export type GLTFMaterialExtensions = z.infer<typeof GLTFMaterialExtensionsSchema>;
|
|
77
89
|
/** Typed node-level extensions with arbitrary additional extension names. */
|
|
78
90
|
export type GLTFNodeExtensions = z.infer<typeof GLTFNodeExtensionsSchema>;
|
|
79
91
|
/** Typed scene-level extensions with arbitrary additional extension names. */
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import type {GLTFBoundingVolume, GLTFShape} from './gltf-shape-schema';
|
|
7
7
|
import type {
|
|
8
8
|
GLTFPropertyExtensions,
|
|
9
|
+
GLTFMaterialExtensions,
|
|
9
10
|
GLTFRootExtensions,
|
|
10
11
|
GLTFNodeExtensions,
|
|
11
12
|
GLTFSceneExtensions,
|
|
@@ -506,7 +507,7 @@ export type GLTFMaterialOcclusionTextureInfo = {
|
|
|
506
507
|
export type GLTFMaterial = {
|
|
507
508
|
name?: any;
|
|
508
509
|
/** Known metadata extensions with additional extension names preserved. */
|
|
509
|
-
extensions?:
|
|
510
|
+
extensions?: GLTFMaterialExtensions & Record<string, any>;
|
|
510
511
|
extras?: any;
|
|
511
512
|
/**
|
|
512
513
|
* A set of parameter values that are used to define the metallic-roughness material model from Physically-Based Rendering (PBR) methodology. When not specified, all the default values of `pbrMetallicRoughness` apply.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Serialized value types in the experimental procedural graph proposal. */
|
|
6
|
+
export type GLTFProceduralValueType =
|
|
7
|
+
| 'boolean'
|
|
8
|
+
| 'float'
|
|
9
|
+
| 'integer'
|
|
10
|
+
| 'color3'
|
|
11
|
+
| 'color4'
|
|
12
|
+
| 'vector2'
|
|
13
|
+
| 'vector3'
|
|
14
|
+
| 'vector4'
|
|
15
|
+
| 'integer2'
|
|
16
|
+
| 'integer3'
|
|
17
|
+
| 'integer4'
|
|
18
|
+
| 'matrix3x3'
|
|
19
|
+
| 'matrix4x4'
|
|
20
|
+
| 'string'
|
|
21
|
+
| 'filename';
|
|
22
|
+
|
|
23
|
+
/** Named graph port, retaining serialized connections without evaluating them. */
|
|
24
|
+
export interface GLTFProceduralPort {
|
|
25
|
+
/** Port category. */
|
|
26
|
+
nodetype: 'input' | 'output';
|
|
27
|
+
/** Declared value type. */
|
|
28
|
+
type: GLTFProceduralValueType;
|
|
29
|
+
/** Authored constant; scalar numeric arrays are retained as authored. */
|
|
30
|
+
value?: boolean | string | number | number[];
|
|
31
|
+
/** Upstream processing node index. */
|
|
32
|
+
node?: number;
|
|
33
|
+
/** Name of a graph interface input. */
|
|
34
|
+
input?: string;
|
|
35
|
+
/** Name of the selected upstream output. */
|
|
36
|
+
output?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Processing node in a procedural graph. */
|
|
40
|
+
export interface GLTFProceduralNode {
|
|
41
|
+
/** Optional display name. */
|
|
42
|
+
name?: string;
|
|
43
|
+
/** MaterialX or custom node category; unknown categories are retained. */
|
|
44
|
+
nodetype: string;
|
|
45
|
+
/** Single output type, or multiple named outputs. */
|
|
46
|
+
type: GLTFProceduralValueType | 'multioutput';
|
|
47
|
+
/** Named input ports. */
|
|
48
|
+
inputs?: Record<string, GLTFProceduralPort>;
|
|
49
|
+
/** Named output ports. */
|
|
50
|
+
outputs: Record<string, GLTFProceduralPort>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Flat procedural graph using the draft's named-port representation. */
|
|
54
|
+
export interface GLTFProceduralGraph extends GLTFProceduralNode {
|
|
55
|
+
/** Graph category. */
|
|
56
|
+
nodetype: 'nodegraph';
|
|
57
|
+
/** Processing nodes addressed by index. */
|
|
58
|
+
nodes: GLTFProceduralNode[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Procedural output attached to a material texture-info object. */
|
|
62
|
+
export interface GLTFProceduralBinding {
|
|
63
|
+
/** Index into the root extension's procedurals array. */
|
|
64
|
+
index: number;
|
|
65
|
+
/** Selected output name; required for graphs with multiple outputs. */
|
|
66
|
+
output?: string;
|
|
67
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
6
|
|
|
7
7
|
import {ImageType} from '@loaders.gl/images';
|
|
8
|
+
import type {TextureLevel} from '@loaders.gl/core/schema';
|
|
8
9
|
import type {GLTF} from './gltf-json-schema';
|
|
9
10
|
import type {GLTFGaussianSplatPrimitive} from './gltf-ext-gaussian-splatting-schema';
|
|
10
11
|
import type {GLTFSpatialAudio} from './gltf-mpeg-audio-spatial-schema';
|
|
@@ -50,6 +51,13 @@ export type GLTFExternalFile = GLTFExternalBuffer & {
|
|
|
50
51
|
|
|
51
52
|
type GLTFExternalImage =
|
|
52
53
|
| ImageType
|
|
54
|
+
| {
|
|
55
|
+
compressed: true;
|
|
56
|
+
mipmaps: true;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
data: TextureLevel[];
|
|
60
|
+
}
|
|
53
61
|
| {
|
|
54
62
|
compressed: true;
|
|
55
63
|
mipmaps: false;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import {z} from 'zod';
|
|
6
6
|
import {
|
|
7
7
|
GLTFPropertyExtensionsSchema,
|
|
8
|
+
GLTFMaterialExtensionsSchema,
|
|
8
9
|
GLTFRootExtensionsSchema,
|
|
9
10
|
GLTFNodeExtensionsSchema,
|
|
10
11
|
GLTFSceneExtensionsSchema,
|
|
@@ -313,7 +314,7 @@ export const GLTFMaterialSchema = z
|
|
|
313
314
|
alphaCutoff: z.number().optional(),
|
|
314
315
|
doubleSided: z.boolean().optional(),
|
|
315
316
|
...GLTF_NAMED_PROPERTY_SHAPE,
|
|
316
|
-
extensions:
|
|
317
|
+
extensions: GLTFMaterialExtensionsSchema.optional()
|
|
317
318
|
})
|
|
318
319
|
.catchall(z.unknown());
|
|
319
320
|
|
|
@@ -539,6 +540,11 @@ export const GLTFEXTTextureWebpSchema = z
|
|
|
539
540
|
.object({source: GLTFIdSchema, extras: z.unknown().optional()})
|
|
540
541
|
.catchall(z.unknown());
|
|
541
542
|
|
|
543
|
+
/** Zod schema for the EXT_texture_avif texture source extension. */
|
|
544
|
+
export const GLTFEXTTextureAvifSchema = z
|
|
545
|
+
.object({source: GLTFIdSchema, extras: z.unknown().optional()})
|
|
546
|
+
.catchall(z.unknown());
|
|
547
|
+
|
|
542
548
|
/** Zod schema for the MSFT_texture_dds extension. */
|
|
543
549
|
export const GLTFMSFTTextureDdsSchema = z
|
|
544
550
|
.object({source: GLTFIdSchema, extras: z.unknown().optional()})
|
package/src/gltf/schema.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
2
|
// Copyright (c) vis.gl contributors
|
|
3
|
+
// loaders.gl
|
|
4
4
|
|
|
5
5
|
export * from './usd/index';
|
|
6
6
|
export type * from './gltf/index';
|
|
@@ -20,3 +20,8 @@ export {DracoLoader, DracoWorkerLoader} from './draco/draco-loader-types';
|
|
|
20
20
|
export {DracoFormat} from './draco/draco-format';
|
|
21
21
|
export type * from './draco/index';
|
|
22
22
|
export {DRACO_EXTERNAL_LIBRARIES, DRACO_EXTERNAL_LIBRARY_URLS} from './draco/draco-libraries';
|
|
23
|
+
|
|
24
|
+
export {MaterialXLoader} from './materialx-loader-types';
|
|
25
|
+
export type {MaterialXDocument, MaterialXElement} from './materialx/parse-materialx';
|
|
26
|
+
|
|
27
|
+
export {STLLoader} from './stl-loader-types';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# MaterialX parser
|
|
2
|
+
|
|
3
|
+
Native XML parsing implementation for browsers and Node.js. `parseMaterialX` returns an ordered element tree retaining string attributes, named connections, custom node categories and unresolved includes. It rejects malformed XML, document types, and missing or unsupported major versions.
|
|
4
|
+
|
|
5
|
+
This implementation does not resolve libraries, validate MaterialX node signatures, evaluate graphs, or generate shaders. The scene package exports MaterialXLoader with a materialx-loader implementation subpath.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {parseXMLSync} from '@loaders.gl/documents/xml-parser';
|
|
2
|
+
// loaders.gl
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
// Copyright vis.gl contributors
|
|
5
|
+
|
|
6
|
+
/** Authored MaterialX element, including extension categories and connection attributes. */
|
|
7
|
+
export interface MaterialXElement {
|
|
8
|
+
/** XML element category, for example nodegraph, input, or multiply. */
|
|
9
|
+
category: string;
|
|
10
|
+
/** Authored string attributes; values are not coerced or evaluated. */
|
|
11
|
+
attributes: Record<string, string>;
|
|
12
|
+
/** Child elements in document order. */
|
|
13
|
+
children: MaterialXElement[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Parsed MaterialX document. External includes remain unresolved. */
|
|
17
|
+
export interface MaterialXDocument {
|
|
18
|
+
/** Authored MaterialX version. */
|
|
19
|
+
version: string;
|
|
20
|
+
/** MaterialX root element. */
|
|
21
|
+
root: MaterialXElement;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Parses a MaterialX XML document using the native documents XML parser.
|
|
26
|
+
* Preserves unknown categories, connection references and value strings.
|
|
27
|
+
* Does not load includes, resolve node definitions, or evaluate shader graphs.
|
|
28
|
+
*/
|
|
29
|
+
export function parseMaterialX(text: string): MaterialXDocument {
|
|
30
|
+
if (/<!DOCTYPE|<!ENTITY/i.test(text)) {
|
|
31
|
+
throw new Error('MaterialX: document types and entity declarations are unsupported.');
|
|
32
|
+
}
|
|
33
|
+
let element: OrderedXMLElement;
|
|
34
|
+
try {
|
|
35
|
+
element = parseXMLSync(text, {
|
|
36
|
+
preserveOrder: true,
|
|
37
|
+
parseAttributeValue: false,
|
|
38
|
+
trimValues: false
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new Error('MaterialX: malformed XML.', {cause: error});
|
|
42
|
+
}
|
|
43
|
+
if (element.name !== 'materialx') {
|
|
44
|
+
throw new Error('MaterialX: expected a materialx root element.');
|
|
45
|
+
}
|
|
46
|
+
const version = element.attributes.version;
|
|
47
|
+
if (!version || !/^1\.\d+$/.test(version)) {
|
|
48
|
+
throw new Error('MaterialX: expected a MaterialX 1.x version.');
|
|
49
|
+
}
|
|
50
|
+
return {version, root: parseElement(element, 0)};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Ordered element representation returned by the XML parser. */
|
|
54
|
+
interface OrderedXMLElement {
|
|
55
|
+
/** XML element name. */
|
|
56
|
+
name: string;
|
|
57
|
+
/** Authored string attributes. */
|
|
58
|
+
attributes: Record<string, string>;
|
|
59
|
+
/** Ordered child elements. */
|
|
60
|
+
children: OrderedXMLElement[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Converts the native XML tree to MaterialX categories. */
|
|
64
|
+
function parseElement(element: OrderedXMLElement, depth: number): MaterialXElement {
|
|
65
|
+
return {
|
|
66
|
+
category: element.name,
|
|
67
|
+
attributes: element.attributes,
|
|
68
|
+
children: element.children.map(child => parseElement(child, depth + 1))
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/** Typed connection to one node output. */
|
|
5
|
+
export interface ProceduralConnection {
|
|
6
|
+
/** Stable identifier of the upstream node. */
|
|
7
|
+
node: string;
|
|
8
|
+
/** Name of its output port. */
|
|
9
|
+
output: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Input supplied by a constant or another node. */
|
|
13
|
+
export interface ProceduralInput {
|
|
14
|
+
/** Declared value type. */
|
|
15
|
+
type: string;
|
|
16
|
+
/** Constant value, retained without implicit conversion. */
|
|
17
|
+
value?: unknown;
|
|
18
|
+
/** Optional upstream connection. */
|
|
19
|
+
connection?: ProceduralConnection;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Renderer-independent operation with explicitly declared ports. */
|
|
23
|
+
export interface ProceduralNode {
|
|
24
|
+
/** Stable node identifier, unique within the graph. */
|
|
25
|
+
id: string;
|
|
26
|
+
/** Operation identifier for a downstream implementation registry. */
|
|
27
|
+
operation: string;
|
|
28
|
+
/** Named inputs. */
|
|
29
|
+
inputs: Record<string, ProceduralInput>;
|
|
30
|
+
/** Named output value types. */
|
|
31
|
+
outputs: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Graph contract independent of GPU resources or shader languages. */
|
|
35
|
+
export interface ProceduralGraph {
|
|
36
|
+
/** Nodes in authored order. */
|
|
37
|
+
nodes: ProceduralNode[];
|
|
38
|
+
/** Named graph outputs and their upstream connections. */
|
|
39
|
+
outputs: Record<string, ProceduralConnection>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Validates explicit references and exact port types, returning dependency-first nodes.
|
|
44
|
+
* Does not infer conversions, resolve MaterialX definitions, or evaluate operations.
|
|
45
|
+
*/
|
|
46
|
+
export function orderProceduralGraph(graph: ProceduralGraph): ProceduralNode[] {
|
|
47
|
+
const nodes = new Map<string, ProceduralNode>();
|
|
48
|
+
for (const node of graph.nodes) {
|
|
49
|
+
if (!node.id || nodes.has(node.id))
|
|
50
|
+
throw new Error('Procedural graph: duplicate or empty node ID.');
|
|
51
|
+
nodes.set(node.id, node);
|
|
52
|
+
}
|
|
53
|
+
const dependencies = new Map<string, Set<string>>();
|
|
54
|
+
const dependents = new Map<string, string[]>();
|
|
55
|
+
for (const node of graph.nodes) {
|
|
56
|
+
const upstream = new Set<string>();
|
|
57
|
+
for (const input of Object.values(node.inputs)) {
|
|
58
|
+
if (!input.connection) continue;
|
|
59
|
+
if (Object.hasOwn(input, 'value'))
|
|
60
|
+
throw new Error('Procedural graph: connected input also has a value.');
|
|
61
|
+
const source = resolveOutput(input.connection);
|
|
62
|
+
if (source.outputs[input.connection.output] !== input.type) {
|
|
63
|
+
throw new Error('Procedural graph: incompatible connection types.');
|
|
64
|
+
}
|
|
65
|
+
upstream.add(source.id);
|
|
66
|
+
}
|
|
67
|
+
dependencies.set(node.id, upstream);
|
|
68
|
+
for (const identifier of upstream) {
|
|
69
|
+
const downstream = dependents.get(identifier) || [];
|
|
70
|
+
downstream.push(node.id);
|
|
71
|
+
dependents.set(identifier, downstream);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const output of Object.values(graph.outputs)) resolveOutput(output);
|
|
75
|
+
const ordered = graph.nodes.filter(node => dependencies.get(node.id)!.size === 0);
|
|
76
|
+
for (let index = 0; index < ordered.length; index++) {
|
|
77
|
+
for (const identifier of dependents.get(ordered[index].id) || []) {
|
|
78
|
+
const upstream = dependencies.get(identifier)!;
|
|
79
|
+
upstream.delete(ordered[index].id);
|
|
80
|
+
if (!upstream.size) ordered.push(nodes.get(identifier)!);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (ordered.length !== graph.nodes.length) throw new Error('Procedural graph: cycle detected.');
|
|
84
|
+
return ordered;
|
|
85
|
+
|
|
86
|
+
/** Resolves an explicitly named output without accepting inherited properties. */
|
|
87
|
+
function resolveOutput(connection: ProceduralConnection): ProceduralNode {
|
|
88
|
+
const node = nodes.get(connection.node);
|
|
89
|
+
if (!node || !Object.hasOwn(node.outputs, connection.output)) {
|
|
90
|
+
throw new Error('Procedural graph: missing node or output.');
|
|
91
|
+
}
|
|
92
|
+
return node;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type {MaterialXDocument} from './materialx/parse-materialx';
|
|
4
|
+
|
|
5
|
+
/** Loads the parser-bearing MaterialX implementation. */
|
|
6
|
+
async function preload() {
|
|
7
|
+
const {MaterialXLoaderWithParser} = await import('@loaders.gl/scene/materialx-loader');
|
|
8
|
+
return MaterialXLoaderWithParser;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Metadata-only loader for MaterialX XML documents. */
|
|
12
|
+
export const MaterialXLoader = {
|
|
13
|
+
name: 'MaterialX',
|
|
14
|
+
id: 'materialx',
|
|
15
|
+
module: 'scene',
|
|
16
|
+
version: 'latest',
|
|
17
|
+
extensions: ['mtlx'],
|
|
18
|
+
mimeTypes: ['application/xml'],
|
|
19
|
+
text: true,
|
|
20
|
+
dataType: null as unknown as MaterialXDocument,
|
|
21
|
+
batchType: null as never,
|
|
22
|
+
options: {},
|
|
23
|
+
preload
|
|
24
|
+
} as const;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import {MaterialXLoader} from './materialx-loader-types';
|
|
4
|
+
import {parseMaterialX} from './materialx/parse-materialx';
|
|
5
|
+
|
|
6
|
+
const {preload: _preload, ...metadata} = MaterialXLoader;
|
|
7
|
+
|
|
8
|
+
/** Parser-bearing loader for MaterialX XML, using the native XML parser. */
|
|
9
|
+
export const MaterialXLoaderWithParser = {
|
|
10
|
+
...metadata,
|
|
11
|
+
parse: async (data: ArrayBuffer) => parseMaterialX(new TextDecoder().decode(data)),
|
|
12
|
+
parseSync: (data: ArrayBuffer) => parseMaterialX(new TextDecoder().decode(data)),
|
|
13
|
+
parseText: async (text: string) => parseMaterialX(text),
|
|
14
|
+
parseTextSync: parseMaterialX
|
|
15
|
+
} as const;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type {Loader, LoaderOptions} from '@loaders.gl/core/loader-utils';
|
|
6
6
|
import type {Mesh, MeshArrowTable, ArrowTableBatch} from '@loaders.gl/core/schema';
|
|
7
7
|
import {OBJFormat} from './obj-format';
|
|
8
|
-
import {serializeArrowWorkerTable} from '@loaders.gl/core/
|
|
8
|
+
import {serializeArrowWorkerTable} from '@loaders.gl/core/arrow-worker-transport';
|
|
9
9
|
|
|
10
10
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
11
11
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|