@zephyr3d/editor 0.3.0 → 0.3.1

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 (48) hide show
  1. package/README.md +143 -0
  2. package/dist/assets/{index-BaUzUcND.js → index-IISR7uQv.js} +1 -1
  3. package/dist/assistant/zephyr-types-index.json +1 -1
  4. package/dist/index.html +2 -2
  5. package/dist/modules/zephyr3d_backend-webgpu.js.map +1 -1
  6. package/dist/modules/zephyr3d_imgui.js +3 -3
  7. package/dist/modules/zephyr3d_imgui.js.map +1 -1
  8. package/dist/modules/zephyr3d_scene.js +1439 -1439
  9. package/dist/modules/zephyr3d_scene.js.map +1 -1
  10. package/dist/vendor/zephyr3d/backend-webgpu/dist/bindgroup_webgpu.js.map +1 -1
  11. package/dist/vendor/zephyr3d/backend-webgpu/dist/buffer_webgpu.js.map +1 -1
  12. package/dist/vendor/zephyr3d/backend-webgpu/dist/commandqueue.js.map +1 -1
  13. package/dist/vendor/zephyr3d/backend-webgpu/dist/uploadringbuffer.js.map +1 -1
  14. package/dist/vendor/zephyr3d/imgui/dist/imgui_impl.js.map +1 -1
  15. package/dist/vendor/zephyr3d/imgui/dist/renderer.js +3 -3
  16. package/dist/vendor/zephyr3d/imgui/dist/renderer.js.map +1 -1
  17. package/dist/vendor/zephyr3d/scene/dist/animation/animationset.js +135 -135
  18. package/dist/vendor/zephyr3d/scene/dist/animation/animationset.js.map +1 -1
  19. package/dist/vendor/zephyr3d/scene/dist/animation/joint_dynamics/controller.js +146 -146
  20. package/dist/vendor/zephyr3d/scene/dist/animation/joint_dynamics/controller.js.map +1 -1
  21. package/dist/vendor/zephyr3d/scene/dist/animation/spring/spring_system.js +75 -75
  22. package/dist/vendor/zephyr3d/scene/dist/animation/spring/spring_system.js.map +1 -1
  23. package/dist/vendor/zephyr3d/scene/dist/camera/camera.js +184 -184
  24. package/dist/vendor/zephyr3d/scene/dist/camera/camera.js.map +1 -1
  25. package/dist/vendor/zephyr3d/scene/dist/material/material.js +288 -288
  26. package/dist/vendor/zephyr3d/scene/dist/material/material.js.map +1 -1
  27. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/history_resource_manager.js +93 -93
  28. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  29. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/history_resources.js +3 -3
  30. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/history_resources.js.map +1 -1
  31. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/types.js +22 -22
  32. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/types.js.map +1 -1
  33. package/dist/vendor/zephyr3d/scene/dist/utility/blueprint/material/ir.js +489 -489
  34. package/dist/vendor/zephyr3d/scene/dist/utility/blueprint/material/ir.js.map +1 -1
  35. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js.map +1 -1
  36. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js.map +1 -1
  37. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/common.js.map +1 -1
  38. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/light.js.map +1 -1
  39. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/material.js.map +1 -1
  40. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/mesh.js.map +1 -1
  41. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js.map +1 -1
  42. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/particle.js.map +1 -1
  43. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/primitive.js.map +1 -1
  44. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/scene.js.map +1 -1
  45. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/terrain.js.map +1 -1
  46. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/types.js +4 -4
  47. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/types.js.map +1 -1
  48. package/package.json +1 -1
@@ -4,99 +4,99 @@ import { RenderBundleWrapper } from '../render/renderbundle_wrapper.js';
4
4
  import { Disposable } from '@zephyr3d/base';
5
5
  import { getEngine } from '../app/api.js';
6
6
 
