@galacean/engine-physics-lite 0.0.0-experimental-0.9-plus.0 → 0.0.0-experimental-0.9-plus.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15174,7 +15174,10 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15174
15174
  lightManager._updateShaderData(this.shaderData);
15175
15175
  var sunLightIndex = lightManager._getSunLightIndex();
15176
15176
  if (sunLightIndex !== -1) {
15177
- this._sunLight = lightManager._directLights.get(sunLightIndex);
15177
+ var sunlight = lightManager._directLights.get(sunLightIndex);
15178
+ shaderData.setColor(Scene._sunlightColorProperty, sunlight.color);
15179
+ shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
15180
+ this._sunLight = sunlight;
15178
15181
  }
15179
15182
  if (this.castShadows && this._sunLight && this._sunLight.shadowType !== exports.ShadowType.None) {
15180
15183
  shaderData.enableMacro("SHADOW_TYPE", this._sunLight.shadowType.toString());
@@ -15366,6 +15369,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15366
15369
  (function() {
15367
15370
  Scene._fogParamsProperty = Shader.getPropertyByName("oasis_FogParams");
15368
15371
  })();
15372
+ (function() {
15373
+ Scene._sunlightColorProperty = Shader.getPropertyByName("galacean_SunlightColor");
15374
+ })();
15375
+ (function() {
15376
+ Scene._sunlightDirectionProperty = Shader.getPropertyByName("galacean_SunlightDirection");
15377
+ })();
15369
15378
  /**
15370
15379
  * Scene manager.
15371
15380
  */ var SceneManager = /*#__PURE__*/ function() {
@@ -34244,6 +34253,38 @@ function _inherits(subClass, superClass) {
34244
34253
  });
34245
34254
  if (superClass) _set_prototype_of(subClass, superClass);
34246
34255
  }
