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