@galacean/engine 0.9.0 → 0.9.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.
package/dist/browser.js CHANGED
@@ -17730,6 +17730,7 @@
17730
17730
  var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
17731
17731
  var _this;
17732
17732
  _this = MeshRenderer.call(this, entity) || this;
17733
+ _this._supportSkinning = false;
17733
17734
  _this._hasInitSkin = false;
17734
17735
  _this._jointDataCreateCache = new Vector2(-1, -1);
17735
17736
  _this._localBounds = new BoundingBox();
@@ -17739,7 +17740,7 @@
17739
17740
  // Limit size to 256 to avoid some problem:
17740
17741
  // For renderer is "Apple GPU", when uniform is large than 256 the skeleton matrix array access in shader very slow in Safari or WKWebview. This may be a apple bug, Chrome and Firefox is OK!
17741
17742
  // For renderer is "ANGLE (AMD, AMD Radeon(TM) Graphics Direct3011 vs_5_0 ps_5_0, D3011)", compile shader si very slow because of max uniform is 4096.
17742
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, 256);
17743
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
17743
17744
  _this._maxVertexUniformVectors = maxVertexUniformVectors;
17744
17745
  _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
17745
17746
  var localBounds = _this._localBounds;
@@ -17758,9 +17759,8 @@
17758
17759
  this._initSkin();
17759
17760
  this._hasInitSkin = true;
17760
17761
  }
17761
- var skin = this._skin;
17762
- if (skin) {
17763
- var ibms = skin.inverseBindMatrices;
17762
+ if (this._supportSkinning) {
17763
+ var ibms = this._skin.inverseBindMatrices;
17764
17764
  var worldToLocal = this._rootBone.getInvModelMatrix();
17765
17765
  var _this = this, joints = _this._jointEntities, jointMatrices = _this._jointMatrices;
17766
17766
  for(var i = joints.length - 1; i >= 0; i--){
@@ -17779,8 +17779,6 @@
17779
17779
  * @override
17780
17780
  */ _proto._updateShaderData = function _updateShaderData(context) {
17781
17781
  var entity = this.entity;
17782
- var worldMatrix = this._rootBone ? this._rootBone.transform.worldMatrix : entity.transform.worldMatrix;
17783
- this._updateTransformShaderData(context, worldMatrix);
17784
17782
  var shaderData = this.shaderData;
17785
17783
  var mesh = this.mesh;
17786
17784
  var blendShapeManager = mesh._blendShapeManager;
@@ -17807,12 +17805,18 @@
17807
17805
  shaderData.disableMacro("O3_JOINTS_NUM");
17808
17806
  shaderData.enableMacro("O3_USE_JOINT_TEXTURE");
17809
17807
  shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
17808
+ this._supportSkinning = true;
17810
17809
  } else {
17811
- Logger.error("component's joints count(" + jointCount + ") greater than device's MAX_VERTEX_UNIFORM_VECTORS number " + this._maxVertexUniformVectors + ", and don't support jointTexture in this device. suggest joint count less than " + remainUniformJointCount + ".", this);
17810
+ var _this__jointTexture1;
17811
+ this._supportSkinning = false;
17812
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
17813
+ shaderData.disableMacro("O3_HAS_SKIN");
17814
+ Logger.warn("component's joints count(" + jointCount + ") greater than device's MAX_VERTEX_UNIFORM_VECTORS number " + this._maxVertexUniformVectors + ", and don't support jointTexture in this device. suggest joint count less than " + remainUniformJointCount + ".", this);
17812
17815
  }
17813
17816
  } else {
17814
- var _this__jointTexture1;
17815
- (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
17817
+ var _this__jointTexture2;
17818
+ this._supportSkinning = true;
17819
+ (_this__jointTexture2 = this._jointTexture) == null ? void 0 : _this__jointTexture2.destroy();
17816
17820
  shaderData.disableMacro("O3_USE_JOINT_TEXTURE");
17817
17821
  shaderData.enableMacro("O3_JOINTS_NUM", remainUniformJointCount.toString());
17818
17822
  shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, this._jointMatrices);
@@ -17823,6 +17827,8 @@
17823
17827
  this._jointTexture.setPixelBuffer(this._jointMatrices);
17824
17828
  }
17825
17829
  }
17830
+ var worldMatrix = this._supportSkinning && this._rootBone ? this._rootBone.transform.worldMatrix : entity.transform.worldMatrix;
17831
+ this._updateTransformShaderData(context, worldMatrix);
17826
17832
  var layer = entity.layer;
17827
17833
  this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
17828
17834
  };
