@galacean/engine 2.0.0-alpha.18 → 2.0.0-alpha.19

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/browser.js CHANGED
@@ -17946,118 +17946,13 @@
17946
17946
  this._fixedTimeStep = 1 / 60;
17947
17947
  this._colliders = new DisorderedArray();
17948
17948
  this._gravity = new Vector3(0, -9.81, 0);
17949
- this._onContactEnter = function(nativeCollision) {
17950
- var physicalObjectsMap = Engine._physicalObjectsMap;
17951
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
17952
- var shape1 = physicalObjectsMap[shape0Id];
17953
- var shape2 = physicalObjectsMap[shape1Id];
17954
- var collision = PhysicsScene._collision;
17955
- collision._nativeCollision = nativeCollision;
17956
- shape1.collider.entity._scripts.forEach(function(element) {
17957
- collision.shape = shape2;
17958
- element.onCollisionEnter(collision);
17959
- }, function(element, index) {
17960
- element._entityScriptsIndex = index;
17961
- });
17962
- shape2.collider.entity._scripts.forEach(function(element) {
17963
- collision.shape = shape1;
17964
- element.onCollisionEnter(collision);
17965
- }, function(element, index) {
17966
- element._entityScriptsIndex = index;
17967
- });
17968
- };
17969
- this._onContactExit = function(nativeCollision) {
17970
- var physicalObjectsMap = Engine._physicalObjectsMap;
17971
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
17972
- var shape1 = physicalObjectsMap[shape0Id];
17973
- var shape2 = physicalObjectsMap[shape1Id];
17974
- var collision = PhysicsScene._collision;
17975
- collision._nativeCollision = nativeCollision;
17976
- shape1.collider.entity._scripts.forEach(function(element) {
17977
- collision.shape = shape2;
17978
- element.onCollisionExit(collision);
17979
- }, function(element, index) {
17980
- element._entityScriptsIndex = index;
17981
- });
17982
- shape2.collider.entity._scripts.forEach(function(element) {
17983
- collision.shape = shape1;
17984
- element.onCollisionExit(collision);
17985
- }, function(element, index) {
17986
- element._entityScriptsIndex = index;
17987
- });
17988
- };
17989
- this._onContactStay = function(nativeCollision) {
17990
- var physicalObjectsMap = Engine._physicalObjectsMap;
17991
- var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
17992
- var shape1 = physicalObjectsMap[shape0Id];
17993
- var shape2 = physicalObjectsMap[shape1Id];
17994
- var collision = PhysicsScene._collision;
17995
- collision._nativeCollision = nativeCollision;
17996
- shape1.collider.entity._scripts.forEach(function(element) {
17997
- collision.shape = shape2;
17998
- element.onCollisionStay(collision);
17999
- }, function(element, index) {
18000
- element._entityScriptsIndex = index;
18001
- });
18002
- shape2.collider.entity._scripts.forEach(function(element) {
18003
- collision.shape = shape1;
18004
- element.onCollisionStay(collision);
18005
- }, function(element, index) {
18006
- element._entityScriptsIndex = index;
18007
- });
18008
- };
18009
- this._onTriggerEnter = function(obj1, obj2) {
18010
- var physicalObjectsMap = Engine._physicalObjectsMap;
18011
- var shape1 = physicalObjectsMap[obj1];
18012
- var shape2 = physicalObjectsMap[obj2];
18013
- shape1.collider.entity._scripts.forEach(function(element) {
18014
- element.onTriggerEnter(shape2);
18015
- }, function(element, index) {
18016
- element._entityScriptsIndex = index;
18017
- });
18018
- shape2.collider.entity._scripts.forEach(function(element) {
18019
- element.onTriggerEnter(shape1);
18020
- }, function(element, index) {
18021
- element._entityScriptsIndex = index;
18022
- });
18023
- };
18024
- this._onTriggerExit = function(obj1, obj2) {
18025
- var physicalObjectsMap = Engine._physicalObjectsMap;
18026
- var shape1 = physicalObjectsMap[obj1];
18027
- var shape2 = physicalObjectsMap[obj2];
18028
- shape1.collider.entity._scripts.forEach(function(element) {
18029
- element.onTriggerExit(shape2);
18030
- }, function(element, index) {
18031
- element._entityScriptsIndex = index;
18032
- });
18033
- shape2.collider.entity._scripts.forEach(function(element) {
18034
- element.onTriggerExit(shape1);
18035
- }, function(element, index) {
18036
- element._entityScriptsIndex = index;
18037
- });
18038
- };
18039
- this._onTriggerStay = function(obj1, obj2) {
18040
- var physicalObjectsMap = Engine._physicalObjectsMap;
18041
- var shape1 = physicalObjectsMap[obj1];
18042
- var shape2 = physicalObjectsMap[obj2];
18043
- shape1.collider.entity._scripts.forEach(function(element) {
18044
- element.onTriggerStay(shape2);
18045
- }, function(element, index) {
18046
- element._entityScriptsIndex = index;
18047
- });
18048
- shape2.collider.entity._scripts.forEach(function(element) {
18049
- element.onTriggerStay(shape1);
18050
- }, function(element, index) {
18051
- element._entityScriptsIndex = index;
18052
- });
18053
- };
18054
17949
  this._scene = scene;
