@margoengine/gltf 0.1.0 → 1.0.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.
Files changed (83) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +4 -4
  3. package/README.md +1754 -1438
  4. package/dist/accessor-CU_1uSZ1.js +1 -0
  5. package/dist/asset-DN3ocEdY.js +4 -0
  6. package/dist/asset-entry.js +1 -1
  7. package/dist/asset.d.ts +76 -0
  8. package/dist/audio.js +1 -1
  9. package/dist/auto.js +1 -1
  10. package/dist/compression-CUOCmjmE.js +1 -0
  11. package/dist/compression.d.ts +6 -0
  12. package/dist/dds.js +1 -1
  13. package/dist/default-materials.d.ts +3 -1
  14. package/dist/default-transmission.d.ts +13 -0
  15. package/dist/extended.js +1 -1
  16. package/dist/group.d.ts +15 -3
  17. package/dist/index.d.ts +11 -0
  18. package/dist/index.js +1 -1
  19. package/dist/{instanced-shader-BebTnbkj.js → instanced-shader-C9ZMazvo.js} +1 -1
  20. package/dist/instancing.js +1 -1
  21. package/dist/lights.js +1 -1
  22. package/dist/material-draw-state-GKiHDb0p.js +1 -0
  23. package/dist/material-draw.js +1 -1
  24. package/dist/meshopt.js +1 -1
  25. package/dist/mipmaps-38NmjDc3.js +21 -0
  26. package/dist/model-C77ATxi1.js +25 -0
  27. package/dist/model-entry.js +1 -1
  28. package/dist/model.d.ts +84 -7
  29. package/dist/native-glass-D85twud0.js +19 -0
  30. package/dist/pack-DdxRO8k6.js +1 -0
  31. package/dist/pbr-instancing.js +1 -1
  32. package/dist/pbr.js +1 -1
  33. package/dist/physics.js +1 -1
  34. package/dist/prepare.js +1 -1
  35. package/dist/progressive-lod.d.ts +13 -0
  36. package/dist/progressive.d.ts +5 -2
  37. package/dist/progressive.js +3 -3
  38. package/dist/quantized.js +1 -1
  39. package/dist/report.js +1 -1
  40. package/dist/scene-data.js +1 -1
  41. package/dist/scene-scope-CZDEkd24.js +2 -2
  42. package/dist/scene.js +3 -3
  43. package/dist/{shader-DPqfUcmp.js → shader-C29RtPAw.js} +43 -39
  44. package/dist/shader.d.ts +24 -0
  45. package/dist/shared/caster.d.ts +159 -152
  46. package/dist/shared/gltf.d.ts +257 -257
  47. package/dist/shared/iridescence.d.ts +2 -2
  48. package/dist/shared/prepared-geometry.d.ts +8 -8
  49. package/dist/soft-mesh.d.ts +39 -1
  50. package/dist/soft-mesh.js +2 -2
  51. package/dist/spec-gloss.js +2 -2
  52. package/dist/splats.js +1 -1
  53. package/dist/src-Btvz5f6i.js +4 -0
  54. package/dist/stream-CrfNNCRd.js +1 -0
  55. package/dist/stream.d.ts +20 -3
  56. package/dist/stroke-width-B2cnYGgn.js +1 -0
  57. package/dist/stroke-width.d.ts +18 -0
  58. package/dist/strokes.d.ts +12 -0
  59. package/dist/strokes.js +1 -0
  60. package/dist/texture-stream-Cu_XpyVO.js +3 -3
  61. package/dist/textured.js +3 -3
  62. package/dist/transmission.d.ts +81 -0
  63. package/dist/transmission.js +66 -0
  64. package/dist/version-B6NE5cJf.js +1 -0
  65. package/dist/vertex-inputs.d.ts +6 -0
  66. package/dist/{unit-light-DvtsuFYP.js → warning-UqjZyyqW.js} +2 -22
  67. package/dist/warning.d.ts +24 -0
  68. package/dist/worker.d.ts +1 -1
  69. package/dist/worker.js +3 -3
  70. package/dist/workers/gltf.js +36 -36
  71. package/dist/workers/progressive.js +1 -1
  72. package/package.json +234 -213
  73. package/dist/accessor-nVsu_f1L.js +0 -1
  74. package/dist/asset-1b8ejkZX.js +0 -4
  75. package/dist/compression-D4IkO5vE.js +0 -1
  76. package/dist/errors-THVaUwlL.js +0 -1
  77. package/dist/material-draw-state-BHeTb1FP.js +0 -1
  78. package/dist/model-iRvuj19h.js +0 -39
  79. package/dist/optimize-7SEzNA23.js +0 -1
  80. package/dist/pack-BVDYuqZe.js +0 -1
  81. package/dist/src-WMRHArDp.js +0 -4
  82. package/dist/stream-C3bKMy1B.js +0 -1
  83. package/dist/version-BmU1nesQ.js +0 -1
