@galacean/engine-core 2.0.0-alpha.52 → 2.0.0-alpha.53

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/dist/main.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var engineMath = require('@galacean/engine-math');
6
+ var engineDesign = require('@galacean/engine-design');
6
7
 
7
8
  /**
8
9
  * The platform (including operating system and hardware) is running on.
@@ -4400,6 +4401,26 @@ var RenderStateElementKey = /*#__PURE__*/ function(RenderStateElementKey) {
4400
4401
  return ShaderLanguage;
4401
4402
  }({});
4402
4403
 
4404
+ /**
4405
+ * Directive types for shader preprocessor instructions.
4406
+ */ var ShaderPreprocessorDirective = /*#__PURE__*/ function(ShaderPreprocessorDirective) {
4407
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["Text"] = 0] = "Text";
4408
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["IfDef"] = 1] = "IfDef";
4409
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["IfNdef"] = 2] = "IfNdef";
4410
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["IfCmp"] = 3] = "IfCmp";
4411
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["IfExpr"] = 4] = "IfExpr";
4412
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["Else"] = 5] = "Else";
4413
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["Endif"] = 6] = "Endif";
4414
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["Define"] = 7] = "Define";
4415
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["DefineVal"] = 8] = "DefineVal";
4416
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["DefineFunc"] = 9] = "DefineFunc";
4417
+ ShaderPreprocessorDirective[ShaderPreprocessorDirective["Undef"] = 10] = "Undef";
4418
+ /** Activates a declaration: [ownerId, groupId, sourceScope]. */ ShaderPreprocessorDirective[ShaderPreprocessorDirective["Declaration"] = 11] = "Declaration";
4419
+ /** Text retained when any listed declaration is selected and reachable: [text, ...ownerIds]. */ ShaderPreprocessorDirective[ShaderPreprocessorDirective["OwnedText"] = 12] = "OwnedText";
4420
+ /** Declaration dependency: [fromOwnerId, toOwnerId]; owner zero denotes a stage root. */ ShaderPreprocessorDirective[ShaderPreprocessorDirective["Reference"] = 13] = "Reference";
4421
+ return ShaderPreprocessorDirective;
4422
+ }({});
4423
+
4403
4424
  /**
4404
4425
  * Shader Property type.
4405
4426
  */ var ShaderPropertyType = /*#__PURE__*/ function(ShaderPropertyType) {
@@ -6901,17 +6922,33 @@ ShaderBlockProperty._nameMap = Object.create(null);
6901
6922
  * Register a chunk source so `#include` resolves it.
6902
6923
  * @param includeName - The path key referenced in `#include "..."`.
6903
6924
  * @param includeSource - GLSL chunk source text.
6925
+ * @throws Error when the key is empty, malformed, or already registered after normalization.
6904
6926
  */ ShaderFactory.registerInclude = function registerInclude(includeName, includeSource) {
6905
- if (ShaderFactory.includeMap[includeName]) {
6906
- throw 'The "' + includeName + '" shader include already exist';
6907
- }
6908
- ShaderFactory.includeMap[includeName] = includeSource;
6927
+ var key = engineDesign.normalizeShaderIncludeKey(includeName);
6928
+ if (Object.prototype.hasOwnProperty.call(ShaderFactory.includeMap, key)) {
6929
+ throw new Error('The shader include "' + key + '" is already registered.');
6930
+ }
6931
+ Object.defineProperty(ShaderFactory.includeMap, key, {
6932
+ value: includeSource,
6933
+ writable: true,
6934
+ enumerable: true,
6935
+ configurable: true
6936
+ });
6937
+ };
6938
+ /**
6939
+ * Remove a registered shader chunk.
6940
+ * @param includeName - The path key passed to `registerInclude`.
6941
+ * @throws Error when the key is empty or malformed.
6942
+ */ ShaderFactory.unregisterInclude = function unregisterInclude(includeName) {
6943
+ delete ShaderFactory.includeMap[engineDesign.normalizeShaderIncludeKey(includeName)];
6909
6944
  };
6910
6945
  /**
6911
6946
  * Remove a registered shader chunk.
6912
6947
  * @param includeName - The path key passed to `registerInclude`.
6948
+ * @deprecated Use `unregisterInclude`.
6949
+ * @throws Error when the key is empty or malformed.
6913
6950
  */ ShaderFactory.unRegisterInclude = function unRegisterInclude(includeName) {
6914
- delete ShaderFactory.includeMap[includeName];
6951
+ ShaderFactory.unregisterInclude(includeName);
6915
6952
  };
6916
6953
  /**
6917
6954
  * Convert lower GLSL version to GLSL 300 es.
@@ -7100,7 +7137,7 @@ ShaderBlockProperty._nameMap = Object.create(null);
7100
7137
  ShaderFactory.RENDERER_INSTANCE_BLOCK_NAME = "RendererInstanceData";
7101
7138
  var _obj;
7102
7139
  ShaderFactory.uniformBlockBindingMap = (_obj = {}, _obj[ShaderBlockProperty.getByName(ShaderFactory.RENDERER_INSTANCE_BLOCK_NAME)._uniqueId] = ConstantBufferBindingPoint.RendererInstance, _obj);
7103
- ShaderFactory.includeMap = {};
7140
+ ShaderFactory.includeMap = Object.create(null);
7104
7141
  ShaderFactory.shaderExtension = [
7105
7142
  "GL_EXT_shader_texture_lod",
7106
7143
  "GL_OES_standard_derivatives",
@@ -8020,23 +8057,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
8020
8057
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
8021
8058
  }
8022
8059
 
8023
- /**
8024
- * Directive types for shader preprocessor instructions.
8025
- */ var ShaderPreprocessorDirective = /*#__PURE__*/ function(ShaderPreprocessorDirective) {
8026
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["Text"] = 0] = "Text";
8027
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["IfDef"] = 1] = "IfDef";
8028
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["IfNdef"] = 2] = "IfNdef";
8029
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["IfCmp"] = 3] = "IfCmp";
8030
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["IfExpr"] = 4] = "IfExpr";
8031
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["Else"] = 5] = "Else";
8032
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["Endif"] = 6] = "Endif";
8033
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["Define"] = 7] = "Define";
8034
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["DefineVal"] = 8] = "DefineVal";
8035
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["DefineFunc"] = 9] = "DefineFunc";
8036
- ShaderPreprocessorDirective[ShaderPreprocessorDirective["Undef"] = 10] = "Undef";
8037
- return ShaderPreprocessorDirective;
8038
- }({});
8039
-
8040
8060
  /**
8041
8061
  * @internal
8042
8062
  */ var ShaderMacroProcessor = /*#__PURE__*/ function() {
@@ -8045,6 +8065,7 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
8045
8065
  * Evaluate a flat instruction array with active macros.
8046
8066
  * Macros are expanded immediately when text chunks are collected,
8047
8067
  * using the current macro state at that point (conforming to GLSL/C99 §6.10 standard).
8068
+ * Declaration ownership filters buffered text after execution; it never skips macro directives.
8048
8069
  * @param instructions - Pre-parsed instruction array
8049
8070
  * @param macros - Active runtime macros
8050
8071
  * @returns Pure GLSL string with all conditionals resolved and macros expanded
@@ -8052,9 +8073,21 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
8052
8073
  var valueMacros = ShaderMacroProcessor._valueMacros;
8053
8074
  var funcMacros = ShaderMacroProcessor._funcMacros;
8054
8075
  var shaderChunks = ShaderMacroProcessor._shaderChunks;
8076
+ var declarationGroups = ShaderMacroProcessor._declarationGroups;
8077
+ var activeDeclarations = ShaderMacroProcessor._activeDeclarations;
8078
+ var ownedChunks = ShaderMacroProcessor._ownedChunks;
8079
+ var references = ShaderMacroProcessor._references;
8080
+ var reachableDeclarations = ShaderMacroProcessor._reachableDeclarations;
8081
+ var pendingDeclarations = ShaderMacroProcessor._pendingDeclarations;
8055
8082
  valueMacros.clear();
8056
8083
  funcMacros.clear();
8057
8084
  shaderChunks.length = 0;
8085
+ declarationGroups.clear();
8086
+ activeDeclarations.clear();
8087
+ ownedChunks.clear();
8088
+ references.clear();
8089
+ reachableDeclarations.clear();
8090
+ pendingDeclarations.length = 0;
8058
8091
  for(var _iterator = _create_for_of_iterator_helper_loose(macros), _step; !(_step = _iterator()).done;){
8059
8092
  var _step_value = _step.value, name = _step_value[0], value = _step_value[1];
8060
8093
  valueMacros.set(name, value);
@@ -8070,6 +8103,52 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
8070
8103
  shaderChunks.push(ShaderMacroProcessor._expandChunk(instruction[1], valueMacros, funcMacros));
8071
8104
  index++;
8072
8105
  break;
8106
+ case ShaderPreprocessorDirective.Declaration:
8107
+ {
8108
+ var ownerId = instruction[1];
8109
+ var groupId = instruction[2];
8110
+ var sourceScope = instruction[3];
8111
+ var group = declarationGroups.get(groupId);
8112
+ if (!group) {
8113
+ group = {
8114
+ sourceScope: sourceScope
8115
+ };
8116
+ declarationGroups.set(groupId, group);
8117
+ } else if (sourceScope > group.sourceScope) {
8118
+ group.sourceScope = sourceScope;
8119
+ }
8120
+ activeDeclarations.set(ownerId, {
8121
+ group: group,
8122
+ sourceScope: sourceScope
8123
+ });
8124
+ index++;
8125
+ break;
8126
+ }
8127
+ case ShaderPreprocessorDirective.OwnedText:
8128
+ {
8129
+ var chunk = {
8130
+ instruction: instruction
8131
+ };
8132
+ ownedChunks.set(shaderChunks.length, chunk);
8133
+ try {
8134
+ shaderChunks.push(ShaderMacroProcessor._expandChunk(instruction[1], valueMacros, funcMacros));
8135
+ } catch (error) {
8136
+ // Ownership may be activated later; discarded bodies must not surface their expansion errors
8137
+ chunk.error = error;
8138
+ shaderChunks.push("");
8139
+ }
8140
+ index++;
8141
+ break;
8142
+ }
8143
+ case ShaderPreprocessorDirective.Reference:
8144
+ {
8145
+ var from = instruction[1];
8146
+ var dependencies = references.get(from);
8147
+ if (!dependencies) references.set(from, dependencies = []);
8148
+ dependencies.push(instruction[2]);
8149
+ index++;
8150
+ break;
8151
+ }
8073
8152
  case ShaderPreprocessorDirective.IfDef:
8074
8153
  {
8075
8154
  var name1 = instruction[1];
@@ -8101,6 +8180,7 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
8101
8180
  break;
8102
8181
  case ShaderPreprocessorDirective.Define:
8103
8182
  valueMacros.set(instruction[1], "");
8183
+ ShaderMacroProcessor._macroFirstCharsDirty = true;
8104
8184
  index++;
8105
8185
  break;
8106
8186
  case ShaderPreprocessorDirective.DefineVal:
@@ -8119,6 +8199,7 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
8119
8199
  case ShaderPreprocessorDirective.Undef:
8120
8200
  valueMacros.delete(instruction[1]);
8121
8201
  funcMacros.delete(instruction[1]);
8202
+ ShaderMacroProcessor._macroFirstCharsDirty = true;
8122
8203
  index++;
8123
8204
  break;
8124
8205
  default:
@@ -8126,256 +8207,139 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
8126
8207
  break;
8127
8208
  }
8128
8209
  }
8210
+ if (ownedChunks.size) {
8211
+ var hasReferences = references.size > 0;
8212
+ if (hasReferences) {
8213
+ // Traverse only selected declarations, so discarded callers cannot retain their dependencies.
8214
+ // Each reached owner is queued once, bounding cycles and diamonds by the encoded graph size.
8215
+ pendingDeclarations.push(0);
8216
+ while(pendingDeclarations.length){
8217
+ var dependencies1 = references.get(pendingDeclarations.pop());
8218
+ if (!dependencies1) continue;
8219
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(dependencies1), _step1; !(_step1 = _iterator1()).done;){
8220
+ var ownerId1 = _step1.value;
8221
+ if (reachableDeclarations.has(ownerId1)) continue;
8222
+ var active = activeDeclarations.get(ownerId1);
8223
+ if (!active || active.sourceScope !== active.group.sourceScope) continue;
8224
+ reachableDeclarations.add(ownerId1);
8225
+ pendingDeclarations.push(ownerId1);
8226
+ }
8227
+ }
8228
+ }
8229
+ var count = 0;
8230
+ for(var i = 0; i < shaderChunks.length; i++){
8231
+ var owned = ownedChunks.get(i);
8232
+ if (owned) {
8233
+ var instruction1 = owned.instruction;
8234
+ var selected = false;
8235
+ for(var j = 2; j < instruction1.length; j++){
8236
+ var ownerId2 = instruction1[j];
8237
+ var active1 = activeDeclarations.get(ownerId2);
8238
+ if (active1 && active1.sourceScope === active1.group.sourceScope && (!hasReferences || reachableDeclarations.has(ownerId2))) {
8239
+ selected = true;
8240
+ break;
8241
+ }
8242
+ }
8243
+ if (!selected) continue;
8244
+ if ("error" in owned) throw owned.error;
8245
+ }
8246
+ shaderChunks[count++] = shaderChunks[i];
8247
+ }
8248
+ shaderChunks.length = count;
8249
+ }
8129
8250
  return ShaderMacroProcessor._concatChunks(shaderChunks);
