@margoengine/gltf 0.0.0-stage → 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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1438 -3
- package/dist/accessor-DuqjpuxI.js +1 -0
- package/dist/accessor-nVsu_f1L.js +1 -0
- package/dist/accessor.d.ts +12 -0
- package/dist/asset-1b8ejkZX.js +4 -0
- package/dist/asset-entry.d.ts +1 -0
- package/dist/asset-entry.js +1 -0
- package/dist/asset.d.ts +319 -0
- package/dist/audio.d.ts +47 -0
- package/dist/audio.js +1 -0
- package/dist/auto.d.ts +29 -0
- package/dist/auto.js +1 -0
- package/dist/base-textures.d.ts +20 -0
- package/dist/coalesce.d.ts +29 -0
- package/dist/compression-D4IkO5vE.js +1 -0
- package/dist/compression.d.ts +15 -0
- package/dist/coordinates.d.ts +1 -0
- package/dist/coordinates.js +1 -0
- package/dist/dds.d.ts +7 -0
- package/dist/dds.js +1 -0
- package/dist/decoder-default-CxLH8Vz0.js +1 -0
- package/dist/decoder-default.d.ts +5 -0
- package/dist/default-materials.d.ts +8 -0
- package/dist/draco-state.d.ts +7 -0
- package/dist/draw-batch.d.ts +83 -0
- package/dist/draw-memo.d.ts +136 -0
- package/dist/errors-THVaUwlL.js +1 -0
- package/dist/extended.d.ts +12 -0
- package/dist/extended.js +1 -0
- package/dist/gltf.worker.d.ts +1 -0
- package/dist/group.d.ts +6 -0
- package/dist/image-limit-DvFSfR5T.js +1 -0
- package/dist/image-limit.d.ts +6 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +1 -0
- package/dist/instanced-shader-BebTnbkj.js +5 -0
- package/dist/instanced-shader.d.ts +14 -0
- package/dist/instancing.d.ts +9 -0
- package/dist/instancing.js +1 -0
- package/dist/interactivity-graph.d.ts +193 -0
- package/dist/interactivity-model.d.ts +94 -0
- package/dist/interactivity-ops.d.ts +20 -0
- package/dist/interactivity.d.ts +33 -0
- package/dist/interactivity.js +1 -0
- package/dist/lights.d.ts +98 -0
- package/dist/lights.js +1 -0
- package/dist/limits-_LZ441oV.js +1 -0
- package/dist/material-draw-state-BHeTb1FP.js +1 -0
- package/dist/material-draw-state.d.ts +7 -0
- package/dist/material-draw.d.ts +18 -0
- package/dist/material-draw.js +1 -0
- package/dist/material-extension.d.ts +96 -0
- package/dist/mesh-source-DvU8YvMc.js +1 -0
- package/dist/meshopt.d.ts +9 -0
- package/dist/meshopt.js +1 -0
- package/dist/metadata.d.ts +114 -0
- package/dist/metadata.js +1 -0
- package/dist/model-entry.d.ts +2 -0
- package/dist/model-entry.js +1 -0
- package/dist/model-iRvuj19h.js +39 -0
- package/dist/model.d.ts +1011 -0
- package/dist/node-image-decode.d.ts +6 -0
- package/dist/node-matrix-R9BipGnp.js +1 -0
- package/dist/node-matrix.d.ts +16 -0
- package/dist/occlusion.d.ts +8 -0
- package/dist/optimize-7SEzNA23.js +1 -0
- package/dist/pack-BVDYuqZe.js +1 -0
- package/dist/pack.d.ts +27 -0
- package/dist/parts.d.ts +54 -0
- package/dist/pbr-instancing.d.ts +83 -0
- package/dist/pbr-instancing.js +1 -0
- package/dist/pbr.d.ts +13 -0
- package/dist/pbr.js +1 -0
- package/dist/physics.d.ts +148 -0
- package/dist/physics.js +1 -0
- package/dist/prepare.d.ts +26 -0
- package/dist/prepare.js +1 -0
- package/dist/progressive.d.ts +59 -0
- package/dist/progressive.js +4 -0
- package/dist/progressive.worker.d.ts +1 -0
- package/dist/quantized.d.ts +8 -0
- package/dist/quantized.js +1 -0
- package/dist/render-state.d.ts +18 -0
- package/dist/replica.d.ts +37 -0
- package/dist/report.d.ts +128 -0
- package/dist/report.js +1 -0
- package/dist/scene-data.d.ts +61 -0
- package/dist/scene-data.js +1 -0
- package/dist/scene-scope-CZDEkd24.js +4 -0
- package/dist/scene.d.ts +61 -0
- package/dist/scene.js +4 -0
- package/dist/shader-DPqfUcmp.js +405 -0
- package/dist/shader.d.ts +222 -0
- package/dist/shared/caster.d.ts +152 -0
- package/dist/shared/gltf.d.ts +257 -0
- package/dist/shared/iridescence.d.ts +2 -0
- package/dist/shared/prepared-geometry.d.ts +8 -0
- package/dist/side-shader.d.ts +1 -0
- package/dist/soft-mesh.d.ts +94 -0
- package/dist/soft-mesh.js +4 -0
- package/dist/spec-gloss.d.ts +21 -0
- package/dist/spec-gloss.js +18 -0
- package/dist/splat-state.d.ts +7 -0
- package/dist/splats.d.ts +18 -0
- package/dist/splats.js +1 -0
- package/dist/src-WMRHArDp.js +4 -0
- package/dist/stream-C3bKMy1B.js +1 -0
- package/dist/stream.d.ts +87 -0
- package/dist/texture-coordinates-XFsEMdU6.js +2 -0
- package/dist/texture-coordinates.d.ts +26 -0
- package/dist/texture-stream-Cu_XpyVO.js +4 -0
- package/dist/texture-stream.d.ts +88 -0
- package/dist/textured.d.ts +34 -0
- package/dist/textured.js +5 -0
- package/dist/uniform-arena.d.ts +78 -0
- package/dist/unit-light-DvtsuFYP.js +109 -0
- package/dist/version-BmU1nesQ.js +1 -0
- package/dist/version.d.ts +8 -0
- package/dist/vertex-inputs.d.ts +47 -0
- package/dist/view-uniform.d.ts +13 -0
- package/dist/visibility-C_Oqz9Sr.js +1 -0
- package/dist/worker-CY1TQnYX.js +1 -0
- package/dist/worker.d.ts +21 -0
- package/dist/worker.js +4 -0
- package/dist/workers/gltf.js +322 -0
- package/dist/workers/progressive.js +1 -0
- package/package.json +213 -6
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caller-owned, filterable 2D texture and optional filtering sampler. Each is a plain object or `(device) => object`,
|
|
3
|
+
* called once per device and again after a device restore, so nothing is lost. A plain view or sampler belongs to the
|
|
4
|
+
* device that made it: after a restore it is dropped and reported once through `engine.onError` (`'state'`, help
|
|
5
|
+
* `borrowed-lost`), and the surface reads a 1 x 1 white texture and a linear sampler in its place until the material is
|
|
6
|
+
* given a new `MaterialExtension`.
|
|
7
|
+
*/
|
|
8
|
+
export interface MaterialExtensionTexture {
|
|
9
|
+
view: GPUTextureView | ((device: GPUDevice) => GPUTextureView);
|
|
10
|
+
sampler?: GPUSampler | ((device: GPUDevice) => GPUSampler);
|
|
11
|
+
}
|
|
12
|
+
/** True when every view and sampler of the extension is a `(device) => object`, so another device can use it. */
|
|
13
|
+
export declare function extensionTexturesPortable(extension: MaterialExtension | undefined): boolean;
|
|
14
|
+
/** Optional material slot. Group 3 is permanently reserved; lighting stays in group 2. */
|
|
15
|
+
export interface MaterialExtension {
|
|
16
|
+
/**
|
|
17
|
+
* Draw the beauty pass after the opaque phase (for example to read an opaque-scene capture), keeping the material's
|
|
18
|
+
* authored alpha mode, cutoff, blending and depth writes. Such primitives cast no opaque shadows. Default false.
|
|
19
|
+
*/
|
|
20
|
+
afterOpaque?: boolean;
|
|
21
|
+
/** The extension supplies physical lobes in place of imported built-in physical shading. */
|
|
22
|
+
replacesPhysical?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* WGSL f32 expression (evaluated after `wgsl`) of the share of light this surface transmits, for an extension that
|
|
25
|
+
* composites its own transmission in `output`: diffuse and ambient light scale by 1 minus it, as on the native
|
|
26
|
+
* transmission path, so reflections keep their strength. The value is in `s.tr`.
|
|
27
|
+
*/
|
|
28
|
+
transmission?: string;
|
|
29
|
+
/**
|
|
30
|
+
* WGSL f32 expression (evaluated after `wgsl`) of the surface's index of refraction (KHR_materials_ior; 0 is the
|
|
31
|
+
* extension's infinite index, F0 1, and other values below 1 count as 1): the dielectric F0 of direct and ambient
|
|
32
|
+
* light becomes ((ior - 1) / (ior + 1))^2 in place of 0.04 (IOR 1.5), as on the native physical path, so IOR 1 reflects nothing. The value is in `s.f0`. Default: F0 0.04.
|
|
33
|
+
*/
|
|
34
|
+
ior?: string;
|
|
35
|
+
/** Statements after surface(i,front), in every fragment entry point. May mutate s. */
|
|
36
|
+
wgsl?: string;
|
|
37
|
+
/** Beauty-only statements after directional direct lighting, before lighting effects. */
|
|
38
|
+
direct?: string;
|
|
39
|
+
/** Statements after hemispherical ambient lighting; may mutate materialAmbient. */
|
|
40
|
+
ambient?: string;
|
|
41
|
+
/**
|
|
42
|
+
* A layer over all the surface's light, as KHR_materials_clearcoat defines it: direct, local, ambient and emissive
|
|
43
|
+
* light keep the share `keep`, then the layer's own directional and ambient light add on top. The ambient light is
|
|
44
|
+
* `(1 - keep) x margoCoatAmbient(s, v)`, the same function native physical materials use, so lighting effects light it
|
|
45
|
+
* (PBRHooks `coat`). SSAO's ambient replay returns the same sum for its ambient part.
|
|
46
|
+
*/
|
|
47
|
+
coat?: MaterialCoatLayer;
|
|
48
|
+
/** Beauty-only statements after output encoding, before the final return. */
|
|
49
|
+
output?: string;
|
|
50
|
+
/** Disable optional lighting bindings for a caller-managed surface. */
|
|
51
|
+
lighting?: boolean;
|
|
52
|
+
/** Module-scope WGSL helpers, in addition to the generated resource declarations. */
|
|
53
|
+
declarations?: string;
|
|
54
|
+
/** One or more packed vec4 factors, exposed as materialFactors[index]. */
|
|
55
|
+
factors?: Float32Array;
|
|
56
|
+
/** materialTextureN / materialSamplerN, at bindings 1+2*N / 2+2*N. */
|
|
57
|
+
textures?: readonly MaterialExtensionTexture[];
|
|
58
|
+
}
|
|
59
|
+
/** WGSL expressions, evaluated after `wgsl`, of a `MaterialExtension.coat` layer. */
|
|
60
|
+
export interface MaterialCoatLayer {
|
|
61
|
+
/** f32: the share of the light under the layer that it leaves, 1 - factor x Fresnel(v.n). */
|
|
62
|
+
keep: string;
|
|
63
|
+
/** vec3f: the layer's own directional light, before shadows. Shadow visibility applies to it as to the base. */
|
|
64
|
+
direct: string;
|
|
65
|
+
/** vec3f: the layer's unit normal, in `s.cn`. */
|
|
66
|
+
normal: string;
|
|
67
|
+
/** f32: the layer's roughness, in `s.cr`. */
|
|
68
|
+
roughness: string;
|
|
69
|
+
}
|
|
70
|
+
interface ExtensionGroup {
|
|
71
|
+
entries: GPUBindGroupEntry[];
|
|
72
|
+
group: GPUBindGroup;
|
|
73
|
+
gap?: GPUBindGroup;
|
|
74
|
+
}
|
|
75
|
+
export interface MaterialExtensionResource {
|
|
76
|
+
uniform?: GPUBuffer;
|
|
77
|
+
bytes: number;
|
|
78
|
+
entries: GPUBindGroupEntry[];
|
|
79
|
+
groups: Map<GPURenderPipeline, ExtensionGroup>;
|
|
80
|
+
}
|
|
81
|
+
export declare function prepareMaterialExtension(device: GPUDevice, extension: MaterialExtension, previous?: MaterialExtensionResource, engine?: {
|
|
82
|
+
onError(error: unknown): void;
|
|
83
|
+
}): MaterialExtensionResource;
|
|
84
|
+
/**
|
|
85
|
+
* Applies the extension's surface edits (and the phony assignments that keep its bindings) wherever an entry point
|
|
86
|
+
* still builds the plain surface: after materialExtensionShader, an entry appended later (SSAO's occlusion fragment)
|
|
87
|
+
* gets them too, so its layout keeps group 3 and its surface matches the beauty pass.
|
|
88
|
+
*/
|
|
89
|
+
export declare function materialExtensionSurface(code: string, extension: MaterialExtension): string;
|
|
90
|
+
/** `under`, an expression of ambient light, as the coat layer of `extension` leaves it. */
|
|
91
|
+
export declare function coatedAmbient(extension: MaterialExtension | undefined, under: string): string;
|
|
92
|
+
export declare function materialExtensionShader(source: string, extension: MaterialExtension): string;
|
|
93
|
+
/** Apply after optional lighting effects have matched their standard lighting call sites. */
|
|
94
|
+
export declare function materialExtensionAmbientShader(source: string, extension: MaterialExtension): string;
|
|
95
|
+
export declare function bindMaterialExtension(device: GPUDevice, pass: GPURenderPassEncoder, pipeline: GPURenderPipeline, resource: MaterialExtensionResource, lighting: boolean): void;
|
|
96
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Symbol.for(`margoengine.mesh-sources.v1`),t=globalThis[e]??/* @__PURE__ */ new WeakMap;globalThis[e]||Object.defineProperty(globalThis,e,{value:t});var n=Symbol.for(`margoengine.geometry-surfaces.v1`),r=globalThis[n]??/* @__PURE__ */ new WeakMap;globalThis[n]||Object.defineProperty(globalThis,n,{value:r});function i(e,t){t?r.set(e,t):r.delete(e)}function a(e,n){t.set(e,n)}function o(e){t.delete(e)}function s(e){if(e?.geometry)return{kind:`core`,geometry:e.geometry};let n=e&&t.get(e);if(!n||n.model.disposed)return null;try{e.check?.()}catch{return null}return{kind:`pbr`,source:n}}export{a as i,s as n,i as r,o as t};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GLTFExtension } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Lets the light loader read meshopt compressed buffers (`EXT_meshopt_compression` and `KHR_meshopt_compression`,
|
|
4
|
+
* every mode and filter). `@margoengine/decoders/meshopt` is imported on the first file that uses it, so install that
|
|
5
|
+
* package beside this one; a file with no compressed views never loads it. A fallback buffer is not downloaded.
|
|
6
|
+
* Decoded data counts toward a 64 MiB budget. Needs `loadGLTF` or `parseGLTFAsync`.
|
|
7
|
+
* @example const model = await loadGLTF(engine, '/small.glb', { extensions: [meshopt, quantized] });
|
|
8
|
+
*/
|
|
9
|
+
export declare const meshopt: GLTFExtension;
|
package/dist/meshopt.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./accessor-nVsu_f1L.js";import{MargoError as t}from"@margoengine/math/errors";var n=[`EXT_meshopt_compression`,`KHR_meshopt_compression`],r=67108864,i=e=>e.extensions?.[n[0]]??e.extensions?.[n[1]];async function a(){try{return await import(`@margoengine/decoders/meshopt`)}catch(e){throw/Cannot find|Failed to resolve|dynamically imported module/i.test(e.message)?new t(`failed`,`Meshopt glTF needs a decoder; install @margoengine/decoders`):e}}var o={handles:n,async load(t){let o=t.doc.bufferViews??[];if(!o.some(i))return;let{meshoptDecodeGltfBuffer:s}=await a(),c=[...t.buffers],l=[...t.doc.buffers??[]],u=0,d=o.map(t=>{let a=i(t);if(!a)return t;let o=c[e(a.buffer,`meshopt buffer`)],d=e(a.byteOffset??0,`meshopt offset`),f=e(a.byteLength,`meshopt length`,1),p=e(a.count,`meshopt count`,1),m=e(a.byteStride,`meshopt stride`,1);if(!o||d+f>o.length)throw RangeError(`glTF meshopt data is outside its buffer; re-export the file`);if(u+=p*m,u>r)throw RangeError(`glTF meshopt data decodes past 64 MiB; load a smaller file or split it`);let h=s(o.subarray(d,d+f),p,m,a.mode,a.filter);if(h.length<e(t.byteLength,`view length`,1))throw RangeError(`glTF meshopt data is shorter than its bufferView; re-export the file`);let{extensions:g,..._}=t,v=Object.fromEntries(Object.entries(g).filter(([e])=>!n.includes(e)));return c.push(h),l.push({byteLength:h.length}),{..._,buffer:c.length-1,byteOffset:0,...Object.keys(v).length?{extensions:v}:{}}});t.buffers=c,t.doc={...t.doc,buffers:l,bufferViews:d}}};export{o as meshopt};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { GLTFDocument } from './shared/gltf.js';
|
|
2
|
+
import type { GLTFAsset } from './asset.js';
|
|
3
|
+
import type { PBRModel } from './pbr.js';
|
|
4
|
+
/** The namespaces `fields` reads, by their usual prefix. */
|
|
5
|
+
export declare const xmpNamespaces: {
|
|
6
|
+
readonly dc: "http://purl.org/dc/elements/1.1/";
|
|
7
|
+
readonly xmp: "http://ns.adobe.com/xap/1.0/";
|
|
8
|
+
readonly xmpRights: "http://ns.adobe.com/xap/1.0/rights/";
|
|
9
|
+
readonly cc: "http://creativecommons.org/ns#";
|
|
10
|
+
readonly rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
|
11
|
+
};
|
|
12
|
+
/** Text in a stated language, from a value object or a local `@context`. */
|
|
13
|
+
export interface XMPText {
|
|
14
|
+
readonly text: string;
|
|
15
|
+
readonly language?: string;
|
|
16
|
+
}
|
|
17
|
+
/** An `rdf:Alt`: the same text in several languages, in `rdf:_N` order. */
|
|
18
|
+
export interface XMPAlternatives {
|
|
19
|
+
readonly alternatives: readonly XMPText[];
|
|
20
|
+
}
|
|
21
|
+
/** An XMP structure. */
|
|
22
|
+
export interface XMPStructure {
|
|
23
|
+
readonly properties: readonly XMPProperty[];
|
|
24
|
+
}
|
|
25
|
+
/** One XMP value: `@list` and `@set` become arrays; the packet's `raw` keeps which one the file used. */
|
|
26
|
+
export type XMPValue = string | number | boolean | XMPText | XMPAlternatives | XMPStructure | readonly XMPValue[];
|
|
27
|
+
/** One property of a packet or structure. */
|
|
28
|
+
export interface XMPProperty {
|
|
29
|
+
/** Namespace URI, from `@context`; unset for a prefix nothing defines. */
|
|
30
|
+
readonly namespace?: string;
|
|
31
|
+
/** The prefix as written in this packet. */
|
|
32
|
+
readonly prefix?: string;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly value: XMPValue;
|
|
35
|
+
}
|
|
36
|
+
/** What attribution and asset pipelines ask for. Unset or empty when the metadata does not say. */
|
|
37
|
+
export interface GLTFMetadataFields {
|
|
38
|
+
/** `dc:title`. */
|
|
39
|
+
readonly title: string | undefined;
|
|
40
|
+
/** `dc:description`. */
|
|
41
|
+
readonly description: string | undefined;
|
|
42
|
+
/** `dc:creator`, in the file's order. */
|
|
43
|
+
readonly authors: readonly string[];
|
|
44
|
+
/** `dc:contributor`. */
|
|
45
|
+
readonly contributors: readonly string[];
|
|
46
|
+
/** `dc:publisher`. */
|
|
47
|
+
readonly publishers: readonly string[];
|
|
48
|
+
/** The first `dc:date`, as written. */
|
|
49
|
+
readonly date: string | undefined;
|
|
50
|
+
/** `dc:source`. */
|
|
51
|
+
readonly source: string | undefined;
|
|
52
|
+
/** `xmp:CreatorTool`; for the whole file, else glTF `asset.generator`. */
|
|
53
|
+
readonly tool: string | undefined;
|
|
54
|
+
/** `dc:rights` as written: XMP's one free-text rights statement, which files use for a copyright line or a licence name. */
|
|
55
|
+
readonly rights: string | undefined;
|
|
56
|
+
/** `cc:license`, else `xmpRights:UsageTerms`, else `xmpRights:WebStatement`, else `rights`. */
|
|
57
|
+
readonly license: string | undefined;
|
|
58
|
+
/** For the whole file glTF `asset.copyright`, else `rights`; for an object its own `rights`, else the whole file's. */
|
|
59
|
+
readonly copyright: string | undefined;
|
|
60
|
+
}
|
|
61
|
+
/** One entry of the file's `packets` array. */
|
|
62
|
+
export interface XMPPacket {
|
|
63
|
+
/** Its index in `packets`. */
|
|
64
|
+
readonly index: number;
|
|
65
|
+
/** The packet as written in the file. */
|
|
66
|
+
readonly raw: Readonly<Record<string, unknown>>;
|
|
67
|
+
/** Prefix to namespace URI, as in `@context`. */
|
|
68
|
+
readonly namespaces: ReadonlyMap<string, string>;
|
|
69
|
+
/** `@id`, the AboutURI, usually empty. */
|
|
70
|
+
readonly about: string | undefined;
|
|
71
|
+
readonly properties: readonly XMPProperty[];
|
|
72
|
+
/** This packet alone, with nothing inherited. Packets no object lists, such as credits for a sound, read here. */
|
|
73
|
+
readonly fields: GLTFMetadataFields;
|
|
74
|
+
/** A property by namespace URI and name, whichever prefix the packet gave that namespace. */
|
|
75
|
+
get(namespace: string, name: string): XMPValue | undefined;
|
|
76
|
+
}
|
|
77
|
+
/** The glTF objects a packet can sit on, besides `asset`. */
|
|
78
|
+
export type GLTFMetadataKind = 'scene' | 'node' | 'mesh' | 'material' | 'image' | 'animation';
|
|
79
|
+
/** One glTF object with its own packet. */
|
|
80
|
+
export interface GLTFMetadataObject {
|
|
81
|
+
readonly kind: GLTFMetadataKind;
|
|
82
|
+
/** Index in the file's array for `kind`. */
|
|
83
|
+
readonly index: number;
|
|
84
|
+
/** The object's glTF `name`. */
|
|
85
|
+
readonly name: string | undefined;
|
|
86
|
+
/** Index of its packet. */
|
|
87
|
+
readonly packet: number;
|
|
88
|
+
/** Its packet over the whole file's fields. */
|
|
89
|
+
readonly fields: GLTFMetadataFields;
|
|
90
|
+
}
|
|
91
|
+
/** Everything `readGLTFMetadata` found. */
|
|
92
|
+
export interface GLTFMetadata {
|
|
93
|
+
/** Every packet of the file, referenced or not. */
|
|
94
|
+
readonly packets: readonly XMPPacket[];
|
|
95
|
+
/** The packet on glTF `asset`, which applies to the whole file, with `asset.copyright` and `asset.generator`. */
|
|
96
|
+
readonly asset: GLTFMetadataFields;
|
|
97
|
+
/** Each object with its own packet, in the order scenes, nodes, meshes, materials, images, animations. */
|
|
98
|
+
readonly objects: readonly GLTFMetadataObject[];
|
|
99
|
+
/** The fields that apply to one object: its packet property by property over the whole file's. */
|
|
100
|
+
fieldsOf(kind: GLTFMetadataKind, index: number): GLTFMetadataFields;
|
|
101
|
+
}
|
|
102
|
+
/** Options of `readGLTFMetadata`. */
|
|
103
|
+
export interface GLTFMetadataOptions {
|
|
104
|
+
/** BCP 47 tag to prefer among language alternatives, such as `it` or `it-it`. Default: `x-default`, else the first listed. */
|
|
105
|
+
language?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reads a file's KHR_xmp_json_ld metadata: author, licence, copyright and every other XMP property, for the whole file
|
|
109
|
+
* and per object. Metadata on an object takes precedence over metadata on `asset`, property by property, as the
|
|
110
|
+
* extension says. A file without the extension gives no packets and whatever glTF `asset` itself states.
|
|
111
|
+
* @param source A loaded model, a `GLTFAsset` or a glTF document.
|
|
112
|
+
* @throws TypeError for a packet list or `packet` reference that is not valid glTF.
|
|
113
|
+
*/
|
|
114
|
+
export declare function readGLTFMetadata(source: PBRModel | GLTFAsset | GLTFDocument, options?: GLTFMetadataOptions): GLTFMetadata;
|
package/dist/metadata.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`KHR_xmp_json_ld`,t=`http://purl.org/dc/elements/1.1/`,n=`http://ns.adobe.com/xap/1.0/`,r=`http://ns.adobe.com/xap/1.0/rights/`,i=`http://creativecommons.org/ns#`,a=`http://www.w3.org/1999/02/22-rdf-syntax-ns#`,o={dc:t,xmp:n,xmpRights:r,cc:i,rdf:a},s=new Map(Object.entries(o)),c=64,l={scene:`scenes`,node:`nodes`,mesh:`meshes`,material:`materials`,image:`images`,animation:`animations`},u=t=>/* @__PURE__ */ TypeError(`Invalid ${e} ${t}; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`),d=e=>!!e&&typeof e==`object`&&!Array.isArray(e),f=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0;function p(e,t){return t.get(e)??s.get(e)}function m(e,t){let n=e.indexOf(`:`);if(n<0)return{name:e};let r=e.slice(0,n);return{namespace:p(r,t),prefix:r,name:e.slice(n+1)}}function h(e,t){let n=f(e,`@type`);if(typeof n!=`string`)return!1;let{namespace:r,name:i}=m(n,t);return r===a&&i===`Alt`}function g(e,t,n,r){let i=[];for(let o of Object.keys(e)){let{namespace:s,name:c}=m(o,t),l=/^_(\d+)$/.exec(c)?.[1];if(s!==a||l===void 0)continue;let u=_(f(e,o),t,n,r+1),d=x(u);d!==void 0&&i.push({order:Number(l),text:b(u)&&u.language!==void 0?{text:d,language:u.language}:{text:d}})}return i.sort((e,t)=>e.order-t.order).map(e=>e.text)}function _(e,t,n,r){if(r>c)throw u(`packet: values nest deeper than ${c} levels`);if(typeof e==`string`)return n===void 0?e:{text:e,language:n};if(typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e))return v(e,t,n,r);if(!d(e))return;let i=f(e,`@context`),a=d(i)?f(i,`@language`):void 0,o=typeof a==`string`?a:n;for(let n of[`@list`,`@set`])if(Object.hasOwn(e,n)){let i=f(e,n);return v(Array.isArray(i)?i:[i],t,o,r)}if(Object.hasOwn(e,`@value`)){let n=f(e,`@value`),i=f(e,`@language`);return _(n,t,typeof i==`string`?i:o,r+1)}return h(e,t)?{alternatives:g(e,t,o,r)}:{properties:y(e,t,o,r+1)}}function v(e,t,n,r){let i=[];for(let a of e){let e=_(a,t,n,r+1);e!==void 0&&i.push(e)}return i}function y(e,t,n,r){let i=[];for(let a of Object.keys(e)){if(a.startsWith(`@`))continue;let o=_(f(e,a),t,n,r);o!==void 0&&i.push({...m(a,t),value:o})}return i}var b=e=>d(e)&&typeof e.text==`string`,x=e=>typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):b(e)?e.text:void 0;function S(e,t){let n=e=>e.language?.toLowerCase(),r=t?.toLowerCase(),i=r?.split(`-`)[0];return(r&&e.find(e=>n(e)===r)||i&&e.find(e=>n(e)?.split(`-`)[0]===i)||e.find(e=>n(e)===`x-default`)||e[0])?.text}function C(e,t){if(Array.isArray(e))return e.flatMap(e=>C(e,t));let n=d(e)&&`alternatives`in e?S(e.alternatives,t):x(e);return n===void 0?[]:[n]}function w(e,a){let o=(t,n)=>C(e.get(t,n),a),s=(e,t)=>o(e,t)[0],c=s(t,`rights`);return{title:s(t,`title`),description:s(t,`description`),authors:o(t,`creator`),contributors:o(t,`contributor`),publishers:o(t,`publisher`),date:s(t,`date`),source:s(t,`source`),tool:s(n,`CreatorTool`),rights:c,license:s(i,`license`)??s(r,`UsageTerms`)??s(r,`WebStatement`)??c,copyright:c}}function T(e,t,n){if(!d(e))throw u(`packet ${t}: it is not an object`);let r=f(e,`@context`);if(!d(r))throw u(`packet ${t}: it has no @context`);let i=/* @__PURE__ */ new Map;for(let e of Object.keys(r)){let n=f(r,e);if(typeof n!=`string`)throw u(`packet ${t}: @context entry ${e} is not a string`);i.set(e,n)}let a=f(e,`@id`),o=y(e,i,void 0,0),s=(e,t)=>o.find(n=>n.namespace===e&&n.name===t)?.value;return{index:t,raw:e,namespaces:i,about:typeof a==`string`?a:void 0,properties:o,fields:w({get:s},n),get:s}}function E(e,t){let n=(e,t)=>e.length?e:t;return{title:e.title??t.title,description:e.description??t.description,authors:n(e.authors,t.authors),contributors:n(e.contributors,t.contributors),publishers:n(e.publishers,t.publishers),date:e.date??t.date,source:e.source??t.source,tool:e.tool??t.tool,rights:e.rights??t.rights,license:e.license??t.license,copyright:e.copyright??t.copyright}}var D=w({get:()=>void 0},void 0);function O(t,n={}){let r=t,i=r.asset?.doc??r.doc??t,a=i.extensions?.[e],{language:o}=n;if(a!==void 0&&!Array.isArray(a?.packets))throw u(`extension: packets is not an array`);let s=(a?.packets??[]).map((e,t)=>T(e,t,o)),c=(t,n)=>{let r=d(t)&&d(t.extensions)?f(t.extensions,e):void 0;if(r===void 0)return;let i=d(r)?f(r,`packet`):void 0;if(!Number.isInteger(i)||!s[i])throw u(`reference on ${n}: it names no entry of packets`);return s[i]},p=c(i.asset,`asset`)?.fields??D,m={...p,tool:p.tool??x(i.asset?.generator),copyright:x(i.asset?.copyright)??p.copyright},h=[],g=/* @__PURE__ */ new Map;for(let e of Object.keys(l))(i[l[e]]??[]).forEach((t,n)=>{let r=c(t,`${e} ${n}`);if(!r)return;let i=E(r.fields,m);g.set(`${e} ${n}`,i),h.push({kind:e,index:n,name:t?.name,packet:r.index,fields:i})});return{packets:s,asset:m,objects:h,fieldsOf(e,t){let n=l[e];if(!n)throw RangeError(`Unknown glTF object kind ${String(e)}; pass ${Object.keys(l).join(`, `)}`);if(!Number.isInteger(t)||t<0||t>=(i[n]?.length??0))throw RangeError(`No glTF ${e} ${String(t)}; pass an index below ${i[n]?.length??0}`);return g.get(`${e} ${t}`)??m}}}export{O as readGLTFMetadata,o as xmpNamespaces};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,c as t,n,s as r,t as i}from"./model-iRvuj19h.js";import{o as a,t as o}from"./asset-1b8ejkZX.js";import{r as s}from"./texture-coordinates-XFsEMdU6.js";export{o as GLTFAsset,i as PBRDrawRun,n as PBRModel,a as closeImages,e as parseGLTF,r as parsePreparedPBR,s as textureCoordinates,t as textureTransform};
|