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

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.
@@ -15019,6 +15019,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15019
15019
  _this._fogEnd = 300;
15020
15020
  _this._fogDensity = 0.01;
15021
15021
  _this._fogParams = new miniprogram$7.Vector4();
15022
+ _this._sunlightVector3 = new miniprogram$7.Vector3();
15022
15023
  _this.name = name || "";
15023
15024
  var shaderData = _this.shaderData;
15024
15025
  shaderData._addRefCount(1);
@@ -15174,7 +15175,13 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15174
15175
  lightManager._updateShaderData(this.shaderData);
15175
15176
  var sunLightIndex = lightManager._getSunLightIndex();
15176
15177
  if (sunLightIndex !== -1) {
15177
- this._sunLight = lightManager._directLights.get(sunLightIndex);
15178
+ var sunlight = lightManager._directLights.get(sunLightIndex);
15179
+ var sunlightColor = sunlight.color;
15180
+ var sunlightIntensity = sunlight.intensity;
15181
+ this._sunlightVector3.set(sunlightColor.r * sunlightIntensity, sunlightColor.g * sunlightIntensity, sunlightColor.b * sunlightIntensity);
15182
+ shaderData.setVector3(Scene._sunlightColorProperty, this._sunlightVector3);
15183
+ shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
15184
+ this._sunLight = sunlight;
15178
15185
  }
15179
15186
  if (this.castShadows && this._sunLight && this._sunLight.shadowType !== exports.ShadowType.None) {
15180
15187
  shaderData.enableMacro("SHADOW_TYPE", this._sunLight.shadowType.toString());
@@ -15366,6 +15373,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15366
15373
  (function() {
15367
15374
  Scene._fogParamsProperty = Shader.getPropertyByName("oasis_FogParams");
15368
15375
  })();
15376
+ (function() {
15377
+ Scene._sunlightColorProperty = Shader.getPropertyByName("galacean_SunlightColor");
15378
+ })();
15379
+ (function() {
15380
+ Scene._sunlightDirectionProperty = Shader.getPropertyByName("galacean_SunlightDirection");
15381
+ })();
15369
15382
  /**
15370
15383
  * Scene manager.
15371
15384
  */ var SceneManager = /*#__PURE__*/ function() {
@@ -34244,6 +34257,38 @@ function _inherits(subClass, superClass) {
34244
34257
  });
34245
34258
  if (superClass) _set_prototype_of(subClass, superClass);
34246
34259
  }