@@ -18017,6 +18023,9 @@
18017
18023
  (function() {
18018
18024
  SkinnedMeshRenderer._jointMatrixProperty = Shader.getPropertyByName("u_jointMatrix");
18019
18025
  })();
18026
+ __decorate$1([
18027
+ ignoreClone
18028
+ ], SkinnedMeshRenderer.prototype, "_supportSkinning", void 0);
18020
18029
  __decorate$1([
18021
18030
  ignoreClone
18022
18031
  ], SkinnedMeshRenderer.prototype, "_hasInitSkin", void 0);
@@ -31040,7 +31049,8 @@
31040
31049
  webGLMode: 0,
31041
31050
  alpha: false,
31042
31051
  stencil: true,
31043
- _forceFlush: false
31052
+ _forceFlush: false,
31053
+ _maxAllowSkinUniformVectorCount: 256
31044
31054
  }, initializeOptions);
31045
31055
  if (SystemInfo.platform === exports.Platform.IPhone || SystemInfo.platform === exports.Platform.IPad) {
31046
31056
  var version = SystemInfo.operatingSystem.match(/(\d+).?(\d+)?.?(\d+)?/);
@@ -33126,21 +33136,31 @@
33126
33136
  var vertexCount;
33127
33137
  var bufferBindIndex = 0;
33128
33138
  var positions;
33129
- keepMeshData && (positions = new Array(vertexCount));
33139
+ var boneIndices;
33140
+ var boneWeights;
33141
+ if (keepMeshData) {
33142
+ positions = new Array(vertexCount);
33143
+ boneIndices = new Array(vertexCount);
33144
+ boneWeights = new Array(vertexCount);
33145
+ }
33130
33146
  for(var attribute in attributes){
33131
33147
  var accessor = accessors[attributes[attribute]];
33132
33148
  var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
33133
- var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
33134
- var attributeCount = accessor.count;
33149
+ var dataElementSize = GLTFUtil.getAccessorTypeSize(accessor.type);
33150
+ var accessorCount = accessor.count;
33135
33151
  var vertices = accessorBuffer.data;
33136
33152
  var vertexElement = void 0;
33137
33153
  var meshId = mesh.instanceId;
33138
33154
  var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
33139
- var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElmentSize, accessor.normalized);
33155
+ var elementNormalized = accessor.normalized;
33156
+ var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
33157
+ var scaleFactor = void 0;
33158
+ elementNormalized && (scaleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType));
33159
+ var elementOffset = void 0;
33140
33160
  if (accessorBuffer.interleaved) {
33141
33161
  var byteOffset = accessor.byteOffset || 0;
33142
33162
  var stride = accessorBuffer.stride;
33143
- var elementOffset = byteOffset % stride;
33163
+ elementOffset = byteOffset % stride;
33144
33164
  if (vertexBindingInfos[meshId] === undefined) {
33145
33165
  vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
33146
33166
  var vertexBuffer = accessorBuffer.vertexBuffer;
@@ -33155,7 +33175,8 @@
33155
33175
  vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
33156
33176
  }
33157
33177
  } else {
33158
- vertexElement = new VertexElement(attribute, 0, elementFormat, bufferBindIndex);
33178
+ elementOffset = 0;
33179
+ vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
33159
33180
  var vertexBuffer1 = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
33160
33181
  vertexBuffer1.setData(vertices);
33161
33182
  mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
@@ -33163,35 +33184,60 @@
33163
33184
  }
33164
33185
  vertexElements.push(vertexElement);