7
- /**
8
- * Base class for all materials.
9
- *
10
- * Responsibilities:
11
- * - Defines a multi-pass rendering interface (`numPasses`, `apply`, `bind`, `draw`, `drawPrimitive`).
12
- * - Builds and caches GPU shader programs per pass and per-render-context hash.
13
- * - Manages a per-material bind group (typically at index 2) for uniforms and resources.
14
- * - Updates render states per pass (`updateRenderStates`) and uploads uniforms (`_applyUniforms`).
15
- * - Tracks "option" changes that affect shader variant hashing and render bundles.
16
- *
17
- * Caching and hashing:
18
- * - `createHash(pass)` produces a stable hash representing shader variant options for a pass.
19
- * Override `_createHash()` in subclasses to encode feature toggles (defines, keywords, macros).
20
- * - The global hash used to key `MaterialState` also includes `ctx.materialFlags` and
21
- * `ctx.renderPassHash`, allowing context-sensitive variants (e.g., MSAA, MRT layout).
22
- * - GPU programs are additionally memoized in a global static `_programCache` across materials
23
- * by `constructor.name` + hash, to avoid recompilation of identical variants.
24
- *
25
- * Bind groups and uniforms:
26
- * - If a program declares a bind group layout at index 2 (i.e., `bindGroupLayouts.length > 2`),
27
- * `apply()` will allocate the group and keep it in the state. Subclasses should fill it in
28
- * `_applyUniforms()`.
29
- * - `applyUniforms()` only calls `_applyUniforms()` when `needUpdate` is true, based on
30
- * `_optionTag` changes (see `optionChanged()`).
31
- *
32
- * Lifecycle:
33
- * - Constructed materials register a persistent ID into a global registry for serialization.
34
- * - `apply(ctx)` prepares all passes: creates/gets state, programs, bind groups, render states,
35
- * and uploads uniforms as needed.
36
- * - `bind(device, pass)` binds the program, bind group (index 2), and render states.
37
- * - `draw(primitive, ctx, numInstances)` runs all passes, calling `bind()` and `drawPrimitive()`.
38
- * - `onDispose()` releases bind groups and registry entries.
39
- *
40
- * Extending:
41
- * - Override `_createProgram(pb, ctx, pass)` to build a shader.
42
- * - Override `_applyUniforms(bindGroup, ctx, pass)` to upload uniforms and resources.
43
- * - Override `updateRenderStates(pass, renderStates, ctx)` to set depth, blend, cull, etc.
44
- * - Override `_createHash()` to encode options that affect program compilation.
45
- * - Override `supportLighting`, `supportInstancing`, `isTransparentPass`, `getQueueType`, etc.
46
- *
47
- * Thread-safety:
48
- * - Intended for main-thread use in a renderer driving WebGPU/WebGL-like devices.
49
- *
50
- * @public
7
+ /**
8
+ * Base class for all materials.
9
+ *
10
+ * Responsibilities:
11
+ * - Defines a multi-pass rendering interface (`numPasses`, `apply`, `bind`, `draw`, `drawPrimitive`).
12
+ * - Builds and caches GPU shader programs per pass and per-render-context hash.
13
+ * - Manages a per-material bind group (typically at index 2) for uniforms and resources.
14
+ * - Updates render states per pass (`updateRenderStates`) and uploads uniforms (`_applyUniforms`).
15
+ * - Tracks "option" changes that affect shader variant hashing and render bundles.
16
+ *
17
+ * Caching and hashing:
18
+ * - `createHash(pass)` produces a stable hash representing shader variant options for a pass.
19
+ * Override `_createHash()` in subclasses to encode feature toggles (defines, keywords, macros).
20
+ * - The global hash used to key `MaterialState` also includes `ctx.materialFlags` and
21
+ * `ctx.renderPassHash`, allowing context-sensitive variants (e.g., MSAA, MRT layout).
22
+ * - GPU programs are additionally memoized in a global static `_programCache` across materials
23
+ * by `constructor.name` + hash, to avoid recompilation of identical variants.
24
+ *
25
+ * Bind groups and uniforms:
26
+ * - If a program declares a bind group layout at index 2 (i.e., `bindGroupLayouts.length > 2`),
27
+ * `apply()` will allocate the group and keep it in the state. Subclasses should fill it in
28
+ * `_applyUniforms()`.
29
+ * - `applyUniforms()` only calls `_applyUniforms()` when `needUpdate` is true, based on
30
+ * `_optionTag` changes (see `optionChanged()`).
31
+ *
32
+ * Lifecycle:
33
+ * - Constructed materials register a persistent ID into a global registry for serialization.
34
+ * - `apply(ctx)` prepares all passes: creates/gets state, programs, bind groups, render states,
35
+ * and uploads uniforms as needed.
36
+ * - `bind(device, pass)` binds the program, bind group (index 2), and render states.
37
+ * - `draw(primitive, ctx, numInstances)` runs all passes, calling `bind()` and `drawPrimitive()`.
38
+ * - `onDispose()` releases bind groups and registry entries.
39
+ *
40
+ * Extending:
41
+ * - Override `_createProgram(pb, ctx, pass)` to build a shader.
42
+ * - Override `_applyUniforms(bindGroup, ctx, pass)` to upload uniforms and resources.
43
+ * - Override `updateRenderStates(pass, renderStates, ctx)` to set depth, blend, cull, etc.
44
+ * - Override `_createHash()` to encode options that affect program compilation.
45
+ * - Override `supportLighting`, `supportInstancing`, `isTransparentPass`, `getQueueType`, etc.
46
+ *
47
+ * Thread-safety:
48
+ * - Intended for main-thread use in a renderer driving WebGPU/WebGL-like devices.
49
+ *
50
+ * @public
51
51
  */ class Material extends Disposable {
52
- /**
53
- * Monotonic instance ID counter.
54
- * @internal
52
+ /**
53
+ * Monotonic instance ID counter.
54
+ * @internal
55
55
  */ static _nextId = 0;
56
- /**
57
- * Global program cache keyed by global hash
56
+ /**
57
+ * Global program cache keyed by global hash
58
58
  */ static _programCache = {};
59
- /**
60
- * Per-material state cache keyed by global hash (material + context + pass).
61
- * @internal
59
+ /**
60
+ * Per-material state cache keyed by global hash (material + context + pass).
61
+ * @internal
62
62
  */ _states;
63
- /**
64
- * Number of rendering passes.
65
- * Subclasses can increase this to implement multi-pass rendering.
66
- * @internal
63
+ /**
64
+ * Number of rendering passes.
65
+ * Subclasses can increase this to implement multi-pass rendering.
66
+ * @internal
67
67
  */ _numPasses;
68
- /**
69
- * Per-pass hash cached results. Length scales with `numPasses`.
70
- * @internal
68
+ /**
69
+ * Per-pass hash cached results. Length scales with `numPasses`.
70
+ * @internal
71
71
  */ _hash;
72
- /**
73
- * Incremented each time options change (via `optionChanged`), used to decide whether
74
- * uniforms need update on next `apply()`.
75
- * @internal
72
+ /**
73
+ * Incremented each time options change (via `optionChanged`), used to decide whether
74
+ * uniforms need update on next `apply()`.
75
+ * @internal
76
76
  */ _optionTag;
77
- /**
78
- * Unique runtime instance ID.
79
- * @internal
77
+ /**
78
+ * Unique runtime instance ID.
79
+ * @internal
80
80
  */ _id;
81
- /**
82
- * Latest computed global hash per pass, set during `apply()`, read in `bind()`.
83
- * @internal
81
+ /**
82
+ * Latest computed global hash per pass, set during `apply()`, read in `bind()`.
83
+ * @internal
84
84
  */ _currentHash;
85
- /**
86
- * Incremented when material states affecting render bundles change (e.g., bind group id changes
87
- * or `optionChanged(true)`), used to trigger re-recording of render bundles.
88
- * @internal
85
+ /**
86
+ * Incremented when material states affecting render bundles change (e.g., bind group id changes
87
+ * or `optionChanged(true)`), used to trigger re-recording of render bundles.
88
+ * @internal
89
89
  */ _changeTag;
90
- /**
91
- * Unique program id counter for naming compiled programs.
92
- * @internal
90
+ /**
91
+ * Unique program id counter for naming compiled programs.
92
+ * @internal
93
93
  */ _nextProgramId = 0;
94
- /**
95
- * Create a new material instance.
96
- *
97
- * - Initializes one pass by default.
98
- * - Prepares per-pass hash storage and change tracking.
99
- * - Registers a persistent ID in the global registry.
94
+ /**
95
+ * Create a new material instance.
96
+ *
97
+ * - Initializes one pass by default.
98
+ * - Prepares per-pass hash storage and change tracking.
99
+ * - Registers a persistent ID in the global registry.
100
100
  */ constructor(){
101
101
  super();
102
102
  this._id = ++Material._nextId;
@@ -110,46 +110,46 @@ import { getEngine } from '../app/api.js';
110
110
  this._changeTag = 0;
111
111
  this._currentHash = [];
112
112
  }
113
- /**
114
- * Create a shallow clone of this material.
115
- *
116
- * Note: The base implementation returns a base `Material`. Subclasses should
117
- * override to return their own type and copy custom fields.
113
+ /**
114
+ * Create a shallow clone of this material.
115
+ *
116
+ * Note: The base implementation returns a base `Material`. Subclasses should
117
+ * override to return their own type and copy custom fields.
118
118
  */ clone() {
119
119
  const other = new Material();
120
120
  other.copyFrom(this);
121
121
  return other;
122
122
  }
123
- /**
124
- * Copy basic properties from another material.
125
- *
126
- * Disposes existing bind groups/states, copies `numPasses`. Subclasses should
127
- * extend this to copy their own fields and call `optionChanged(true)` if
128
- * shader-affecting options differ.
129
- *
130
- * @param other - Source material.
123
+ /**
124
+ * Copy basic properties from another material.
125
+ *
126
+ * Disposes existing bind groups/states, copies `numPasses`. Subclasses should
127
+ * extend this to copy their own fields and call `optionChanged(true)` if
128
+ * shader-affecting options differ.
129
+ *
130
+ * @param other - Source material.
131
131
  */ copyFrom(other) {
132
132
  this.clearCache();
133
133
  this._numPasses = other._numPasses;
134
134
  getEngine().resourceManager.setAssetId(this, getEngine().resourceManager.getAssetId(other.coreMaterial));
135
135
  }
136
- /**
137
- * Incremented when the material’s GPU-relevant state changes and render bundles
138
- * may need to be rebuilt.
136
+ /**
137
+ * Incremented when the material’s GPU-relevant state changes and render bundles
138
+ * may need to be rebuilt.
139
139
  */ get changeTag() {
140
140
  return this._changeTag;
141
141
  }
142
- /**
143
- * Runtime-unique numeric identifier for the material instance.
142
+ /**
143
+ * Runtime-unique numeric identifier for the material instance.
144
144
  */ get instanceId() {
145
145
  return this._id;
146
146
  }
147
- /**
148
- * Number of rendering passes this material uses.
149
- *
150
- * Increasing this will expand the per-pass hash cache; make sure to implement
151
- * `createHash(pass)`, `_createProgram(pb, ctx, pass)`, and `updateRenderStates(pass, ...)`
152
- * accordingly for each pass.
147
+ /**
148
+ * Number of rendering passes this material uses.
149
+ *
150
+ * Increasing this will expand the per-pass hash cache; make sure to implement
151
+ * `createHash(pass)`, `_createProgram(pb, ctx, pass)`, and `updateRenderStates(pass, ...)`
152
+ * accordingly for each pass.
153
153
  */ get numPasses() {
154
154
  return this._numPasses;
155
155
  }
@@ -159,86 +159,86 @@ import { getEngine } from '../app/api.js';
159
159
  }
