@galacean/engine-physics-lite 0.0.0-experimental-0.9-plus.4 → 0.0.0-experimental-0.9-plus.5

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.
@@ -12842,6 +12842,7 @@ var VertexChangedFlags;
12842
12842
  var mesh = this._mesh;
12843
12843
  if (mesh && !mesh.destroyed) {
12844
12844
  mesh._addRefCount(-1);
12845
+ mesh._updateFlagManager.removeListener(this._onMeshChanged);
12845
12846
  this._mesh = null;
12846
12847
  }
12847
12848
  };
@@ -13137,6 +13138,7 @@ var rePropName = RegExp("[^.[\\]]+" + "|" + // Or match property names within br
13137
13138
  (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13138
13139
  this._jointTexture = new Texture2D(engine, 4, jointCount, exports.TextureFormat.R32G32B32A32, false);
13139
13140
  this._jointTexture.filterMode = exports.TextureFilterMode.Point;
13141
+ this._jointTexture.isGCIgnored = true;
13140
13142
  }
13141
13143
  shaderData.disableMacro("O3_JOINTS_NUM");
13142
13144
  shaderData.enableMacro("O3_USE_JOINT_TEXTURE");
@@ -13170,6 +13172,15 @@ var rePropName = RegExp("[^.[\\]]+" + "|" + // Or match property names within br
13170
13172
  };
13171
13173
  /**
13172
13174
  * @internal
13175
+ * @override
13176
+ */ _proto._onDestroy = function _onDestroy() {
13177
+ var _this_rootBone, _this__jointTexture;
13178
+ MeshRenderer.prototype._onDestroy.call(this);
13179
+ (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13180
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13181
+ };
13182
+ /**
13183
+ * @internal
13173
13184
  */ _proto._cloneTo = function _cloneTo(target) {
13174
13185
  MeshRenderer.prototype._cloneTo.call(this, target);
13175
13186
  this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
@@ -34260,6 +34271,38 @@ function _inherits(subClass, superClass) {
34260
34271
  });
34261
34272
  if (superClass) _set_prototype_of(subClass, superClass);
34262
34273
  }
34274
+ /**
34275
+ * WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
34276
+ */ var WebGLEngine = /*#__PURE__*/ function(Engine) {
34277
+ var WebGLEngine = function WebGLEngine() {
34278
+ return Engine.apply(this, arguments);
34279
+ };
34280
+ _inherits(WebGLEngine, Engine);
34281
+ /**
34282
+ * Create a WebGL engine.
34283
+ * @param configuration - WebGL engine configuration
34284
+ * @returns A promise that will resolve when the engine is created
34285
+ */ WebGLEngine.create = function create(configuration) {
34286
+ var canvas = configuration.canvas;
34287
+ var webCanvas = new WebCanvas(typeof canvas === "string" ? engineMiniprogramAdapter.document.getElementById(canvas) : canvas);
34288
+ var webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
34289
+ var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
34290
+ // @ts-ignore
34291
+ return engine._initialize(configuration);
34292
+ };
34293
+ _create_class(WebGLEngine, [
34294
+ {
34295
+ key: "canvas",
34296
+ get: /**
34297
+ * Web canvas.
34298
+ */ function get() {
34299
+ // @ts-ignore
34300
+ return this._canvas;
34301
+ }
34302
+ }
34303
+ ]);
34304
+ return WebGLEngine;
34305
+ }(miniprogram$1$1.Engine);
34263
34306
  function _extends() {
34264
34307
  _extends = Object.assign || function assign(target) {
34265
34308
  for(var i = 1; i < arguments.length; i++){
@@ -34270,6 +34313,83 @@ function _extends() {
34270
34313
  };
34271
34314
  return _extends.apply(this, arguments);
34272
34315
  }
34316
+ var GLBuffer = /*#__PURE__*/ function() {
34317
+ var GLBuffer = function GLBuffer(rhi, type, byteLength, bufferUsage, data) {
34318
+ if (bufferUsage === void 0) bufferUsage = miniprogram$1$1.BufferUsage.Static;
34319
+ var gl = rhi.gl;
34320
+ var glBuffer = gl.createBuffer();
34321
+ var glBufferUsage = this._getGLBufferUsage(gl, bufferUsage);
34322
+ var glBindTarget = type === miniprogram$1$1.BufferBindFlag.VertexBuffer ? gl.ARRAY_BUFFER : gl.ELEMENT_ARRAY_BUFFER;
34323
+ this._gl = gl;
34324
+ this._glBuffer = glBuffer;
34325
+ this._glBufferUsage = glBufferUsage;
34326
+ this._glBindTarget = glBindTarget;
34327
+ this._isWebGL2 = rhi.isWebGL2;
34328
+ this.bind();
34329
+ if (data) {
34330
+ gl.bufferData(glBindTarget, data, glBufferUsage);
34331
+ } else {
34332
+ gl.bufferData(glBindTarget, byteLength, glBufferUsage);
34333
+ }
34334
+ gl.bindBuffer(glBindTarget, null);
34335
+ };
34336
+ var _proto = GLBuffer.prototype;
34337
+ _proto.bind = function bind() {
34338
+ this._gl.bindBuffer(this._glBindTarget, this._glBuffer);
34339
+ };
34340
+ _proto.setData = function setData(byteLength, data, bufferByteOffset, dataOffset, dataLength, options) {
34341
+ var gl = this._gl;
34342
+ var glBindTarget = this._glBindTarget;
34343
+ this.bind();
34344
+ if (options === miniprogram$1$1.SetDataOptions.Discard) {
34345
+ gl.bufferData(glBindTarget, byteLength, this._glBufferUsage);
34346
+ }
34347
+ // TypeArray is BYTES_PER_ELEMENT, unTypeArray is 1
34348
+ var byteSize = data.BYTES_PER_ELEMENT || 1;
34349
+ var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
34350
+ if (dataOffset !== 0 || dataByteLength < data.byteLength) {
34351
+ var isArrayBufferView = data.byteOffset !== undefined;
34352
+ if (this._isWebGL2 && isArrayBufferView) {
34353
+ gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
34354
+ } else {
34355
+ var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
34356
+ gl.bufferSubData(glBindTarget, bufferByteOffset, subData);
34357
+ }
34358
+ } else {
34359
+ gl.bufferSubData(glBindTarget, bufferByteOffset, data);
34360
+ }
34361
+ gl.bindBuffer(glBindTarget, null);
34362
+ };
34363
+ _proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
34364
+ if (this._isWebGL2) {
34365
+ var gl = this._gl;
34366
+ this.bind();
34367
+ gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
34368
+ } else {
34369
+ throw "Buffer is write-only on WebGL1.0 platforms.";
34370
+ }
34371
+ };
34372
+ _proto.resize = function resize(byteLength) {
34373
+ this.bind();
34374
+ this._gl.bufferData(this._glBindTarget, byteLength, this._glBufferUsage);
34375
+ };
34376
+ _proto.destroy = function destroy() {
34377
+ this._gl.deleteBuffer(this._glBuffer);
34378
+ this._gl = null;
34379
+ this._glBuffer = null;
34380
+ };
34381
+ _proto._getGLBufferUsage = function _getGLBufferUsage(gl, bufferUsage) {
34382
+ switch(bufferUsage){
34383
+ case miniprogram$1$1.BufferUsage.Static:
34384
+ return gl.STATIC_DRAW;
34385
+ case miniprogram$1$1.BufferUsage.Dynamic:
34386
+ return gl.DYNAMIC_DRAW;
34387
+ case miniprogram$1$1.BufferUsage.Stream:
34388
+ return gl.STREAM_DRAW;
34389
+ }
34390
+ };
34391
+ return GLBuffer;
34392
+ }();
34273
34393
  /**
34274
34394
  * GL capability.
34275
34395
  */ var GLCapability = /*#__PURE__*/ function() {
@@ -34532,8 +34652,8 @@ function _extends() {
34532
34652
  if (useVao) {
34533
34653
  gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
34534
34654
  } else {
34535
- var _nativeBuffer = _indexBufferBinding.buffer._nativeBuffer;
34536
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer);
34655
+ var _glBuffer = _indexBufferBinding.buffer._platformBuffer._glBuffer;
34656
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer);
34537
34657
  gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
34538
34658
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
34539
34659
  }
@@ -34546,8 +34666,8 @@ function _extends() {
34546
34666
  if (useVao) {
34547
34667
  gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
34548
34668
  } else {
34549
- var _nativeBuffer1 = _indexBufferBinding.buffer._nativeBuffer;
34550
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer1);
34669
+ var _glBuffer1 = _indexBufferBinding.buffer._platformBuffer._glBuffer;
34670
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
34551
34671
  gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
34552
34672
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
34553
34673
  }
@@ -34587,7 +34707,7 @@ function _extends() {
34587
34707
  var element = attributes[name];
34588
34708
  if (element) {
34589
34709
  var _vertexBufferBindings_element_bindingIndex = vertexBufferBindings[element.bindingIndex], buffer = _vertexBufferBindings_element_bindingIndex.buffer, stride = _vertexBufferBindings_element_bindingIndex.stride;
34590
- vbo = buffer._nativeBuffer;
34710
+ vbo = buffer._platformBuffer._glBuffer;
34591
34711
  // prevent binding the vbo which already bound at the last loop, e.g. a buffer with multiple attributes.
34592
34712
  if (lastBoundVbo !== vbo) {
34593
34713
  lastBoundVbo = vbo;
@@ -34619,7 +34739,7 @@ function _extends() {
34619
34739
  // @ts-ignore
34620
34740
  var _indexBufferBinding = this._primitive._indexBufferBinding;
34621
34741
  if (_indexBufferBinding) {
34622
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._nativeBuffer);
34742
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._platformBuffer._glBuffer);
34623
34743
  }
34624
34744
  this._bindBufferAndAttrib(shaderProgram);
34625
34745
  /** unbind */ gl.bindVertexArray(null);
@@ -35676,23 +35796,21 @@ exports.WebGLMode = void 0;
35676
35796
  WebGLMode[WebGLMode[/** WebGL1.0, */ "WebGL1"] = 2] = "WebGL1";
35677
35797
  })(exports.WebGLMode || (exports.WebGLMode = {}));
35678
35798
  /**
35679
- * WebGL renderer, including WebGL1.0 and WebGL2.0.
35680
- */ var WebGLRenderer = /*#__PURE__*/ function() {
35681
- var WebGLRenderer = function WebGLRenderer(initializeOptions) {
35799
+ * WebGL graphic device, including WebGL1.0 and WebGL2.0.
35800
+ */ var WebGLGraphicDevice = /*#__PURE__*/ function() {
35801
+ var WebGLGraphicDevice = function WebGLGraphicDevice(initializeOptions) {
35682
35802
  if (initializeOptions === void 0) initializeOptions = {};
35803
+ /** @internal */ this._readFrameBuffer = null;
35683
35804
  /** @internal */ this._enableGlobalDepthBias = false;
35684
35805
  this._activeTextures = new Array(32);
35685
- // cache value
35686
35806
  this._lastViewport = new miniprogram$1.Vector4(null, null, null, null);
35687
35807
  this._lastScissor = new miniprogram$1.Vector4(null, null, null, null);
35688
35808
  this._lastClearColor = new miniprogram$1.Color(null, null, null, null);
35689
35809
  this._scissorEnable = false;
35690
35810
  var options = _extends({
35691
35811
  webGLMode: 0,
35692
- alpha: false,
35693
35812
  stencil: true,
35694
- _forceFlush: false,
35695
- _maxAllowSkinUniformVectorCount: 256
35813
+ _forceFlush: false
35696
35814
  }, initializeOptions);
35697
35815
  if (miniprogram$1$1.SystemInfo.platform === miniprogram$1$1.Platform.IPhone || miniprogram$1$1.SystemInfo.platform === miniprogram$1$1.Platform.IPad) {
35698
35816
  var version = miniprogram$1$1.SystemInfo.operatingSystem.match(/(\d+).?(\d+)?.?(\d+)?/);
@@ -35705,12 +35823,20 @@ exports.WebGLMode = void 0;
35705
35823
  }
35706
35824
  }
35707
35825
  this._options = options;
35826
+ this._onWebGLContextLost = this._onWebGLContextLost.bind(this);
35827
+ this._onWebGLContextRestored = this._onWebGLContextRestored.bind(this);
35708
35828
  };
35709
- var _proto = WebGLRenderer.prototype;
35710
- _proto.init = function init(canvas) {
35829
+ var _proto = WebGLGraphicDevice.prototype;
35830
+ _proto.init = function init(canvas, onDeviceLost, onDeviceRestored) {
35711
35831
  var options = this._options;
35712
- var webCanvas = this._webCanvas = canvas._webCanvas;
35832
+ var webCanvas = canvas._webCanvas;
35713
35833
  var webGLMode = options.webGLMode;
35834
+ this._onDeviceLost = onDeviceLost;
35835
+ this._onDeviceRestored = onDeviceRestored;
35836
+ webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
35837
+ webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
35838
+ webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
35839
+ this._webCanvas = webCanvas;
35714
35840
  var gl;
35715
35841
  if (webGLMode == 0 || webGLMode == 1) {
35716
35842
  gl = webCanvas.getContext("webgl2", options);
@@ -35736,16 +35862,7 @@ exports.WebGLMode = void 0;
35736
35862
  throw new Error("Get GL Context FAILED.");
35737
35863
  }
35738
35864
  this._gl = gl;
35739
- this._activeTextureID = gl.TEXTURE0;
35740
- this._renderStates = new GLRenderStates(gl);
35741
- this._extensions = new GLExtensions(this);
35742
- this._capability = new GLCapability(this);
35743
- // Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
35744
- gl.activeTexture(gl.TEXTURE0);
35745
- var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
35746
- if (debugRenderInfo != null) {
35747
- this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
35748
- }
35865
+ this._initGLState(gl);
35749
35866
  };
35750
35867
  _proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
35751
35868
  return new GLPrimitive(this, primitive);
@@ -35762,6 +35879,10 @@ exports.WebGLMode = void 0;
35762
35879
  _proto.createPlatformRenderTarget = function createPlatformRenderTarget(target) {
35763
35880
  return new GLRenderTarget(this, target);
35764
35881
  };
35882
+ _proto.createPlatformBuffer = function createPlatformBuffer(type, byteLength, bufferUsage, data) {
35883
+ if (bufferUsage === void 0) bufferUsage = miniprogram$1$1.BufferUsage.Static;
35884
+ return new GLBuffer(this, type, byteLength, bufferUsage, data);
35885
+ };
35765
35886
  _proto.requireExtension = function requireExtension(ext) {
35766
35887
  return this._extensions.requireExtension(ext);
35767
35888
  };
@@ -35889,8 +36010,57 @@ exports.WebGLMode = void 0;
35889
36010
  _proto.flush = function flush() {
35890
36011
  this._gl.flush();
35891
36012
  };
35892
- _proto.destroy = function destroy() {};
35893
- _create_class(WebGLRenderer, [
36013
+ _proto.forceLoseDevice = function forceLoseDevice() {
36014
+ var extension = this.requireExtension(miniprogram$1$1.GLCapabilityType.WEBGL_lose_context);
36015
+ extension.loseContext();
36016
+ };
36017
+ _proto.forceRestoreDevice = function forceRestoreDevice() {
36018
+ var extension = this.requireExtension(miniprogram$1$1.GLCapabilityType.WEBGL_lose_context);
36019
+ extension.restoreContext();
36020
+ };
36021
+ _proto.resetState = function resetState() {
36022
+ this._readFrameBuffer = null;
36023
+ this._enableGlobalDepthBias = false;
36024
+ this._currentBindShaderProgram = null;
36025
+ var activeTextures = this._activeTextures;
36026
+ for(var i = 0, n = activeTextures.length; i < n; i++){
36027
+ activeTextures[i] = null;
36028
+ }
36029
+ this._lastViewport.set(null, null, null, null);
36030
+ this._lastScissor.set(null, null, null, null);
36031
+ this._lastClearColor.set(null, null, null, null);
36032
+ this._scissorEnable = false;
36033
+ this._initGLState(this._gl);
36034
+ };
36035
+ _proto._initGLState = function _initGLState(gl) {
36036
+ this._activeTextureID = gl.TEXTURE0;
36037
+ this._renderStates = new GLRenderStates(gl);
36038
+ this._extensions = new GLExtensions(this);
36039
+ this._capability = new GLCapability(this);
36040
+ // Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
36041
+ gl.activeTexture(gl.TEXTURE0);
36042
+ var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
36043
+ if (debugRenderInfo != null) {
36044
+ this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
36045
+ }
36046
+ };
36047
+ _proto.destroy = function destroy() {
36048
+ var webCanvas = this._webCanvas;
36049
+ webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
36050
+ webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
36051
+ webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
36052
+ };
36053
+ _proto._onContextCreationError = function _onContextCreationError(event) {
36054
+ console.error("WebGLRenderer: WebGL context could not be created. Reason: ", event.statusMessage);
36055
+ };
36056
+ _proto._onWebGLContextLost = function _onWebGLContextLost(event) {
36057
+ event.preventDefault();
36058
+ this._onDeviceLost();
36059
+ };
36060
+ _proto._onWebGLContextRestored = function _onWebGLContextRestored(event) {
36061
+ this._onDeviceRestored();
36062
+ };
36063
+ _create_class(WebGLGraphicDevice, [
35894
36064
  {
35895
36065
  key: "isWebGL2",
35896
36066
  get: function get() {
@@ -35931,32 +36101,11 @@ exports.WebGLMode = void 0;
35931
36101
  }
35932
36102
  }
35933
36103
  ]);
35934
- return WebGLRenderer;
36104
+ return WebGLGraphicDevice;
35935
36105
  }();
35936
- /**
35937
- * WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
35938
- */ var WebGLEngine = /*#__PURE__*/ function(Engine) {
35939
- var WebGLEngine = function WebGLEngine(canvas, webGLRendererOptions) {
35940
- var webCanvas = new WebCanvas(typeof canvas === "string" ? engineMiniprogramAdapter.document.getElementById(canvas) : canvas);
35941
- var hardwareRenderer = new WebGLRenderer(webGLRendererOptions);
35942
- return Engine.call(this, webCanvas, hardwareRenderer);
35943
- };
35944
- _inherits(WebGLEngine, Engine);
35945
- _create_class(WebGLEngine, [
35946
- {
35947
- key: "canvas",
35948
- get: /**
35949
- * Web canvas.
35950
- */ function get() {
35951
- return this._canvas;
35952
- }
35953
- }
35954
- ]);
35955
- return WebGLEngine;
35956
- }(miniprogram$1$1.Engine);
35957
36106
  exports.WebCanvas = WebCanvas;
35958
36107
  exports.WebGLEngine = WebGLEngine;
35959
- exports.WebGLRenderer = WebGLRenderer;
36108
+ exports.WebGLGraphicDevice = WebGLGraphicDevice;
35960
36109
 
35961
36110
  var miniprogram$3 = /*#__PURE__*/Object.freeze({
35962
36111
  __proto__: null
@@ -35997,7 +36146,7 @@ function _interopNamespace(e) {
35997
36146
  }
35998
36147
  var CoreObjects__namespace = /*#__PURE__*/ _interopNamespace(CoreObjects);
35999
36148
  //@ts-ignore
36000
- var version = "0.0.0-experimental-0.9-plus.4";
36149
+ var version = "0.0.0-experimental-0.9-plus.5";
36001
36150
  console.log("Galacean engine version: " + version);
36002
36151
  for(var key in CoreObjects__namespace){
36003
36152
  CoreObjects.Loader.registerClass(key, CoreObjects__namespace[key]);