@galacean/engine-core 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/module.js CHANGED
@@ -8006,6 +8006,9 @@ SimpleSpriteAssembler = __decorate([
8006
8006
  __decorate([
8007
8007
  assignmentClone
8008
8008
  ], SpriteMask.prototype, "influenceLayers", void 0);
8009
+ __decorate([
8010
+ ignoreClone
8011
+ ], SpriteMask.prototype, "_verticesData", void 0);
8009
8012
  __decorate([
8010
8013
  ignoreClone
8011
8014
  ], SpriteMask.prototype, "_sprite", void 0);
@@ -10793,6 +10796,10 @@ var VertexElementIndex;
10793
10796
  var sphereInfo = primitiveInfo;
10794
10797
  PrimitiveMesh._setSphereData(this.resource, sphereInfo.radius, sphereInfo.segments, sphereInfo.noLongerAccessible, true, sphereInfo.vertexBuffer);
10795
10798
  break;
10799
+ case 7:
10800
+ var CCSphereInfo = primitiveInfo;
10801
+ PrimitiveMesh._setSubdivisionSurfaceSphereData(this.resource, CCSphereInfo.radius, CCSphereInfo.step, CCSphereInfo.noLongerAccessible, true, CCSphereInfo.vertexBuffer);
10802
+ break;
10796
10803
  case 1:
10797
10804
  var cuboidInfo = primitiveInfo;
10798
10805
  PrimitiveMesh._setCuboidData(this.resource, cuboidInfo.width, cuboidInfo.height, cuboidInfo.depth, cuboidInfo.noLongerAccessible, true, cuboidInfo.vertexBuffer);
@@ -10830,6 +10837,7 @@ var PrimitiveType;
10830
10837
  PrimitiveType[PrimitiveType["Torus"] = 4] = "Torus";
10831
10838
  PrimitiveType[PrimitiveType["Cone"] = 5] = "Cone";
10832
10839
  PrimitiveType[PrimitiveType["Capsule"] = 6] = "Capsule";
10840
+ PrimitiveType[PrimitiveType["CCSphere"] = 7] = "CCSphere";
10833
10841
  })(PrimitiveType || (PrimitiveType = {}));
10834
10842
  /**
10835
10843
  * @internal
@@ -10851,6 +10859,19 @@ var PrimitiveType;
10851
10859
  }
10852
10860
  return SphereRestoreInfo;
10853
10861
  }(PrimitiveRestoreInfo);
10862
+ /**
10863
+ * @internal
10864
+ */ var SubdivisionSurfaceSphereRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
10865
+ _inherits(SubdivisionSurfaceSphereRestoreInfo, PrimitiveRestoreInfo);
10866
+ function SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible) {
10867
+ var _this;
10868
+ _this = PrimitiveRestoreInfo.call(this, 7, vertexBuffer, noLongerAccessible) || this;
10869
+ _this.radius = radius;
10870
+ _this.step = step;
10871
+ return _this;
10872
+ }
10873
+ return SubdivisionSurfaceSphereRestoreInfo;
10874
+ }(PrimitiveRestoreInfo);
10854
10875
  /**
10855
10876
  * @internal
10856
10877
  */ var CuboidRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
@@ -10965,6 +10986,24 @@ var PrimitiveType;
10965
10986
  return sphereMesh;
10966
10987
  };