160
160
  this._numPasses = val;
161
161
  }
162
- /**
163
- * Get or compute the per-pass shader hash used for program caching.
164
- *
165
- * Calls `createHash(pass)` lazily and caches the result.
166
- * @internal
162
+ /**
163
+ * Get or compute the per-pass shader hash used for program caching.
164
+ *
165
+ * Calls `createHash(pass)` lazily and caches the result.
166
+ * @internal
167
167
  */ getHash(pass) {
168
168
  if (this._hash[pass] === null) {
169
169
  this._hash[pass] = this.createHash(pass);
170
170
  }
171
171
  return this._hash[pass];
172
172
  }
173
- /**
174
- * Return the queue type to which this material belongs.
175
- *
176
- * Override this in transparent or special materials (e.g., post-process).
173
+ /**
174
+ * Return the queue type to which this material belongs.
175
+ *
176
+ * Override this in transparent or special materials (e.g., post-process).
177
177
  */ getQueueType() {
178
178
  return QUEUE_OPAQUE;
179
179
  }
180
- /**
181
- * Whether the given pass is transparent.
182
- *
183
- * Used to place draw calls into appropriate render queues and set blending states.
180
+ /**
181
+ * Whether the given pass is transparent.
182
+ *
183
+ * Used to place draw calls into appropriate render queues and set blending states.
184
184
  */ isTransparentPass(_pass) {
185
185
  return false;
186
186
  }
