@galacean/engine 1.1.0-beta.32 → 1.1.0-beta.34

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
@@ -12834,6 +12834,9 @@
12834
12834
  __decorate$1([
12835
12835
  assignmentClone
12836
12836
  ], SpriteMask.prototype, "influenceLayers", void 0);
12837
+ __decorate$1([
12838
+ ignoreClone
12839
+ ], SpriteMask.prototype, "_verticesData", void 0);
12837
12840
  __decorate$1([
12838
12841
  ignoreClone
12839
12842
  ], SpriteMask.prototype, "_sprite", void 0);
@@ -15599,6 +15602,10 @@
15599
15602
  var sphereInfo = primitiveInfo;
15600
15603
  PrimitiveMesh._setSphereData(this.resource, sphereInfo.radius, sphereInfo.segments, sphereInfo.noLongerAccessible, true, sphereInfo.vertexBuffer);
15601
15604
  break;
15605
+ case 7:
15606
+ var CCSphereInfo = primitiveInfo;
15607
+ PrimitiveMesh._setSubdivisionSurfaceSphereData(this.resource, CCSphereInfo.radius, CCSphereInfo.step, CCSphereInfo.noLongerAccessible, true, CCSphereInfo.vertexBuffer);
15608
+ break;
15602
15609
  case 1:
15603
15610
  var cuboidInfo = primitiveInfo;
15604
15611
  PrimitiveMesh._setCuboidData(this.resource, cuboidInfo.width, cuboidInfo.height, cuboidInfo.depth, cuboidInfo.noLongerAccessible, true, cuboidInfo.vertexBuffer);
@@ -15636,6 +15643,7 @@
15636
15643
  PrimitiveType[PrimitiveType["Torus"] = 4] = "Torus";
15637
15644
  PrimitiveType[PrimitiveType["Cone"] = 5] = "Cone";
15638
15645
  PrimitiveType[PrimitiveType["Capsule"] = 6] = "Capsule";
15646
+ PrimitiveType[PrimitiveType["CCSphere"] = 7] = "CCSphere";
15639
15647
  })(PrimitiveType || (PrimitiveType = {}));
15640
15648
  /**
15641
15649
  * @internal
@@ -15657,6 +15665,19 @@
15657
15665
  _inherits$2(SphereRestoreInfo, PrimitiveRestoreInfo);
15658
15666
  return SphereRestoreInfo;
15659
15667
  }(PrimitiveRestoreInfo);
15668
+ /**
15669
+ * @internal
15670
+ */ var SubdivisionSurfaceSphereRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
15671
+ var SubdivisionSurfaceSphereRestoreInfo = function SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible) {
15672
+ var _this;
15673
+ _this = PrimitiveRestoreInfo.call(this, 7, vertexBuffer, noLongerAccessible) || this;
15674
+ _this.radius = radius;
15675
+ _this.step = step;
15676
+ return _this;
15677
+ };
15678
+ _inherits$2(SubdivisionSurfaceSphereRestoreInfo, PrimitiveRestoreInfo);
15679
+ return SubdivisionSurfaceSphereRestoreInfo;
15680
+ }(PrimitiveRestoreInfo);
15660
15681
  /**
15661
15682
  * @internal
15662
15683
  */ var CuboidRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
@@ -15770,6 +15791,24 @@
15770
15791
  return sphereMesh;
15771
15792
  };