34260
+ /**
34261
+ * WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
34262
+ */ var WebGLEngine = /*#__PURE__*/ function(Engine) {
34263
+ var WebGLEngine = function WebGLEngine() {
34264
+ return Engine.apply(this, arguments);
34265
+ };
34266
+ _inherits(WebGLEngine, Engine);
34267
+ /**
34268
+ * Create a WebGL engine.
34269
+ * @param configuration - WebGL engine configuration
34270
+ * @returns A promise that will resolve when the engine is created
34271
+ */ WebGLEngine.create = function create(configuration) {
34272
+ var canvas = configuration.canvas;
34273
+ var webCanvas = new WebCanvas(typeof canvas === "string" ? engineMiniprogramAdapter.document.getElementById(canvas) : canvas);
34274
+ var webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
34275
+ var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
34276
+ // @ts-ignore
34277
+ return engine._initialize(configuration);
34278
+ };
34279
+ _create_class(WebGLEngine, [
34280
+ {
34281
+ key: "canvas",
34282
+ get: /**
34283
+ * Web canvas.
34284
+ */ function get() {
34285
+ // @ts-ignore
34286
+ return this._canvas;
34287
+ }
34288
+ }
34289
+ ]);
34290
+ return WebGLEngine;
34291
+ }(miniprogram$1$1.Engine);
34247
34292
  function _extends() {
34248
34293
  _extends = Object.assign || function assign(target) {
34249
34294
  for(var i = 1; i < arguments.length; i++){
@@ -34254,6 +34299,83 @@ function _extends() {
34254
34299
  };
34255
34300
  return _extends.apply(this, arguments);
34256
34301
  }
34302
+ var GLBuffer = /*#__PURE__*/ function() {
34303
+ var GLBuffer = function GLBuffer(rhi, type, byteLength, bufferUsage, data) {
34304
+ if (bufferUsage === void 0) bufferUsage = miniprogram$1$1.BufferUsage.Static;
34305
+ var gl = rhi.gl;
34306
+ var glBuffer = gl.createBuffer();
34307
+ var glBufferUsage = this._getGLBufferUsage(gl, bufferUsage);
34308
+ var glBindTarget = type === miniprogram$1$1.BufferBindFlag.VertexBuffer ? gl.ARRAY_BUFFER : gl.ELEMENT_ARRAY_BUFFER;
34309
+ this._gl = gl;
34310
+ this._glBuffer = glBuffer;
34311
+ this._glBufferUsage = glBufferUsage;
34312
+ this._glBindTarget = glBindTarget;
34313
+ this._isWebGL2 = rhi.isWebGL2;
34314
+ this.bind();
34315
+ if (data) {
34316
+ gl.bufferData(glBindTarget, data, glBufferUsage);
34317
+ } else {
34318
+ gl.bufferData(glBindTarget, byteLength, glBufferUsage);
34319
+ }
34320
+ gl.bindBuffer(glBindTarget, null);
34321
+ };
34322
+ var _proto = GLBuffer.prototype;
34323
+ _proto.bind = function bind() {
34324
+ this._gl.bindBuffer(this._glBindTarget, this._glBuffer);
34325
+ };
34326
+ _proto.setData = function setData(byteLength, data, bufferByteOffset, dataOffset, dataLength, options) {
34327
+ var gl = this._gl;
34328
+ var glBindTarget = this._glBindTarget;
34329
+ this.bind();
34330
+ if (options === miniprogram$1$1.SetDataOptions.Discard) {
34331
+ gl.bufferData(glBindTarget, byteLength, this._glBufferUsage);
34332
+ }
34333
+ // TypeArray is BYTES_PER_ELEMENT, unTypeArray is 1
34334
+ var byteSize = data.BYTES_PER_ELEMENT || 1;
34335
+ var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
34336
+ if (dataOffset !== 0 || dataByteLength < data.byteLength) {
34337
+ var isArrayBufferView = data.byteOffset !== undefined;
34338
+ if (this._isWebGL2 && isArrayBufferView) {
34339
+ gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
34340
+ } else {
34341
+ var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
34342
+ gl.bufferSubData(glBindTarget, bufferByteOffset, subData);
34343
+ }
34344
+ } else {
34345
+ gl.bufferSubData(glBindTarget, bufferByteOffset, data);
34346
+ }
34347
+ gl.bindBuffer(glBindTarget, null);
34348
+ };
34349
+ _proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
34350
+ if (this._isWebGL2) {
34351
+ var gl = this._gl;
34352
+ this.bind();
34353
+ gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
34354
+ } else {
34355
+ throw "Buffer is write-only on WebGL1.0 platforms.";
34356
+ }
34357
+ };
34358
+ _proto.resize = function resize(byteLength) {
34359
+ this.bind();
34360
+ this._gl.bufferData(this._glBindTarget, byteLength, this._glBufferUsage);
34361
+ };
34362
+ _proto.destroy = function destroy() {
34363
+ this._gl.deleteBuffer(this._glBuffer);
34364
+ this._gl = null;
34365
+ this._glBuffer = null;
34366
+ };
34367
+ _proto._getGLBufferUsage = function _getGLBufferUsage(gl, bufferUsage) {
34368
+ switch(bufferUsage){
34369
+ case miniprogram$1$1.BufferUsage.Static:
34370
+ return gl.STATIC_DRAW;
34371
+ case miniprogram$1$1.BufferUsage.Dynamic:
34372
+ return gl.DYNAMIC_DRAW;
34373
+ case miniprogram$1$1.BufferUsage.Stream:
34374
+ return gl.STREAM_DRAW;
34375
+ }
34376
+ };
34377
+ return GLBuffer;
34378
+ }();
34257
34379
  /**
34258
34380
  * GL capability.
34259
34381
  */ var GLCapability = /*#__PURE__*/ function() {
@@ -34516,8 +34638,8 @@ function _extends() {
34516
34638
  if (useVao) {
34517
34639
  gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
34518
34640
  } else {
34519
- var _nativeBuffer = _indexBufferBinding.buffer._nativeBuffer;
34520
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer);
34641
+ var _glBuffer = _indexBufferBinding.buffer._platformBuffer._glBuffer;
34642
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer);
34521
34643
  gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
34522
34644
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
34523
34645
  }
@@ -34530,8 +34652,8 @@ function _extends() {
34530
34652
  if (useVao) {
34531
34653
  gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
34532
34654
  } else {
34533
- var _nativeBuffer1 = _indexBufferBinding.buffer._nativeBuffer;
34534
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer1);
34655
+ var _glBuffer1 = _indexBufferBinding.buffer._platformBuffer._glBuffer;
34656
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
34535
34657
  gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
34536
34658
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
34537
34659
  }
@@ -34571,7 +34693,7 @@ function _extends() {
34571
34693
  var element = attributes[name];
34572
34694
  if (element) {
34573
34695
  var _vertexBufferBindings_element_bindingIndex = vertexBufferBindings[element.bindingIndex], buffer = _vertexBufferBindings_element_bindingIndex.buffer, stride = _vertexBufferBindings_element_bindingIndex.stride;
34574
- vbo = buffer._nativeBuffer;
34696
+ vbo = buffer._platformBuffer._glBuffer;
34575
34697
  // prevent binding the vbo which already bound at the last loop, e.g. a buffer with multiple attributes.
34576
34698
  if (lastBoundVbo !== vbo) {
34577
34699
  lastBoundVbo = vbo;
@@ -34603,7 +34725,7 @@ function _extends() {
34603
34725
  // @ts-ignore
34604
34726
  var _indexBufferBinding = this._primitive._indexBufferBinding;
34605
34727
  if (_indexBufferBinding) {
34606
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._nativeBuffer);
34728
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._platformBuffer._glBuffer);
34607
34729
  }
34608
34730
  this._bindBufferAndAttrib(shaderProgram);
34609
34731
  /** unbind */ gl.bindVertexArray(null);
@@ -35660,23 +35782,21 @@ exports.WebGLMode = void 0;
35660
35782
  WebGLMode[WebGLMode[/** WebGL1.0, */ "WebGL1"] = 2] = "WebGL1";
35661
35783
  })(exports.WebGLMode || (exports.WebGLMode = {}));
35662
35784
  /**
35663
- * WebGL renderer, including WebGL1.0 and WebGL2.0.
35664
- */ var WebGLRenderer = /*#__PURE__*/ function() {
35665
- var WebGLRenderer = function WebGLRenderer(initializeOptions) {
35785
+ * WebGL graphic device, including WebGL1.0 and WebGL2.0.
35786
+ */ var WebGLGraphicDevice = /*#__PURE__*/ function() {
35787
+ var WebGLGraphicDevice = function WebGLGraphicDevice(initializeOptions) {
35666
35788
  if (initializeOptions === void 0) initializeOptions = {};
35789
+ /** @internal */ this._readFrameBuffer = null;
35667
35790
  /** @internal */ this._enableGlobalDepthBias = false;
35668
35791
  this._activeTextures = new Array(32);
35669
- // cache value
35670
35792
  this._lastViewport = new miniprogram$1.Vector4(null, null, null, null);
35671
35793
  this._lastScissor = new miniprogram$1.Vector4(null, null, null, null);
35672
35794
  this._lastClearColor = new miniprogram$1.Color(null, null, null, null);
35673
35795
  this._scissorEnable = false;
35674
35796
  var options = _extends({
35675
35797
  webGLMode: 0,
35676
- alpha: false,
35677
35798
  stencil: true,
35678
- _forceFlush: false,
35679
- _maxAllowSkinUniformVectorCount: 256
35799
+ _forceFlush: false
35680
35800
  }, initializeOptions);
35681
35801
  if (miniprogram$1$1.SystemInfo.platform === miniprogram$1$1.Platform.IPhone || miniprogram$1$1.SystemInfo.platform === miniprogram$1$1.Platform.IPad) {
35682
35802
  var version = miniprogram$1$1.SystemInfo.operatingSystem.match(/(\d+).?(\d+)?.?(\d+)?/);
@@ -35689,12 +35809,20 @@ exports.WebGLMode = void 0;
35689
35809
  }
35690
35810
  }
35691
35811
  this._options = options;
35812
+ this._onWebGLContextLost = this._onWebGLContextLost.bind(this);
35813
+ this._onWebGLContextRestored = this._onWebGLContextRestored.bind(this);
35692
35814
  };
35693
- var _proto = WebGLRenderer.prototype;
35694
- _proto.init = function init(canvas) {
35815
+ var _proto = WebGLGraphicDevice.prototype;
35816
+ _proto.init = function init(canvas, onDeviceLost, onDeviceRestored) {
35695
35817
  var options = this._options;
35696
- var webCanvas = this._webCanvas = canvas._webCanvas;
35818
+ var webCanvas = canvas._webCanvas;
35697
35819
  var webGLMode = options.webGLMode;
35820
+ this._onDeviceLost = onDeviceLost;
35821
+ this._onDeviceRestored = onDeviceRestored;
35822
+ webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
35823
+ webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
35824
+ webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
35825
+ this._webCanvas = webCanvas;
35698
35826
  var gl;
35699
35827
  if (webGLMode == 0 || webGLMode == 1) {
35700
35828
  gl = webCanvas.getContext("webgl2", options);
@@ -35720,16 +35848,7 @@ exports.WebGLMode = void 0;
35720
35848
  throw new Error("Get GL Context FAILED.");
35721
35849
  }
35722
35850
  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
- }
35851
+ this._initGLState(gl);
35733
35852
  };
35734
35853
  _proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
35735
35854
  return new GLPrimitive(this, primitive);
@@ -35746,6 +35865,10 @@ exports.WebGLMode = void 0;
35746
35865
  _proto.createPlatformRenderTarget = function createPlatformRenderTarget(target) {
35747
35866
  return new GLRenderTarget(this, target);
35748
35867
  };
35868
+ _proto.createPlatformBuffer = function createPlatformBuffer(type, byteLength, bufferUsage, data) {
35869
+ if (bufferUsage === void 0) bufferUsage = miniprogram$1$1.BufferUsage.Static;
35870
+ return new GLBuffer(this, type, byteLength, bufferUsage, data);
35871
+ };
35749
35872
  _proto.requireExtension = function requireExtension(ext) {
35750
35873
  return this._extensions.requireExtension(ext);
35751
35874
  };
@@ -35873,8 +35996,57 @@ exports.WebGLMode = void 0;
35873
35996
  _proto.flush = function flush() {
35874
35997
  this._gl.flush();
35875
35998
  };
35876
- _proto.destroy = function destroy() {};
35877
- _create_class(WebGLRenderer, [
35999
+ _proto.forceLoseDevice = function forceLoseDevice() {
36000
+ var extension = this.requireExtension(miniprogram$1$1.GLCapabilityType.WEBGL_lose_context);
36001
+ extension.loseContext();
36002
+ };
36003
+ _proto.forceRestoreDevice = function forceRestoreDevice() {
36004
+ var extension = this.requireExtension(miniprogram$1$1.GLCapabilityType.WEBGL_lose_context);
36005
+ extension.restoreContext();
36006
+ };
36007
+ _proto.resetState = function resetState() {
36008
+ this._readFrameBuffer = null;
36009
+ this._enableGlobalDepthBias = false;
36010
+ this._currentBindShaderProgram = null;
36011
+ var activeTextures = this._activeTextures;
36012
+ for(var i = 0, n = activeTextures.length; i < n; i++){
36013
+ activeTextures[i] = null;
36014
+ }
36015
+ this._lastViewport.set(null, null, null, null);
36016
+ this._lastScissor.set(null, null, null, null);
36017
+ this._lastClearColor.set(null, null, null, null);
36018
+ this._scissorEnable = false;
36019
+ this._initGLState(this._gl);
36020
+ };
36021
+ _proto._initGLState = function _initGLState(gl) {
36022
+ this._activeTextureID = gl.TEXTURE0;
36023
+ this._renderStates = new GLRenderStates(gl);
36024
+ this._extensions = new GLExtensions(this);
36025
+ this._capability = new GLCapability(this);
36026
+ // Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
36027
+ gl.activeTexture(gl.TEXTURE0);
36028
+ var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
36029
+ if (debugRenderInfo != null) {
36030
+ this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
36031
+ }
36032
+ };
36033
+ _proto.destroy = function destroy() {
36034
+ var webCanvas = this._webCanvas;
36035
+ webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
36036
+ webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
36037
+ webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
36038
+ };
36039
+ _proto._onContextCreationError = function _onContextCreationError(event) {
36040
+ console.error("WebGLRenderer: WebGL context could not be created. Reason: ", event.statusMessage);
36041
+ };
36042
+ _proto._onWebGLContextLost = function _onWebGLContextLost(event) {
36043
+ event.preventDefault();
36044
+ this._onDeviceLost();
36045
+ };
36046
+ _proto._onWebGLContextRestored = function _onWebGLContextRestored(event) {
36047
+ this._onDeviceRestored();
36048
+ };
36049
+ _create_class(WebGLGraphicDevice, [
35878
36050
  {
35879
36051
  key: "isWebGL2",
35880
36052
  get: function get() {
@@ -35915,32 +36087,11 @@ exports.WebGLMode = void 0;
35915
36087
  }
35916
36088
  }
35917
36089
  ]);
35918
- return WebGLRenderer;
36090
+ return WebGLGraphicDevice;
35919
36091
  }();
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
36092
  exports.WebCanvas = WebCanvas;
35942
36093
  exports.WebGLEngine = WebGLEngine;
35943
- exports.WebGLRenderer = WebGLRenderer;
36094
+ exports.WebGLGraphicDevice = WebGLGraphicDevice;
35944
36095
 
35945
36096
  var miniprogram$3 = /*#__PURE__*/Object.freeze({
35946
36097
  __proto__: null
@@ -35981,7 +36132,7 @@ function _interopNamespace(e) {
35981
36132
  }
35982
36133
  var CoreObjects__namespace = /*#__PURE__*/ _interopNamespace(CoreObjects);
35983
36134
  //@ts-ignore
35984
- var version = "0.0.0-experimental-0.9-plus.0";
36135
+ var version = "0.0.0-experimental-0.9-plus.2";
35985
36136
  console.log("Galacean engine version: " + version);
35986
36137
  for(var key in CoreObjects__namespace){
35987
36138
  CoreObjects.Loader.registerClass(key, CoreObjects__namespace[key]);