187
- /**
188
- * Whether this material's shading is affected by scene lights.
189
- *
190
- * Override and return `false` for unlit materials.
187
+ /**
188
+ * Whether this material's shading is affected by scene lights.
189
+ *
190
+ * Override and return `false` for unlit materials.
191
191
  */ supportLighting() {
192
192
  return true;
193
193
  }
194
- /**
195
- * Whether this material supports hardware instancing.
196
- *
197
- * Override and return `false` if per-instance data is not supported in the shader.
194
+ /**
195
+ * Whether this material supports hardware instancing.
196
+ *
197
+ * Override and return `false` if per-instance data is not supported in the shader.
198
198
  */ supportInstancing() {
199
199
  return true;
200
200
  }
201
201
  /** Returns true if this is a instance of material */ isBatchable() {
202
202
  return false;
203
203
  }
204
- /**
205
- * Whether this material requires the scene color texture (e.g., for refraction).
204
+ /**
205
+ * Whether this material requires the scene color texture (e.g., for refraction).
206
206
  */ needSceneColor() {
207
207
  return false;
208
208
  }
209
- /**
210
- * Whether this material requires the linear scene depth texture (e.g., for depth-aware effects).
209
+ /**
210
+ * Whether this material requires the linear scene depth texture (e.g., for depth-aware effects).
211
211
  */ needSceneDepth() {
212
212
  return false;
213
213
  }