8130
8251
  };
8131
8252
  /**
8132
8253
  * Expand macros in a single text chunk using the current macro state.
8133
8254
  * Returns the chunk as-is if no expandable macros exist.
8134
8255
  */ ShaderMacroProcessor._expandChunk = function _expandChunk(chunk, valueMacros, funcMacros) {
8135
- // Fast path: no expandable macros at this point
8136
- if (funcMacros.size === 0) {
8137
- var hasExpandable = false;
8138
- for(var _iterator = _create_for_of_iterator_helper_loose(valueMacros), _step; !(_step = _iterator()).done;){
8139
- var _step_value = _step.value, val = _step_value[1];
8140
- if (val !== "") {
8141
- hasExpandable = true;
8142
- break;
8143
- }
8144
- }
8145
- if (!hasExpandable) return chunk;
8146
- }
8147
- // Rebuild first-char filter if macros changed
8256
+ if (funcMacros.size === 0 && valueMacros.size === 0) return chunk;
8148
8257
  if (ShaderMacroProcessor._macroFirstCharsDirty) {
8149
8258
  var macroFirstChars = ShaderMacroProcessor._macroFirstChars;
8150
8259
  macroFirstChars.clear();
8151
- for(var _iterator1 = _create_for_of_iterator_helper_loose(valueMacros.keys()), _step1; !(_step1 = _iterator1()).done;){
8152
- var name = _step1.value;
8260
+ for(var _iterator = _create_for_of_iterator_helper_loose(valueMacros.keys()), _step; !(_step = _iterator()).done;){
8261
+ var name = _step.value;
8153
8262
  macroFirstChars.add(name.charCodeAt(0));
8154
8263
  }
8155
- for(var _iterator2 = _create_for_of_iterator_helper_loose(funcMacros.keys()), _step2; !(_step2 = _iterator2()).done;){
8156
- var name1 = _step2.value;
8264
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(funcMacros.keys()), _step1; !(_step1 = _iterator1()).done;){
8265
+ var name1 = _step1.value;
8157
8266
  macroFirstChars.add(name1.charCodeAt(0));
8158
8267
  }
8159
8268
  ShaderMacroProcessor._macroFirstCharsDirty = false;
8160
8269
  }
8270
+ // Most chunks contain no active macro names; avoid tokenizing those shader bodies.
8161
8271
  var macroFirstChars1 = ShaderMacroProcessor._macroFirstChars;
8162
- var expandedNames = ShaderMacroProcessor._expandedNames;
8163
- var out = ShaderMacroProcessor._out;
8164
- out.length = 0;
8165
- var len = chunk.length;
8166
- var i = 0;
8167
- while(i < len){
8168
- var cc = chunk.charCodeAt(i);
8169
- if (ShaderMacroProcessor._isIdentifierStart(cc)) {
8170
- var start = i;
8171
- i++;
8172
- while(i < len && ShaderMacroProcessor._isIdentifierPart(chunk.charCodeAt(i)))i++;
8173
- // Fast path: first char not in any macro name
8174
- if (!macroFirstChars1.has(chunk.charCodeAt(start))) {
8175
- out.push(chunk.substring(start, i));
8176
- continue;
8177
- }
8178
- var name2 = chunk.substring(start, i);
8179
- // Try function macro
8180
- var func = funcMacros.get(name2);
8181
- if (func) {
8182
- var lookAhead = i;
8183
- while(lookAhead < len && (chunk.charCodeAt(lookAhead) === 32 /* space */ || chunk.charCodeAt(lookAhead) === 9))lookAhead++;
8184
- if (lookAhead < len && chunk.charCodeAt(lookAhead) === 40 /* '(' */ ) {
8185
- var args = ShaderMacroProcessor._parseFuncArgs(chunk, lookAhead);
8186
- if (args) {
8187
- i = args.end;
8188
- var expanded = ShaderMacroProcessor._expandFuncBody(func, args.values);
8189
- expandedNames.clear();
8190
- expandedNames.add(name2);
8191
- out.push(ShaderMacroProcessor._recursiveExpandMacro(expanded, valueMacros, funcMacros, expandedNames));
8192
- continue;
8193
- }
8194
- }
8195
- }
8196
- // Try value macro
8197
- var val1 = valueMacros.get(name2);
8198
- if (val1 !== undefined && val1 !== "") {
8199
- expandedNames.clear();
8200
- expandedNames.add(name2);
8201
- out.push(ShaderMacroProcessor._recursiveExpandMacro(val1, valueMacros, funcMacros, expandedNames));
8202
- continue;
8203
- }
8204
- out.push(name2);
8205
- continue;
8206
- }
8207
- // Batch collect non-identifier characters
8208
- var batchStart = i;
8209
- while(i < len && !ShaderMacroProcessor._isIdentifierStart(chunk.charCodeAt(i)))i++;
8210
- out.push(chunk.substring(batchStart, i));
8211
- }
8212
- return out.join("");
8213
- };
8214
- /**
8215
- * Recursively expand macro substitution results until no more macros remain.
8216
- * @param macroExpansion - Intermediate text from a macro substitution that may contain further macro references
8217
- * @param valueMacros - Current value macro definitions
8218
- * @param funcMacros - Current function macro definitions
8219
- * @param expandedNames - Macro names already on the expansion chain, prevents circular references (C99 §6.10.3.4)
8220
- */ ShaderMacroProcessor._recursiveExpandMacro = function _recursiveExpandMacro(macroExpansion, valueMacros, funcMacros, expandedNames) {
8221
- if (macroExpansion.length === 0) return macroExpansion;
8222
- var len = macroExpansion.length;
8223
- var out = [];
8224
- var i = 0;
8225
- while(i < len){
8226
- var cc = macroExpansion.charCodeAt(i);
8227
- if (ShaderMacroProcessor._isIdentifierStart(cc)) {
8228
- var start = i;
8229
- i++;
8230
- while(i < len && ShaderMacroProcessor._isIdentifierPart(macroExpansion.charCodeAt(i)))i++;
8231
- var name = macroExpansion.substring(start, i);
8232
- // Skip already-expanded names (circular reference prevention)
8233
- // Skip GL_ prefixed names (reserved GLSL built-ins, charCodes: G=71, L=76, _=95)
8234
- if (expandedNames.has(name) || name.charCodeAt(0) === 71 && name.charCodeAt(1) === 76 && name.charCodeAt(2) === 95) {
8235
- out.push(name);
8236
- continue;
8237
- }
8272
+ for(var index = 0; index < chunk.length;){
8273
+ var char = chunk.charCodeAt(index++);
8274
+ if (!ShaderMacroProcessor._isIdentifierStart(char)) continue;
8275
+ var start = index - 1;
8276
+ while(index < chunk.length && ShaderMacroProcessor._isIdentifierPart(chunk.charCodeAt(index)))index++;
8277
+ if (!macroFirstChars1.has(char)) continue;
8278
+ var name2 = chunk.slice(start, index);
8279
+ if (!valueMacros.has(name2) && !funcMacros.has(name2)) continue;
8280
+ var expanded = engineDesign.expandShaderMacros(chunk, function(name) {
8238
8281
  var func = funcMacros.get(name);
8239
- if (func) {
8240
- var lookAhead = i;
8241
- while(lookAhead < len && (macroExpansion.charCodeAt(lookAhead) === 32 /* space */ || macroExpansion.charCodeAt(lookAhead) === 9))lookAhead++;
8242
- if (lookAhead < len && macroExpansion.charCodeAt(lookAhead) === 40 /* '(' */ ) {
8243
- var args = ShaderMacroProcessor._parseFuncArgs(macroExpansion, lookAhead);
8244
- if (args) {
8245
- i = args.end;
8246
- expandedNames.add(name);
8247
- out.push(ShaderMacroProcessor._recursiveExpandMacro(ShaderMacroProcessor._expandFuncBody(func, args.values), valueMacros, funcMacros, expandedNames));
8248
- expandedNames.delete(name);
8249
- continue;
8250
- }
8251
- }
8252
- }
8253
- var val = valueMacros.get(name);
8254
- if (val !== undefined && val !== "") {
8255
- expandedNames.add(name);
8256
- out.push(ShaderMacroProcessor._recursiveExpandMacro(val, valueMacros, funcMacros, expandedNames));
8257
- expandedNames.delete(name);
8258
- continue;
8259
- }
8260
- out.push(name);
8261
- continue;
8262
- }
8263
- // Batch collect non-identifier characters
8264
- var batchStart = i;
8265
- while(i < len && !ShaderMacroProcessor._isIdentifierStart(macroExpansion.charCodeAt(i)))i++;
8266
- out.push(macroExpansion.substring(batchStart, i));
8267
- }
8268
- return out.join("");
8269
- };
8270
- /**
8271
- * Substitute function macro params in body.
8272
- */ ShaderMacroProcessor._expandFuncBody = function _expandFuncBody(func, args) {
8273
- if (func.params.length === 0 || args.length !== func.params.length) return func.body;
8274
- var result = func.body;
8275
- for(var i = 0; i < func.params.length; i++){
8276
- result = ShaderMacroProcessor._replaceWord(result, func.params[i], args[i]);
8282
+ if (func) return {
8283
+ body: func.body,
8284
+ parameters: func.params
8285
+ };
8286
+ var body = valueMacros.get(name);
8287
+ return body === undefined ? undefined : {
8288
+ body: body
8289
+ };
8290
+ });
8291
+ if (expanded.error) throw new Error(expanded.error);
8292
+ return expanded.source;
8277
8293
  }
8278
- return result;
8294
+ return chunk;
8279
8295
  };
8280
8296
  /**
8281
8297
  * Evaluate a compound condition tree.
8282
8298
  */ ShaderMacroProcessor._evalCondition = function _evalCondition(cond, valueMacros, funcMacros) {
8283
- switch(cond.t){
8284
- case "def":
8285
- return valueMacros.has(cond.m) || funcMacros.has(cond.m);
8286
- case "ndef":
8287
- return !valueMacros.has(cond.m) && !funcMacros.has(cond.m);
8288
- case "cmp":
8289
- {
8290
- var val = valueMacros.get(cond.m);
8291
- if (val === undefined) return false;
8292
- return ShaderMacroProcessor._compareValues(Number(val) || 0, cond.op, cond.v);
8293
- }
8294
- case "and":
8295
- return ShaderMacroProcessor._evalCondition(cond.l, valueMacros, funcMacros) && ShaderMacroProcessor._evalCondition(cond.r, valueMacros, funcMacros);
8296
- case "or":
8297
- return ShaderMacroProcessor._evalCondition(cond.l, valueMacros, funcMacros) || ShaderMacroProcessor._evalCondition(cond.r, valueMacros, funcMacros);
8298
- case "not":
8299
- return !ShaderMacroProcessor._evalCondition(cond.c, valueMacros, funcMacros);
8300
- case "bool":
8301
- return cond.v;
8299
+ if (cond.t === "deferred") return ShaderMacroProcessor._evalDeferredCondition(cond.e, valueMacros, funcMacros);
8300
+ return engineDesign.evaluatePreprocessorExpression(cond, ShaderMacroProcessor._expressionContext) !== 0;
8301
+ };
8302
+ ShaderMacroProcessor._evalDeferredCondition = function _evalDeferredCondition(expression, valueMacros, funcMacros) {
8303
+ var withDefinedValues = engineDesign.resolvePreprocessorDefinedOperators(expression, function(name) {
8304
+ return valueMacros.has(name) || funcMacros.has(name);
8305
+ });
8306
+ var expanded = engineDesign.expandPreprocessorExpressionMacros(withDefinedValues, function(name) {
8307
+ var func = funcMacros.get(name);
8308
+ if (func) return {
8309
+ body: func.body,
8310
+ parameters: func.params
8311
+ };
8312
+ var body = valueMacros.get(name);
8313
+ return body === undefined ? undefined : {
8314
+ body: body
8315
+ };
8316
+ });
8317
+ if (expanded.error) throw new Error(expanded.error);
8318
+ var result = engineDesign.parsePreprocessorExpression(expanded.expression);
8319
+ if ("error" in result) {
8320
+ throw new Error("Invalid preprocessor expression after macro expansion: " + result.error.message);
8302
8321
  }
8322
+ return engineDesign.evaluatePreprocessorExpression(result.condition, ShaderMacroProcessor._expressionContext) !== 0;
8303
8323
  };
8304
- /**
8305
- * Evaluate a comparison operator.
8306
- */ ShaderMacroProcessor._compareValues = function _compareValues(numVal, op, value) {
8307
- switch(op){
8324
+ ShaderMacroProcessor._compareValues = function _compareValues(left, operator, right) {
8325
+ left |= 0;
8326
+ right |= 0;
8327
+ switch(operator){
8308
8328
  case "==":
8309
- return numVal === value;
8329
+ return left === right;
8310
8330
  case "!=":
8311
- return numVal !== value;
8331
+ return left !== right;
8312
8332
  case ">":
8313
- return numVal > value;
8333
+ return left > right;
8314
8334
  case "<":
8315
- return numVal < value;
8335
+ return left < right;
8316
8336
  case ">=":
8317
- return numVal >= value;
8337
+ return left >= right;
8318
8338
  case "<=":
8319
- return numVal <= value;
8339
+ return left <= right;
8320
8340
  default:
8321
- return false;
8322
- }
8323
- };
8324
- /**
8325
- * Parse function macro call arguments.
8326
- * Returns reusable static result object to avoid allocation.
8327
- */ ShaderMacroProcessor._parseFuncArgs = function _parseFuncArgs(text, openParen) {
8328
- var result = ShaderMacroProcessor._parsedFuncArgs;
8329
- result.values.length = 0;
8330
- var level = 1;
8331
- var argStart = openParen + 1;
8332
- var k = argStart;
8333
- var len = text.length;
8334
- while(k < len && level > 0){
8335
- var cc = text.charCodeAt(k);
8336
- if (cc === 40 /* '(' */ ) {
8337
- level++;
8338
- } else if (cc === 41 /* ')' */ ) {
8339
- if (--level === 0) {
8340
- var arg = text.substring(argStart, k).trim();
8341
- if (arg.length > 0 || result.values.length > 0) result.values.push(arg);
8342
- result.end = k + 1;
8343
- return result;
8344
- }
8345
- } else if (cc === 44 /* ',' */ && level === 1) {
8346
- result.values.push(text.substring(argStart, k).trim());
8347
- argStart = k + 1;
8348
- }
8349
- k++;
8350
- }
8351
- return null;
8352
- };
8353
- /**
8354
- * Replace all whole-word occurrences of `word` in `text` with `replacement`.
8355
- */ ShaderMacroProcessor._replaceWord = function _replaceWord(text, word, replacement) {
8356
- var wLen = word.length;
8357
- var parts = ShaderMacroProcessor._replaceWordParts;
8358
- parts.length = 0;
8359
- var start = 0;
8360
- var idx = text.indexOf(word, start);
8361
- while(idx !== -1){
8362
- if (idx > 0 && ShaderMacroProcessor._isIdentifierPart(text.charCodeAt(idx - 1))) {
8363
- idx = text.indexOf(word, idx + 1);
8364
- continue;
8365
- }
8366
- var afterIdx = idx + wLen;
8367
- if (afterIdx < text.length && ShaderMacroProcessor._isIdentifierPart(text.charCodeAt(afterIdx))) {
8368
- idx = text.indexOf(word, idx + 1);
8369
- continue;
8370
- }
8371
- parts.push(text.substring(start, idx));
8372
- parts.push(replacement);
8373
- start = afterIdx;
8374
- idx = text.indexOf(word, start);
8341
+ throw new Error("Unsupported preprocessor comparison operator '" + operator + "'.");
8375
8342
  }
8376
- if (start === 0) return text;
8377
- parts.push(text.substring(start));
8378
- return parts.join("");
8379
8343
  };
8380
8344
  /**
8381
8345
  * Concatenate shader chunks with consecutive blank lines collapsed to a single newline.
@@ -8426,14 +8390,23 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
8426
8390
  ShaderMacroProcessor._valueMacros = new Map();
8427
8391
  ShaderMacroProcessor._funcMacros = new Map();
8428
8392
  ShaderMacroProcessor._shaderChunks = [];
8393
+ ShaderMacroProcessor._declarationGroups = new Map();
8394
+ ShaderMacroProcessor._activeDeclarations = new Map();
8395
+ ShaderMacroProcessor._ownedChunks = new Map();
8396
+ ShaderMacroProcessor._references = new Map();
8397
+ ShaderMacroProcessor._reachableDeclarations = new Set();
8398
+ ShaderMacroProcessor._pendingDeclarations = [];
8429
8399
  ShaderMacroProcessor._out = [];
8430
- ShaderMacroProcessor._expandedNames = new Set();
8431
8400
  ShaderMacroProcessor._macroFirstChars = new Set();
8432
8401
  ShaderMacroProcessor._macroFirstCharsDirty = true;
8433
- ShaderMacroProcessor._replaceWordParts = [];
8434
- ShaderMacroProcessor._parsedFuncArgs = {
8435
- values: [],
8436
- end: 0
8402
+ ShaderMacroProcessor._expressionContext = {
8403
+ resolveIdentifier: function resolveIdentifier(name) {
8404
+ var value = ShaderMacroProcessor._valueMacros.get(name);
8405
+ return value === undefined ? 0 : Number(value) | 0;
8406
+ },
8407
+ isDefined: function isDefined(name) {
8408
+ return ShaderMacroProcessor._valueMacros.has(name) || ShaderMacroProcessor._funcMacros.has(name);
8409
+ }
8437
8410
  };
8438
8411
 
8439
8412
  /**
@@ -9137,7 +9110,6 @@ var precisionStr = "\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision hig
9137
9110
  return ShaderPass;
9138
9111
  }(ShaderPart);
9139
9112
  /** @internal */ ShaderPass._shaderPassCounter = 0;
9140
- /** @internal */ ShaderPass._shaderRootPath = "shaders://root/";
9141
9113
  ShaderPass._shaderMacroList = [];
9142
9114
  ShaderPass._macroMap = new Map();
9143
9115
 
@@ -9246,62 +9218,71 @@ ShaderPass._macroMap = new Map();
9246
9218
  */ _proto._addReferCount = function _addReferCount(value) {
9247
9219
  this._refCount += value;
9248
9220
  };
9249
- Shader.create = function create(nameOrShaderSource, shaderPassesOrSubShadersOrPlatformTarget, path) {
9221
+ Shader.create = function create(nameOrShaderSource, shaderPassesOrSubShadersOrPlatformTarget) {
9222
+ if (shaderPassesOrSubShadersOrPlatformTarget == undefined || typeof shaderPassesOrSubShadersOrPlatformTarget === "number") {
9223
+ var platformTarget = typeof shaderPassesOrSubShadersOrPlatformTarget === "number" ? shaderPassesOrSubShadersOrPlatformTarget : ShaderLanguage.GLSLES100;
9224
+ return Shader._createFromSource(nameOrShaderSource, platformTarget);
9225
+ }
9250
9226
  var shader;
9251
9227
  var shaderMap = Shader._shaderMap;
9252
- if (shaderPassesOrSubShadersOrPlatformTarget == undefined) {
9253
- shaderPassesOrSubShadersOrPlatformTarget = ShaderLanguage.GLSLES100;
9228
+ if (shaderMap[nameOrShaderSource]) {
9229
+ console.error('Shader named "' + nameOrShaderSource + '" already exists.');
9230
+ return;
9254
9231
  }
9255
- if (typeof shaderPassesOrSubShadersOrPlatformTarget === "number") {
9256
- var shaderCompiler = Shader._shaderCompiler;
9257
- if (!shaderCompiler) {
9258
- throw "ShaderCompiler has not been set up yet.";
9259
- }
9260
- var shaderSource = shaderCompiler._parseShaderSource(nameOrShaderSource);
9261
- if (shaderMap[shaderSource.name]) {
9262
- console.error('Shader named "' + shaderSource.name + '" already exists.');
9263
- return;
9264
- }
9265
- var basePathForIncludeKey = new URL(path != null ? path : "", ShaderPass._shaderRootPath).href;
9266
- var subShaderList = shaderSource.subShaders.map(function(subShaderSource) {
9267
- var passList = subShaderSource.passes.map(function(passSource) {
9268
- if (passSource.isUsePass) {
9269
- return Shader._resolveUsePass(passSource.name);
9270
- }
9271
- var shaderPassSource = Shader._shaderCompiler._parseShaderPass(passSource.contents, passSource.vertexEntry, passSource.fragmentEntry, shaderPassesOrSubShadersOrPlatformTarget, basePathForIncludeKey);
9272
- if (!shaderPassSource) {
9273
- throw 'Shader pass "' + shaderSource.name + "." + subShaderSource.name + "." + passSource.name + '" parse failed, please check the shader source code.';
9274
- }
9275
- var shaderPass = new ShaderPass(passSource.name, shaderPassSource.vertexShaderInstructions, shaderPassSource.fragmentShaderInstructions, shaderPassesOrSubShadersOrPlatformTarget, passSource.tags);
9276
- Shader._applyRenderStates(shaderPass, passSource.renderStates.constantMap, passSource.renderStates.variableMap, false);
9277
- return shaderPass;
9278
- });
9279
- return new SubShader(subShaderSource.name, passList, subShaderSource.tags);
9280
- });
9281
- shader = new Shader(shaderSource.name, subShaderList);
9282
- shaderMap[shaderSource.name] = shader;
9283
- return shader;
9284
- } else {
9285
- if (shaderMap[nameOrShaderSource]) {
9286
- console.error('Shader named "' + nameOrShaderSource + '" already exists.');
9287
- return;
9288
- }
9289
- if (shaderPassesOrSubShadersOrPlatformTarget.length > 0) {
9290
- if (shaderPassesOrSubShadersOrPlatformTarget[0].constructor === ShaderPass) {
9291
- shader = new Shader(nameOrShaderSource, [
9292
- new SubShader("Default", shaderPassesOrSubShadersOrPlatformTarget)
9293
- ]);
9294
- } else {
9295
- shader = new Shader(nameOrShaderSource, shaderPassesOrSubShadersOrPlatformTarget.slice());
9296
- }
9232
+ if (shaderPassesOrSubShadersOrPlatformTarget.length > 0) {
9233
+ if (shaderPassesOrSubShadersOrPlatformTarget[0].constructor === ShaderPass) {
9234
+ shader = new Shader(nameOrShaderSource, [
9235
+ new SubShader("Default", shaderPassesOrSubShadersOrPlatformTarget)
9236
+ ]);
9297
9237
  } else {
9298
- throw "SubShader or ShaderPass count must large than 0.";
9238
+ shader = new Shader(nameOrShaderSource, shaderPassesOrSubShadersOrPlatformTarget.slice());
9299
9239
  }
9240
+ } else {
9241
+ throw "SubShader or ShaderPass count must large than 0.";
9300
9242
  }
9301
9243
  shaderMap[nameOrShaderSource] = shader;
9302
9244
  return shader;
9303
9245
  };
9304
9246
  /**
9247
+ * Creates a shader while retaining loader-owned source location metadata for relative includes.
9248
+ * @param shaderSource - Complete ShaderLab source.
9249
+ * @param platformTarget - Shader backend target.
9250
+ * @param sourceFile - Canonical source location supplied by an asset loader or authoring tool.
9251
+ * @returns The compiled shader, or `undefined` if its name already exists.
9252
+ * @throws When the shader compiler is unavailable or a pass cannot be compiled.
9253
+ * @internal
9254
+ */ Shader._createFromSource = function _createFromSource(shaderSource, platformTarget, sourceFile) {
9255
+ if (platformTarget === void 0) platformTarget = ShaderLanguage.GLSLES100;
9256
+ var shaderCompiler = Shader._shaderCompiler;
9257
+ if (!shaderCompiler) {
9258
+ throw "ShaderCompiler has not been set up yet.";
9259
+ }
9260
+ var parsedSource = shaderCompiler._parseShaderSource(shaderSource);
9261
+ var shaderMap = Shader._shaderMap;
9262
+ if (shaderMap[parsedSource.name]) {
9263
+ console.error('Shader named "' + parsedSource.name + '" already exists.');
9264
+ return;
9265
+ }
9266
+ var subShaderList = parsedSource.subShaders.map(function(subShaderSource) {
9267
+ var passList = subShaderSource.passes.map(function(passSource) {
9268
+ if (passSource.isUsePass) {
9269
+ return Shader._resolveUsePass(passSource.name);
9270
+ }
9271
+ var shaderPassSource = shaderCompiler._parseShaderPass(passSource.contents, passSource.vertexEntry, passSource.fragmentEntry, platformTarget, sourceFile, passSource.contentScopeStarts);
9272
+ if (!shaderPassSource) {
9273
+ throw 'Shader pass "' + parsedSource.name + "." + subShaderSource.name + "." + passSource.name + '" parse failed, please check the shader source code.';
9274
+ }
9275
+ var shaderPass = new ShaderPass(passSource.name, shaderPassSource.vertexShaderInstructions, shaderPassSource.fragmentShaderInstructions, platformTarget, passSource.tags);
9276
+ Shader._applyRenderStates(shaderPass, passSource.renderStates.constantMap, passSource.renderStates.variableMap, false);
9277
+ return shaderPass;
9278
+ });
9279
+ return new SubShader(subShaderSource.name, passList, subShaderSource.tags);
9280
+ });
9281
+ var shader = new Shader(parsedSource.name, subShaderList);
9282
+ shaderMap[parsedSource.name] = shader;
9283
+ return shader;
9284
+ };
9285
+ /**
9305
9286
  * Find a shader by name.
9306
9287
  * @param name - Name of the shader
9307
9288
  */ Shader.find = function find(name) {
@@ -19712,15 +19693,6 @@ var PointerEventType = /*#__PURE__*/ function(PointerEventType) {
19712
19693
  return CameraClearFlags;
19713
19694
  }({});
19714
19695
 
19715
- /**
19716
- * @internal
19717
- */ var ColliderShapeChangeFlag = /*#__PURE__*/ function(ColliderShapeChangeFlag) {
19718
- ColliderShapeChangeFlag[ColliderShapeChangeFlag["Property"] = 1] = "Property";
19719
- ColliderShapeChangeFlag[ColliderShapeChangeFlag["Count"] = 2] = "Count";
19720
- ColliderShapeChangeFlag[ColliderShapeChangeFlag["Both"] = 3] = "Both";
19721
- return ColliderShapeChangeFlag;
19722
- }({});
19723
-
19724
19696
  exports.Collider = /*#__PURE__*/ function(Component) {
19725
19697
  _inherits(Collider, Component);
19726
19698
  function Collider(entity) {
@@ -19742,7 +19714,7 @@ exports.Collider = /*#__PURE__*/ function(Component) {
19742
19714
  }
19743
19715
  this._addNativeShape(shape);
19744
19716
  this._shapes.push(shape);
19745
- this._handleShapesChanged(ColliderShapeChangeFlag.Count);
19717
+ this._handleShapesChanged();
19746
19718
  }
19747
19719
  };
19748
19720
  /**
@@ -19753,7 +19725,7 @@ exports.Collider = /*#__PURE__*/ function(Component) {
19753
19725
  if (index !== -1) {
19754
19726
  this._shapes.splice(index, 1);
19755
19727
  this._removeNativeShape(shape);
19756
- this._handleShapesChanged(ColliderShapeChangeFlag.Count);
19728
+ this._handleShapesChanged();
19757
19729
  }
19758
19730
  };
19759
19731
  /**
@@ -19764,7 +19736,7 @@ exports.Collider = /*#__PURE__*/ function(Component) {
19764
19736
  this._removeNativeShape(shapes[i]);
19765
19737
  }
19766
19738
  shapes.length = 0;
19767
- this._handleShapesChanged(ColliderShapeChangeFlag.Count);
19739
+ this._handleShapesChanged();
19768
19740
  };
19769
19741
  /**
19770
19742
  * @internal
@@ -19802,11 +19774,7 @@ exports.Collider = /*#__PURE__*/ function(Component) {
19802
19774
  };
19803
19775
  /**
19804
19776
  * @internal
19805
- */ _proto._handleShapesChanged = function _handleShapesChanged(changeType) {
19806
- if (changeType & ColliderShapeChangeFlag.Count) {
19807
- this._setCollisionLayer();
19808
- }
19809
- };
19777
+ */ _proto._handleShapesChanged = function _handleShapesChanged() {};
19810
19778
  /**
19811
19779
  * @internal
19812
19780
  */ _proto._setNativeShapeAttached = function _setNativeShapeAttached(shape, attached) {
@@ -19814,7 +19782,7 @@ exports.Collider = /*#__PURE__*/ function(Component) {
19814
19782
  if (nativeShape && shape._isShapeAttached !== attached) {
19815
19783
  if (attached) {
19816
19784
  nativeShape.setWorldScale(this.entity.transform.lossyWorldScale);
19817
- this._nativeCollider.addShape(nativeShape);
19785
+ this._nativeCollider.addShape(nativeShape, this._collisionLayerIndex);
19818
19786
  } else {
19819
19787
  this._nativeCollider.removeShape(nativeShape);
19820
19788
  }
@@ -19825,7 +19793,6 @@ exports.Collider = /*#__PURE__*/ function(Component) {
19825
19793
  for(var i = 0, n = this.shapes.length; i < n; i++){
19826
19794
  this._addNativeShape(this.shapes[i]);
19827
19795
  }
19828
- this._setCollisionLayer();
19829
19796
  };
19830
19797
  /**
19831
19798
  * @internal
@@ -19848,9 +19815,6 @@ exports.Collider = /*#__PURE__*/ function(Component) {
19848
19815
  this._setNativeShapeAttached(shape, false);
19849
19816
  shape._collider = null;
19850
19817
  };
19851
- _proto._setCollisionLayer = function _setCollisionLayer() {
19852
- this._nativeCollider.setCollisionLayer(this._collisionLayerIndex);
19853
- };
19854
19818
  _create_class(Collider, [
19855
19819
  {
19856
19820
  key: "shapes",
@@ -20163,11 +20127,7 @@ __decorate([
20163
20127
  _inherits(ColliderShape, DataObject);
20164
20128
  function ColliderShape() {
20165
20129
  var _this;
20166
- _this = DataObject.call(this) || this, /** @internal */ _this._isShapeAttached = false, _this._isTrigger = false, _this._rotation = new engineMath.Vector3(), _this._position = new engineMath.Vector3(), _this._contactOffset = 0.02, /**
20167
- * @internal
20168
- * @beta
20169
- * Whether raycast can select it.
20170
- */ _this.isSceneQuery = true;
20130
+ _this = DataObject.call(this) || this, /** @internal */ _this._isShapeAttached = false, _this._isTrigger = false, _this._isSceneQuery = true, _this._rotation = new engineMath.Vector3(), _this._position = new engineMath.Vector3(), _this._contactOffset = 0.02;
20171
20131
  _this._material = new PhysicsMaterial();
20172
20132
  _this._id = ColliderShape._idGenerator++;
20173
20133
  _this._setRotation = _this._setRotation.bind(_this);
@@ -20222,20 +20182,39 @@ __decorate([
20222
20182
  this._nativeShape.setRotation(this._rotation);
20223
20183
  this._nativeShape.setContactOffset(this._contactOffset);
20224
20184
  this._nativeShape.setIsTrigger(this._isTrigger);
20185
+ this._nativeShape.setIsSceneQuery(this._isSceneQuery);
20225
20186
  this._nativeShape.setMaterial(this._material._nativeMaterial);
20226
- (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged(ColliderShapeChangeFlag.Property);
20187
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
20227
20188
  };
20228
20189
  _proto._setPosition = function _setPosition() {
20229
20190
  var _this__nativeShape, _this__collider;
20230
20191
  (_this__nativeShape = this._nativeShape) == null ? void 0 : _this__nativeShape.setPosition(this._position);
20231
- (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged(ColliderShapeChangeFlag.Property);
20192
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
20232
20193
  };
20233
20194
  _proto._setRotation = function _setRotation() {
20234
20195
  var _this__nativeShape, _this__collider;
20235
20196
  (_this__nativeShape = this._nativeShape) == null ? void 0 : _this__nativeShape.setRotation(this._rotation);
20236
- (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged(ColliderShapeChangeFlag.Property);
20197
+ (_this__collider = this._collider) == null ? void 0 : _this__collider._handleShapesChanged();
20237
20198
  };
20238
20199
  _create_class(ColliderShape, [
20200
+ {
20201
+ key: "isSceneQuery",
20202
+ get: /**
20203
+ * @internal
20204
+ * @beta
20205
+ * Whether this shape participates in scene queries, including raycasts, shape casts, and overlap queries.
20206
+ * This does not affect collision response.
20207
+ */ function get() {
20208
+ return this._isSceneQuery;
20209
+ },
20210
+ set: function set(value) {
20211
+ if (this._isSceneQuery !== value) {
20212
+ var _this__nativeShape;
20213
+ this._isSceneQuery = value;
20214
+ (_this__nativeShape = this._nativeShape) == null ? void 0 : _this__nativeShape.setIsSceneQuery(value);
20215
+ }
20216
+ }
20217
+ },
20239
20218
  {
20240
20219
  key: "collider",
20241
20220
  get: /**
@@ -20635,8 +20614,7 @@ __decorate([
20635
20614
  };
20636
20615
  /**
20637
20616
  * @internal
20638
- */ _proto._handleShapesChanged = function _handleShapesChanged(changeType) {
20639
- Collider.prototype._handleShapesChanged.call(this, changeType);
20617
+ */ _proto._handleShapesChanged = function _handleShapesChanged() {
20640
20618
  if (this._automaticCenterOfMass || this._automaticInertiaTensor) {
20641
20619
  this._setMassAndUpdateInertia();
20642
20620
  }
@@ -21152,16 +21130,61 @@ __decorate([
21152
21130
  hitResult = outHitResult;
21153
21131
  }
21154
21132
  var normalizedDirection = PhysicsScene._normalizeDirection(ray.direction);
21155
- var preFilter = this._createPreFilter(layerMask);
21156
21133
  var result = false;
21157
21134
  if (normalizedDirection) {
21158
- result = this._nativePhysicsScene.raycast(ray.origin, normalizedDirection, distance, preFilter, hitResult ? this._createHitCallback(hitResult) : undefined);
21135
+ result = this._nativePhysicsScene.raycast(ray.origin, normalizedDirection, distance, layerMask, hitResult ? this._createHitCallback(hitResult) : undefined);
21159
21136
  }
21160
21137
  if (!result && hitResult) {
21161
21138
  this._clearHitResult(hitResult);
21162
21139
  }
21163
21140
  return result;
21164
21141
  };
21142
+ _proto.raycastAll = function raycastAll(ray, distance, layerMask, outHitResults) {
21143
+ var _this = this;
21144
+ if (distance === void 0) distance = Number.MAX_VALUE;
21145
+ if (layerMask === void 0) layerMask = Layer.Everything;
21146
+ if (typeof layerMask !== "number") {
21147
+ outHitResults || (outHitResults = layerMask);
21148
+ layerMask = Layer.Everything;
21149
+ }
21150
+ if (typeof distance !== "number") {
21151
+ outHitResults || (outHitResults = distance);
21152
+ distance = Number.MAX_VALUE;
21153
+ }
21154
+ if (!outHitResults) {
21155
+ return this.raycast(ray, distance, layerMask);
21156
+ }
21157
+ var pool = PhysicsScene._raycastHitPool;
21158
+ var hitCount = 0;
21159
+ var normalizedDirection = PhysicsScene._normalizeDirection(ray.direction);
21160
+ if (distance > 0 && normalizedDirection) {
21161
+ this._nativePhysicsScene.raycastAll(ray.origin, normalizedDirection, distance, layerMask, function(shapeUniqueID, hitDistance, position, normal) {
21162
+ var _outHitResults, _ref;
21163
+ var _pool_pop;
21164
+ var hitResult = (_outHitResults = outHitResults)[_ref = hitCount++] || (_outHitResults[_ref] = (_pool_pop = pool.pop()) != null ? _pool_pop : new HitResult());
21165
+ _this._setHitResult(hitResult, shapeUniqueID, hitDistance, position, normal);
21166
+ });
21167
+ }
21168
+ var length = outHitResults.length;
21169
+ if (hitCount < length) {
21170
+ // Preserve active aliases and recycle each unused object only once
21171
+ var seenHits = PhysicsScene._raycastSeenHits;
21172
+ for(var i = 0; i < hitCount; i++){
21173
+ seenHits.add(outHitResults[i]);
21174
+ }
21175
+ for(var i1 = hitCount; i1 < length; i1++){
21176
+ var hitResult = outHitResults[i1];
21177
+ if (hitResult && !seenHits.has(hitResult)) {
21178
+ seenHits.add(hitResult);
21179
+ this._clearHitResult(hitResult);
21180
+ pool.push(hitResult);
21181
+ }
21182
+ }
21183
+ seenHits.clear();
21184
+ }
21185
+ outHitResults.length = hitCount;
21186
+ return hitCount > 0;
21187
+ };
21165
21188
  _proto.boxCast = function boxCast(center, halfExtents, direction, orientationOrDistanceOrResult, distanceOrResult, layerMaskOrResult, outHitResult) {
21166
21189
  var hitResult;
21167
21190
  var orientation = PhysicsScene._identityQuaternion;
@@ -21188,10 +21211,9 @@ __decorate([
21188
21211
  hitResult = outHitResult;
21189
21212
  }
21190
21213
  var normalizedDirection = PhysicsScene._normalizeDirection(direction);
21191
- var preFilter = this._createPreFilter(layerMask);
21192
21214
  var result = false;
21193
21215
  if (normalizedDirection) {
21194
- result = this._nativePhysicsScene.boxCast(center, orientation, halfExtents, normalizedDirection, distance, preFilter, hitResult ? this._createHitCallback(hitResult) : undefined);
21216
+ result = this._nativePhysicsScene.boxCast(center, orientation, halfExtents, normalizedDirection, distance, layerMask, hitResult ? this._createHitCallback(hitResult) : undefined);
21195
21217
  }
21196
21218
  if (!result && hitResult) {
21197
21219
  this._clearHitResult(hitResult);
@@ -21217,10 +21239,9 @@ __decorate([
21217
21239
  hitResult = outHitResult;
21218
21240
  }
21219
21241
  var normalizedDirection = PhysicsScene._normalizeDirection(direction);
21220
- var preFilter = this._createPreFilter(layerMask);
21221
21242
  var result = false;
21222
21243
  if (normalizedDirection) {
21223
- result = this._nativePhysicsScene.sphereCast(center, radius, normalizedDirection, distance, preFilter, hitResult ? this._createHitCallback(hitResult) : undefined);
21244
+ result = this._nativePhysicsScene.sphereCast(center, radius, normalizedDirection, distance, layerMask, hitResult ? this._createHitCallback(hitResult) : undefined);
21224
21245
  }
21225
21246
  if (!result && hitResult) {
21226
21247
  this._clearHitResult(hitResult);
@@ -21252,10 +21273,9 @@ __decorate([
21252
21273
  hitResult = outHitResult;
21253
21274
  }
21254
21275
  var normalizedDirection = PhysicsScene._normalizeDirection(direction);
21255
- var preFilter = this._createPreFilter(layerMask);
21256
21276
  var result = false;
21257
21277
  if (normalizedDirection) {
21258
- result = this._nativePhysicsScene.capsuleCast(center, radius, height, orientation, normalizedDirection, distance, preFilter, hitResult ? this._createHitCallback(hitResult) : undefined);
21278
+ result = this._nativePhysicsScene.capsuleCast(center, radius, height, orientation, normalizedDirection, distance, layerMask, hitResult ? this._createHitCallback(hitResult) : undefined);
21259
21279
  }
21260
21280
  if (!result && hitResult) {
21261
21281
  this._clearHitResult(hitResult);
@@ -21274,7 +21294,7 @@ __decorate([
21274
21294
  if (orientation === void 0) orientation = PhysicsScene._identityQuaternion;
21275
21295
  if (layerMask === void 0) layerMask = Layer.Everything;
21276
21296
  if (shapes === void 0) shapes = [];
21277
- var ids = this._nativePhysicsScene.overlapBoxAll(center, orientation, halfExtents, this._createPreFilter(layerMask));
21297
+ var ids = this._nativePhysicsScene.overlapBoxAll(center, orientation, halfExtents, layerMask);
21278
21298
  shapes.length = 0;
21279
21299
  for(var i = 0, n = ids.length; i < n; i++){
21280
21300
  shapes.push(Engine._physicalObjectsMap[ids[i]]);
@@ -21291,7 +21311,7 @@ __decorate([
21291
21311
  */ _proto.overlapSphereAll = function overlapSphereAll(center, radius, layerMask, shapes) {
21292
21312
  if (layerMask === void 0) layerMask = Layer.Everything;
21293
21313
  if (shapes === void 0) shapes = [];
21294
- var ids = this._nativePhysicsScene.overlapSphereAll(center, radius, this._createPreFilter(layerMask));
21314
+ var ids = this._nativePhysicsScene.overlapSphereAll(center, radius, layerMask);
21295
21315
  shapes.length = 0;
21296
21316
  for(var i = 0; i < ids.length; i++){
21297
21317
  shapes.push(Engine._physicalObjectsMap[ids[i]]);
@@ -21311,7 +21331,7 @@ __decorate([
21311
21331
  if (orientation === void 0) orientation = PhysicsScene._identityQuaternion;
21312
21332
  if (layerMask === void 0) layerMask = Layer.Everything;
21313
21333
  if (shapes === void 0) shapes = [];
21314
- var ids = this._nativePhysicsScene.overlapCapsuleAll(center, radius, height, orientation, this._createPreFilter(layerMask));
21334
+ var ids = this._nativePhysicsScene.overlapCapsuleAll(center, radius, height, orientation, layerMask);
21315
21335
  shapes.length = 0;
21316
21336
  for(var i = 0; i < ids.length; i++){
21317
21337
  shapes.push(Engine._physicalObjectsMap[ids[i]]);
@@ -21408,6 +21428,8 @@ __decorate([
21408
21428
  * @internal
21409
21429
  */ _proto._gc = function _gc() {
21410
21430
  var _this__nativePhysicsScene;
21431
+ PhysicsScene._raycastHitPool.length = 0;
21432
+ PhysicsScene._raycastSeenHits.clear();
21411
21433
  this._colliders.garbageCollection();
21412
21434
  (_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.gc();
21413
21435
  };
@@ -21415,6 +21437,8 @@ __decorate([
21415
21437
  * @internal
21416
21438
  */ _proto._destroy = function _destroy() {
21417
21439
  var _this__nativePhysicsScene;
21440
+ PhysicsScene._raycastHitPool.length = 0;
21441
+ PhysicsScene._raycastSeenHits.clear();
21418
21442
  (_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.destroy();
21419
21443
  };
21420
21444
  _proto._dispatchEvents = function _dispatchEvents(events) {
@@ -21506,24 +21530,20 @@ __decorate([
21506
21530
  _proto._setGravity = function _setGravity() {
21507
21531
  this._nativePhysicsScene.setGravity(this._gravity);
21508
21532
  };
21509
- _proto._createPreFilter = function _createPreFilter(mask) {
21510
- return function(obj) {
21511
- var shape = Engine._physicalObjectsMap[obj];
21512
- if (!shape) {
21513
- return false;
21514
- }
21515
- return (shape.collider.collisionLayer & mask) !== 0 && shape.isSceneQuery;
21516
- };
21517
- };
21518
21533
  _proto._createHitCallback = function _createHitCallback(outHitResult) {
21534
+ var _this = this;
21519
21535
  return function(shapeUniqueID, distance, position, normal) {
21520
- outHitResult.entity = Engine._physicalObjectsMap[shapeUniqueID].collider.entity;
21521
- outHitResult.shape = Engine._physicalObjectsMap[shapeUniqueID];
21522
- outHitResult.distance = distance;
21523
- outHitResult.point.copyFrom(position);
21524
- outHitResult.normal.copyFrom(normal);
21536
+ _this._setHitResult(outHitResult, shapeUniqueID, distance, position, normal);
21525
21537
  };
21526
21538
  };
21539
+ _proto._setHitResult = function _setHitResult(outHitResult, shapeUniqueID, distance, position, normal) {
21540
+ var shape = Engine._physicalObjectsMap[shapeUniqueID];
21541
+ outHitResult.entity = shape.collider.entity;
21542
+ outHitResult.shape = shape;
21543
+ outHitResult.distance = distance;
21544
+ outHitResult.point.copyFrom(position);
21545
+ outHitResult.normal.copyFrom(normal);
21546
+ };
21527
21547
  _proto._clearHitResult = function _clearHitResult(hitResult) {
21528
21548
  hitResult.entity = null;
21529
21549
  hitResult.shape = null;
@@ -21567,6 +21587,8 @@ __decorate([
21567
21587
  PhysicsScene._collision = new Collision();
21568
21588
  PhysicsScene._identityQuaternion = new engineMath.Quaternion(0, 0, 0, 1);
21569
21589
  PhysicsScene._tempDirection = new engineMath.Vector3();
21590
+ PhysicsScene._raycastHitPool = [];
21591
+ PhysicsScene._raycastSeenHits = new Set();
21570
21592
  PhysicsScene._scriptIndexSetter = function(element, index) {
21571
21593
  element._entityScriptsIndex = index;
21572
21594
  };
@@ -27662,8 +27684,6 @@ var OverlayCamera = function OverlayCamera() {
27662
27684
  // shader-compiler defaults to an empty map and stays free of any direct
27663
27685
  // ShaderFactory dependency, so the binding has to be wired here at the
27664
27686
  // runtime boundary.
27665
- // @ts-ignore — `_setIncludeMap` is shader-compiler @internal; `includeMap`
27666
- // is `ShaderFactory` @internal. Both intentionally cross-package wired.
27667
27687
  shaderCompiler._setIncludeMap(ShaderFactory.includeMap);
27668
27688
  Shader._shaderCompiler = shaderCompiler;
27669
27689
  }
@@ -43575,6 +43595,7 @@ exports.ShaderLanguage = ShaderLanguage;
43575
43595
  exports.ShaderMacro = ShaderMacro;
43576
43596
  exports.ShaderMacroCollection = ShaderMacroCollection;
43577
43597
  exports.ShaderPass = ShaderPass;
43598
+ exports.ShaderPreprocessorDirective = ShaderPreprocessorDirective;
43578
43599
  exports.ShaderProperty = ShaderProperty;
43579
43600
  exports.ShaderPropertyType = ShaderPropertyType;
43580
43601
  exports.ShaderTagKey = ShaderTagKey;