@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
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
import { type BaseTextureSource, type PackedBaseTextures } from './base-textures.js';
|
|
2
|
+
import type { GLTFPrimitive, GLTFMaterial, GLTFTextureInfo } from './shared/gltf.js';
|
|
3
|
+
import type { EngineKernel, Mesh as PublicMesh, Scene as CoreScene } from '@margoengine/core';
|
|
4
|
+
import { type Engine, type EnginePlugin, type FrameGraph, type PassContext, type Mesh } from '@margoengine/core/extension';
|
|
5
|
+
import { type UniformSlot } from './uniform-arena.js';
|
|
6
|
+
import { type DeviceDraws, type DrawDerivation, type DrawFrame } from './draw-memo.js';
|
|
7
|
+
import { type BatchState, type RowsState } from './draw-batch.js';
|
|
8
|
+
import { validatePreparedGeometry } from './shared/prepared-geometry.js';
|
|
9
|
+
import { GLTFAsset, type GLTFImage, type GLTFStreamedImage, type AssetOptions, type GLTFDecoderHooks, type GLTFExtendedMaterials } from './asset.js';
|
|
10
|
+
import { type ExtendedPlan, type PBRLighting, type PBRTransparency, type PBRCapture, type PBRTransmission } from './shader.js';
|
|
11
|
+
export type { PBRLighting, PBRTransparency, PBRCapture, PBRTransmission, ExtendedPlan } from './shader.js';
|
|
12
|
+
import { type MaterialExtension, type MaterialExtensionResource } from './material-extension.js';
|
|
13
|
+
import type { GLTFLoadOptions as CompressionOptions } from './compression.js';
|
|
14
|
+
import { type CoordinateExtension } from './texture-coordinates.js';
|
|
15
|
+
import { type PBRDeviceRenderer, type PBRDeformationRenderer } from './replica.js';
|
|
16
|
+
export type { PBRDeviceDrawOptions, PBRDeviceRenderer, PBRDeformationRenderer } from './replica.js';
|
|
17
|
+
import type { PBRInstances } from './pbr-instancing.js';
|
|
18
|
+
import { type StaticBatch } from './coalesce.js';
|
|
19
|
+
export { GLTFAsset, closeImages } from './asset.js';
|
|
20
|
+
export type { GLTFDocument } from './asset.js';
|
|
21
|
+
export type { GLTFImage, GLTFPixelImage, GLTFStreamedImage, GLTFStreamSource, GLTFTextureOpener, KTX2Image, } from './asset.js';
|
|
22
|
+
export { textureCoordinates } from './texture-coordinates.js';
|
|
23
|
+
import type { TextureTransform } from './texture-coordinates.js';
|
|
24
|
+
export type { TextureTransform } from './texture-coordinates.js';
|
|
25
|
+
export type { MaterialExtension, MaterialExtensionTexture } from './material-extension.js';
|
|
26
|
+
/** KHR_lights_punctual light on a scene node, as data. Intensity is candela (point, spot) or lux (directional); the light points down the node's -Z. */
|
|
27
|
+
export interface GLTFLight {
|
|
28
|
+
node: Mesh;
|
|
29
|
+
nodeIndex: number;
|
|
30
|
+
type: 'directional' | 'point' | 'spot';
|
|
31
|
+
color: number[];
|
|
32
|
+
intensity: number;
|
|
33
|
+
range?: number;
|
|
34
|
+
innerConeAngle?: number;
|
|
35
|
+
outerConeAngle?: number;
|
|
36
|
+
name?: string;
|
|
37
|
+
}
|
|
38
|
+
/** glTF camera on a scene node, as data; the camera looks down the node's -Z. */
|
|
39
|
+
export interface GLTFCamera {
|
|
40
|
+
node: Mesh;
|
|
41
|
+
nodeIndex: number;
|
|
42
|
+
type: 'perspective' | 'orthographic';
|
|
43
|
+
perspective?: {
|
|
44
|
+
yfov: number;
|
|
45
|
+
znear: number;
|
|
46
|
+
zfar?: number;
|
|
47
|
+
aspectRatio?: number;
|
|
48
|
+
};
|
|
49
|
+
orthographic?: {
|
|
50
|
+
xmag: number;
|
|
51
|
+
ymag: number;
|
|
52
|
+
znear: number;
|
|
53
|
+
zfar: number;
|
|
54
|
+
};
|
|
55
|
+
name?: string;
|
|
56
|
+
}
|
|
57
|
+
/** One object of `PBRModel.lods`, read from a node's `MSFT_lod` extension. */
|
|
58
|
+
export interface GLTFLOD {
|
|
59
|
+
/** The node that carries the extension: the finest level, and the object's place in the scene. */
|
|
60
|
+
node: Mesh;
|
|
61
|
+
/** Every level, finest first: `node`, then its `MSFT_lod` ids. All but the first start hidden. */
|
|
62
|
+
levels: Mesh[];
|
|
63
|
+
/**
|
|
64
|
+
* The node's `extras.MSFT_screencoverage`, when it has them, decreasing: entry `i` is the screen coverage below which
|
|
65
|
+
* level `i` gives way to the next. An extra last entry hides the object below it.
|
|
66
|
+
*/
|
|
67
|
+
screenCoverage?: number[];
|
|
68
|
+
}
|
|
69
|
+
/** A node's glTF `extras` object (Blender: the object's custom properties, exported with Include > Custom Properties) and a copy of its world matrix (column-major, translation in 12-14). */
|
|
70
|
+
export interface GLTFNodeExtras {
|
|
71
|
+
node: Mesh;
|
|
72
|
+
nodeIndex: number;
|
|
73
|
+
name: string;
|
|
74
|
+
extras: Record<string, unknown>;
|
|
75
|
+
matrix: Float32Array;
|
|
76
|
+
}
|
|
77
|
+
/** Point or spot light shaped for @margoengine/clustered `setLights`. */
|
|
78
|
+
export interface GLTFClusteredLight {
|
|
79
|
+
position: [number, number, number];
|
|
80
|
+
range: number;
|
|
81
|
+
color: [number, number, number];
|
|
82
|
+
intensity: number;
|
|
83
|
+
direction?: [number, number, number];
|
|
84
|
+
outerAngle?: number;
|
|
85
|
+
innerAngle?: number;
|
|
86
|
+
}
|
|
87
|
+
/** What `applyGLTFLights` uses of @margoengine/clustered's `Clustered` (structural, so gltf/pbr does not import it). */
|
|
88
|
+
export interface GLTFLightReceiver {
|
|
89
|
+
setLights(lights: GLTFClusteredLight[]): unknown;
|
|
90
|
+
add(model: PBRModel): () => void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Options of loadGLTF: asset limits and fetch options, plus the Draco, meshopt and KTX2 decoders and an AbortSignal.
|
|
94
|
+
*/
|
|
95
|
+
export type GLTFLoadOptions = Omit<AssetOptions, 'buffers'> & CompressionOptions;
|
|
96
|
+
import type { GLTFSplatCloud } from './asset.js';
|
|
97
|
+
export type { GLTFDecoderHooks, GLTFCompressedImage, GLTFExtendedMaterials, GLTFSplatCloud, GLTFSplatReader, } from './asset.js';
|
|
98
|
+
type Context = Extract<PassContext, {
|
|
99
|
+
backend: 'webgpu';
|
|
100
|
+
}>;
|
|
101
|
+
/** A caller-owned, already-open eye pass (`createRenderer`); `pass` is the one open after the draw. */
|
|
102
|
+
type ExternalPass = {
|
|
103
|
+
pass: GPURenderPassEncoder;
|
|
104
|
+
view: ArrayLike<number>;
|
|
105
|
+
depthCompare: GPUCompareFunction;
|
|
106
|
+
};
|
|
107
|
+
/** Narrow encoding hook for optional GPU deformation consumers. */
|
|
108
|
+
export type PBRDeformationContext = Pick<Context, 'backend' | 'device' | 'encoder'>;
|
|
109
|
+
/** The triangles of one node for picking: its vertices, indices, sidedness and world matrix. */
|
|
110
|
+
export interface PBRPickingGeometry {
|
|
111
|
+
node: Mesh;
|
|
112
|
+
vertices: Float32Array;
|
|
113
|
+
indices: Uint32Array;
|
|
114
|
+
doubleSided: boolean;
|
|
115
|
+
side?: MaterialSide;
|
|
116
|
+
matrix: Float32Array;
|
|
117
|
+
/**
|
|
118
|
+
* Index of the primitive in `model.primitives`, captured when the query started (before any GPU readback). Absent
|
|
119
|
+
* for point and line primitives, which `model.primitives` does not list.
|
|
120
|
+
*/
|
|
121
|
+
primitiveIndex?: number;
|
|
122
|
+
/** glTF node index of the primitive, captured with `primitiveIndex`. Absent for a primitive with no glTF node. */
|
|
123
|
+
nodeIndex?: number;
|
|
124
|
+
}
|
|
125
|
+
/** What a run's short path (`PBRModel.joinRun`) checked once for its pass context. */
|
|
126
|
+
interface QuickRun {
|
|
127
|
+
c: Context;
|
|
128
|
+
section: GPUBuffer | undefined;
|
|
129
|
+
draws: DeviceDraws;
|
|
130
|
+
/** A caller-owned opaque phase is open (`beginOpaquePass`): draws take the full path. */
|
|
131
|
+
opaque: boolean;
|
|
132
|
+
/** The run's view block matched the camera, lights and target since the last full draw. */
|
|
133
|
+
viewChecked: boolean;
|
|
134
|
+
/** The last derivation context, and the model inputs it was made for. */
|
|
135
|
+
frame: DrawFrame | undefined;
|
|
136
|
+
lighting: readonly LightingEffect[] | undefined;
|
|
137
|
+
oit: object | undefined;
|
|
138
|
+
hook: object | undefined;
|
|
139
|
+
hooks: GLTFExtendedMaterials | undefined;
|
|
140
|
+
}
|
|
141
|
+
/** A run's last view block (see `PBRDrawRun.view`). */
|
|
142
|
+
interface RunView {
|
|
143
|
+
data: Float32Array;
|
|
144
|
+
format: GPUTextureFormat | undefined;
|
|
145
|
+
at: GPUBufferBinding | undefined;
|
|
146
|
+
}
|
|
147
|
+
/** Draws of a run gathered into one instanced draw (draw-batch.ts). */
|
|
148
|
+
interface PendingBatch {
|
|
149
|
+
model: PBRModel;
|
|
150
|
+
/** The first draw's resource: its buffers, groups and batch state serve the batch. */
|
|
151
|
+
owner: DrawResource;
|
|
152
|
+
d: DrawDerivation;
|
|
153
|
+
c: Context;
|
|
154
|
+
view: object;
|
|
155
|
+
viewAt: GPUBufferBinding;
|
|
156
|
+
members: DrawResource[];
|
|
157
|
+
/** Each member's model. */
|
|
158
|
+
models: PBRModel[];
|
|
159
|
+
/** Each member's node, read for its matrix when the batch draws (not through its resource and primitive again). */
|
|
160
|
+
nodes: Mesh[];
|
|
161
|
+
/** Each member's derivation. */
|
|
162
|
+
ds: DrawDerivation[];
|
|
163
|
+
/** True once a member of another material record folded in (`foldable`): instance tints carry the base colours. */
|
|
164
|
+
folded: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* True once a member of another material record joined by its draw group (`DrawDerivation.group`): each instance
|
|
167
|
+
* reads its own uniform block (`BatchKind.rows`).
|
|
168
|
+
*/
|
|
169
|
+
rows: boolean;
|
|
170
|
+
/** The run's blended-batch count when this batch began: an opaque draw joins only a batch begun after the last one. */
|
|
171
|
+
fence: number;
|
|
172
|
+
}
|
|
173
|
+
/** What a pass has bound: draws on it set a pipeline, group or buffer only when it differs. */
|
|
174
|
+
interface PassBindings {
|
|
175
|
+
pass: GPURenderPassEncoder | undefined;
|
|
176
|
+
pipeline?: GPURenderPipeline;
|
|
177
|
+
groups: (GPUBindGroup | undefined)[];
|
|
178
|
+
vertex?: GPUBuffer;
|
|
179
|
+
vertexOffset?: number;
|
|
180
|
+
instances?: GPUBuffer;
|
|
181
|
+
uvs?: GPUBuffer;
|
|
182
|
+
index?: GPUBuffer;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A run of `PBRModel.draw` calls that share one render pass and one uniform upload (pass it as the last argument of
|
|
186
|
+
* each `draw`, then call `end()`). Without a run every draw begins and ends its own pass and uploads its own uniforms.
|
|
187
|
+
*/
|
|
188
|
+
export declare class PBRDrawRun {
|
|
189
|
+
/** The pass the run's draws continue, once one began; `end()` closes it. */
|
|
190
|
+
pass?: GPURenderPassEncoder;
|
|
191
|
+
/** @internal The draw contexts of the run's draws (draw-memo.ts); draws under an equal one share derivations. */
|
|
192
|
+
readonly frames: DrawFrame[];
|
|
193
|
+
/** @internal The last of them, and the pass context and descriptor it was matched for. */
|
|
194
|
+
lastFrame?: DrawFrame;
|
|
195
|
+
lastContext?: Context;
|
|
196
|
+
lastDescriptor?: unknown;
|
|
197
|
+
/** @internal What the run's draws bound on `pass`, so they set only what changes. */
|
|
198
|
+
readonly bindings: PassBindings;
|
|
199
|
+
/** @internal The device the run's draws record on; `end()` uploads their uniform changes there. */
|
|
200
|
+
device?: GPUDevice;
|
|
201
|
+
/** @internal The view block the run's draws bound last and the camera, lights and target it holds. */
|
|
202
|
+
readonly view: RunView;
|
|
203
|
+
/** @internal Draws waiting to draw as instanced batches (draw-batch.ts), in first-draw order, and by derivation. */
|
|
204
|
+
readonly pending: PendingBatch[];
|
|
205
|
+
/** @internal Drawn batch records, emptied, for the run's next batches. */
|
|
206
|
+
readonly spare: PendingBatch[];
|
|
207
|
+
readonly batches: Map<object, PendingBatch[]>;
|
|
208
|
+
/** @internal Blended batches begun so far (`PendingBatch.fence`), and which derivations fold together this frame. */
|
|
209
|
+
fence: number;
|
|
210
|
+
readonly folds: Map<DrawDerivation, Map<DrawDerivation, boolean>>;
|
|
211
|
+
/** @internal What `draw` checked once for the run's context: its section binding and device caches. */
|
|
212
|
+
private quick?;
|
|
213
|
+
/** @internal The run's context with its section binding and device caches, for draws that join batches. */
|
|
214
|
+
quickFor(c: Context): QuickRun;
|
|
215
|
+
/**
|
|
216
|
+
* Ends the shared pass and uploads the draws' uniform changes. Safe to call twice; the run can then carry the next
|
|
217
|
+
* frame's draws (nothing derived for this frame carries over).
|
|
218
|
+
*/
|
|
219
|
+
end(): void;
|
|
220
|
+
}
|
|
221
|
+
/** Which faces a material draws: 'front', 'back' or 'double'. */
|
|
222
|
+
export type MaterialSide = 'front' | 'back' | 'double';
|
|
223
|
+
/**
|
|
224
|
+
* A glTF PBR material as the model draws it: base colour, factors, emission, settings, side and optional extension.
|
|
225
|
+
*/
|
|
226
|
+
export interface PBRMaterial extends GLTFMaterial {
|
|
227
|
+
base: number[];
|
|
228
|
+
factors: number[];
|
|
229
|
+
emission: number[];
|
|
230
|
+
settings: number[];
|
|
231
|
+
/** Live triangle face selection. Legacy structural materials may supply only settings[2]. */
|
|
232
|
+
side?: MaterialSide;
|
|
233
|
+
/** Draw each triangle's three edges as one-pixel lines (default false), read live. Picking retains triangles. */
|
|
234
|
+
wireframe?: boolean;
|
|
235
|
+
maps: (GLTFTextureInfo | undefined)[];
|
|
236
|
+
uvt?: number[];
|
|
237
|
+
ext?: number[];
|
|
238
|
+
/** KHR_materials_dispersion strength, finite and non-negative (default 0); read live each draw. */
|
|
239
|
+
dispersion?: number;
|
|
240
|
+
physical?: number[];
|
|
241
|
+
extended?: Omit<ExtendedPlan, 'slots'>;
|
|
242
|
+
tint?: number[];
|
|
243
|
+
/** Volume attenuation at the thickness factor, for a tint draw that reads the rest from the surface (surfaceTintPBR). */
|
|
244
|
+
attenuation?: number[];
|
|
245
|
+
/** Natural optical depth at mesh thickness, before world scaling. Parsed volumes retain precision until an attenuation channel changes; replacing attenuation invalidates all channels. Default undefined derives it from attenuation. */
|
|
246
|
+
opticalDepth?: number[];
|
|
247
|
+
volume?: number[];
|
|
248
|
+
renderState?: PBRRenderState;
|
|
249
|
+
extension?: MaterialExtension;
|
|
250
|
+
/** Per-material surface shader and bindings, composed before model-wide lighting effects. */
|
|
251
|
+
shading?: PBRMaterialShading;
|
|
252
|
+
/**
|
|
253
|
+
* Vertex displacement the shading applies (`@margoengine/materials` displacementMap), for shadow casters to apply
|
|
254
|
+
* too: the materials feature uniform, the map's view and its sampler (shared/displacement.js `displacedDepth`).
|
|
255
|
+
*/
|
|
256
|
+
displacement?: import('./shared/caster.js').CasterDisplacement;
|
|
257
|
+
/**
|
|
258
|
+
* Clipping planes the shading applies (`@margoengine/materials` clippingPlanes with clipShadows), for shadow casters
|
|
259
|
+
* to clip too: a uniform of up to 6 world planes in the scene `section` binding's layout (plane count in settings.x).
|
|
260
|
+
*/
|
|
261
|
+
clip?: GPUBufferBinding;
|
|
262
|
+
/** True when those planes may cut in the rasterizer: a union of planes on a device with 'clip-distances'. */
|
|
263
|
+
clipHardware?: boolean;
|
|
264
|
+
/** The same planes for passes that follow the surface and not its shadow: picking and TAA velocity. */
|
|
265
|
+
surfaceClip?: GPUBufferBinding;
|
|
266
|
+
/**
|
|
267
|
+
* The cut-out a material draws from its own maps (`@margoengine/materials` map and alphaMap with alphaTest), for shadow
|
|
268
|
+
* casters to cut alike in place of `maps[0]`: the map's view and sampler, its UV set and affine rows, and an opacity map
|
|
269
|
+
* if any (the materials feature uniform, its view and sampler). Absent for anything uncut, which draws as ever.
|
|
270
|
+
*/
|
|
271
|
+
castMask?: {
|
|
272
|
+
readonly view: GPUTextureView;
|
|
273
|
+
readonly sampler: GPUSampler;
|
|
274
|
+
readonly texCoord: 0 | 1;
|
|
275
|
+
readonly transform: Float32Array;
|
|
276
|
+
readonly opacity?: {
|
|
277
|
+
readonly buffer: GPUBuffer;
|
|
278
|
+
readonly view: GPUTextureView;
|
|
279
|
+
readonly sampler: GPUSampler;
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
/** The same mask for picking, which a blended material's holes also pass through. Absent draws as ever. */
|
|
283
|
+
pickMask?: PBRMaterial['castMask'];
|
|
284
|
+
/**
|
|
285
|
+
* Moving UVs of the shadow cut-out, as the colour pass moves them (`@margoengine/rigging` MToon UV animation): an
|
|
286
|
+
* 80-byte uniform, the mask view and its sampler (shared/caster.js `animationCode`). Absent casts as ever.
|
|
287
|
+
*/
|
|
288
|
+
castAnimation?: {
|
|
289
|
+
readonly buffer: GPUBuffer;
|
|
290
|
+
readonly view: GPUTextureView;
|
|
291
|
+
readonly sampler: GPUSampler;
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* Set when the colour pass cuts against hashed noise (`@margoengine/materials` `alphaHash()`): the caster shader edit
|
|
295
|
+
* that makes shadow casters cut by the same object-space hash instead of the cutoff, so the shadow keeps a share of
|
|
296
|
+
* texels equal to the opacity. The material carries it, so a shadow package bundles no hash WGSL of its own.
|
|
297
|
+
*/
|
|
298
|
+
castHashed?: (code: string) => string;
|
|
299
|
+
/** False when the material's colour pass reads white for vertex colours (`@margoengine/materials` `vertexColors`). */
|
|
300
|
+
vertexAlpha?: boolean;
|
|
301
|
+
/** Use the retained UV-transform frame layout for constructed optional materials. */
|
|
302
|
+
extendedFrame?: boolean;
|
|
303
|
+
}
|
|
304
|
+
/** One drawn glTF primitive: its node, CPU vertices and indices, source definition, material and morph weights. */
|
|
305
|
+
export interface PBRPrimitive {
|
|
306
|
+
node: Mesh;
|
|
307
|
+
nodeIndex: number;
|
|
308
|
+
vertices: Float32Array;
|
|
309
|
+
indices: Uint32Array;
|
|
310
|
+
/** TEXCOORD_2 and 3, four floats a vertex, when a material of the primitive reads either: a second vertex buffer. */
|
|
311
|
+
uvs?: Float32Array;
|
|
312
|
+
definition: GLTFPrimitive;
|
|
313
|
+
material: PBRMaterial;
|
|
314
|
+
weights: Float32Array;
|
|
315
|
+
targetNames: string[];
|
|
316
|
+
/** Overrides the material's shared extension when supplied. Attach after loading. */
|
|
317
|
+
extension?: MaterialExtension;
|
|
318
|
+
/**
|
|
319
|
+
* The current deformed (skinned or morphed) vertices, written each frame by a deformer such as `@margoengine/animation`;
|
|
320
|
+
* the primitive's 80-byte vertices start `deformedOffset` bytes into it. Unset: draw the bind-pose `buffers.vertex`.
|
|
321
|
+
*/
|
|
322
|
+
deformed?: GPUBuffer;
|
|
323
|
+
/**
|
|
324
|
+
* Byte offset of this primitive's first vertex in `deformed`, a multiple of 256 (a storage-binding offset). Default 0.
|
|
325
|
+
* Deformers that pack many primitives into one buffer set it; read `vertices.byteLength` bytes from there.
|
|
326
|
+
*/
|
|
327
|
+
deformedOffset?: number;
|
|
328
|
+
/** Draw once per instance (node space) in one instanced draw, see `PBRInstances` (@margoengine/gltf/pbr-instancing); set for EXT_mesh_gpu_instancing nodes when `decoders.instancing` is passed. */
|
|
329
|
+
instances?: PBRInstances;
|
|
330
|
+
/**
|
|
331
|
+
* Set by a GPU-culling package (`CulledModels` in @margoengine/culling/models) on a primitive with `instances`: its
|
|
332
|
+
* draws read rows from `instances` and drawIndexedIndirect arguments from `args` (offset 0), as core reads
|
|
333
|
+
* `Batch.redirect`. Depth casters, picking and export keep reading every row. A wireframe draw ignores it.
|
|
334
|
+
*/
|
|
335
|
+
redirect?: {
|
|
336
|
+
instances: GPUBuffer;
|
|
337
|
+
args: GPUBuffer;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Set by a GPU-culling package (`CulledModels` in @margoengine/culling/models) on a primitive without `instances`: its
|
|
341
|
+
* own draw reads drawIndexedIndirect arguments from `args` at `offset`, so a culled primitive draws nothing. Depth
|
|
342
|
+
* casters, picking and export ignore it, and so do a wireframe draw and a draw joined into an instanced batch.
|
|
343
|
+
*/
|
|
344
|
+
culled?: {
|
|
345
|
+
args: GPUBuffer;
|
|
346
|
+
offset: number;
|
|
347
|
+
};
|
|
348
|
+
/** The 80-byte-stride vertex and uint32 index buffers while the model is set up on a device (for picking and outlines). */
|
|
349
|
+
buffers?: {
|
|
350
|
+
vertex: GPUBuffer;
|
|
351
|
+
index: GPUBuffer;
|
|
352
|
+
};
|
|
353
|
+
/** Set for glTF POINTS (`point-list`) and LINES, LINE_LOOP, LINE_STRIP (`line-list`, as index pairs); absent for triangles. */
|
|
354
|
+
topology?: 'point-list' | 'line-list';
|
|
355
|
+
/**
|
|
356
|
+
* Set when the primitive's definition has more vertices than `maxPartVertices`: this is part `index` of `count`, all
|
|
357
|
+
* with the same node, material and definition. `vertexMap` holds the definition's vertex for each local vertex:
|
|
358
|
+
* read any per-vertex accessor of the definition (JOINTS_n, WEIGHTS_n, morph target deltas) through it.
|
|
359
|
+
*/
|
|
360
|
+
part?: PrimitivePart;
|
|
361
|
+
}
|
|
362
|
+
/** Where a part of a split primitive comes from (see `PBRPrimitive.part`). */
|
|
363
|
+
export interface PrimitivePart {
|
|
364
|
+
index: number;
|
|
365
|
+
count: number;
|
|
366
|
+
vertexMap: Uint32Array;
|
|
367
|
+
}
|
|
368
|
+
/** Packed geometry: 20 floats per vertex and uint32 indices; `topology` as on PBRPrimitive (absent: a triangle list). */
|
|
369
|
+
export interface PreparedGeometry {
|
|
370
|
+
/** Convex interpolants of authored unit normals/tangents, for triangle clipping. Normalize only in the fragment shader. Default false. */
|
|
371
|
+
interpolatedDirections?: boolean;
|
|
372
|
+
vertices: Float32Array;
|
|
373
|
+
indices: Uint32Array;
|
|
374
|
+
/** TEXCOORD_2 and 3, four floats a vertex, when a material of the primitive reads either. */
|
|
375
|
+
uvs?: Float32Array;
|
|
376
|
+
topology?: 'point-list' | 'line-list';
|
|
377
|
+
/** Set on each part of a primitive split into parts (`PBRPrimitive.part`). */
|
|
378
|
+
part?: PrimitivePart;
|
|
379
|
+
}
|
|
380
|
+
/** A prepared primitive: one geometry, or its parts. */
|
|
381
|
+
export type PreparedPrimitive = PreparedGeometry | readonly PreparedGeometry[];
|
|
382
|
+
/**
|
|
383
|
+
* Optional beauty-pass pipeline overrides, set as `primitive.material.renderState` (shared by every primitive using
|
|
384
|
+
* that material). Unset fields keep gltf/pbr's defaults; `blend: null` turns blending off. The state is part of the
|
|
385
|
+
* pipeline cache key, so treat it as fixed (replace the object to change it). G-buffer and ambient passes ignore it.
|
|
386
|
+
*/
|
|
387
|
+
export interface PBRRenderState {
|
|
388
|
+
blend?: GPUBlendState | null;
|
|
389
|
+
depthWrite?: boolean;
|
|
390
|
+
depthCompare?: GPUCompareFunction;
|
|
391
|
+
/** Native WebGPU polygon bias, applied before the reverse-Z depth test. Ignored for points and lines. */
|
|
392
|
+
depthBias?: number;
|
|
393
|
+
depthBiasSlopeScale?: number;
|
|
394
|
+
depthBiasClamp?: number;
|
|
395
|
+
/** Native preserves literal WebGPU bias. Away makes positive bias recede in reverse-Z and forward-Z device views. */
|
|
396
|
+
depthBiasMode?: 'native' | 'away';
|
|
397
|
+
/** Native raster front/back faces, including reflected winding, as defined by WebGPU. */
|
|
398
|
+
stencilFront?: GPUStencilFaceState;
|
|
399
|
+
stencilBack?: GPUStencilFaceState;
|
|
400
|
+
stencilReadMask?: number;
|
|
401
|
+
stencilWriteMask?: number;
|
|
402
|
+
/** Live per-draw reference; changing only this value preserves the pipeline. */
|
|
403
|
+
stencilReference?: number;
|
|
404
|
+
/** False disables color writes while depth and stencil still run. */
|
|
405
|
+
colorWrite?: boolean;
|
|
406
|
+
/** MASK materials on a multisampled target cut by sample coverage instead of a per-pixel test; elsewhere no effect. */
|
|
407
|
+
alphaToCoverage?: boolean;
|
|
408
|
+
/**
|
|
409
|
+
* Where a BLEND material (without `blend` set here and without transmission) mixes with what is behind it on a
|
|
410
|
+
* display-encoded target (rgba8unorm, bgra8unorm): 'display' (default) blends the encoded values in the fixed-function
|
|
411
|
+
* blender, as most WebGL engines do; 'linear' mixes in linear light, so 50% red (linear 0.5) over black
|
|
412
|
+
* reads sRGB(0.25) = 137 instead of 94. Linear costs a pass break and a full-target copy before each such surface,
|
|
413
|
+
* and its instances do not blend over one another (one snapshot per draw). On a linear HDR target (rgba16float)
|
|
414
|
+
* both are the same. The transparency hook (OIT) does not read this option.
|
|
415
|
+
*/
|
|
416
|
+
blendSpace?: 'display' | 'linear';
|
|
417
|
+
}
|
|
418
|
+
export { validatePreparedGeometry };
|
|
419
|
+
interface DrawResource {
|
|
420
|
+
primitive: PBRPrimitive;
|
|
421
|
+
device: GPUDevice;
|
|
422
|
+
vertex: GPUBuffer;
|
|
423
|
+
uvs?: GPUBuffer;
|
|
424
|
+
index: GPUBuffer;
|
|
425
|
+
wireframe?: {
|
|
426
|
+
index: GPUBuffer;
|
|
427
|
+
count: number;
|
|
428
|
+
};
|
|
429
|
+
/** This draw's uniform block: a window of the device's uniform arena (`uniform-arena.ts`). */
|
|
430
|
+
uniform: UniformSlot;
|
|
431
|
+
volume?: GPUBuffer;
|
|
432
|
+
/** Streamed images this draw's material binds: replacing one's texture calls bindMaterial here again. */
|
|
433
|
+
streamed?: GLTFStreamedImage[];
|
|
434
|
+
/** Float32 copy of `material.volume`, reused so a transmission draw does not allocate. */
|
|
435
|
+
volumeData?: Float32Array;
|
|
436
|
+
/** Buffer that `volumeData` was last written to. A new buffer uploads again. */
|
|
437
|
+
volumeWritten?: GPUBuffer;
|
|
438
|
+
values: Float32Array;
|
|
439
|
+
groups: Map<GPURenderPipeline, DrawGroups>;
|
|
440
|
+
/**
|
|
441
|
+
* Group 0 for another view block or a copy of `uniform` (a draw repeated with other values in a frame), by uniform
|
|
442
|
+
* buffer, view block and pipeline; cleared with `groups`.
|
|
443
|
+
*/
|
|
444
|
+
copies?: Map<GPUBuffer, Map<GPUBufferBinding | undefined, Map<GPURenderPipeline, GPUBindGroup>>>;
|
|
445
|
+
sectionBuffer?: GPUBuffer;
|
|
446
|
+
views: GPUTextureView[];
|
|
447
|
+
samplers: GPUSampler[];
|
|
448
|
+
packedBase?: PackedBaseTextures;
|
|
449
|
+
baseSources?: BaseTextureSource[];
|
|
450
|
+
replacesTextures?: boolean;
|
|
451
|
+
extension?: MaterialExtensionResource;
|
|
452
|
+
coordinates?: CoordinateExtension;
|
|
453
|
+
/** Set on a static part while its material batch can replace it. */
|
|
454
|
+
mergedInto?: DrawResource;
|
|
455
|
+
/** Set on the one resource that draws a material batch. */
|
|
456
|
+
batch?: StaticBatch;
|
|
457
|
+
/** Set once `writeGeometry` rewrote this primitive: shadows then redraw it every frame instead of caching it. */
|
|
458
|
+
edited?: boolean;
|
|
459
|
+
/** Instanced batches this resource leads (draw-batch.ts), by derivation and view. */
|
|
460
|
+
batchStates?: Map<DrawDerivation, BatchState[]>;
|
|
461
|
+
/** Rows batches this resource leads (`BatchKind.rows`), by rows-variant derivation and view. */
|
|
462
|
+
rowStates?: Map<DrawDerivation, RowsState[]>;
|
|
463
|
+
/** The node matrix this draw's normal rows were last derived for, then those rows (see `PBRModel.nodeRows`). */
|
|
464
|
+
nodeCache?: Float32Array;
|
|
465
|
+
}
|
|
466
|
+
interface ShadowCasterRecord {
|
|
467
|
+
primitive: PBRPrimitive;
|
|
468
|
+
/** Linear RGB of the light a diffuse transmission material lets through, for `transmission` of `@margoengine/shadows`. */
|
|
469
|
+
transmits?: readonly number[];
|
|
470
|
+
node: Mesh;
|
|
471
|
+
vertex: GPUBuffer;
|
|
472
|
+
/** Byte offset and size of the primitive's vertices in `vertex` (a deformer's shared buffer). */
|
|
473
|
+
vertexOffset: number;
|
|
474
|
+
vertexSize: number;
|
|
475
|
+
index: GPUBuffer;
|
|
476
|
+
count: number;
|
|
477
|
+
/** Absent for triangles; line-list when the material draws triangle edges. */
|
|
478
|
+
topology?: 'line-list';
|
|
479
|
+
stride: number;
|
|
480
|
+
alphaTexture: GPUTextureView;
|
|
481
|
+
alphaSampler: GPUSampler;
|
|
482
|
+
alpha: number;
|
|
483
|
+
cutoff: number;
|
|
484
|
+
texCoord: 0 | 1;
|
|
485
|
+
alphaTransform?: Float32Array;
|
|
486
|
+
instances?: PBRInstances;
|
|
487
|
+
displacement?: PBRMaterial['displacement'];
|
|
488
|
+
opacity?: NonNullable<PBRMaterial['castMask']>['opacity'];
|
|
489
|
+
animation?: PBRMaterial['castAnimation'];
|
|
490
|
+
/** The caster edit that compares alpha with hashed noise (`PBRMaterial.castHashed`). Set only on a primitive that cuts. */
|
|
491
|
+
hashed?: (code: string) => string;
|
|
492
|
+
/** False keeps vertex alpha out of the cut-out, as the colour pass does. Set only on a primitive that cuts. */
|
|
493
|
+
vertexAlpha?: boolean;
|
|
494
|
+
clip?: GPUBufferBinding;
|
|
495
|
+
clipHardware?: boolean;
|
|
496
|
+
surfaceClip?: GPUBufferBinding;
|
|
497
|
+
dynamic: boolean;
|
|
498
|
+
}
|
|
499
|
+
/** A draw's groups 0 and 1 for one pipeline; `view` is the view block group 0 binds. */
|
|
500
|
+
type DrawGroups = GPUBindGroup[] & {
|
|
501
|
+
view?: GPUBufferBinding;
|
|
502
|
+
};
|
|
503
|
+
interface DrawScratch {
|
|
504
|
+
context?: Context;
|
|
505
|
+
/** Set by `PBRModel.compile`: derivations stop at the pipeline and compile it here, by key, off the frame. */
|
|
506
|
+
compiling?: Map<string, Promise<unknown>>;
|
|
507
|
+
/** A batch's member matrices, tints (folded batches) and uniform values (draw-batch.ts). */
|
|
508
|
+
matrices: ArrayLike<number>[];
|
|
509
|
+
tints: ArrayLike<number>[];
|
|
510
|
+
/** A rows batch's member uniform blocks and their derivations' versions (draw-batch.ts `BatchRows`). */
|
|
511
|
+
blocks: Float32Array[];
|
|
512
|
+
versions: number[];
|
|
513
|
+
/** The material records a folded batch's check (`PBRModel.folds`) has seen. */
|
|
514
|
+
checked: Set<PBRMaterial>;
|
|
515
|
+
batchValues: Float32Array;
|
|
516
|
+
/** This call's view block (view-uniform.ts). */
|
|
517
|
+
viewData: Float32Array;
|
|
518
|
+
/** What this call bound on its pass (a call without a run). */
|
|
519
|
+
bound: PassBindings;
|
|
520
|
+
/** This invocation's camera: a nested draw (probe face, second view) may change the context's camera meanwhile. */
|
|
521
|
+
projection: Float32Array;
|
|
522
|
+
view: Float32Array;
|
|
523
|
+
eye: Float32Array;
|
|
524
|
+
resources: DrawResource[];
|
|
525
|
+
effects: LightingEffect[];
|
|
526
|
+
entries: GPUBindGroupEntry[];
|
|
527
|
+
color: GPURenderPassColorAttachment;
|
|
528
|
+
depth: GPURenderPassDepthStencilAttachment;
|
|
529
|
+
descriptor: GPURenderPassDescriptor;
|
|
530
|
+
compare: (a: DrawResource, b: DrawResource) => number;
|
|
531
|
+
code: string;
|
|
532
|
+
ambient: boolean;
|
|
533
|
+
effectCount: number;
|
|
534
|
+
liveBatches: Map<StaticBatch, boolean>;
|
|
535
|
+
blendDistance: Map<DrawResource, number>;
|
|
536
|
+
}
|
|
537
|
+
/** A lighting or shading effect for `addLighting`: `pbr` hooks (lighting; preferred) or a `shader` text patch (materials, LOD baking). */
|
|
538
|
+
export interface LightingEffect {
|
|
539
|
+
readonly owner?: Engine;
|
|
540
|
+
pbr?(group: number): PBRLighting | undefined;
|
|
541
|
+
shader?(source: string, group: number): string;
|
|
542
|
+
bindings(): GPUBindGroupEntry[];
|
|
543
|
+
}
|
|
544
|
+
/** Per-material shader that may replace native textures and supply a texture-dependent transmission tint. */
|
|
545
|
+
export interface PBRMaterialShading extends LightingEffect {
|
|
546
|
+
readonly replacesTextures?: boolean;
|
|
547
|
+
readonly texturedTint?: boolean;
|
|
548
|
+
/**
|
|
549
|
+
* True when the shader reads data of its own by instance index: `@margoengine/culling` then draws these instances in
|
|
550
|
+
* their own rows instead of compacting or sorting them.
|
|
551
|
+
*/
|
|
552
|
+
readonly instanceRows?: boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Rewrites the shader once the model's lighting effects are composed in (`shader` runs before them): Lambert and Phong
|
|
555
|
+
* materials give clustered lights their own BRDF there. Return `code` itself to leave it unchanged.
|
|
556
|
+
*/
|
|
557
|
+
lit?(code: string): string;
|
|
558
|
+
/**
|
|
559
|
+
* A number that stays the same while `shader()` and `lit()` would return the same text for the same input code;
|
|
560
|
+
* undefined or NaN when that is not known. While it, the record's structure and the draw context stay the same, a
|
|
561
|
+
* draw keeps last frame's shader and pipeline instead of composing them again (with no lighting effects on the
|
|
562
|
+
* model); the uniform rows are read and `bindings()` runs every frame as before.
|
|
563
|
+
*/
|
|
564
|
+
readonly shaderRevision?: number;
|
|
565
|
+
/**
|
|
566
|
+
* A number that changes whenever anything the record, `shader()`, `lit()` or `bindings()` reads changes; undefined
|
|
567
|
+
* or NaN when that is not known. While it stays the same (and so does the draw context, with no lighting effects on
|
|
568
|
+
* the model), a draw reuses last frame's derivation whole: its uniform rows, shader, pipeline and group 2, without
|
|
569
|
+
* reading the record or calling `bindings()` again (draw-memo.ts).
|
|
570
|
+
*/
|
|
571
|
+
readonly version?: number;
|
|
572
|
+
}
|
|
573
|
+
/** UV offset, scale and rotation (radians), with KHR_texture_transform semantics: uv' = offset * rotation * scale * uv. */
|
|
574
|
+
/** One map's two uniform rows (offset*rotation*scale) as gltf/pbr's shader reads them; the first row's w holds the UV set. */
|
|
575
|
+
export declare function textureTransform(x?: TextureTransform, texCoord?: number): number[];
|
|
576
|
+
/**
|
|
577
|
+
* A node of a {@link PBRModel}: the engine's mesh, also the public `Mesh` that `engine.createMesh()` returns, so either
|
|
578
|
+
* parents the other without a cast (KB-GLTF-MESHTYPE1).
|
|
579
|
+
*/
|
|
580
|
+
export type ModelNode = Mesh & PublicMesh;
|
|
581
|
+
/**
|
|
582
|
+
* A glTF model attached to an engine as a plugin: its nodes, materials, variants, animation targets and picking data. Dispose it to release the GPU resources.
|
|
583
|
+
*/
|
|
584
|
+
export declare class PBRModel implements EnginePlugin {
|
|
585
|
+
readonly asset: GLTFAsset;
|
|
586
|
+
private readonly images;
|
|
587
|
+
private releaseNativeGlass?;
|
|
588
|
+
/** True while an acquisition asked for during a frame waits for the frame to end (`wantGlass`). */
|
|
589
|
+
private glassQueued;
|
|
590
|
+
/** Optional scene-wide opaque phase, used by caller-owned color captures. */
|
|
591
|
+
static beginOpaquePass(context: Context): void;
|
|
592
|
+
static cancelOpaquePass(context: Context): void;
|
|
593
|
+
static endOpaquePass(context: Context): void;
|
|
594
|
+
readonly name: string;
|
|
595
|
+
/**
|
|
596
|
+
* The model's root and its glTF nodes in file order. Typed as both of core's Mesh types (one object at run time), so
|
|
597
|
+
* `model.root.setParent(engine.createMesh())` and `engine.createMesh().setParent(model.root)` need no cast
|
|
598
|
+
* (KB-GLTF-MESHTYPE1).
|
|
599
|
+
*/
|
|
600
|
+
readonly root: ModelNode;
|
|
601
|
+
readonly nodes: ModelNode[];
|
|
602
|
+
readonly primitives: PBRPrimitive[];
|
|
603
|
+
/**
|
|
604
|
+
* The nodes that draw the model's triangle `primitives`, each once, in primitive order: the meshes `@margoengine/gltf`'s
|
|
605
|
+
* `loadGLTF` returns as `meshes`, so code that loops over a loaded model's drawn meshes reads the same from either
|
|
606
|
+
* loader. A new array on each read; every one is also in `nodes`.
|
|
607
|
+
*/
|
|
608
|
+
get meshes(): readonly Mesh[];
|
|
609
|
+
/** Installed by optional deformation packages; does not advance animation time. */
|
|
610
|
+
prepareDeformation?: (context: PBRDeformationContext) => void;
|
|
611
|
+
/** Optional isolated deformation kernels for another rendering device. */
|
|
612
|
+
createDeformationRenderer?: (model: PBRModel, device: GPUDevice) => PBRDeformationRenderer;
|
|
613
|
+
readonly lights: GLTFLight[];
|
|
614
|
+
/** The file's `MSFT_lod` objects; `LOD.fromModel` from `@margoengine/lod` drives them. Empty without the extension. */
|
|
615
|
+
readonly lods: GLTFLOD[];
|
|
616
|
+
readonly cameras: GLTFCamera[];
|
|
617
|
+
/**
|
|
618
|
+
* glTF POINTS, LINES, LINE_LOOP and LINE_STRIP primitives (`topology` set), drawn in the beauty pass only: no shadows,
|
|
619
|
+
* SSAO, SSR or transparency hook. Kept out of `primitives`, which picking, BVH, outlines, walk collisions and exporters
|
|
620
|
+
* read as triangles. Empty for `@margoengine/gltf/progressive` loads, which leave points and lines out.
|
|
621
|
+
*/
|
|
622
|
+
readonly pointsAndLines: PBRPrimitive[];
|
|
623
|
+
/** KHR_materials_variants names in file order (empty without the extension); `selectVariant` takes a name or its index. */
|
|
624
|
+
readonly variants: readonly string[];
|
|
625
|
+
/** The variant `selectVariant` last chose, by its index in `variants`; undefined for each primitive's own material. */
|
|
626
|
+
selectedVariant: number | undefined;
|
|
627
|
+
private readonly materials;
|
|
628
|
+
private readonly defaults;
|
|
629
|
+
disposed: boolean;
|
|
630
|
+
private readonly created;
|
|
631
|
+
private resources;
|
|
632
|
+
/** Each node's primitives in model order (its mesh source's list). */
|
|
633
|
+
private readonly byNode;
|
|
634
|
+
private textures;
|
|
635
|
+
private readonly gpuCache;
|
|
636
|
+
private readonly inverse;
|
|
637
|
+
private readonly workspace;
|
|
638
|
+
/** Material batches baked once. Device restore uploads them again and keeps the same nodes. */
|
|
639
|
+
private staticBatches?;
|
|
640
|
+
/** Primitives drawn from another primitive's buffer pair (see `shareBuffers`), each mapped to the pair's owner. */
|
|
641
|
+
private readonly bufferSources;
|
|
642
|
+
private relative?;
|
|
643
|
+
private engine;
|
|
644
|
+
private readonly cleanupCallbacks;
|
|
645
|
+
/** @internal The mesh primitives `decoders.splats` reads in place of drawing them. */
|
|
646
|
+
readonly splatPrimitives: {
|
|
647
|
+
primitive: GLTFPrimitive;
|
|
648
|
+
nodeIndex: number;
|
|
649
|
+
}[];
|
|
650
|
+
/** The file's Gaussian clouds (KHR_gaussian_splatting), attached to the engine. `model.dispose()` disposes them. */
|
|
651
|
+
splats: readonly GLTFSplatCloud[];
|
|
652
|
+
private readonly lighting;
|
|
653
|
+
/**
|
|
654
|
+
* Lit by the image-based light of its scene's `Sky` (`@margoengine/sky`, the scene's `'sky'` plugin): diffuse light
|
|
655
|
+
* and reflections blurred by each material's roughness, as core meshes get it, without `sky.add(model)`. It joins on
|
|
656
|
+
* the next draw once the sky has an ambient (`lighting.ambient` or `environment`) and leaves when the sky does. An
|
|
657
|
+
* ambient given to the model itself (`environment.add(model)`, light probes, another sky) takes its place, as on core
|
|
658
|
+
* meshes. Set false to keep the built-in ambient. Default true.
|
|
659
|
+
*/
|
|
660
|
+
sceneSky: boolean;
|
|
661
|
+
/** The scene sky this model joined by itself (`sceneSky`), and its remover. */
|
|
662
|
+
private joinedSky?;
|
|
663
|
+
/** `lighting` in order, a new array on every change (draw-memo.ts compares derivation contexts by it). */
|
|
664
|
+
private lightingList;
|
|
665
|
+
private readonly replays;
|
|
666
|
+
private gpuRevision;
|
|
667
|
+
/** Pose answers for one shadow-primitive write. Draw calls keep their own map on the scratch. */
|
|
668
|
+
private shadowBatchLive?;
|
|
669
|
+
private transparency?;
|
|
670
|
+
private capture?;
|
|
671
|
+
private transmission?;
|
|
672
|
+
constructor(instance: EngineKernel, asset: GLTFAsset, images?: readonly GLTFImage[], prepared?: readonly (readonly PreparedPrimitive[])[],
|
|
673
|
+
/**
|
|
674
|
+
* The scene the model's meshes are created in (`scene.use(model)` then adds it as a plugin there). Default: the
|
|
675
|
+
* engine's default scene, as `engine.use(model)` expects (GAP-REACT-SCENEMODELS).
|
|
676
|
+
*/
|
|
677
|
+
scene?: CoreScene);
|
|
678
|
+
/**
|
|
679
|
+
* @internal Progressive loading: puts `made`, the next part of `after`'s split primitive, right after `after` in model
|
|
680
|
+
* and draw order with its draw resource, so the finished model lists its parts as a plain load does.
|
|
681
|
+
*/
|
|
682
|
+
private insertPart;
|
|
683
|
+
/** Current node transforms applied to bind-pose CPU positions. Does not perform GPU readback. */
|
|
684
|
+
get bounds(): Float32Array;
|
|
685
|
+
/**
|
|
686
|
+
* @internal Hands the file's Gaussian splats to `decoders.splats` and keeps the clouds in `splats`. The loaders call it.
|
|
687
|
+
* A node hidden by KHR_node_visibility, or under a hidden node, gives no cloud.
|
|
688
|
+
*/
|
|
689
|
+
attachSplats(signal?: AbortSignal): Promise<void>;
|
|
690
|
+
/** Borrowed GPU buffers, preserving one record per primitive and current deformation. */
|
|
691
|
+
get raw(): {
|
|
692
|
+
primitive: PBRPrimitive;
|
|
693
|
+
node: Mesh;
|
|
694
|
+
vertex: GPUBuffer;
|
|
695
|
+
vertexOffset: number;
|
|
696
|
+
index: GPUBuffer;
|
|
697
|
+
count: number;
|
|
698
|
+
stride: 80;
|
|
699
|
+
alphaTexture: GPUTextureView;
|
|
700
|
+
alphaSampler: GPUSampler;
|
|
701
|
+
alpha: number;
|
|
702
|
+
cutoff: number;
|
|
703
|
+
side: MaterialSide;
|
|
704
|
+
doubleSided: boolean;
|
|
705
|
+
texCoord: 0 | 1;
|
|
706
|
+
alphaTransform?: Float32Array<ArrayBufferLike> | undefined;
|
|
707
|
+
opacity?: {
|
|
708
|
+
readonly buffer: GPUBuffer;
|
|
709
|
+
readonly view: GPUTextureView;
|
|
710
|
+
readonly sampler: GPUSampler;
|
|
711
|
+
} | undefined;
|
|
712
|
+
animation?: {
|
|
713
|
+
readonly buffer: GPUBuffer;
|
|
714
|
+
readonly view: GPUTextureView;
|
|
715
|
+
readonly sampler: GPUSampler;
|
|
716
|
+
} | undefined;
|
|
717
|
+
vertexAlpha?: boolean | undefined;
|
|
718
|
+
displacement?: import("./shared/caster.js").CasterDisplacement | undefined;
|
|
719
|
+
clip?: GPUBufferBinding | undefined;
|
|
720
|
+
instances?: PBRInstances | undefined;
|
|
721
|
+
}[];
|
|
722
|
+
private bufferUpload;
|
|
723
|
+
/** Lets go of one of this model's vertex or index buffers and forgets every cache key that names it. */
|
|
724
|
+
private dropBuffer;
|
|
725
|
+
setup(engine: Engine, device?: GPUDevice | null): void;
|
|
726
|
+
/**
|
|
727
|
+
* Points `target` at `source`'s vertex and index GPU buffers and frees the pair `target` used, so identical shapes
|
|
728
|
+
* draw from one pair. Both must be triangle primitives of this model with
|
|
729
|
+
* equal vertices and indices, neither skinned nor morphed; their CPU arrays, materials and nodes stay separate, and
|
|
730
|
+
* the sharing survives a device restore. Returns false, changing nothing, when they do not qualify or the model is
|
|
731
|
+
* still streaming.
|
|
732
|
+
*/
|
|
733
|
+
shareBuffers(target: PBRPrimitive, source: PBRPrimitive): boolean;
|
|
734
|
+
/**
|
|
735
|
+
* Replaces the geometry of every triangle primitive in place: `geometry[i]` becomes `primitives[i]`'s vertices and
|
|
736
|
+
* indices (`PreparedGeometry` layout), keeping nodes, materials, instances and plugin registrations. A GPU buffer is
|
|
737
|
+
* rewritten when the new data fits it and reallocated at twice its size (or the data size) otherwise, so repeated
|
|
738
|
+
* edits stop allocating. With `range` (vertex units) only those vertices differ from the current ones: the vertex
|
|
739
|
+
* count and the index contents stay the same (the arrays may be new objects, which refreshes identity-keyed caches
|
|
740
|
+
* such as BVHs) and only the range's bytes upload. CPU readers (bounds, BVH, worldTriangles, exporters) see the new
|
|
741
|
+
* arrays at once. Static material batches are retired, and edited primitives cast shadows as dynamic from then on.
|
|
742
|
+
* Renderers from `createRenderer` keep the geometry they were created with.
|
|
743
|
+
*/
|
|
744
|
+
writeGeometry(geometry: readonly PreparedGeometry[], range?: {
|
|
745
|
+
readonly start: number;
|
|
746
|
+
readonly count: number;
|
|
747
|
+
}): void;
|
|
748
|
+
/** Drops every static material batch for good: its parts draw individually from their own, now editable, buffers. */
|
|
749
|
+
private retireBatches;
|
|
750
|
+
/**
|
|
751
|
+
* Takes `source`'s baked static batches instead of baking, for a copy of it (one asset, the same node transforms)
|
|
752
|
+
* that is not set up yet. Baking reads world matrices, and publishing those is a tick of every mesh of the engine,
|
|
753
|
+
* so a crowd of copies cost a tick each. Returns false, changing nothing, when `source`'s batches do not fit: this
|
|
754
|
+
* model then bakes for itself at setup. Draws are right either way, because a part away from its baked pose draws
|
|
755
|
+
* alone.
|
|
756
|
+
*/
|
|
757
|
+
adoptStaticBatches(source: PBRModel): boolean;
|
|
758
|
+
/** Bakes static same-material triangles once the asset's geometry and instances are final. */
|
|
759
|
+
private commitStaticBatches;
|
|
760
|
+
private batchNode;
|
|
761
|
+
/** Bakes static same-material triangles once, after world matrices exist, and uploads that mesh on each device. */
|
|
762
|
+
private installBatches;
|
|
763
|
+
/**
|
|
764
|
+
* True while every baked part still has the captured root-relative pose, material and visibility, and is in
|
|
765
|
+
* `context`'s view. `anyVisibility` leaves visibility out, for a batch that is only being copied.
|
|
766
|
+
*/
|
|
767
|
+
private pose;
|
|
768
|
+
/** Per-node casters stay individual so `shadows.add(node)` still finds that node's triangles. */
|
|
769
|
+
private nodeShadowPrimitives;
|
|
770
|
+
private bindMaterial;
|
|
771
|
+
registerPasses(graph: FrameGraph): void;
|
|
772
|
+
/**
|
|
773
|
+
* Whether a primitive draws as native glass or as a linear-light blend (both read the capture's snapshot); a linear
|
|
774
|
+
* layer a transparency hook takes reads it in the hook's composite (KB3148d).
|
|
775
|
+
*/
|
|
776
|
+
private glassActive;
|
|
777
|
+
/**
|
|
778
|
+
* KB3148b: a draw found a linear-blend material and no capture (the option was set after the model joined the frame
|
|
779
|
+
* graph, or the model draws for the materials queue). Plugins cannot join a frame graph while it runs, so the capture
|
|
780
|
+
* is acquired once this frame ends, in the scene that drew; the surface blends in linear light from the next frame.
|
|
781
|
+
*/
|
|
782
|
+
private wantGlass;
|
|
783
|
+
/**
|
|
784
|
+
* Models whose passes follow one another in the frame graph draw as one run (one render pass, shared batches), in
|
|
785
|
+
* graph order, at the first one's pass; the others' passes then draw nothing. A model whose neighbours are other
|
|
786
|
+
* passes draws on its own, as before. (A render pass per model stored and reloaded the multisampled colour and depth
|
|
787
|
+
* each time: 100 models, 100 passes and 1.2 ms of GPU time.)
|
|
788
|
+
*/
|
|
789
|
+
private drawSegment;
|
|
790
|
+
/**
|
|
791
|
+
* This model's decoded images for another model of the same asset (`new PBRModel(engine, asset, images)`), which then
|
|
792
|
+
* holds them too: each closes with its last holder, and the two share the GPU textures made from them. Pass them to
|
|
793
|
+
* `closeImages` if no model ends up holding them.
|
|
794
|
+
*/
|
|
795
|
+
shareImages(): GLTFImage[];
|
|
796
|
+
/** Binds the draws of `image` again after its texture was replaced; a stream calls this. */
|
|
797
|
+
rebindStreamed(image: GLTFStreamedImage): void;
|
|
798
|
+
/** Lets go of one of this model's material textures and forgets its cache key. */
|
|
799
|
+
private dropTexture;
|
|
800
|
+
/**
|
|
801
|
+
* Compiles the render pipelines of this model's beauty draws without blocking, so its first frame finds them ready.
|
|
802
|
+
* Call it once the scene's lights and effects are set: a change that alters a shader afterwards compiles on the draw
|
|
803
|
+
* as before, so calling this is never needed for correctness. Off WebGPU it does nothing. Pipelines of batched
|
|
804
|
+
* textureless meshes compile on their first draw. Rejects with the GPU's error if a pipeline fails.
|
|
805
|
+
*/
|
|
806
|
+
compile(): Promise<void>;
|
|
807
|
+
/** Borrow a decoded image; optional lookup returns undefined for an unavailable alternative texture source. */
|
|
808
|
+
image(index: number): Exclude<GLTFImage, undefined>;
|
|
809
|
+
image(index: number, optional: true): GLTFImage;
|
|
810
|
+
/** Upload a retained image; the caller owns and destroys the returned texture. */
|
|
811
|
+
uploadImage(index: number, device: GPUDevice, srgb?: boolean): GPUTexture;
|
|
812
|
+
/**
|
|
813
|
+
* KB-GLTF-SCENESKY1: joins or leaves the scene's sky (`sceneSky`) before a draw. A glTF or FBX model in a sky scene
|
|
814
|
+
* had only the flat built-in ambient unless the caller wrote `sky.add(model)`, while core meshes beside it took the
|
|
815
|
+
* sky's light, so outfits, props and vehicles read warm and flat beside the ground.
|
|
816
|
+
*/
|
|
817
|
+
private joinSceneSky;
|
|
818
|
+
addLighting(effect: LightingEffect): () => void;
|
|
819
|
+
/** Whether this material draws in the transparency hook's pass. */
|
|
820
|
+
private takesTransparent;
|
|
821
|
+
/**
|
|
822
|
+
* Draws the BLEND primitives into `hook`'s pass, as `draw(c, 'transparent', ...)` does, in place of the hook set with
|
|
823
|
+
* `setTransparency` for this call alone: a second pass over the same surfaces.
|
|
824
|
+
*/
|
|
825
|
+
drawTransparent(c: Context, hook: PBRTransparency): void;
|
|
826
|
+
/** Hands this model's BLEND primitives to a transparency hook (README "Transparency hook"); returns a remover that restores sorted blending. */
|
|
827
|
+
setTransparency(hook: PBRTransparency): () => void;
|
|
828
|
+
/** Lets a capture hook (README "Capture hook"; SSR's `ssr.add(model)`) draw this model's materials with `draw(c, 'capture', ...)`; returns a remover. */
|
|
829
|
+
setCapture(hook: PBRCapture): () => void;
|
|
830
|
+
/** Hands this model's transmission primitives to a transmission hook (README "Transmission hook"); returns a remover that restores the tinted blend. */
|
|
831
|
+
setTransmission(hook: PBRTransmission): () => void;
|
|
832
|
+
/**
|
|
833
|
+
* Shows a KHR_materials_variants variant (a name from `variants` or its index): every primitive with a mapping for it draws
|
|
834
|
+
* that material, the others their own (the glTF fallback); `undefined` restores every primitive's own material. A variant's
|
|
835
|
+
* textures upload on first use and stay cached. With `@margoengine/gltf/progressive`, call it after `complete`.
|
|
836
|
+
*/
|
|
837
|
+
selectVariant(variant?: string | number): void;
|
|
838
|
+
/**
|
|
839
|
+
* Changes authored material indices on this model's primitives and refreshes their texture bindings. All references
|
|
840
|
+
* and UV requirements are validated before any primitive changes. `undefined` restores the primitive's initial
|
|
841
|
+
* material. Geometry, skinning and morph buffers are retained. Call after a progressive load completes.
|
|
842
|
+
* @throws MargoError when disposed; RangeError for a foreign primitive, repeated primitive or invalid material index.
|
|
843
|
+
*/
|
|
844
|
+
setPrimitiveMaterials(changes: readonly {
|
|
845
|
+
primitive: PBRPrimitive;
|
|
846
|
+
material: number | undefined;
|
|
847
|
+
}[]): void;
|
|
848
|
+
/**
|
|
849
|
+
* Every mesh this model made and will dispose: `root`, `nodes` and the meshes of its baked batches. A mesh you
|
|
850
|
+
* parented to a node is yours and is not here. `@margoengine/save/engine` reads it to tell the two apart.
|
|
851
|
+
*/
|
|
852
|
+
get ownedMeshes(): readonly Mesh[];
|
|
853
|
+
get shadowPrimitives(): ShadowCasterRecord[];
|
|
854
|
+
/**
|
|
855
|
+
* Transmissive and blended primitives for coloured shadows (`Shadows` `colored`), with the light each lets through:
|
|
856
|
+
* the transmission tint, or the base colour weighed by alpha.
|
|
857
|
+
*/
|
|
858
|
+
get tintPrimitives(): (ShadowCasterRecord & {
|
|
859
|
+
tint: readonly number[];
|
|
860
|
+
})[];
|
|
861
|
+
/** Borrowed current draw buffers; picking never substitutes bind-pose geometry. */
|
|
862
|
+
get pickingPrimitives(): {
|
|
863
|
+
primitive: PBRPrimitive;
|
|
864
|
+
node: Mesh;
|
|
865
|
+
vertex: GPUBuffer;
|
|
866
|
+
vertexOffset: number;
|
|
867
|
+
index: GPUBuffer;
|
|
868
|
+
count: number;
|
|
869
|
+
stride: 80;
|
|
870
|
+
alphaTexture: GPUTextureView;
|
|
871
|
+
alphaSampler: GPUSampler;
|
|
872
|
+
alpha: number;
|
|
873
|
+
cutoff: number;
|
|
874
|
+
side: MaterialSide;
|
|
875
|
+
doubleSided: boolean;
|
|
876
|
+
texCoord: 0 | 1;
|
|
877
|
+
alphaTransform?: Float32Array<ArrayBufferLike> | undefined;
|
|
878
|
+
opacity?: {
|
|
879
|
+
readonly buffer: GPUBuffer;
|
|
880
|
+
readonly view: GPUTextureView;
|
|
881
|
+
readonly sampler: GPUSampler;
|
|
882
|
+
} | undefined;
|
|
883
|
+
animation?: {
|
|
884
|
+
readonly buffer: GPUBuffer;
|
|
885
|
+
readonly view: GPUTextureView;
|
|
886
|
+
readonly sampler: GPUSampler;
|
|
887
|
+
} | undefined;
|
|
888
|
+
vertexAlpha?: boolean | undefined;
|
|
889
|
+
displacement?: import("./shared/caster.js").CasterDisplacement | undefined;
|
|
890
|
+
clip?: GPUBufferBinding | undefined;
|
|
891
|
+
instances?: PBRInstances | undefined;
|
|
892
|
+
}[];
|
|
893
|
+
/** Explicit CPU-query snapshot. Only deformed geometry incurs GPU readback. */
|
|
894
|
+
readPickingGeometry(): Promise<readonly PBRPickingGeometry[]>;
|
|
895
|
+
private writeShadowPrimitives;
|
|
896
|
+
/** `transparent` draws only the BLEND primitives a transparency hook took over (`setTransparency`), into its pass; `transmission`
|
|
897
|
+
* those a transmission hook took over (`setTransmission`); `capture` the opaque and MASK ones into the capture hook's pass
|
|
898
|
+
* (`setCapture`); for these `color`/`depth` are unused.
|
|
899
|
+
*
|
|
900
|
+
* `carry` is a `PBRDrawRun`: draws that pass the same run share one render pass instead of each beginning one
|
|
901
|
+
* (a pass stores and reloads the multisampled colour and depth), blended draws included; a blended primitive drawn
|
|
902
|
+
* without a run ends the pass around itself. Call
|
|
903
|
+
* `carry.end()` after the last draw, before anything else records on `c.encoder`. */
|
|
904
|
+
draw(c: Context, mode: 'beauty' | 'gbuffer' | 'ambient' | 'transparent' | 'transmission' | 'capture' | 'occlusion', color: GPUTextureView, depth: GPUTextureView, phase?: 'all' | 'opaque' | 'blend', external?: ExternalPass, carry?: PBRDrawRun): void;
|
|
905
|
+
/**
|
|
906
|
+
* The derivation of `r`'s draw under `frame`, derived now (draw-memo.ts) into the entry of the same context from an
|
|
907
|
+
* earlier call or frame, if any, so its GPU objects are reused; it fills `r.values` completely.
|
|
908
|
+
*/
|
|
909
|
+
private derivation;
|
|
910
|
+
/**
|
|
911
|
+
* @internal `draw()`'s short path in a run: when this model is one opaque primitive whose draw joins an instanced
|
|
912
|
+
* batch of `run` under the run's current view block and an existing derivation, adds it (or skips it when hidden)
|
|
913
|
+
* and returns true; returns false for everything else, which `draw()` handles.
|
|
914
|
+
*/
|
|
915
|
+
joinRun(c: Context, run: PBRDrawRun, phase: 'all' | 'opaque' | 'blend', quick: QuickRun, viewAt: GPUBufferBinding): boolean;
|
|
916
|
+
/**
|
|
917
|
+
* @internal Draws `batch` (draw-batch.ts) into `run`'s pass: one mesh as its own draw, exactly as without a run;
|
|
918
|
+
* several as one instanced draw of the instanced variant of their derivation, with a batch uniform (identity model
|
|
919
|
+
* rows) and their world matrices as instance rows.
|
|
920
|
+
*/
|
|
921
|
+
drawBatch(batch: PendingBatch, run: PBRDrawRun): void;
|
|
922
|
+
/**
|
|
923
|
+
* @internal Draws rows batch `batch` (draw-batch.ts `BatchKind.rows`): meshes of several material records of one draw
|
|
924
|
+
* group as instanced draws of the leading member's rows variant, each instance reading its own uniform block (its
|
|
925
|
+
* material's rows, with its world matrix as its instance row), one draw per `rowsPerBinding` instances. When any
|
|
926
|
+
* member's rows variant would not draw as the leader's does (`rowsFit`), every member draws on its own, in order.
|
|
927
|
+
*/
|
|
928
|
+
private drawRows;
|
|
929
|
+
/**
|
|
930
|
+
* @internal True when every member of rows batch `batch` draws as the leader's rows variant `derived` would draw it:
|
|
931
|
+
* its own material's rows variant has the same pipeline, group 2 resources and uniform size, and reads the model rows
|
|
932
|
+
* only in the instanced vertex stage. Kept on each member's derivation while both versions stay the same.
|
|
933
|
+
*/
|
|
934
|
+
private rowsFit;
|
|
935
|
+
/**
|
|
936
|
+
* @internal True when every member of folded `batch` draws as the owner's instanced variant `derived` would draw
|
|
937
|
+
* it: its own material's instanced variant has the same pipeline, group 2 entries and shader (`tintable`).
|
|
938
|
+
*/
|
|
939
|
+
private folds;
|
|
940
|
+
/** @internal Draws batch member `r` as its own draw (its material's shader reads the model rows; see `drawBatch`). */
|
|
941
|
+
drawOwn(r: DrawResource, batch: PendingBatch, run: PBRDrawRun, scratch: DrawScratch): void;
|
|
942
|
+
/**
|
|
943
|
+
* Derives what draws of `r`'s material record share under `frame` (draw-memo.ts): the shader, pipeline, lighting
|
|
944
|
+
* group and uniform rows. It fills `r.values` completely (node rows included) and returns the derivation, reusing
|
|
945
|
+
* `d`'s GPU objects when their inputs compare equal.
|
|
946
|
+
*/
|
|
947
|
+
private derive;
|
|
948
|
+
/**
|
|
949
|
+
* Writes node matrix `a` (rows 16-31) and its normal matrix, the inverse transpose (rows 32-47), into `v`. The rows
|
|
950
|
+
* are kept on `r` and reused while the matrix stays the same: most meshes do not move between frames. A matrix with
|
|
951
|
+
* no inverse (a zero scale, glTF 2.0 section 3.5.3) gets the cofactor matrix, the inverse transpose times the
|
|
952
|
+
* determinant, which exists for every matrix (Turkowski, Graphics Gems 1990); the vertex stage turns a normal it maps
|
|
953
|
+
* to zero into +Y.
|
|
954
|
+
*/
|
|
955
|
+
private nodeRows;
|
|
956
|
+
/**
|
|
957
|
+
* Group 2 of a draw of `pipeline`: the entries of the material's shading hook, then (`lit`) the model's lighting
|
|
958
|
+
* effects, then (`through`) the transparency hook, gathered now. `d`'s group is kept when they are the same.
|
|
959
|
+
*/
|
|
960
|
+
private effectGroup;
|
|
961
|
+
/** Isolated GPU resources for stereo eyes or another caller-owned WebGPU device. */
|
|
962
|
+
createRenderer(device: GPUDevice): PBRDeviceRenderer;
|
|
963
|
+
/** World-space visible point and spot lights for `clustered.setLights()`. Hidden ancestors hide their lights. Directional lights are left to engine lighting; an unset range ends where intensity/d² reaches 1/256. */
|
|
964
|
+
clusteredLights(): GLTFClusteredLight[];
|
|
965
|
+
/** Every node whose glTF `extras` is an object, in node order, with its current world matrix: markers and spawn points placed in Blender. Mesh and material extras stay in `asset.doc.meshes[i].extras` and `asset.doc.materials[i].extras`. */
|
|
966
|
+
extras(): GLTFNodeExtras[];
|
|
967
|
+
onDispose(callback: () => void): () => void;
|
|
968
|
+
private releaseGPU;
|
|
969
|
+
onDeviceRestored(engine: Engine): void;
|
|
970
|
+
dispose(): void;
|
|
971
|
+
[Symbol.dispose]: () => void;
|
|
972
|
+
/** @deprecated Use dispose(); kept as an alias until 1.0. */
|
|
973
|
+
destroy(): void;
|
|
974
|
+
}
|
|
975
|
+
/** Synchronous parse of in-memory JSON/GLB with decoded `images`; `decoders` takes only the synchronous `instancing` reader, `meshopt` decoder and `materials` shaders; `maxNodes` and `maxPartVertices` as for loadGLTF. */
|
|
976
|
+
export declare function parseGLTF(instance: EngineKernel, input: string | object | ArrayBuffer | ArrayBufferView, buffers?: Array<ArrayBuffer | ArrayBufferView>, images?: readonly GLTFImage[], decoders?: Pick<GLTFDecoderHooks, 'instancing' | 'materials' | 'meshopt'>, { maxNodes, maxPartVertices }?: Pick<AssetOptions, 'maxNodes' | 'maxPartVertices'>): PBRModel;
|
|
977
|
+
/** A static scene whose geometry is already packed (as @margoengine/blender's .margo); `maxNodes` and `maxPartVertices` as for loadGLTF. */
|
|
978
|
+
export declare function parsePreparedPBR(instance: EngineKernel, doc: GLTFAsset['doc'], geometry: readonly (readonly PreparedPrimitive[])[], images?: readonly GLTFImage[], { maxNodes, maxPartVertices }?: Pick<AssetOptions, 'maxNodes' | 'maxPartVertices'>): PBRModel;
|
|
979
|
+
/**
|
|
980
|
+
* Fetches a glTF or GLB over HTTP(S), decodes it and attaches it to the engine as a PBRModel. Aborts with `options.signal`. @throws TypeError or RangeError when the file is malformed or over a limit.
|
|
981
|
+
*/
|
|
982
|
+
export declare function loadGLTF(instance: EngineKernel, url: string | URL, options?: GLTFLoadOptions): Promise<PBRModel>;
|
|
983
|
+
/**
|
|
984
|
+
* Async in-memory JSON/GLB parsing, including Draco, meshopt and KTX2. With no third argument (or an options object),
|
|
985
|
+
* decodes embedded images and resolves external URIs against the `baseURL` option (a file in memory has no location: without it an external URI is refused). The positional buffers/images overload uses
|
|
986
|
+
* supplied ordinary bitmaps; an undefined buffers argument keeps that overload when images or later options are passed.
|
|
987
|
+
*/
|
|
988
|
+
export declare function parseGLTFAsync(instance: EngineKernel, input: string | object | ArrayBuffer | ArrayBufferView, buffersOrOptions?: Array<ArrayBuffer | ArrayBufferView> | (AssetOptions & CompressionOptions), images?: readonly GLTFImage[], options?: GLTFLoadOptions): Promise<PBRModel>;
|
|
989
|
+
/**
|
|
990
|
+
* Applies a model's KHR_lights_punctual lights in one call. The first visible directional light becomes the engine's light
|
|
991
|
+
* (`engine.lighting`: direction toward the light, its colour, and its lux x `exposure` as the strength; core's default
|
|
992
|
+
* strength is 3 and core has one directional light, so further ones are ignored). Point and spot lights go to `clustered`
|
|
993
|
+
* (@margoengine/clustered, candela x `exposure`), which then lights the model; without it they are ignored. Lights are
|
|
994
|
+
* placed where their nodes are now: after moving the model, call `clustered.setLights(model.clusteredLights())` (or this
|
|
995
|
+
* again for the sun). Reapply after changing light visibility. If this model owns the last imported sun and none of its
|
|
996
|
+
* directional lights remain visible, restores the lighting from before imported suns were applied, unless the caller
|
|
997
|
+
* changed it afterward. The most recently applied model owns the sun; no other model is selected automatically.
|
|
998
|
+
* Call once per clustered instance; returns the remover from `clustered.add` (a no-op without one).
|
|
999
|
+
*/
|
|
1000
|
+
export declare function applyGLTFLights(model: PBRModel, { clustered, exposure }?: {
|
|
1001
|
+
clustered?: GLTFLightReceiver;
|
|
1002
|
+
exposure?: number;
|
|
1003
|
+
}): () => void;
|
|
1004
|
+
/**
|
|
1005
|
+
* Views through one of the model's glTF cameras (`model.cameras[camera]`, default the first) with the engine camera:
|
|
1006
|
+
* position, view direction and up from the camera node's world matrix now. Perspective: `yfov` and `znear`, `zfar` when
|
|
1007
|
+
* set (else the camera keeps its `far`), with the canvas aspect. Orthographic: `ymag`, `znear` and `zfar` through
|
|
1008
|
+
* `camera.project`, the width following the canvas aspect; a later perspective camera removes that projection. The target
|
|
1009
|
+
* is 1 unit ahead, so orbit controls turn the view around that point (call their `saveState()` afterwards).
|
|
1010
|
+
*/
|
|
1011
|
+
export declare function viewGLTFCamera(model: PBRModel, camera?: number | GLTFCamera): void;
|