214
- /**
215
- * Create a material instance (instance-uniform-driven variant).
216
- *
217
- * Base returns `null`. Subclasses that support instancing can return a lightweight instance.
214
+ /**
215
+ * Create a material instance (instance-uniform-driven variant).
216
+ *
217
+ * Base returns `null`. Subclasses that support instancing can return a lightweight instance.
218
218
  */ createInstance() {
219
219
  throw new Error('Abstract function call');
220
220
  }
221
- /**
222
- * Returns the core material that owns GPU state.
223
- *
224
- * Instances may delegate to a shared core to reuse compiled programs and caches.
225
- * @public
221
+ /**
222
+ * Returns the core material that owns GPU state.
223
+ *
224
+ * Instances may delegate to a shared core to reuse compiled programs and caches.
225
+ * @public
226
226
  */ get coreMaterial() {
227
227
  return this;
228
228
  }
229
- /**
230
- * Prepare the material for drawing across all passes for the given draw context.
231
- *
232
- * Steps per pass:
233
- * - Compute global hash (material variant + context).
234
- * - Retrieve or build the GPU program, cache in `_programCache`.
235
- * - Create per-material bind group (index 2) if the program exposes it.
236
- * - Update uniforms if `_optionTag` indicates changes since last apply.
237
- * - Update and cache render states for the pass.
238
- * - Detect bind group GPU ID changes to bump `changeTag` and notify `RenderBundleWrapper`.
239
- *
240
- * @param ctx - Draw context (device, flags, pass hash, instance data, etc.).
241
- * @returns `true` if successful; `false` if any pass lacks a valid program.
229
+ /**
230
+ * Prepare the material for drawing across all passes for the given draw context.
231
+ *
232
+ * Steps per pass:
233
+ * - Compute global hash (material variant + context).
234
+ * - Retrieve or build the GPU program, cache in `_programCache`.
235
+ * - Create per-material bind group (index 2) if the program exposes it.
236
+ * - Update uniforms if `_optionTag` indicates changes since last apply.
237
+ * - Update and cache render states for the pass.
238
+ * - Detect bind group GPU ID changes to bump `changeTag` and notify `RenderBundleWrapper`.
239
+ *
240
+ * @param ctx - Draw context (device, flags, pass hash, instance data, etc.).
241
+ * @returns `true` if successful; `false` if any pass lacks a valid program.
242
242
  */ apply(ctx) {
243
243
  for(let pass = 0; pass < this._numPasses; pass++){
244
244
  const hash = this.calcGlobalHash(ctx, pass);
@@ -280,15 +280,15 @@ import { getEngine } from '../app/api.js';
280
280
  }
281
281
  return true;
282
282
  }
283
- /**
284
- * Bind the program, bind group, and render states for the specified pass.
285
- *
286
- * Must be called after `apply(ctx)` for the same pass.
287
- *
288
- * @param device - Rendering device.
289
- * @param pass - Pass index to bind.
290
- * @returns `true` on success; `false` if state or program missing.
291
- * @internal
283
+ /**
284
+ * Bind the program, bind group, and render states for the specified pass.
285
+ *
286
+ * Must be called after `apply(ctx)` for the same pass.
287
+ *
288
+ * @param device - Rendering device.
289
+ * @param pass - Pass index to bind.
290
+ * @returns `true` on success; `false` if state or program missing.
291
+ * @internal
292
292
  */ bind(device, pass) {
293
293
  const hash = this._currentHash[pass];
294
294
  const state = this._states[hash];
@@ -306,56 +306,56 @@ import { getEngine } from '../app/api.js';
306
306
  device.setRenderStates(state.renderStateSet);
307
307
  return true;
308
308
  }