@@ -1,152 +1,159 @@
1
- /** Vertex buffers of a 24-byte (core) or 80-byte (gltf/pbr) caster, plus instance matrices when `instanced`. */
2
- export function casterBuffers(stride: number, displaced?: boolean, instanced?: boolean): GPUVertexBufferLayout[];
3
- /** How a caster cuts its surface out like its colour pass, besides its alpha texture and cutoff. */
4
- export interface CasterCutout {
5
- /** UV transform of `alphaTexture` (80-byte vertices): 8 finite floats, rows (a, b, offset, unused) for u and then v. */
6
- alphaTransform?: Float32Array;
7
- /** Opacity map of the cut-out (materials `alphaMap`, 80-byte vertices): its green channel multiplies the alpha tested. */
8
- opacity?: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler };
9
- /**
10
- * Moving UVs of the cut-out (VRMC_materials_mtoon 1.0 UV animation, 80-byte vertices): an 80-byte uniform (scroll x,
11
- * scroll y, rotation, time; the base map's affine rows; the mask's affine rows), the mask view and its sampler. The
12
- * alpha map is read at the animated UV in place of `alphaTransform`'s, as the colour pass reads it.
13
- */
14
- animation?: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler };
15
- /** False keeps vertex alpha out of the cut-out, as the colour pass does (materials `vertexColors: false`). Default true. */
16
- vertexAlpha?: boolean;
17
- /**
18
- * Cuts against hashed noise instead of `cutoff`, as materials `alphaHash()` does in its colour pass, so the shadow
19
- * keeps a share of texels equal to the opacity: the caster shader edit (shared/alpha-hash.js `hashedDepth`) that a
20
- * materials record hands over as `castHashed`, so only an app that imports `alphaHash` carries its WGSL. Only a
21
- * primitive that cuts (`cutoff` above 0) uses it. Default none.
22
- */
23
- hashed?: (code: string) => string;
24
- /** Vertex displacement along the normal (materials `displacementMap`, 80-byte vertices). */
25
- displacement?: CasterDisplacement;
26
- /** Planes that clip the shadow (materials `clippingPlanes` with `clipShadows`, 80-byte vertices). */
27
- clip?: GPUBufferBinding;
28
- /** Planes that clip the surface, whatever `clipShadows` says (80-byte vertices). */
29
- surfaceClip?: GPUBufferBinding;
30
- }
31
- /**
32
- * What moves a caster's vertices: a displacement map's uniform, view and sampler, or a shader patch of its own (a
33
- * NodeMaterial's graph), with a `key` for its pipeline and its bind group.
34
- */
35
- export type CasterDisplacement =
36
- | {
37
- readonly buffer: GPUBuffer;
38
- readonly view: GPUTextureView;
39
- readonly sampler: GPUSampler;
40
- readonly key?: undefined;
41
- readonly depth?: undefined;
42
- readonly velocity?: undefined;
43
- readonly entries?: undefined;
44
- readonly layout?: undefined;
45
- readonly cuts?: undefined;
46
- readonly move?: undefined;
47
- readonly program?: undefined;
48
- }
49
- | {
50
- readonly key: string;
51
- depth(code: string, group: number): string;
52
- /** TAA's object velocity shader, moved and cut as `depth` does it. Absent on a patch that does not support it. */
53
- velocity?(code: string, group: number): string;
54
- entries(): GPUBindGroupEntry[];
55
- /** The group's layout, for passes that build their pipeline layouts by hand. */
56
- layout(): GPUBindGroupLayout;
57
- /** The patch discards fragments, so a pass that skips the fragment stage of opaque casters needs it here. */
58
- readonly cuts: boolean;
59
- /**
60
- * The WGSL lines of the patch's move of `margoPosition` alone (empty: no move), and its program: TAA runs a move
61
- * that reads the uniform block `ndu` again on last frame's bytes of it, bound at `program.next`.
62
- */
63
- readonly move?: readonly string[];
64
- readonly program?: { readonly next: number; readonly buffers: WeakMap<GPUDevice, { bytes: Uint8Array }> };
65
- };
66
- /** A depth-only caster pipeline (less-equal depth into depth32float, line lists for `lines`). */
67
- export function casterPipeline(
68
- device: GPUDevice,
69
- module: GPUShaderModule,
70
- stride: number,
71
- displaced: boolean,
72
- instanced: boolean,
73
- lines: boolean | undefined,
74
- ): GPURenderPipeline;
75
- /** The per-primitive draw records of `node` in `draws`, created empty on first use. */
76
- export function nodeRecords<N, K, R>(draws: Map<N, Map<K, R>>, node: N): Map<K, R>;
77
- /** The runtime object of a caster source; throws MargoError 'disposed' or 'attached'. */
78
- export function casterRuntime<S extends object, R>(source: S, engine: unknown, noun: string): R;
79
- /**
80
- * The bind group of a displaced caster: its feature uniform, map and sampler; else undefined. Also undefined when the
81
- * displacement binds nothing and `layout` is an automatic layout's group (`explicit` false, the default), which a
82
- * default pipeline layout does not hold.
83
- */
84
- export function displacementGroup(
85
- device: GPUDevice,
86
- layout: () => GPUBindGroupLayout,
87
- displacement: CasterDisplacement | undefined,
88
- explicit?: boolean,
89
- ): GPUBindGroup | undefined;
90
- /** WGSL of a moving cut-out (MToon UV animation) at bindings `first` to `first` + 2 (default 7), and `margoAnimatedUV`. */
91
- export function animationCode(group: number, first?: number): string;
92
- /** A caster depth shader whose cut-out reads its alpha map at the animated UV, bound at 7-9 of `group`. */
93
- export function animatedDepth(code: string, group: number, first?: number): string;
94
- /** The bind group entries of a caster's UV `animation`, from binding `first` (default 7). */
95
- export function animationEntries(
96
- animation: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler },
97
- first?: number,
98
- ): GPUBindGroupEntry[];
99
- /** WGSL of an opacity map at bindings `first` to `first` + 2 (default 4) of `group`, and `margoOpacityAt` of both UV sets. */
100
- export function opacityCode(group: number, first?: number): string;
101
- /** A caster depth shader whose cut-out also multiplies by an opacity map's green channel, bound at 4-6 of `group`. */
102
- export function opacityDepth(code: string, group: number): string;
103
- /** The bind group entries of a caster's `opacity`, from binding `first` (default 4). */
104
- export function opacityEntries(
105
- opacity: {
106
- buffer: GPUBuffer;
107
- view: GPUTextureView;
108
- sampler: GPUSampler;
109
- },
110
- first?: number,
111
- ): GPUBindGroupEntry[];
112
- /** A caster shader that leaves vertex alpha out of its cut-out (a primitive with `vertexAlpha: false`). */
113
- export function solidVertexDepth(code: string): string;
114
- /** A caster shader that discards what uniform `name`'s planes cut away, bound at `binding` of group 0. */
115
- export function clippedDepth(code: string, binding: number, name: string, hardware?: boolean): string;
116
- /** A cleared depth-only pass descriptor; set `depthStencilAttachment.view` before each use. */
117
- export function depthPassDescriptor(): GPURenderPassDescriptor & {
118
- depthStencilAttachment: GPURenderPassDepthStencilAttachment;
119
- };
120
- /** Writes one caster's uniform (view, node matrix, alpha, cutoff at least `floor`, uv set, alpha transform), uploads it and draws. */
121
- export function drawCaster(
122
- pass: GPURenderPassEncoder,
123
- device: GPUDevice,
124
- pipeline: GPURenderPipeline,
125
- group: GPUBindGroup,
126
- uniform: GPUBuffer,
127
- values: Float32Array<ArrayBuffer>,
128
- view: ArrayLike<number>,
129
- p: {
130
- node: { matrix: ArrayLike<number> };
131
- alpha?: number;
132
- cutoff?: number;
133
- texCoord?: number;
134
- vertex: GPUBuffer;
135
- /** Byte offset of the caster's vertices in `vertex`. Default 0. */
136
- vertexOffset?: number;
137
- index: GPUBuffer;
138
- count: number;
139
- },
140
- transform: ArrayLike<number> | undefined | null,
141
- displaced: GPUBindGroup | undefined,
142
- instances: { upload(device: GPUDevice): GPUBuffer; count: number } | undefined | null,
143
- /** Lowest cutoff written: the larger of this and `p.cutoff`. Default 0. */
144
- floor?: number,
145
- ): void;
146
- /** Whether a caster's cached draw `record` no longer fits primitive `p` drawn with `pipeline` and `displacement`. */
147
- export function staleCaster<R extends object>(
148
- record: R | undefined,
149
- p: { vertex: GPUBuffer; alphaTexture?: unknown; alphaSampler?: unknown; opacity?: unknown; animation?: unknown },
150
- pipeline: GPURenderPipeline,
151
- displacement: unknown,
152
- ): record is undefined;
1
+ /** Vertex buffers of a 24-byte (core) or 80-byte (gltf/pbr) caster, plus instance matrices when `instanced`. */
2
+ export function casterBuffers(stride: number, displaced?: boolean, instanced?: boolean): GPUVertexBufferLayout[];
3
+ /** How a caster cuts its surface out like its colour pass, besides its alpha texture and cutoff. */
4
+ export interface CasterCutout {
5
+ /** UV transform of `alphaTexture` (80-byte vertices): 8 finite floats, rows (a, b, offset, unused) for u and then v. */
6
+ alphaTransform?: Float32Array;
7
+ /** Opacity map of the cut-out (materials `alphaMap`, 80-byte vertices): its green channel multiplies the alpha tested. */
8
+ opacity?: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler };
9
+ /**
10
+ * Moving UVs of the cut-out (VRMC_materials_mtoon 1.0 UV animation, 80-byte vertices): an 80-byte uniform (scroll x,
11
+ * scroll y, rotation, time; the base map's affine rows; the mask's affine rows), the mask view and its sampler. The
12
+ * alpha map is read at the animated UV in place of `alphaTransform`'s, as the colour pass reads it.
13
+ */
14
+ animation?: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler };
15
+ /** False keeps vertex alpha out of the cut-out, as the colour pass does (materials `vertexColors: false`). Default true. */
16
+ vertexAlpha?: boolean;
17
+ /**
18
+ * Cuts against hashed noise instead of `cutoff`, as materials `alphaHash()` does in its colour pass, so the shadow
19
+ * keeps a share of texels equal to the opacity: the caster shader edit (shared/alpha-hash.js `hashedDepth`) that a
20
+ * materials record hands over as `castHashed`, so only an app that imports `alphaHash` carries its WGSL. Only a
21
+ * primitive that cuts (`cutoff` above 0) uses it. Default none.
22
+ */
23
+ hashed?: (code: string) => string;
24
+ /** Vertex displacement along the normal (materials `displacementMap`, 80-byte vertices). */
25
+ displacement?: CasterDisplacement;
26
+ /** Planes that clip the shadow (materials `clippingPlanes` with `clipShadows`, 80-byte vertices). */
27
+ clip?: GPUBufferBinding;
28
+ /** Planes that clip the surface, whatever `clipShadows` says (80-byte vertices). */
29
+ surfaceClip?: GPUBufferBinding;
30
+ }
31
+ /**
32
+ * What moves a caster's vertices: a displacement map's uniform, view and sampler, or a shader patch of its own (a
33
+ * NodeMaterial's graph), with a `key` for its pipeline and its bind group.
34
+ */
35
+ export type CasterDisplacement =
36
+ | {
37
+ readonly buffer: GPUBuffer;
38
+ readonly view: GPUTextureView;
39
+ readonly sampler: GPUSampler;
40
+ readonly key?: undefined;
41
+ readonly depth?: undefined;
42
+ readonly velocity?: undefined;
43
+ readonly entries?: undefined;
44
+ readonly layout?: undefined;
45
+ readonly cuts?: undefined;
46
+ readonly move?: undefined;
47
+ readonly program?: undefined;
48
+ }
49
+ | {
50
+ readonly key: string;
51
+ depth(code: string, group: number): string;
52
+ /** TAA's object velocity shader, moved and cut as `depth` does it. Absent on a patch that does not support it. */
53
+ velocity?(code: string, group: number): string;
54
+ entries(): GPUBindGroupEntry[];
55
+ /** The group's layout, for passes that build their pipeline layouts by hand. */
56
+ layout(): GPUBindGroupLayout;
57
+ /** The patch discards fragments, so a pass that skips the fragment stage of opaque casters needs it here. */
58
+ readonly cuts: boolean;
59
+ /**
60
+ * The WGSL lines of the patch's move of `margoPosition` alone (empty: no move), and its program: TAA runs a move
61
+ * that reads the uniform block `ndu` again on last frame's bytes of it, bound at `program.next`.
62
+ */
63
+ readonly move?: readonly string[];
64
+ readonly program?: { readonly next: number; readonly buffers: WeakMap<GPUDevice, { bytes: Uint8Array }> };
65
+ };
66
+ /** A depth-only caster pipeline (less-equal depth into depth32float, line lists for `lines`). */
67
+ export function casterPipeline(
68
+ device: GPUDevice,
69
+ module: GPUShaderModule,
70
+ stride: number,
71
+ displaced: boolean,
72
+ instanced: boolean,
73
+ lines: boolean | undefined,
74
+ ): GPURenderPipeline;
75
+ /** The per-primitive draw records of `node` in `draws`, created empty on first use. */
76
+ export function nodeRecords<N, K, R>(draws: Map<N, Map<K, R>>, node: N): Map<K, R>;
77
+ /** The runtime object of a caster source; throws MargoError 'disposed' or 'attached'. */
78
+ export function casterRuntime<S extends object, R>(source: S, engine: unknown, noun: string): R;
79
+ /**
80
+ * The bind group of a displaced caster: its feature uniform, map and sampler; else undefined. Also undefined when the
81
+ * displacement binds nothing and `layout` is an automatic layout's group (`explicit` false, the default), which a
82
+ * default pipeline layout does not hold.
83
+ */
84
+ export function displacementGroup(
85
+ device: GPUDevice,
86
+ layout: () => GPUBindGroupLayout,
87
+ displacement: CasterDisplacement | undefined,
88
+ explicit?: boolean,
89
+ ): GPUBindGroup | undefined;
90
+ /** WGSL of a moving cut-out (MToon UV animation) at bindings `first` to `first` + 2 (default 7), and `margoAnimatedUV`. */
91
+ export function animationCode(group: number, first?: number): string;
92
+ /** A caster depth shader whose cut-out reads its alpha map at the animated UV, bound at 7-9 of `group`. */
93
+ export function animatedDepth(code: string, group: number, first?: number): string;
94
+ /** The bind group entries of a caster's UV `animation`, from binding `first` (default 7). */
95
+ export function animationEntries(
96
+ animation: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler },
97
+ first?: number,
98
+ ): GPUBindGroupEntry[];
99
+ /** WGSL of an opacity map at bindings `first` to `first` + 2 (default 4) of `group`, and `margoOpacityAt` of both UV sets. */
100
+ export function opacityCode(group: number, first?: number): string;
101
+ /** A caster depth shader whose cut-out also multiplies by an opacity map's green channel, bound at 4-6 of `group`. */
102
+ export function opacityDepth(code: string, group: number): string;
103
+ /** The bind group entries of a caster's `opacity`, from binding `first` (default 4). */
104
+ export function opacityEntries(
105
+ opacity: {
106
+ buffer: GPUBuffer;
107
+ view: GPUTextureView;
108
+ sampler: GPUSampler;
109
+ },
110
+ first?: number,
111
+ ): GPUBindGroupEntry[];
112
+ /** A caster shader that leaves vertex alpha out of its cut-out (a primitive with `vertexAlpha: false`). */
113
+ export function solidVertexDepth(code: string): string;
114
+ /** A caster shader that discards what uniform `name`'s planes cut away, bound at `binding` of `group` (default 0); its vertex stage writes `o.clip=<camera>*...` (default `f.camera`). */
115
+ export function clippedDepth(
116
+ code: string,
117
+ binding: number,
118
+ name: string,
119
+ hardware?: boolean,
120
+ group?: number,
121
+ camera?: string,
122
+ ): string;
123
+ /** A cleared depth-only pass descriptor; set `depthStencilAttachment.view` before each use. */
124
+ export function depthPassDescriptor(): GPURenderPassDescriptor & {
125
+ depthStencilAttachment: GPURenderPassDepthStencilAttachment;
126
+ };
127
+ /** Writes one caster's uniform (view, node matrix, alpha, cutoff at least `floor`, uv set, alpha transform), uploads it and draws. */
128
+ export function drawCaster(
129
+ pass: GPURenderPassEncoder,
130
+ device: GPUDevice,
131
+ pipeline: GPURenderPipeline,
132
+ group: GPUBindGroup,
133
+ uniform: GPUBuffer,
134
+ values: Float32Array<ArrayBuffer>,
135
+ view: ArrayLike<number>,
136
+ p: {
137
+ node: { matrix: ArrayLike<number> };
138
+ alpha?: number;
139
+ cutoff?: number;
140
+ texCoord?: number;
141
+ vertex: GPUBuffer;
142
+ /** Byte offset of the caster's vertices in `vertex`. Default 0. */
143
+ vertexOffset?: number;
144
+ index: GPUBuffer;
145
+ count: number;
146
+ },
147
+ transform: ArrayLike<number> | undefined | null,
148
+ displaced: GPUBindGroup | undefined,
149
+ instances: { upload(device: GPUDevice): GPUBuffer; count: number } | undefined | null,
150
+ /** Lowest cutoff written: the larger of this and `p.cutoff`. Default 0. */
151
+ floor?: number,
152
+ ): void;
153
+ /** Whether a caster's cached draw `record` no longer fits primitive `p` drawn with `pipeline` and `displacement`. */
154
+ export function staleCaster<R extends object>(
155
+ record: R | undefined,
156
+ p: { vertex: GPUBuffer; alphaTexture?: unknown; alphaSampler?: unknown; opacity?: unknown; animation?: unknown },
157
+ pipeline: GPURenderPipeline,
158
+ displacement: unknown,
159
+ ): record is undefined;