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