309
- /**
310
- * Compute the global hash for the given pass and draw context.
311
- *
312
- * Includes:
313
- * - Per-pass material hash from `getHash(pass)`.
314
- * - `ctx.materialFlags` for context-dependent toggles.
315
- * - `ctx.renderPassHash` for framebuffer/attachment layout variants.
316
- * @internal
309
+ /**
310
+ * Compute the global hash for the given pass and draw context.
311
+ *
312
+ * Includes:
313
+ * - Per-pass material hash from `getHash(pass)`.
314
+ * - `ctx.materialFlags` for context-dependent toggles.
315
+ * - `ctx.renderPassHash` for framebuffer/attachment layout variants.
316
+ * @internal
317
317
  */ calcGlobalHash(ctx, pass) {
318
318
  return `${this.getHash(pass)}:${ctx.materialFlags}:${ctx.renderPassHash}`;
319
319
  }
320
- /**
321
- * Draw a primitive for all passes using this material.
322
- *
323
- * Calls `bind()` then `drawPrimitive()` per pass. If `numInstances` is zero,
324
- * and `ctx.instanceData` exists, uses `ctx.instanceData.numInstances`.
325
- *
326
- * @param primitive - Geometry to draw.
327
- * @param ctx - Draw context.
328
- * @param numInstances - Instance count; 0 means auto-detect from context.
329
- * @internal
320
+ /**
321
+ * Draw a primitive for all passes using this material.
322
+ *
323
+ * Calls `bind()` then `drawPrimitive()` per pass. If `numInstances` is zero,
324
+ * and `ctx.instanceData` exists, uses `ctx.instanceData.numInstances`.
325
+ *
326
+ * @param primitive - Geometry to draw.
327
+ * @param ctx - Draw context.
328
+ * @param numInstances - Instance count; 0 means auto-detect from context.
329
+ * @internal
330
330
  */ draw(primitive, ctx, numInstances = 0) {
331
331
  for(let pass = 0; pass < this._numPasses; pass++){
332
332
  this.bind(ctx.device, pass);
333
333
  this.drawPrimitive(pass, primitive, ctx, numInstances);
334
334
  }
335
335
  }
336
- /**
337
- * Conditionally update uniforms/resources into the material bind group.
338
- *
339
- * Delegates to `_applyUniforms()` when `needUpdate` is true (based on `_optionTag` check).
340
- *
341
- * @param bindGroup - Material bind group at index 2 (may be `null` if program has no layout).
342
- * @param ctx - Draw context.
343
- * @param needUpdate - Whether uniforms need to be refreshed.
344
- * @param pass - Pass index.
336
+ /**
337
+ * Conditionally update uniforms/resources into the material bind group.
338
+ *
339
+ * Delegates to `_applyUniforms()` when `needUpdate` is true (based on `_optionTag` check).
340
+ *
341
+ * @param bindGroup - Material bind group at index 2 (may be `null` if program has no layout).
342
+ * @param ctx - Draw context.
343
+ * @param needUpdate - Whether uniforms need to be refreshed.
344
+ * @param pass - Pass index.
345
345
  */ applyUniforms(bindGroup, ctx, needUpdate, pass) {
346
346
  if (needUpdate) {
347
347
  this._applyUniforms(bindGroup, ctx, pass);
348
348
  }
349
349
  }
350
- /**
351
- * Notify the material that some option changed.
352
- *
353
- * - Always increments `_optionTag`. This will trigger uniforms update on next `apply()`.
354
- * - If `changeHash` is true, clears per-pass hashes so programs/states will be rebuilt,
355
- * increments `_changeTag`, and notifies `RenderBundleWrapper` to regenerate recorded bundles.
356
- *
357
- * @param changeHash - Set true if the change affects shader compilation or render states.
358
- * @internal
350
+ /**
351
+ * Notify the material that some option changed.
352
+ *
353
+ * - Always increments `_optionTag`. This will trigger uniforms update on next `apply()`.
354
+ * - If `changeHash` is true, clears per-pass hashes so programs/states will be rebuilt,
355
+ * increments `_changeTag`, and notifies `RenderBundleWrapper` to regenerate recorded bundles.
356
+ *
357
+ * @param changeHash - Set true if the change affects shader compilation or render states.
358
+ * @internal
359
359
  */ optionChanged(changeHash) {
360
360
  this._optionTag++;
361
361
  if (changeHash) {
@@ -374,39 +374,39 @@ import { getEngine } from '../app/api.js';
374
374
  }
375
375
  this._states = {};
376
376
  }