18055
17950
  this._setGravity = this._setGravity.bind(this);
18056
17951
  //@ts-ignore
18057
17952
  this._gravity._onValueChanged = this._setGravity;
18058
17953
  var engine = scene.engine;
18059
17954
  if (engine._physicsInitialized) {
18060
- this._nativePhysicsScene = Engine._nativePhysics.createPhysicsScene(engine._nativePhysicsManager, this._onContactEnter, this._onContactExit, this._onContactStay, this._onTriggerEnter, this._onTriggerExit, this._onTriggerStay);
17955
+ this._nativePhysicsScene = Engine._nativePhysics.createPhysicsScene(engine._nativePhysicsManager);
18061
17956
  }
18062
17957
  }
18063
17958
  var _proto = PhysicsScene.prototype;
@@ -18269,6 +18164,7 @@
18269
18164
  this._callColliderOnUpdate();
18270
18165
  nativePhysicsManager.update(fixedTimeStep);
18271
18166
  this._callColliderOnLateUpdate();
18167
+ this._dispatchEvents(nativePhysicsManager.updateEvents());
18272
18168
  }
18273
18169
  };
18274
18170
  /**
@@ -18332,7 +18228,9 @@
18332
18228
  /**
18333
18229
  * @internal
18334
18230
  */ _proto._gc = function _gc() {
18231
+ var _this__nativePhysicsScene;
18335
18232
  this._colliders.garbageCollection();
18233
+ (_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.gc();
18336
18234
  };
18337
18235
  /**
18338
18236
  * @internal
@@ -18340,6 +18238,92 @@
18340
18238
  var _this__nativePhysicsScene;
18341
18239
  (_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.destroy();
18342
18240
  };
18241
+ _proto._dispatchEvents = function _dispatchEvents(events) {
18242
+ var _loop = function _loop(i, n) {
18243
+ var _shape1_collider, _shape2_collider;
18244
+ var event = contactEvents[i];
18245
+ var shape1 = physicalObjectsMap[event.shape0Id];
18246
+ var shape2 = physicalObjectsMap[event.shape1Id];
18247
+ // entity.destroy() is deferred, so shapes/colliders stay valid through the dispatch loop
18248
+ // This guard covers synchronous removeShape()/clearShapes() which sets shape._collider = null
18249
+ if (!(shape1 == null ? void 0 : (_shape1_collider = shape1.collider) == null ? void 0 : _shape1_collider.entity) || !(shape2 == null ? void 0 : (_shape2_collider = shape2.collider) == null ? void 0 : _shape2_collider.entity)) return "continue";
18250
+ collision._nativeCollision = event;
18251
+ switch(event.state){
18252
+ case 0:
18253
+ shape1.collider.entity._scripts.forEach(function(element) {
18254
+ collision.shape = shape2;
18255
+ element.onCollisionEnter(collision);
18256
+ }, scriptIndexSetter);
18257
+ shape2.collider.entity._scripts.forEach(function(element) {
18258
+ collision.shape = shape1;
18259
+ element.onCollisionEnter(collision);
18260
+ }, scriptIndexSetter);
18261
+ break;
18262
+ case 1:
18263
+ shape1.collider.entity._scripts.forEach(function(element) {
18264
+ collision.shape = shape2;
18265
+ element.onCollisionStay(collision);
18266
+ }, scriptIndexSetter);
18267
+ shape2.collider.entity._scripts.forEach(function(element) {
18268
+ collision.shape = shape1;
18269
+ element.onCollisionStay(collision);
18270
+ }, scriptIndexSetter);
18271
+ break;
18272
+ case 2:
18273
+ shape1.collider.entity._scripts.forEach(function(element) {
18274
+ collision.shape = shape2;
18275
+ element.onCollisionExit(collision);
18276
+ }, scriptIndexSetter);
18277
+ shape2.collider.entity._scripts.forEach(function(element) {
18278
+ collision.shape = shape1;
18279
+ element.onCollisionExit(collision);
18280
+ }, scriptIndexSetter);
18281
+ break;
18282
+ }
18283
+ }, _loop1 = function _loop1(i1, n1) {
18284
+ var _shape1_collider, _shape2_collider;
18285
+ var event = triggerEvents[i1];
18286
+ var shape1 = physicalObjectsMap[event.index1];
18287
+ var shape2 = physicalObjectsMap[event.index2];
18288
+ // entity.destroy() is deferred, so shapes/colliders stay valid through the dispatch loop
18289
+ // This guard covers synchronous removeShape()/clearShapes() which sets shape._collider = null
18290
+ if (!(shape1 == null ? void 0 : (_shape1_collider = shape1.collider) == null ? void 0 : _shape1_collider.entity) || !(shape2 == null ? void 0 : (_shape2_collider = shape2.collider) == null ? void 0 : _shape2_collider.entity)) return "continue";
18291
+ switch(event.dispatchState){
18292
+ case 0:
18293
+ shape1.collider.entity._scripts.forEach(function(element) {
18294
+ element.onTriggerEnter(shape2);
18295
+ }, scriptIndexSetter);
18296
+ shape2.collider.entity._scripts.forEach(function(element) {
18297
+ element.onTriggerEnter(shape1);
18298
+ }, scriptIndexSetter);
18299
+ break;
18300
+ case 1:
18301
+ shape1.collider.entity._scripts.forEach(function(element) {
18302
+ element.onTriggerStay(shape2);
18303
+ }, scriptIndexSetter);
18304
+ shape2.collider.entity._scripts.forEach(function(element) {
18305
+ element.onTriggerStay(shape1);
18306
+ }, scriptIndexSetter);
18307
+ break;
18308
+ case 2:
18309
+ shape1.collider.entity._scripts.forEach(function(element) {
18310
+ element.onTriggerExit(shape2);
18311
+ }, scriptIndexSetter);
18312
+ shape2.collider.entity._scripts.forEach(function(element) {
18313
+ element.onTriggerExit(shape1);
18314
+ }, scriptIndexSetter);
18315
+ break;
18316
+ }
18317
+ };
18318
+ var physicalObjectsMap = Engine._physicalObjectsMap;
18319
+ var collision = PhysicsScene._collision;
18320
+ var scriptIndexSetter = PhysicsScene._scriptIndexSetter;
18321
+ var contactEvents = events.contactEvents, contactEventCount = events.contactEventCount, triggerEvents = events.triggerEvents;
18322
+ // Dispatch contact events
18323
+ for(var i = 0, n = contactEventCount; i < n; i++)_loop(i);
18324
+ // Dispatch trigger events
18325
+ for(var i1 = 0, n1 = triggerEvents.length; i1 < n1; i1++)_loop1(i1);
18326
+ };
18343
18327
  _proto._setGravity = function _setGravity() {
18344
18328
  this._nativePhysicsScene.setGravity(this._gravity);
18345
18329
  };
@@ -18399,6 +18383,9 @@
18399
18383
  }();
18400
18384
  PhysicsScene._collision = new Collision();
18401
18385
  PhysicsScene._identityQuaternion = new Quaternion(0, 0, 0, 1);
18386
+ PhysicsScene._scriptIndexSetter = function(element, index) {
18387
+ element._entityScriptsIndex = index;
18388
+ };
18402
18389
  /**
18403
18390
  * A static collider component that will not move.
18404
18391
  * @remarks Mostly used for object which always stays at the same place and never moves around.
@@ -31832,6 +31819,11 @@
31832
31819
  this._textSubRenderElementPool.garbageCollection();
31833
31820
  this._renderElementPool.garbageCollection();
31834
31821
  this._renderContext.garbageCollection();
31822
+ var scenes = this._sceneManager._scenes.getLoopArray();
31823
+ for(var i = 0, n = scenes.length; i < n; i++){
31824
+ var _scenes_i_physics, _scenes_i;
31825
+ (_scenes_i = scenes[i]) == null ? void 0 : (_scenes_i_physics = _scenes_i.physics) == null ? void 0 : _scenes_i_physics._gc();
31826
+ }
31835
31827
  };
31836
31828
  _create_class$2(Engine, [
31837
31829
  {
@@ -45850,7 +45842,9 @@
45850
45842
  _proto._bindMainFBO = function _bindMainFBO() {
45851
45843
  var gl = this._gl;
45852
45844
  var isWebGL2 = this._isWebGL2;
45853
- /** @ts-ignore */ var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount, width = _this__target.width, height = _this__target.height;
45845
+ /** @ts-ignore */ var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount;
45846
+ _this__target.width;
45847
+ _this__target.height;
45854
45848
  var drawBuffers = new Array(colorTextureCount);
45855
45849
  gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
45856
45850
  /** color render buffer */ for(var i = 0; i < colorTextureCount; i++){
@@ -45872,11 +45866,7 @@
45872
45866
  gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
45873
45867
  } else if (this._target.antiAliasing <= 1) {
45874
45868
  var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl, isWebGL2), internalFormat = _GLTexture__getRenderBufferDepthFormatDetail.internalFormat, attachment1 = _GLTexture__getRenderBufferDepthFormatDetail.attachment;
45875
- var depthRenderBuffer = gl.createRenderbuffer();
45876
- this._depthRenderBuffer = depthRenderBuffer;
45877
- gl.bindRenderbuffer(gl.RENDERBUFFER, depthRenderBuffer);
45878
- gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
45879
- gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, depthRenderBuffer);
45869
+ this._depthRenderBuffer = this._createRenderBuffer(internalFormat, attachment1);
45880
45870
  }