15772
15793
  /**
15794
+ * Create a sphere mesh by implementing Catmull-Clark Surface Subdivision Algorithm.
15795
+ * Max step is limited to 6.
15796
+ * @param engine - Engine
15797
+ * @param radius - Sphere radius
15798
+ * @param step - Number of subdiv steps
15799
+ * @param noLongerAccessible - No longer access the vertices of the mesh after creation
15800
+ * @returns Sphere model mesh
15801
+ */ PrimitiveMesh.createSubdivisionSurfaceSphere = function createSubdivisionSurfaceSphere(engine, radius, step, noLongerAccessible) {
15802
+ if (radius === void 0) radius = 0.5;
15803
+ if (step === void 0) step = 3;
15804
+ if (noLongerAccessible === void 0) noLongerAccessible = true;
15805
+ var sphereMesh = new ModelMesh(engine);
15806
+ PrimitiveMesh._setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, false);
15807
+ var vertexBuffer = sphereMesh.vertexBufferBindings[0].buffer;
15808
+ engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(sphereMesh, new SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible)));
15809
+ return sphereMesh;
15810
+ };
15811
+ /**
15773
15812
  * Create a cuboid mesh.
15774
15813
  * @param engine - Engine
15775
15814
  * @param width - Cuboid width
@@ -15899,6 +15938,90 @@
15899
15938
  };
15900
15939
  /**
15901
15940
  * @internal
15941
+ */ PrimitiveMesh._setSubdivisionSurfaceSphereData = function _setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15942
+ // Max step is limited to 6. Because 7 step will generate a single mesh with over 98306 vertices
15943
+ step = MathUtil$1.clamp(Math.floor(step), 1, 6);
15944
+ var positions = new Float32Array(3 * (6 * Math.pow(4, step) + 2));
15945
+ var cells = new Float32Array(24 * Math.pow(4, step));
15946
+ PrimitiveMesh._subdiveCatmullClark(step, positions, cells);
15947
+ var positionCount = positions.length / 3;
15948
+ var cellsCount = cells.length / 4;
15949
+ var poleOffset = positionCount + Math.pow(2, step + 1) - 1;
15950
+ // 16 extra vertices for pole uv
15951
+ // 2 vertices at each pole are idle
15952
+ var vertexCount = poleOffset + 16;
15953
+ var vertices = new Float32Array(vertexCount * 8);
15954
+ var indices = PrimitiveMesh._generateIndices(sphereMesh.engine, positionCount, cellsCount * 6);
15955
+ var seamCount = 0;
15956
+ var seamVertices = {};
15957
+ // Get normals, uvs, and scale to radius
15958
+ for(var i = 0; i < positionCount; i++){
15959
+ var offset = 3 * i;
15960
+ var x = positions[offset];
15961
+ var y = positions[offset + 1];
15962
+ var z = positions[offset + 2];
15963
+ var reciprocalLength = 1 / Math.sqrt(x * x + y * y + z * z);
15964
+ x *= reciprocalLength;
15965
+ y *= reciprocalLength;
15966
+ z *= reciprocalLength;
15967
+ offset = 8 * i;
15968
+ vertices[offset] = x * radius;
15969
+ vertices[offset + 1] = y * radius;
15970
+ vertices[offset + 2] = z * radius;
15971
+ vertices[offset + 3] = x;
15972
+ vertices[offset + 4] = y;
15973
+ vertices[offset + 5] = z;
15974
+ vertices[offset + 6] = (Math.PI - Math.atan2(z, x)) / (2 * Math.PI);
15975
+ vertices[offset + 7] = Math.acos(y) / Math.PI;
15976
+ if (vertices[offset + 6] === 0) {
15977
+ // Generate seam vertex
15978
+ var seamOffset = 8 * (positionCount + seamCount++);
15979
+ vertices.set(vertices.subarray(offset, offset + 8), seamOffset);
15980
+ vertices[seamOffset + 6] = 1.0;
15981
+ // Cache seam vertex
15982
+ seamVertices[offset / 8] = seamOffset / 8;
15983
+ }
15984
+ }
15985
+ // Get indices
15986
+ var offset1 = 0;
15987
+ this._spherePoleIdx = 0;
15988
+ for(var i1 = 0; i1 < cellsCount; i1++){
15989
+ var idx = 4 * i1;
15990
+ var indexA = cells[idx];
15991
+ var indexB = cells[idx + 1];
15992
+ var indexC = cells[idx + 2];
15993
+ var indexD = cells[idx + 3];
15994
+ // Handle seam by replacing vertex index to seam vertex index if necessary
15995
+ var floatIndexA = 8 * indexA;
15996
+ var floatIndexB = 8 * indexB;
15997
+ var floatIndexC = 8 * indexC;
15998
+ var floatIndexD = 8 * indexD;
15999
+ // If center Z is negative
16000
+ if (vertices[floatIndexA + 2] + vertices[floatIndexB + 2] + vertices[floatIndexC + 2] < 0) {
16001
+ vertices[floatIndexA + 6] === 0 && (indexA = seamVertices[indexA]);
16002
+ vertices[floatIndexB + 6] === 0 && (indexB = seamVertices[indexB]);
16003
+ vertices[floatIndexC + 6] === 0 && (indexC = seamVertices[indexC]);
16004
+ vertices[floatIndexD + 6] === 0 && (indexD = seamVertices[indexD]);
16005
+ }
16006
+ indices[offset1] = indexA;
16007
+ indices[offset1 + 1] = indexB;
16008
+ indices[offset1 + 2] = indexC;
16009
+ this._generateAndReplacePoleUV(indices, vertices, offset1, poleOffset);
16010
+ indices[offset1 + 3] = indexA;
16011
+ indices[offset1 + 4] = indexC;
16012
+ indices[offset1 + 5] = indexD;
16013
+ this._generateAndReplacePoleUV(indices, vertices, offset1 + 3, poleOffset);
16014
+ offset1 += 6;
16015
+ }
16016
+ if (!isRestoreMode) {
16017
+ var bounds = sphereMesh.bounds;
16018
+ bounds.min.set(-radius, -radius, -radius);
16019
+ bounds.max.set(radius, radius, radius);
16020
+ }
16021
+ PrimitiveMesh._initialize(sphereMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
16022
+ };
16023
+ /**
16024
+ * @internal
15902
16025
  */ PrimitiveMesh._setSphereData = function _setSphereData(sphereMesh, radius, segments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15903
16026
  segments = Math.max(2, Math.floor(segments));
15904
16027
  var count = segments + 1;
@@ -15959,6 +16082,135 @@
15959
16082
  };