33165
33186
  if (attribute === "POSITION") {
33166
- vertexCount = attributeCount;
33187
+ vertexCount = accessorCount;
33167
33188
  var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
33168
33189
  if (accessor.min && accessor.max) {
33169
33190
  min.copyFromArray(accessor.min);
33170
33191
  max.copyFromArray(accessor.max);
33171
33192
  if (keepMeshData) {
33172
- var stride1 = vertices.length / attributeCount;
33173
- for(var j = 0; j < attributeCount; j++){
33174
- var offset = j * stride1;
33175
- positions[j] = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
33193
+ var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
33194
+ var stride1 = vertices.length / accessorCount;
33195
+ for(var j = 0; j < accessorCount; j++){
33196
+ var offset = baseOffset + j * stride1;
33197
+ var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
33198
+ elementNormalized && position.scale(scaleFactor);
33199
+ positions[j] = position;
33176
33200
  }
33177
33201
  }
33178
33202
  } else {
33179
- var position = MeshParser._tempVector3;
33203
+ var position1 = MeshParser._tempVector3;
33180
33204
  min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
33181
33205
  max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
33182
- var stride2 = vertices.length / attributeCount;
33183
- for(var j1 = 0; j1 < attributeCount; j1++){
33184
- var offset1 = j1 * stride2;
33185
- position.copyFromArray(vertices, offset1);
33186
- Vector3.min(min, position, min);
33187
- Vector3.max(max, position, max);
33188
- keepMeshData && (positions[j1] = position.clone());
33206
+ var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
33207
+ var stride2 = vertices.length / accessorCount;
33208
+ for(var j1 = 0; j1 < accessorCount; j1++){
33209
+ var offset1 = baseOffset1 + j1 * stride2;
33210
+ position1.copyFromArray(vertices, offset1);
33211
+ Vector3.min(min, position1, min);
33212
+ Vector3.max(max, position1, max);
33213
+ if (keepMeshData) {
33214
+ var clonePosition = position1.clone();
33215
+ elementNormalized && clonePosition.scale(scaleFactor);
33216
+ positions[j1] = clonePosition;
33217
+ }
33189
33218
  }
33190
33219
  }
33191
- if (accessor.normalized) {
33192
- var sacleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
33193
- min.scale(sacleFactor);
33194
- max.scale(sacleFactor);
33220
+ if (elementNormalized) {
33221
+ min.scale(scaleFactor);
33222
+ max.scale(scaleFactor);
33223
+ }
33224
+ } else if (attribute === "JOINTS_0" && keepMeshData) {
33225
+ var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
33226
+ var stride3 = vertices.length / accessorCount;
33227
+ for(var j2 = 0; j2 < accessorCount; j2++){
33228
+ var offset2 = baseOffset2 + j2 * stride3;
33229
+ var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
33230
+ elementNormalized && boneIndex.scale(scaleFactor);
33231
+ boneIndices[j2] = boneIndex;
33232
+ }
33233
+ } else if (attribute === "WEIGHTS_0" && keepMeshData) {
33234
+ var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
33235
+ var stride4 = vertices.length / accessorCount;
33236
+ for(var j3 = 0; j3 < accessorCount; j3++){
33237
+ var offset3 = baseOffset3 + j3 * stride4;
33238
+ var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
33239
+ elementNormalized && boneWeight.scale(scaleFactor);
33240
+ boneWeights[j3] = boneWeight;
33195
33241
  }
33196
33242
  }
33197
33243
  }
@@ -33210,6 +33256,10 @@
33210
33256
  mesh.uploadData(!keepMeshData);
33211
33257
  //@ts-ignore
33212
33258
  mesh._positions = positions;
33259
+ //@ts-ignore
33260
+ mesh._boneIndices = boneIndices;
33261
+ //@ts-ignore
33262
+ mesh._boneWeights = boneWeights;
33213
33263
  return Promise.resolve(mesh);
33214
33264
  };
33215
33265
  _proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
@@ -35737,7 +35787,7 @@
35737
35787
  }));
35738
35788
 
35739
35789
  //@ts-ignore
35740
- var version = "0.9.0";
35790
+ var version = "0.9.2";
35741
35791
  console.log("Galacean engine version: " + version);
35742
35792
  for(var key in CoreObjects){
35743
35793
  Loader.registerClass(key, CoreObjects[key]);