@galacean/engine 2.0.0-alpha.29 → 2.0.0-alpha.30

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.
@@ -28272,7 +28272,7 @@ BasicResources._maskReadInsideRenderStates = null;
28272
28272
  BasicResources._maskReadOutsideRenderStates = null;
28273
28273
  BasicResources._maskWriteIncrementRenderStates = null;
28274
28274
  BasicResources._maskWriteDecrementRenderStates = null;
28275
- function _is_native_reflect_construct$1() {
28275
+ function _is_native_reflect_construct() {
28276
28276
  // Since Reflect.construct can't be properly polyfilled, some
28277
28277
  // implementations (e.g. core-js@2) don't set the correct internal slots.
28278
28278
  // Those polyfills don't allow us to subclass built-ins, so we need to
@@ -28282,14 +28282,14 @@ function _is_native_reflect_construct$1() {
28282
28282
  // TypeError: this is not a Boolean object.
28283
28283
  var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
28284
28284
  } catch (_) {}
28285
- return (_is_native_reflect_construct$1 = function _is_native_reflect_construct() {
28285
+ return (_is_native_reflect_construct = function _is_native_reflect_construct() {
28286
28286
  return !!result;
28287
28287
  })();
28288
28288
  }
28289
- function _construct$1(Parent, args, Class) {
28290
- if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
28289
+ function _construct(Parent, args, Class) {
28290
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
28291
28291
  else {
28292
- _construct$1 = function construct(Parent, args, Class) {
28292
+ _construct = function construct(Parent, args, Class) {
28293
28293
  var a = [
28294
28294
  null
28295
28295
  ];
@@ -28300,7 +28300,7 @@ function _construct$1(Parent, args, Class) {
28300
28300
  return instance;
28301
28301
  };
28302
28302
  }
28303
- return _construct$1.apply(null, arguments);
28303
+ return _construct.apply(null, arguments);
28304
28304
  }
28305
28305
  var ComponentCloner = /*#__PURE__*/ function() {
28306
28306
  function ComponentCloner() {}
@@ -28353,7 +28353,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
28353
28353
  args[_key - 1] = arguments[_key];
28354
28354
  }
28355
28355
  ComponentsDependencies._addCheck(this, type);
28356
- var component = _construct$1(type, [].concat([
28356
+ var component = _construct(type, [].concat([
28357
28357
  this
28358
28358
  ], args));
28359
28359
  this._components.push(component);
@@ -28512,7 +28512,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
28512
28512
  for(var i = 0, n = components.length; i < n; i++){
28513
28513
  componentConstructors[i] = components[i].constructor;
28514
28514
  }
28515
- var cloneEntity = _construct$1(Entity, [].concat([
28515
+ var cloneEntity = _construct(Entity, [].concat([
28516
28516
  this.engine,
28517
28517
  this.name
28518
28518
  ], componentConstructors));
@@ -39760,30 +39760,48 @@ __decorate$1([
39760
39760
  }
39761
39761
  this._emitBySubBurst(middleTime, playTime, duration);
39762
39762
  } else {
39763
- this._emitBySubBurst(lastPlayTime, playTime, duration);
39763
+ if (lastPlayTime < duration) {
39764
+ this._emitBySubBurst(lastPlayTime, Math.min(playTime, duration), duration);
39765
+ }
39764
39766
  }
39765
39767
  };
39766
39768
  _proto._emitBySubBurst = function _emitBySubBurst(lastPlayTime, playTime, duration) {
39767
- var generator = this._generator;
39768
- var rand = this._burstRand;
39769
- var bursts = this.bursts;
39770
- // Calculate the relative time of the burst
39769
+ var _this = this, generator = _this._generator, rand = _this._burstRand, bursts = _this.bursts;
39771
39770
  var baseTime = Math.floor(lastPlayTime / duration) * duration;
39772
39771
  var startTime = lastPlayTime % duration;
39773
39772
  var endTime = startTime + (playTime - lastPlayTime);
39773
+ var pendingIndex = -1;
39774
39774
  var index = this._currentBurstIndex;
39775
39775
  for(var n = bursts.length; index < n; index++){
39776
39776
  var burst = bursts[index];
39777
39777
  var burstTime = burst.time;
39778
- if (burstTime > endTime) {
39779
- break;
39780
- }
39781
- if (burstTime >= startTime) {
39782
- var count = burst.count.evaluate(undefined, rand.random());
39783
- generator._emit(baseTime + burstTime, count);
39778
+ if (burstTime >= endTime) break;
39779
+ var cycles = burst.cycles, repeatInterval = burst.repeatInterval;
39780
+ if (cycles === 1) {
39781
+ if (burstTime >= startTime) {
39782
+ generator._emit(baseTime + burstTime, burst.count.evaluate(undefined, rand.random()));
39783
+ }
39784
+ } else {
39785
+ var maxCycles = cycles === Infinity ? Math.ceil((duration - burstTime) / repeatInterval) : cycles;
39786
+ // Absorb float drift: (startTime - burstTime) / repeatInterval may land at cycle + 1e-15
39787
+ // when it should be exactly cycle, and ceil would then skip ahead to cycle + 1.
39788
+ var tolerance = MathUtil.zeroTolerance;
39789
+ var lastCycle = Math.ceil((endTime - burstTime) / repeatInterval - tolerance) - 1;
39790
+ var first = Math.max(0, Math.ceil((startTime - burstTime) / repeatInterval - tolerance));
39791
+ var last = Math.min(maxCycles - 1, lastCycle);
39792
+ for(var c = first; c <= last; c++){
39793
+ var effectiveTime = burstTime + c * repeatInterval;
39794
+ if (effectiveTime >= duration) break;
39795
+ generator._emit(baseTime + effectiveTime, burst.count.evaluate(undefined, rand.random()));
39796
+ }
39797
+ // `_currentBurstIndex` caches next frame's scan start, so only the earliest unfinished
39798
+ // burst can be the entry point — skipping past it would drop its remaining cycles
39799
+ if (pendingIndex < 0 && lastCycle < maxCycles - 1) {
39800
+ pendingIndex = index;
39801
+ }
39784
39802
  }
39785
39803
  }
39786
- this._currentBurstIndex = index;
39804
+ this._currentBurstIndex = pendingIndex >= 0 ? pendingIndex : index;
39787
39805
  };
39788
39806
  _create_class$2(EmissionModule, [
39789
39807
  {
@@ -42916,10 +42934,39 @@ __decorate$1([
42916
42934
  }(EffectMaterial);
42917
42935
  /**
42918
42936
  * A burst is a particle emission event, where a number of particles are all emitted at the same time
42919
- */ var Burst = function Burst(time, count) {
42920
- this.time = time;
42921
- this.count = count;
42922
- };
42937
+ */ var Burst = /*#__PURE__*/ function() {
42938
+ function Burst(time, count, cycles, repeatInterval) {
42939
+ this.time = time;
42940
+ this.count = count;
42941
+ this._cycles = Math.max(cycles != null ? cycles : 1, 1);
42942
+ this._repeatInterval = Math.max(repeatInterval != null ? repeatInterval : 0.01, 0.01);
42943
+ }
42944
+ _create_class$2(Burst, [
42945
+ {
42946
+ key: "cycles",
42947
+ get: /**
42948
+ * Number of times to repeat the burst.
42949
+ */ function get() {
42950
+ return this._cycles;
42951
+ },
42952
+ set: function set(value) {
42953
+ this._cycles = Math.max(value, 1);
42954
+ }
42955
+ },
42956
+ {
42957
+ key: "repeatInterval",
42958
+ get: /**
42959
+ * Time interval between each repeated burst.
42960
+ */ function get() {
42961
+ return this._repeatInterval;
42962
+ },
42963
+ set: function set(value) {
42964
+ this._repeatInterval = Math.max(value, 0.01);
42965
+ }
42966
+ }
42967
+ ]);
42968
+ return Burst;
42969
+ }();
42923
42970
  __decorate$1([
42924
42971
  deepClone
42925
42972
  ], Burst.prototype, "count", void 0);
@@ -48295,35 +48342,23 @@ function float32ArrayToVector2(float32Array, vertexCount) {
48295
48342
  }
48296
48343
  return array;
48297
48344
  }
48298
- function _is_native_reflect_construct() {
48299
- // Since Reflect.construct can't be properly polyfilled, some
48300
- // implementations (e.g. core-js@2) don't set the correct internal slots.
48301
- // Those polyfills don't allow us to subclass built-ins, so we need to
48302
- // use our fallback implementation.
48303
- try {
48304
- // If the internal slots aren't set, this throws an error similar to
48305
- // TypeError: this is not a Boolean object.
48306
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
48307
- } catch (_) {}
48308
- return (_is_native_reflect_construct = function _is_native_reflect_construct() {
48309
- return !!result;
48310
- })();
48345
+ function _object_without_properties_loose(source, excluded) {
48346
+ if (source == null) return {};
48347
+ var target = {};
48348
+ var sourceKeys = Object.keys(source);
48349
+ var key, i;
48350
+ for(i = 0; i < sourceKeys.length; i++){
48351
+ key = sourceKeys[i];
48352
+ if (excluded.indexOf(key) >= 0) continue;
48353
+ target[key] = source[key];
48354
+ }
48355
+ return target;
48311
48356
  }
48312
- function _construct(Parent, args, Class) {
48313
- if (_is_native_reflect_construct()) _construct = Reflect.construct;
48314
- else {
48315
- _construct = function construct(Parent, args, Class) {
48316
- var a = [
48317
- null
48318
- ];
48319
- a.push.apply(a, args);
48320
- var Constructor = Function.bind.apply(Parent, a);
48321
- var instance = new Constructor();
48322
- if (Class) _set_prototype_of(instance, Class.prototype);
48323
- return instance;
48324
- };
48357
+ function resolveRefItem(refs, index, owner, label) {
48358
+ if (!Number.isInteger(index) || index < 0 || index >= refs.length) {
48359
+ throw new Error(owner + ": invalid ref index " + index + " for " + label);
48325
48360
  }
48326
- return _construct.apply(null, arguments);
48361
+ return refs[index];
48327
48362
  }
48328
48363
  var ParserType = /*#__PURE__*/ function(ParserType) {
48329
48364
  ParserType[ParserType["Prefab"] = 0] = "Prefab";
@@ -48338,32 +48373,20 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
48338
48373
  this.engine = engine;
48339
48374
  this.type = type;
48340
48375
  this.resource = resource;
48341
- this.entityMap = new Map();
48342
- this.entityConfigMap = new Map();
48343
- this.components = new Map();
48344
- this.componentConfigMap = new Map();
48345
- this.rootIds = [];
48346
- this.strippedIds = [];
48347
- this._tasks = new Set();
48376
+ this./** Runtime Entity instances, indexed by the flat entities[] position. */ entityInstances = [];
48377
+ this./** Components waiting for props/calls application (Stage 4). */ pendingComponents = [];
48348
48378
  this._loaded = 0;
48349
48379
  this._total = 0;
48350
48380
  this.resourceManager = engine.resourceManager;
48351
48381
  }
48352
48382
  var _proto = ParserContext.prototype;
48353
48383
  _proto.clear = function clear() {
48354
- this.entityMap.clear();
48355
- this.components.clear();
48356
- this.componentConfigMap.clear();
48357
- this.entityConfigMap.clear();
48358
- this.rootIds.length = 0;
48359
- this.strippedIds.length = 0;
48360
- };
48361
- /** @internal */ _proto._addDependentAsset = function _addDependentAsset(url, promise) {
48384
+ this.entityInstances.length = 0;
48385
+ this.pendingComponents.length = 0;
48386
+ };
48387
+ /** @internal */ _proto._addDependentAsset = function _addDependentAsset(promise) {
48362
48388
  var _this = this;
48363
- var tasks = this._tasks;
48364
- if (tasks.has(url)) return;
48365
48389
  ++this._total;
48366
- tasks.add(url);
48367
48390
  promise.finally(function() {
48368
48391
  ++_this._loaded;
48369
48392
  _this._setTaskCompleteProgress(_this._loaded, _this._total);
@@ -48372,230 +48395,198 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
48372
48395
  return ParserContext;
48373
48396
  }();
48374
48397
  var ReflectionParser = /*#__PURE__*/ function() {
48375
- function ReflectionParser(_context) {
48398
+ function ReflectionParser(_context, _refs) {
48376
48399
  this._context = _context;
48400
+ this._refs = _refs;
48377
48401
  }
48378
48402
  var _proto = ReflectionParser.prototype;
48379
- _proto.parseEntity = function parseEntity(entityConfig) {
48380
- var _this = this;
48381
- return this._getEntityByConfig(entityConfig).then(function(entity) {
48382
- var _entityConfig_isActive;
48383
- entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : true;
48384
- var transform = entity.transform;
48385
- var transformConfig = entityConfig.transform;
48386
- if (transformConfig) {
48387
- _this.parsePropsAndMethods(transform, transformConfig);
48388
- } else {
48389
- var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
48390
- if (position) transform.position.copyFrom(position);
48391
- if (rotation) transform.rotation.copyFrom(rotation);
48392
- if (scale) transform.scale.copyFrom(scale);
48393
- }
48394
- var _entityConfig_layer;
48395
- entity.layer = (_entityConfig_layer = entityConfig.layer) != null ? _entityConfig_layer : entity.layer;
48396
- // @ts-ignore
48397
- _this._context.type === ParserType.Prefab && entity._markAsTemplate(_this._context.resource);
48398
- return entity;
48399
- });
48400
- };
48401
- _proto.parseClassObject = function parseClassObject(item) {
48402
- var _this = this;
48403
- var Class = Loader.getClass(item.class);
48404
- var _item_constructParams;
48405
- var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
48406
- return Promise.all(params.map(function(param) {
48407
- return _this.parseBasicType(param);
48408
- })).then(function(resultParams) {
48409
- return _construct(Class, [].concat(resultParams));
48410
- }).then(function(instance) {
48411
- return _this.parsePropsAndMethods(instance, item);
48412
- });
48413
- };
48414
- _proto.parsePropsAndMethods = function parsePropsAndMethods(instance, item) {
48403
+ /**
48404
+ * Apply v2 props to a component/object instance.
48405
+ * Each prop value is resolved recursively (handling $ref, $type, $entity, $component, $signal).
48406
+ */ _proto.parseProps = function parseProps(instance, props) {
48415
48407
  var promises = [];
48416
- if (item.methods) {
48417
- for(var methodName in item.methods){
48418
- var methodParams = item.methods[methodName];
48419
- for(var i = 0, count = methodParams.length; i < count; i++){
48420
- promises.push(this.parseMethod(instance, methodName, methodParams[i]));
48421
- }
48422
- }
48423
- }
48424
- if (item.props) {
48408
+ if (props) {
48425
48409
  var _this, _loop = function _loop(key) {
48426
- var value = item.props[key];
48427
- var promise = _this.parseBasicType(value, instance[key]).then(function(v) {
48428
- return instance[key] = v;
48410
+ var promise = _this._resolveValue(props[key], instance[key]).then(function(v) {
48411
+ instance[key] = v;
48429
48412
  });
48430
48413
  promises.push(promise);
48431
48414
  };
48432
- for(var key in item.props)_this = this, _loop(key);
48415
+ for(var key in props)_this = this, _loop(key);
48433
48416
  }
48434
48417
  return Promise.all(promises).then(function() {
48435
48418
  return instance;
48436
48419
  });
48437
48420
  };
48438
- _proto.parseMethod = function parseMethod(instance, methodName, methodParams) {
48421
+ /**
48422
+ * Execute calls sequentially on a target instance.
48423
+ * Call args are resolved with the same v2 value rules as props.
48424
+ */ _proto.parseCalls = function parseCalls(instance, calls) {
48425
+ var _loop = function _loop(i, n) {
48426
+ var call = calls[i];
48427
+ chain = chain.then(function() {
48428
+ var method = instance == null ? void 0 : instance[call.method];
48429
+ if (typeof method !== "function") {
48430
+ return Promise.reject(new Error('Call target does not have method "' + call.method + '"'));
48431
+ }
48432
+ var _call_args;
48433
+ return Promise.all(((_call_args = call.args) != null ? _call_args : []).map(function(arg) {
48434
+ return _this._resolveValue(arg);
48435
+ })).then(function(resolvedArgs) {
48436
+ return Promise.resolve(method.apply(instance, resolvedArgs));
48437
+ }).then(function(result) {
48438
+ if (!call.result) return result;
48439
+ if (result == null || (typeof result === "undefined" ? "undefined" : _type_of1(result)) !== "object" && typeof result !== "function") {
48440
+ return Promise.reject(new Error('Call "' + call.method + '" returned ' + result + " and cannot be mutated by result"));
48441
+ }
48442
+ return _this.parseMutationBlock(result, call.result);
48443
+ });
48444
+ });
48445
+ };
48439
48446
  var _this = this;
48440
- var isMethodObject = ReflectionParser._isMethodObject(methodParams);
48441
- var params = isMethodObject ? methodParams.params : methodParams;
48442
- return Promise.all(params.map(function(param) {
48443
- return _this.parseBasicType(param);
48444
- })).then(function(result) {
48445
- var _instance;
48446
- var methodResult = (_instance = instance)[methodName].apply(_instance, [].concat(result));
48447
- if (isMethodObject && methodParams.result) {
48448
- return _this.parsePropsAndMethods(methodResult, methodParams.result);
48449
- } else {
48450
- return methodResult;
48451
- }
48447
+ if (!(calls == null ? void 0 : calls.length)) return Promise.resolve(instance);
48448
+ var chain = Promise.resolve();
48449
+ for(var i = 0, n = calls.length; i < n; i++)_loop(i);
48450
+ return chain.then(function() {
48451
+ return instance;
48452
48452
  });
48453
48453
  };
48454
- _proto.parseSignal = function parseSignal(signalRef) {
48455
- var _this = this;
48456
- var signal = new Signal();
48457
- return Promise.all(signalRef.listeners.map(function(listener) {
48458
- return Promise.all([
48459
- _this.parseBasicType(listener.target),
48460
- listener.arguments ? Promise.all(listener.arguments.map(function(a) {
48461
- return _this.parseBasicType(a);
48462
- })) : Promise.resolve([])
48463
- ]).then(function(param) {
48464
- var target = param[0], resolvedArgs = param[1];
48465
- if (target) {
48466
- var _signal;
48467
- (_signal = signal).on.apply(_signal, [].concat([
48468
- target,
48469
- listener.methodName
48470
- ], resolvedArgs));
48471
- }
48472
- });
48473
- })).then(function() {
48474
- return signal;
48454
+ /**
48455
+ * Apply props and calls from the same mutation block without imposing ordering between them.
48456
+ */ _proto.parseMutationBlock = function parseMutationBlock(target, block) {
48457
+ if (!block) return Promise.resolve(target);
48458
+ return Promise.all([
48459
+ this.parseProps(target, block.props),
48460
+ this.parseCalls(target, block.calls)
48461
+ ]).then(function() {
48462
+ return target;
48475
48463
  });
48476
48464
  };
48477
- _proto.parseBasicType = function parseBasicType(value, originValue) {
48478
- var _this = this;
48479
- if (Array.isArray(value)) {
48480
- return Promise.all(value.map(function(item) {
48481
- return _this.parseBasicType(item);
48465
+ /**
48466
+ * Resolve a v2 value with $ prefix detection.
48467
+ *
48468
+ * Priority:
48469
+ * 1. null/undefined/primitive → passthrough
48470
+ * 2. Array → recurse each element
48471
+ * 3. { $ref } → asset reference
48472
+ * 4. { $type } → polymorphic type construct
48473
+ * 5. { $entity } → entity reference by path (flat index + optional children descent)
48474
+ * 6. { $component } → component reference
48475
+ * 7. { $signal } → signal binding
48476
+ * 8. plain object → recurse values (modify originValue in place if exists)
48477
+ */ _proto._resolveValue = function _resolveValue(value, originValue) {
48478
+ var _this, _loop = function _loop(key) {
48479
+ promises.push(_this._resolveValue(obj[key], target[key]).then(function(v) {
48480
+ return target[key] = v;
48482
48481
  }));
48483
- } else if ((typeof value === "undefined" ? "undefined" : _type_of1(value)) === "object" && value != null) {
48484
- if (ReflectionParser._isClassType(value)) {
48485
- return Promise.resolve(Loader.getClass(value["classType"]));
48486
- } else if (ReflectionParser._isClass(value)) {
48487
- // class object
48488
- return this.parseClassObject(value);
48489
- } else if (ReflectionParser._isAssetRef(value)) {
48490
- var _this1 = this, context = _this1._context;
48491
- // reference object
48492
- // @ts-ignore
48493
- return context.resourceManager.getResourceByRef(value).then(function(resource) {
48494
- if (resource && context.type === ParserType.Prefab) {
48495
- // @ts-ignore
48496
- context.resource._addDependenceAsset(resource);
48497
- }
48498
- return resource;
48499
- });
48500
- } else if (ReflectionParser._isComponentRef(value)) {
48501
- var entity = this._resolveEntityByPath(value.entityPath);
48502
- if (!entity) return Promise.resolve(null);
48503
- var type = Loader.getClass(value.componentType);
48504
- if (!type) return Promise.resolve(null);
48505
- var _entity_getComponents_value_componentIndex;
48506
- return Promise.resolve((_entity_getComponents_value_componentIndex = entity.getComponents(type, [])[value.componentIndex]) != null ? _entity_getComponents_value_componentIndex : null);
48507
- } else if (ReflectionParser._isEntityRef(value)) {
48508
- return Promise.resolve(this._resolveEntityByPath(value.entityPath));
48509
- } else if (ReflectionParser._isSignalRef(value)) {
48510
- return this.parseSignal(value);
48511
- } else if (originValue) {
48512
- var _this2, _loop = function _loop(key) {
48513
- if (key === "methods") {
48514
- var methods = value[key];
48515
- for(var methodName in methods){
48516
- var methodParams = methods[methodName];
48517
- for(var i = 0, count = methodParams.length; i < count; i++){
48518
- var params = methodParams[i];
48519
- var promise = _this2.parseMethod(originValue, methodName, params);
48520
- promises.push(promise);
48521
- }
48522
- }
48523
- } else {
48524
- promises.push(_this2.parseBasicType(value[key], originValue[key]).then(function(v) {
48525
- return originValue[key] = v;
48526
- }));
48527
- }
48528
- };
48529
- var promises = [];
48530
- for(var key in value)_this2 = this, _loop(key);
48531
- return Promise.all(promises).then(function() {
48532
- return originValue;
48533
- });
48482
+ };
48483
+ var _this1 = this;
48484
+ if (value == null || (typeof value === "undefined" ? "undefined" : _type_of1(value)) !== "object") return Promise.resolve(value);
48485
+ if (Array.isArray(value)) return Promise.all(value.map(function(v) {
48486
+ return _this1._resolveValue(v);
48487
+ }));
48488
+ var obj = value;
48489
+ // $ref asset reference (index into refs array)
48490
+ if ("$ref" in obj) {
48491
+ var _this2 = this, context = _this2._context;
48492
+ var refItem;
48493
+ try {
48494
+ refItem = resolveRefItem(this._refs, obj.$ref, "ReflectionParser", "$ref");
48495
+ } catch (error) {
48496
+ return Promise.reject(error);
48534
48497
  }
48535
- }
48536
- // primitive type
48537
- return Promise.resolve(value);
48538
- };
48539
- _proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
48540
- var _this = this;
48541
- // @ts-ignore
48542
- var assetUrl = entityConfig.assetUrl;
48543
- var engine = this._context.engine;
48544
- if (assetUrl) {
48545
- return engine.resourceManager // @ts-ignore
48546
- .getResourceByRef({
48547
- url: assetUrl,
48548
- key: entityConfig.key,
48549
- isClone: entityConfig.isClone
48550
- }).then(function(entity) {
48551
- // @ts-ignore
48552
- var resource = engine.resourceManager._objectPool[assetUrl];
48553
- if (resource && _this._context.type === ParserType.Prefab) {
48498
+ // @ts-ignore
48499
+ return context.resourceManager.getResourceByRef(refItem).then(function(resource) {
48500
+ if (resource && context.type === ParserType.Prefab) {
48554
48501
  // @ts-ignore
48555
- _this._context.resource._addDependenceAsset(resource);
48502
+ context.resource._addDependenceAsset(resource);
48556
48503
  }
48557
- entity.name = entityConfig.name;
48558
- return entity;
48504
+ return resource;
48559
48505
  });
48560
- } else {
48561
- var transform = entityConfig.transform;
48562
- var entity = new Entity(engine, entityConfig.name, transform ? Loader.getClass(transform.class) : Transform);
48563
- return Promise.resolve(entity);
48564
48506
  }
48565
- };
48566
- _proto._resolveEntityByPath = function _resolveEntityByPath(entityPath) {
48567
- var _this__context = this._context, rootIds = _this__context.rootIds, entityMap = _this__context.entityMap;
48568
- if (!entityPath.length || entityPath[0] >= rootIds.length) return null;
48569
- var entity = entityMap.get(rootIds[entityPath[0]]);
48570
- for(var i = 1; i < entityPath.length; i++){
48571
- if (!entity || entityPath[i] >= entity.children.length) return null;
48572
- entity = entity.children[entityPath[i]];
48507
+ // $type — polymorphic type: construct instance and apply remaining props
48508
+ if ("$type" in obj) {
48509
+ var $type = obj.$type, rest = _object_without_properties_loose(obj, [
48510
+ "$type"
48511
+ ]);
48512
+ var typeName = $type;
48513
+ var Class = Loader.getClass(typeName);
48514
+ if (!Class) return Promise.reject(new Error('Loader.getClass: class "' + typeName + '" is not registered'));
48515
+ var instance = new Class();
48516
+ if (Object.keys(rest).length > 0) {
48517
+ return this.parseProps(instance, rest);
48518
+ }
48519
+ return Promise.resolve(instance);
48573
48520
  }
48574
- return entity;
48575
- };
48576
- ReflectionParser._isClass = function _isClass(value) {
48577
- return value["class"] !== undefined;
48578
- };
48579
- ReflectionParser._isClassType = function _isClassType(value) {
48580
- return value["classType"] !== undefined;
48581
- };
48582
- ReflectionParser._isAssetRef = function _isAssetRef(value) {
48583
- return value["url"] !== undefined;
48584
- };
48585
- ReflectionParser._isEntityRef = function _isEntityRef(value) {
48586
- return Array.isArray(value["entityPath"]) && value["componentType"] === undefined;
48521
+ // $entity — entity reference by path (first element = flat index, subsequent = children indices)
48522
+ if ("$entity" in obj) {
48523
+ return Promise.resolve(this._resolveEntityRef(obj.$entity));
48524
+ }
48525
+ // $component — component reference: { entity, type, index }
48526
+ if ("$component" in obj) {
48527
+ return Promise.resolve(this._resolveComponent(obj.$component));
48528
+ }
48529
+ // $signal signal binding: register listeners on the existing Signal instance
48530
+ if ("$signal" in obj) {
48531
+ return this._resolveSignal(originValue, obj.$signal);
48532
+ }
48533
+ // Plain object — recurse each value, modifying originValue in place or building a new object
48534
+ var target = originValue && (typeof originValue === "undefined" ? "undefined" : _type_of1(originValue)) === "object" && !Array.isArray(originValue) ? originValue : {};
48535
+ var promises = [];
48536
+ for(var key in obj)_this = this, _loop(key);
48537
+ return Promise.all(promises).then(function() {
48538
+ return target;
48539
+ });
48587
48540
  };
48588
- ReflectionParser._isComponentRef = function _isComponentRef(value) {
48589
- return Array.isArray(value["entityPath"]) && value["componentType"] !== undefined;
48541
+ _proto._resolveSignal = function _resolveSignal(signal, listeners) {
48542
+ var _this = this;
48543
+ if (!signal || typeof signal.on !== "function") {
48544
+ return Promise.reject(new Error("$signal requires a pre-initialized Signal instance on the target property"));
48545
+ }
48546
+ var promises = listeners.map(function(listener) {
48547
+ var targetComponent = _this._resolveComponent(listener.target.$component);
48548
+ if (!targetComponent) return Promise.resolve();
48549
+ var _listener_args;
48550
+ return Promise.all(((_listener_args = listener.args) != null ? _listener_args : []).map(function(a) {
48551
+ return _this._resolveValue(a);
48552
+ })).then(function(resolvedArgs) {
48553
+ var _signal;
48554
+ (_signal = signal).on.apply(_signal, [].concat([
48555
+ targetComponent,
48556
+ listener.methodName
48557
+ ], resolvedArgs));
48558
+ });
48559
+ });
48560
+ return Promise.all(promises).then(function() {
48561
+ return signal;
48562
+ });
48590
48563
  };
48591
- ReflectionParser._isSignalRef = function _isSignalRef(value) {
48592
- return value["listeners"] !== undefined;
48564
+ _proto._resolveComponent = function _resolveComponent(comp) {
48565
+ var entity = this._resolveEntityRef(comp.entity);
48566
+ if (!entity) return null;
48567
+ var type = Loader.getClass(comp.type);
48568
+ if (!type) return null;
48569
+ var buffer = ReflectionParser._componentBuffer;
48570
+ buffer.length = 0;
48571
+ entity.getComponents(type, buffer);
48572
+ var _buffer_comp_index;
48573
+ var result = (_buffer_comp_index = buffer[comp.index]) != null ? _buffer_comp_index : null;
48574
+ buffer.length = 0;
48575
+ return result;
48593
48576
  };
48594
- ReflectionParser._isMethodObject = function _isMethodObject(value) {
48595
- return Array.isArray(value == null ? void 0 : value.params);
48577
+ _proto._resolveEntityRef = function _resolveEntityRef(path) {
48578
+ if (!path || path.length === 0) return null;
48579
+ var _this__context_entityInstances_path_;
48580
+ var entity = (_this__context_entityInstances_path_ = this._context.entityInstances[path[0]]) != null ? _this__context_entityInstances_path_ : null;
48581
+ for(var i = 1, n = path.length; entity && i < n; i++){
48582
+ var _entity_children_path_i;
48583
+ entity = (_entity_children_path_i = entity.children[path[i]]) != null ? _entity_children_path_i : null;
48584
+ }
48585
+ return entity;
48596
48586
  };
48597
48587
  return ReflectionParser;
48598
48588
  }();
48589
+ /** @internal shared with HierarchyParser; each use must length=0 -> getComponents -> read -> length=0 synchronously. */ ReflectionParser._componentBuffer = [];
48599
48590
  /**
48600
48591
  * HDR (Radiance RGBE) image decoder.
48601
48592
  *
@@ -48892,38 +48883,6 @@ function _instanceof1(left, right) {
48892
48883
  return !!right[Symbol.hasInstance](left);
48893
48884
  } else return _instanceof(left, right);
48894
48885
  }
48895
- function _array_like_to_array(arr, len) {
48896
- if (len == null || len > arr.length) len = arr.length;
48897
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
48898
- return arr2;
48899
- }
48900
- function _unsupported_iterable_to_array(o, minLen) {
48901
- if (!o) return;
48902
- if (typeof o === "string") return _array_like_to_array(o, minLen);
48903
- var n = Object.prototype.toString.call(o).slice(8, -1);
48904
- if (n === "Object" && o.constructor) n = o.constructor.name;
48905
- if (n === "Map" || n === "Set") return Array.from(n);
48906
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
48907
- }
48908
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
48909
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
48910
- if (it) return (it = it.call(o)).next.bind(it);
48911
- // Fallback for engines without symbol support
48912
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
48913
- if (it) o = it;
48914
- var i = 0;
48915
- return function() {
48916
- if (i >= o.length) return {
48917
- done: true
48918
- };
48919
- return {
48920
- done: false,
48921
- value: o[i++]
48922
- };
48923
- };
48924
- }
48925
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
48926
- }
48927
48886
  /**
48928
48887
  * The Prefab resource.
48929
48888
  */ var PrefabResource = /*#__PURE__*/ function(ReferResource1) {
@@ -48955,8 +48914,9 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
48955
48914
  };
48956
48915
  _proto._onDestroy = function _onDestroy() {
48957
48916
  var _this = this;
48917
+ var _this__root;
48958
48918
  ReferResource1.prototype._onDestroy.call(this);
48959
- this._root.destroy();
48919
+ (_this__root = this._root) == null ? void 0 : _this__root.destroy();
48960
48920
  this._dependenceAssets.forEach(function(asset) {
48961
48921
  if (_instanceof1(asset, ReferResource)) {
48962
48922
  // @ts-ignore
@@ -48971,316 +48931,259 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
48971
48931
  var _this = this;
48972
48932
  this.data = data;
48973
48933
  this.context = context;
48974
- this._prefabContextMap = new WeakMap();
48975
- this._prefabPromiseMap = new Map();
48934
+ if (data.version !== "2.0") {
48935
+ var resourceType = context.type === ParserType.Scene ? "scene" : "prefab";
48936
+ throw new Error("Unsupported " + resourceType + ' format version "' + data.version + '". Expected "2.0".');
48937
+ }
48976
48938
  this._engine = this.context.engine;
48977
- this._organizeEntities = this._organizeEntities.bind(this);
48978
- this._parseComponents = this._parseComponents.bind(this);
48979
- this._parsePrefabModification = this._parsePrefabModification.bind(this);
48980
- this._parseAddedComponents = this._parseAddedComponents.bind(this);
48981
- this._parseComponentsPropsAndMethods = this._parseComponentsPropsAndMethods.bind(this);
48982
- this._parsePrefabRemovedEntities = this._parsePrefabRemovedEntities.bind(this);
48983
- this._parsePrefabRemovedComponents = this._parsePrefabRemovedComponents.bind(this);
48984
- this._clearAndResolve = this._clearAndResolve.bind(this);
48985
48939
  this.promise = new Promise(function(resolve, reject) {
48986
48940
  _this._reject = reject;
48987
48941
  _this._resolve = resolve;
48988
48942
  });
48989
- this._reflectionParser = new ReflectionParser(context);
48943
+ this._reflectionParser = new ReflectionParser(context, data.refs);
48990
48944
  }
48991
48945
  var _proto = HierarchyParser.prototype;
48992
- /** start parse the scene or prefab or others */ _proto.start = function start() {
48993
- this._parseEntities().then(this._organizeEntities).then(this._parseComponents).then(this._parseAddedComponents).then(this._parseComponentsPropsAndMethods).then(this._parsePrefabModification).then(this._parsePrefabRemovedEntities).then(this._parsePrefabRemovedComponents).then(this._clearAndResolve).then(this._resolve).catch(this._reject);
48994
- };
48995
- _proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
48996
- if (entityConfig === void 0) entityConfig = {};
48997
- var _entityConfig_isActive;
48998
- entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
48999
- var _entityConfig_name;
49000
- entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
49001
- var transform = entity.transform;
49002
- var transformConfig = entityConfig.transform;
49003
- if (transformConfig) {
49004
- this._reflectionParser.parsePropsAndMethods(transform, transformConfig);
49005
- } else {
49006
- var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
49007
- if (position) transform.position.copyFrom(position);
49008
- if (rotation) transform.rotation.copyFrom(rotation);
49009
- if (scale) transform.scale.copyFrom(scale);
49010
- }
49011
- if (entityConfig.layer) entity.layer = entityConfig.layer;
49012
- return entity;
49013
- };
49014
- _proto._parseEntities = function _parseEntities() {
48946
+ _proto.start = function start() {
49015
48947
  var _this = this;
49016
- var entitiesConfig = this.data.entities;
49017
- var entityConfigMap = this.context.entityConfigMap;
49018
- var entityMap = this.context.entityMap;
49019
- var engine = this._engine;
49020
- var promises = entitiesConfig.map(function(entityConfig) {
49021
- var _entityConfig_strippedId;
49022
- var id = (_entityConfig_strippedId = entityConfig.strippedId) != null ? _entityConfig_strippedId : entityConfig.id;
49023
- entityConfig.id = id;
49024
- entityConfigMap.set(id, entityConfig);
49025
- return _this._getEntityByConfig(entityConfig, engine);
49026
- });
49027
- return Promise.all(promises).then(function(entities) {
49028
- for(var i = 0, l = entities.length; i < l; i++){
49029
- entityMap.set(entitiesConfig[i].id, entities[i]);
49030
- }
49031
- // Build rootIds in serialization order (not async completion order)
49032
- var rootIds = _this.context.rootIds;
49033
- for(var i1 = 0, l1 = entitiesConfig.length; i1 < l1; i1++){
49034
- if (!entitiesConfig[i1].parent && !entitiesConfig[i1].strippedId) {
49035
- rootIds.push(entitiesConfig[i1].id);
49036
- }
49037
- }
49038
- return entities;
49039
- });
49040
- };
49041
- _proto._parseComponents = function _parseComponents() {
49042
- var entitiesConfig = this.data.entities;
49043
- var entityMap = this.context.entityMap;
49044
- for(var i = 0, l = entitiesConfig.length; i < l; i++){
49045
- var entityConfig = entitiesConfig[i];
49046
- if (entityConfig.strippedId) {
49047
- continue;
49048
- }
49049
- var entity = entityMap.get(entityConfig.id);
49050
- this._addComponents(entity, entityConfig.components);
49051
- }
49052
- };
49053
- _proto._parsePrefabModification = function _parsePrefabModification() {
49054
- var _loop = function _loop(i, l) {
49055
- var entityConfig = entitiesConfig[i];
49056
- var id = entityConfig.id, modifications = entityConfig.modifications;
49057
- if (modifications == null ? void 0 : modifications.length) {
49058
- var _promises;
49059
- var rootEntity = entityMap.get(id);
49060
- (_promises = promises).push.apply(_promises, [].concat(modifications.map(function(modification) {
49061
- var target = modification.target, props = modification.props, methods = modification.methods;
49062
- var entityId = target.entityId, componentId = target.componentId;
49063
- var context = _this._prefabContextMap.get(rootEntity);
49064
- var targetEntity = context.entityMap.get(entityId);
49065
- var targetComponent = context.components.get(componentId);
49066
- if (targetComponent) {
49067
- return _this._reflectionParser.parsePropsAndMethods(targetComponent, {
49068
- props: props,
49069
- methods: methods
49070
- });
49071
- } else if (targetEntity) {
49072
- return Promise.resolve(_this._applyEntityData(targetEntity, props));
49073
- }
49074
- })));
48948
+ this._parseEntities().then(function() {
48949
+ return _this._organizeEntities();
48950
+ }).then(function() {
48951
+ return _this._parseComponents();
48952
+ }).then(function() {
48953
+ return _this._parseComponentsPropsAndCalls();
48954
+ }).then(function() {
48955
+ return _this._parsePrefabOverrides();
48956
+ }).then(function() {
48957
+ return _this._clearAndResolve();
48958
+ }).then(this._resolve).catch(this._reject);
48959
+ };
48960
+ _proto._onEntityCreated = function _onEntityCreated(_entity) {};
48961
+ // ---------------------------------------------------------------------------
48962
+ // Stage 1: Create entity instances
48963
+ // ---------------------------------------------------------------------------
48964
+ _proto._parseEntities = function _parseEntities() {
48965
+ var _this, _loop = function _loop(i, n) {
48966
+ var entityConfig = entities[i];
48967
+ if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) {
48968
+ promises.push(_this._loadPrefabInstance(entityConfig, engine).then(function(entity) {
48969
+ entityInstances[i] = entity;
48970
+ }));
48971
+ } else {
48972
+ var entity = new Entity(engine, entityConfig.name);
48973
+ HierarchyParser._applyEntityProps(entity, entityConfig);
48974
+ _this._onEntityCreated(entity);
48975
+ entityInstances[i] = entity;
49075
48976
  }
49076
48977
  };
49077
- var _this = this;
49078
- var entitiesConfig = this.data.entities;
49079
- var entityMap = this.context.entityMap;
48978
+ var entities = this.data.entities;
48979
+ var entityInstances = this.context.entityInstances;
48980
+ var engine = this._engine;
49080
48981
  var promises = [];
49081
- for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
48982
+ for(var i = 0, n = entities.length; i < n; i++)_this = this, _loop(i);
49082
48983
  return Promise.all(promises);
49083
48984
  };
49084
- _proto._parseAddedComponents = function _parseAddedComponents() {
49085
- var entityMap = this.context.entityMap;
49086
- var entityConfigMap = this.context.entityConfigMap;
49087
- var strippedIds = this.context.strippedIds;
49088
- for(var i = 0, n = strippedIds.length; i < n; i++){
49089
- var entityConfig = entityConfigMap.get(strippedIds[i]);
49090
- var prefabContext = this._prefabContextMap.get(entityMap.get(entityConfig.prefabInstanceId));
49091
- var entity = prefabContext.entityMap.get(entityConfig.prefabSource.entityId);
49092
- this._addComponents(entity, entityConfig.components);
49093
- }
49094
- };
49095
- _proto._parsePrefabRemovedEntities = function _parsePrefabRemovedEntities() {
49096
- var entitiesConfig = this.data.entities;
49097
- var entityMap = this.context.entityMap;
49098
- for(var i = 0, l = entitiesConfig.length; i < l; i++){
49099
- var entityConfig = entitiesConfig[i];
49100
- var id = entityConfig.id, removedEntities = entityConfig.removedEntities;
49101
- if (removedEntities == null ? void 0 : removedEntities.length) {
49102
- var rootEntity = entityMap.get(id);
49103
- for(var j = 0, m = removedEntities.length; j < m; j++){
49104
- var target = removedEntities[j];
49105
- var entityId = target.entityId;
49106
- var context = this._prefabContextMap.get(rootEntity);
49107
- var targetEntity = context.entityMap.get(entityId);
49108
- if (targetEntity) {
49109
- targetEntity.destroy();
49110
- }
49111
- }
48985
+ // ---------------------------------------------------------------------------
48986
+ // Stage 2: Build parent-child hierarchy
48987
+ // ---------------------------------------------------------------------------
48988
+ _proto._organizeEntities = function _organizeEntities() {
48989
+ var entities = this.data.entities;
48990
+ var entityInstances = this.context.entityInstances;
48991
+ for(var i = 0, n = entities.length; i < n; i++){
48992
+ var entityConfig = entities[i];
48993
+ // Prefab instance entities manage their own children.
48994
+ if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
48995
+ var children = entityConfig.children;
48996
+ if (!children) continue;
48997
+ var parent = entityInstances[i];
48998
+ for(var j = 0, m = children.length; j < m; j++){
48999
+ parent.addChild(entityInstances[children[j]]);
49112
49000
  }
49113
49001
  }
49002
+ var rootIndices = this._getRootIndices();
49003
+ for(var i1 = 0, n1 = rootIndices.length; i1 < n1; i1++){
49004
+ this._handleRootEntity(rootIndices[i1]);
49005
+ }
49114
49006
  };
49115
- _proto._parsePrefabRemovedComponents = function _parsePrefabRemovedComponents() {
49116
- var entitiesConfig = this.data.entities;
49117
- var entityMap = this.context.entityMap;
49118
- var prefabContextMap = this._prefabContextMap;
49119
- for(var i = 0, l = entitiesConfig.length; i < l; i++){
49120
- var entityConfig = entitiesConfig[i];
49121
- var id = entityConfig.id, removedComponents = entityConfig.removedComponents;
49122
- if (removedComponents == null ? void 0 : removedComponents.length) {
49123
- var rootEntity = entityMap.get(id);
49124
- for(var j = 0, m = removedComponents.length; j < m; j++){
49125
- var target = removedComponents[j];
49126
- var componentId = target.componentId;
49127
- var context = prefabContextMap.get(rootEntity);
49128
- var targetComponent = context.components.get(componentId);
49129
- if (targetComponent) {
49130
- targetComponent.destroy();
49131
- }
49132
- }
49007
+ // ---------------------------------------------------------------------------
49008
+ // Stage 3: Add components to entities
49009
+ // ---------------------------------------------------------------------------
49010
+ _proto._parseComponents = function _parseComponents() {
49011
+ var entities = this.data.entities;
49012
+ var allComponents = this.data.components;
49013
+ var entityInstances = this.context.entityInstances;
49014
+ var pendingComponents = this.context.pendingComponents;
49015
+ var refs = this.data.refs;
49016
+ for(var i = 0, n = entities.length; i < n; i++){
49017
+ var entityConfig = entities[i];
49018
+ if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
49019
+ var entity = entityInstances[i];
49020
+ var componentIndices = entityConfig.components;
49021
+ if (!componentIndices) continue;
49022
+ for(var j = 0, m = componentIndices.length; j < m; j++){
49023
+ var config = allComponents[componentIndices[j]];
49024
+ var instance = HierarchyParser._addComponentFromConfig(entity, config, refs);
49025
+ pendingComponents.push({
49026
+ instance: instance,
49027
+ config: config
49028
+ });
49133
49029
  }
49134
49030
  }
49135
49031
  };
49136
- _proto._organizeEntities = function _organizeEntities() {
49137
- var _this_context = this.context, rootIds = _this_context.rootIds, strippedIds = _this_context.strippedIds;
49138
- var parentIds = rootIds.concat(strippedIds);
49139
- for(var i = 0, l = parentIds.length; i < l; i++){
49140
- this._parseChildren(parentIds[i]);
49141
- }
49142
- for(var i1 = 0; i1 < rootIds.length; i1++){
49143
- this._handleRootEntity(rootIds[i1]);
49032
+ // ---------------------------------------------------------------------------
49033
+ // Stage 4: Apply props and execute calls on components
49034
+ // ---------------------------------------------------------------------------
49035
+ _proto._parseComponentsPropsAndCalls = function _parseComponentsPropsAndCalls() {
49036
+ var pendingComponents = this.context.pendingComponents;
49037
+ var reflectionParser = this._reflectionParser;
49038
+ var promises = [];
49039
+ for(var i = 0, n = pendingComponents.length; i < n; i++){
49040
+ var _pendingComponents_i = pendingComponents[i], instance = _pendingComponents_i.instance, config = _pendingComponents_i.config;
49041
+ promises.push(reflectionParser.parseMutationBlock(instance, config));
49144
49042
  }
49043
+ return Promise.all(promises);
49145
49044
  };
49146
- _proto._getEntityByConfig = function _getEntityByConfig(entityConfig, engine) {
49147
- var _this = this;
49148
- var entityPromise;
49149
- if (entityConfig.assetUrl) {
49150
- entityPromise = this._parsePrefab(entityConfig, engine);
49151
- } else if (entityConfig.strippedId) {
49152
- entityPromise = this._parseStrippedEntity(entityConfig);
49153
- } else {
49154
- entityPromise = this._parseEntity(entityConfig, engine);
49045
+ // ---------------------------------------------------------------------------
49046
+ // Stage 5: Apply prefab instance overrides
49047
+ // ---------------------------------------------------------------------------
49048
+ _proto._parsePrefabOverrides = function _parsePrefabOverrides() {
49049
+ var entities = this.data.entities;
49050
+ var entityInstances = this.context.entityInstances;
49051
+ var promises = [];
49052
+ for(var i = 0, n = entities.length; i < n; i++){
49053
+ var entityConfig = entities[i];
49054
+ if (!HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
49055
+ var overrides = entityConfig.instance.overrides;
49056
+ if (!overrides) continue;
49057
+ this._applyOverrides(entityInstances[i], overrides, promises);
49155
49058
  }
49156
- return entityPromise.then(function(entity) {
49157
- return _this._applyEntityData(entity, entityConfig);
49158
- });
49059
+ return Promise.all(promises);
49159
49060
  };
49160
- _proto._parseEntity = function _parseEntity(entityConfig, engine) {
49161
- var transform = entityConfig.transform;
49162
- var entity = new Entity(engine, entityConfig.name, transform ? Loader.getClass(transform.class) : Transform);
49163
- this._addEntityPlugin(entityConfig.id, entity);
49164
- return Promise.resolve(entity);
49061
+ _proto._applyOverrides = function _applyOverrides(rootEntity, overrides, promises) {
49062
+ var refs = this.data.refs;
49063
+ var reflectionParser = this._reflectionParser;
49064
+ // entityProps — entity-level property overrides
49065
+ if (overrides.entityProps) {
49066
+ for(var j = 0, m = overrides.entityProps.length; j < m; j++){
49067
+ var override = overrides.entityProps[j];
49068
+ HierarchyParser._applyEntityProps(HierarchyParser._resolveEntity(rootEntity, override.path), override);
49069
+ }
49070
+ }
49071
+ // componentProps — component-level property overrides
49072
+ if (overrides.componentProps) {
49073
+ for(var j1 = 0, m1 = overrides.componentProps.length; j1 < m1; j1++){
49074
+ var override1 = overrides.componentProps[j1];
49075
+ var entity = HierarchyParser._resolveEntity(rootEntity, override1.path);
49076
+ var target = HierarchyParser._resolveComponent(entity, override1.selector);
49077
+ promises.push(reflectionParser.parseMutationBlock(target, override1));
49078
+ }
49079
+ }
49080
+ // addedComponents — attach top-level components[index] to a prefab entity and parse props
49081
+ if (overrides.addedComponents) {
49082
+ var allComponents = this.data.components;
49083
+ for(var j2 = 0, m2 = overrides.addedComponents.length; j2 < m2; j2++){
49084
+ var added = overrides.addedComponents[j2];
49085
+ var entity1 = HierarchyParser._resolveEntity(rootEntity, added.target);
49086
+ var config = allComponents[added.component];
49087
+ var component = HierarchyParser._addComponentFromConfig(entity1, config, refs);
49088
+ promises.push(reflectionParser.parseMutationBlock(component, config));
49089
+ }
49090
+ }
49091
+ // addedEntities — attach already-created top-level entityInstances[index] as a child
49092
+ if (overrides.addedEntities) {
49093
+ var entityInstances = this.context.entityInstances;
49094
+ for(var j3 = 0, m3 = overrides.addedEntities.length; j3 < m3; j3++){
49095
+ var added1 = overrides.addedEntities[j3];
49096
+ var parent = HierarchyParser._resolveEntity(rootEntity, added1.parent);
49097
+ parent.addChild(entityInstances[added1.entity]);
49098
+ }
49099
+ }
49100
+ // removedEntities — pre-resolve all targets then destroy (destroy shifts sibling indices)
49101
+ if (overrides.removedEntities) {
49102
+ var removed = overrides.removedEntities;
49103
+ var targets = new Array(removed.length);
49104
+ for(var j4 = 0, m4 = removed.length; j4 < m4; j4++){
49105
+ targets[j4] = HierarchyParser._resolveEntity(rootEntity, removed[j4]);
49106
+ }
49107
+ for(var j5 = 0, m5 = targets.length; j5 < m5; j5++){
49108
+ targets[j5].destroy();
49109
+ }
49110
+ }
49111
+ // removedComponents — pre-resolve all targets then destroy (destroy shifts component indices)
49112
+ if (overrides.removedComponents) {
49113
+ var targets1 = [];
49114
+ for(var j6 = 0, m6 = overrides.removedComponents.length; j6 < m6; j6++){
49115
+ var override2 = overrides.removedComponents[j6];
49116
+ var entity2 = HierarchyParser._resolveEntity(rootEntity, override2.path);
49117
+ var selectors = override2.selectors;
49118
+ for(var k = 0, p = selectors.length; k < p; k++){
49119
+ targets1.push(HierarchyParser._resolveComponent(entity2, selectors[k]));
49120
+ }
49121
+ }
49122
+ for(var j7 = 0, m7 = targets1.length; j7 < m7; j7++){
49123
+ targets1[j7].destroy();
49124
+ }
49125
+ }
49165
49126
  };
49166
- _proto._parsePrefab = function _parsePrefab(entityConfig, engine) {
49127
+ // ---------------------------------------------------------------------------
49128
+ // Prefab instance loading
49129
+ // ---------------------------------------------------------------------------
49130
+ _proto._loadPrefabInstance = function _loadPrefabInstance(entityConfig, engine) {
49167
49131
  var _this = this;
49168
- var assetUrl = entityConfig.assetUrl;
49132
+ var instance = entityConfig.instance;
49133
+ var refItem;
49134
+ try {
49135
+ refItem = resolveRefItem(this.data.refs, instance.asset, "HierarchyParser", "instance.asset");
49136
+ } catch (error) {
49137
+ return Promise.reject(error);
49138
+ }
49169
49139
  return engine.resourceManager // @ts-ignore
49170
- .getResourceByRef({
49171
- url: assetUrl
49172
- }).then(function(prefabResource) {
49140
+ .getResourceByRef(refItem).then(function(prefabResource) {
49173
49141
  var entity = _instanceof1(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
49174
- var instanceContext = new ParserContext(engine, ParserType.Prefab, null);
49175
- _this._generateInstanceContext(entity, instanceContext, "");
49176
- _this._prefabContextMap.set(entity, instanceContext);
49177
- var cbArray = _this._prefabPromiseMap.get(entityConfig.id);
49178
- if (cbArray) {
49179
- for(var i = 0, n = cbArray.length; i < n; i++){
49180
- cbArray[i].resolve(instanceContext);
49181
- }
49182
- }
49142
+ _this._onEntityCreated(entity);
49183
49143
  return entity;
49184
49144
  });
49185
49145
  };
49186
- _proto._parseStrippedEntity = function _parseStrippedEntity(entityConfig) {
49187
- var _this = this;
49188
- this.context.strippedIds.push(entityConfig.id);
49189
- return new Promise(function(resolve, reject) {
49190
- var _this__prefabPromiseMap_get;
49191
- var cbArray = (_this__prefabPromiseMap_get = _this._prefabPromiseMap.get(entityConfig.prefabInstanceId)) != null ? _this__prefabPromiseMap_get : [];
49192
- cbArray.push({
49193
- resolve: resolve,
49194
- reject: reject
49195
- });
49196
- _this._prefabPromiseMap.set(entityConfig.prefabInstanceId, cbArray);
49197
- }).then(function(context) {
49198
- var entityId = entityConfig.prefabSource.entityId;
49199
- return context.entityMap.get(entityId);
49200
- });
49201
- };
49202
- _proto._parseChildren = function _parseChildren(parentId) {
49203
- var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap;
49204
- var children = entityConfigMap.get(parentId).children;
49205
- if (children && children.length > 0) {
49206
- var parent = entityMap.get(parentId);
49207
- for(var i = 0; i < children.length; i++){
49208
- var childId = children[i];
49209
- var entity = entityMap.get(childId);
49210
- parent.addChild(entity);
49211
- this._parseChildren(childId);
49212
- }
49146
+ // ---------------------------------------------------------------------------
49147
+ // Utilities
49148
+ // ---------------------------------------------------------------------------
49149
+ /** Resolve an entity inside a prefab instance by walking the child-index path from root */ HierarchyParser._resolveEntity = function _resolveEntity(root, path) {
49150
+ var entity = root;
49151
+ for(var i = 0, n = path.length; i < n; i++){
49152
+ entity = entity.children[path[i]];
49153
+ if (!entity) throw new Error("HierarchyParser: override target entity not found at path [" + path + "], failed at depth " + i);
49213
49154
  }
49155
+ return entity;
49214
49156
  };
49215
- _proto._addComponents = function _addComponents(entity, components) {
49216
- var context = this.context;
49217
- var componentMap = context.components;
49218
- var componentConfigMap = context.componentConfigMap;
49219
- for(var i = 0, n = components.length; i < n; i++){
49220
- var componentConfig = components[i];
49221
- var key = !componentConfig.url ? componentConfig.class : componentConfig.url;
49222
- var componentId = componentConfig.id;
49223
- var component = entity.addComponent(Loader.getClass(key));
49224
- componentMap.set(componentId, component);
49225
- componentConfigMap.set(componentId, componentConfig);
49226
- this._addComponentPlugin(componentId, component);
49227
- }
49228
- };
49229
- _proto._generateInstanceContext = function _generateInstanceContext(entity, context, path) {
49230
- var entityMap = context.entityMap, components = context.components;
49231
- var componentsMap = {};
49232
- var componentIndexMap = {};
49233
- entityMap.set(path, entity);
49234
- // @ts-ignore
49235
- entity._components.forEach(function(component) {
49236
- // @ts-ignore
49237
- var name = Loader.getClassName(component.constructor);
49238
- if (!componentsMap[name]) {
49239
- componentsMap[name] = entity.getComponents(component.constructor, []);
49240
- componentIndexMap[name] = 0;
49241
- }
49242
- components.set(path + ":" + name + "/" + componentIndexMap[name]++, component);
49243
- });
49244
- for(var i = 0, n = entity.children.length; i < n; i++){
49245
- var child = entity.children[i];
49246
- var childPath = path ? path + "/" + i : "" + i;
49247
- this._generateInstanceContext(child, context, childPath);
49248
- }
49157
+ /** Resolve a component on an entity by type name + per-type index */ HierarchyParser._resolveComponent = function _resolveComponent(entity, selector) {
49158
+ var type = Loader.getClass(selector.type);
49159
+ if (!type) throw new Error('HierarchyParser: override target component type "' + selector.type + '" is not registered');
49160
+ var buffer = ReflectionParser._componentBuffer;
49161
+ buffer.length = 0;
49162
+ entity.getComponents(type, buffer);
49163
+ var result = buffer[selector.index];
49164
+ buffer.length = 0;
49165
+ if (!result) throw new Error("HierarchyParser: override target component not found: " + selector.type + "/" + selector.index);
49166
+ return result;
49249
49167
  };
49250
- _proto._parseComponentsPropsAndMethods = function _parseComponentsPropsAndMethods() {
49251
- var context = this.context;
49252
- var componentConfigMap = context.componentConfigMap;
49253
- var reflectionParser = this._reflectionParser;
49254
- var promises = [];
49255
- for(var _iterator = _create_for_of_iterator_helper_loose(context.components), _step; !(_step = _iterator()).done;){
49256
- var _step_value = _step.value, componentId = _step_value[0], component = _step_value[1];
49257
- var componentConfig = componentConfigMap.get(componentId);
49258
- if (componentConfig) {
49259
- promises.push(reflectionParser.parsePropsAndMethods(component, componentConfig));
49260
- }
49261
- }
49262
- return Promise.all(promises);
49168
+ /** Resolve component class from config and add to entity. Throws if class is not registered. */ HierarchyParser._addComponentFromConfig = function _addComponentFromConfig(entity, config, refs) {
49169
+ var key = config.script != null ? resolveRefItem(refs, config.script, "HierarchyParser", "component.script").url : config.type;
49170
+ var Class = Loader.getClass(key);
49171
+ if (!Class) throw new Error('Loader.getClass: class "' + key + '" is not registered');
49172
+ return entity.addComponent(Class);
49173
+ };
49174
+ HierarchyParser._isPrefabInstanceEntity = function _isPrefabInstanceEntity(entityConfig) {
49175
+ return "instance" in entityConfig;
49176
+ };
49177
+ /** Apply entity-level props (name, isActive, layer, transform) to an entity. */ HierarchyParser._applyEntityProps = function _applyEntityProps(entity, props) {
49178
+ if (props.name != null) entity.name = props.name;
49179
+ if (props.isActive != null) entity.isActive = props.isActive;
49180
+ if (props.layer != null) entity.layer = props.layer;
49181
+ if (props.position) entity.transform.position.set(props.position[0], props.position[1], props.position[2]);
49182
+ if (props.rotation) entity.transform.rotation.set(props.rotation[0], props.rotation[1], props.rotation[2]);
49183
+ if (props.scale) entity.transform.scale.set(props.scale[0], props.scale[1], props.scale[2]);
49263
49184
  };
49264
- _proto._addComponentPlugin = function _addComponentPlugin(componentId, component) {};
49265
- _proto._addEntityPlugin = function _addEntityPlugin(entityId, entity) {};
49266
49185
  return HierarchyParser;
49267
49186
  }();
49268
- var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
49269
- MaterialLoaderType["Vector2"] = "Vector2";
49270
- MaterialLoaderType["Vector3"] = "Vector3";
49271
- MaterialLoaderType["Vector4"] = "Vector4";
49272
- MaterialLoaderType["Color"] = "Color";
49273
- MaterialLoaderType["Float"] = "Float";
49274
- MaterialLoaderType["Texture"] = "Texture";
49275
- MaterialLoaderType["Boolean"] = "Boolean";
49276
- MaterialLoaderType["Integer"] = "Integer";
49277
- return MaterialLoaderType;
49278
- }({});
49279
- var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
49280
- SpecularMode["Sky"] = "Sky";
49281
- SpecularMode["Custom"] = "Custom";
49282
- return SpecularMode;
49283
- }({});
49284
49187
  /** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser) {
49285
49188
  _inherits(SceneParser, HierarchyParser);
49286
49189
  function SceneParser(data, context, scene) {
@@ -49294,90 +49197,40 @@ var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
49294
49197
  */ _proto._collectDependentAssets = function _collectDependentAssets(data) {
49295
49198
  var context = this.context;
49296
49199
  var resourceManager = context.resourceManager;
49297
- this._parseDependentAssets(data);
49298
- var scene = data.scene;
49299
- var ambient = scene.ambient;
49300
- if (ambient) {
49301
- var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
49302
- var useSH = ambient.diffuseMode === DiffuseMode.SphericalHarmonics;
49303
- var customAmbientLight = ambient.customAmbientLight, ambientLight = ambient.ambientLight;
49304
- if (useCustomAmbient && customAmbientLight) {
49305
- // @ts-ignore
49306
- context._addDependentAsset(customAmbientLight.url, resourceManager.getResourceByRef(customAmbientLight));
49307
- }
49308
- if (ambientLight && (!useCustomAmbient || useSH)) {
49309
- // @ts-ignore
49310
- context._addDependentAsset(ambientLight.url, resourceManager.getResourceByRef(ambientLight));
49311
- }
49312
- }
49313
- var background = scene.background;
49314
- var backgroundMode = background.mode;
49315
- if (backgroundMode === BackgroundMode.Texture) {
49316
- var texture = background.texture;
49200
+ var refs = data.refs;
49201
+ for(var i = 0, n = refs.length; i < n; i++){
49317
49202
  // @ts-ignore
49318
- texture && context._addDependentAsset(texture.url, resourceManager.getResourceByRef(texture));
49319
- } else if (backgroundMode === BackgroundMode.Sky) {
49320
- var skyMesh = background.skyMesh, skyMaterial = background.skyMaterial;
49321
- if (skyMesh && skyMaterial) {
49322
- // @ts-ignore
49323
- context._addDependentAsset(skyMesh.url, resourceManager.getResourceByRef(skyMesh));
49324
- // @ts-ignore
49325
- context._addDependentAsset(skyMaterial.url, resourceManager.getResourceByRef(skyMaterial));
49326
- }
49203
+ context._addDependentAsset(resourceManager.getResourceByRef(refs[i]));
49327
49204
  }
49328
49205
  };
49329
- _proto._handleRootEntity = function _handleRootEntity(id) {
49330
- var entityMap = this.context.entityMap;
49331
- this.scene.addRootEntity(entityMap.get(id));
49206
+ _proto._getRootIndices = function _getRootIndices() {
49207
+ return this.data.scene.entities;
49208
+ };
49209
+ _proto._handleRootEntity = function _handleRootEntity(index) {
49210
+ this.scene.addRootEntity(this.context.entityInstances[index]);
49332
49211
  };
49333
49212
  _proto._clearAndResolve = function _clearAndResolve() {
49334
49213
  this.context.clear();
49335
49214
  return this.scene;
49336
49215
  };
49337
- _proto._parseDependentAssets = function _parseDependentAssets(file) {
49338
- var entities = file.entities;
49339
- for(var i = 0, n = entities.length; i < n; i++){
49340
- var entity = entities[i];
49341
- if (!!entity.assetUrl) {
49342
- var context = this.context;
49343
- var url = entity.assetUrl, key = entity.key;
49344
- // @ts-ignore
49345
- context._addDependentAsset(url, context.resourceManager.getResourceByRef({
49346
- url: url,
49347
- key: key
49348
- }));
49349
- } else if (entity.strippedId) {
49350
- continue;
49351
- } else {
49352
- var components = entity.components;
49353
- for(var j = 0, m = components.length; j < m; j++){
49354
- var component = components[j];
49355
- this._searchDependentAssets(component.methods);
49356
- this._searchDependentAssets(component.props);
49357
- }
49358
- }
49359
- }
49360
- };
49361
- _proto._searchDependentAssets = function _searchDependentAssets(value) {
49362
- if (Array.isArray(value)) {
49363
- for(var i = 0, n = value.length; i < n; i++){
49364
- this._searchDependentAssets(value[i]);
49365
- }
49366
- } else if (!!value && (typeof value === "undefined" ? "undefined" : _type_of1(value)) === "object") {
49367
- // @ts-ignore
49368
- if (ReflectionParser._isAssetRef(value)) {
49369
- var context = this.context;
49370
- // @ts-ignore
49371
- context._addDependentAsset(value.url, context.resourceManager.getResourceByRef(value));
49372
- } else {
49373
- for(var key in value){
49374
- this._searchDependentAssets(value[key]);
49375
- }
49376
- }
49377
- }
49378
- };
49379
49216
  return SceneParser;
49380
49217
  }(HierarchyParser);
49218
+ var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
49219
+ SpecularMode["Sky"] = "Sky";
49220
+ SpecularMode["Custom"] = "Custom";
49221
+ return SpecularMode;
49222
+ }({});
49223
+ var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
49224
+ MaterialLoaderType["Vector2"] = "Vector2";
49225
+ MaterialLoaderType["Vector3"] = "Vector3";
49226
+ MaterialLoaderType["Vector4"] = "Vector4";
49227
+ MaterialLoaderType["Color"] = "Color";
49228
+ MaterialLoaderType["Float"] = "Float";
49229
+ MaterialLoaderType["Texture"] = "Texture";
49230
+ MaterialLoaderType["Boolean"] = "Boolean";
49231
+ MaterialLoaderType["Integer"] = "Integer";
49232
+ return MaterialLoaderType;
49233
+ }({});
49381
49234
  /**
49382
49235
  * Decode engine binary resource.
49383
49236
  * @param arrayBuffer - array buffer of decode binary file
@@ -50838,6 +50691,38 @@ function getMeshoptDecoder() {
50838
50691
  ]);
50839
50692
  return GLTFResource;
50840
50693
  }(ReferResource);
50694
+ function _array_like_to_array(arr, len) {
50695
+ if (len == null || len > arr.length) len = arr.length;
50696
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
50697
+ return arr2;
50698
+ }
50699
+ function _unsupported_iterable_to_array(o, minLen) {
50700
+ if (!o) return;
50701
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
50702
+ var n = Object.prototype.toString.call(o).slice(8, -1);
50703
+ if (n === "Object" && o.constructor) n = o.constructor.name;
50704
+ if (n === "Map" || n === "Set") return Array.from(n);
50705
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
50706
+ }
50707
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
50708
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
50709
+ if (it) return (it = it.call(o)).next.bind(it);
50710
+ // Fallback for engines without symbol support
50711
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
50712
+ if (it) o = it;
50713
+ var i = 0;
50714
+ return function() {
50715
+ if (i >= o.length) return {
50716
+ done: true
50717
+ };
50718
+ return {
50719
+ done: false,
50720
+ value: o[i++]
50721
+ };
50722
+ };
50723
+ }
50724
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
50725
+ }
50841
50726
  /**
50842
50727
  * Module for glTF 2.0 Interface
50843
50728
  */ /**
@@ -53088,15 +52973,17 @@ var PrefabParser = /*#__PURE__*/ function(HierarchyParser) {
53088
52973
  return _this;
53089
52974
  }
53090
52975
  var _proto = PrefabParser.prototype;
53091
- _proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
53092
- if (entityConfig === void 0) entityConfig = {};
53093
- HierarchyParser.prototype._applyEntityData.call(this, entity, entityConfig);
52976
+ _proto._onEntityCreated = function _onEntityCreated(entity) {
53094
52977
  // @ts-ignore
53095
52978
  entity._markAsTemplate(this.context.resource);
53096
- return entity;
53097
52979
  };
53098
- _proto._handleRootEntity = function _handleRootEntity(id) {
53099
- this.prefabResource._root = this.context.entityMap.get(id);
52980
+ _proto._getRootIndices = function _getRootIndices() {
52981
+ return [
52982
+ this.data.root
52983
+ ];
52984
+ };
52985
+ _proto._handleRootEntity = function _handleRootEntity(index) {
52986
+ this.prefabResource._root = this.context.entityInstances[index];
53100
52987
  };
53101
52988
  _proto._clearAndResolve = function _clearAndResolve() {
53102
52989
  this.context.clear();
@@ -53107,9 +52994,7 @@ var PrefabParser = /*#__PURE__*/ function(HierarchyParser) {
53107
52994
  var context = new ParserContext(engine, ParserType.Prefab, prefabResource);
53108
52995
  var parser = new PrefabParser(data, context, prefabResource);
53109
52996
  parser.start();
53110
- return parser.promise.then(function() {
53111
- return prefabResource;
53112
- });
52997
+ return parser.promise;
53113
52998
  };
53114
52999
  return PrefabParser;
53115
53000
  }(HierarchyParser);
@@ -54217,6 +54102,122 @@ RenderTargetLoader = __decorate([
54217
54102
  "renderTarget"
54218
54103
  ])
54219
54104
  ], RenderTargetLoader);
54105
+ function loadRef(refs, index, resourceManager, label) {
54106
+ var ref = resolveRefItem(refs, index, "SceneLoader", label);
54107
+ // @ts-ignore
54108
+ return resourceManager.getResourceByRef(ref);
54109
+ }
54110
+ /**
54111
+ * Apply scene-level data (ambient, background, shadow, fog, AO) to a Scene.
54112
+ * @internal
54113
+ */ function applySceneData(scene, sceneData, resourceManager, refs) {
54114
+ var promises = [];
54115
+ try {
54116
+ // parse ambient light
54117
+ var ambient = sceneData.ambient;
54118
+ if (ambient) {
54119
+ var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
54120
+ var useSH = ambient.diffuseMode === DiffuseMode.SphericalHarmonics;
54121
+ scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
54122
+ scene.ambientLight.specularIntensity = ambient.specularIntensity;
54123
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
54124
+ var solidColor = ambient.diffuseSolidColor;
54125
+ if (solidColor) {
54126
+ scene.ambientLight.diffuseSolidColor.set(solidColor[0], solidColor[1], solidColor[2], solidColor[3]);
54127
+ }
54128
+ if (useCustomAmbient && ambient.customAmbientLight != null) {
54129
+ promises.push(loadRef(refs, ambient.customAmbientLight, resourceManager, "scene.ambient.customAmbientLight").then(function(ambientLight) {
54130
+ scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
54131
+ }));
54132
+ }
54133
+ if (ambient.ambientLight != null && (!useCustomAmbient || useSH)) {
54134
+ promises.push(loadRef(refs, ambient.ambientLight, resourceManager, "scene.ambient.ambientLight").then(function(ambientLight) {
54135
+ if (!useCustomAmbient) {
54136
+ scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
54137
+ }
54138
+ if (useSH) {
54139
+ scene.ambientLight.diffuseSphericalHarmonics = ambientLight == null ? void 0 : ambientLight.diffuseSphericalHarmonics;
54140
+ }
54141
+ }));
54142
+ }
54143
+ }
54144
+ // parse background
54145
+ var background = sceneData.background;
54146
+ scene.background.mode = background.mode;
54147
+ switch(scene.background.mode){
54148
+ case BackgroundMode.SolidColor:
54149
+ {
54150
+ var color = background.color;
54151
+ scene.background.solidColor.set(color[0], color[1], color[2], color[3]);
54152
+ break;
54153
+ }
54154
+ case BackgroundMode.Sky:
54155
+ if (background.skyMesh != null && background.skyMaterial != null) {
54156
+ promises.push(loadRef(refs, background.skyMesh, resourceManager, "scene.background.skyMesh").then(function(mesh) {
54157
+ scene.background.sky.mesh = mesh;
54158
+ }), loadRef(refs, background.skyMaterial, resourceManager, "scene.background.skyMaterial").then(function(material) {
54159
+ scene.background.sky.material = material;
54160
+ }));
54161
+ } else {
54162
+ Logger.warn("Sky background mode requires skyMesh and skyMaterial");
54163
+ }
54164
+ break;
54165
+ case BackgroundMode.Texture:
54166
+ if (background.texture != null) {
54167
+ promises.push(loadRef(refs, background.texture, resourceManager, "scene.background.texture").then(function(texture) {
54168
+ scene.background.texture = texture;
54169
+ }));
54170
+ var _background_textureFillMode;
54171
+ scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
54172
+ }
54173
+ break;
54174
+ }
54175
+ } catch (error) {
54176
+ return Promise.reject(error);
54177
+ }
54178
+ // parse shadow
54179
+ var shadow = sceneData.shadow;
54180
+ if (shadow) {
54181
+ if (shadow.castShadows != undefined) scene.castShadows = shadow.castShadows;
54182
+ if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
54183
+ if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
54184
+ if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
54185
+ if (shadow.enableTransparentShadow != undefined) scene.enableTransparentShadow = shadow.enableTransparentShadow;
54186
+ if (shadow.shadowTwoCascadeSplits != undefined) scene.shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits;
54187
+ if (shadow.shadowFourCascadeSplits) {
54188
+ var splits = shadow.shadowFourCascadeSplits;
54189
+ scene.shadowFourCascadeSplits.set(splits[0], splits[1], splits[2]);
54190
+ }
54191
+ if (shadow.shadowFadeBorder != undefined) scene.shadowFadeBorder = shadow.shadowFadeBorder;
54192
+ }
54193
+ // parse fog
54194
+ var fog = sceneData.fog;
54195
+ if (fog) {
54196
+ if (fog.fogMode != undefined) scene.fogMode = fog.fogMode;
54197
+ if (fog.fogStart != undefined) scene.fogStart = fog.fogStart;
54198
+ if (fog.fogEnd != undefined) scene.fogEnd = fog.fogEnd;
54199
+ if (fog.fogDensity != undefined) scene.fogDensity = fog.fogDensity;
54200
+ if (fog.fogColor) scene.fogColor.set(fog.fogColor[0], fog.fogColor[1], fog.fogColor[2], fog.fogColor[3]);
54201
+ }
54202
+ // Post Process
54203
+ if (sceneData.postProcess) {
54204
+ Logger.warn("Post Process is not supported in scene yet, please add PostProcess component in entity instead.");
54205
+ }
54206
+ // Ambient Occlusion
54207
+ var ambientOcclusion = sceneData.ambientOcclusion;
54208
+ if (ambientOcclusion) {
54209
+ var sceneAO = scene.ambientOcclusion;
54210
+ if (ambientOcclusion.enabledAmbientOcclusion != undefined) sceneAO.enabled = ambientOcclusion.enabledAmbientOcclusion;
54211
+ if (ambientOcclusion.quality != undefined) sceneAO.quality = ambientOcclusion.quality;
54212
+ if (ambientOcclusion.intensity != undefined) sceneAO.intensity = ambientOcclusion.intensity;
54213
+ if (ambientOcclusion.radius != undefined) sceneAO.radius = ambientOcclusion.radius;
54214
+ if (ambientOcclusion.bias != undefined) sceneAO.bias = ambientOcclusion.bias;
54215
+ if (ambientOcclusion.power != undefined) sceneAO.power = ambientOcclusion.power;
54216
+ if (ambientOcclusion.bilateralThreshold != undefined) sceneAO.bilateralThreshold = ambientOcclusion.bilateralThreshold;
54217
+ if (ambientOcclusion.minHorizonAngle != undefined) sceneAO.minHorizonAngle = ambientOcclusion.minHorizonAngle;
54218
+ }
54219
+ return Promise.all(promises).then(function() {});
54220
+ }
54220
54221
  var SceneLoader = /*#__PURE__*/ function(Loader) {
54221
54222
  _inherits(SceneLoader, Loader);
54222
54223
  function SceneLoader() {
@@ -54230,120 +54231,15 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
54230
54231
  ._request(item.url, _extends({}, item, {
54231
54232
  type: "json"
54232
54233
  })).then(function(data) {
54233
- var _data_name;
54234
- var scene = new Scene(engine, (_data_name = data.name) != null ? _data_name : "");
54234
+ var _data_scene_name;
54235
+ var scene = new Scene(engine, (_data_scene_name = data.scene.name) != null ? _data_scene_name : "");
54235
54236
  var context = new ParserContext(engine, ParserType.Scene, scene);
54236
54237
  var parser = new SceneParser(data, context, scene);
54237
54238
  parser._collectDependentAssets(data);
54238
54239
  context._setTaskCompleteProgress = setTaskCompleteProgress;
54239
54240
  parser.start();
54240
54241
  return parser.promise.then(function() {
54241
- var promises = [];
54242
- // parse ambient light
54243
- var ambient = data.scene.ambient;
54244
- if (ambient) {
54245
- var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
54246
- var useSH = ambient.diffuseMode === DiffuseMode.SphericalHarmonics;
54247
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
54248
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
54249
- scene.ambientLight.diffuseMode = ambient.diffuseMode;
54250
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
54251
- if (useCustomAmbient && ambient.customAmbientLight) {
54252
- promises.push(resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
54253
- scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
54254
- }));
54255
- }
54256
- if (ambient.ambientLight && (!useCustomAmbient || useSH)) {
54257
- promises.push(resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
54258
- if (!useCustomAmbient) {
54259
- scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
54260
- }
54261
- if (useSH) {
54262
- scene.ambientLight.diffuseSphericalHarmonics = ambientLight == null ? void 0 : ambientLight.diffuseSphericalHarmonics;
54263
- }
54264
- }));
54265
- }
54266
- }
54267
- // parse background
54268
- var background = data.scene.background;
54269
- scene.background.mode = background.mode;
54270
- switch(scene.background.mode){
54271
- case BackgroundMode.SolidColor:
54272
- scene.background.solidColor.copyFrom(background.color);
54273
- break;
54274
- case BackgroundMode.Sky:
54275
- if (background.skyMesh && background.skyMaterial) {
54276
- // @ts-ignore
54277
- var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
54278
- scene.background.sky.mesh = mesh;
54279
- });
54280
- // @ts-ignore
54281
- // prettier-ignore
54282
- var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
54283
- scene.background.sky.material = material;
54284
- });
54285
- promises.push(skyMeshPromise, skyMaterialPromise);
54286
- } else {
54287
- Logger.warn("Sky background mode requires skyMesh and skyMaterial");
54288
- }
54289
- break;
54290
- case BackgroundMode.Texture:
54291
- if (background.texture) {
54292
- // @ts-ignore
54293
- // prettier-ignore
54294
- var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
54295
- scene.background.texture = texture;
54296
- });
54297
- promises.push(backgroundPromise);
54298
- var _background_textureFillMode;
54299
- scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
54300
- }
54301
- break;
54302
- }
54303
- // parse shadow
54304
- var shadow = data.scene.shadow;
54305
- if (shadow) {
54306
- if (shadow.castShadows != undefined) scene.castShadows = shadow.castShadows;
54307
- if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
54308
- if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
54309
- if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
54310
- if (shadow.enableTransparentShadow != undefined) {
54311
- scene.enableTransparentShadow = shadow.enableTransparentShadow;
54312
- }
54313
- var _shadow_shadowTwoCascadeSplits;
54314
- scene.shadowTwoCascadeSplits = (_shadow_shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits) != null ? _shadow_shadowTwoCascadeSplits : scene.shadowTwoCascadeSplits;
54315
- shadow.shadowFourCascadeSplits && scene.shadowFourCascadeSplits.copyFrom(shadow.shadowFourCascadeSplits);
54316
- var _shadow_shadowFadeBorder;
54317
- scene.shadowFadeBorder = (_shadow_shadowFadeBorder = shadow.shadowFadeBorder) != null ? _shadow_shadowFadeBorder : scene.shadowFadeBorder;
54318
- }
54319
- // parse fog
54320
- var fog = data.scene.fog;
54321
- if (fog) {
54322
- if (fog.fogMode != undefined) scene.fogMode = fog.fogMode;
54323
- if (fog.fogStart != undefined) scene.fogStart = fog.fogStart;
54324
- if (fog.fogEnd != undefined) scene.fogEnd = fog.fogEnd;
54325
- if (fog.fogDensity != undefined) scene.fogDensity = fog.fogDensity;
54326
- if (fog.fogColor != undefined) scene.fogColor.copyFrom(fog.fogColor);
54327
- }
54328
- // Post Process
54329
- var postProcessData = data.scene.postProcess;
54330
- if (postProcessData) {
54331
- Logger.warn("Post Process is not supported in scene yet, please add PostProcess component in entity instead.");
54332
- }
54333
- // Ambient Occlusion
54334
- var ambientOcclusion = data.scene.ambientOcclusion;
54335
- if (ambientOcclusion) {
54336
- var sceneAmbientOcclusion = scene.ambientOcclusion;
54337
- sceneAmbientOcclusion.enabled = ambientOcclusion.enabledAmbientOcclusion;
54338
- sceneAmbientOcclusion.intensity = ambientOcclusion.intensity;
54339
- sceneAmbientOcclusion.radius = ambientOcclusion.radius;
54340
- sceneAmbientOcclusion.bias = ambientOcclusion.bias;
54341
- sceneAmbientOcclusion.power = ambientOcclusion.power;
54342
- sceneAmbientOcclusion.quality = ambientOcclusion.quality;
54343
- sceneAmbientOcclusion.bilateralThreshold = ambientOcclusion.bilateralThreshold;
54344
- sceneAmbientOcclusion.minHorizonAngle = ambientOcclusion.minHorizonAngle;
54345
- }
54346
- return Promise.all(promises).then(function() {
54242
+ return applySceneData(scene, data.scene, resourceManager, data.refs).then(function() {
54347
54243
  resolve(scene);
54348
54244
  });
54349
54245
  });
@@ -54851,7 +54747,7 @@ EXT_texture_webp = __decorate([
54851
54747
  ], EXT_texture_webp);
54852
54748
 
54853
54749
  //@ts-ignore
54854
- var version = "2.0.0-alpha.29";
54750
+ var version = "2.0.0-alpha.30";
54855
54751
  console.log("Galacean Engine Version: " + version);
54856
54752
  for(var key in CoreObjects){
54857
54753
  Loader.registerClass(key, CoreObjects[key]);