10967
10988
  /**
10989
+ * Create a sphere mesh by implementing Catmull-Clark Surface Subdivision Algorithm.
10990
+ * Max step is limited to 6.
10991
+ * @param engine - Engine
10992
+ * @param radius - Sphere radius
10993
+ * @param step - Number of subdiv steps
10994
+ * @param noLongerAccessible - No longer access the vertices of the mesh after creation
10995
+ * @returns Sphere model mesh
10996
+ */ PrimitiveMesh.createSubdivisionSurfaceSphere = function createSubdivisionSurfaceSphere(engine, radius, step, noLongerAccessible) {
10997
+ if (radius === void 0) radius = 0.5;
10998
+ if (step === void 0) step = 3;
10999
+ if (noLongerAccessible === void 0) noLongerAccessible = true;
11000
+ var sphereMesh = new ModelMesh(engine);
11001
+ PrimitiveMesh._setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, false);
11002
+ var vertexBuffer = sphereMesh.vertexBufferBindings[0].buffer;
11003
+ engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(sphereMesh, new SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible)));
11004
+ return sphereMesh;
11005
+ };
11006
+ /**
10968
11007
  * Create a cuboid mesh.
10969
11008
  * @param engine - Engine
10970
11009
  * @param width - Cuboid width
@@ -11094,6 +11133,90 @@ var PrimitiveType;
11094
11133
  };
11095
11134
  /**
11096
11135
  * @internal
11136
+ */ PrimitiveMesh._setSubdivisionSurfaceSphereData = function _setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
11137
+ // Max step is limited to 6. Because 7 step will generate a single mesh with over 98306 vertices
11138
+ step = MathUtil$1.clamp(Math.floor(step), 1, 6);
11139
+ var positions = new Float32Array(3 * (6 * Math.pow(4, step) + 2));
11140
+ var cells = new Float32Array(24 * Math.pow(4, step));
11141
+ PrimitiveMesh._subdiveCatmullClark(step, positions, cells);
11142
+ var positionCount = positions.length / 3;
11143
+ var cellsCount = cells.length / 4;
11144
+ var poleOffset = positionCount + Math.pow(2, step + 1) - 1;
11145
+ // 16 extra vertices for pole uv
11146
+ // 2 vertices at each pole are idle
11147
+ var vertexCount = poleOffset + 16;
11148
+ var vertices = new Float32Array(vertexCount * 8);
11149
+ var indices = PrimitiveMesh._generateIndices(sphereMesh.engine, positionCount, cellsCount * 6);
11150
+ var seamCount = 0;
11151
+ var seamVertices = {};
11152
+ // Get normals, uvs, and scale to radius
11153
+ for(var i = 0; i < positionCount; i++){
11154
+ var offset = 3 * i;
11155
+ var x = positions[offset];
11156
+ var y = positions[offset + 1];
11157
+ var z = positions[offset + 2];
11158
+ var reciprocalLength = 1 / Math.sqrt(x * x + y * y + z * z);
11159
+ x *= reciprocalLength;
11160
+ y *= reciprocalLength;
11161
+ z *= reciprocalLength;
11162
+ offset = 8 * i;
11163
+ vertices[offset] = x * radius;
11164
+ vertices[offset + 1] = y * radius;
11165
+ vertices[offset + 2] = z * radius;
11166
+ vertices[offset + 3] = x;
11167
+ vertices[offset + 4] = y;
11168
+ vertices[offset + 5] = z;
11169
+ vertices[offset + 6] = (Math.PI - Math.atan2(z, x)) / (2 * Math.PI);
11170
+ vertices[offset + 7] = Math.acos(y) / Math.PI;
11171
+ if (vertices[offset + 6] === 0) {
11172
+ // Generate seam vertex
11173
+ var seamOffset = 8 * (positionCount + seamCount++);
11174
+ vertices.set(vertices.subarray(offset, offset + 8), seamOffset);
11175
+ vertices[seamOffset + 6] = 1.0;
11176
+ // Cache seam vertex
11177
+ seamVertices[offset / 8] = seamOffset / 8;
11178
+ }
11179
+ }
11180
+ // Get indices
11181
+ var offset1 = 0;
11182
+ this._spherePoleIdx = 0;
11183
+ for(var i1 = 0; i1 < cellsCount; i1++){
11184
+ var idx = 4 * i1;
11185
+ var indexA = cells[idx];
11186
+ var indexB = cells[idx + 1];
11187
+ var indexC = cells[idx + 2];
11188
+ var indexD = cells[idx + 3];
11189
+ // Handle seam by replacing vertex index to seam vertex index if necessary
11190
+ var floatIndexA = 8 * indexA;
11191
+ var floatIndexB = 8 * indexB;
11192
+ var floatIndexC = 8 * indexC;
11193
+ var floatIndexD = 8 * indexD;
11194
+ // If center Z is negative
11195
+ if (vertices[floatIndexA + 2] + vertices[floatIndexB + 2] + vertices[floatIndexC + 2] < 0) {
11196
+ vertices[floatIndexA + 6] === 0 && (indexA = seamVertices[indexA]);
11197
+ vertices[floatIndexB + 6] === 0 && (indexB = seamVertices[indexB]);
11198
+ vertices[floatIndexC + 6] === 0 && (indexC = seamVertices[indexC]);
11199
+ vertices[floatIndexD + 6] === 0 && (indexD = seamVertices[indexD]);
11200
+ }
11201
+ indices[offset1] = indexA;
11202
+ indices[offset1 + 1] = indexB;
11203
+ indices[offset1 + 2] = indexC;
11204
+ this._generateAndReplacePoleUV(indices, vertices, offset1, poleOffset);
11205
+ indices[offset1 + 3] = indexA;
11206
+ indices[offset1 + 4] = indexC;
11207
+ indices[offset1 + 5] = indexD;
11208
+ this._generateAndReplacePoleUV(indices, vertices, offset1 + 3, poleOffset);
11209
+ offset1 += 6;
11210
+ }
11211
+ if (!isRestoreMode) {
11212
+ var bounds = sphereMesh.bounds;
11213
+ bounds.min.set(-radius, -radius, -radius);
11214
+ bounds.max.set(radius, radius, radius);
11215
+ }
11216
+ PrimitiveMesh._initialize(sphereMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
11217
+ };
11218
+ /**
11219
+ * @internal
11097
11220
  */ PrimitiveMesh._setSphereData = function _setSphereData(sphereMesh, radius, segments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
11098
11221
  segments = Math.max(2, Math.floor(segments));
11099
11222
  var count = segments + 1;
@@ -11154,6 +11277,135 @@ var PrimitiveType;
11154
11277
  };