34256
+ /**
34257
+ * WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
34258
+ */ var WebGLEngine = /*#__PURE__*/ function(Engine) {
34259
+ var WebGLEngine = function WebGLEngine() {
34260
+ return Engine.apply(this, arguments);
34261
+ };
34262
+ _inherits(WebGLEngine, Engine);
34263
+ /**
34264
+ * Create a WebGL engine.
34265
+ * @param configuration - WebGL engine configuration
34266
+ * @returns A promise that will resolve when the engine is created
34267
+ */ WebGLEngine.create = function create(configuration) {
34268
+ var canvas = configuration.canvas;
34269
+ var webCanvas = new WebCanvas(typeof canvas === "string" ? engineMiniprogramAdapter.document.getElementById(canvas) : canvas);
34270
+ var webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
34271
+ var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
34272
+ // @ts-ignore
34273
+ return engine._initialize(configuration);
34274
+ };
34275
+ _create_class(WebGLEngine, [
34276
+ {
34277
+ key: "canvas",
34278
+ get: /**
34279
+ * Web canvas.
34280
+ */ function get() {
34281
+ // @ts-ignore
34282
+ return this._canvas;
34283
+ }
34284
+ }
34285
+ ]);
34286
+ return WebGLEngine;
34287
+ }(miniprogram$1$1.Engine);
34247
34288
  function _extends() {
34248
34289
  _extends = Object.assign || function assign(target) {
34249
34290
  for(var i = 1; i < arguments.length; i++){
@@ -34254,6 +34295,83 @@ function _extends() {
34254
34295
  };
34255
34296
  return _extends.apply(this, arguments);
34256
34297
  }
34298
+ var GLBuffer = /*#__PURE__*/ function() {
34299
+ var GLBuffer = function GLBuffer(rhi, type, byteLength, bufferUsage, data) {
34300
+ if (bufferUsage === void 0) bufferUsage = miniprogram$1$1.BufferUsage.Static;
34301
+ var gl = rhi.gl;
34302
+ var glBuffer = gl.createBuffer();
34303
+ var glBufferUsage = this._getGLBufferUsage(gl, bufferUsage);
34304
+ var glBindTarget = type === miniprogram$1$1.BufferBindFlag.VertexBuffer ? gl.ARRAY_BUFFER : gl.ELEMENT_ARRAY_BUFFER;
34305
+ this._gl = gl;
34306
+ this._glBuffer = glBuffer;
34307
+ this._glBufferUsage = glBufferUsage;
34308
+ this._glBindTarget = glBindTarget;
34309
+ this._isWebGL2 = rhi.isWebGL2;
34310
+ this.bind();
34311
+ if (data) {
34312
+ gl.bufferData(glBindTarget, data, glBufferUsage);
34313
+ } else {
34314
+ gl.bufferData(glBindTarget, byteLength, glBufferUsage);
34315
+ }
34316
+ gl.bindBuffer(glBindTarget, null);
34317
+ };
34318
+ var _proto = GLBuffer.prototype;
34319
+ _proto.bind = function bind() {
34320
+ this._gl.bindBuffer(this._glBindTarget, this._glBuffer);
34321
+ };
34322
+ _proto.setData = function setData(byteLength, data, bufferByteOffset, dataOffset, dataLength, options) {
34323
+ var gl = this._gl;
34324
+ var glBindTarget = this._glBindTarget;
34325
+ this.bind();
34326
+ if (options === miniprogram$1$1.SetDataOptions.Discard) {
34327
+ gl.bufferData(glBindTarget, byteLength, this._glBufferUsage);
34328
+ }
34329
+ // TypeArray is BYTES_PER_ELEMENT, unTypeArray is 1
34330
+ var byteSize = data.BYTES_PER_ELEMENT || 1;
34331
+ var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
34332
+ if (dataOffset !== 0 || dataByteLength < data.byteLength) {
34333
+ var isArrayBufferView = data.byteOffset !== undefined;
34334
+ if (this._isWebGL2 && isArrayBufferView) {
34335
+ gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
34336
+ } else {
34337
+ var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
34338
+ gl.bufferSubData(glBindTarget, bufferByteOffset, subData);
34339
+ }
34340
+ } else {
34341
+ gl.bufferSubData(glBindTarget, bufferByteOffset, data);
34342
+ }
34343
+ gl.bindBuffer(glBindTarget, null);
34344
+ };
34345
+ _proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
34346
+ if (this._isWebGL2) {
34347
+ var gl = this._gl;
34348
+ this.bind();
34349
+ gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
34350
+ } else {
34351
+ throw "Buffer is write-only on WebGL1.0 platforms.";
34352
+ }
34353
+ };
34354
+ _proto.resize = function resize(byteLength) {
34355
+ this.bind();
34356
+ this._gl.bufferData(this._glBindTarget, byteLength, this._glBufferUsage);
34357
+ };
34358
+ _proto.destroy = function destroy() {
34359
+ this._gl.deleteBuffer(this._glBuffer);
34360
+ this._gl = null;
34361
+ this._glBuffer = null;
34362
+ };
34363
+ _proto._getGLBufferUsage = function _getGLBufferUsage(gl, bufferUsage) {
34364
+ switch(bufferUsage){
34365
+ case miniprogram$1$1.BufferUsage.Static:
34366
+ return gl.STATIC_DRAW;
34367
+ case miniprogram$1$1.BufferUsage.Dynamic:
34368
+ return gl.DYNAMIC_DRAW;
34369
+ case miniprogram$1$1.BufferUsage.Stream:
34370
+ return gl.STREAM_DRAW;
34371
+ }
34372
+ };
34373
+ return GLBuffer;
34374
+ }();
34257
34375
  /**
34258
34376
  * GL capability.
34259
34377
  */ var GLCapability = /*#__PURE__*/ function() {
@@ -34516,8 +34634,8 @@ function _extends() {
34516
34634
  if (useVao) {
34517
34635
  gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
34518
34636
  } else {
34519
- var _nativeBuffer = _indexBufferBinding.buffer._nativeBuffer;
34520
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer);
34637
+ var _glBuffer = _indexBufferBinding.buffer._platformBuffer._glBuffer;
34638
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer);
34521
34639
  gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
34522
34640
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
34523
34641
  }
@@ -34530,8 +34648,8 @@ function _extends() {
34530
34648
  if (useVao) {
34531
34649
  gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
34532
34650
  } else {
34533
- var _nativeBuffer1 = _indexBufferBinding.buffer._nativeBuffer;
34534
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer1);
34651
+ var _glBuffer1 = _indexBufferBinding.buffer._platformBuffer._glBuffer;
34652
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
34535
34653
  gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
34536
34654
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
34537
34655
  }
@@ -34571,7 +34689,7 @@ function _extends() {
34571
34689
  var element = attributes[name];
34572
34690
  if (element) {
34573
34691
  var _vertexBufferBindings_element_bindingIndex = vertexBufferBindings[element.bindingIndex], buffer = _vertexBufferBindings_element_bindingIndex.buffer, stride = _vertexBufferBindings_element_bindingIndex.stride;
34574
- vbo = buffer._nativeBuffer;
34692
+ vbo = buffer._platformBuffer._glBuffer;
34575
34693
  // prevent binding the vbo which already bound at the last loop, e.g. a buffer with multiple attributes.
34576
34694
  if (lastBoundVbo !== vbo) {
34577
34695
  lastBoundVbo = vbo;
@@ -34603,7 +34721,7 @@ function _extends() {
34603
34721
  // @ts-ignore
34604
34722
  var _indexBufferBinding = this._primitive._indexBufferBinding;
34605
34723
  if (_indexBufferBinding) {
34606
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._nativeBuffer);
34724
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._platformBuffer._glBuffer);
34607
34725
  }
34608
34726
  this._bindBufferAndAttrib(shaderProgram);
34609
34727
  /** unbind */ gl.bindVertexArray(null);
@@ -35660,23 +35778,21 @@ exports.WebGLMode = void 0;
35660
35778
  WebGLMode[WebGLMode[/** WebGL1.0, */ "WebGL1"] = 2] = "WebGL1";
35661
35779
  })(exports.WebGLMode || (exports.WebGLMode = {}));
35662
35780
  /**
35663
- * WebGL renderer, including WebGL1.0 and WebGL2.0.
35664
- */ var WebGLRenderer = /*#__PURE__*/ function() {
35665
- var WebGLRenderer = function WebGLRenderer(initializeOptions) {
35781
+ * WebGL graphic device, including WebGL1.0 and WebGL2.0.
35782
+ */ var WebGLGraphicDevice = /*#__PURE__*/ function() {
35783
+ var WebGLGraphicDevice = function WebGLGraphicDevice(initializeOptions) {
35666
35784
  if (initializeOptions === void 0) initializeOptions = {};
35785
+ /** @internal */ this._readFrameBuffer = null;
35667
35786
  /** @internal */ this._enableGlobalDepthBias = false;
35668
35787
  this._activeTextures = new Array(32);
35669
- // cache value
35670
35788
  this._lastViewport = new miniprogram$1.Vector4(null, null, null, null);
35671
35789
  this._lastScissor = new miniprogram$1.Vector4(null, null, null, null);
35672
35790
  this._lastClearColor = new miniprogram$1.Color(null, null, null, null);
35673
35791
  this._scissorEnable = false;
35674
35792
  var options = _extends({
35675
35793
  webGLMode: 0,
35676
- alpha: false,
35677
35794
  stencil: true,
35678
- _forceFlush: false,
35679
- _maxAllowSkinUniformVectorCount: 256
35795
+ _forceFlush: false
35680
35796
  }, initializeOptions);
35681
35797
  if (miniprogram$1$1.SystemInfo.platform === miniprogram$1$1.Platform.IPhone || miniprogram$1$1.SystemInfo.platform === miniprogram$1$1.Platform.IPad) {
35682
35798
  var version = miniprogram$1$1.SystemInfo.operatingSystem.match(/(\d+).?(\d+)?.?(\d+)?/);
@@ -35689,12 +35805,20 @@ exports.WebGLMode = void 0;
35689
35805
  }
35690
35806
  }
35691
35807
  this._options = options;
35808
+ this._onWebGLContextLost = this._onWebGLContextLost.bind(this);
35809
+ this._onWebGLContextRestored = this._onWebGLContextRestored.bind(this);
35692
35810
  };
35693
- var _proto = WebGLRenderer.prototype;
35694
- _proto.init = function init(canvas) {
35811
+ var _proto = WebGLGraphicDevice.prototype;
35812
+ _proto.init = function init(canvas, onDeviceLost, onDeviceRestored) {
35695
35813
  var options = this._options;
35696
- var webCanvas = this._webCanvas = canvas._webCanvas;
35814
+ var webCanvas = canvas._webCanvas;
35697
35815
  var webGLMode = options.webGLMode;
35816
+ this._onDeviceLost = onDeviceLost;
35817
+ this._onDeviceRestored = onDeviceRestored;
35818
+ webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
35819
+ webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
35820
+ webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
35821
+ this._webCanvas = webCanvas;
35698
35822
  var gl;
35699
35823
  if (webGLMode == 0 || webGLMode == 1) {
35700
35824
  gl = webCanvas.getContext("webgl2", options);
@@ -35720,16 +35844,7 @@ exports.WebGLMode = void 0;
35720
35844
  throw new Error("Get GL Context FAILED.");
35721
35845
  }
35722
35846
  this._gl = gl;
35723
- this._activeTextureID = gl.TEXTURE0;
35724
- this._renderStates = new GLRenderStates(gl);
35725
- this._extensions = new GLExtensions(this);
35726
- this._capability = new GLCapability(this);
35727
- // Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
35728
- gl.activeTexture(gl.TEXTURE0);
35729
- var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
35730
- if (debugRenderInfo != null) {
35731
- this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
35732
- }
35847
+ this._initGLState(gl);
35733
35848
  };
35734
35849
  _proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
35735
35850
  return new GLPrimitive(this, primitive);
@@ -35746,6 +35861,10 @@ exports.WebGLMode = void 0;
35746
35861
  _proto.createPlatformRenderTarget = function createPlatformRenderTarget(target) {
35747
35862
  return new GLRenderTarget(this, target);
35748
35863
  };
35864
+ _proto.createPlatformBuffer = function createPlatformBuffer(type, byteLength, bufferUsage, data) {
35865
+ if (bufferUsage === void 0) bufferUsage = miniprogram$1$1.BufferUsage.Static;
35866
+ return new GLBuffer(this, type, byteLength, bufferUsage, data);
35867
+ };
35749
35868
  _proto.requireExtension = function requireExtension(ext) {
35750
35869
  return this._extensions.requireExtension(ext);
35751
35870
  };
@@ -35873,8 +35992,57 @@ exports.WebGLMode = void 0;
35873
35992
  _proto.flush = function flush() {
35874
35993
  this._gl.flush();
35875
35994
  };
35876
- _proto.destroy = function destroy() {};
35877
- _create_class(WebGLRenderer, [
35995
+ _proto.forceLoseDevice = function forceLoseDevice() {
35996
+ var extension = this.requireExtension(miniprogram$1$1.GLCapabilityType.WEBGL_lose_context);
35997
+ extension.loseContext();
35998
+ };
35999
+ _proto.forceRestoreDevice = function forceRestoreDevice() {
36000
+ var extension = this.requireExtension(miniprogram$1$1.GLCapabilityType.WEBGL_lose_context);
36001
+ extension.restoreContext();
36002
+ };
36003
+ _proto.resetState = function resetState() {
36004
+ this._readFrameBuffer = null;
36005
+ this._enableGlobalDepthBias = false;
36006
+ this._currentBindShaderProgram = null;
36007
+ var activeTextures = this._activeTextures;
36008
+ for(var i = 0, n = activeTextures.length; i < n; i++){
36009
+ activeTextures[i] = null;
36010
+ }
36011
+ this._lastViewport.set(null, null, null, null);
36012
+ this._lastScissor.set(null, null, null, null);
36013
+ this._lastClearColor.set(null, null, null, null);
36014
+ this._scissorEnable = false;
36015
+ this._initGLState(this._gl);
36016
+ };
36017
+ _proto._initGLState = function _initGLState(gl) {
36018
+ this._activeTextureID = gl.TEXTURE0;
36019
+ this._renderStates = new GLRenderStates(gl);
36020
+ this._extensions = new GLExtensions(this);
36021
+ this._capability = new GLCapability(this);
36022
+ // Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
36023
+ gl.activeTexture(gl.TEXTURE0);
36024
+ var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
36025
+ if (debugRenderInfo != null) {
36026
+ this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
36027
+ }
36028
+ };
36029
+ _proto.destroy = function destroy() {
36030
+ var webCanvas = this._webCanvas;
36031
+ webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
36032
+ webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
36033
+ webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
36034
+ };
36035
+ _proto._onContextCreationError = function _onContextCreationError(event) {
36036
+ console.error("WebGLRenderer: WebGL context could not be created. Reason: ", event.statusMessage);
36037
+ };
36038
+ _proto._onWebGLContextLost = function _onWebGLContextLost(event) {
36039
+ event.preventDefault();
36040
+ this._onDeviceLost();
36041
+ };
36042
+ _proto._onWebGLContextRestored = function _onWebGLContextRestored(event) {
36043
+ this._onDeviceRestored();
36044
+ };
36045
+ _create_class(WebGLGraphicDevice, [
35878
36046
  {
35879
36047
  key: "isWebGL2",
35880
36048
  get: function get() {
@@ -35915,32 +36083,11 @@ exports.WebGLMode = void 0;
35915
36083
  }
35916
36084
  }
35917
36085
  ]);
35918
- return WebGLRenderer;
36086
+ return WebGLGraphicDevice;
35919
36087
  }();
35920
- /**
35921
- * WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
35922
- */ var WebGLEngine = /*#__PURE__*/ function(Engine) {
35923
- var WebGLEngine = function WebGLEngine(canvas, webGLRendererOptions) {
35924
- var webCanvas = new WebCanvas(typeof canvas === "string" ? engineMiniprogramAdapter.document.getElementById(canvas) : canvas);
35925
- var hardwareRenderer = new WebGLRenderer(webGLRendererOptions);
35926
- return Engine.call(this, webCanvas, hardwareRenderer);
35927
- };
35928
- _inherits(WebGLEngine, Engine);
35929
- _create_class(WebGLEngine, [
35930
- {
35931
- key: "canvas",
35932
- get: /**
35933
- * Web canvas.
35934
- */ function get() {
35935
- return this._canvas;
35936
- }
35937
- }
35938
- ]);
35939
- return WebGLEngine;
35940
- }(miniprogram$1$1.Engine);
35941
36088
  exports.WebCanvas = WebCanvas;
35942
36089
  exports.WebGLEngine = WebGLEngine;
35943
- exports.WebGLRenderer = WebGLRenderer;
36090
+ exports.WebGLGraphicDevice = WebGLGraphicDevice;
35944
36091
 
35945
36092
  var miniprogram$3 = /*#__PURE__*/Object.freeze({
35946
36093
  __proto__: null
@@ -35981,7 +36128,7 @@ function _interopNamespace(e) {
35981
36128
  }
35982
36129
  var CoreObjects__namespace = /*#__PURE__*/ _interopNamespace(CoreObjects);
35983
36130
  //@ts-ignore
35984
- var version = "0.0.0-experimental-0.9-plus.0";
36131
+ var version = "0.0.0-experimental-0.9-plus.1";
35985
36132
  console.log("Galacean engine version: " + version);
35986
36133
  for(var key in CoreObjects__namespace){
35987
36134
  CoreObjects.Loader.registerClass(key, CoreObjects__namespace[key]);