377
- /**
378
- * Convert a pass index to a hash seed string.
379
- *
380
- * Subclasses may override to encode per-pass role (e.g., "depth", "forward", "shadow").
381
- *
382
- * @param pass - Pass number.
383
- * @returns String used when building full hash.
377
+ /**
378
+ * Convert a pass index to a hash seed string.
379
+ *
380
+ * Subclasses may override to encode per-pass role (e.g., "depth", "forward", "shadow").
381
+ *
382
+ * @param pass - Pass number.
383
+ * @returns String used when building full hash.
384
384
  */ passToHash(pass) {
385
385
  return String(pass);
386
386
  }
387
- /**
388
- * Build the material hash for a pass (excluding context-dependent parts).
389
- *
390
- * Default formula: `${constructor.name}|${pass}|${_createHash()}`
391
- *
392
- * @param pass - Pass number.
393
- * @returns Hash string used in program caching.
394
- * @internal
387
+ /**
388
+ * Build the material hash for a pass (excluding context-dependent parts).
389
+ *
390
+ * Default formula: `${constructor.name}|${pass}|${_createHash()}`
391
+ *
392
+ * @param pass - Pass number.
393
+ * @returns Hash string used in program caching.
394
+ * @internal
395
395
  */ createHash(pass) {
396
396
  return `${this.constructor.name}|${pass}|${this._createHash()}`;
397
397
  }
398
- /**
399
- * Issue the actual draw call for a pass.
400
- *
401
- * Override for custom per-pass draw behavior if necessary. The default implementation:
402
- * - Draws instanced if `numInstances > 0`.
403
- * - Else uses `ctx.instanceData.numInstances` if available.
404
- * - Else issues a non-instanced draw.
405
- *
406
- * @param pass - Pass number.
407
- * @param primitive - Primitive to draw.
408
- * @param ctx - Draw context.
409
- * @param numInstances - Explicit instance count (0 = auto).
398
+ /**
399
+ * Issue the actual draw call for a pass.
400
+ *
401
+ * Override for custom per-pass draw behavior if necessary. The default implementation:
402
+ * - Draws instanced if `numInstances > 0`.
403
+ * - Else uses `ctx.instanceData.numInstances` if available.
404
+ * - Else issues a non-instanced draw.
405
+ *
406
+ * @param pass - Pass number.
407
+ * @param primitive - Primitive to draw.
408
+ * @param ctx - Draw context.
409
+ * @param numInstances - Explicit instance count (0 = auto).
410
410
  */ drawPrimitive(pass, primitive, ctx, numInstances) {
411
411
  if (numInstances > 0) {
412
412
  primitive.drawInstanced(numInstances);
@@ -416,88 +416,88 @@ import { getEngine } from '../app/api.js';
416
416
  primitive.draw();
417
417
  }
418
418
  }
419
- /**
420
- * Dispose the material and release GPU-side resource references.
421
- *
422
- * - Unregisters from the global registry.
423
- * - Disposes the per-material bind groups kept in `_states`.
419
+ /**
420
+ * Dispose the material and release GPU-side resource references.
421
+ *
422
+ * - Unregisters from the global registry.
423
+ * - Disposes the per-material bind groups kept in `_states`.
424
424
  */ onDispose() {
425
425
  super.onDispose();
426
426
  this.clearCache();
427
427
  }
428
- /**
429
- * Build the GPU program for a pass.
430
- *
431
- * Default creates a `ProgramBuilder` and calls `_createProgram(pb, ctx, pass)`.
432
- * Subclasses should override `_createProgram` instead of this method unless
433
- * they need to replace builder instantiation.
434
- *
435
- * @param ctx - Draw context.
436
- * @param pass - Pass number.
437
- * @returns The compiled `GPUProgram`, or `null` on failure.
438
- * @internal
428
+ /**
429
+ * Build the GPU program for a pass.
430
+ *
431
+ * Default creates a `ProgramBuilder` and calls `_createProgram(pb, ctx, pass)`.
432
+ * Subclasses should override `_createProgram` instead of this method unless
433
+ * they need to replace builder instantiation.
434
+ *
435
+ * @param ctx - Draw context.
436
+ * @param pass - Pass number.
437
+ * @returns The compiled `GPUProgram`, or `null` on failure.
438
+ * @internal
439
439
  */ createProgram(ctx, pass) {
440
440
  const pb = new ProgramBuilder(ctx.device);
441
441
  return this._createProgram(pb, ctx, pass);
442
442
  }