15960
16083
  /**
15961
16084
  * @internal
16085
+ */ PrimitiveMesh._subdiveCatmullClark = function _subdiveCatmullClark(step, positions, cells) {
16086
+ var edges = new Map();
16087
+ var faces = new Array();
16088
+ positions.set(PrimitiveMesh._sphereSeedPositions);
16089
+ cells.set(PrimitiveMesh._sphereSeedCells);
16090
+ for(var i = 0; i < step; i++){
16091
+ var cellCount = 6 * Math.pow(4, i);
16092
+ var positionCount = 4 * cellCount + 2;
16093
+ edges.clear();
16094
+ faces.length = 0;
16095
+ // Get cell face's facePoint
16096
+ for(var j = 0; j < cellCount; j++){
16097
+ var face = faces[j] = {
16098
+ facePoint: new Vector3(),
16099
+ adjacentEdges: new Array(4)
16100
+ };
16101
+ // Get cell's edgePoint
16102
+ for(var k = 0; k < 4; k++){
16103
+ var offset = 3 * cells[4 * j + k];
16104
+ face.facePoint.x += 0.25 * positions[offset];
16105
+ face.facePoint.y += 0.25 * positions[offset + 1];
16106
+ face.facePoint.z += 0.25 * positions[offset + 2];
16107
+ }
16108
+ // Get cell edges
16109
+ for(var k1 = 0; k1 < 4; k1++){
16110
+ var vertexIdxA = cells[4 * j + k1];
16111
+ var vertexIdxB = cells[4 * j + (k1 + 1) % 4];
16112
+ var edgeIdxKey = Math.min(vertexIdxA, vertexIdxB) * positionCount + Math.max(vertexIdxA, vertexIdxB);
16113
+ if (!edges.has(edgeIdxKey)) {
16114
+ var edge = {
16115
+ edgePoint: new Vector3(),
16116
+ edgePointIndex: undefined
16117
+ };
16118
+ var offsetA = 3 * vertexIdxA;
16119
+ var offsetB = 3 * vertexIdxB;
16120
+ edge.edgePoint.set(0.25 * (positions[offsetA] + positions[offsetB]), 0.25 * (positions[offsetA + 1] + positions[offsetB + 1]), 0.25 * (positions[offsetA + 2] + positions[offsetB + 2]));
16121
+ edges.set(edgeIdxKey, edge);
16122
+ }
16123
+ var edge1 = edges.get(edgeIdxKey);
16124
+ face.adjacentEdges[k1] = edge1;
16125
+ var edgePoint = edge1.edgePoint;
16126
+ var facePoint = face.facePoint;
16127
+ edgePoint.x += 0.25 * facePoint.x;
16128
+ edgePoint.y += 0.25 * facePoint.y;
16129
+ edgePoint.z += 0.25 * facePoint.z;
16130
+ }
16131
+ }
16132
+ var prePointCount = cellCount + 2;
16133
+ var edgePointOffset = prePointCount + cellCount;
16134
+ var pointIdx = 0;
16135
+ this._sphereEdgeIdx = 0;
16136
+ var preCells = cells.slice(0, 4 * cellCount);
16137
+ // Get New positions, which consists of updated positions of existing points, face points and edge points
16138
+ for(var j1 = 0; j1 < cellCount; j1++){
16139
+ // Add face point to new positions
16140
+ var face1 = faces[j1];
16141
+ face1.facePoint.copyToArray(positions, 3 * (prePointCount + j1));
16142
+ // Get the face point index
16143
+ var ic = prePointCount + j1;
16144
+ var id = void 0, ib = void 0, temp = void 0;
16145
+ // ia -- id -- ia
16146
+ // | | |
16147
+ // ib -- ic -- ib
16148
+ // | | |
16149
+ // ia -- id -- ia
16150
+ for(var k2 = 0; k2 < 4; k2++){
16151
+ // Get the updated existing point index
16152
+ var ia = preCells[pointIdx++];
16153
+ // ib and id share four edge points in one cell
16154
+ switch(k2){
16155
+ case 0:
16156
+ {
16157
+ var edgeB = face1.adjacentEdges[k2 % 4];
16158
+ var edgeD = face1.adjacentEdges[(k2 + 3) % 4];
16159
+ ib = this._calculateEdgeIndex(positions, edgeB, edgePointOffset);
16160
+ id = this._calculateEdgeIndex(positions, edgeD, edgePointOffset);
16161
+ temp = id;
16162
+ break;
16163
+ }
16164
+ case 1:
16165
+ case 2:
16166
+ {
16167
+ var edgeB1 = face1.adjacentEdges[k2 % 4];
16168
+ id = ib;
16169
+ ib = this._calculateEdgeIndex(positions, edgeB1, edgePointOffset);
16170
+ break;
16171
+ }
16172
+ case 3:
16173
+ {
16174
+ id = ib;
16175
+ ib = temp;
16176
+ break;
16177
+ }
16178
+ }
16179
+ var idx = 4 * (4 * j1 + k2);
16180
+ cells[idx] = ia;
16181
+ cells[idx + 1] = ib;
16182
+ cells[idx + 2] = ic;
16183
+ cells[idx + 3] = id;
16184
+ }
16185
+ }
16186
+ }
16187
+ };
16188
+ /**
16189
+ * Duplicate vertices at the poles and adjust their UV coordinates.
16190
+ */ PrimitiveMesh._generateAndReplacePoleUV = function _generateAndReplacePoleUV(indices, vertices, idx, poleOffset) {
16191
+ var v = vertices[8 * indices[idx] + 7];
16192
+ if (v === 0 || v === 1) {
16193
+ var offset = 8 * indices[idx];
16194
+ var addedOffset = 8 * (poleOffset + this._spherePoleIdx);
16195
+ vertices.set(vertices.subarray(offset, offset + 8), addedOffset);
16196
+ vertices[addedOffset + 6] = 0.5 * (vertices[offset + 6] + vertices[8 * indices[idx + 1] + 6] + vertices[8 * indices[idx + 2] + 6] - 0.5);
16197
+ indices[idx] = poleOffset + this._spherePoleIdx++;
16198
+ }
16199
+ };
16200
+ /**
16201
+ * Get edge point index for subdivision surface sphere.
16202
+ */ PrimitiveMesh._calculateEdgeIndex = function _calculateEdgeIndex(positions, edge, offset) {
16203
+ if (edge.edgePointIndex !== undefined) {
16204
+ return edge.edgePointIndex;
16205
+ } else {
16206
+ edge.edgePoint.copyToArray(positions, 3 * (offset + PrimitiveMesh._sphereEdgeIdx));
16207
+ var index = offset + PrimitiveMesh._sphereEdgeIdx++;
16208
+ edge.edgePointIndex = index;
16209
+ return index;
16210
+ }
16211
+ };
16212
+ /**
16213
+ * @internal
15962
16214
  */ PrimitiveMesh._setCuboidData = function _setCuboidData(cuboidMesh, width, height, depth, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15963
16215
  var halfWidth = width / 2;
15964
16216
  var halfHeight = height / 2;
@@ -16583,6 +16835,68 @@
16583
16835
  (function() {
16584
16836
  PrimitiveMesh._tempVec30 = new Vector3();
16585
16837
  })();
16838
+ (function() {
16839
+ PrimitiveMesh._sphereSeedPositions = new Float32Array([
16840
+ -1,
16841
+ 1,
16842
+ 1,
16843
+ -1,
16844
+ -1,
16845
+ 1,
16846
+ 1,
16847
+ -1,
16848
+ 1,
16849
+ 1,
16850
+ 1,
16851
+ 1,
16852
+ 1,
16853
+ -1,
16854
+ -1,
16855
+ 1,
16856
+ 1,
16857
+ -1,
16858
+ -1,
16859
+ -1,
16860
+ -1,
16861
+ -1,
16862
+ 1,
16863
+ -1
16864
+ ]);
16865
+ })();
16866
+ (function() {
16867
+ PrimitiveMesh._sphereSeedCells = new Float32Array([
16868
+ 0,
16869
+ 1,
16870
+ 2,
16871
+ 3,
16872
+ 3,
16873
+ 2,
16874
+ 4,
16875
+ 5,
16876
+ 5,
16877
+ 4,
16878
+ 6,
16879
+ 7,
16880
+ 7,
16881
+ 0,
16882
+ 3,
16883
+ 5,
16884
+ 7,
16885
+ 6,
16886
+ 1,
16887
+ 0,
16888
+ 6,
16889
+ 4,
16890
+ 2,
16891
+ 1
16892
+ ]);
16893
+ })();
16894
+ (function() {
16895
+ PrimitiveMesh._sphereEdgeIdx = 0;
16896
+ })();
16897
+ (function() {
16898
+ PrimitiveMesh._spherePoleIdx = 0;
16899
+ })();
16586
16900
  /**
16587
16901
  * Mesh skin data, equal glTF skins define
16588
16902
  */ var Skin = /*#__PURE__*/ function(EngineObject1) {
@@ -17088,8 +17402,10 @@
17088
17402
  }
17089
17403
  mesh.addSubMesh(this._getSubMeshFromPool(vertexStartIndex, vertexCount));
17090
17404
  batchedQueue[curMeshIndex] = preElement;
17091
- this._vertexBuffers[_flushId].setData(vertices, 0, 0, vertexIndex);
17092
- this._indiceBuffers[_flushId].setData(indices, 0, 0, indiceIndex);
17405
+ // Set data option use Discard, or will resulted in performance slowdown when open antialias and cross-rendering of 3D and 2D elements.
17406
+ // Device: iphone X(16.7.2)、iphone 15 pro max(17.1.1)、iphone XR(17.1.2) etc.
17407
+ this._vertexBuffers[_flushId].setData(vertices, 0, 0, vertexIndex, exports.SetDataOptions.Discard);
17408
+ this._indiceBuffers[_flushId].setData(indices, 0, 0, indiceIndex, exports.SetDataOptions.Discard);
17093
17409
  };
17094
17410
  _proto._getSubMeshFromPool = function _getSubMeshFromPool(start, count) {
17095
17411
  var subMesh = this._subMeshPool.getFromPool();
@@ -43661,7 +43977,7 @@
43661
43977
  ], GALACEAN_animation_event);
43662
43978
 
43663
43979
  //@ts-ignore
43664
- var version = "1.1.0-beta.32";
43980
+ var version = "1.1.0-beta.34";
43665
43981
  console.log("Galacean engine version: " + version);
43666
43982
  for(var key in CoreObjects){
43667
43983
  Loader.registerClass(key, CoreObjects[key]);