11155
11278
  /**
11156
11279
  * @internal
11280
+ */ PrimitiveMesh._subdiveCatmullClark = function _subdiveCatmullClark(step, positions, cells) {
11281
+ var edges = new Map();
11282
+ var faces = new Array();
11283
+ positions.set(PrimitiveMesh._sphereSeedPositions);
11284
+ cells.set(PrimitiveMesh._sphereSeedCells);
11285
+ for(var i = 0; i < step; i++){
11286
+ var cellCount = 6 * Math.pow(4, i);
11287
+ var positionCount = 4 * cellCount + 2;
11288
+ edges.clear();
11289
+ faces.length = 0;
11290
+ // Get cell face's facePoint
11291
+ for(var j = 0; j < cellCount; j++){
11292
+ var face = faces[j] = {
11293
+ facePoint: new Vector3(),
11294
+ adjacentEdges: new Array(4)
11295
+ };
11296
+ // Get cell's edgePoint
11297
+ for(var k = 0; k < 4; k++){
11298
+ var offset = 3 * cells[4 * j + k];
11299
+ face.facePoint.x += 0.25 * positions[offset];
11300
+ face.facePoint.y += 0.25 * positions[offset + 1];
11301
+ face.facePoint.z += 0.25 * positions[offset + 2];
11302
+ }
11303
+ // Get cell edges
11304
+ for(var k1 = 0; k1 < 4; k1++){
11305
+ var vertexIdxA = cells[4 * j + k1];
11306
+ var vertexIdxB = cells[4 * j + (k1 + 1) % 4];
11307
+ var edgeIdxKey = Math.min(vertexIdxA, vertexIdxB) * positionCount + Math.max(vertexIdxA, vertexIdxB);
11308
+ if (!edges.has(edgeIdxKey)) {
11309
+ var edge = {
11310
+ edgePoint: new Vector3(),
11311
+ edgePointIndex: undefined
11312
+ };
11313
+ var offsetA = 3 * vertexIdxA;
11314
+ var offsetB = 3 * vertexIdxB;
11315
+ 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]));
11316
+ edges.set(edgeIdxKey, edge);
11317
+ }
11318
+ var edge1 = edges.get(edgeIdxKey);
11319
+ face.adjacentEdges[k1] = edge1;
11320
+ var edgePoint = edge1.edgePoint;
11321
+ var facePoint = face.facePoint;
11322
+ edgePoint.x += 0.25 * facePoint.x;
11323
+ edgePoint.y += 0.25 * facePoint.y;
11324
+ edgePoint.z += 0.25 * facePoint.z;
11325
+ }
11326
+ }
11327
+ var prePointCount = cellCount + 2;
11328
+ var edgePointOffset = prePointCount + cellCount;
11329
+ var pointIdx = 0;
11330
+ this._sphereEdgeIdx = 0;
11331
+ var preCells = cells.slice(0, 4 * cellCount);
11332
+ // Get New positions, which consists of updated positions of existing points, face points and edge points
11333
+ for(var j1 = 0; j1 < cellCount; j1++){
11334
+ // Add face point to new positions
11335
+ var face1 = faces[j1];
11336
+ face1.facePoint.copyToArray(positions, 3 * (prePointCount + j1));
11337
+ // Get the face point index
11338
+ var ic = prePointCount + j1;
11339
+ var id = void 0, ib = void 0, temp = void 0;
11340
+ // ia -- id -- ia
11341
+ // | | |
11342
+ // ib -- ic -- ib
11343
+ // | | |
11344
+ // ia -- id -- ia
11345
+ for(var k2 = 0; k2 < 4; k2++){
11346
+ // Get the updated existing point index
11347
+ var ia = preCells[pointIdx++];
11348
+ // ib and id share four edge points in one cell
11349
+ switch(k2){
11350
+ case 0:
11351
+ {
11352
+ var edgeB = face1.adjacentEdges[k2 % 4];
11353
+ var edgeD = face1.adjacentEdges[(k2 + 3) % 4];
11354
+ ib = this._calculateEdgeIndex(positions, edgeB, edgePointOffset);
11355
+ id = this._calculateEdgeIndex(positions, edgeD, edgePointOffset);
11356
+ temp = id;
11357
+ break;
11358
+ }
11359
+ case 1:
11360
+ case 2:
11361
+ {
11362
+ var edgeB1 = face1.adjacentEdges[k2 % 4];
11363
+ id = ib;
11364
+ ib = this._calculateEdgeIndex(positions, edgeB1, edgePointOffset);
11365
+ break;
11366
+ }
11367
+ case 3:
11368
+ {
11369
+ id = ib;
11370
+ ib = temp;
11371
+ break;
11372
+ }
11373
+ }
11374
+ var idx = 4 * (4 * j1 + k2);
11375
+ cells[idx] = ia;
11376
+ cells[idx + 1] = ib;
11377
+ cells[idx + 2] = ic;
11378
+ cells[idx + 3] = id;
11379
+ }
11380
+ }
11381
+ }
11382
+ };
11383
+ /**
11384
+ * Duplicate vertices at the poles and adjust their UV coordinates.
11385
+ */ PrimitiveMesh._generateAndReplacePoleUV = function _generateAndReplacePoleUV(indices, vertices, idx, poleOffset) {
11386
+ var v = vertices[8 * indices[idx] + 7];
11387
+ if (v === 0 || v === 1) {
11388
+ var offset = 8 * indices[idx];
11389
+ var addedOffset = 8 * (poleOffset + this._spherePoleIdx);
11390
+ vertices.set(vertices.subarray(offset, offset + 8), addedOffset);
11391
+ vertices[addedOffset + 6] = 0.5 * (vertices[offset + 6] + vertices[8 * indices[idx + 1] + 6] + vertices[8 * indices[idx + 2] + 6] - 0.5);
11392
+ indices[idx] = poleOffset + this._spherePoleIdx++;
11393
+ }
11394
+ };
11395
+ /**
11396
+ * Get edge point index for subdivision surface sphere.
11397
+ */ PrimitiveMesh._calculateEdgeIndex = function _calculateEdgeIndex(positions, edge, offset) {
11398
+ if (edge.edgePointIndex !== undefined) {
11399
+ return edge.edgePointIndex;
11400
+ } else {
11401
+ edge.edgePoint.copyToArray(positions, 3 * (offset + PrimitiveMesh._sphereEdgeIdx));
11402
+ var index = offset + PrimitiveMesh._sphereEdgeIdx++;
11403
+ edge.edgePointIndex = index;
11404
+ return index;
11405
+ }
11406
+ };
11407
+ /**
11408
+ * @internal
11157
11409
  */ PrimitiveMesh._setCuboidData = function _setCuboidData(cuboidMesh, width, height, depth, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
11158
11410
  var halfWidth = width / 2;
11159
11411
  var halfHeight = height / 2;
@@ -11783,6 +12035,68 @@ var PrimitiveType;
11783
12035
  (function() {
11784
12036
  PrimitiveMesh._tempVec30 = new Vector3();
11785
12037
  })();
12038
+ (function() {
12039
+ PrimitiveMesh._sphereSeedPositions = new Float32Array([
12040
+ -1,
12041
+ 1,
12042
+ 1,
12043
+ -1,
12044
+ -1,
12045
+ 1,
12046
+ 1,
12047
+ -1,
12048
+ 1,
12049
+ 1,
12050
+ 1,
12051
+ 1,
12052
+ 1,
12053
+ -1,
12054
+ -1,
12055
+ 1,
12056
+ 1,
12057
+ -1,
12058
+ -1,
12059
+ -1,
12060
+ -1,
12061
+ -1,
12062
+ 1,
12063
+ -1
12064
+ ]);
12065
+ })();
12066
+ (function() {
12067
+ PrimitiveMesh._sphereSeedCells = new Float32Array([
12068
+ 0,
12069
+ 1,
12070
+ 2,
12071
+ 3,
12072
+ 3,
12073
+ 2,
12074
+ 4,
12075
+ 5,
12076
+ 5,
12077
+ 4,
12078
+ 6,
12079
+ 7,
12080
+ 7,
12081
+ 0,
12082
+ 3,
12083
+ 5,
12084
+ 7,
12085
+ 6,
12086
+ 1,
12087
+ 0,
12088
+ 6,
12089
+ 4,
12090
+ 2,
12091
+ 1
12092
+ ]);
12093
+ })();
12094
+ (function() {
12095
+ PrimitiveMesh._sphereEdgeIdx = 0;
12096
+ })();
12097
+ (function() {
12098
+ PrimitiveMesh._spherePoleIdx = 0;
12099
+ })();
11786
12100
 
11787
12101
  /**
11788
12102
  * Mesh skin data, equal glTF skins define
@@ -12291,8 +12605,10 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
12291
12605
  }
12292
12606
  mesh.addSubMesh(this._getSubMeshFromPool(vertexStartIndex, vertexCount));
12293
12607
  batchedQueue[curMeshIndex] = preElement;
12294
- this._vertexBuffers[_flushId].setData(vertices, 0, 0, vertexIndex);
12295
- this._indiceBuffers[_flushId].setData(indices, 0, 0, indiceIndex);
12608
+ // Set data option use Discard, or will resulted in performance slowdown when open antialias and cross-rendering of 3D and 2D elements.
12609
+ // Device: iphone X(16.7.2)、iphone 15 pro max(17.1.1)、iphone XR(17.1.2) etc.
12610
+ this._vertexBuffers[_flushId].setData(vertices, 0, 0, vertexIndex, SetDataOptions.Discard);
12611
+ this._indiceBuffers[_flushId].setData(indices, 0, 0, indiceIndex, SetDataOptions.Discard);
12296
12612
  };
12297
12613
  _proto._getSubMeshFromPool = function _getSubMeshFromPool(start, count) {
12298
12614
  var subMesh = this._subMeshPool.getFromPool();