443
- /**
444
- * Create and compile the shader program for this material/pass.
445
- *
446
- * Implement in subclasses:
447
- * - Define shader stages, entry points, macros/defines, and resource layouts.
448
- * - Return a compiled `GPUProgram`.
449
- *
450
- * @param pb - Program builder.
451
- * @param ctx - Draw context.
452
- * @param _pass - Pass number.
453
- * @returns The created program, or `null` on failure.
443
+ /**
444
+ * Create and compile the shader program for this material/pass.
445
+ *
446
+ * Implement in subclasses:
447
+ * - Define shader stages, entry points, macros/defines, and resource layouts.
448
+ * - Return a compiled `GPUProgram`.
449
+ *
450
+ * @param pb - Program builder.
451
+ * @param ctx - Draw context.
452
+ * @param _pass - Pass number.
453
+ * @returns The created program, or `null` on failure.
454
454
  */ _createProgram(_pb, _ctx, _pass) {
455
455
  throw new Error('Abstract function call');
456
456
  }
457
- /**
458
- * Upload uniforms and bind resources to the per-material bind group (index 2).
459
- *
460
- * Implement in subclasses to:
461
- * - Write uniform buffers/textures/samplers to the `bindGroup`.
462
- * - Respect the current `pass` and `ctx`.
463
- *
464
- * @param _bindGroup - The bind group to populate.
465
- * @param _ctx - Draw context.
466
- * @param _pass - Pass number.
457
+ /**
458
+ * Upload uniforms and bind resources to the per-material bind group (index 2).
459
+ *
460
+ * Implement in subclasses to:
461
+ * - Write uniform buffers/textures/samplers to the `bindGroup`.
462
+ * - Respect the current `pass` and `ctx`.
463
+ *
464
+ * @param _bindGroup - The bind group to populate.
465
+ * @param _ctx - Draw context.
466
+ * @param _pass - Pass number.
467
467
  */ _applyUniforms(_bindGroup, _ctx, _pass) {}
468
- /**
469
- * Update render states (depth/stencil, blending, rasterization) for the pass.
470
- *
471
- * Implement in subclasses based on transparency, double-sidedness, depth writes/tests,
472
- * color mask, stencil ops, etc., and any context flags in `ctx`.
473
- *
474
- * @param _pass - Current pass index.
475
- * @param _renderStates - Render state set to mutate.
476
- * @param _ctx - Draw context.
468
+ /**
469
+ * Update render states (depth/stencil, blending, rasterization) for the pass.
470
+ *
471
+ * Implement in subclasses based on transparency, double-sidedness, depth writes/tests,
472
+ * color mask, stencil ops, etc., and any context flags in `ctx`.
473
+ *
474
+ * @param _pass - Current pass index.
475
+ * @param _renderStates - Render state set to mutate.
476
+ * @param _ctx - Draw context.
477
477
  */ updateRenderStates(_pass, _renderStates, _ctx) {}
478
- /**
479
- * Compute the material-specific portion of the shader hash for the current options.
480
- *
481
- * Subclasses should override to include macro/define sets that influence program compilation.
482
- * Example return: `"USE_NORMALMAP=1;ALPHA_MODE=BLEND;RECEIVE_SHADOWS=1"`.
483
- *
484
- * @returns Hash fragment string (no context/pass info).
478
+ /**
479
+ * Compute the material-specific portion of the shader hash for the current options.
480
+ *
481
+ * Subclasses should override to include macro/define sets that influence program compilation.
482
+ * Example return: `"USE_NORMALMAP=1;ALPHA_MODE=BLEND;RECEIVE_SHADOWS=1"`.
483
+ *
484
+ * @returns Hash fragment string (no context/pass info).
485
485
  */ _createHash() {
486
486
  return '';
487
487
  }
488
- /**
489
- * Whether this is a lightweight instance of a core material.
490
- *
491
- * Instances typically share GPU programs with a core and only override instance uniforms.
492
- * @internal
488
+ /**
489
+ * Whether this is a lightweight instance of a core material.
490
+ *
491
+ * Instances typically share GPU programs with a core and only override instance uniforms.
492
+ * @internal
493
493
  */ get $isInstance() {
494
494
  return false;
495
495
  }
496
- /**
497
- * Instance-uniform buffer for material instances, if supported.
498
- *
499
- * Returned as a typed Float32 view over a backing ArrayBuffer.
500
- * @internal
496
+ /**
497
+ * Instance-uniform buffer for material instances, if supported.
498
+ *
499
+ * Returned as a typed Float32 view over a backing ArrayBuffer.
500
+ * @internal
501
501
  */ get $instanceUniforms() {
502
502
  throw new Error('Abstract function call');
503
503
  }