45881
45871
  }
45882
45872
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
@@ -45885,32 +45875,38 @@
45885
45875
  _proto._bindMSAAFBO = function _bindMSAAFBO() {
45886
45876
  var gl = this._gl;
45887
45877
  var isWebGL2 = this._isWebGL2;
45888
- var MSAADepthRenderBuffer = gl.createRenderbuffer();
45889
- /** @ts-ignore */ var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount, antiAliasing = _this__target.antiAliasing, width = _this__target.width, height = _this__target.height;
45878
+ /** @ts-ignore */ var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount;
45890
45879
  this._blitDrawBuffers = new Array(colorTextureCount);
45891
- this._MSAADepthRenderBuffer = MSAADepthRenderBuffer;
45892
45880
  gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
45893
45881
  // prepare MRT+MSAA color RBOs
45894
45882
  for(var i = 0; i < colorTextureCount; i++){
45895
- var MSAAColorRenderBuffer = gl.createRenderbuffer();
45896
- this._MSAAColorRenderBuffers[i] = MSAAColorRenderBuffer;
45897
45883
  this._blitDrawBuffers[i] = gl.NONE;
45898
- gl.bindRenderbuffer(gl.RENDERBUFFER, MSAAColorRenderBuffer);
45899
- gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, /** @ts-ignore */ this._target.getColorTexture(i)._platformTexture._formatDetail.internalFormat, width, height);
45900
- gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, MSAAColorRenderBuffer);
45884
+ var internalFormat = /** @ts-ignore */ this._target.getColorTexture(i)._platformTexture._formatDetail.internalFormat;
45885
+ this._MSAAColorRenderBuffers[i] = this._createRenderBuffer(internalFormat, gl.COLOR_ATTACHMENT0 + i);
45901
45886
  }
45902
45887
  gl.drawBuffers(this._oriDrawBuffers);
45903
45888
  // prepare MSAA depth RBO
45904
45889
  if (_depth !== null) {
45905
- var _ref = _instanceof1$1(_depth, Texture) ? /** @ts-ignore */ _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl, isWebGL2), internalFormat = _ref.internalFormat, attachment = _ref.attachment;
45906
- gl.bindRenderbuffer(gl.RENDERBUFFER, MSAADepthRenderBuffer);
45907
- gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, internalFormat, width, height);
45908
- gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, MSAADepthRenderBuffer);
45890
+ var _ref = _instanceof1$1(_depth, Texture) ? /** @ts-ignore */ _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl, isWebGL2), internalFormat1 = _ref.internalFormat, attachment = _ref.attachment;
45891
+ this._MSAADepthRenderBuffer = this._createRenderBuffer(internalFormat1, attachment);
45909
45892
  }
45910
45893
  this._checkFrameBuffer();
45911
45894
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
45912
45895
  gl.bindRenderbuffer(gl.RENDERBUFFER, null);
45913
45896
  };
45897
+ _proto._createRenderBuffer = function _createRenderBuffer(internalFormat, attachment) {
45898
+ var gl = this._gl;
45899
+ var _this__target = this._target, width = _this__target.width, height = _this__target.height, antiAliasing = _this__target.antiAliasing;
45900
+ var renderBuffer = gl.createRenderbuffer();
45901
+ gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
45902
+ if (antiAliasing > 1) {
45903
+ gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, internalFormat, width, height);
45904
+ } else {
45905
+ gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
45906
+ }
45907
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, renderBuffer);
45908
+ return renderBuffer;
45909
+ };
45914
45910
  _proto._checkFrameBuffer = function _checkFrameBuffer() {
45915
45911
  var gl = this._gl;
45916
45912
  var e = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
@@ -54059,7 +54055,7 @@
54059
54055
  ], EXT_texture_webp);
54060
54056
 
54061
54057
  //@ts-ignore
54062
- var version = "2.0.0-alpha.18";
54058
+ var version = "2.0.0-alpha.19";
54063
54059
  console.log("Galacean Engine Version: " + version);
54064
54060
  for(var key in CoreObjects){
54065
54061
  Loader.registerClass(key, CoreObjects[key]);