@galacean/engine-core 2.0.0-alpha.56 → 2.0.0-alpha.57

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
@@ -9285,8 +9285,6 @@ ShaderPass._macroMap = new Map();
9285
9285
  return shaders == null ? void 0 : shaders[shaders.length - 1];
9286
9286
  };
9287
9287
  /**
9288
- * Create a shader from precompiled instructions.
9289
- * @param data - Precompiled shader data
9290
9288
  * @internal
9291
9289
  */ Shader._createFromPrecompiled = function _createFromPrecompiled(data) {
9292
9290
  var subShaderList = data.subShaders.map(function(subData) {
@@ -11156,6 +11154,9 @@ var TextChunk = function TextChunk() {
11156
11154
  _inherits(Material, ReferResource);
11157
11155
  function Material(engine, shader) {
11158
11156
  var _this;
11157
+ if (shader.destroyed) {
11158
+ throw new Error("Cannot create a material with a destroyed shader.");
11159
+ }
11159
11160
  _this = ReferResource.call(this, engine) || this, _this._shaderData = new ShaderData(ShaderDataGroup.Material);
11160
11161
  _this.shader = shader;
11161
11162
  _this.name = shader.name;
@@ -11446,7 +11447,7 @@ BaseMaterial._rasterStateCullModeProp = ShaderProperty.getByName("rasterStateCul
11446
11447
  _inherits(BlinnPhongMaterial, BaseMaterial);
11447
11448
  function BlinnPhongMaterial(engine) {
11448
11449
  var _this;
11449
- _this = BaseMaterial.call(this, engine, Shader.find("BlinnPhong")) || this;
11450
+ _this = BaseMaterial.call(this, engine, Engine._builtinShaders.blinnPhong) || this;
11450
11451
  var shaderData = _this.shaderData;
11451
11452
  shaderData.enableMacro("MATERIAL_NEED_WORLD_POS");
11452
11453
  shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
@@ -11642,7 +11643,7 @@ BlinnPhongMaterial._specularTextureProp = ShaderProperty.getByName("material_Spe
11642
11643
  _inherits(PBRMaterial, BaseMaterial1);
11643
11644
  function PBRMaterial(engine) {
11644
11645
  var _this;
11645
- _this = BaseMaterial1.call(this, engine, Shader.find("PBR")) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new engineMath.Vector2(100, 400), _this._sheenEnabled = false;
11646
+ _this = BaseMaterial1.call(this, engine, Engine._builtinShaders.pbr) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new engineMath.Vector2(100, 400), _this._sheenEnabled = false;
11646
11647
  var shaderData = _this.shaderData;
11647
11648
  shaderData.enableMacro("MATERIAL_NEED_WORLD_POS");
11648
11649
  shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
@@ -12438,7 +12439,7 @@ PBRMaterial._specularColorTextureProp = ShaderProperty.getByName("material_Specu
12438
12439
  _inherits(UnlitMaterial, BaseMaterial);
12439
12440
  function UnlitMaterial(engine) {
12440
12441
  var _this;
12441
- _this = BaseMaterial.call(this, engine, Shader.find("Unlit")) || this;
12442
+ _this = BaseMaterial.call(this, engine, Engine._builtinShaders.unlit) || this;
12442
12443
  var shaderData = _this.shaderData;
12443
12444
  shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
12444
12445
  shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
@@ -13780,6 +13781,134 @@ BlendShapeManager._blendShapeWeightsProperty = ShaderProperty.getByName("rendere
13780
13781
  BlendShapeManager._blendShapeTextureProperty = ShaderProperty.getByName("renderer_BlendShapeTexture");
13781
13782
  BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("renderer_BlendShapeTextureInfo");
13782
13783
 
13784
+ /**
13785
+ * @internal
13786
+ */ var MeshTangentUtils = /*#__PURE__*/ function() {
13787
+ function MeshTangentUtils() {}
13788
+ MeshTangentUtils.calculateTangents = function calculateTangents(positions, normals, uvs, indices) {
13789
+ return MeshTangentUtils._calculateTangents(positions, normals, uvs, indices, null);
13790
+ };
13791
+ MeshTangentUtils.calculateTangentsFromBuffer = function calculateTangentsFromBuffer(vertices, indices) {
13792
+ return MeshTangentUtils._calculateTangents(null, null, null, indices, vertices);
13793
+ };
13794
+ MeshTangentUtils._calculateTangents = function _calculateTangents(positions, normals, uvs, indices, vertices) {
13795
+ var vertexCount = vertices ? vertices.length / 8 : positions.length;
13796
+ var indexCount = indices ? indices.length : vertexCount;
13797
+ // Accumulate the tangent basis in double precision
13798
+ var basis = new Float64Array(vertexCount * 6);
13799
+ for(var i = 0; i + 2 < indexCount; i += 3){
13800
+ var a = indices ? indices[i] : i;
13801
+ var b = indices ? indices[i + 1] : i + 1;
13802
+ var c = indices ? indices[i + 2] : i + 2;
13803
+ var e1x = void 0, e1y = void 0, e1z = void 0, e2x = void 0, e2y = void 0, e2z = void 0;
13804
+ var x1 = void 0, x2 = void 0, y1 = void 0, y2 = void 0;
13805
+ if (vertices) {
13806
+ var offsetA = a * 8;
13807
+ var offsetB = b * 8;
13808
+ var offsetC = c * 8;
13809
+ e1x = vertices[offsetB] - vertices[offsetA];
13810
+ e1y = vertices[offsetB + 1] - vertices[offsetA + 1];
13811
+ e1z = vertices[offsetB + 2] - vertices[offsetA + 2];
13812
+ e2x = vertices[offsetC] - vertices[offsetA];
13813
+ e2y = vertices[offsetC + 1] - vertices[offsetA + 1];
13814
+ e2z = vertices[offsetC + 2] - vertices[offsetA + 2];
13815
+ x1 = vertices[offsetB + 6] - vertices[offsetA + 6];
13816
+ x2 = vertices[offsetC + 6] - vertices[offsetA + 6];
13817
+ y1 = vertices[offsetB + 7] - vertices[offsetA + 7];
13818
+ y2 = vertices[offsetC + 7] - vertices[offsetA + 7];
13819
+ } else {
13820
+ var p0 = positions[a];
13821
+ var p1 = positions[b];
13822
+ var p2 = positions[c];
13823
+ var uv0 = uvs[a];
13824
+ var uv1 = uvs[b];
13825
+ var uv2 = uvs[c];
13826
+ e1x = p1.x - p0.x;
13827
+ e1y = p1.y - p0.y;
13828
+ e1z = p1.z - p0.z;
13829
+ e2x = p2.x - p0.x;
13830
+ e2y = p2.y - p0.y;
13831
+ e2z = p2.z - p0.z;
13832
+ x1 = uv1.x - uv0.x;
13833
+ x2 = uv2.x - uv0.x;
13834
+ y1 = uv1.y - uv0.y;
13835
+ y2 = uv2.y - uv0.y;
13836
+ }
13837
+ var determinant = x1 * y2 - x2 * y1;
13838
+ if (determinant === 0) {
13839
+ continue;
13840
+ }
13841
+ var inverse = 1 / determinant;
13842
+ var ty1 = y1 * inverse;
13843
+ var ty2 = y2 * inverse;
13844
+ var bx1 = x1 * inverse;
13845
+ var bx2 = x2 * inverse;
13846
+ var tx = e1x * ty2 - e2x * ty1;
13847
+ var ty = e1y * ty2 - e2y * ty1;
13848
+ var tz = e1z * ty2 - e2z * ty1;
13849
+ var bx = e2x * bx1 - e1x * bx2;
13850
+ var by = e2y * bx1 - e1y * bx2;
13851
+ var bz = e2z * bx1 - e1z * bx2;
13852
+ for(var corner = 0; corner < 3; corner++){
13853
+ var offset = (corner === 0 ? a : corner === 1 ? b : c) * 6;
13854
+ basis[offset] += tx;
13855
+ basis[offset + 1] += ty;
13856
+ basis[offset + 2] += tz;
13857
+ basis[offset + 3] += bx;
13858
+ basis[offset + 4] += by;
13859
+ basis[offset + 5] += bz;
13860
+ }
13861
+ }
13862
+ var tangents = vertices ? new Float32Array(vertexCount * 4) : new Array(vertexCount);
13863
+ for(var i1 = 0; i1 < vertexCount; i1++){
13864
+ var nx = void 0, ny = void 0, nz = void 0;
13865
+ if (vertices) {
13866
+ var offset1 = i1 * 8;
13867
+ nx = vertices[offset1 + 3];
13868
+ ny = vertices[offset1 + 4];
13869
+ nz = vertices[offset1 + 5];
13870
+ } else {
13871
+ var normal = normals[i1];
13872
+ nx = normal.x;
13873
+ ny = normal.y;
13874
+ nz = normal.z;
13875
+ }
13876
+ var offset2 = i1 * 6;
13877
+ var tx1 = basis[offset2];
13878
+ var ty3 = basis[offset2 + 1];
13879
+ var tz1 = basis[offset2 + 2];
13880
+ var bx3 = basis[offset2 + 3];
13881
+ var by1 = basis[offset2 + 4];
13882
+ var bz1 = basis[offset2 + 5];
13883
+ var handedness = (ty3 * bz1 - tz1 * by1) * nx + (tz1 * bx3 - tx1 * bz1) * ny + (tx1 * by1 - ty3 * bx3) * nz > 0 ? 1 : -1;
13884
+ // Custom normals need not have unit length
13885
+ var normalLengthSquared = nx * nx + ny * ny + nz * nz;
13886
+ var projection = normalLengthSquared > 0 ? (tx1 * nx + ty3 * ny + tz1 * nz) / normalLengthSquared : 0;
13887
+ tx1 -= nx * projection;
13888
+ ty3 -= ny * projection;
13889
+ tz1 -= nz * projection;
13890
+ var length = Math.hypot(tx1, ty3, tz1);
13891
+ if (length > 0) {
13892
+ var inverse1 = 1 / length;
13893
+ tx1 *= inverse1;
13894
+ ty3 *= inverse1;
13895
+ tz1 *= inverse1;
13896
+ }
13897
+ if (vertices) {
13898
+ var result = tangents;
13899
+ result[i1 * 4] = tx1;
13900
+ result[i1 * 4 + 1] = ty3;
13901
+ result[i1 * 4 + 2] = tz1;
13902
+ result[i1 * 4 + 3] = handedness;
13903
+ } else {
13904
+ tangents[i1] = new engineMath.Vector4(tx1, ty3, tz1, handedness);
13905
+ }
13906
+ }
13907
+ return tangents;
13908
+ };
13909
+ return MeshTangentUtils;
13910
+ }();
13911
+
13783
13912
  /**
13784
13913
  * Vertex attribute types of a vertex in a ModelMesh.
13785
13914
  */ var VertexAttribute = /*#__PURE__*/ function(VertexAttribute) {
@@ -14192,9 +14321,11 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
14192
14321
  }
14193
14322
  };
14194
14323
  /**
14195
- * Calculate mesh tangent.
14196
- * @remark need to set positions(with or not with indices), normals, uv before calculation.
14197
- * @remark based on http://foundationsofgameenginedev.com/FGED2-sample.pdf
14324
+ * Calculate tangents from readable positions, normals and UVs.
14325
+ * @remarks
14326
+ * Without indices, every three consecutive vertices form a triangle.
14327
+ * Incomplete trailing triangles and triangles with zero UV area are ignored.
14328
+ * @see http://foundationsofgameenginedev.com/FGED2-sample.pdf
14198
14329
  */ _proto.calculateTangents = function calculateTangents() {
14199
14330
  var positions = this.getPositions();
14200
14331
  var normals = this.getNormals();
@@ -14202,68 +14333,7 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
14202
14333
  if (!normals || !uvs) {
14203
14334
  throw "Set normal and uv before calculation.";
14204
14335
  }
14205
- var _this = this, indices = _this._indices, vertexCount = _this.vertexCount;
14206
- var e1 = ModelMesh._tempVec0, e2 = ModelMesh._tempVec1, t = ModelMesh._tempVec2, b = ModelMesh._tempVec3, temp = ModelMesh._tempVec4;
14207
- var triangleCount = indices ? indices.length / 3 : positions.length / 3;
14208
- var tangents = new Array(vertexCount);
14209
- var biTangents = new Array(vertexCount);
14210
- for(var i = 0; i < vertexCount; i++){
14211
- tangents[i] = new engineMath.Vector4();
14212
- biTangents[i] = new engineMath.Vector3();
14213
- }
14214
- // Calculate tangent and bi-tangent for each triangle and add to all three vertices.
14215
- for(var k = 0; k < triangleCount; k++){
14216
- var i0 = 3 * k;
14217
- var i1 = 3 * k + 1;
14218
- var i2 = 3 * k + 2;
14219
- if (indices) {
14220
- i0 = indices[i0];
14221
- i1 = indices[i1];
14222
- i2 = indices[i2];
14223
- }
14224
- var p0 = positions[i0];
14225
- var p1 = positions[i1];
14226
- var p2 = positions[i2];
14227
- var w0 = uvs[i0];
14228
- var w1 = uvs[i1];
14229
- var w2 = uvs[i2];
14230
- engineMath.Vector3.subtract(p1, p0, e1);
14231
- engineMath.Vector3.subtract(p2, p0, e2);
14232
- var x1 = w1.x - w0.x;
14233
- var x2 = w2.x - w0.x;
14234
- var y1 = w1.y - w0.y;
14235
- var y2 = w2.y - w0.y;
14236
- var r = 1.0 / (x1 * y2 - x2 * y1);
14237
- engineMath.Vector3.scale(e1, y2 * r, t);
14238
- engineMath.Vector3.scale(e2, y1 * r, temp);
14239
- engineMath.Vector3.subtract(t, temp, t);
14240
- engineMath.Vector3.scale(e2, x1 * r, b);
14241
- engineMath.Vector3.scale(e1, x2 * r, temp);
14242
- engineMath.Vector3.subtract(b, temp, b);
14243
- var tangent = tangents[i0];
14244
- tangent.set(tangent.x + t.x, tangent.y + t.y, tangent.z + t.z, 1.0);
14245
- tangent = tangents[i1];
14246
- tangent.set(tangent.x + t.x, tangent.y + t.y, tangent.z + t.z, 1.0);
14247
- tangent = tangents[i2];
14248
- tangent.set(tangent.x + t.x, tangent.y + t.y, tangent.z + t.z, 1.0);
14249
- biTangents[i0].add(b);
14250
- biTangents[i1].add(b);
14251
- biTangents[i2].add(b);
14252
- }
14253
- // Orthonormalize each tangent and calculate the handedness.
14254
- for(var i3 = 0; i3 < vertexCount; i3++){
14255
- var n = normals[i3];
14256
- var b1 = biTangents[i3];
14257
- var tangent1 = tangents[i3];
14258
- t.set(tangent1.x, tangent1.y, tangent1.z);
14259
- engineMath.Vector3.cross(t, b1, temp);
14260
- var w = engineMath.Vector3.dot(temp, n) > 0.0 ? 1 : -1;
14261
- engineMath.Vector3.scale(n, engineMath.Vector3.dot(t, n), temp);
14262
- engineMath.Vector3.subtract(t, temp, t);
14263
- t.normalize();
14264
- tangent1.set(t.x, t.y, t.z, w);
14265
- }
14266
- this.setTangents(tangents);
14336
+ this.setTangents(MeshTangentUtils.calculateTangents(positions, normals, uvs, this._indices));
14267
14337
  };
14268
14338
  /**
14269
14339
  * @internal
@@ -14271,25 +14341,25 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
14271
14341
  var _this = this;
14272
14342
  var vertexBufferBindings = this._primitive.vertexBufferBindings;
14273
14343
  var updateInfos = this._vertexBufferInfos;
14274
- var onVertexBufferChanged = function() {
14275
- if (!_this._advancedDataSyncToBuffer) {
14276
- updateInfos[index].dataVersion = _this._dataVersionCounter++;
14277
- }
14278
- };
14279
- // Remove listener from previous binding
14344
+ var updateInfo = updateInfos[index];
14280
14345
  var previousBinding = vertexBufferBindings[index];
14281
- previousBinding && previousBinding.buffer._dataUpdateManager.removeListener(onVertexBufferChanged);
14346
+ if (previousBinding) {
14347
+ previousBinding.buffer._dataUpdateManager.removeListener(updateInfo.onBufferChanged);
14348
+ }
14282
14349
  Mesh.prototype._setVertexBufferBinding.call(this, index, binding);
14283
- // Add listener to new binding and trigger update
14284
14350
  if (binding) {
14285
- var _updateInfos, _index;
14286
- binding.buffer._dataUpdateManager.addListener(onVertexBufferChanged);
14287
- ((_updateInfos = updateInfos)[_index = index] || (_updateInfos[_index] = new BufferUpdateInfo())).reset();
14288
- onVertexBufferChanged();
14289
- } else {
14290
- if (index + 1 == vertexBufferBindings.length) {
14291
- vertexBufferBindings.length--;
14351
+ if (!updateInfo) {
14352
+ updateInfo = updateInfos[index] = new BufferUpdateInfo(function() {
14353
+ if (!_this._advancedDataSyncToBuffer) {
14354
+ updateInfos[index].dataVersion = _this._dataVersionCounter++;
14355
+ }
14356
+ });
14292
14357
  }
14358
+ binding.buffer._dataUpdateManager.addListener(updateInfo.onBufferChanged);
14359
+ updateInfo.reset();
14360
+ updateInfo.onBufferChanged();
14361
+ } else if (index + 1 == vertexBufferBindings.length) {
14362
+ vertexBufferBindings.length--;
14293
14363
  }
14294
14364
  };
14295
14365
  /**
@@ -14311,6 +14381,11 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
14311
14381
  /**
14312
14382
  * @internal
14313
14383
  */ _proto._onDestroy = function _onDestroy() {
14384
+ var bindings = this._primitive.vertexBufferBindings;
14385
+ for(var i = 0; i < bindings.length; i++){
14386
+ var _bindings_i;
14387
+ (_bindings_i = bindings[i]) == null ? void 0 : _bindings_i.buffer._dataUpdateManager.removeListener(this._vertexBufferInfos[i].onBufferChanged);
14388
+ }
14314
14389
  Mesh.prototype._onDestroy.call(this);
14315
14390
  this._releaseCache(true);
14316
14391
  };
@@ -14782,13 +14857,9 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
14782
14857
  ]);
14783
14858
  return ModelMesh;
14784
14859
  }(Mesh);
14785
- ModelMesh._tempVec0 = new engineMath.Vector3();
14786
- ModelMesh._tempVec1 = new engineMath.Vector3();
14787
- ModelMesh._tempVec2 = new engineMath.Vector3();
14788
- ModelMesh._tempVec3 = new engineMath.Vector3();
14789
- ModelMesh._tempVec4 = new engineMath.Vector3();
14790
14860
  var BufferUpdateInfo = /*#__PURE__*/ function() {
14791
- function BufferUpdateInfo() {
14861
+ function BufferUpdateInfo(onBufferChanged) {
14862
+ this.onBufferChanged = onBufferChanged;
14792
14863
  this.dataVersion = -1;
14793
14864
  this.uploadAdvancedData = false;
14794
14865
  }
@@ -14799,337 +14870,2339 @@ var BufferUpdateInfo = /*#__PURE__*/ function() {
14799
14870
  return BufferUpdateInfo;
14800
14871
  }();
14801
14872
 
14873
+ function _type_of(obj) {
14874
+ "@swc/helpers - typeof";
14875
+
14876
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
14877
+ }
14878
+
14879
+ /**
14880
+ * End caps generated for cylinders and truncated cones.
14881
+ */ var PrimitiveMeshCapMode = /*#__PURE__*/ function(PrimitiveMeshCapMode) {
14882
+ /**
14883
+ * Generate both the top and bottom caps.
14884
+ */ PrimitiveMeshCapMode["Both"] = "both";
14885
+ /**
14886
+ * Generate only the top cap, facing +Y.
14887
+ */ PrimitiveMeshCapMode["Top"] = "top";
14888
+ /**
14889
+ * Generate only the bottom cap, facing -Y.
14890
+ */ PrimitiveMeshCapMode["Bottom"] = "bottom";
14891
+ /**
14892
+ * Leave both ends open.
14893
+ */ PrimitiveMeshCapMode["None"] = "none";
14894
+ return PrimitiveMeshCapMode;
14895
+ }({});
14896
+
14897
+ /**
14898
+ * @internal
14899
+ */ var PrimitiveMeshBuilder = /*#__PURE__*/ function() {
14900
+ function PrimitiveMeshBuilder(vertexCapacity, indexCapacity) {
14901
+ if (vertexCapacity === void 0) vertexCapacity = 0;
14902
+ if (indexCapacity === void 0) indexCapacity = 0;
14903
+ this.vertexCount = 0;
14904
+ this.indexCount = 0;
14905
+ this.groups = [];
14906
+ this.vertices = new Float32Array(vertexCapacity * 8);
14907
+ this.indices = vertexCapacity > 65535 ? new Uint32Array(indexCapacity) : new Uint16Array(indexCapacity);
14908
+ }
14909
+ var _proto = PrimitiveMeshBuilder.prototype;
14910
+ _proto.addVertex = function addVertex(x, y, z, nx, ny, nz, u, v) {
14911
+ var index = this.vertexCount++;
14912
+ this._ensureVertexCapacity(this.vertexCount);
14913
+ var length = Math.hypot(nx, ny, nz);
14914
+ var inverse = length > 0 ? 1 / length : 0;
14915
+ var vertices = this.vertices;
14916
+ var offset = index * 8;
14917
+ vertices[offset] = x;
14918
+ vertices[offset + 1] = y;
14919
+ vertices[offset + 2] = z;
14920
+ vertices[offset + 3] = nx * inverse;
14921
+ vertices[offset + 4] = ny * inverse;
14922
+ vertices[offset + 5] = nz * inverse;
14923
+ vertices[offset + 6] = u;
14924
+ vertices[offset + 7] = v;
14925
+ return index;
14926
+ };
14927
+ _proto.addTriangle = function addTriangle(a, b, c) {
14928
+ this._ensureIndexCapacity(this.indexCount + 3);
14929
+ this.indices[this.indexCount++] = a;
14930
+ this.indices[this.indexCount++] = b;
14931
+ this.indices[this.indexCount++] = c;
14932
+ };
14933
+ _proto.addIndex = function addIndex(index) {
14934
+ this._ensureIndexCapacity(this.indexCount + 1);
14935
+ this.indices[this.indexCount++] = index;
14936
+ };
14937
+ _proto.addGroup = function addGroup(start) {
14938
+ var count = this.indexCount - start;
14939
+ if (count > 0) {
14940
+ this.groups.push({
14941
+ start: start,
14942
+ count: count
14943
+ });
14944
+ }
14945
+ };
14946
+ _proto.addFace = function addFace(a, b, c, uvA, uvB, uvC) {
14947
+ var abX = b.x - a.x;
14948
+ var abY = b.y - a.y;
14949
+ var abZ = b.z - a.z;
14950
+ var acX = c.x - a.x;
14951
+ var acY = c.y - a.y;
14952
+ var acZ = c.z - a.z;
14953
+ var nx = abY * acZ - abZ * acY;
14954
+ var ny = abZ * acX - abX * acZ;
14955
+ var nz = abX * acY - abY * acX;
14956
+ var start = this.vertexCount;
14957
+ this.addVertex(a.x, a.y, a.z, nx, ny, nz, uvA.x, uvA.y);
14958
+ this.addVertex(b.x, b.y, b.z, nx, ny, nz, uvB.x, uvB.y);
14959
+ this.addVertex(c.x, c.y, c.z, nx, ny, nz, uvC.x, uvC.y);
14960
+ this.addTriangle(start, start + 1, start + 2);
14961
+ };
14962
+ _proto.setData = function setData(vertices, indices) {
14963
+ this.vertices = vertices;
14964
+ this.indices = indices;
14965
+ this.vertexCount = vertices.length / 8;
14966
+ this.indexCount = indices.length;
14967
+ };
14968
+ _proto.trim = function trim() {
14969
+ if (this.vertices.length !== this.vertexCount * 8) {
14970
+ this.vertices = this.vertices.subarray(0, this.vertexCount * 8);
14971
+ }
14972
+ if (this.indices.length !== this.indexCount) {
14973
+ this.indices = this.indices.subarray(0, this.indexCount);
14974
+ }
14975
+ var IndexArray = this.vertexCount > 65535 ? Uint32Array : Uint16Array;
14976
+ if (!_instanceof(this.indices, IndexArray)) {
14977
+ this.indices = new IndexArray(this.indices);
14978
+ }
14979
+ };
14980
+ _proto._ensureVertexCapacity = function _ensureVertexCapacity(count) {
14981
+ if (count * 8 > this.vertices.length) {
14982
+ var vertices = new Float32Array(Math.max(count * 8, this.vertices.length * 2, 64));
14983
+ vertices.set(this.vertices);
14984
+ this.vertices = vertices;
14985
+ }
14986
+ };
14987
+ _proto._ensureIndexCapacity = function _ensureIndexCapacity(count) {
14988
+ var previous = this.indices;
14989
+ var useUint32 = this.vertexCount > 65535;
14990
+ if (count > previous.length || useUint32 && _instanceof(previous, Uint16Array)) {
14991
+ var capacity = count > previous.length ? Math.max(count, previous.length * 2, 24) : previous.length;
14992
+ var IndexArray = useUint32 || _instanceof(previous, Uint32Array) ? Uint32Array : Uint16Array;
14993
+ var indices = new IndexArray(capacity);
14994
+ indices.set(previous);
14995
+ this.indices = indices;
14996
+ }
14997
+ };
14998
+ return PrimitiveMeshBuilder;
14999
+ }();
15000
+
14802
15001
  /**
14803
15002
  * @internal
14804
15003
  */ var PrimitiveMeshRestorer = /*#__PURE__*/ function(ContentRestorer) {
14805
15004
  _inherits(PrimitiveMeshRestorer, ContentRestorer);
14806
- function PrimitiveMeshRestorer(resource, primitiveInfo) {
15005
+ function PrimitiveMeshRestorer(mesh, _generate, _args) {
14807
15006
  var _this;
14808
- _this = ContentRestorer.call(this, resource) || this, _this.primitiveInfo = primitiveInfo;
15007
+ var _mesh_vertexBufferBindings_;
15008
+ _this = ContentRestorer.call(this, mesh) || this, _this._generate = _generate, _this._args = _args;
15009
+ _this._vertexBuffer = mesh.vertexBufferBindings[0].buffer;
15010
+ _this._tangentBuffer = (_mesh_vertexBufferBindings_ = mesh.vertexBufferBindings[1]) == null ? void 0 : _mesh_vertexBufferBindings_.buffer;
15011
+ _this._indexBuffer = mesh._primitive.indexBufferBinding._buffer;
14809
15012
  return _this;
14810
15013
  }
14811
15014
  var _proto = PrimitiveMeshRestorer.prototype;
14812
15015
  _proto.restoreContent = function restoreContent() {
14813
- var primitiveInfo = this.primitiveInfo;
14814
- switch(primitiveInfo.type){
14815
- case 0:
14816
- var sphereInfo = primitiveInfo;
14817
- PrimitiveMesh._setSphereData(this.resource, sphereInfo.radius, sphereInfo.segments, sphereInfo.noLongerAccessible, true, sphereInfo.vertexBuffer);
14818
- break;
14819
- case 7:
14820
- var CCSphereInfo = primitiveInfo;
14821
- PrimitiveMesh._setSubdivisionSurfaceSphereData(this.resource, CCSphereInfo.radius, CCSphereInfo.step, CCSphereInfo.noLongerAccessible, true, CCSphereInfo.vertexBuffer);
14822
- break;
14823
- case 1:
14824
- var cuboidInfo = primitiveInfo;
14825
- PrimitiveMesh._setCuboidData(this.resource, cuboidInfo.width, cuboidInfo.height, cuboidInfo.depth, cuboidInfo.noLongerAccessible, true, cuboidInfo.vertexBuffer);
14826
- break;
14827
- case 2:
14828
- var planeInfo = primitiveInfo;
14829
- PrimitiveMesh._setPlaneData(this.resource, planeInfo.width, planeInfo.height, planeInfo.horizontalSegments, planeInfo.verticalSegments, planeInfo.noLongerAccessible, true, planeInfo.vertexBuffer);
14830
- break;
14831
- case 3:
14832
- var cylinderInfo = primitiveInfo;
14833
- PrimitiveMesh._setCylinderData(this.resource, cylinderInfo.radiusTop, cylinderInfo.radiusBottom, cylinderInfo.height, cylinderInfo.radialSegments, cylinderInfo.heightSegments, cylinderInfo.noLongerAccessible, true, cylinderInfo.vertexBuffer);
14834
- break;
14835
- case 4:
14836
- var torusInfo = primitiveInfo;
14837
- PrimitiveMesh._setTorusData(this.resource, torusInfo.radius, torusInfo.tubeRadius, torusInfo.radialSegments, torusInfo.tubularSegments, torusInfo.arc, torusInfo.noLongerAccessible, true, torusInfo.vertexBuffer);
14838
- break;
14839
- case 5:
14840
- var coneInfo = primitiveInfo;
14841
- PrimitiveMesh._setConeData(this.resource, coneInfo.radius, coneInfo.height, coneInfo.radialSegments, coneInfo.heightSegments, coneInfo.noLongerAccessible, true, coneInfo.vertexBuffer);
14842
- break;
14843
- case 6:
14844
- var capsuleInfo = primitiveInfo;
14845
- PrimitiveMesh._setCapsuleData(this.resource, capsuleInfo.radius, capsuleInfo.height, capsuleInfo.radialSegments, capsuleInfo.heightSegments, capsuleInfo.noLongerAccessible, true, capsuleInfo.vertexBuffer);
14846
- break;
15016
+ var _mesh__primitive_indexBufferBinding;
15017
+ var mesh = this.resource;
15018
+ var data = this._generate.apply(this, [].concat(this._args));
15019
+ data.trim();
15020
+ for(var _iterator = _create_for_of_iterator_helper_loose(mesh.vertexBufferBindings), _step; !(_step = _iterator()).done;){
15021
+ var binding = _step.value;
15022
+ var buffer = binding == null ? void 0 : binding.buffer;
15023
+ if (!buffer) {
15024
+ continue;
15025
+ }
15026
+ if (buffer === this._vertexBuffer) {
15027
+ buffer.setData(data.vertices);
15028
+ } else if (buffer === this._tangentBuffer) {
15029
+ buffer.setData(MeshTangentUtils.calculateTangentsFromBuffer(data.vertices, data.indices));
15030
+ }
15031
+ }
15032
+ var indexBuffer = (_mesh__primitive_indexBufferBinding = mesh._primitive.indexBufferBinding) == null ? void 0 : _mesh__primitive_indexBufferBinding._buffer;
15033
+ if (indexBuffer === this._indexBuffer) {
15034
+ indexBuffer.setData(data.indices);
14847
15035
  }
14848
15036
  };
14849
15037
  return PrimitiveMeshRestorer;
14850
15038
  }(ContentRestorer);
15039
+
14851
15040
  /**
14852
15041
  * @internal
14853
- */ var PrimitiveRestoreInfo = function PrimitiveRestoreInfo(type, vertexBuffer, noLongerAccessible) {
14854
- this.type = type;
14855
- this.vertexBuffer = vertexBuffer;
14856
- this.noLongerAccessible = noLongerAccessible;
14857
- };
14858
- /**
14859
- * @internal
14860
- */ var SphereRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
14861
- _inherits(SphereRestoreInfo, PrimitiveRestoreInfo);
14862
- function SphereRestoreInfo(radius, segments, vertexBuffer, noLongerAccessible) {
14863
- var _this;
14864
- _this = PrimitiveRestoreInfo.call(this, 0, vertexBuffer, noLongerAccessible) || this, _this.radius = radius, _this.segments = segments;
14865
- return _this;
14866
- }
14867
- return SphereRestoreInfo;
14868
- }(PrimitiveRestoreInfo);
14869
- /**
14870
- * @internal
14871
- */ var SubdivisionSurfaceSphereRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
14872
- _inherits(SubdivisionSurfaceSphereRestoreInfo, PrimitiveRestoreInfo);
14873
- function SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible) {
14874
- var _this;
14875
- _this = PrimitiveRestoreInfo.call(this, 7, vertexBuffer, noLongerAccessible) || this, _this.radius = radius, _this.step = step;
14876
- return _this;
14877
- }
14878
- return SubdivisionSurfaceSphereRestoreInfo;
14879
- }(PrimitiveRestoreInfo);
14880
- /**
14881
- * @internal
14882
- */ var CuboidRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
14883
- _inherits(CuboidRestoreInfo, PrimitiveRestoreInfo);
14884
- function CuboidRestoreInfo(width, height, depth, vertexBuffer, noLongerAccessible) {
14885
- var _this;
14886
- _this = PrimitiveRestoreInfo.call(this, 1, vertexBuffer, noLongerAccessible) || this, _this.width = width, _this.height = height, _this.depth = depth;
14887
- return _this;
14888
- }
14889
- return CuboidRestoreInfo;
14890
- }(PrimitiveRestoreInfo);
14891
- /**
14892
- * @internal
14893
- */ var PlaneRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
14894
- _inherits(PlaneRestoreInfo, PrimitiveRestoreInfo);
14895
- function PlaneRestoreInfo(width, height, horizontalSegments, verticalSegments, vertexBuffer, noLongerAccessible) {
14896
- var _this;
14897
- _this = PrimitiveRestoreInfo.call(this, 2, vertexBuffer, noLongerAccessible) || this, _this.width = width, _this.height = height, _this.horizontalSegments = horizontalSegments, _this.verticalSegments = verticalSegments;
14898
- return _this;
14899
- }
14900
- return PlaneRestoreInfo;
14901
- }(PrimitiveRestoreInfo);
14902
- /**
14903
- * @internal
14904
- */ var CylinderRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
14905
- _inherits(CylinderRestoreInfo, PrimitiveRestoreInfo);
14906
- function CylinderRestoreInfo(radiusTop, radiusBottom, height, radialSegments, heightSegments, vertexBuffer, noLongerAccessible) {
14907
- var _this;
14908
- _this = PrimitiveRestoreInfo.call(this, 3, vertexBuffer, noLongerAccessible) || this, _this.radiusTop = radiusTop, _this.radiusBottom = radiusBottom, _this.height = height, _this.radialSegments = radialSegments, _this.heightSegments = heightSegments;
14909
- return _this;
14910
- }
14911
- return CylinderRestoreInfo;
14912
- }(PrimitiveRestoreInfo);
14913
- /**
14914
- * @internal
14915
- */ var TorusRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
14916
- _inherits(TorusRestoreInfo, PrimitiveRestoreInfo);
14917
- function TorusRestoreInfo(radius, tubeRadius, radialSegments, tubularSegments, arc, vertexBuffer, noLongerAccessible) {
14918
- var _this;
14919
- _this = PrimitiveRestoreInfo.call(this, 4, vertexBuffer, noLongerAccessible) || this, _this.radius = radius, _this.tubeRadius = tubeRadius, _this.radialSegments = radialSegments, _this.tubularSegments = tubularSegments, _this.arc = arc;
14920
- return _this;
14921
- }
14922
- return TorusRestoreInfo;
14923
- }(PrimitiveRestoreInfo);
15042
+ */ var MeshPathUtils = /*#__PURE__*/ function() {
15043
+ function MeshPathUtils() {}
15044
+ MeshPathUtils.sample = function sample(path, divisions, closed, tangents) {
15045
+ var result = new Array(divisions + 1);
15046
+ if (path.length < 2) {
15047
+ throw new Error("A mesh path needs at least two points.");
15048
+ }
15049
+ var points = [];
15050
+ for(var _iterator = _create_for_of_iterator_helper_loose(path), _step; !(_step = _iterator()).done;){
15051
+ var point = _step.value;
15052
+ if (points.length === 0 || engineMath.Vector3.distance(points[points.length - 1], point) > 0) {
15053
+ points.push(point);
15054
+ }
15055
+ }
15056
+ if (closed && engineMath.Vector3.distance(points[0], points[points.length - 1]) > 0) {
15057
+ points.push(points[0]);
15058
+ }
15059
+ var lengths = new Float64Array(points.length);
15060
+ for(var i = 1; i < points.length; i++){
15061
+ lengths[i] = lengths[i - 1] + engineMath.Vector3.distance(points[i], points[i - 1]);
15062
+ }
15063
+ var length = lengths[lengths.length - 1];
15064
+ if (length === 0) {
15065
+ throw new Error("A mesh path must have nonzero length.");
15066
+ }
15067
+ if (tangents) {
15068
+ tangents.length = divisions + 1;
15069
+ }
15070
+ var adjacent = new engineMath.Vector3();
15071
+ var direction = new engineMath.Vector3();
15072
+ var tangent;
15073
+ var tangentEdge = 0;
15074
+ var edge = 1;
15075
+ for(var i1 = 0; i1 <= divisions; i1++){
15076
+ var distance = i1 / divisions * length;
15077
+ while(edge < lengths.length - 1 && lengths[edge] < distance){
15078
+ edge++;
15079
+ }
15080
+ var edgeLength = lengths[edge] - lengths[edge - 1];
15081
+ var t = edgeLength > 0 ? (distance - lengths[edge - 1]) / edgeLength : 0;
15082
+ var point1 = new engineMath.Vector3();
15083
+ engineMath.Vector3.lerp(points[edge - 1], points[edge], t, point1);
15084
+ result[i1] = point1;
15085
+ if (tangents) {
15086
+ if (tangentEdge !== edge) {
15087
+ engineMath.Vector3.subtract(points[edge], points[edge - 1], direction);
15088
+ MeshPathUtils._normalize(direction);
15089
+ tangent = MeshPathUtils._normalize(direction.clone());
15090
+ tangentEdge = edge;
15091
+ }
15092
+ if (t === 0 && (edge > 1 || closed)) {
15093
+ var previous = points[edge > 1 ? edge - 2 : points.length - 2];
15094
+ engineMath.Vector3.subtract(points[edge - 1], previous, adjacent);
15095
+ } else if (t === 1 && (edge + 1 < points.length || closed)) {
15096
+ var next = points[edge + 1 < points.length ? edge + 1 : 1];
15097
+ engineMath.Vector3.subtract(next, points[edge], adjacent);
15098
+ } else {
15099
+ tangents[i1] = tangent;
15100
+ continue;
15101
+ }
15102
+ MeshPathUtils._normalize(adjacent).add(direction);
15103
+ tangents[i1] = engineMath.Vector3.dot(adjacent, adjacent) > 0 ? MeshPathUtils._normalize(adjacent.clone()) : tangent;
15104
+ }
15105
+ }
15106
+ return result;
15107
+ };
15108
+ MeshPathUtils.computeFrames = function computeFrames(points, closed, fallbackTangents) {
15109
+ var last = points.length - 1;
15110
+ var tangents = new Array(points.length);
15111
+ for(var i = 0; i <= last; i++){
15112
+ var before = points[i === 0 ? closed ? last - 1 : 0 : i - 1];
15113
+ var after = points[i === last ? closed ? 1 : last : i + 1];
15114
+ var tangent = new engineMath.Vector3();
15115
+ engineMath.Vector3.subtract(after, before, tangent);
15116
+ if (engineMath.Vector3.dot(tangent, tangent) === 0 && fallbackTangents) {
15117
+ tangent.copyFrom(fallbackTangents[i]);
15118
+ }
15119
+ tangents[i] = MeshPathUtils._normalize(tangent);
15120
+ }
15121
+ var tangent1 = tangents[0];
15122
+ var axis = Math.abs(tangent1.x) <= Math.abs(tangent1.y) && Math.abs(tangent1.x) <= Math.abs(tangent1.z) ? new engineMath.Vector3(1, 0, 0) : Math.abs(tangent1.y) <= Math.abs(tangent1.z) ? new engineMath.Vector3(0, 1, 0) : new engineMath.Vector3(0, 0, 1);
15123
+ var normal = new engineMath.Vector3();
15124
+ var binormal = new engineMath.Vector3();
15125
+ engineMath.Vector3.cross(tangent1, axis, normal);
15126
+ MeshPathUtils._normalize(normal);
15127
+ engineMath.Vector3.cross(tangent1, normal, binormal);
15128
+ MeshPathUtils._normalize(binormal);
15129
+ var normals = [
15130
+ normal
15131
+ ];
15132
+ var binormals = [
15133
+ binormal
15134
+ ];
15135
+ var rotationAxis = new engineMath.Vector3();
15136
+ for(var i1 = 1; i1 <= last; i1++){
15137
+ engineMath.Vector3.cross(tangents[i1 - 1], tangents[i1], rotationAxis);
15138
+ var sine = Math.hypot(rotationAxis.x, rotationAxis.y, rotationAxis.z);
15139
+ var normal1 = normals[i1 - 1];
15140
+ if (sine > 1e-10) {
15141
+ normal1 = MeshPathUtils._rotate(normal1, MeshPathUtils._normalize(rotationAxis), Math.atan2(sine, engineMath.Vector3.dot(tangents[i1 - 1], tangents[i1])), new engineMath.Vector3());
15142
+ }
15143
+ normals.push(normal1);
15144
+ var binormal1 = new engineMath.Vector3();
15145
+ engineMath.Vector3.cross(tangents[i1], normal1, binormal1);
15146
+ binormals.push(MeshPathUtils._normalize(binormal1));
15147
+ }
15148
+ if (closed) {
15149
+ engineMath.Vector3.cross(normals[last], normals[0], rotationAxis);
15150
+ var angle = Math.atan2(engineMath.Vector3.dot(tangents[0], rotationAxis), engineMath.Vector3.dot(normals[last], normals[0]));
15151
+ for(var i2 = 1; i2 <= last; i2++){
15152
+ normals[i2] = MeshPathUtils._rotate(normals[i2], tangents[i2], angle * i2 / last, new engineMath.Vector3());
15153
+ engineMath.Vector3.cross(tangents[i2], normals[i2], binormals[i2]);
15154
+ MeshPathUtils._normalize(binormals[i2]);
15155
+ }
15156
+ }
15157
+ return {
15158
+ normals: normals,
15159
+ binormals: binormals
15160
+ };
15161
+ };
15162
+ MeshPathUtils._normalize = function _normalize(vector) {
15163
+ var length = Math.hypot(vector.x, vector.y, vector.z);
15164
+ return vector.scale(length > 0 ? 1 / length : 0);
15165
+ };
15166
+ MeshPathUtils._rotate = function _rotate(point, axis, angle, out) {
15167
+ var c = Math.cos(angle);
15168
+ var s = Math.sin(angle);
15169
+ var px = axis.y * point.z - axis.z * point.y;
15170
+ var py = axis.z * point.x - axis.x * point.z;
15171
+ var pz = axis.x * point.y - axis.y * point.x;
15172
+ var parallel = engineMath.Vector3.dot(axis, point) * (1 - c);
15173
+ return out.set(point.x * c + px * s + axis.x * parallel, point.y * c + py * s + axis.y * parallel, point.z * c + pz * s + axis.z * parallel);
15174
+ };
15175
+ return MeshPathUtils;
15176
+ }();
15177
+
14924
15178
  /**
14925
15179
  * @internal
14926
- */ var ConeRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
14927
- _inherits(ConeRestoreInfo, PrimitiveRestoreInfo);
14928
- function ConeRestoreInfo(radius, height, radialSegments, heightSegments, vertexBuffer, noLongerAccessible) {
14929
- var _this;
14930
- _this = PrimitiveRestoreInfo.call(this, 5, vertexBuffer, noLongerAccessible) || this, _this.radius = radius, _this.height = height, _this.radialSegments = radialSegments, _this.heightSegments = heightSegments;
14931
- return _this;
14932
- }
14933
- return ConeRestoreInfo;
14934
- }(PrimitiveRestoreInfo);
15180
+ */ var PolygonUtils = /*#__PURE__*/ function() {
15181
+ function PolygonUtils() {}
15182
+ PolygonUtils.prepareContours = function prepareContours(shape) {
15183
+ var _shape_holes;
15184
+ return [].concat([
15185
+ shape.points
15186
+ ], (_shape_holes = shape.holes) != null ? _shape_holes : []).map(function(points, index) {
15187
+ var contour = [];
15188
+ for(var _iterator = _create_for_of_iterator_helper_loose(points), _step; !(_step = _iterator()).done;){
15189
+ var point = _step.value;
15190
+ var previous = contour[contour.length - 1];
15191
+ if (!previous || previous.x !== point.x || previous.y !== point.y) {
15192
+ contour.push(point);
15193
+ }
15194
+ }
15195
+ var first = contour[0];
15196
+ var last = contour[contour.length - 1];
15197
+ if (contour.length > 1 && first.x === last.x && first.y === last.y) {
15198
+ contour.pop();
15199
+ }
15200
+ if (contour.length < 3) {
15201
+ throw new Error("A mesh contour needs at least three distinct points.");
15202
+ }
15203
+ var area = 0;
15204
+ for(var i = 0; i < contour.length; i++){
15205
+ var next = contour[(i + 1) % contour.length];
15206
+ area += contour[i].x * next.y - next.x * contour[i].y;
15207
+ }
15208
+ if (area > 0 !== (index === 0)) {
15209
+ contour.reverse();
15210
+ }
15211
+ return contour;
15212
+ });
15213
+ };
15214
+ PolygonUtils.triangulateContours = function triangulateContours(contours) {
15215
+ var points = [];
15216
+ var holes = [];
15217
+ for(var i = 0; i < contours.length; i++){
15218
+ if (i > 0) {
15219
+ holes.push(points.length);
15220
+ }
15221
+ for(var _iterator = _create_for_of_iterator_helper_loose(contours[i]), _step; !(_step = _iterator()).done;){
15222
+ var point = _step.value;
15223
+ points.push(point);
15224
+ }
15225
+ }
15226
+ var coordinates = new Float64Array(points.length * 2);
15227
+ for(var i1 = 0; i1 < points.length; i1++){
15228
+ coordinates[2 * i1] = points[i1].x;
15229
+ coordinates[2 * i1 + 1] = points[i1].y;
15230
+ }
15231
+ var indices = PolygonUtils.triangulate(coordinates, holes);
15232
+ for(var i2 = 0; i2 < indices.length; i2 += 3){
15233
+ var a = points[indices[i2]];
15234
+ var b = points[indices[i2 + 1]];
15235
+ var c = points[indices[i2 + 2]];
15236
+ if ((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x) < 0) {
15237
+ var ref;
15238
+ ref = [
15239
+ indices[i2 + 2],
15240
+ indices[i2 + 1]
15241
+ ], indices[i2 + 1] = ref[0], indices[i2 + 2] = ref[1];
15242
+ }
15243
+ }
15244
+ return {
15245
+ points: points,
15246
+ indices: indices
15247
+ };
15248
+ };
15249
+ PolygonUtils.triangulate = function triangulate(data, holeIndices) {
15250
+ if (holeIndices === void 0) holeIndices = [];
15251
+ var hasHoles = holeIndices.length > 0;
15252
+ var outerLen = hasHoles ? holeIndices[0] * 2 : data.length;
15253
+ var outerNode = PolygonUtils._linkedList(data, 0, outerLen, true);
15254
+ var triangles = [];
15255
+ if (!outerNode || outerNode.next === outerNode.prev) {
15256
+ return triangles;
15257
+ }
15258
+ var minX = 0, minY = 0, invSize = 0;
15259
+ if (hasHoles) {
15260
+ outerNode = PolygonUtils._eliminateHoles(data, holeIndices, outerNode);
15261
+ }
15262
+ // Spatial indexing avoids testing every vertex against each ear in large polygons
15263
+ if (data.length > 160) {
15264
+ minX = data[0];
15265
+ minY = data[1];
15266
+ var maxX = minX;
15267
+ var maxY = minY;
15268
+ for(var i = 2; i < outerLen; i += 2){
15269
+ var x = data[i];
15270
+ var y = data[i + 1];
15271
+ if (x < minX) {
15272
+ minX = x;
15273
+ }
15274
+ if (y < minY) {
15275
+ minY = y;
15276
+ }
15277
+ if (x > maxX) {
15278
+ maxX = x;
15279
+ }
15280
+ if (y > maxY) {
15281
+ maxY = y;
15282
+ }
15283
+ }
15284
+ // Morton codes use 15 bits per coordinate
15285
+ invSize = Math.max(maxX - minX, maxY - minY);
15286
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
15287
+ }
15288
+ PolygonUtils._earcutLinked(outerNode, triangles, minX, minY, invSize, 0);
15289
+ return triangles;
15290
+ };
15291
+ PolygonUtils._linkedList = function _linkedList(data, start, end, clockwise) {
15292
+ var last = null;
15293
+ if (clockwise === PolygonUtils._signedArea(data, start, end) > 0) {
15294
+ for(var i = start; i < end; i += 2){
15295
+ last = PolygonUtils._insertNode(i / 2 | 0, data[i], data[i + 1], last);
15296
+ }
15297
+ } else {
15298
+ for(var i1 = end - 2; i1 >= start; i1 -= 2){
15299
+ last = PolygonUtils._insertNode(i1 / 2 | 0, data[i1], data[i1 + 1], last);
15300
+ }
15301
+ }
15302
+ if (last && PolygonUtils._equals(last, last.next)) {
15303
+ PolygonUtils._removeNode(last);
15304
+ last = last.next;
15305
+ }
15306
+ return last;
15307
+ };
15308
+ PolygonUtils._filterPoints = function _filterPoints(start, end) {
15309
+ if (end === void 0) end = start;
15310
+ var p = start;
15311
+ var again;
15312
+ do {
15313
+ again = false;
15314
+ if (!p.steiner && (PolygonUtils._equals(p, p.next) || PolygonUtils._area(p.prev, p, p.next) === 0)) {
15315
+ PolygonUtils._removeNode(p);
15316
+ p = end = p.prev;
15317
+ if (p === p.next) {
15318
+ break;
15319
+ }
15320
+ again = true;
15321
+ } else {
15322
+ p = p.next;
15323
+ }
15324
+ }while (again || p !== end);
15325
+ return end;
15326
+ };
15327
+ PolygonUtils._earcutLinked = function _earcutLinked(ear, triangles, minX, minY, invSize, pass) {
15328
+ if (!pass && invSize) {
15329
+ PolygonUtils._indexCurve(ear, minX, minY, invSize);
15330
+ }
15331
+ var stop = ear;
15332
+ while(ear.prev !== ear.next){
15333
+ var prev = ear.prev;
15334
+ var next = ear.next;
15335
+ if (invSize ? PolygonUtils._isEarHashed(ear, minX, minY, invSize) : PolygonUtils._isEar(ear)) {
15336
+ triangles.push(prev.i, ear.i, next.i);
15337
+ PolygonUtils._removeNode(ear);
15338
+ // Skipping the adjacent vertex reduces narrow triangles
15339
+ ear = next.next;
15340
+ stop = next.next;
15341
+ continue;
15342
+ }
15343
+ ear = next;
15344
+ if (ear === stop) {
15345
+ // Retry after removing degeneracies, then heal intersections or split the ring
15346
+ if (!pass) {
15347
+ PolygonUtils._earcutLinked(PolygonUtils._filterPoints(ear), triangles, minX, minY, invSize, 1);
15348
+ } else if (pass === 1) {
15349
+ ear = PolygonUtils._cureLocalIntersections(PolygonUtils._filterPoints(ear), triangles);
15350
+ PolygonUtils._earcutLinked(ear, triangles, minX, minY, invSize, 2);
15351
+ } else if (pass === 2) {
15352
+ PolygonUtils._splitEarcut(ear, triangles, minX, minY, invSize);
15353
+ }
15354
+ break;
15355
+ }
15356
+ }
15357
+ };
15358
+ PolygonUtils._isEar = function _isEar(ear) {
15359
+ var a = ear.prev, b = ear, c = ear.next;
15360
+ if (PolygonUtils._area(a, b, c) >= 0) {
15361
+ return false;
15362
+ }
15363
+ var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
15364
+ var x0 = Math.min(ax, bx, cx), y0 = Math.min(ay, by, cy), x1 = Math.max(ax, bx, cx), y1 = Math.max(ay, by, cy);
15365
+ var p = c.next;
15366
+ while(p !== a){
15367
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && PolygonUtils._pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && PolygonUtils._area(p.prev, p, p.next) >= 0) {
15368
+ return false;
15369
+ }
15370
+ p = p.next;
15371
+ }
15372
+ return true;
15373
+ };
15374
+ PolygonUtils._isEarHashed = function _isEarHashed(ear, minX, minY, invSize) {
15375
+ var a = ear.prev, b = ear, c = ear.next;
15376
+ if (PolygonUtils._area(a, b, c) >= 0) {
15377
+ return false;
15378
+ }
15379
+ var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
15380
+ var x0 = Math.min(ax, bx, cx), y0 = Math.min(ay, by, cy), x1 = Math.max(ax, bx, cx), y1 = Math.max(ay, by, cy);
15381
+ var minZ = PolygonUtils._zOrder(x0, y0, minX, minY, invSize), maxZ = PolygonUtils._zOrder(x1, y1, minX, minY, invSize);
15382
+ var p = ear.prevZ, n = ear.nextZ;
15383
+ while(p && p.z >= minZ && n && n.z <= maxZ){
15384
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && PolygonUtils._pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && PolygonUtils._area(p.prev, p, p.next) >= 0) {
15385
+ return false;
15386
+ }
15387
+ p = p.prevZ;
15388
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && PolygonUtils._pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, n.x, n.y) && PolygonUtils._area(n.prev, n, n.next) >= 0) {
15389
+ return false;
15390
+ }
15391
+ n = n.nextZ;
15392
+ }
15393
+ while(p && p.z >= minZ){
15394
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && PolygonUtils._pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && PolygonUtils._area(p.prev, p, p.next) >= 0) {
15395
+ return false;
15396
+ }
15397
+ p = p.prevZ;
15398
+ }
15399
+ while(n && n.z <= maxZ){
15400
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && PolygonUtils._pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, n.x, n.y) && PolygonUtils._area(n.prev, n, n.next) >= 0) {
15401
+ return false;
15402
+ }
15403
+ n = n.nextZ;
15404
+ }
15405
+ return true;
15406
+ };
15407
+ PolygonUtils._cureLocalIntersections = function _cureLocalIntersections(start, triangles) {
15408
+ var p = start;
15409
+ do {
15410
+ var a = p.prev, b = p.next.next;
15411
+ if (!PolygonUtils._equals(a, b) && PolygonUtils._intersects(a, p, p.next, b) && PolygonUtils._locallyInside(a, b) && PolygonUtils._locallyInside(b, a)) {
15412
+ triangles.push(a.i, p.i, b.i);
15413
+ PolygonUtils._removeNode(p);
15414
+ PolygonUtils._removeNode(p.next);
15415
+ p = start = b;
15416
+ }
15417
+ p = p.next;
15418
+ }while (p !== start);
15419
+ return PolygonUtils._filterPoints(p);
15420
+ };
15421
+ PolygonUtils._splitEarcut = function _splitEarcut(start, triangles, minX, minY, invSize) {
15422
+ var a = start;
15423
+ do {
15424
+ var b = a.next.next;
15425
+ while(b !== a.prev){
15426
+ if (a.i !== b.i && PolygonUtils._isValidDiagonal(a, b)) {
15427
+ var c = PolygonUtils._splitPolygon(a, b);
15428
+ a = PolygonUtils._filterPoints(a, a.next);
15429
+ c = PolygonUtils._filterPoints(c, c.next);
15430
+ PolygonUtils._earcutLinked(a, triangles, minX, minY, invSize, 0);
15431
+ PolygonUtils._earcutLinked(c, triangles, minX, minY, invSize, 0);
15432
+ return;
15433
+ }
15434
+ b = b.next;
15435
+ }
15436
+ a = a.next;
15437
+ }while (a !== start);
15438
+ };
15439
+ PolygonUtils._eliminateHoles = function _eliminateHoles(data, holeIndices, outerNode) {
15440
+ var queue = [];
15441
+ for(var i = 0, len = holeIndices.length; i < len; i++){
15442
+ var start = holeIndices[i] * 2;
15443
+ var end = i < len - 1 ? holeIndices[i + 1] * 2 : data.length;
15444
+ var list = PolygonUtils._linkedList(data, start, end, false);
15445
+ if (list === list.next) {
15446
+ list.steiner = true;
15447
+ }
15448
+ queue.push(PolygonUtils._getLeftmost(list));
15449
+ }
15450
+ queue.sort(PolygonUtils._compareXYSlope);
15451
+ for(var i1 = 0; i1 < queue.length; i1++){
15452
+ outerNode = PolygonUtils._eliminateHole(queue[i1], outerNode);
15453
+ }
15454
+ return outerNode;
15455
+ };
15456
+ PolygonUtils._compareXYSlope = function _compareXYSlope(a, b) {
15457
+ var result = a.x - b.x;
15458
+ // Touching holes must be bridged in counterclockwise order at their shared vertex
15459
+ if (result === 0) {
15460
+ result = a.y - b.y;
15461
+ if (result === 0) {
15462
+ var aSlope = (a.next.y - a.y) / (a.next.x - a.x);
15463
+ var bSlope = (b.next.y - b.y) / (b.next.x - b.x);
15464
+ result = aSlope - bSlope;
15465
+ }
15466
+ }
15467
+ return result;
15468
+ };
15469
+ PolygonUtils._eliminateHole = function _eliminateHole(hole, outerNode) {
15470
+ var bridge = PolygonUtils._findHoleBridge(hole, outerNode);
15471
+ if (!bridge) {
15472
+ return outerNode;
15473
+ }
15474
+ var bridgeReverse = PolygonUtils._splitPolygon(bridge, hole);
15475
+ // Joining rings can introduce collinear vertices on either side of the bridge
15476
+ PolygonUtils._filterPoints(bridgeReverse, bridgeReverse.next);
15477
+ return PolygonUtils._filterPoints(bridge, bridge.next);
15478
+ };
15479
+ PolygonUtils._findHoleBridge = function _findHoleBridge(hole, outerNode) {
15480
+ var p = outerNode;
15481
+ var hx = hole.x;
15482
+ var hy = hole.y;
15483
+ var qx = -Infinity;
15484
+ var m = null;
15485
+ // Cast left from the hole and choose a visible endpoint on the nearest intersected edge
15486
+ if (PolygonUtils._equals(hole, p)) {
15487
+ return p;
15488
+ }
15489
+ do {
15490
+ if (PolygonUtils._equals(hole, p.next)) {
15491
+ return p.next;
15492
+ } else if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
15493
+ var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
15494
+ if (x <= hx && x > qx) {
15495
+ qx = x;
15496
+ m = p.x < p.next.x ? p : p.next;
15497
+ if (x === hx) {
15498
+ return m;
15499
+ }
15500
+ }
15501
+ }
15502
+ p = p.next;
15503
+ }while (p !== outerNode);
15504
+ if (!m) {
15505
+ return null;
15506
+ }
15507
+ // A vertex inside the candidate triangle may provide a closer visible bridge
15508
+ var stop = m;
15509
+ var mx = m.x;
15510
+ var my = m.y;
15511
+ var tanMin = Infinity;
15512
+ p = m;
15513
+ do {
15514
+ if (hx >= p.x && p.x >= mx && hx !== p.x && PolygonUtils._pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
15515
+ var tan = Math.abs(hy - p.y) / (hx - p.x);
15516
+ if (PolygonUtils._locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && PolygonUtils._sectorContainsSector(m, p)))) {
15517
+ m = p;
15518
+ tanMin = tan;
15519
+ }
15520
+ }
15521
+ p = p.next;
15522
+ }while (p !== stop);
15523
+ return m;
15524
+ };
15525
+ PolygonUtils._sectorContainsSector = function _sectorContainsSector(m, p) {
15526
+ return PolygonUtils._area(m.prev, m, p.prev) < 0 && PolygonUtils._area(p.next, m, m.next) < 0;
15527
+ };
15528
+ PolygonUtils._indexCurve = function _indexCurve(start, minX, minY, invSize) {
15529
+ var p = start;
15530
+ do {
15531
+ if (p.z === 0) {
15532
+ p.z = PolygonUtils._zOrder(p.x, p.y, minX, minY, invSize);
15533
+ }
15534
+ p.prevZ = p.prev;
15535
+ p.nextZ = p.next;
15536
+ p = p.next;
15537
+ }while (p !== start);
15538
+ p.prevZ.nextZ = null;
15539
+ p.prevZ = null;
15540
+ PolygonUtils._sortLinked(p);
15541
+ };
15542
+ PolygonUtils._sortLinked = function _sortLinked(list) {
15543
+ // Bottom-up merge sort keeps the Morton-code list linked without allocating an array
15544
+ var numMerges;
15545
+ var inSize = 1;
15546
+ do {
15547
+ var p = list;
15548
+ var e = void 0;
15549
+ list = null;
15550
+ var tail = null;
15551
+ numMerges = 0;
15552
+ while(p){
15553
+ numMerges++;
15554
+ var q = p;
15555
+ var pSize = 0;
15556
+ for(var i = 0; i < inSize; i++){
15557
+ pSize++;
15558
+ q = q.nextZ;
15559
+ if (!q) {
15560
+ break;
15561
+ }
15562
+ }
15563
+ var qSize = inSize;
15564
+ while(pSize > 0 || qSize > 0 && q){
15565
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
15566
+ e = p;
15567
+ p = p.nextZ;
15568
+ pSize--;
15569
+ } else {
15570
+ e = q;
15571
+ q = q.nextZ;
15572
+ qSize--;
15573
+ }
15574
+ if (tail) {
15575
+ tail.nextZ = e;
15576
+ } else {
15577
+ list = e;
15578
+ }
15579
+ e.prevZ = tail;
15580
+ tail = e;
15581
+ }
15582
+ p = q;
15583
+ }
15584
+ tail.nextZ = null;
15585
+ inSize *= 2;
15586
+ }while (numMerges > 1);
15587
+ return list;
15588
+ };
15589
+ PolygonUtils._zOrder = function _zOrder(x, y, minX, minY, invSize) {
15590
+ x = (x - minX) * invSize | 0;
15591
+ y = (y - minY) * invSize | 0;
15592
+ x = (x | x << 8) & 0x00ff00ff;
15593
+ x = (x | x << 4) & 0x0f0f0f0f;
15594
+ x = (x | x << 2) & 0x33333333;
15595
+ x = (x | x << 1) & 0x55555555;
15596
+ y = (y | y << 8) & 0x00ff00ff;
15597
+ y = (y | y << 4) & 0x0f0f0f0f;
15598
+ y = (y | y << 2) & 0x33333333;
15599
+ y = (y | y << 1) & 0x55555555;
15600
+ return x | y << 1;
15601
+ };
15602
+ PolygonUtils._getLeftmost = function _getLeftmost(start) {
15603
+ var p = start, leftmost = start;
15604
+ do {
15605
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) {
15606
+ leftmost = p;
15607
+ }
15608
+ p = p.next;
15609
+ }while (p !== start);
15610
+ return leftmost;
15611
+ };
15612
+ PolygonUtils._pointInTriangle = function _pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
15613
+ return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
15614
+ };
15615
+ PolygonUtils._pointInTriangleExceptFirst = function _pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, px, py) {
15616
+ return !(ax === px && ay === py) && PolygonUtils._pointInTriangle(ax, ay, bx, by, cx, cy, px, py);
15617
+ };
15618
+ PolygonUtils._isValidDiagonal = function _isValidDiagonal(a, b) {
15619
+ return !!(a.next.i !== b.i && a.prev.i !== b.i && !PolygonUtils._intersectsPolygon(a, b) && (PolygonUtils._locallyInside(a, b) && PolygonUtils._locallyInside(b, a) && PolygonUtils._middleInside(a, b) && (PolygonUtils._area(a.prev, a, b.prev) || PolygonUtils._area(a, b.prev, b)) || PolygonUtils._equals(a, b) && PolygonUtils._area(a.prev, a, a.next) > 0 && PolygonUtils._area(b.prev, b, b.next) > 0));
15620
+ };
15621
+ PolygonUtils._area = function _area(p, q, r) {
15622
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
15623
+ };
15624
+ PolygonUtils._equals = function _equals(p1, p2) {
15625
+ return p1.x === p2.x && p1.y === p2.y;
15626
+ };
15627
+ PolygonUtils._intersects = function _intersects(p1, q1, p2, q2) {
15628
+ var o1 = PolygonUtils._sign(PolygonUtils._area(p1, q1, p2));
15629
+ var o2 = PolygonUtils._sign(PolygonUtils._area(p1, q1, q2));
15630
+ var o3 = PolygonUtils._sign(PolygonUtils._area(p2, q2, p1));
15631
+ var o4 = PolygonUtils._sign(PolygonUtils._area(p2, q2, q1));
15632
+ if (o1 !== o2 && o3 !== o4) {
15633
+ return true;
15634
+ }
15635
+ if (o1 === 0 && PolygonUtils._onSegment(p1, p2, q1)) {
15636
+ return true;
15637
+ }
15638
+ if (o2 === 0 && PolygonUtils._onSegment(p1, q2, q1)) {
15639
+ return true;
15640
+ }
15641
+ if (o3 === 0 && PolygonUtils._onSegment(p2, p1, q2)) {
15642
+ return true;
15643
+ }
15644
+ if (o4 === 0 && PolygonUtils._onSegment(p2, q1, q2)) {
15645
+ return true;
15646
+ }
15647
+ return false;
15648
+ };
15649
+ PolygonUtils._onSegment = function _onSegment(p, q, r) {
15650
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
15651
+ };
15652
+ PolygonUtils._sign = function _sign(num) {
15653
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
15654
+ };
15655
+ PolygonUtils._intersectsPolygon = function _intersectsPolygon(a, b) {
15656
+ var p = a;
15657
+ do {
15658
+ if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && PolygonUtils._intersects(p, p.next, a, b)) {
15659
+ return true;
15660
+ }
15661
+ p = p.next;
15662
+ }while (p !== a);
15663
+ return false;
15664
+ };
15665
+ PolygonUtils._locallyInside = function _locallyInside(a, b) {
15666
+ return PolygonUtils._area(a.prev, a, a.next) < 0 ? PolygonUtils._area(a, b, a.next) >= 0 && PolygonUtils._area(a, a.prev, b) >= 0 : PolygonUtils._area(a, b, a.prev) < 0 || PolygonUtils._area(a, a.next, b) < 0;
15667
+ };
15668
+ PolygonUtils._middleInside = function _middleInside(a, b) {
15669
+ var p = a;
15670
+ var inside = false;
15671
+ var px = (a.x + b.x) / 2;
15672
+ var py = (a.y + b.y) / 2;
15673
+ do {
15674
+ if (p.y > py !== p.next.y > py && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x) {
15675
+ inside = !inside;
15676
+ }
15677
+ p = p.next;
15678
+ }while (p !== a);
15679
+ return inside;
15680
+ };
15681
+ PolygonUtils._splitPolygon = function _splitPolygon(a, b) {
15682
+ var a2 = new TriangulationNode(a.i, a.x, a.y), b2 = new TriangulationNode(b.i, b.x, b.y), an = a.next, bp = b.prev;
15683
+ a.next = b;
15684
+ b.prev = a;
15685
+ a2.next = an;
15686
+ an.prev = a2;
15687
+ b2.next = a2;
15688
+ a2.prev = b2;
15689
+ bp.next = b2;
15690
+ b2.prev = bp;
15691
+ return b2;
15692
+ };
15693
+ PolygonUtils._insertNode = function _insertNode(i, x, y, last) {
15694
+ var p = new TriangulationNode(i, x, y);
15695
+ if (last) {
15696
+ p.next = last.next;
15697
+ p.prev = last;
15698
+ last.next.prev = p;
15699
+ last.next = p;
15700
+ }
15701
+ return p;
15702
+ };
15703
+ PolygonUtils._removeNode = function _removeNode(p) {
15704
+ p.next.prev = p.prev;
15705
+ p.prev.next = p.next;
15706
+ if (p.prevZ) {
15707
+ p.prevZ.nextZ = p.nextZ;
15708
+ }
15709
+ if (p.nextZ) {
15710
+ p.nextZ.prevZ = p.prevZ;
15711
+ }
15712
+ };
15713
+ PolygonUtils._signedArea = function _signedArea(data, start, end) {
15714
+ var sum = 0;
15715
+ for(var i = start, j = end - 2; i < end; i += 2){
15716
+ sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
15717
+ j = i;
15718
+ }
15719
+ return sum;
15720
+ };
15721
+ return PolygonUtils;
15722
+ }();
15723
+ var TriangulationNode = function TriangulationNode(i, x, y) {
15724
+ this.prev = this;
15725
+ this.next = this;
15726
+ this.z = 0;
15727
+ this.prevZ = null;
15728
+ this.nextZ = null;
15729
+ this.steiner = false;
15730
+ this.i = i;
15731
+ this.x = x;
15732
+ this.y = y;
15733
+ };
15734
+
14935
15735
  /**
14936
15736
  * @internal
14937
- */ var CapsuleRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
14938
- _inherits(CapsuleRestoreInfo, PrimitiveRestoreInfo);
14939
- function CapsuleRestoreInfo(radius, height, radialSegments, heightSegments, vertexBuffer, noLongerAccessible) {
14940
- var _this;
14941
- _this = PrimitiveRestoreInfo.call(this, 6, vertexBuffer, noLongerAccessible) || this, _this.radius = radius, _this.height = height, _this.radialSegments = radialSegments, _this.heightSegments = heightSegments;
14942
- return _this;
14943
- }
14944
- return CapsuleRestoreInfo;
14945
- }(PrimitiveRestoreInfo);
15737
+ */ var SubdivisionUtils = /*#__PURE__*/ function() {
15738
+ function SubdivisionUtils() {}
15739
+ SubdivisionUtils.subdivideQuads = function subdivideQuads(positions, quads, iterations) {
15740
+ var vertexCount = positions.length / 3;
15741
+ var faceCount = quads.length / 4;
15742
+ var growth = Math.pow(4, iterations);
15743
+ // Each pass adds one face point and two shared edge points per quad on a closed surface
15744
+ var resultPositions = new Float32Array((vertexCount + faceCount * (growth - 1)) * 3);
15745
+ var resultQuads = new Uint32Array(quads.length * growth);
15746
+ resultPositions.set(positions);
15747
+ resultQuads.set(quads);
15748
+ var maxFaceCount = iterations > 0 ? faceCount * growth / 4 : 0;
15749
+ var facePoints = new Float64Array(maxFaceCount * 3);
15750
+ var faceEdges = new Uint32Array(maxFaceCount * 4);
15751
+ var edgePoints = new Float64Array(maxFaceCount * 6);
15752
+ var edgeIndices = new Uint32Array(maxFaceCount * 2);
15753
+ var edges = new Map();
15754
+ var edgeOrder = [
15755
+ 0,
15756
+ 3,
15757
+ 1,
15758
+ 2
15759
+ ];
15760
+ for(var iteration = 0; iteration < iterations; iteration++){
15761
+ edges.clear();
15762
+ var edgeCount = 0;
15763
+ for(var faceIndex = 0; faceIndex < faceCount; faceIndex++){
15764
+ var faceOffset = faceIndex * 4;
15765
+ var pointOffset = faceIndex * 3;
15766
+ var x = 0;
15767
+ var y = 0;
15768
+ var z = 0;
15769
+ for(var corner = 0; corner < 4; corner++){
15770
+ var offset = 3 * resultQuads[faceOffset + corner];
15771
+ x += 0.25 * resultPositions[offset];
15772
+ y += 0.25 * resultPositions[offset + 1];
15773
+ z += 0.25 * resultPositions[offset + 2];
15774
+ }
15775
+ facePoints[pointOffset] = x;
15776
+ facePoints[pointOffset + 1] = y;
15777
+ facePoints[pointOffset + 2] = z;
15778
+ for(var corner1 = 0; corner1 < 4; corner1++){
15779
+ var a = resultQuads[faceOffset + corner1];
15780
+ var b = resultQuads[faceOffset + (corner1 + 1) % 4];
15781
+ var key = Math.min(a, b) * vertexCount + Math.max(a, b);
15782
+ var edge = edges.get(key);
15783
+ if (edge === undefined) {
15784
+ edge = edgeCount++;
15785
+ edges.set(key, edge);
15786
+ edgeIndices[edge] = 0;
15787
+ edgePoints[edge * 3] = 0.25 * (resultPositions[3 * a] + resultPositions[3 * b]);
15788
+ edgePoints[edge * 3 + 1] = 0.25 * (resultPositions[3 * a + 1] + resultPositions[3 * b + 1]);
15789
+ edgePoints[edge * 3 + 2] = 0.25 * (resultPositions[3 * a + 2] + resultPositions[3 * b + 2]);
15790
+ }
15791
+ faceEdges[faceOffset + corner1] = edge;
15792
+ edgePoints[edge * 3] += 0.25 * x;
15793
+ edgePoints[edge * 3 + 1] += 0.25 * y;
15794
+ edgePoints[edge * 3 + 2] += 0.25 * z;
15795
+ }
15796
+ }
15797
+ var nextVertexIndex = vertexCount + faceCount;
15798
+ for(var faceIndex1 = 0; faceIndex1 < faceCount; faceIndex1++){
15799
+ var facePointIndex = vertexCount + faceIndex1;
15800
+ resultPositions[3 * facePointIndex] = facePoints[3 * faceIndex1];
15801
+ resultPositions[3 * facePointIndex + 1] = facePoints[3 * faceIndex1 + 1];
15802
+ resultPositions[3 * facePointIndex + 2] = facePoints[3 * faceIndex1 + 2];
15803
+ for(var corner2 = 0; corner2 < 4; corner2++){
15804
+ var edge1 = faceEdges[faceIndex1 * 4 + edgeOrder[corner2]];
15805
+ if (edgeIndices[edge1] === 0) {
15806
+ var index = nextVertexIndex++;
15807
+ edgeIndices[edge1] = index;
15808
+ resultPositions[3 * index] = edgePoints[3 * edge1];
15809
+ resultPositions[3 * index + 1] = edgePoints[3 * edge1 + 1];
15810
+ resultPositions[3 * index + 2] = edgePoints[3 * edge1 + 2];
15811
+ }
15812
+ }
15813
+ }
15814
+ // Expand backward so the output cannot overwrite an unread input quad
15815
+ for(var faceIndex2 = faceCount - 1; faceIndex2 >= 0; faceIndex2--){
15816
+ for(var corner3 = 3; corner3 >= 0; corner3--){
15817
+ var offset1 = 4 * (4 * faceIndex2 + corner3);
15818
+ resultQuads[offset1] = resultQuads[4 * faceIndex2 + corner3];
15819
+ resultQuads[offset1 + 1] = edgeIndices[faceEdges[4 * faceIndex2 + corner3]];
15820
+ resultQuads[offset1 + 2] = vertexCount + faceIndex2;
15821
+ resultQuads[offset1 + 3] = edgeIndices[faceEdges[4 * faceIndex2 + (corner3 + 3) % 4]];
15822
+ }
15823
+ }
15824
+ vertexCount = nextVertexIndex;
15825
+ faceCount *= 4;
15826
+ }
15827
+ return {
15828
+ positions: resultPositions,
15829
+ quads: resultQuads
15830
+ };
15831
+ };
15832
+ return SubdivisionUtils;
15833
+ }();
14946
15834
 
14947
15835
  /**
14948
- * Used to generate common primitive meshes.
15836
+ * Creates primitive meshes in local space. Angle ranges use degrees.
15837
+ * Meshes have one sub-mesh unless material grouping is enabled.
15838
+ * @remarks
15839
+ * Input arrays and vectors are copied. Changing them later does not update the mesh.
15840
+ * Device restoration uses the original creation inputs; later mesh edits are not backed up.
14949
15841
  */ var PrimitiveMesh = /*#__PURE__*/ function() {
14950
15842
  function PrimitiveMesh() {}
14951
15843
  /**
14952
- * Create a sphere mesh.
14953
- * @param engine - Engine
14954
- * @param radius - Sphere radius
14955
- * @param segments - Number of segments
14956
- * @param noLongerAccessible - No longer access the vertices of the mesh after creation
14957
- * @returns Sphere model mesh
14958
- */ PrimitiveMesh.createSphere = function createSphere(engine, radius, segments, noLongerAccessible) {
14959
- if (radius === void 0) radius = 0.5;
14960
- if (segments === void 0) segments = 18;
14961
- if (noLongerAccessible === void 0) noLongerAccessible = true;
14962
- var sphereMesh = new ModelMesh(engine);
14963
- PrimitiveMesh._setSphereData(sphereMesh, radius, segments, noLongerAccessible, false);
14964
- var vertexBuffer = sphereMesh.vertexBufferBindings[0].buffer;
14965
- engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(sphereMesh, new SphereRestoreInfo(radius, segments, vertexBuffer, noLongerAccessible)));
14966
- return sphereMesh;
14967
- };
14968
- /**
14969
- * Create a sphere mesh by implementing Catmull-Clark Surface Subdivision Algorithm.
14970
- * Max step is limited to 6.
14971
- * @param engine - Engine
14972
- * @param radius - Sphere radius
14973
- * @param step - Number of subdiv steps
14974
- * @param noLongerAccessible - No longer access the vertices of the mesh after creation
14975
- * @returns Sphere model mesh
14976
- */ PrimitiveMesh.createSubdivisionSurfaceSphere = function createSubdivisionSurfaceSphere(engine, radius, step, noLongerAccessible) {
14977
- if (radius === void 0) radius = 0.5;
14978
- if (step === void 0) step = 3;
14979
- if (noLongerAccessible === void 0) noLongerAccessible = true;
14980
- var sphereMesh = new ModelMesh(engine);
14981
- PrimitiveMesh._setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, false);
14982
- var vertexBuffer = sphereMesh.vertexBufferBindings[0].buffer;
14983
- engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(sphereMesh, new SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible)));
14984
- return sphereMesh;
14985
- };
14986
- /**
14987
- * Create a cuboid mesh.
14988
- * @param engine - Engine
14989
- * @param width - Cuboid width
14990
- * @param height - Cuboid height
14991
- * @param depth - Cuboid depth
14992
- * @param noLongerAccessible - No longer access the vertices of the mesh after creation
14993
- * @returns Cuboid model mesh
14994
- */ PrimitiveMesh.createCuboid = function createCuboid(engine, width, height, depth, noLongerAccessible) {
14995
- if (width === void 0) width = 1;
14996
- if (height === void 0) height = 1;
14997
- if (depth === void 0) depth = 1;
14998
- if (noLongerAccessible === void 0) noLongerAccessible = true;
14999
- var mesh = new ModelMesh(engine);
15000
- PrimitiveMesh._setCuboidData(mesh, width, height, depth, noLongerAccessible, false);
15001
- var vertexBuffer = mesh.vertexBufferBindings[0].buffer;
15002
- engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, new CuboidRestoreInfo(width, height, depth, vertexBuffer, noLongerAccessible)));
15003
- return mesh;
15844
+ * Create a sphere or an open spherical section from a subdivided cube.
15845
+ * U follows the horizontal angle interval and V follows the vertical angle interval, each scaled to 0–1.
15846
+ * The horizontal start marks the U seam; V increases from the upper to the lower boundary.
15847
+ * @param engine - The engine that owns the mesh
15848
+ * @param radius - The radius in local units
15849
+ * @param options - Optional mesh generation settings
15850
+ * @returns The generated mesh
15851
+ */ PrimitiveMesh.createSphere = function createSphere(engine, radius, options) {
15852
+ var _options_subdivisionLevel;
15853
+ var subdivisionLevel = (_options_subdivisionLevel = options == null ? void 0 : options.subdivisionLevel) != null ? _options_subdivisionLevel : 3;
15854
+ var horizontalAngleRange = options == null ? void 0 : options.horizontalAngleRange;
15855
+ var verticalAngleRange = options == null ? void 0 : options.verticalAngleRange;
15856
+ var _horizontalAngleRange_x, _horizontalAngleRange_y, _verticalAngleRange_x, _verticalAngleRange_y;
15857
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createSphereData, [
15858
+ radius,
15859
+ subdivisionLevel,
15860
+ (_horizontalAngleRange_x = horizontalAngleRange == null ? void 0 : horizontalAngleRange.x) != null ? _horizontalAngleRange_x : 0,
15861
+ (_horizontalAngleRange_y = horizontalAngleRange == null ? void 0 : horizontalAngleRange.y) != null ? _horizontalAngleRange_y : 360,
15862
+ (_verticalAngleRange_x = verticalAngleRange == null ? void 0 : verticalAngleRange.x) != null ? _verticalAngleRange_x : 0,
15863
+ (_verticalAngleRange_y = verticalAngleRange == null ? void 0 : verticalAngleRange.y) != null ? _verticalAngleRange_y : 180
15864
+ ], options);
15865
+ };
15866
+ /**
15867
+ * Create an axis-aligned cuboid centered at the origin.
15868
+ * @remarks
15869
+ * Each face spans 0–1 in U/V. Face directions (+U, +V) are:
15870
+ * +Y: (+X, +Z); -Y: (+X, -Z); -X: (+Z, -Y);
15871
+ * +X: (-Z, -Y); +Z: (+X, -Y); -Z: (-X, -Y).
15872
+ * @param engine - The engine that owns the mesh
15873
+ * @param width - The full size along X in local units
15874
+ * @param height - The full size along Y in local units
15875
+ * @param depth - The full size along Z in local units
15876
+ * @param options - Optional mesh generation settings
15877
+ * @returns The generated mesh
15878
+ */ PrimitiveMesh.createCuboid = function createCuboid(engine, width, height, depth, options) {
15879
+ var _options_widthSegments;
15880
+ var widthSegments = (_options_widthSegments = options == null ? void 0 : options.widthSegments) != null ? _options_widthSegments : 1;
15881
+ var _options_heightSegments;
15882
+ var heightSegments = (_options_heightSegments = options == null ? void 0 : options.heightSegments) != null ? _options_heightSegments : widthSegments;
15883
+ var _options_depthSegments;
15884
+ var depthSegments = (_options_depthSegments = options == null ? void 0 : options.depthSegments) != null ? _options_depthSegments : widthSegments;
15885
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createCuboidData, [
15886
+ width,
15887
+ height,
15888
+ depth,
15889
+ widthSegments,
15890
+ heightSegments,
15891
+ depthSegments
15892
+ ], options);
15893
+ };
15894
+ /**
15895
+ * Create a plane in XZ facing +Y, centered at the origin.
15896
+ * UVs span 0–1, with U along +X and V along +Z.
15897
+ * @param engine - The engine that owns the mesh
15898
+ * @param width - The full size along X in local units
15899
+ * @param depth - The full size along Z in local units
15900
+ * @param options - Optional mesh generation settings
15901
+ * @returns The generated mesh
15902
+ */ PrimitiveMesh.createPlane = function createPlane(engine, width, depth, options) {
15903
+ var _options_widthSegments;
15904
+ var widthSegments = (_options_widthSegments = options == null ? void 0 : options.widthSegments) != null ? _options_widthSegments : 1;
15905
+ var _options_depthSegments;
15906
+ var depthSegments = (_options_depthSegments = options == null ? void 0 : options.depthSegments) != null ? _options_depthSegments : widthSegments;
15907
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createPlaneData, [
15908
+ width,
15909
+ depth,
15910
+ widthSegments,
15911
+ depthSegments
15912
+ ], options);
15913
+ };
15914
+ /**
15915
+ * Create a cylinder centered on Y with equal end radii.
15916
+ * U spans the angular range from 0 to 1; V runs from 0 at the top to 1 at the bottom.
15917
+ * The default side seam is at -Z. Both caps use planar UVs with U along +X and V along -Z.
15918
+ * @param engine - The engine that owns the mesh
15919
+ * @param radius - The radius in local units
15920
+ * @param height - The full size along Y in local units
15921
+ * @param options - Optional mesh generation settings
15922
+ * @returns The generated mesh
15923
+ */ PrimitiveMesh.createCylinder = function createCylinder(engine, radius, height, options) {
15924
+ var _options_radialSegments;
15925
+ var radialSegments = (_options_radialSegments = options == null ? void 0 : options.radialSegments) != null ? _options_radialSegments : 20;
15926
+ var _options_heightSegments;
15927
+ var heightSegments = (_options_heightSegments = options == null ? void 0 : options.heightSegments) != null ? _options_heightSegments : 1;
15928
+ var _options_caps;
15929
+ var caps = (_options_caps = options == null ? void 0 : options.caps) != null ? _options_caps : PrimitiveMeshCapMode.Both;
15930
+ var angleRange = options == null ? void 0 : options.angleRange;
15931
+ var _angleRange_x;
15932
+ var startAngle = (_angleRange_x = angleRange == null ? void 0 : angleRange.x) != null ? _angleRange_x : 0;
15933
+ var _angleRange_y, _options_separateMaterialSlots;
15934
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createCylinderData, [
15935
+ radius,
15936
+ radius,
15937
+ height,
15938
+ radialSegments,
15939
+ heightSegments,
15940
+ caps === PrimitiveMeshCapMode.Both || caps === PrimitiveMeshCapMode.Top,
15941
+ caps === PrimitiveMeshCapMode.Both || caps === PrimitiveMeshCapMode.Bottom,
15942
+ startAngle,
15943
+ ((_angleRange_y = angleRange == null ? void 0 : angleRange.y) != null ? _angleRange_y : 360) - startAngle,
15944
+ (_options_separateMaterialSlots = options == null ? void 0 : options.separateMaterialSlots) != null ? _options_separateMaterialSlots : false
15945
+ ], options);
15946
+ };
15947
+ /**
15948
+ * Create a truncated cone centered on Y with independently sized ends.
15949
+ * U spans the angular range from 0 to 1; V runs from 0 at the top to 1 at the bottom.
15950
+ * The default side seam is at -Z. Both caps use planar UVs with U along +X and V along -Z.
15951
+ * @param engine - The engine that owns the mesh
15952
+ * @param topRadius - The top radius in local units
15953
+ * @param bottomRadius - The bottom radius in local units
15954
+ * @param height - The full size along Y in local units
15955
+ * @param options - Optional mesh generation settings
15956
+ * @returns The generated mesh
15957
+ */ PrimitiveMesh.createTruncatedCone = function createTruncatedCone(engine, topRadius, bottomRadius, height, options) {
15958
+ var _options_radialSegments;
15959
+ var radialSegments = (_options_radialSegments = options == null ? void 0 : options.radialSegments) != null ? _options_radialSegments : 20;
15960
+ var _options_heightSegments;
15961
+ var heightSegments = (_options_heightSegments = options == null ? void 0 : options.heightSegments) != null ? _options_heightSegments : 1;
15962
+ var _options_caps;
15963
+ var caps = (_options_caps = options == null ? void 0 : options.caps) != null ? _options_caps : PrimitiveMeshCapMode.Both;
15964
+ var angleRange = options == null ? void 0 : options.angleRange;
15965
+ var _angleRange_x;
15966
+ var startAngle = (_angleRange_x = angleRange == null ? void 0 : angleRange.x) != null ? _angleRange_x : 0;
15967
+ var _angleRange_y, _options_separateMaterialSlots;
15968
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createCylinderData, [
15969
+ topRadius,
15970
+ bottomRadius,
15971
+ height,
15972
+ radialSegments,
15973
+ heightSegments,
15974
+ caps === PrimitiveMeshCapMode.Both || caps === PrimitiveMeshCapMode.Top,
15975
+ caps === PrimitiveMeshCapMode.Both || caps === PrimitiveMeshCapMode.Bottom,
15976
+ startAngle,
15977
+ ((_angleRange_y = angleRange == null ? void 0 : angleRange.y) != null ? _angleRange_y : 360) - startAngle,
15978
+ (_options_separateMaterialSlots = options == null ? void 0 : options.separateMaterialSlots) != null ? _options_separateMaterialSlots : false
15979
+ ], options);
15980
+ };
15981
+ /**
15982
+ * Create a cone centered on Y with its tip at the top.
15983
+ * U spans the angular range from 0 to 1; V runs from 0 at the tip to 1 at the base.
15984
+ * The default side seam is at -Z. The base uses planar UVs with U along +X and V along -Z.
15985
+ * @param engine - The engine that owns the mesh
15986
+ * @param radius - The bottom radius in local units
15987
+ * @param height - The full size along Y in local units
15988
+ * @param options - Optional mesh generation settings
15989
+ * @returns The generated mesh
15990
+ */ PrimitiveMesh.createCone = function createCone(engine, radius, height, options) {
15991
+ var _options_radialSegments;
15992
+ var radialSegments = (_options_radialSegments = options == null ? void 0 : options.radialSegments) != null ? _options_radialSegments : 20;
15993
+ var _options_heightSegments;
15994
+ var heightSegments = (_options_heightSegments = options == null ? void 0 : options.heightSegments) != null ? _options_heightSegments : 1;
15995
+ var _options_cap;
15996
+ var cap = (_options_cap = options == null ? void 0 : options.cap) != null ? _options_cap : true;
15997
+ var angleRange = options == null ? void 0 : options.angleRange;
15998
+ var _angleRange_x;
15999
+ var startAngle = (_angleRange_x = angleRange == null ? void 0 : angleRange.x) != null ? _angleRange_x : 0;
16000
+ var _angleRange_y;
16001
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createCylinderData, [
16002
+ 0,
16003
+ radius,
16004
+ height,
16005
+ radialSegments,
16006
+ heightSegments,
16007
+ false,
16008
+ cap,
16009
+ startAngle,
16010
+ ((_angleRange_y = angleRange == null ? void 0 : angleRange.y) != null ? _angleRange_y : 360) - startAngle
16011
+ ], options);
16012
+ };
16013
+ /**
16014
+ * Create a capsule centered on Y.
16015
+ * U runs around Y from -Z towards -X. V runs from 0 at the top to 1 at the bottom,
16016
+ * proportional to surface length along the hemispheres and cylinder.
16017
+ * @param engine - The engine that owns the mesh
16018
+ * @param radius - The radius of the cylinder and hemispherical ends in local units
16019
+ * @param cylinderHeight - The straight cylindrical section height in local units; total height is `cylinderHeight + 2 * radius`
16020
+ * @param options - Optional mesh generation settings
16021
+ * @returns The generated mesh
16022
+ */ PrimitiveMesh.createCapsule = function createCapsule(engine, radius, cylinderHeight, options) {
16023
+ var _options_radialSegments;
16024
+ var radialSegments = (_options_radialSegments = options == null ? void 0 : options.radialSegments) != null ? _options_radialSegments : 6;
16025
+ var _options_capSegments;
16026
+ var capSegments = (_options_capSegments = options == null ? void 0 : options.capSegments) != null ? _options_capSegments : radialSegments;
16027
+ var _options_heightSegments;
16028
+ var heightSegments = (_options_heightSegments = options == null ? void 0 : options.heightSegments) != null ? _options_heightSegments : 1;
16029
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createCapsuleData, [
16030
+ radius,
16031
+ cylinderHeight,
16032
+ radialSegments,
16033
+ capSegments,
16034
+ heightSegments
16035
+ ], options);
16036
+ };
16037
+ /**
16038
+ * Create a torus centered in XY around Z.
16039
+ * U spans the ring angle interval and V spans the tube angle interval, each scaled to 0–1.
16040
+ * @param engine - The engine that owns the mesh
16041
+ * @param radius - The distance from the origin to the tube centerline in local units
16042
+ * @param tubeRadius - The radius of the tube cross-section in local units
16043
+ * @param options - Optional mesh generation settings
16044
+ * @returns The generated mesh
16045
+ */ PrimitiveMesh.createTorus = function createTorus(engine, radius, tubeRadius, options) {
16046
+ var _options_ringSegments;
16047
+ var ringSegments = (_options_ringSegments = options == null ? void 0 : options.ringSegments) != null ? _options_ringSegments : 30;
16048
+ var _options_radialSegments;
16049
+ var radialSegments = (_options_radialSegments = options == null ? void 0 : options.radialSegments) != null ? _options_radialSegments : 30;
16050
+ var ringAngleRange = options == null ? void 0 : options.ringAngleRange;
16051
+ var tubeAngleRange = options == null ? void 0 : options.tubeAngleRange;
16052
+ var _ringAngleRange_x;
16053
+ var startAngle = (_ringAngleRange_x = ringAngleRange == null ? void 0 : ringAngleRange.x) != null ? _ringAngleRange_x : 0;
16054
+ var _tubeAngleRange_x;
16055
+ var tubeStartAngle = (_tubeAngleRange_x = tubeAngleRange == null ? void 0 : tubeAngleRange.x) != null ? _tubeAngleRange_x : 0;
16056
+ var _ringAngleRange_y, _tubeAngleRange_y;
16057
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createTorusData, [
16058
+ radius,
16059
+ tubeRadius,
16060
+ radialSegments,
16061
+ ringSegments,
16062
+ ((_ringAngleRange_y = ringAngleRange == null ? void 0 : ringAngleRange.y) != null ? _ringAngleRange_y : 360) - startAngle,
16063
+ tubeStartAngle,
16064
+ ((_tubeAngleRange_y = tubeAngleRange == null ? void 0 : tubeAngleRange.y) != null ? _tubeAngleRange_y : 360) - tubeStartAngle,
16065
+ startAngle
16066
+ ], options);
16067
+ };
16068
+ /**
16069
+ * Create a filled disk or sector in XY facing +Z.
16070
+ * UVs project X/Y onto the full disk's bounding square; angular cuts do not rescale them.
16071
+ * @param engine - The engine that owns the mesh
16072
+ * @param radius - The radius in local units
16073
+ * @param options - Optional mesh generation settings
16074
+ * @returns The generated mesh
16075
+ */ PrimitiveMesh.createCircle = function createCircle(engine, radius, options) {
16076
+ var _options_segments;
16077
+ var segments = (_options_segments = options == null ? void 0 : options.segments) != null ? _options_segments : 32;
16078
+ var angleRange = options == null ? void 0 : options.angleRange;
16079
+ var _angleRange_x;
16080
+ var startAngle = (_angleRange_x = angleRange == null ? void 0 : angleRange.x) != null ? _angleRange_x : 0;
16081
+ var _angleRange_y;
16082
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createCircleData, [
16083
+ radius,
16084
+ segments,
16085
+ startAngle,
16086
+ ((_angleRange_y = angleRange == null ? void 0 : angleRange.y) != null ? _angleRange_y : 360) - startAngle
16087
+ ], options);
16088
+ };
16089
+ /**
16090
+ * Create a ring or ring sector in XY facing +Z.
16091
+ * UVs project X/Y onto the outer disk's bounding square; angular cuts do not rescale them.
16092
+ * @param engine - The engine that owns the mesh
16093
+ * @param outerRadius - The outer radius in local units
16094
+ * @param innerRadius - The inner radius in local units
16095
+ * @param options - Optional mesh generation settings
16096
+ * @returns The generated mesh
16097
+ */ PrimitiveMesh.createRing = function createRing(engine, outerRadius, innerRadius, options) {
16098
+ var _options_ringSegments;
16099
+ var ringSegments = (_options_ringSegments = options == null ? void 0 : options.ringSegments) != null ? _options_ringSegments : 32;
16100
+ var _options_widthSegments;
16101
+ var widthSegments = (_options_widthSegments = options == null ? void 0 : options.widthSegments) != null ? _options_widthSegments : 1;
16102
+ var angleRange = options == null ? void 0 : options.angleRange;
16103
+ var _angleRange_x;
16104
+ var startAngle = (_angleRange_x = angleRange == null ? void 0 : angleRange.x) != null ? _angleRange_x : 0;
16105
+ var _angleRange_y;
16106
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createRingData, [
16107
+ innerRadius,
16108
+ outerRadius,
16109
+ ringSegments,
16110
+ widthSegments,
16111
+ startAngle,
16112
+ ((_angleRange_y = angleRange == null ? void 0 : angleRange.y) != null ? _angleRange_y : 360) - startAngle
16113
+ ], options);
16114
+ };
16115
+ /**
16116
+ * Create a regular tetrahedron or its spherical subdivision.
16117
+ * UVs use spherical projection around Y, with the U seam at +X and V from 0 at +Y to 1 at -Y.
16118
+ * Triangles crossing the U seam may use values above 1.
16119
+ * @param engine - The engine that owns the mesh
16120
+ * @param radius - The distance from the origin to each vertex in local units
16121
+ * @param options - Optional mesh generation settings
16122
+ * @returns The generated mesh
16123
+ */ PrimitiveMesh.createTetrahedron = function createTetrahedron(engine, radius, options) {
16124
+ var _options_edgeSegments;
16125
+ var edgeSegments = (_options_edgeSegments = options == null ? void 0 : options.edgeSegments) != null ? _options_edgeSegments : 1;
16126
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createRegularPolyhedronData, [
16127
+ "tetrahedron",
16128
+ radius,
16129
+ edgeSegments
16130
+ ], options);
16131
+ };
16132
+ /**
16133
+ * Create a regular octahedron or its spherical subdivision.
16134
+ * UVs use spherical projection around Y, with the U seam at +X and V from 0 at +Y to 1 at -Y.
16135
+ * Triangles crossing the U seam may use values above 1.
16136
+ * @param engine - The engine that owns the mesh
16137
+ * @param radius - The distance from the origin to each vertex in local units
16138
+ * @param options - Optional mesh generation settings
16139
+ * @returns The generated mesh
16140
+ */ PrimitiveMesh.createOctahedron = function createOctahedron(engine, radius, options) {
16141
+ var _options_edgeSegments;
16142
+ var edgeSegments = (_options_edgeSegments = options == null ? void 0 : options.edgeSegments) != null ? _options_edgeSegments : 1;
16143
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createRegularPolyhedronData, [
16144
+ "octahedron",
16145
+ radius,
16146
+ edgeSegments
16147
+ ], options);
16148
+ };
16149
+ /**
16150
+ * Create a regular icosahedron or its spherical subdivision.
16151
+ * UVs use spherical projection around Y, with the U seam at +X and V from 0 at +Y to 1 at -Y.
16152
+ * Triangles crossing the U seam may use values above 1.
16153
+ * @param engine - The engine that owns the mesh
16154
+ * @param radius - The distance from the origin to each vertex in local units
16155
+ * @param options - Optional mesh generation settings
16156
+ * @returns The generated mesh
16157
+ */ PrimitiveMesh.createIcosahedron = function createIcosahedron(engine, radius, options) {
16158
+ var _options_edgeSegments;
16159
+ var edgeSegments = (_options_edgeSegments = options == null ? void 0 : options.edgeSegments) != null ? _options_edgeSegments : 1;
16160
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createRegularPolyhedronData, [
16161
+ "icosahedron",
16162
+ radius,
16163
+ edgeSegments
16164
+ ], options);
16165
+ };
16166
+ /**
16167
+ * Create a regular dodecahedron or its spherical subdivision.
16168
+ * UVs use spherical projection around Y, with the U seam at +X and V from 0 at +Y to 1 at -Y.
16169
+ * Triangles crossing the U seam may use values above 1.
16170
+ * @param engine - The engine that owns the mesh
16171
+ * @param radius - The distance from the origin to each vertex in local units
16172
+ * @param options - Optional mesh generation settings
16173
+ * @returns The generated mesh
16174
+ */ PrimitiveMesh.createDodecahedron = function createDodecahedron(engine, radius, options) {
16175
+ var _options_edgeSegments;
16176
+ var edgeSegments = (_options_edgeSegments = options == null ? void 0 : options.edgeSegments) != null ? _options_edgeSegments : 1;
16177
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createRegularPolyhedronData, [
16178
+ "dodecahedron",
16179
+ radius,
16180
+ edgeSegments
16181
+ ], options);
16182
+ };
16183
+ /**
16184
+ * Create a surface of revolution by rotating a radius-height profile around Y.
16185
+ * No end caps are added automatically.
16186
+ * Define inner walls and closed ends in the profile when needed.
16187
+ * U spans the revolution from 0 to 1; V advances uniformly by profile point index from 0 to 1.
16188
+ * @param engine - The engine that owns the mesh
16189
+ * @param profile - The profile points in input order, with at least two points; X is radius and Y is height. Repeat the first point to close the profile
16190
+ * @param options - Optional mesh generation settings
16191
+ * @returns The generated mesh
16192
+ */ PrimitiveMesh.createRevolvedSurface = function createRevolvedSurface(engine, profile, options) {
16193
+ var _options_segments;
16194
+ var segments = (_options_segments = options == null ? void 0 : options.segments) != null ? _options_segments : 12;
16195
+ var angleRange = options == null ? void 0 : options.angleRange;
16196
+ var _angleRange_x;
16197
+ var startAngle = (_angleRange_x = angleRange == null ? void 0 : angleRange.x) != null ? _angleRange_x : 0;
16198
+ var _angleRange_y;
16199
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createRevolvedSurfaceData, [
16200
+ profile,
16201
+ segments,
16202
+ startAngle,
16203
+ ((_angleRange_y = angleRange == null ? void 0 : angleRange.y) != null ? _angleRange_y : 360) - startAngle
16204
+ ], options);
16205
+ };
16206
+ /**
16207
+ * Sweep a circular cross-section along a path without end caps.
16208
+ * U measures normalized path distance; V runs around the generated path frame from 0 to 1.
16209
+ * @param engine - The engine that owns the mesh
16210
+ * @param path - The centerline points, resampled at equal distances along the polyline; at least two distinct points are required
16211
+ * @param radius - The radius of the cross-section in local units
16212
+ * @param options - Optional mesh generation settings
16213
+ * @returns The generated mesh
16214
+ */ PrimitiveMesh.createTube = function createTube(engine, path, radius, options) {
16215
+ var _options_pathSegments;
16216
+ var pathSegments = (_options_pathSegments = options == null ? void 0 : options.pathSegments) != null ? _options_pathSegments : 64;
16217
+ var _options_radialSegments;
16218
+ var radialSegments = (_options_radialSegments = options == null ? void 0 : options.radialSegments) != null ? _options_radialSegments : 8;
16219
+ var _options_closedPath;
16220
+ var closedPath = (_options_closedPath = options == null ? void 0 : options.closedPath) != null ? _options_closedPath : false;
16221
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createTubeData, [
16222
+ path,
16223
+ radius,
16224
+ pathSegments,
16225
+ radialSegments,
16226
+ closedPath
16227
+ ], options);
16228
+ };
16229
+ /**
16230
+ * Create a zero-thickness polygon mesh in the XY plane, facing +Z.
16231
+ * UVs use the local X/Y coordinates directly, without normalization.
16232
+ * @param engine - The engine that owns the mesh
16233
+ * @param shapes - A contour, a polygon with holes, or an array of polygons; closing points need not be repeated
16234
+ * @param options - Optional mesh generation settings
16235
+ * @returns The triangulated polygon mesh without side walls
16236
+ */ PrimitiveMesh.createPolygon = function createPolygon(engine, shapes, options) {
16237
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createPolygonData, [
16238
+ PrimitiveMesh._polygons(shapes)
16239
+ ], options);
16240
+ };
16241
+ PrimitiveMesh.createExtrudedPolygon = function createExtrudedPolygon(engine, shapes, depthOrPath, options) {
16242
+ var extrudedPolygonOptions = options;
16243
+ var _extrudedPolygonOptions_depthSegments;
16244
+ var depthSegments = (_extrudedPolygonOptions_depthSegments = extrudedPolygonOptions == null ? void 0 : extrudedPolygonOptions.depthSegments) != null ? _extrudedPolygonOptions_depthSegments : 1;
16245
+ var _extrudedPolygonOptions_pathSegments;
16246
+ var pathSegments = (_extrudedPolygonOptions_pathSegments = extrudedPolygonOptions == null ? void 0 : extrudedPolygonOptions.pathSegments) != null ? _extrudedPolygonOptions_pathSegments : 1;
16247
+ var _extrudedPolygonOptions_closedPath;
16248
+ var closedPath = (_extrudedPolygonOptions_closedPath = extrudedPolygonOptions == null ? void 0 : extrudedPolygonOptions.closedPath) != null ? _extrudedPolygonOptions_closedPath : false;
16249
+ var _extrudedPolygonOptions_bevelWidth;
16250
+ var bevelWidth = (_extrudedPolygonOptions_bevelWidth = extrudedPolygonOptions == null ? void 0 : extrudedPolygonOptions.bevelWidth) != null ? _extrudedPolygonOptions_bevelWidth : 0;
16251
+ var _extrudedPolygonOptions_bevelDepth;
16252
+ var bevelDepth = (_extrudedPolygonOptions_bevelDepth = extrudedPolygonOptions == null ? void 0 : extrudedPolygonOptions.bevelDepth) != null ? _extrudedPolygonOptions_bevelDepth : bevelWidth;
16253
+ var _extrudedPolygonOptions_contourOffset;
16254
+ var contourOffset = (_extrudedPolygonOptions_contourOffset = extrudedPolygonOptions == null ? void 0 : extrudedPolygonOptions.contourOffset) != null ? _extrudedPolygonOptions_contourOffset : 0;
16255
+ var _extrudedPolygonOptions_bevelSegments;
16256
+ var bevelSegments = (_extrudedPolygonOptions_bevelSegments = extrudedPolygonOptions == null ? void 0 : extrudedPolygonOptions.bevelSegments) != null ? _extrudedPolygonOptions_bevelSegments : 3;
16257
+ var path = typeof depthOrPath === "number" ? undefined : depthOrPath;
16258
+ var depth = typeof depthOrPath === "number" ? depthOrPath : 0;
16259
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createExtrudedPolygonData, [
16260
+ PrimitiveMesh._polygons(shapes),
16261
+ depth,
16262
+ path ? pathSegments : depthSegments,
16263
+ path,
16264
+ path ? closedPath : false,
16265
+ bevelDepth,
16266
+ bevelWidth,
16267
+ contourOffset,
16268
+ bevelSegments
16269
+ ], options);
16270
+ };
16271
+ /**
16272
+ * Create a closed torus knot. At least one of `axisTurns` and `crossSectionTurns` must be nonzero.
16273
+ * U follows the knot parameter from 0 to 1; V runs around the generated tube cross-section from 0 to 1.
16274
+ * @param engine - The engine that owns the mesh
16275
+ * @param radius - The base radius of the torus in local units
16276
+ * @param tubeRadius - The radius of the tube cross-section in local units
16277
+ * @param axisTurns - The signed integer revolution count around the torus axis; negative values reverse the winding
16278
+ * @param crossSectionTurns - The signed integer revolution count around the torus cross-section; negative values reverse the winding
16279
+ * @param options - Optional mesh generation settings
16280
+ * @returns The generated mesh
16281
+ */ PrimitiveMesh.createTorusKnot = function createTorusKnot(engine, radius, tubeRadius, axisTurns, crossSectionTurns, options) {
16282
+ var _options_pathSegments;
16283
+ var pathSegments = (_options_pathSegments = options == null ? void 0 : options.pathSegments) != null ? _options_pathSegments : 64;
16284
+ var _options_radialSegments;
16285
+ var radialSegments = (_options_radialSegments = options == null ? void 0 : options.radialSegments) != null ? _options_radialSegments : 8;
16286
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createTorusKnotData, [
16287
+ radius,
16288
+ tubeRadius,
16289
+ pathSegments,
16290
+ radialSegments,
16291
+ axisTurns,
16292
+ crossSectionTurns
16293
+ ], options);
16294
+ };
16295
+ /**
16296
+ * Create an axis-aligned cuboid with rounded edges and corners.
16297
+ * @remarks
16298
+ * UVs preserve the face orientations of {@link PrimitiveMesh.createCuboid} and account for rounded edge length.
16299
+ * @param engine - The engine that owns the mesh
16300
+ * @param width - The full size along X in local units
16301
+ * @param height - The full size along Y in local units
16302
+ * @param depth - The full size along Z in local units
16303
+ * @param cornerRadius - The edge and corner radius in local units, clamped to half the smallest dimension
16304
+ * @param options - Optional mesh generation settings
16305
+ * @returns The generated mesh
16306
+ */ PrimitiveMesh.createRoundedCuboid = function createRoundedCuboid(engine, width, height, depth, cornerRadius, options) {
16307
+ var _options_roundingSegments;
16308
+ var roundingSegments = (_options_roundingSegments = options == null ? void 0 : options.roundingSegments) != null ? _options_roundingSegments : 2;
16309
+ return PrimitiveMesh._createMesh(engine, PrimitiveMesh._createRoundedCuboidData, [
16310
+ width,
16311
+ height,
16312
+ depth,
16313
+ cornerRadius,
16314
+ roundingSegments
16315
+ ], options);
16316
+ };
16317
+ PrimitiveMesh._createPlaneData = function _createPlaneData(width, depth, widthSegments, depthSegments) {
16318
+ var columns = PrimitiveMesh._getSegmentCount(widthSegments);
16319
+ var rows = PrimitiveMesh._getSegmentCount(depthSegments);
16320
+ var data = new PrimitiveMeshBuilder((columns + 1) * (rows + 1), columns * rows * 6);
16321
+ for(var y = 0; y <= rows; y++){
16322
+ for(var x = 0; x <= columns; x++){
16323
+ data.addVertex((x / columns - 0.5) * width, 0, (y / rows - 0.5) * depth, 0, 1, 0, x / columns, y / rows);
16324
+ }
16325
+ }
16326
+ for(var y1 = 0; y1 < rows; y1++){
16327
+ for(var x1 = 0; x1 < columns; x1++){
16328
+ var a = y1 * (columns + 1) + x1;
16329
+ var c = a + columns + 1;
16330
+ data.addTriangle(a, c, a + 1);
16331
+ data.addTriangle(a + 1, c, c + 1);
16332
+ }
16333
+ }
16334
+ data.boundsExtent = new engineMath.Vector3(width / 2, 0, depth / 2);
16335
+ return data;
15004
16336
  };
15005
- /**
15006
- * Create a plane mesh with U mapped along local +X and V along local +Z.
15007
- * @param engine - Engine
15008
- * @param width - Plane width along the local X axis
15009
- * @param height - Plane height along the local Z axis
15010
- * @param horizontalSegments - Plane horizontal segments
15011
- * @param verticalSegments - Plane vertical segments
15012
- * @param noLongerAccessible - No longer access the vertices of the mesh after creation
15013
- * @returns Plane model mesh
15014
- */ PrimitiveMesh.createPlane = function createPlane(engine, width, height, horizontalSegments, verticalSegments, noLongerAccessible) {
15015
- if (width === void 0) width = 1;
15016
- if (height === void 0) height = 1;
15017
- if (horizontalSegments === void 0) horizontalSegments = 1;
15018
- if (verticalSegments === void 0) verticalSegments = 1;
15019
- if (noLongerAccessible === void 0) noLongerAccessible = true;
15020
- var mesh = new ModelMesh(engine);
15021
- PrimitiveMesh._setPlaneData(mesh, width, height, horizontalSegments, verticalSegments, noLongerAccessible, false);
15022
- var vertexBuffer = mesh.vertexBufferBindings[0].buffer;
15023
- engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, new PlaneRestoreInfo(width, height, horizontalSegments, verticalSegments, vertexBuffer, noLongerAccessible)));
15024
- return mesh;
16337
+ PrimitiveMesh._createCuboidData = function _createCuboidData(width, height, depth, widthSegments, heightSegments, depthSegments) {
16338
+ var x = width / 2;
16339
+ var y = height / 2;
16340
+ var z = depth / 2;
16341
+ var sx = PrimitiveMesh._getSegmentCount(widthSegments);
16342
+ var sy = PrimitiveMesh._getSegmentCount(heightSegments);
16343
+ var sz = PrimitiveMesh._getSegmentCount(depthSegments);
16344
+ var data = new PrimitiveMeshBuilder(2 * ((sx + 1) * (sy + 1) + (sx + 1) * (sz + 1) + (sy + 1) * (sz + 1)), 12 * (sx * sy + sx * sz + sy * sz));
16345
+ // Origins and UV directions preserve the existing cuboid texture orientation
16346
+ grid(new engineMath.Vector3(-x, y, -z), new engineMath.Vector3(2 * x, 0, 0), new engineMath.Vector3(0, 0, 2 * z), new engineMath.Vector3(0, 1, 0), sx, sz, false, false);
16347
+ grid(new engineMath.Vector3(-x, -y, -z), new engineMath.Vector3(2 * x, 0, 0), new engineMath.Vector3(0, 0, 2 * z), new engineMath.Vector3(0, -1, 0), sx, sz, false, true);
16348
+ grid(new engineMath.Vector3(-x, y, -z), new engineMath.Vector3(0, 0, 2 * z), new engineMath.Vector3(0, -2 * y, 0), new engineMath.Vector3(-1, 0, 0), sz, sy, false, false);
16349
+ grid(new engineMath.Vector3(x, y, -z), new engineMath.Vector3(0, 0, 2 * z), new engineMath.Vector3(0, -2 * y, 0), new engineMath.Vector3(1, 0, 0), sz, sy, true, false);
16350
+ grid(new engineMath.Vector3(-x, y, z), new engineMath.Vector3(2 * x, 0, 0), new engineMath.Vector3(0, -2 * y, 0), new engineMath.Vector3(0, 0, 1), sx, sy, false, false);
16351
+ grid(new engineMath.Vector3(-x, y, -z), new engineMath.Vector3(2 * x, 0, 0), new engineMath.Vector3(0, -2 * y, 0), new engineMath.Vector3(0, 0, -1), sx, sy, true, false);
16352
+ data.boundsExtent = new engineMath.Vector3(width / 2, height / 2, depth / 2);
16353
+ return data;
16354
+ function grid(origin, u, v, normal, columns, rows, flipU, flipV) {
16355
+ var base = data.vertexCount;
16356
+ var start = data.indexCount;
16357
+ var crossDot = (u.y * v.z - u.z * v.y) * normal.x + (u.z * v.x - u.x * v.z) * normal.y + (u.x * v.y - u.y * v.x) * normal.z;
16358
+ for(var row = 0; row <= rows; row++){
16359
+ for(var column = 0; column <= columns; column++){
16360
+ var a = column / columns;
16361
+ var b = row / rows;
16362
+ data.addVertex(origin.x + u.x * a + v.x * b, origin.y + u.y * a + v.y * b, origin.z + u.z * a + v.z * b, normal.x, normal.y, normal.z, flipU ? 1 - a : a, flipV ? 1 - b : b);
16363
+ }
16364
+ }
16365
+ for(var row1 = 0; row1 < rows; row1++){
16366
+ for(var column1 = 0; column1 < columns; column1++){
16367
+ var a1 = base + row1 * (columns + 1) + column1;
16368
+ var c = a1 + columns + 1;
16369
+ if (crossDot > 0) {
16370
+ data.addTriangle(a1, a1 + 1, c);
16371
+ data.addTriangle(a1 + 1, c + 1, c);
16372
+ } else {
16373
+ data.addTriangle(a1, c, a1 + 1);
16374
+ data.addTriangle(a1 + 1, c, c + 1);
16375
+ }
16376
+ }
16377
+ }
16378
+ data.addGroup(start);
16379
+ }
15025
16380
  };
15026
- /**
15027
- * Create a cylinder mesh.
15028
- * @param engine - Engine
15029
- * @param radiusTop - The radius of top cap
15030
- * @param radiusBottom - The radius of bottom cap
15031
- * @param height - The height of torso
15032
- * @param radialSegments - Cylinder radial segments
15033
- * @param heightSegments - Cylinder height segments
15034
- * @param noLongerAccessible - No longer access the vertices of the mesh after creation
15035
- * @returns Cylinder model mesh
15036
- */ PrimitiveMesh.createCylinder = function createCylinder(engine, radiusTop, radiusBottom, height, radialSegments, heightSegments, noLongerAccessible) {
15037
- if (radiusTop === void 0) radiusTop = 0.5;
15038
- if (radiusBottom === void 0) radiusBottom = 0.5;
15039
- if (height === void 0) height = 2;
15040
- if (radialSegments === void 0) radialSegments = 20;
15041
- if (heightSegments === void 0) heightSegments = 1;
15042
- if (noLongerAccessible === void 0) noLongerAccessible = true;
15043
- var mesh = new ModelMesh(engine);
15044
- PrimitiveMesh._setCylinderData(mesh, radiusTop, radiusBottom, height, radialSegments, heightSegments, noLongerAccessible, false);
15045
- var vertexBuffer = mesh.vertexBufferBindings[0].buffer;
15046
- engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, new CylinderRestoreInfo(radiusTop, radiusBottom, height, radialSegments, heightSegments, vertexBuffer, noLongerAccessible)));
15047
- return mesh;
16381
+ PrimitiveMesh._createCylinderData = function _createCylinderData(radiusTop, radiusBottom, height, radialSegments, heightSegments, includeTopCap, includeBottomCap, startAngleDegrees, arcDegrees, separateMaterialSlots) {
16382
+ if (separateMaterialSlots === void 0) separateMaterialSlots = false;
16383
+ var radial = PrimitiveMesh._getSegmentCount(radialSegments, 3);
16384
+ var vertical = PrimitiveMesh._getSegmentCount(heightSegments);
16385
+ var startAngle = Math.PI + engineMath.MathUtil.degreeToRadian(startAngleDegrees);
16386
+ var arc = engineMath.MathUtil.degreeToRadian(arcDegrees);
16387
+ var circle = PrimitiveMesh._createArcSamples(radial, startAngle, arc);
16388
+ var slope = height === 0 ? 0 : (radiusBottom - radiusTop) / height;
16389
+ var full = Math.abs(arc) === Math.PI * 2;
16390
+ var capCount = (includeTopCap && radiusTop !== 0 ? 1 : 0) + (includeBottomCap && radiusBottom !== 0 ? 1 : 0);
16391
+ var sideTriangles = 2 * vertical - (radiusTop === 0 ? 1 : 0) - (radiusBottom === 0 ? 1 : 0);
16392
+ var data = new PrimitiveMeshBuilder((radial + 1) * (vertical + 1) + capCount * (radial + (full ? 1 : 2)), radial * (sideTriangles + capCount) * 3);
16393
+ for(var y = 0; y <= vertical; y++){
16394
+ var v = y / vertical;
16395
+ var radius = radiusBottom + (radiusTop - radiusBottom) * v;
16396
+ for(var x = 0; x <= radial; x++){
16397
+ var u = x / radial;
16398
+ var cos = circle[x * 2];
16399
+ var sin = circle[x * 2 + 1];
16400
+ data.addVertex(radius * sin, (v - 0.5) * height, radius * cos, sin, slope, cos, u, 1 - v);
16401
+ }
16402
+ }
16403
+ for(var y1 = 0; y1 < vertical; y1++){
16404
+ for(var x1 = 0; x1 < radial; x1++){
16405
+ var a = y1 * (radial + 1) + x1;
16406
+ var c = a + radial + 1;
16407
+ if (radiusBottom !== 0 || y1 !== 0) {
16408
+ data.addTriangle(a + 1, c, a);
16409
+ }
16410
+ if (radiusTop !== 0 || y1 !== vertical - 1) {
16411
+ data.addTriangle(a + 1, c + 1, c);
16412
+ }
16413
+ }
16414
+ }
16415
+ data.addGroup(0);
16416
+ var capStart = data.indexCount;
16417
+ // Interleave ungrouped caps to preserve transparent blending order
16418
+ var interleaveCaps = capCount === 2 && !separateMaterialSlots;
16419
+ if (includeTopCap) {
16420
+ cap(radiusTop, 1);
16421
+ }
16422
+ if (includeBottomCap) {
16423
+ cap(radiusBottom, -1);
16424
+ }
16425
+ if (interleaveCaps) {
16426
+ data.addGroup(capStart);
16427
+ }
16428
+ data.boundsExtent = new engineMath.Vector3(Math.max(radiusTop, radiusBottom), height / 2, Math.max(radiusTop, radiusBottom));
16429
+ return data;
16430
+ function cap(radius, sign) {
16431
+ if (radius === 0) {
16432
+ return;
16433
+ }
16434
+ var start = data.indexCount;
16435
+ var center = data.addVertex(0, sign * height / 2, 0, 0, sign, 0, 0.5, 0.5);
16436
+ var rowStart = sign > 0 ? vertical * (radial + 1) : 0;
16437
+ var inverseDiameter = 1 / (2 * radius);
16438
+ // A partial cap includes both endpoints; a full cap reuses its first rim vertex
16439
+ var rimCount = full ? radial : radial + 1;
16440
+ for(var x = 0; x < rimCount; x++){
16441
+ var offset = (rowStart + x) * 8;
16442
+ var positionX = data.vertices[offset];
16443
+ var positionZ = data.vertices[offset + 2];
16444
+ data.addVertex(positionX, sign * height / 2, positionZ, 0, sign, 0, positionX * inverseDiameter + 0.5, 0.5 - positionZ * inverseDiameter);
16445
+ }
16446
+ var indexOffset = interleaveCaps ? capStart + (sign > 0 ? 3 : 0) : start;
16447
+ var indexStride = interleaveCaps ? 6 : 3;
16448
+ for(var x1 = 0; x1 < radial; x1++){
16449
+ var current = center + x1 + 1;
16450
+ var next = full && x1 === radial - 1 ? center + 1 : current + 1;
16451
+ data.indices[indexOffset] = center;
16452
+ data.indices[indexOffset + 1] = sign > 0 ? current : next;
16453
+ data.indices[indexOffset + 2] = sign > 0 ? next : current;
16454
+ indexOffset += indexStride;
16455
+ }
16456
+ data.indexCount += radial * 3;
16457
+ if (!interleaveCaps) {
16458
+ data.addGroup(start);
16459
+ }
16460
+ }
16461
+ };
16462
+ PrimitiveMesh._createCapsuleData = function _createCapsuleData(radius, cylinderHeight, radialSegments, capSegments, heightSegments) {
16463
+ var radial = PrimitiveMesh._getSegmentCount(radialSegments, 3);
16464
+ var caps = PrimitiveMesh._getSegmentCount(capSegments);
16465
+ var vertical = PrimitiveMesh._getSegmentCount(heightSegments);
16466
+ var rows = caps * 2 + vertical;
16467
+ var circle = PrimitiveMesh._createArcSamples(radial, Math.PI);
16468
+ var capLength = Math.PI * radius / 2;
16469
+ var totalLength = capLength * 2 + cylinderHeight;
16470
+ var data = new PrimitiveMeshBuilder((radial + 1) * (rows + 1), radial * (rows - 1) * 6);
16471
+ for(var y = 0; y <= rows; y++){
16472
+ var py = void 0;
16473
+ var ringRadius = void 0;
16474
+ var ny = void 0;
16475
+ var distance = void 0;
16476
+ if (y <= caps) {
16477
+ var angle = y / caps * Math.PI / 2;
16478
+ ringRadius = radius * Math.sin(angle);
16479
+ ny = -Math.cos(angle);
16480
+ py = -cylinderHeight / 2 + radius * ny;
16481
+ distance = y / caps * capLength;
16482
+ } else if (y <= caps + vertical) {
16483
+ ringRadius = radius;
16484
+ ny = 0;
16485
+ py = -cylinderHeight / 2 + (y - caps) / vertical * cylinderHeight;
16486
+ distance = capLength + (y - caps) / vertical * cylinderHeight;
16487
+ } else {
16488
+ var angle1 = (y - caps - vertical) / caps * Math.PI / 2;
16489
+ ringRadius = radius * Math.cos(angle1);
16490
+ ny = Math.sin(angle1);
16491
+ py = cylinderHeight / 2 + radius * ny;
16492
+ distance = capLength + cylinderHeight + (y - caps - vertical) / caps * capLength;
16493
+ }
16494
+ var normalRadius = Math.sqrt(Math.max(0, 1 - ny * ny));
16495
+ // Center pole UVs between the other two vertices of each triangle
16496
+ var offset = y === 0 ? -0.5 / radial : y === rows ? 0.5 / radial : 0;
16497
+ for(var x = 0; x <= radial; x++){
16498
+ var cos = circle[x * 2];
16499
+ var sin = circle[x * 2 + 1];
16500
+ data.addVertex(ringRadius * sin, py, ringRadius * cos, sin * normalRadius, ny, cos * normalRadius, x / radial + offset, totalLength > 0 ? 1 - distance / totalLength : 0);
16501
+ }
16502
+ }
16503
+ for(var y1 = 0; y1 < rows; y1++){
16504
+ for(var x1 = 0; x1 < radial; x1++){
16505
+ var a = y1 * (radial + 1) + x1;
16506
+ var c = a + radial + 1;
16507
+ if (y1 !== 0) {
16508
+ data.addTriangle(a + 1, c, a);
16509
+ }
16510
+ if (y1 !== rows - 1) {
16511
+ data.addTriangle(a + 1, c + 1, c);
16512
+ }
16513
+ }
16514
+ }
16515
+ data.boundsExtent = new engineMath.Vector3(radius, cylinderHeight / 2 + radius, radius);
16516
+ return data;
15048
16517
  };
15049
- /**
15050
- * Create a torus mesh.
15051
- * @param engine - Engine
15052
- * @param radius - Torus radius
15053
- * @param tubeRadius - Torus tube
15054
- * @param radialSegments - Torus radial segments
15055
- * @param tubularSegments - Torus tubular segments
15056
- * @param arc - Central angle
15057
- * @param noLongerAccessible - No longer access the vertices of the mesh after creation
15058
- * @returns Torus model mesh
15059
- */ PrimitiveMesh.createTorus = function createTorus(engine, radius, tubeRadius, radialSegments, tubularSegments, arc, noLongerAccessible) {
15060
- if (radius === void 0) radius = 0.5;
15061
- if (tubeRadius === void 0) tubeRadius = 0.1;
15062
- if (radialSegments === void 0) radialSegments = 30;
15063
- if (tubularSegments === void 0) tubularSegments = 30;
15064
- if (arc === void 0) arc = 360;
15065
- if (noLongerAccessible === void 0) noLongerAccessible = true;
15066
- var mesh = new ModelMesh(engine);
15067
- PrimitiveMesh._setTorusData(mesh, radius, tubeRadius, radialSegments, tubularSegments, arc, noLongerAccessible, false);
15068
- var vertexBuffer = mesh.vertexBufferBindings[0].buffer;
15069
- engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, new TorusRestoreInfo(radius, tubeRadius, radialSegments, tubularSegments, arc, vertexBuffer, noLongerAccessible)));
15070
- return mesh;
16518
+ PrimitiveMesh._createTorusData = function _createTorusData(radius, tubeRadius, radialSegments, ringSegments, arcDegrees, tubeStartAngleDegrees, tubeArcDegrees, startAngleDegrees) {
16519
+ var radial = PrimitiveMesh._getSegmentCount(radialSegments, 3);
16520
+ var tubular = PrimitiveMesh._getSegmentCount(ringSegments, 1);
16521
+ var arc = engineMath.MathUtil.degreeToRadian(arcDegrees);
16522
+ var tubeStart = engineMath.MathUtil.degreeToRadian(tubeStartAngleDegrees);
16523
+ var tubeArc = engineMath.MathUtil.degreeToRadian(tubeArcDegrees);
16524
+ var circle = PrimitiveMesh._createArcSamples(tubular, engineMath.MathUtil.degreeToRadian(startAngleDegrees), arc);
16525
+ var data = new PrimitiveMeshBuilder((radial + 1) * (tubular + 1), radial * tubular * 6);
16526
+ for(var y = 0; y <= radial; y++){
16527
+ var v = tubeStart + y / radial * tubeArc;
16528
+ var cosV = Math.cos(v);
16529
+ var nz = Math.sin(v);
16530
+ for(var x = 0; x <= tubular; x++){
16531
+ var cosU = circle[x * 2];
16532
+ var sinU = circle[x * 2 + 1];
16533
+ var nx = cosV * cosU;
16534
+ var ny = cosV * sinU;
16535
+ data.addVertex(radius * cosU + tubeRadius * nx, radius * sinU + tubeRadius * ny, tubeRadius * nz, nx, ny, nz, x / tubular, y / radial);
16536
+ }
16537
+ }
16538
+ for(var y1 = 0; y1 < radial; y1++){
16539
+ for(var x1 = 0; x1 < tubular; x1++){
16540
+ var a = y1 * (tubular + 1) + x1;
16541
+ var c = a + tubular + 1;
16542
+ data.addTriangle(c, a, c + 1);
16543
+ data.addTriangle(a, a + 1, c + 1);
16544
+ }
16545
+ }
16546
+ data.boundsExtent = new engineMath.Vector3(radius + tubeRadius, radius + tubeRadius, tubeRadius);
16547
+ return data;
15071
16548
  };
15072
- /**
15073
- * Create a cone mesh.
15074
- * @param engine - Engine
15075
- * @param radius - The radius of cap
15076
- * @param height - The height of torso
15077
- * @param radialSegments - Cone radial segments
15078
- * @param heightSegments - Cone height segments
15079
- * @param noLongerAccessible - No longer access the vertices of the mesh after creation
15080
- * @returns Cone model mesh
15081
- */ PrimitiveMesh.createCone = function createCone(engine, radius, height, radialSegments, heightSegments, noLongerAccessible) {
15082
- if (radius === void 0) radius = 0.5;
15083
- if (height === void 0) height = 2;
15084
- if (radialSegments === void 0) radialSegments = 20;
15085
- if (heightSegments === void 0) heightSegments = 1;
15086
- if (noLongerAccessible === void 0) noLongerAccessible = true;
15087
- var mesh = new ModelMesh(engine);
15088
- PrimitiveMesh._setConeData(mesh, radius, height, radialSegments, heightSegments, noLongerAccessible, false);
15089
- var vertexBuffer = mesh.vertexBufferBindings[0].buffer;
15090
- engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, new ConeRestoreInfo(radius, height, radialSegments, heightSegments, vertexBuffer, noLongerAccessible)));
15091
- return mesh;
16549
+ PrimitiveMesh._createCircleData = function _createCircleData(radius, segments, startAngle, arcDegrees) {
16550
+ var count = PrimitiveMesh._getSegmentCount(segments, 3);
16551
+ var start = engineMath.MathUtil.degreeToRadian(startAngle);
16552
+ var arc = engineMath.MathUtil.degreeToRadian(arcDegrees);
16553
+ var data = new PrimitiveMeshBuilder(count + 2, count * 3);
16554
+ data.addVertex(0, 0, 0, 0, 0, 1, 0.5, 0.5);
16555
+ for(var i = 0; i <= count; i++){
16556
+ var angle = start + i / count * arc;
16557
+ var x = Math.cos(angle);
16558
+ var y = Math.sin(angle);
16559
+ data.addVertex(radius * x, radius * y, 0, 0, 0, 1, (x + 1) / 2, (y + 1) / 2);
16560
+ if (i > 0) {
16561
+ data.addTriangle(0, i, i + 1);
16562
+ }
16563
+ }
16564
+ return data;
15092
16565
  };
15093
- /**
15094
- * Create a capsule mesh.
15095
- * @param engine - Engine
15096
- * @param radius - The radius of the two hemispherical ends
15097
- * @param height - The height of the cylindrical part, measured between the centers of the hemispherical ends
15098
- * @param radialSegments - Hemispherical end radial segments
15099
- * @param heightSegments - Cylindrical part height segments
15100
- * @param noLongerAccessible - No longer access the vertices of the mesh after creation
15101
- * @returns Capsule model mesh
15102
- */ PrimitiveMesh.createCapsule = function createCapsule(engine, radius, height, radialSegments, heightSegments, noLongerAccessible) {
15103
- if (radius === void 0) radius = 0.5;
15104
- if (height === void 0) height = 2;
15105
- if (radialSegments === void 0) radialSegments = 6;
15106
- if (heightSegments === void 0) heightSegments = 1;
15107
- if (noLongerAccessible === void 0) noLongerAccessible = true;
15108
- var mesh = new ModelMesh(engine);
15109
- PrimitiveMesh._setCapsuleData(mesh, radius, height, radialSegments, heightSegments, noLongerAccessible, false);
15110
- var vertexBuffer = mesh.vertexBufferBindings[0].buffer;
15111
- engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, new CapsuleRestoreInfo(radius, height, radialSegments, heightSegments, vertexBuffer, noLongerAccessible)));
15112
- return mesh;
16566
+ PrimitiveMesh._createRingData = function _createRingData(innerRadius, outerRadius, ringSegments, widthSegments, startAngle, arcDegrees) {
16567
+ var radial = PrimitiveMesh._getSegmentCount(ringSegments, 3);
16568
+ var width = PrimitiveMesh._getSegmentCount(widthSegments);
16569
+ var start = engineMath.MathUtil.degreeToRadian(startAngle);
16570
+ var arc = engineMath.MathUtil.degreeToRadian(arcDegrees);
16571
+ var circle = PrimitiveMesh._createArcSamples(radial, start, arc);
16572
+ var data = new PrimitiveMeshBuilder((radial + 1) * (width + 1), radial * width * 6);
16573
+ for(var y = 0; y <= width; y++){
16574
+ var radius = innerRadius + (outerRadius - innerRadius) * y / width;
16575
+ for(var x = 0; x <= radial; x++){
16576
+ var px = radius * circle[x * 2];
16577
+ var py = radius * circle[x * 2 + 1];
16578
+ data.addVertex(px, py, 0, 0, 0, 1, outerRadius !== 0 ? (px / outerRadius + 1) / 2 : 0.5, outerRadius !== 0 ? (py / outerRadius + 1) / 2 : 0.5);
16579
+ }
16580
+ }
16581
+ for(var y1 = 0; y1 < width; y1++){
16582
+ for(var x1 = 0; x1 < radial; x1++){
16583
+ var a = y1 * (radial + 1) + x1;
16584
+ var c = a + radial + 1;
16585
+ data.addTriangle(a, c, a + 1);
16586
+ data.addTriangle(a + 1, c, c + 1);
16587
+ }
16588
+ }
16589
+ return data;
15113
16590
  };
15114
- /**
15115
- * @internal
15116
- */ PrimitiveMesh._setSubdivisionSurfaceSphereData = function _setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15117
- // Max step is limited to 6. Because 7 step will generate a single mesh with over 98306 vertices
15118
- step = engineMath.MathUtil.clamp(Math.floor(step), 1, 6);
15119
- var positions = new Float32Array(3 * (6 * Math.pow(4, step) + 2));
15120
- var cells = new Float32Array(24 * Math.pow(4, step));
15121
- PrimitiveMesh._subdiveCatmullClark(step, positions, cells);
16591
+ PrimitiveMesh._createRoundedCuboidData = function _createRoundedCuboidData(width, height, depth, cornerRadius, roundingSegments) {
16592
+ var radius = Math.max(0, Math.min(cornerRadius, width / 2, height / 2, depth / 2));
16593
+ if (radius === 0) {
16594
+ return PrimitiveMesh._createCuboidData(width, height, depth, 1, 1, 1);
16595
+ }
16596
+ var cornerSegments = PrimitiveMesh._getSegmentCount(roundingSegments);
16597
+ var count = cornerSegments * 2 + 1;
16598
+ var data = PrimitiveMesh._createCuboidData(width, height, depth, count, count, count);
16599
+ var inner = new engineMath.Vector3(width / 2 - radius, height / 2 - radius, depth / 2 - radius);
16600
+ var center = new engineMath.Vector3();
16601
+ var delta = new engineMath.Vector3();
16602
+ var components = [
16603
+ "x",
16604
+ "y",
16605
+ "z"
16606
+ ];
16607
+ var uvAxes = {
16608
+ x: [
16609
+ "z",
16610
+ "y"
16611
+ ],
16612
+ y: [
16613
+ "x",
16614
+ "z"
16615
+ ],
16616
+ z: [
16617
+ "x",
16618
+ "y"
16619
+ ]
16620
+ };
16621
+ for(var i = 0; i < data.vertexCount * 8; i += 8){
16622
+ var faceAxis = data.vertices[i + 3] !== 0 ? "x" : data.vertices[i + 4] !== 0 ? "y" : "z";
16623
+ for(var axis = 0; axis < 3; axis++){
16624
+ var component = components[axis];
16625
+ var halfSize = inner[component] + radius;
16626
+ var gridIndex = Math.round((data.vertices[i + axis] / halfSize + 1) / 2 * count);
16627
+ var p = gridIndex <= cornerSegments ? -inner[component] - radius * (1 - gridIndex / cornerSegments) : inner[component] + radius * (gridIndex - cornerSegments - 1) / cornerSegments;
16628
+ center[component] = Math.max(-inner[component], Math.min(inner[component], p));
16629
+ delta[component] = p - center[component];
16630
+ }
16631
+ var length = Math.hypot(delta.x, delta.y, delta.z);
16632
+ for(var axis1 = 0; axis1 < 3; axis1++){
16633
+ var component1 = components[axis1];
16634
+ var n = delta[component1] / length;
16635
+ data.vertices[i + axis1] = center[component1] + n * radius;
16636
+ data.vertices[i + 3 + axis1] = n;
16637
+ }
16638
+ for(var uv = 0; uv < 2; uv++){
16639
+ var component2 = uvAxes[faceAxis][uv];
16640
+ var angle = Math.atan2(Math.abs(delta[component2]), Math.abs(delta[faceAxis]));
16641
+ var distance = Math.abs(center[component2]) + radius * angle;
16642
+ var surfaceLength = inner[component2] * 2 + Math.PI * radius / 2;
16643
+ var direction = Math.sign(data.vertices[i + 6 + uv] - 0.5);
16644
+ data.vertices[i + 6 + uv] = 0.5 + direction * distance / surfaceLength;
16645
+ }
16646
+ }
16647
+ return data;
16648
+ };
16649
+ PrimitiveMesh._createRevolvedSurfaceData = function _createRevolvedSurfaceData(points, segmentCount, startAngle, arcDegrees) {
16650
+ if (points.length < 2) {
16651
+ throw new Error("A revolved surface profile needs at least two points.");
16652
+ }
16653
+ var count = PrimitiveMesh._getSegmentCount(segmentCount);
16654
+ var start = engineMath.MathUtil.degreeToRadian(startAngle);
16655
+ var arc = engineMath.MathUtil.degreeToRadian(arcDegrees);
16656
+ var data = new PrimitiveMeshBuilder((count + 1) * points.length, count * (points.length - 1) * 6);
16657
+ var normals = [];
16658
+ for(var i = 0; i < points.length; i++){
16659
+ var previous = points[Math.max(0, i - 1)];
16660
+ var current = points[i];
16661
+ var next = points[Math.min(points.length - 1, i + 1)];
16662
+ var a = PrimitiveMesh._normalizeVector(new engineMath.Vector3(current.y - previous.y, previous.x - current.x, 0));
16663
+ var b = PrimitiveMesh._normalizeVector(new engineMath.Vector3(next.y - current.y, current.x - next.x, 0));
16664
+ normals.push(PrimitiveMesh._normalizeVector(a.add(b)));
16665
+ }
16666
+ for(var x = 0; x <= count; x++){
16667
+ var angle = start + x / count * arc;
16668
+ var sin = Math.sin(angle);
16669
+ var cos = Math.cos(angle);
16670
+ for(var y = 0; y < points.length; y++){
16671
+ var point = points[y];
16672
+ var normal = normals[y];
16673
+ data.addVertex(point.x * sin, point.y, point.x * cos, normal.x * sin, normal.y, normal.x * cos, x / count, y / (points.length - 1));
16674
+ }
16675
+ }
16676
+ for(var x1 = 0; x1 < count; x1++){
16677
+ for(var y1 = 0; y1 < points.length - 1; y1++){
16678
+ var a1 = x1 * points.length + y1;
16679
+ var b1 = a1 + points.length;
16680
+ if (points[y1].x !== 0) {
16681
+ data.addTriangle(a1, b1, a1 + 1);
16682
+ }
16683
+ if (points[y1 + 1].x !== 0) {
16684
+ data.addTriangle(b1, b1 + 1, a1 + 1);
16685
+ }
16686
+ }
16687
+ }
16688
+ return data;
16689
+ };
16690
+ PrimitiveMesh._createTubeData = function _createTubeData(path, radius, pathSegments, radialSegments, closedPath) {
16691
+ var tangents = [];
16692
+ var points = MeshPathUtils.sample(path, PrimitiveMesh._getSegmentCount(pathSegments), closedPath, tangents);
16693
+ return PrimitiveMesh._createTubeSurfaceData(points, radius, radialSegments, closedPath, tangents);
16694
+ };
16695
+ PrimitiveMesh._createTubeSurfaceData = function _createTubeSurfaceData(points, radius, radialSegments, closedPath, fallbackTangents) {
16696
+ var count = points.length - 1;
16697
+ var radial = PrimitiveMesh._getSegmentCount(radialSegments, 3);
16698
+ var frames = MeshPathUtils.computeFrames(points, closedPath, fallbackTangents);
16699
+ var data = new PrimitiveMeshBuilder((count + 1) * (radial + 1), count * radial * 6);
16700
+ var circle = PrimitiveMesh._createArcSamples(radial);
16701
+ for(var y = 0; y <= count; y++){
16702
+ var point = points[y];
16703
+ var normal = frames.normals[y];
16704
+ var binormal = frames.binormals[y];
16705
+ for(var x = 0; x <= radial; x++){
16706
+ var c = circle[x * 2];
16707
+ var s = circle[x * 2 + 1];
16708
+ var nx = normal.x * c + binormal.x * s;
16709
+ var ny = normal.y * c + binormal.y * s;
16710
+ var nz = normal.z * c + binormal.z * s;
16711
+ data.addVertex(point.x + radius * nx, point.y + radius * ny, point.z + radius * nz, nx, ny, nz, y / count, x / radial);
16712
+ }
16713
+ }
16714
+ for(var y1 = 0; y1 < count; y1++){
16715
+ for(var x1 = 0; x1 < radial; x1++){
16716
+ var a = y1 * (radial + 1) + x1;
16717
+ var c1 = a + radial + 1;
16718
+ data.addTriangle(a, a + 1, c1);
16719
+ data.addTriangle(a + 1, c1 + 1, c1);
16720
+ }
16721
+ }
16722
+ return data;
16723
+ };
16724
+ PrimitiveMesh._createTorusKnotData = function _createTorusKnotData(radius, tubeRadius, pathSegments, radialSegments, axisTurns, crossSectionTurns) {
16725
+ if (axisTurns === 0 && crossSectionTurns === 0) {
16726
+ throw new Error("A torus knot needs at least one nonzero winding.");
16727
+ }
16728
+ var count = PrimitiveMesh._getSegmentCount(pathSegments);
16729
+ var points = [];
16730
+ var tangents = [];
16731
+ for(var i = 0; i < count; i++){
16732
+ var angle = i / count * Math.PI * 2;
16733
+ var u = axisTurns * angle;
16734
+ var v = crossSectionTurns * angle;
16735
+ points.push(new engineMath.Vector3(radius * (2 + Math.cos(v)) * Math.cos(u) / 2, radius * (2 + Math.cos(v)) * Math.sin(u) / 2, radius * Math.sin(v) / 2));
16736
+ var radialDerivative = -crossSectionTurns * Math.sin(v);
16737
+ var angularDerivative = axisTurns * (2 + Math.cos(v));
16738
+ tangents.push(new engineMath.Vector3(radialDerivative * Math.cos(u) - angularDerivative * Math.sin(u), radialDerivative * Math.sin(u) + angularDerivative * Math.cos(u), crossSectionTurns * Math.cos(v)));
16739
+ }
16740
+ points.push(points[0]);
16741
+ tangents.push(tangents[0]);
16742
+ return PrimitiveMesh._createTubeSurfaceData(points, tubeRadius, radialSegments, true, tangents);
16743
+ };
16744
+ PrimitiveMesh._createRegularPolyhedronData = function _createRegularPolyhedronData(type, radius, segments) {
16745
+ var _PrimitiveMesh__regularPolyhedra_type = PrimitiveMesh._regularPolyhedra[type], positions = _PrimitiveMesh__regularPolyhedra_type[0], indices = _PrimitiveMesh__regularPolyhedra_type[1];
16746
+ var divisions = PrimitiveMesh._getSegmentCount(segments);
16747
+ var vertexCount = indices.length * divisions * divisions;
16748
+ var data = new PrimitiveMeshBuilder(vertexCount, vertexCount);
16749
+ var vertices = new Float64Array((divisions + 1) * (divisions + 2) * 8 / 2);
16750
+ var left = new engineMath.Vector3();
16751
+ var right = new engineMath.Vector3();
16752
+ var point = new engineMath.Vector3();
16753
+ for(var face = 0; face < indices.length; face += 3){
16754
+ var offset = 0;
16755
+ for(var i = 0; i <= divisions; i++){
16756
+ left.copyFromArray(positions, indices[face] * 3);
16757
+ right.copyFromArray(positions, indices[face + 1] * 3);
16758
+ point.copyFromArray(positions, indices[face + 2] * 3);
16759
+ engineMath.Vector3.lerp(left, point, i / divisions, left);
16760
+ engineMath.Vector3.lerp(right, point, i / divisions, right);
16761
+ for(var j = 0; j <= divisions - i; j++){
16762
+ engineMath.Vector3.lerp(left, right, divisions === i ? 0 : j / (divisions - i), point);
16763
+ PrimitiveMesh._normalizeVector(point);
16764
+ vertices[offset] = point.x * radius;
16765
+ vertices[offset + 1] = point.y * radius;
16766
+ vertices[offset + 2] = point.z * radius;
16767
+ point.copyToArray(vertices, offset + 3);
16768
+ vertices[offset + 6] = Math.atan2(point.z, -point.x) / (2 * Math.PI) + 0.5;
16769
+ vertices[offset + 7] = Math.acos(Math.max(-1, Math.min(1, point.y))) / Math.PI;
16770
+ offset += 8;
16771
+ }
16772
+ }
16773
+ var row = 0;
16774
+ for(var i1 = 0; i1 < divisions; i1++){
16775
+ var next = row + divisions - i1 + 1;
16776
+ for(var j1 = 0; j1 < divisions - i1; j1++){
16777
+ PrimitiveMesh._addPolyhedronFace(data, vertices, (row + j1 + 1) * 8, (next + j1) * 8, (row + j1) * 8, divisions === 1);
16778
+ if (j1 < divisions - i1 - 1) {
16779
+ PrimitiveMesh._addPolyhedronFace(data, vertices, (row + j1 + 1) * 8, (next + j1 + 1) * 8, (next + j1) * 8, divisions === 1);
16780
+ }
16781
+ }
16782
+ row = next;
16783
+ }
16784
+ }
16785
+ return data;
16786
+ };
16787
+ PrimitiveMesh._addPolyhedronFace = function _addPolyhedronFace(data, vertices, a, b, c, flat) {
16788
+ var uA = vertices[a + 6];
16789
+ var uB = vertices[b + 6];
16790
+ var uC = vertices[c + 6];
16791
+ var poleA = Math.abs(vertices[a + 4]) > 1 - 1e-10;
16792
+ var poleB = Math.abs(vertices[b + 4]) > 1 - 1e-10;
16793
+ var poleC = Math.abs(vertices[c + 4]) > 1 - 1e-10;
16794
+ if (poleA) {
16795
+ uA = uB;
16796
+ }
16797
+ if (poleB) {
16798
+ uB = uC;
16799
+ }
16800
+ if (poleC) {
16801
+ uC = uA;
16802
+ }
16803
+ var minU = Math.min(uA, uB, uC);
16804
+ var maxU = Math.max(uA, uB, uC);
16805
+ var middleU = uA === minU ? Math.min(uB, uC) : uB === minU ? Math.min(uA, uC) : Math.min(uA, uB);
16806
+ // Choose the shortest U interval before averaging pole coordinates
16807
+ var gap = 1 + minU - maxU;
16808
+ var startU = minU;
16809
+ if (middleU - minU > gap) {
16810
+ gap = middleU - minU;
16811
+ startU = middleU;
16812
+ }
16813
+ if (maxU - middleU > gap) {
16814
+ startU = maxU;
16815
+ }
16816
+ if (uA < startU) {
16817
+ uA += 1;
16818
+ }
16819
+ if (uB < startU) {
16820
+ uB += 1;
16821
+ }
16822
+ if (uC < startU) {
16823
+ uC += 1;
16824
+ }
16825
+ if (poleA) {
16826
+ uA = (uB + uC) / 2;
16827
+ }
16828
+ if (poleB) {
16829
+ uB = (uC + uA) / 2;
16830
+ }
16831
+ if (poleC) {
16832
+ uC = (uA + uB) / 2;
16833
+ }
16834
+ var nx = 0;
16835
+ var ny = 0;
16836
+ var nz = 0;
16837
+ if (flat) {
16838
+ var abX = vertices[b] - vertices[a];
16839
+ var abY = vertices[b + 1] - vertices[a + 1];
16840
+ var abZ = vertices[b + 2] - vertices[a + 2];
16841
+ var acX = vertices[c] - vertices[a];
16842
+ var acY = vertices[c + 1] - vertices[a + 1];
16843
+ var acZ = vertices[c + 2] - vertices[a + 2];
16844
+ nx = abY * acZ - abZ * acY;
16845
+ ny = abZ * acX - abX * acZ;
16846
+ nz = abX * acY - abY * acX;
16847
+ var length = Math.hypot(nx, ny, nz);
16848
+ var inverse = length > 0 ? 1 / length : 0;
16849
+ nx *= inverse;
16850
+ ny *= inverse;
16851
+ nz *= inverse;
16852
+ }
16853
+ var start = data.vertexCount;
16854
+ for(var i = 0; i < 3; i++){
16855
+ var offset = i === 0 ? a : i === 1 ? b : c;
16856
+ data.addVertex(vertices[offset], vertices[offset + 1], vertices[offset + 2], flat ? nx : vertices[offset + 3], flat ? ny : vertices[offset + 4], flat ? nz : vertices[offset + 5], i === 0 ? uA : i === 1 ? uB : uC, vertices[offset + 7]);
16857
+ }
16858
+ data.addTriangle(start, start + 1, start + 2);
16859
+ };
16860
+ PrimitiveMesh._createPolygonData = function _createPolygonData(shapes) {
16861
+ var data = new PrimitiveMeshBuilder();
16862
+ for(var _iterator = _create_for_of_iterator_helper_loose(shapes), _step; !(_step = _iterator()).done;){
16863
+ var polygon = _step.value;
16864
+ var contours = PolygonUtils.prepareContours(polygon);
16865
+ var _PolygonUtils_triangulateContours = PolygonUtils.triangulateContours(contours), points = _PolygonUtils_triangulateContours.points, indices = _PolygonUtils_triangulateContours.indices;
16866
+ var base = data.vertexCount;
16867
+ var start = data.indexCount;
16868
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(points), _step1; !(_step1 = _iterator1()).done;){
16869
+ var point = _step1.value;
16870
+ data.addVertex(point.x, point.y, 0, 0, 0, 1, point.x, point.y);
16871
+ }
16872
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(indices), _step2; !(_step2 = _iterator2()).done;){
16873
+ var index = _step2.value;
16874
+ data.addIndex(base + index);
16875
+ }
16876
+ data.addGroup(start);
16877
+ }
16878
+ return data;
16879
+ };
16880
+ PrimitiveMesh._createExtrudedPolygonData = function _createExtrudedPolygonData(shapes, depth, stepCount, pathInput, closedPath, bevelDepth, bevelWidth, contourOffset, bevelSegmentCount) {
16881
+ var data = new PrimitiveMeshBuilder();
16882
+ var steps = PrimitiveMesh._getSegmentCount(stepCount, closedPath ? 3 : 1);
16883
+ var tangents = [];
16884
+ var path = pathInput ? MeshPathUtils.sample(pathInput, steps, closedPath, tangents) : undefined;
16885
+ var frames = path ? MeshPathUtils.computeFrames(path, closedPath, tangents) : undefined;
16886
+ var bevelEnabled = !path && bevelWidth > 0;
16887
+ var bevelSegments = bevelEnabled ? PrimitiveMesh._getSegmentCount(bevelSegmentCount) : 0;
16888
+ var thickness = bevelEnabled ? Math.min(bevelDepth, depth / 2) : 0;
16889
+ var size = bevelEnabled ? bevelWidth : 0;
16890
+ var offset = path ? 0 : contourOffset;
16891
+ var layers = [];
16892
+ var uvA = new engineMath.Vector2();
16893
+ var uvB = new engineMath.Vector2();
16894
+ var uvC = new engineMath.Vector2();
16895
+ var uvD = new engineMath.Vector2();
16896
+ for(var i = 0; i < bevelSegments; i++){
16897
+ var angle = i / bevelSegments * Math.PI / 2;
16898
+ layers.push({
16899
+ z: thickness * (1 - Math.cos(angle)),
16900
+ inset: size * (1 - Math.sin(angle))
16901
+ });
16902
+ }
16903
+ for(var i1 = 0; i1 <= steps; i1++){
16904
+ layers.push({
16905
+ z: thickness + (depth - thickness * 2) * i1 / steps,
16906
+ inset: 0
16907
+ });
16908
+ }
16909
+ for(var i2 = 1; i2 <= bevelSegments; i2++){
16910
+ var angle1 = i2 / bevelSegments * Math.PI / 2;
16911
+ layers.push({
16912
+ z: depth - thickness + thickness * Math.sin(angle1),
16913
+ inset: size * (1 - Math.cos(angle1))
16914
+ });
16915
+ }
16916
+ for(var _iterator = _create_for_of_iterator_helper_loose(shapes), _step; !(_step = _iterator()).done;){
16917
+ var _loop = function(i3) {
16918
+ offsetContours[i3] = i3 > 0 && layers[i3].inset === layers[i3 - 1].inset ? offsetContours[i3 - 1] : contours.map(function(contour) {
16919
+ return PrimitiveMesh._insetContour(contour, layers[i3].inset - offset);
16920
+ });
16921
+ };
16922
+ var polygon = _step.value;
16923
+ var cap = function cap(layer, top) {
16924
+ var _PolygonUtils_triangulateContours = PolygonUtils.triangulateContours(offsetContours[layer]), points = _PolygonUtils_triangulateContours.points, indices = _PolygonUtils_triangulateContours.indices;
16925
+ var positions = rings[layer].flat();
16926
+ for(var i = 0; i < indices.length; i += 3){
16927
+ var a = indices[i];
16928
+ var b = indices[i + (top ? 1 : 2)];
16929
+ var c = indices[i + (top ? 2 : 1)];
16930
+ data.addFace(positions[a], positions[b], positions[c], points[a], points[b], points[c]);
16931
+ }
16932
+ };
16933
+ var contours = PolygonUtils.prepareContours(polygon);
16934
+ var offsetContours = new Array(layers.length);
16935
+ for(var i3 = 0; i3 < layers.length; i3++)_loop(i3);
16936
+ var rings = offsetContours.map(function(contour, layer) {
16937
+ var z = layers[layer].z;
16938
+ var center = path == null ? void 0 : path[layer];
16939
+ var normal = frames == null ? void 0 : frames.normals[layer];
16940
+ var binormal = frames == null ? void 0 : frames.binormals[layer];
16941
+ return contour.map(function(points) {
16942
+ return points.map(function(point) {
16943
+ return center ? new engineMath.Vector3(center.x + normal.x * point.x + binormal.x * point.y, center.y + normal.y * point.x + binormal.y * point.y, center.z + normal.z * point.x + binormal.z * point.y) : new engineMath.Vector3(point.x, point.y, z);
16944
+ });
16945
+ });
16946
+ });
16947
+ if (!closedPath) {
16948
+ var capStart = data.indexCount;
16949
+ cap(0, false);
16950
+ cap(layers.length - 1, true);
16951
+ data.addGroup(capStart);
16952
+ }
16953
+ var sideStart = data.indexCount;
16954
+ for(var contour = 0; contour < contours.length; contour++){
16955
+ var original = contours[contour];
16956
+ var distances = [
16957
+ 0
16958
+ ];
16959
+ for(var point = 0; point < original.length; point++){
16960
+ var next = original[(point + 1) % original.length];
16961
+ distances.push(distances[point] + Math.hypot(next.x - original[point].x, next.y - original[point].y));
16962
+ }
16963
+ for(var layer = 0; layer < layers.length - 1; layer++){
16964
+ for(var point1 = 0; point1 < original.length; point1++){
16965
+ var next1 = (point1 + 1) % original.length;
16966
+ var a = rings[layer][contour][point1];
16967
+ var b = rings[layer][contour][next1];
16968
+ var c = rings[layer + 1][contour][point1];
16969
+ var d = rings[layer + 1][contour][next1];
16970
+ uvA.set(distances[point1], layer / (layers.length - 1));
16971
+ uvB.set(distances[point1 + 1], uvA.y);
16972
+ uvC.set(uvA.x, (layer + 1) / (layers.length - 1));
16973
+ uvD.set(uvB.x, uvC.y);
16974
+ data.addFace(a, b, c, uvA, uvB, uvC);
16975
+ data.addFace(b, d, c, uvB, uvD, uvC);
16976
+ }
16977
+ }
16978
+ }
16979
+ data.addGroup(sideStart);
16980
+ }
16981
+ return data;
16982
+ };
16983
+ PrimitiveMesh._insetContour = function _insetContour(contour, distance) {
16984
+ if (distance === 0) {
16985
+ return contour;
16986
+ }
16987
+ return contour.map(function(point, index) {
16988
+ var previous = contour[(index + contour.length - 1) % contour.length];
16989
+ var next = contour[(index + 1) % contour.length];
16990
+ var ax = point.x - previous.x;
16991
+ var ay = point.y - previous.y;
16992
+ var bx = next.x - point.x;
16993
+ var by = next.y - point.y;
16994
+ var al = Math.hypot(ax, ay);
16995
+ var bl = Math.hypot(bx, by);
16996
+ var nx = -ay / al - by / bl;
16997
+ var ny = ax / al + bx / bl;
16998
+ var denominator = nx * (-by / bl) + ny * (bx / bl);
16999
+ var scale = Math.abs(denominator) > 1e-10 ? distance / denominator : 0;
17000
+ return new engineMath.Vector2(point.x + nx * scale, point.y + ny * scale);
17001
+ });
17002
+ };
17003
+ PrimitiveMesh._createSphereData = function _createSphereData(radius, subdivisionLevel, horizontalStart, horizontalEnd, verticalStart, verticalEnd) {
17004
+ var horizontalArc = Math.min(360, horizontalEnd - horizontalStart);
17005
+ verticalStart = Math.max(0, verticalStart);
17006
+ verticalEnd = Math.min(180, verticalEnd);
17007
+ if (horizontalArc < 360 || verticalStart > 0 || verticalEnd < 180) {
17008
+ var surface = PrimitiveMesh._createSphereSurfaceData(1, subdivisionLevel);
17009
+ return PrimitiveMesh._createSphereSectionData(surface, radius, horizontalStart, horizontalArc, verticalStart, verticalEnd);
17010
+ }
17011
+ var data = PrimitiveMesh._createSphereSurfaceData(radius, subdivisionLevel);
17012
+ if (horizontalStart !== 0) {
17013
+ var angle = engineMath.MathUtil.degreeToRadian(horizontalStart);
17014
+ var cos = Math.cos(angle);
17015
+ var sin = Math.sin(angle);
17016
+ var vertices = data.vertices;
17017
+ for(var i = 0; i < vertices.length; i += 8){
17018
+ var x = vertices[i];
17019
+ var z = vertices[i + 2];
17020
+ var nx = vertices[i + 3];
17021
+ var nz = vertices[i + 5];
17022
+ vertices[i] = x * cos + z * sin;
17023
+ vertices[i + 2] = -x * sin + z * cos;
17024
+ vertices[i + 3] = nx * cos + nz * sin;
17025
+ vertices[i + 5] = -nx * sin + nz * cos;
17026
+ }
17027
+ }
17028
+ return data;
17029
+ };
17030
+ PrimitiveMesh._createSphereSectionData = function _createSphereSectionData(surface, radius, horizontalStart, horizontalArc, verticalStart, verticalEnd) {
17031
+ var data = new PrimitiveMeshBuilder(surface.vertexCount, surface.indexCount);
17032
+ if (horizontalArc <= 0 || verticalEnd <= verticalStart) {
17033
+ return data;
17034
+ }
17035
+ var vertices = surface.vertices;
17036
+ var indices = surface.indices;
17037
+ var horizontalArcRadians = engineMath.MathUtil.degreeToRadian(horizontalArc);
17038
+ var verticalStartRadians = engineMath.MathUtil.degreeToRadian(verticalStart);
17039
+ var verticalArcRadians = engineMath.MathUtil.degreeToRadian(verticalEnd - verticalStart);
17040
+ var startAngle = engineMath.MathUtil.degreeToRadian(horizontalStart);
17041
+ var cos = Math.cos(startAngle);
17042
+ var sin = Math.sin(startAngle);
17043
+ var fullTurn = horizontalArc === 360;
17044
+ var segmentCount = fullTurn ? 1 : Math.ceil(horizontalArc / 180);
17045
+ var boundaries = [];
17046
+ for(var i = 0; i < segmentCount; i++){
17047
+ var start = horizontalArcRadians * i / segmentCount;
17048
+ var end = horizontalArcRadians * (i + 1) / segmentCount;
17049
+ boundaries.push({
17050
+ start: new engineMath.Vector3(Math.sin(start), 0, Math.cos(start)),
17051
+ end: new engineMath.Vector3(-Math.sin(end), 0, -Math.cos(end))
17052
+ });
17053
+ }
17054
+ var topNormal = new engineMath.Vector3(0, -1, 0);
17055
+ var bottomNormal = new engineMath.Vector3(0, 1, 0);
17056
+ var topOffset = -Math.cos(verticalStartRadians);
17057
+ var bottomOffset = Math.cos(engineMath.MathUtil.degreeToRadian(verticalEnd));
17058
+ var vertexMap = new Map();
17059
+ var trianglePoints = [
17060
+ new engineMath.Vector3(),
17061
+ new engineMath.Vector3(),
17062
+ new engineMath.Vector3()
17063
+ ];
17064
+ var verticalPoints = [];
17065
+ var clippedPoints = [];
17066
+ var polygonPoints = [];
17067
+ var points = new Array(3);
17068
+ var uvs = new Float64Array(6);
17069
+ var poles = new Array(3);
17070
+ var ab = new engineMath.Vector3();
17071
+ var ac = new engineMath.Vector3();
17072
+ for(var i1 = 0; i1 < indices.length; i1 += 3){
17073
+ var triangle = trianglePoints;
17074
+ var triangleCount = 3;
17075
+ for(var corner = 0; corner < 3; corner++){
17076
+ var offset = indices[i1 + corner] * 8;
17077
+ PrimitiveMesh._normalizeVector(triangle[corner].set(vertices[offset], vertices[offset + 1], vertices[offset + 2]));
17078
+ }
17079
+ if (verticalStart > 0) {
17080
+ triangleCount = PrimitiveMesh._clipSpherePolygon(triangle, triangleCount, topNormal, topOffset, verticalPoints);
17081
+ triangle = verticalPoints;
17082
+ }
17083
+ if (verticalEnd < 180) {
17084
+ var output = triangle === trianglePoints ? verticalPoints : trianglePoints;
17085
+ triangleCount = PrimitiveMesh._clipSpherePolygon(triangle, triangleCount, bottomNormal, bottomOffset, output);
17086
+ triangle = output;
17087
+ }
17088
+ for(var _iterator = _create_for_of_iterator_helper_loose(boundaries), _step; !(_step = _iterator()).done;){
17089
+ var boundary = _step.value;
17090
+ var polygon = triangle;
17091
+ var polygonCount = triangleCount;
17092
+ if (!fullTurn) {
17093
+ polygonCount = PrimitiveMesh._clipSpherePolygon(polygon, polygonCount, boundary.start, 0, clippedPoints);
17094
+ polygonCount = PrimitiveMesh._clipSpherePolygon(clippedPoints, polygonCount, boundary.end, 0, polygonPoints);
17095
+ polygon = polygonPoints;
17096
+ }
17097
+ for(var corner1 = 1; corner1 + 1 < polygonCount; corner1++){
17098
+ points[0] = polygon[0];
17099
+ points[1] = polygon[corner1];
17100
+ points[2] = polygon[corner1 + 1];
17101
+ engineMath.Vector3.subtract(points[1], points[0], ab);
17102
+ engineMath.Vector3.subtract(points[2], points[0], ac);
17103
+ engineMath.Vector3.cross(ab, ac, ab);
17104
+ if (ab.length() < 1e-12) {
17105
+ continue;
17106
+ }
17107
+ var minU = Infinity;
17108
+ var maxU = -Infinity;
17109
+ var nonPoleCount = 0;
17110
+ for(var j = 0; j < 3; j++){
17111
+ var point = points[j];
17112
+ var angle = Math.atan2(point.z, -point.x);
17113
+ angle = angle < -1e-10 ? angle + Math.PI * 2 : Math.max(0, angle);
17114
+ var u = engineMath.MathUtil.clamp(angle / horizontalArcRadians, 0, 1);
17115
+ uvs[j * 2] = u;
17116
+ uvs[j * 2 + 1] = engineMath.MathUtil.clamp((Math.acos(engineMath.MathUtil.clamp(point.y, -1, 1)) - verticalStartRadians) / verticalArcRadians, 0, 1);
17117
+ poles[j] = Math.hypot(point.x, point.z) <= 1e-10;
17118
+ if (!poles[j]) {
17119
+ minU = Math.min(minU, u);
17120
+ maxU = Math.max(maxU, u);
17121
+ nonPoleCount++;
17122
+ }
17123
+ }
17124
+ var sumU = 0;
17125
+ for(var j1 = 0; j1 < 3; j1++){
17126
+ if (!poles[j1]) {
17127
+ if (fullTurn && maxU - minU > 0.5 && uvs[j1 * 2] < 0.5) {
17128
+ uvs[j1 * 2] += 1;
17129
+ }
17130
+ sumU += uvs[j1 * 2];
17131
+ }
17132
+ }
17133
+ for(var j2 = 0; j2 < 3; j2++){
17134
+ var point1 = points[j2];
17135
+ var u1 = poles[j2] ? sumU / nonPoleCount : uvs[j2 * 2];
17136
+ var v = uvs[j2 * 2 + 1];
17137
+ var key = Math.round(point1.x * 1e10) + "," + Math.round(point1.y * 1e10) + "," + Math.round(point1.z * 1e10) + "," + Math.round(u1 * 1e10) + "," + Math.round(v * 1e10);
17138
+ var index = vertexMap.get(key);
17139
+ if (index === undefined) {
17140
+ var nx = point1.x * cos + point1.z * sin;
17141
+ var nz = -point1.x * sin + point1.z * cos;
17142
+ index = data.addVertex(radius * nx, radius * point1.y, radius * nz, nx, point1.y, nz, u1, v);
17143
+ vertexMap.set(key, index);
17144
+ }
17145
+ data.addIndex(index);
17146
+ }
17147
+ }
17148
+ }
17149
+ }
17150
+ data.boundsExtent = new engineMath.Vector3(radius, radius, radius);
17151
+ return data;
17152
+ };
17153
+ PrimitiveMesh._clipSpherePolygon = function _clipSpherePolygon(polygon, count, normal, offset, out) {
17154
+ if (count === 0) {
17155
+ return 0;
17156
+ }
17157
+ var resultCount = 0;
17158
+ var previous = polygon[count - 1];
17159
+ var previousDistance = engineMath.Vector3.dot(previous, normal) - offset;
17160
+ for(var i = 0; i < count; i++){
17161
+ var current = polygon[i];
17162
+ var distance = engineMath.Vector3.dot(current, normal) - offset;
17163
+ var inside = distance >= -1e-9;
17164
+ var previousInside = previousDistance >= -1e-9;
17165
+ if (inside !== previousInside) {
17166
+ var _out, _ref;
17167
+ var _;
17168
+ var point = (_ = (_out = out)[_ref = resultCount++]) != null ? _ : _out[_ref] = new engineMath.Vector3();
17169
+ var t = previousDistance / (previousDistance - distance);
17170
+ if (t < 1e-10) {
17171
+ point.copyFrom(previous);
17172
+ } else if (t > 1 - 1e-10) {
17173
+ point.copyFrom(current);
17174
+ } else {
17175
+ engineMath.Vector3.lerp(previous, current, t, point);
17176
+ // Preserve latitude boundaries when projecting the intersection back onto the sphere
17177
+ var length = Math.hypot(point.x, point.z);
17178
+ var scale = length > 0 ? Math.sqrt(Math.max(0, 1 - point.y * point.y)) / length : 0;
17179
+ point.x *= scale;
17180
+ point.z *= scale;
17181
+ }
17182
+ }
17183
+ if (inside) {
17184
+ var _out1, _ref1;
17185
+ var _1;
17186
+ ((_1 = (_out1 = out)[_ref1 = resultCount++]) != null ? _1 : _out1[_ref1] = new engineMath.Vector3()).copyFrom(current);
17187
+ }
17188
+ previous = current;
17189
+ previousDistance = distance;
17190
+ }
17191
+ return resultCount;
17192
+ };
17193
+ PrimitiveMesh._createSphereSurfaceData = function _createSphereSurfaceData(radius, subdivisionLevel) {
17194
+ // Level 7 exceeds the 16-bit vertex index range
17195
+ var level = engineMath.MathUtil.clamp(Math.floor(subdivisionLevel), 1, 6);
17196
+ var _SubdivisionUtils_subdivideQuads = SubdivisionUtils.subdivideQuads(PrimitiveMesh._sphereSeedPositions, PrimitiveMesh._sphereSeedCells, level), positions = _SubdivisionUtils_subdivideQuads.positions, cells = _SubdivisionUtils_subdivideQuads.quads;
15122
17197
  var positionCount = positions.length / 3;
15123
17198
  var cellsCount = cells.length / 4;
15124
- var poleOffset = positionCount + Math.pow(2, step + 1) - 1;
15125
- // 16 extra vertices for pole uv
15126
- // 2 vertices at each pole are idle
17199
+ var poleOffset = positionCount + Math.pow(2, level + 1) - 1;
17200
+ // Reserve pole duplicates so each triangle can use a local U coordinate
15127
17201
  var vertexCount = poleOffset + 16;
15128
17202
  var vertices = new Float32Array(vertexCount * 8);
15129
- var indices = PrimitiveMesh._generateIndices(sphereMesh.engine, positionCount, cellsCount * 6);
17203
+ var indices = new Uint16Array(cellsCount * 6);
15130
17204
  var seamCount = 0;
15131
17205
  var seamVertices = {};
15132
- // Get normals, uvs, and scale to radius
15133
17206
  for(var i = 0; i < positionCount; i++){
15134
17207
  var offset = 3 * i;
15135
17208
  var x = positions[offset];
@@ -15148,875 +17221,182 @@ var BufferUpdateInfo = /*#__PURE__*/ function() {
15148
17221
  vertices[offset + 5] = z;
15149
17222
  vertices[offset + 6] = (Math.PI - Math.atan2(z, x)) / (2 * Math.PI);
15150
17223
  vertices[offset + 7] = Math.acos(y) / Math.PI;
17224
+ // Duplicate the seam so adjacent triangles can use U = 0 and U = 1
15151
17225
  if (vertices[offset + 6] === 0) {
15152
- // Generate seam vertex
15153
17226
  var seamOffset = 8 * (positionCount + seamCount++);
15154
17227
  vertices.set(vertices.subarray(offset, offset + 8), seamOffset);
15155
17228
  vertices[seamOffset + 6] = 1.0;
15156
- // Cache seam vertex
15157
17229
  seamVertices[offset / 8] = seamOffset / 8;
15158
17230
  }
15159
17231
  }
15160
- // Get indices
15161
17232
  var offset1 = 0;
15162
- this._spherePoleIdx = 0;
17233
+ var poleIndex = 0;
15163
17234
  for(var i1 = 0; i1 < cellsCount; i1++){
15164
17235
  var idx = 4 * i1;
15165
17236
  var indexA = cells[idx];
15166
17237
  var indexB = cells[idx + 1];
15167
17238
  var indexC = cells[idx + 2];
15168
17239
  var indexD = cells[idx + 3];
15169
- // Handle seam by replacing vertex index to seam vertex index if necessary
15170
17240
  var floatIndexA = 8 * indexA;
15171
17241
  var floatIndexB = 8 * indexB;
15172
17242
  var floatIndexC = 8 * indexC;
15173
17243
  var floatIndexD = 8 * indexD;
15174
- // If center Z is negative
17244
+ // Use the U = 1 copies on the negative-Z side of the seam
15175
17245
  if (vertices[floatIndexA + 2] + vertices[floatIndexB + 2] + vertices[floatIndexC + 2] < 0) {
15176
- vertices[floatIndexA + 6] === 0 && (indexA = seamVertices[indexA]);
15177
- vertices[floatIndexB + 6] === 0 && (indexB = seamVertices[indexB]);
15178
- vertices[floatIndexC + 6] === 0 && (indexC = seamVertices[indexC]);
15179
- vertices[floatIndexD + 6] === 0 && (indexD = seamVertices[indexD]);
17246
+ if (vertices[floatIndexA + 6] === 0) {
17247
+ indexA = seamVertices[indexA];
17248
+ }
17249
+ if (vertices[floatIndexB + 6] === 0) {
17250
+ indexB = seamVertices[indexB];
17251
+ }
17252
+ if (vertices[floatIndexC + 6] === 0) {
17253
+ indexC = seamVertices[indexC];
17254
+ }
17255
+ if (vertices[floatIndexD + 6] === 0) {
17256
+ indexD = seamVertices[indexD];
17257
+ }
15180
17258
  }
15181
17259
  indices[offset1] = indexA;
15182
17260
  indices[offset1 + 1] = indexB;
15183
17261
  indices[offset1 + 2] = indexC;
15184
- this._generateAndReplacePoleUV(indices, vertices, offset1, poleOffset);
17262
+ poleIndex = PrimitiveMesh._replacePoleUV(indices, vertices, offset1, poleOffset, poleIndex);
15185
17263
  indices[offset1 + 3] = indexA;
15186
17264
  indices[offset1 + 4] = indexC;
15187
17265
  indices[offset1 + 5] = indexD;
15188
- this._generateAndReplacePoleUV(indices, vertices, offset1 + 3, poleOffset);
17266
+ poleIndex = PrimitiveMesh._replacePoleUV(indices, vertices, offset1 + 3, poleOffset, poleIndex);
15189
17267
  offset1 += 6;
15190
17268
  }
15191
- if (!isRestoreMode) {
15192
- var bounds = sphereMesh.bounds;
15193
- bounds.min.set(-radius, -radius, -radius);
15194
- bounds.max.set(radius, radius, radius);
15195
- }
15196
- PrimitiveMesh._initialize(sphereMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
15197
- };
15198
- /**
15199
- * @internal
15200
- */ PrimitiveMesh._setSphereData = function _setSphereData(sphereMesh, radius, segments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15201
- segments = Math.max(2, Math.floor(segments));
15202
- var count = segments + 1;
15203
- var vertexCount = count * count;
15204
- var rectangleCount = segments * segments;
15205
- var indices = PrimitiveMesh._generateIndices(sphereMesh.engine, vertexCount, rectangleCount * 6);
15206
- var thetaRange = Math.PI;
15207
- var alphaRange = thetaRange * 2;
15208
- var countReciprocal = 1.0 / count;
15209
- var segmentsReciprocal = 1.0 / segments;
15210
- var vertexFloatCount = 8;
15211
- var vertices = new Float32Array(vertexCount * vertexFloatCount);
15212
- for(var i = 0; i < vertexCount; ++i){
15213
- var x = i % count;
15214
- var y = i * countReciprocal | 0;
15215
- var u = x * segmentsReciprocal;
15216
- var v = y * segmentsReciprocal;
15217
- var alphaDelta = u * alphaRange;
15218
- var thetaDelta = v * thetaRange;
15219
- var sinTheta = Math.sin(thetaDelta);
15220
- var posX = -radius * Math.cos(alphaDelta) * sinTheta;
15221
- var posY = radius * Math.cos(thetaDelta);
15222
- var posZ = radius * Math.sin(alphaDelta) * sinTheta;
15223
- var offset = i * vertexFloatCount;
15224
- // Position
15225
- vertices[offset++] = posX;
15226
- vertices[offset++] = posY;
15227
- vertices[offset++] = posZ;
15228
- // Normal
15229
- vertices[offset++] = posX;
15230
- vertices[offset++] = posY;
15231
- vertices[offset++] = posZ;
15232
- // TexCoord
15233
- vertices[offset++] = u;
15234
- vertices[offset++] = v;
15235
- }
15236
- var offset1 = 0;
15237
- for(var i1 = 0; i1 < rectangleCount; ++i1){
15238
- var x1 = i1 % segments;
15239
- var y1 = i1 * segmentsReciprocal | 0;
15240
- var a = y1 * count + x1;
15241
- var b = a + 1;
15242
- var c = a + count;
15243
- var d = c + 1;
15244
- indices[offset1++] = b;
15245
- indices[offset1++] = a;
15246
- indices[offset1++] = d;
15247
- indices[offset1++] = a;
15248
- indices[offset1++] = c;
15249
- indices[offset1++] = d;
15250
- }
15251
- if (!isRestoreMode) {
15252
- var bounds = sphereMesh.bounds;
15253
- bounds.min.set(-radius, -radius, -radius);
15254
- bounds.max.set(radius, radius, radius);
15255
- }
15256
- PrimitiveMesh._initialize(sphereMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
15257
- };
15258
- /**
15259
- * @internal
15260
- */ PrimitiveMesh._subdiveCatmullClark = function _subdiveCatmullClark(step, positions, cells) {
15261
- var edges = new Map();
15262
- var faces = new Array();
15263
- positions.set(PrimitiveMesh._sphereSeedPositions);
15264
- cells.set(PrimitiveMesh._sphereSeedCells);
15265
- for(var i = 0; i < step; i++){
15266
- var cellCount = 6 * Math.pow(4, i);
15267
- var positionCount = 4 * cellCount + 2;
15268
- edges.clear();
15269
- faces.length = 0;
15270
- // Get cell face's facePoint
15271
- for(var j = 0; j < cellCount; j++){
15272
- var face = faces[j] = {
15273
- facePoint: new engineMath.Vector3(),
15274
- adjacentEdges: new Array(4)
15275
- };
15276
- // Get cell's edgePoint
15277
- for(var k = 0; k < 4; k++){
15278
- var offset = 3 * cells[4 * j + k];
15279
- face.facePoint.x += 0.25 * positions[offset];
15280
- face.facePoint.y += 0.25 * positions[offset + 1];
15281
- face.facePoint.z += 0.25 * positions[offset + 2];
15282
- }
15283
- // Get cell edges
15284
- for(var k1 = 0; k1 < 4; k1++){
15285
- var vertexIdxA = cells[4 * j + k1];
15286
- var vertexIdxB = cells[4 * j + (k1 + 1) % 4];
15287
- var edgeIdxKey = Math.min(vertexIdxA, vertexIdxB) * positionCount + Math.max(vertexIdxA, vertexIdxB);
15288
- if (!edges.has(edgeIdxKey)) {
15289
- var edge = {
15290
- edgePoint: new engineMath.Vector3(),
15291
- edgePointIndex: undefined
15292
- };
15293
- var offsetA = 3 * vertexIdxA;
15294
- var offsetB = 3 * vertexIdxB;
15295
- 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]));
15296
- edges.set(edgeIdxKey, edge);
15297
- }
15298
- var edge1 = edges.get(edgeIdxKey);
15299
- face.adjacentEdges[k1] = edge1;
15300
- var edgePoint = edge1.edgePoint;
15301
- var facePoint = face.facePoint;
15302
- edgePoint.x += 0.25 * facePoint.x;
15303
- edgePoint.y += 0.25 * facePoint.y;
15304
- edgePoint.z += 0.25 * facePoint.z;
15305
- }
15306
- }
15307
- var prePointCount = cellCount + 2;
15308
- var edgePointOffset = prePointCount + cellCount;
15309
- var pointIdx = 0;
15310
- this._sphereEdgeIdx = 0;
15311
- var preCells = cells.slice(0, 4 * cellCount);
15312
- // Get New positions, which consists of updated positions of existing points, face points and edge points
15313
- for(var j1 = 0; j1 < cellCount; j1++){
15314
- // Add face point to new positions
15315
- var face1 = faces[j1];
15316
- face1.facePoint.copyToArray(positions, 3 * (prePointCount + j1));
15317
- // Get the face point index
15318
- var ic = prePointCount + j1;
15319
- var id = void 0, ib = void 0, temp = void 0;
15320
- // ia -- id -- ia
15321
- // | | |
15322
- // ib -- ic -- ib
15323
- // | | |
15324
- // ia -- id -- ia
15325
- for(var k2 = 0; k2 < 4; k2++){
15326
- // Get the updated existing point index
15327
- var ia = preCells[pointIdx++];
15328
- // ib and id share four edge points in one cell
15329
- switch(k2){
15330
- case 0:
15331
- {
15332
- var edgeB = face1.adjacentEdges[k2 % 4];
15333
- var edgeD = face1.adjacentEdges[(k2 + 3) % 4];
15334
- ib = this._calculateEdgeIndex(positions, edgeB, edgePointOffset);
15335
- id = this._calculateEdgeIndex(positions, edgeD, edgePointOffset);
15336
- temp = id;
15337
- break;
15338
- }
15339
- case 1:
15340
- case 2:
15341
- {
15342
- var edgeB1 = face1.adjacentEdges[k2 % 4];
15343
- id = ib;
15344
- ib = this._calculateEdgeIndex(positions, edgeB1, edgePointOffset);
15345
- break;
15346
- }
15347
- case 3:
15348
- {
15349
- id = ib;
15350
- ib = temp;
15351
- break;
15352
- }
15353
- }
15354
- var idx = 4 * (4 * j1 + k2);
15355
- cells[idx] = ia;
15356
- cells[idx + 1] = ib;
15357
- cells[idx + 2] = ic;
15358
- cells[idx + 3] = id;
15359
- }
15360
- }
15361
- }
17269
+ var data = new PrimitiveMeshBuilder();
17270
+ data.setData(vertices, indices);
17271
+ data.boundsExtent = new engineMath.Vector3(radius, radius, radius);
17272
+ return data;
15362
17273
  };
15363
- /**
15364
- * Duplicate vertices at the poles and adjust their UV coordinates.
15365
- */ PrimitiveMesh._generateAndReplacePoleUV = function _generateAndReplacePoleUV(indices, vertices, idx, poleOffset) {
17274
+ PrimitiveMesh._replacePoleUV = function _replacePoleUV(indices, vertices, idx, poleOffset, poleIndex) {
15366
17275
  var v = vertices[8 * indices[idx] + 7];
15367
17276
  if (v === 0 || v === 1) {
15368
17277
  var offset = 8 * indices[idx];
15369
- var addedOffset = 8 * (poleOffset + this._spherePoleIdx);
17278
+ var addedOffset = 8 * (poleOffset + poleIndex);
15370
17279
  vertices.set(vertices.subarray(offset, offset + 8), addedOffset);
15371
17280
  vertices[addedOffset + 6] = 0.5 * (vertices[offset + 6] + vertices[8 * indices[idx + 1] + 6] + vertices[8 * indices[idx + 2] + 6] - 0.5);
15372
- indices[idx] = poleOffset + this._spherePoleIdx++;
17281
+ indices[idx] = poleOffset + poleIndex++;
15373
17282
  }
17283
+ return poleIndex;
15374
17284
  };
15375
- /**
15376
- * Get edge point index for subdivision surface sphere.
15377
- */ PrimitiveMesh._calculateEdgeIndex = function _calculateEdgeIndex(positions, edge, offset) {
15378
- if (edge.edgePointIndex !== undefined) {
15379
- return edge.edgePointIndex;
15380
- } else {
15381
- edge.edgePoint.copyToArray(positions, 3 * (offset + PrimitiveMesh._sphereEdgeIdx));
15382
- var index = offset + PrimitiveMesh._sphereEdgeIdx++;
15383
- edge.edgePointIndex = index;
15384
- return index;
15385
- }
15386
- };
15387
- /**
15388
- * @internal
15389
- */ PrimitiveMesh._setCuboidData = function _setCuboidData(cuboidMesh, width, height, depth, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15390
- var halfWidth = width / 2;
15391
- var halfHeight = height / 2;
15392
- var halfDepth = depth / 2;
15393
- var vertexFloatCount = 8;
15394
- var vertices = new Float32Array(24 * vertexFloatCount);
15395
- // Up
15396
- vertices[0] = -halfWidth, vertices[1] = halfHeight, vertices[2] = -halfDepth;
15397
- vertices[6] = 0, vertices[7] = 0;
15398
- vertices[8] = halfWidth, vertices[9] = halfHeight, vertices[10] = -halfDepth;
15399
- vertices[14] = 1, vertices[15] = 0;
15400
- vertices[16] = halfWidth, vertices[17] = halfHeight, vertices[18] = halfDepth;
15401
- vertices[22] = 1, vertices[23] = 1;
15402
- vertices[24] = -halfWidth, vertices[25] = halfHeight, vertices[26] = halfDepth;
15403
- vertices[30] = 0, vertices[31] = 1;
15404
- for(var i = 0; i < 4; i++){
15405
- var normalOffset = vertexFloatCount * i + 3;
15406
- vertices[normalOffset++] = 0, vertices[normalOffset++] = 1, vertices[normalOffset++] = 0;
15407
- }
15408
- // Down
15409
- vertices[32] = -halfWidth, vertices[33] = -halfHeight, vertices[34] = -halfDepth;
15410
- vertices[38] = 0, vertices[39] = 1;
15411
- vertices[40] = halfWidth, vertices[41] = -halfHeight, vertices[42] = -halfDepth;
15412
- vertices[46] = 1, vertices[47] = 1;
15413
- vertices[48] = halfWidth, vertices[49] = -halfHeight, vertices[50] = halfDepth;
15414
- vertices[54] = 1, vertices[55] = 0;
15415
- vertices[56] = -halfWidth, vertices[57] = -halfHeight, vertices[58] = halfDepth;
15416
- vertices[62] = 0, vertices[63] = 0;
15417
- for(var i1 = 0; i1 < 4; i1++){
15418
- var normalOffset1 = vertexFloatCount * i1 + 35;
15419
- vertices[normalOffset1++] = 0, vertices[normalOffset1++] = -1, vertices[normalOffset1++] = 0;
15420
- }
15421
- // Left
15422
- vertices[64] = -halfWidth, vertices[65] = halfHeight, vertices[66] = -halfDepth;
15423
- vertices[70] = 0, vertices[71] = 0;
15424
- vertices[72] = -halfWidth, vertices[73] = halfHeight, vertices[74] = halfDepth;
15425
- vertices[78] = 1, vertices[79] = 0;
15426
- vertices[80] = -halfWidth, vertices[81] = -halfHeight, vertices[82] = halfDepth;
15427
- vertices[86] = 1, vertices[87] = 1;
15428
- vertices[88] = -halfWidth, vertices[89] = -halfHeight, vertices[90] = -halfDepth;
15429
- vertices[94] = 0, vertices[95] = 1;
15430
- for(var i2 = 0; i2 < 4; i2++){
15431
- var normalOffset2 = vertexFloatCount * i2 + 67;
15432
- vertices[normalOffset2++] = -1, vertices[normalOffset2++] = 0, vertices[normalOffset2++] = 0;
15433
- }
15434
- // Right
15435
- vertices[96] = halfWidth, vertices[97] = halfHeight, vertices[98] = -halfDepth;
15436
- vertices[102] = 1, vertices[103] = 0;
15437
- vertices[104] = halfWidth, vertices[105] = halfHeight, vertices[106] = halfDepth;
15438
- vertices[110] = 0, vertices[111] = 0;
15439
- vertices[112] = halfWidth, vertices[113] = -halfHeight, vertices[114] = halfDepth;
15440
- vertices[118] = 0, vertices[119] = 1;
15441
- vertices[120] = halfWidth, vertices[121] = -halfHeight, vertices[122] = -halfDepth;
15442
- vertices[126] = 1, vertices[127] = 1;
15443
- for(var i3 = 0; i3 < 4; i3++){
15444
- var normalOffset3 = vertexFloatCount * i3 + 99;
15445
- vertices[normalOffset3++] = 1, vertices[normalOffset3++] = 0, vertices[normalOffset3++] = 0;
15446
- }
15447
- // Front
15448
- vertices[128] = -halfWidth, vertices[129] = halfHeight, vertices[130] = halfDepth;
15449
- vertices[134] = 0, vertices[135] = 0;
15450
- vertices[136] = halfWidth, vertices[137] = halfHeight, vertices[138] = halfDepth;
15451
- vertices[142] = 1, vertices[143] = 0;
15452
- vertices[144] = halfWidth, vertices[145] = -halfHeight, vertices[146] = halfDepth;
15453
- vertices[150] = 1, vertices[151] = 1;
15454
- vertices[152] = -halfWidth, vertices[153] = -halfHeight, vertices[154] = halfDepth;
15455
- vertices[158] = 0, vertices[159] = 1;
15456
- for(var i4 = 0; i4 < 4; i4++){
15457
- var normalOffset4 = vertexFloatCount * i4 + 131;
15458
- vertices[normalOffset4++] = 0, vertices[normalOffset4++] = 0, vertices[normalOffset4++] = 1;
15459
- }
15460
- // Back
15461
- vertices[160] = -halfWidth, vertices[161] = halfHeight, vertices[162] = -halfDepth;
15462
- vertices[166] = 1, vertices[167] = 0;
15463
- vertices[168] = halfWidth, vertices[169] = halfHeight, vertices[170] = -halfDepth;
15464
- vertices[174] = 0, vertices[175] = 0;
15465
- vertices[176] = halfWidth, vertices[177] = -halfHeight, vertices[178] = -halfDepth;
15466
- vertices[182] = 0, vertices[183] = 1;
15467
- vertices[184] = -halfWidth, vertices[185] = -halfHeight, vertices[186] = -halfDepth;
15468
- vertices[190] = 1, vertices[191] = 1;
15469
- for(var i5 = 0; i5 < 4; i5++){
15470
- var normalOffset5 = vertexFloatCount * i5 + 163;
15471
- vertices[normalOffset5++] = 0, vertices[normalOffset5++] = 0, vertices[normalOffset5++] = -1;
15472
- }
15473
- var indices = new Uint16Array(36);
15474
- // prettier-ignore
15475
- // Up
15476
- indices[0] = 0, indices[1] = 2, indices[2] = 1, indices[3] = 2, indices[4] = 0, indices[5] = 3, // Down
15477
- indices[6] = 4, indices[7] = 6, indices[8] = 7, indices[9] = 6, indices[10] = 4, indices[11] = 5, // Left
15478
- indices[12] = 8, indices[13] = 10, indices[14] = 9, indices[15] = 10, indices[16] = 8, indices[17] = 11, // Right
15479
- indices[18] = 12, indices[19] = 14, indices[20] = 15, indices[21] = 14, indices[22] = 12, indices[23] = 13, // Front
15480
- indices[24] = 16, indices[25] = 18, indices[26] = 17, indices[27] = 18, indices[28] = 16, indices[29] = 19, // Back
15481
- indices[30] = 20, indices[31] = 22, indices[32] = 23, indices[33] = 22, indices[34] = 20, indices[35] = 21;
15482
- if (!isRestoreMode) {
15483
- var bounds = cuboidMesh.bounds;
15484
- bounds.min.set(-halfWidth, -halfHeight, -halfDepth);
15485
- bounds.max.set(halfWidth, halfHeight, halfDepth);
15486
- }
15487
- PrimitiveMesh._initialize(cuboidMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
15488
- };
15489
- /**
15490
- * @internal
15491
- */ PrimitiveMesh._setPlaneData = function _setPlaneData(planeMesh, width, height, horizontalSegments, verticalSegments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15492
- horizontalSegments = Math.max(1, Math.floor(horizontalSegments));
15493
- verticalSegments = Math.max(1, Math.floor(verticalSegments));
15494
- var horizontalCount = horizontalSegments + 1;
15495
- var verticalCount = verticalSegments + 1;
15496
- var halfWidth = width / 2;
15497
- var halfHeight = height / 2;
15498
- var gridWidth = width / horizontalSegments;
15499
- var gridHeight = height / verticalSegments;
15500
- var vertexCount = horizontalCount * verticalCount;
15501
- var rectangleCount = verticalSegments * horizontalSegments;
15502
- var indices = PrimitiveMesh._generateIndices(planeMesh.engine, vertexCount, rectangleCount * 6);
15503
- var horizontalCountReciprocal = 1.0 / horizontalCount;
15504
- var horizontalSegmentsReciprocal = 1.0 / horizontalSegments;
15505
- var verticalSegmentsReciprocal = 1.0 / verticalSegments;
15506
- var vertexFloatCount = 8;
15507
- var vertices = new Float32Array(vertexCount * vertexFloatCount);
15508
- for(var i = 0; i < vertexCount; ++i){
15509
- var x = i % horizontalCount;
15510
- var z = i * horizontalCountReciprocal | 0;
15511
- var offset = i * vertexFloatCount;
15512
- // Position
15513
- vertices[offset++] = x * gridWidth - halfWidth;
15514
- vertices[offset++] = 0;
15515
- vertices[offset++] = z * gridHeight - halfHeight;
15516
- // Normal
15517
- vertices[offset++] = 0;
15518
- vertices[offset++] = 1;
15519
- vertices[offset++] = 0;
15520
- // TexCoord
15521
- vertices[offset++] = x * horizontalSegmentsReciprocal;
15522
- vertices[offset++] = z * verticalSegmentsReciprocal;
17285
+ PrimitiveMesh._createMesh = function _createMesh(engine, generate, args, options) {
17286
+ var _options_keepMeshData;
17287
+ var keepMeshData = (_options_keepMeshData = options == null ? void 0 : options.keepMeshData) != null ? _options_keepMeshData : false;
17288
+ for(var i = 0; i < args.length; i++){
17289
+ args[i] = PrimitiveMesh._copy(args[i]);
15523
17290
  }
15524
- var offset1 = 0;
15525
- for(var i1 = 0; i1 < rectangleCount; ++i1){
15526
- var x1 = i1 % horizontalSegments;
15527
- var y = i1 * horizontalSegmentsReciprocal | 0;
15528
- var a = y * horizontalCount + x1;
15529
- var b = a + 1;
15530
- var c = a + horizontalCount;
15531
- var d = c + 1;
15532
- indices[offset1++] = a;
15533
- indices[offset1++] = c;
15534
- indices[offset1++] = b;
15535
- indices[offset1++] = c;
15536
- indices[offset1++] = d;
15537
- indices[offset1++] = b;
15538
- }
15539
- if (!isRestoreMode) {
15540
- var bounds = planeMesh.bounds;
15541
- bounds.min.set(-halfWidth, 0, -halfHeight);
15542
- bounds.max.set(halfWidth, 0, halfHeight);
15543
- }
15544
- PrimitiveMesh._initialize(planeMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
15545
- };
15546
- /**
15547
- * @internal
15548
- */ PrimitiveMesh._setCylinderData = function _setCylinderData(cylinderMesh, radiusTop, radiusBottom, height, radialSegments, heightSegments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15549
- if (radiusTop === void 0) radiusTop = 0.5;
15550
- if (radiusBottom === void 0) radiusBottom = 0.5;
15551
- if (height === void 0) height = 2;
15552
- if (radialSegments === void 0) radialSegments = 20;
15553
- if (heightSegments === void 0) heightSegments = 1;
15554
- radialSegments = Math.floor(radialSegments);
15555
- heightSegments = Math.floor(heightSegments);
15556
- var radialCount = radialSegments + 1;
15557
- var verticalCount = heightSegments + 1;
15558
- var halfHeight = height * 0.5;
15559
- var unitHeight = height / heightSegments;
15560
- var torsoVertexCount = radialCount * verticalCount;
15561
- var torsoRectangleCount = radialSegments * heightSegments;
15562
- var capTriangleCount = radialSegments * 2;
15563
- var totalVertexCount = torsoVertexCount + 2 + capTriangleCount;
15564
- var indices = PrimitiveMesh._generateIndices(cylinderMesh.engine, totalVertexCount, torsoRectangleCount * 6 + capTriangleCount * 3);
15565
- var radialCountReciprocal = 1.0 / radialCount;
15566
- var radialSegmentsReciprocal = 1.0 / radialSegments;
15567
- var heightSegmentsReciprocal = 1.0 / heightSegments;
15568
- var vertexFloatCount = 8;
15569
- var vertices = new Float32Array(totalVertexCount * vertexFloatCount);
15570
- var indicesOffset = 0;
15571
- // Create torso
15572
- var thetaStart = Math.PI;
15573
- var thetaRange = Math.PI * 2;
15574
- var radiusDiff = radiusBottom - radiusTop;
15575
- var slope = radiusDiff / height;
15576
- var radiusSlope = radiusDiff / heightSegments;
15577
- for(var i = 0; i < torsoVertexCount; ++i){
15578
- var x = i % radialCount;
15579
- var y = i * radialCountReciprocal | 0;
15580
- var u = x * radialSegmentsReciprocal;
15581
- var v = y * heightSegmentsReciprocal;
15582
- var theta = thetaStart + u * thetaRange;
15583
- var sinTheta = Math.sin(theta);
15584
- var cosTheta = Math.cos(theta);
15585
- var radius = radiusBottom - y * radiusSlope;
15586
- var posX = radius * sinTheta;
15587
- var posY = y * unitHeight - halfHeight;
15588
- var posZ = radius * cosTheta;
15589
- var offset = i * vertexFloatCount;
15590
- // Position
15591
- vertices[offset++] = posX;
15592
- vertices[offset++] = posY;
15593
- vertices[offset++] = posZ;
15594
- // Normal
15595
- vertices[offset++] = sinTheta;
15596
- vertices[offset++] = slope;
15597
- vertices[offset++] = cosTheta;
15598
- // TexCoord
15599
- vertices[offset++] = u;
15600
- vertices[offset++] = 1 - v;
15601
- }
15602
- for(var i1 = 0; i1 < torsoRectangleCount; ++i1){
15603
- var x1 = i1 % radialSegments;
15604
- var y1 = i1 * radialSegmentsReciprocal | 0;
15605
- var a = y1 * radialCount + x1;
15606
- var b = a + 1;
15607
- var c = a + radialCount;
15608
- var d = c + 1;
15609
- indices[indicesOffset++] = b;
15610
- indices[indicesOffset++] = c;
15611
- indices[indicesOffset++] = a;
15612
- indices[indicesOffset++] = b;
15613
- indices[indicesOffset++] = d;
15614
- indices[indicesOffset++] = c;
15615
- }
15616
- var offset1 = torsoVertexCount * vertexFloatCount;
15617
- // Bottom position
15618
- vertices[offset1++] = 0;
15619
- vertices[offset1++] = -halfHeight;
15620
- vertices[offset1++] = 0;
15621
- // Bottom normal
15622
- vertices[offset1++] = 0;
15623
- vertices[offset1++] = -1;
15624
- vertices[offset1++] = 0;
15625
- // Bottom texCoord
15626
- vertices[offset1++] = 0.5;
15627
- vertices[offset1++] = 0.5;
15628
- // Top position
15629
- vertices[offset1++] = 0;
15630
- vertices[offset1++] = halfHeight;
15631
- vertices[offset1++] = 0;
15632
- // Top normal
15633
- vertices[offset1++] = 0;
15634
- vertices[offset1++] = 1;
15635
- vertices[offset1++] = 0;
15636
- // Top texCoord
15637
- vertices[offset1++] = 0.5;
15638
- vertices[offset1++] = 0.5;
15639
- // Add cap vertices
15640
- offset1 = (torsoVertexCount + 2) * vertexFloatCount;
15641
- var diameterTopReciprocal = 1.0 / (radiusTop * 2);
15642
- var diameterBottomReciprocal = 1.0 / (radiusBottom * 2);
15643
- var positionStride = radialCount * heightSegments;
15644
- for(var i2 = 0; i2 < radialSegments; ++i2){
15645
- var curPosBottomOffset = i2 * vertexFloatCount;
15646
- var curPosX = vertices[curPosBottomOffset];
15647
- var curPosZ = vertices[curPosBottomOffset + 2];
15648
- // Bottom position
15649
- vertices[offset1++] = curPosX;
15650
- vertices[offset1++] = -halfHeight;
15651
- vertices[offset1++] = curPosZ;
15652
- // Bottom normal
15653
- vertices[offset1++] = 0;
15654
- vertices[offset1++] = -1;
15655
- vertices[offset1++] = 0;
15656
- // Bottom texcoord
15657
- vertices[offset1++] = curPosX * diameterBottomReciprocal + 0.5;
15658
- vertices[offset1++] = 0.5 - curPosZ * diameterBottomReciprocal;
15659
- var curPosTopOffset = (i2 + positionStride) * vertexFloatCount;
15660
- curPosX = vertices[curPosTopOffset];
15661
- curPosZ = vertices[curPosTopOffset + 2];
15662
- // Top position
15663
- vertices[offset1++] = curPosX;
15664
- vertices[offset1++] = halfHeight;
15665
- vertices[offset1++] = curPosZ;
15666
- // Top normal
15667
- vertices[offset1++] = 0;
15668
- vertices[offset1++] = 1;
15669
- vertices[offset1++] = 0;
15670
- // Top texcoord
15671
- vertices[offset1++] = curPosX * diameterTopReciprocal + 0.5;
15672
- vertices[offset1++] = 0.5 - curPosZ * diameterTopReciprocal;
15673
- }
15674
- // Add cap indices
15675
- var topCapIndex = torsoVertexCount + 1;
15676
- var bottomIndiceIndex = torsoVertexCount + 2;
15677
- var topIndiceIndex = bottomIndiceIndex + 1;
15678
- for(var i3 = 0; i3 < radialSegments; ++i3){
15679
- var firstStride = i3 * 2;
15680
- var secondStride = i3 === radialSegments - 1 ? 0 : firstStride + 2;
15681
- // Bottom
15682
- indices[indicesOffset++] = torsoVertexCount;
15683
- indices[indicesOffset++] = bottomIndiceIndex + secondStride;
15684
- indices[indicesOffset++] = bottomIndiceIndex + firstStride;
15685
- // Top
15686
- indices[indicesOffset++] = topCapIndex;
15687
- indices[indicesOffset++] = topIndiceIndex + firstStride;
15688
- indices[indicesOffset++] = topIndiceIndex + secondStride;
15689
- }
15690
- if (!isRestoreMode) {
15691
- var bounds = cylinderMesh.bounds;
15692
- var radiusMax = Math.max(radiusTop, radiusBottom);
15693
- bounds.min.set(-radiusMax, -halfHeight, -radiusMax);
15694
- bounds.max.set(radiusMax, halfHeight, radiusMax);
15695
- }
15696
- PrimitiveMesh._initialize(cylinderMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
15697
- };
15698
- /**
15699
- * @internal
15700
- */ PrimitiveMesh._setTorusData = function _setTorusData(torusMesh, radius, tubeRadius, radialSegments, tubularSegments, arc, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15701
- radialSegments = Math.floor(radialSegments);
15702
- tubularSegments = Math.floor(tubularSegments);
15703
- var vertexCount = (radialSegments + 1) * (tubularSegments + 1);
15704
- var rectangleCount = radialSegments * tubularSegments;
15705
- var indices = PrimitiveMesh._generateIndices(torusMesh.engine, vertexCount, rectangleCount * 6);
15706
- var vertexFloatCount = 8;
15707
- var vertices = new Float32Array(vertexCount * vertexFloatCount);
15708
- arc = arc / 180 * Math.PI;
15709
- var offset = 0;
15710
- var normal = PrimitiveMesh._tempVec30;
15711
- for(var i = 0; i <= radialSegments; i++){
15712
- for(var j = 0; j <= tubularSegments; j++){
15713
- var u = j / tubularSegments * arc;
15714
- var v = i / radialSegments * Math.PI * 2;
15715
- var cosV = Math.cos(v);
15716
- var sinV = Math.sin(v);
15717
- var cosU = Math.cos(u);
15718
- var sinU = Math.sin(u);
15719
- // Position
15720
- var positionX = (radius + tubeRadius * cosV) * cosU;
15721
- var positionY = (radius + tubeRadius * cosV) * sinU;
15722
- var positionZ = tubeRadius * sinV;
15723
- vertices[offset++] = positionX;
15724
- vertices[offset++] = positionY;
15725
- vertices[offset++] = positionZ;
15726
- // Normal
15727
- var centerX = radius * cosU;
15728
- var centerY = radius * sinU;
15729
- normal.set(positionX - centerX, positionY - centerY, positionZ).normalize();
15730
- vertices[offset++] = normal.x;
15731
- vertices[offset++] = normal.y;
15732
- vertices[offset++] = normal.z;
15733
- // UV
15734
- vertices[offset++] = j / tubularSegments;
15735
- vertices[offset++] = i / radialSegments;
15736
- }
15737
- }
15738
- offset = 0;
15739
- for(var i1 = 1; i1 <= radialSegments; i1++){
15740
- for(var j1 = 1; j1 <= tubularSegments; j1++){
15741
- var a = (tubularSegments + 1) * i1 + j1 - 1;
15742
- var b = (tubularSegments + 1) * (i1 - 1) + j1 - 1;
15743
- var c = (tubularSegments + 1) * (i1 - 1) + j1;
15744
- var d = (tubularSegments + 1) * i1 + j1;
15745
- indices[offset++] = a;
15746
- indices[offset++] = b;
15747
- indices[offset++] = d;
15748
- indices[offset++] = b;
15749
- indices[offset++] = c;
15750
- indices[offset++] = d;
15751
- }
15752
- }
15753
- if (!isRestoreMode) {
15754
- var bounds = torusMesh.bounds;
15755
- var outerRadius = radius + tubeRadius;
15756
- bounds.min.set(-outerRadius, -outerRadius, -tubeRadius);
15757
- bounds.max.set(outerRadius, outerRadius, tubeRadius);
15758
- }
15759
- PrimitiveMesh._initialize(torusMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
15760
- };
15761
- /**
15762
- * @internal
15763
- */ PrimitiveMesh._setConeData = function _setConeData(coneMesh, radius, height, radialSegments, heightSegments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15764
- radialSegments = Math.floor(radialSegments);
15765
- heightSegments = Math.floor(heightSegments);
15766
- var radialCount = radialSegments + 1;
15767
- var verticalCount = heightSegments + 1;
15768
- var halfHeight = height * 0.5;
15769
- var unitHeight = height / heightSegments;
15770
- var torsoVertexCount = radialCount * verticalCount;
15771
- var torsoRectangleCount = radialSegments * heightSegments;
15772
- var totalVertexCount = torsoVertexCount + 1 + radialSegments;
15773
- var indices = PrimitiveMesh._generateIndices(coneMesh.engine, totalVertexCount, torsoRectangleCount * 6 + radialSegments * 3);
15774
- var radialCountReciprocal = 1.0 / radialCount;
15775
- var radialSegmentsReciprocal = 1.0 / radialSegments;
15776
- var heightSegmentsReciprocal = 1.0 / heightSegments;
15777
- var vertexFloatCount = 8;
15778
- var vertices = new Float32Array(totalVertexCount * 8);
15779
- var indicesOffset = 0;
15780
- // Create torso
15781
- var thetaStart = Math.PI;
15782
- var thetaRange = Math.PI * 2;
15783
- var slope = radius / height;
15784
- for(var i = 0; i < torsoVertexCount; ++i){
15785
- var x = i % radialCount;
15786
- var y = i * radialCountReciprocal | 0;
15787
- var u = x * radialSegmentsReciprocal;
15788
- var v = y * heightSegmentsReciprocal;
15789
- var theta = thetaStart + u * thetaRange;
15790
- var sinTheta = Math.sin(theta);
15791
- var cosTheta = Math.cos(theta);
15792
- var curRadius = radius - v * radius;
15793
- var posX = curRadius * sinTheta;
15794
- var posY = y * unitHeight - halfHeight;
15795
- var posZ = curRadius * cosTheta;
15796
- var offset = i * vertexFloatCount;
15797
- // Position
15798
- vertices[offset++] = posX;
15799
- vertices[offset++] = posY;
15800
- vertices[offset++] = posZ;
15801
- // Normal
15802
- vertices[offset++] = sinTheta;
15803
- vertices[offset++] = slope;
15804
- vertices[offset++] = cosTheta;
15805
- // Texcoord
15806
- vertices[offset++] = u;
15807
- vertices[offset++] = 1 - v;
15808
- }
15809
- for(var i1 = 0; i1 < torsoRectangleCount; ++i1){
15810
- var x1 = i1 % radialSegments;
15811
- var y1 = i1 * radialSegmentsReciprocal | 0;
15812
- var a = y1 * radialCount + x1;
15813
- var b = a + 1;
15814
- var c = a + radialCount;
15815
- var d = c + 1;
15816
- indices[indicesOffset++] = b;
15817
- indices[indicesOffset++] = c;
15818
- indices[indicesOffset++] = a;
15819
- indices[indicesOffset++] = b;
15820
- indices[indicesOffset++] = d;
15821
- indices[indicesOffset++] = c;
15822
- }
15823
- var offset1 = torsoVertexCount * vertexFloatCount;
15824
- // Bottom position
15825
- vertices[offset1++] = 0;
15826
- vertices[offset1++] = -halfHeight;
15827
- vertices[offset1++] = 0;
15828
- // Bottom normal
15829
- vertices[offset1++] = 0;
15830
- vertices[offset1++] = -1;
15831
- vertices[offset1++] = 0;
15832
- // Bottom texcoord
15833
- vertices[offset1++] = 0.5;
15834
- vertices[offset1++] = 0.5;
15835
- // Add bottom cap vertices
15836
- offset1 = (torsoVertexCount + 1) * vertexFloatCount;
15837
- var diameterBottomReciprocal = 1.0 / (radius * 2);
15838
- for(var i2 = 0; i2 < radialSegments; ++i2){
15839
- var curPosX = vertices[i2 * vertexFloatCount];
15840
- var curPosZ = vertices[i2 * vertexFloatCount + 2];
15841
- // Bottom position
15842
- vertices[offset1++] = curPosX;
15843
- vertices[offset1++] = -halfHeight;
15844
- vertices[offset1++] = curPosZ;
15845
- // Bottom normal
15846
- vertices[offset1++] = 0;
15847
- vertices[offset1++] = -1;
15848
- vertices[offset1++] = 0;
15849
- // Bottom texcoord
15850
- vertices[offset1++] = curPosX * diameterBottomReciprocal + 0.5;
15851
- vertices[offset1++] = 0.5 - curPosZ * diameterBottomReciprocal;
15852
- }
15853
- var bottomIndiceIndex = torsoVertexCount + 1;
15854
- for(var i3 = 0; i3 < radialSegments; ++i3){
15855
- var firstStride = i3;
15856
- var secondStride = i3 === radialSegments - 1 ? 0 : firstStride + 1;
15857
- // Bottom
15858
- indices[indicesOffset++] = torsoVertexCount;
15859
- indices[indicesOffset++] = bottomIndiceIndex + secondStride;
15860
- indices[indicesOffset++] = bottomIndiceIndex + firstStride;
15861
- }
15862
- if (!isRestoreMode) {
15863
- var bounds = coneMesh.bounds;
15864
- bounds.min.set(-radius, -halfHeight, -radius);
15865
- bounds.max.set(radius, halfHeight, radius);
15866
- }
15867
- PrimitiveMesh._initialize(coneMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
15868
- };
15869
- /**
15870
- * @internal
15871
- */ PrimitiveMesh._setCapsuleData = function _setCapsuleData(capsuleMesh, radius, height, radialSegments, heightSegments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15872
- radialSegments = Math.max(2, Math.floor(radialSegments));
15873
- heightSegments = Math.floor(heightSegments);
15874
- var radialCount = radialSegments + 1;
15875
- var verticalCount = heightSegments + 1;
15876
- var halfHeight = height * 0.5;
15877
- var unitHeight = height / heightSegments;
15878
- var torsoVertexCount = radialCount * verticalCount;
15879
- var torsoRectangleCount = radialSegments * heightSegments;
15880
- var capVertexCount = radialCount * radialCount;
15881
- var capRectangleCount = radialSegments * radialSegments;
15882
- var totalVertexCount = torsoVertexCount + 2 * capVertexCount;
15883
- var indices = PrimitiveMesh._generateIndices(capsuleMesh.engine, totalVertexCount, (torsoRectangleCount + 2 * capRectangleCount) * 6);
15884
- var radialCountReciprocal = 1.0 / radialCount;
15885
- var radialSegmentsReciprocal = 1.0 / radialSegments;
15886
- var heightSegmentsReciprocal = 1.0 / heightSegments;
15887
- var thetaStart = Math.PI;
15888
- var thetaRange = Math.PI * 2;
15889
- var vertexFloatCount = 8;
15890
- var vertices = new Float32Array(totalVertexCount * vertexFloatCount);
15891
- var indicesOffset = 0;
15892
- // create torso
15893
- for(var i = 0; i < torsoVertexCount; ++i){
15894
- var x = i % radialCount;
15895
- var y = i * radialCountReciprocal | 0;
15896
- var u = x * radialSegmentsReciprocal;
15897
- var v = y * heightSegmentsReciprocal;
15898
- var theta = thetaStart + u * thetaRange;
15899
- var sinTheta = Math.sin(theta);
15900
- var cosTheta = Math.cos(theta);
15901
- var offset = i * vertexFloatCount;
15902
- // position
15903
- vertices[offset++] = radius * sinTheta;
15904
- vertices[offset++] = y * unitHeight - halfHeight;
15905
- vertices[offset++] = radius * cosTheta;
15906
- // Normal
15907
- vertices[offset++] = sinTheta;
15908
- vertices[offset++] = 0;
15909
- vertices[offset++] = cosTheta;
15910
- // Texcoord
15911
- vertices[offset++] = u;
15912
- vertices[offset++] = 1 - v;
15913
- }
15914
- for(var i1 = 0; i1 < torsoRectangleCount; ++i1){
15915
- var x1 = i1 % radialSegments;
15916
- var y1 = i1 * radialSegmentsReciprocal | 0;
15917
- var a = y1 * radialCount + x1;
15918
- var b = a + 1;
15919
- var c = a + radialCount;
15920
- var d = c + 1;
15921
- indices[indicesOffset++] = b;
15922
- indices[indicesOffset++] = c;
15923
- indices[indicesOffset++] = a;
15924
- indices[indicesOffset++] = b;
15925
- indices[indicesOffset++] = d;
15926
- indices[indicesOffset++] = c;
15927
- }
15928
- PrimitiveMesh._createCapsuleCap(radius, height, radialSegments, thetaStart, thetaRange, torsoVertexCount, 1, vertices, indices, indicesOffset);
15929
- PrimitiveMesh._createCapsuleCap(radius, height, radialSegments, thetaStart, -thetaRange, torsoVertexCount + capVertexCount, -1, vertices, indices, indicesOffset + 6 * capRectangleCount);
15930
- if (!isRestoreMode) {
15931
- var bounds = capsuleMesh.bounds;
15932
- bounds.min.set(-radius, -radius - halfHeight, -radius);
15933
- bounds.max.set(radius, radius + halfHeight, radius);
15934
- }
15935
- PrimitiveMesh._initialize(capsuleMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
15936
- };
15937
- PrimitiveMesh._initialize = function _initialize(mesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
15938
- if (isRestoreMode) {
15939
- restoreVertexBuffer.setData(vertices);
15940
- mesh.setIndices(indices);
15941
- mesh.uploadData(noLongerAccessible);
17291
+ var data = generate.apply(void 0, [].concat(args));
17292
+ data.trim();
17293
+ if (data.vertexCount > 65535 && !engine._hardwareRenderer.canIUse(GLCapabilityType.elementIndexUint)) {
17294
+ throw new Error("The vertex count is over limit.");
17295
+ }
17296
+ var mesh = new ModelMesh(engine);
17297
+ var vertices = data.vertices;
17298
+ var indices = data.indices;
17299
+ mesh.setVertexElements([
17300
+ new VertexElement(VertexAttribute.Position, 0, VertexElementFormat.Vector3, 0),
17301
+ new VertexElement(VertexAttribute.Normal, 12, VertexElementFormat.Vector3, 0),
17302
+ new VertexElement(VertexAttribute.UV, 24, VertexElementFormat.Vector2, 0)
17303
+ ]);
17304
+ var vertexBuffer = new Buffer(mesh.engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
17305
+ mesh.setVertexBufferBinding(vertexBuffer, 32, 0);
17306
+ mesh.setIndices(indices);
17307
+ mesh.calculateTangents();
17308
+ PrimitiveMesh._setBounds(mesh, data);
17309
+ mesh.uploadData(!keepMeshData);
17310
+ if (!keepMeshData) {
17311
+ vertexBuffer.markAsUnreadable();
17312
+ }
17313
+ if ((options == null ? void 0 : options.separateMaterialSlots) && data.groups.length) {
17314
+ for(var _iterator = _create_for_of_iterator_helper_loose(data.groups), _step; !(_step = _iterator()).done;){
17315
+ var group = _step.value;
17316
+ mesh.addSubMesh(group.start, group.count);
17317
+ }
15942
17318
  } else {
15943
- var vertexElements = [
15944
- new VertexElement(VertexAttribute.Position, 0, VertexElementFormat.Vector3, 0),
15945
- new VertexElement(VertexAttribute.Normal, 12, VertexElementFormat.Vector3, 0),
15946
- new VertexElement(VertexAttribute.UV, 24, VertexElementFormat.Vector2, 0)
15947
- ];
15948
- mesh.setVertexElements(vertexElements);
15949
- var vertexBuffer = new Buffer(mesh.engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
15950
- mesh.setVertexBufferBinding(vertexBuffer, 32, 0);
15951
- mesh.setIndices(indices);
15952
- mesh.calculateTangents();
15953
- mesh.uploadData(noLongerAccessible);
15954
17319
  mesh.addSubMesh(0, indices.length);
15955
17320
  }
17321
+ engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, generate, args));
17322
+ return mesh;
15956
17323
  };
15957
- PrimitiveMesh._generateIndices = function _generateIndices(engine, vertexCount, indexCount) {
15958
- var indices = null;
15959
- if (vertexCount > 65535) {
15960
- if (engine._hardwareRenderer.canIUse(GLCapabilityType.elementIndexUint)) {
15961
- indices = new Uint32Array(indexCount);
15962
- } else {
15963
- throw Error("The vertex count is over limit.");
17324
+ PrimitiveMesh._polygons = function _polygons(input) {
17325
+ if (!Array.isArray(input)) {
17326
+ return [
17327
+ input
17328
+ ];
17329
+ }
17330
+ if (input.length === 0 || "points" in input[0]) {
17331
+ return input;
17332
+ }
17333
+ return [
17334
+ {
17335
+ points: input
15964
17336
  }
15965
- } else {
15966
- indices = new Uint16Array(indexCount);
15967
- }
15968
- return indices;
15969
- };
15970
- PrimitiveMesh._createCapsuleCap = function _createCapsuleCap(radius, height, radialSegments, thetaStart, thetaRange, offset, posIndex, vertices, indices, indicesOffset) {
15971
- var radialCount = radialSegments + 1;
15972
- var halfHeight = height * 0.5 * posIndex;
15973
- var capVertexCount = radialCount * radialCount;
15974
- var capRectangleCount = radialSegments * radialSegments;
15975
- var radialCountReciprocal = 1.0 / radialCount;
15976
- var radialSegmentsReciprocal = 1.0 / radialSegments;
15977
- var vertexFloatCount = 8;
15978
- for(var i = 0; i < capVertexCount; ++i){
15979
- var x = i % radialCount;
15980
- var y = i * radialCountReciprocal | 0;
15981
- var u = x * radialSegmentsReciprocal;
15982
- var v = y * radialSegmentsReciprocal;
15983
- var theta = thetaStart + u * thetaRange;
15984
- var alpha = v * Math.PI * 0.5;
15985
- var sinAlpha = Math.sin(alpha);
15986
- var posX = radius * Math.sin(theta) * sinAlpha;
15987
- var posY = radius * Math.cos(alpha) * posIndex + halfHeight;
15988
- var posZ = radius * Math.cos(theta) * sinAlpha;
15989
- var index = (i + offset) * vertexFloatCount;
15990
- // Position
15991
- vertices[index++] = posX;
15992
- vertices[index++] = posY;
15993
- vertices[index++] = posZ;
15994
- // Normal
15995
- vertices[index++] = posX;
15996
- vertices[index++] = posY - halfHeight;
15997
- vertices[index++] = posZ;
15998
- // Texcoord
15999
- vertices[index++] = u;
16000
- vertices[index++] = v;
16001
- }
16002
- for(var i1 = 0; i1 < capRectangleCount; ++i1){
16003
- var x1 = i1 % radialSegments;
16004
- var y1 = i1 * radialSegmentsReciprocal | 0;
16005
- var a = y1 * radialCount + x1 + offset;
16006
- var b = a + 1;
16007
- var c = a + radialCount;
16008
- var d = c + 1;
16009
- indices[indicesOffset++] = b;
16010
- indices[indicesOffset++] = a;
16011
- indices[indicesOffset++] = d;
16012
- indices[indicesOffset++] = a;
16013
- indices[indicesOffset++] = c;
16014
- indices[indicesOffset++] = d;
17337
+ ];
17338
+ };
17339
+ PrimitiveMesh._setBounds = function _setBounds(mesh, data) {
17340
+ var extent = data.boundsExtent;
17341
+ if (extent) {
17342
+ mesh.bounds.min.set(-extent.x || 0, -extent.y || 0, -extent.z || 0);
17343
+ mesh.bounds.max.copyFrom(extent);
17344
+ return;
17345
+ }
17346
+ var minX = Infinity, minY = Infinity, minZ = Infinity;
17347
+ var maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
17348
+ for(var i = 0; i < data.vertices.length; i += 8){
17349
+ minX = Math.min(minX, data.vertices[i]);
17350
+ minY = Math.min(minY, data.vertices[i + 1]);
17351
+ minZ = Math.min(minZ, data.vertices[i + 2]);
17352
+ maxX = Math.max(maxX, data.vertices[i]);
17353
+ maxY = Math.max(maxY, data.vertices[i + 1]);
17354
+ maxZ = Math.max(maxZ, data.vertices[i + 2]);
16015
17355
  }
17356
+ if (!data.vertices.length) {
17357
+ minX = minY = minZ = maxX = maxY = maxZ = 0;
17358
+ }
17359
+ mesh.bounds.min.set(minX, minY, minZ);
17360
+ mesh.bounds.max.set(maxX, maxY, maxZ);
17361
+ };
17362
+ PrimitiveMesh._copy = function _copy(value) {
17363
+ if (_instanceof(value, engineMath.Vector2) || _instanceof(value, engineMath.Vector3)) {
17364
+ return value.clone();
17365
+ }
17366
+ if (Array.isArray(value)) {
17367
+ return value.map(PrimitiveMesh._copy);
17368
+ }
17369
+ if (value && (typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
17370
+ var result = {};
17371
+ for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(value)), _step; !(_step = _iterator()).done;){
17372
+ var key = _step.value;
17373
+ result[key] = PrimitiveMesh._copy(value[key]);
17374
+ }
17375
+ return result;
17376
+ }
17377
+ return value;
17378
+ };
17379
+ PrimitiveMesh._createArcSamples = function _createArcSamples(segments, start, arc) {
17380
+ if (start === void 0) start = 0;
17381
+ if (arc === void 0) arc = Math.PI * 2;
17382
+ var samples = new Float64Array((segments + 1) * 2);
17383
+ for(var i = 0; i <= segments; i++){
17384
+ var angle = start + i / segments * arc;
17385
+ samples[i * 2] = Math.cos(angle);
17386
+ samples[i * 2 + 1] = Math.sin(angle);
17387
+ }
17388
+ return samples;
17389
+ };
17390
+ PrimitiveMesh._getSegmentCount = function _getSegmentCount(value, minimum) {
17391
+ if (minimum === void 0) minimum = 1;
17392
+ return Math.max(minimum, Math.floor(value));
17393
+ };
17394
+ PrimitiveMesh._normalizeVector = function _normalizeVector(vector) {
17395
+ var length = Math.hypot(vector.x, vector.y, vector.z);
17396
+ return vector.scale(length > 0 ? 1 / length : 0);
16016
17397
  };
16017
17398
  return PrimitiveMesh;
16018
17399
  }();
16019
- PrimitiveMesh._tempVec30 = new engineMath.Vector3();
16020
17400
  PrimitiveMesh._sphereSeedPositions = new Float32Array([
16021
17401
  -1,
16022
17402
  1,
@@ -16069,8 +17449,364 @@ PrimitiveMesh._sphereSeedCells = new Float32Array([
16069
17449
  2,
16070
17450
  1
16071
17451
  ]);
16072
- PrimitiveMesh._sphereEdgeIdx = 0;
16073
- PrimitiveMesh._spherePoleIdx = 0;
17452
+ PrimitiveMesh._goldenRatio = (1 + Math.sqrt(5)) / 2;
17453
+ PrimitiveMesh._inverseGoldenRatio = 1 / PrimitiveMesh._goldenRatio;
17454
+ PrimitiveMesh._regularPolyhedra = {
17455
+ tetrahedron: [
17456
+ [
17457
+ 1,
17458
+ 1,
17459
+ 1,
17460
+ -1,
17461
+ -1,
17462
+ 1,
17463
+ -1,
17464
+ 1,
17465
+ -1,
17466
+ 1,
17467
+ -1,
17468
+ -1
17469
+ ],
17470
+ [
17471
+ 2,
17472
+ 1,
17473
+ 0,
17474
+ 0,
17475
+ 3,
17476
+ 2,
17477
+ 1,
17478
+ 3,
17479
+ 0,
17480
+ 2,
17481
+ 3,
17482
+ 1
17483
+ ]
17484
+ ],
17485
+ octahedron: [
17486
+ [
17487
+ 1,
17488
+ 0,
17489
+ 0,
17490
+ -1,
17491
+ 0,
17492
+ 0,
17493
+ 0,
17494
+ 1,
17495
+ 0,
17496
+ 0,
17497
+ -1,
17498
+ 0,
17499
+ 0,
17500
+ 0,
17501
+ 1,
17502
+ 0,
17503
+ 0,
17504
+ -1
17505
+ ],
17506
+ [
17507
+ 0,
17508
+ 2,
17509
+ 4,
17510
+ 0,
17511
+ 4,
17512
+ 3,
17513
+ 0,
17514
+ 3,
17515
+ 5,
17516
+ 0,
17517
+ 5,
17518
+ 2,
17519
+ 1,
17520
+ 2,
17521
+ 5,
17522
+ 1,
17523
+ 5,
17524
+ 3,
17525
+ 1,
17526
+ 3,
17527
+ 4,
17528
+ 1,
17529
+ 4,
17530
+ 2
17531
+ ]
17532
+ ],
17533
+ icosahedron: [
17534
+ [
17535
+ -1,
17536
+ PrimitiveMesh._goldenRatio,
17537
+ 0,
17538
+ 1,
17539
+ PrimitiveMesh._goldenRatio,
17540
+ 0,
17541
+ -1,
17542
+ -PrimitiveMesh._goldenRatio,
17543
+ 0,
17544
+ 1,
17545
+ -PrimitiveMesh._goldenRatio,
17546
+ 0,
17547
+ 0,
17548
+ -1,
17549
+ PrimitiveMesh._goldenRatio,
17550
+ 0,
17551
+ 1,
17552
+ PrimitiveMesh._goldenRatio,
17553
+ 0,
17554
+ -1,
17555
+ -PrimitiveMesh._goldenRatio,
17556
+ 0,
17557
+ 1,
17558
+ -PrimitiveMesh._goldenRatio,
17559
+ PrimitiveMesh._goldenRatio,
17560
+ 0,
17561
+ -1,
17562
+ PrimitiveMesh._goldenRatio,
17563
+ 0,
17564
+ 1,
17565
+ -PrimitiveMesh._goldenRatio,
17566
+ 0,
17567
+ -1,
17568
+ -PrimitiveMesh._goldenRatio,
17569
+ 0,
17570
+ 1
17571
+ ],
17572
+ [
17573
+ 0,
17574
+ 11,
17575
+ 5,
17576
+ 0,
17577
+ 5,
17578
+ 1,
17579
+ 0,
17580
+ 1,
17581
+ 7,
17582
+ 0,
17583
+ 7,
17584
+ 10,
17585
+ 0,
17586
+ 10,
17587
+ 11,
17588
+ 1,
17589
+ 5,
17590
+ 9,
17591
+ 5,
17592
+ 11,
17593
+ 4,
17594
+ 11,
17595
+ 10,
17596
+ 2,
17597
+ 10,
17598
+ 7,
17599
+ 6,
17600
+ 7,
17601
+ 1,
17602
+ 8,
17603
+ 3,
17604
+ 9,
17605
+ 4,
17606
+ 3,
17607
+ 4,
17608
+ 2,
17609
+ 3,
17610
+ 2,
17611
+ 6,
17612
+ 3,
17613
+ 6,
17614
+ 8,
17615
+ 3,
17616
+ 8,
17617
+ 9,
17618
+ 4,
17619
+ 9,
17620
+ 5,
17621
+ 2,
17622
+ 4,
17623
+ 11,
17624
+ 6,
17625
+ 2,
17626
+ 10,
17627
+ 8,
17628
+ 6,
17629
+ 7,
17630
+ 9,
17631
+ 8,
17632
+ 1
17633
+ ]
17634
+ ],
17635
+ dodecahedron: [
17636
+ [
17637
+ -1,
17638
+ -1,
17639
+ -1,
17640
+ -1,
17641
+ -1,
17642
+ 1,
17643
+ -1,
17644
+ 1,
17645
+ -1,
17646
+ -1,
17647
+ 1,
17648
+ 1,
17649
+ 1,
17650
+ -1,
17651
+ -1,
17652
+ 1,
17653
+ -1,
17654
+ 1,
17655
+ 1,
17656
+ 1,
17657
+ -1,
17658
+ 1,
17659
+ 1,
17660
+ 1,
17661
+ 0,
17662
+ -PrimitiveMesh._inverseGoldenRatio,
17663
+ -PrimitiveMesh._goldenRatio,
17664
+ 0,
17665
+ -PrimitiveMesh._inverseGoldenRatio,
17666
+ PrimitiveMesh._goldenRatio,
17667
+ 0,
17668
+ PrimitiveMesh._inverseGoldenRatio,
17669
+ -PrimitiveMesh._goldenRatio,
17670
+ 0,
17671
+ PrimitiveMesh._inverseGoldenRatio,
17672
+ PrimitiveMesh._goldenRatio,
17673
+ -PrimitiveMesh._inverseGoldenRatio,
17674
+ -PrimitiveMesh._goldenRatio,
17675
+ 0,
17676
+ -PrimitiveMesh._inverseGoldenRatio,
17677
+ PrimitiveMesh._goldenRatio,
17678
+ 0,
17679
+ PrimitiveMesh._inverseGoldenRatio,
17680
+ -PrimitiveMesh._goldenRatio,
17681
+ 0,
17682
+ PrimitiveMesh._inverseGoldenRatio,
17683
+ PrimitiveMesh._goldenRatio,
17684
+ 0,
17685
+ -PrimitiveMesh._goldenRatio,
17686
+ 0,
17687
+ -PrimitiveMesh._inverseGoldenRatio,
17688
+ PrimitiveMesh._goldenRatio,
17689
+ 0,
17690
+ -PrimitiveMesh._inverseGoldenRatio,
17691
+ -PrimitiveMesh._goldenRatio,
17692
+ 0,
17693
+ PrimitiveMesh._inverseGoldenRatio,
17694
+ PrimitiveMesh._goldenRatio,
17695
+ 0,
17696
+ PrimitiveMesh._inverseGoldenRatio
17697
+ ],
17698
+ [
17699
+ 3,
17700
+ 11,
17701
+ 7,
17702
+ 3,
17703
+ 7,
17704
+ 15,
17705
+ 3,
17706
+ 15,
17707
+ 13,
17708
+ 7,
17709
+ 19,
17710
+ 17,
17711
+ 7,
17712
+ 17,
17713
+ 6,
17714
+ 7,
17715
+ 6,
17716
+ 15,
17717
+ 17,
17718
+ 4,
17719
+ 8,
17720
+ 17,
17721
+ 8,
17722
+ 10,
17723
+ 17,
17724
+ 10,
17725
+ 6,
17726
+ 8,
17727
+ 0,
17728
+ 16,
17729
+ 8,
17730
+ 16,
17731
+ 2,
17732
+ 8,
17733
+ 2,
17734
+ 10,
17735
+ 0,
17736
+ 12,
17737
+ 1,
17738
+ 0,
17739
+ 1,
17740
+ 18,
17741
+ 0,
17742
+ 18,
17743
+ 16,
17744
+ 6,
17745
+ 10,
17746
+ 2,
17747
+ 6,
17748
+ 2,
17749
+ 13,
17750
+ 6,
17751
+ 13,
17752
+ 15,
17753
+ 2,
17754
+ 16,
17755
+ 18,
17756
+ 2,
17757
+ 18,
17758
+ 3,
17759
+ 2,
17760
+ 3,
17761
+ 13,
17762
+ 18,
17763
+ 1,
17764
+ 9,
17765
+ 18,
17766
+ 9,
17767
+ 11,
17768
+ 18,
17769
+ 11,
17770
+ 3,
17771
+ 4,
17772
+ 14,
17773
+ 12,
17774
+ 4,
17775
+ 12,
17776
+ 0,
17777
+ 4,
17778
+ 0,
17779
+ 8,
17780
+ 11,
17781
+ 9,
17782
+ 5,
17783
+ 11,
17784
+ 5,
17785
+ 19,
17786
+ 11,
17787
+ 19,
17788
+ 7,
17789
+ 19,
17790
+ 5,
17791
+ 14,
17792
+ 19,
17793
+ 14,
17794
+ 4,
17795
+ 19,
17796
+ 4,
17797
+ 17,
17798
+ 1,
17799
+ 12,
17800
+ 14,
17801
+ 1,
17802
+ 14,
17803
+ 5,
17804
+ 1,
17805
+ 5,
17806
+ 9
17807
+ ]
17808
+ ]
17809
+ };
16074
17810
 
16075
17811
  /**
16076
17812
  * Skin used for skinned mesh renderer.
@@ -16441,7 +18177,7 @@ __decorate([
16441
18177
  /**
16442
18178
  * @internal
16443
18179
  */ var BasicResources = /*#__PURE__*/ function() {
16444
- function BasicResources(engine) {
18180
+ function BasicResources(engine, shaders) {
16445
18181
  this.engine = engine;
16446
18182
  // prettier-ignore
16447
18183
  var vertices = new Float32Array([
@@ -16473,9 +18209,9 @@ __decorate([
16473
18209
  0,
16474
18210
  2
16475
18211
  ]); // left-top
16476
- var blitMaterial = new Material(engine, Shader.find("Blit/Blit"));
18212
+ var blitMaterial = new Material(engine, shaders.blit);
16477
18213
  blitMaterial._addReferCount(1);
16478
- var blitScreenMaterial = new Material(engine, Shader.find("Blit/BlitScreen"));
18214
+ var blitScreenMaterial = new Material(engine, shaders.blitScreen);
16479
18215
  blitScreenMaterial._addReferCount(1);
16480
18216
  this.blitMaterial = blitMaterial;
16481
18217
  this.blitScreenMaterial = blitScreenMaterial;
@@ -16501,11 +18237,11 @@ __decorate([
16501
18237
  ]);
16502
18238
  this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
16503
18239
  }
16504
- this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("2D/Sprite"));
16505
- this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("2D/Text"));
16506
- this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
16507
- this.meshMagentaMaterial = this._createMagentaMaterial(engine, "Unlit");
16508
- this.particleMagentaMaterial = this._createMagentaMaterial(engine, "Effect/Particle");
18240
+ this.spriteDefaultMaterial = this._create2DMaterial(engine, shaders.sprite);
18241
+ this.textDefaultMaterial = this._create2DMaterial(engine, shaders.text);
18242
+ this.spriteMaskDefaultMaterial = this._create2DMaterial(engine, shaders.spriteMask);
18243
+ this.meshMagentaMaterial = this._createMagentaMaterial(engine, shaders.unlit);
18244
+ this.particleMagentaMaterial = this._createMagentaMaterial(engine, shaders.particle);
16509
18245
  }
16510
18246
  var _proto = BasicResources.prototype;
16511
18247
  /**
@@ -16600,17 +18336,12 @@ __decorate([
16600
18336
  material.isGCIgnored = true;
16601
18337
  return material;
16602
18338
  };
16603
- _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
16604
- var material = new BaseMaterial(engine, Shader.find(shaderName));
18339
+ _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shader) {
18340
+ var material = new BaseMaterial(engine, shader);
16605
18341
  material.isGCIgnored = true;
16606
18342
  material.shaderData.setColor("material_BaseColor", new engineMath.Color(1.0, 0.0, 1.01, 1.0));
16607
18343
  return material;
16608
18344
  };
16609
- _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
16610
- var material = new Material(engine, Shader.find("2D/SpriteMask"));
16611
- material.isGCIgnored = true;
16612
- return material;
16613
- };
16614
18345
  BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
16615
18346
  var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
16616
18347
  var renderStates;
@@ -16769,12 +18500,6 @@ function _construct(Parent, args, Class) {
16769
18500
  return Layer;
16770
18501
  }({});
16771
18502
 
16772
- function _type_of(obj) {
16773
- "@swc/helpers - typeof";
16774
-
16775
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
16776
- }
16777
-
16778
18503
  /**
16779
18504
  * @internal
16780
18505
  */ var CloneUtil = /*#__PURE__*/ function() {
@@ -23958,10 +25683,10 @@ var PostProcessUberPass = /*#__PURE__*/ function(PostProcessPass) {
23958
25683
  _this = PostProcessPass.call(this, engine) || this, _this._mipDownRT = [], _this._mipUpRT = [];
23959
25684
  _this.event = PostProcessPassEvent.AfterUber - 1;
23960
25685
  // Uber Material
23961
- var uberMaterial = new Material(engine, Shader.find(PostProcessUberPass.UBER_SHADER_NAME));
25686
+ var uberMaterial = new Material(engine, Engine._builtinShaders.uber);
23962
25687
  _this._uberMaterial = uberMaterial;
23963
25688
  // Bloom Material
23964
- var bloomMaterial = new Material(engine, Shader.find(BloomEffect.SHADER_NAME));
25689
+ var bloomMaterial = new Material(engine, Engine._builtinShaders.bloom);
23965
25690
  _this._bloomMaterial = bloomMaterial;
23966
25691
  // ShaderData initialization
23967
25692
  var bloomShaderData = bloomMaterial.shaderData;
@@ -24336,7 +26061,7 @@ Sky._projectionMatrix = new engineMath.Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, Sky.
24336
26061
  this._solidColor = new engineMath.Color(0.05087608817155679, 0.05087608817155679, 0.05087608817155679, 1.0);
24337
26062
  this._texture = null;
24338
26063
  this._initMesh(_engine);
24339
- this._initMaterial(_engine);
26064
+ this._initMaterial(_engine, Engine._builtinShaders.backgroundTexture);
24340
26065
  }
24341
26066
  var _proto = Background.prototype;
24342
26067
  /**
@@ -24401,8 +26126,8 @@ Sky._projectionMatrix = new engineMath.Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, Sky.
24401
26126
  }(ContentRestorer))());
24402
26127
  this._mesh._addReferCount(1);
24403
26128
  };
24404
- _proto._initMaterial = function _initMaterial(engine) {
24405
- var material = this._material = new Material(engine, Shader.find("Sky/BackgroundTexture"));
26129
+ _proto._initMaterial = function _initMaterial(engine, shader) {
26130
+ var material = this._material = new Material(engine, shader);
24406
26131
  material._addReferCount(1);
24407
26132
  };
24408
26133
  _proto._createPlane = function _createPlane(engine) {
@@ -25328,10 +27053,10 @@ exports.Camera = __decorate([
25328
27053
  * Scalable Ambient Obscurance render pass.
25329
27054
  */ var ScalableAmbientObscurancePass = /*#__PURE__*/ function(PipelinePass) {
25330
27055
  _inherits(ScalableAmbientObscurancePass, PipelinePass);
25331
- function ScalableAmbientObscurancePass(engine) {
27056
+ function ScalableAmbientObscurancePass(engine, shader) {
25332
27057
  var _this;
25333
27058
  _this = PipelinePass.call(this, engine) || this, _this._invProjScaleXY = new engineMath.Vector2(), _this._offsetX = new engineMath.Vector4(), _this._offsetY = new engineMath.Vector4();
25334
- var material = new Material(engine, Shader.find(ScalableAmbientObscurancePass.SHADER_NAME));
27059
+ var material = new Material(engine, shader);
25335
27060
  material._addReferCount(1);
25336
27061
  _this._material = material;
25337
27062
  _this.isSupported = _this.engine._hardwareRenderer.capability.isFragmentHighPrecision;
@@ -25454,7 +27179,6 @@ exports.Camera = __decorate([
25454
27179
  };
25455
27180
  return ScalableAmbientObscurancePass;
25456
27181
  }(PipelinePass);
25457
- ScalableAmbientObscurancePass.SHADER_NAME = "Lighting/ScalableAmbientOcclusion";
25458
27182
  ScalableAmbientObscurancePass._invRadiusSquaredProp = ShaderProperty.getByName("material_invRadiusSquared");
25459
27183
  ScalableAmbientObscurancePass._intensityProp = ShaderProperty.getByName("material_intensity");
25460
27184
  ScalableAmbientObscurancePass._projectionScaleRadiusProp = ShaderProperty.getByName("material_projectionScaleRadius");
@@ -25800,15 +27524,15 @@ PostProcessManager._tempVector3 = new engineMath.Vector3();
25800
27524
  * Processing sRGB Conversion and FXAA.
25801
27525
  */ var FinalPass = /*#__PURE__*/ function(PipelinePass) {
25802
27526
  _inherits(FinalPass, PipelinePass);
25803
- function FinalPass(engine) {
27527
+ function FinalPass(engine, sRGBShader, antiAliasingShader) {
25804
27528
  var _this;
25805
27529
  _this = PipelinePass.call(this, engine) || this;
25806
27530
  // SRGB Material
25807
- var sRGBmaterial = new Material(engine, Shader.find("PostProcess/FinalSRGB"));
27531
+ var sRGBmaterial = new Material(engine, sRGBShader);
25808
27532
  sRGBmaterial._addReferCount(1);
25809
27533
  _this._sRGBmaterial = sRGBmaterial;
25810
27534
  // FXAA Material
25811
- var antiAliasingMaterial = new Material(engine, Shader.find("PostProcess/FinalAntiAliasing"));
27535
+ var antiAliasingMaterial = new Material(engine, antiAliasingShader);
25812
27536
  antiAliasingMaterial._addReferCount(1);
25813
27537
  _this._antiAliasingMaterial = antiAliasingMaterial;
25814
27538
  return _this;
@@ -26889,12 +28613,13 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
26889
28613
  this._shouldCopyBackgroundColor = false;
26890
28614
  this._camera = camera;
26891
28615
  var engine = camera.engine;
28616
+ var shaders = Engine._builtinShaders;
26892
28617
  this._cullingResults = new CullingResults();
26893
28618
  this._cascadedShadowCasterPass = new CascadedShadowCasterPass(camera);
26894
28619
  this._depthOnlyPass = new DepthOnlyPass(engine);
26895
- this._saoPass = new ScalableAmbientObscurancePass(engine);
28620
+ this._saoPass = new ScalableAmbientObscurancePass(engine, shaders.scalableAmbientOcclusion);
26896
28621
  this._opaqueTexturePass = new OpaqueTexturePass(engine);
26897
- this._finalPass = new FinalPass(engine);
28622
+ this._finalPass = new FinalPass(engine, shaders.finalSRGB, shaders.finalAntiAliasing);
26898
28623
  }
26899
28624
  var _proto = BasicRenderPipeline.prototype;
26900
28625
  /**
@@ -27378,7 +29103,7 @@ var OverlayCamera = function OverlayCamera() {
27378
29103
  if (!hardwareRenderer.canIUse(GLCapabilityType.sRGB)) {
27379
29104
  _this._macroCollection.enable(Engine._noSRGBSupportMacro);
27380
29105
  }
27381
- _this._basicResources = new BasicResources(_this);
29106
+ _this._basicResources = new BasicResources(_this, Engine._builtinShaders);
27382
29107
  _this._particleBufferUtils = new ParticleBufferUtils(_this);
27383
29108
  var uberPass = new PostProcessUberPass(_this);
27384
29109
  _this.addPostProcessPass(uberPass);
@@ -34056,7 +35781,7 @@ function _assert_this_initialized(self) {
34056
35781
  _inherits(SkyBoxMaterial, Material);
34057
35782
  function SkyBoxMaterial(engine) {
34058
35783
  var _this;
34059
- _this = Material.call(this, engine, Shader.find("Sky/Skybox")) || this, _this._tintColor = new engineMath.Color(1, 1, 1, 1);
35784
+ _this = Material.call(this, engine, Engine._builtinShaders.skybox) || this, _this._tintColor = new engineMath.Color(1, 1, 1, 1);
34060
35785
  _this.shaderData.setFloat(SkyBoxMaterial._rotationProp, 0);
34061
35786
  _this.shaderData.setFloat(SkyBoxMaterial._exposureProp, 1);
34062
35787
  _this.shaderData.setColor(SkyBoxMaterial._tintColorProp, _this._tintColor);
@@ -34137,7 +35862,7 @@ SkyBoxMaterial._exposureProp = ShaderProperty.getByName("material_Exposure");
34137
35862
  _inherits(SkyProceduralMaterial, Material);
34138
35863
  function SkyProceduralMaterial(engine) {
34139
35864
  var _this;
34140
- _this = Material.call(this, engine, Shader.find("Sky/SkyProcedural")) || this;
35865
+ _this = Material.call(this, engine, Engine._builtinShaders.skyProcedural) || this;
34141
35866
  _this.sunMode = 2;
34142
35867
  _this.sunSize = 0.04;
34143
35868
  _this.sunSizeConvergence = 5;
@@ -35306,14 +37031,13 @@ __decorate([
35306
37031
  return TransformFeedback;
35307
37032
  }(GraphicsResource);
35308
37033
 
35309
- var FEEDBACK_SHADER_NAME$1 = "Effect/ParticleFeedback";
35310
37034
  var GATHER_PASS_NAME = "SubEmitterTrajectoryGather";
35311
37035
  /**
35312
37036
  * Maintains parent trajectory state aligned with sub-emitted particle slots.
35313
37037
  * @internal
35314
37038
  */ var ParticleSubEmitterSpawnState = /*#__PURE__*/ function() {
35315
- function ParticleSubEmitterSpawnState(engine, particleCapacity, needsRenderBinding) {
35316
- var _Shader_find_subShaders_, _Shader_find;
37039
+ function ParticleSubEmitterSpawnState(engine, shader, particleCapacity, needsRenderBinding) {
37040
+ var _shader_subShaders_;
35317
37041
  this._subPrimitive = new SubPrimitive(0, 0, MeshTopology.Points);
35318
37042
  this._renderBinding = null;
35319
37043
  this._pendingParentTrajectoryBinding = null;
@@ -35322,11 +37046,11 @@ var GATHER_PASS_NAME = "SubEmitterTrajectoryGather";
35322
37046
  this._pendingChildrenPerParent = 0;
35323
37047
  this._pendingParentCount = 0;
35324
37048
  this._activeGatherProgram = null;
35325
- var gatherPass = (_Shader_find = Shader.find(FEEDBACK_SHADER_NAME$1)) == null ? void 0 : (_Shader_find_subShaders_ = _Shader_find.subShaders[0]) == null ? void 0 : _Shader_find_subShaders_.passes.find(function(pass) {
37049
+ var gatherPass = !shader.destroyed && ((_shader_subShaders_ = shader.subShaders[0]) == null ? void 0 : _shader_subShaders_.passes.find(function(pass) {
35326
37050
  return pass.name === GATHER_PASS_NAME;
35327
- });
37051
+ }));
35328
37052
  if (!gatherPass) {
35329
- throw new Error(GATHER_PASS_NAME + " pass is not registered in " + FEEDBACK_SHADER_NAME$1 + ".");
37053
+ throw new Error(GATHER_PASS_NAME + " pass is not available in " + shader.name + ".");
35330
37054
  }
35331
37055
  this._gatherPass = gatherPass;
35332
37056
  var primitive = this._primitive = new Primitive(engine);
@@ -35661,25 +37385,19 @@ ParticleSubEmitterSpawnState._gatherMacros = new ShaderMacroCollection();
35661
37385
  return TransformFeedbackSimulator;
35662
37386
  }();
35663
37387
 
35664
- var FEEDBACK_SHADER_NAME = "Effect/ParticleFeedback";
35665
37388
  var FEEDBACK_PASS_NAME = "TransformFeedback";
35666
37389
  /**
35667
37390
  * @internal
35668
37391
  * Particle-specific Transform Feedback simulation.
35669
37392
  */ var ParticleTransformFeedbackSimulator = /*#__PURE__*/ function() {
35670
- function ParticleTransformFeedbackSimulator(engine, trajectoryEnabled, particleCount) {
35671
- var _feedbackShader_subShaders_;
37393
+ function ParticleTransformFeedbackSimulator(engine, shader, trajectoryEnabled, particleCount) {
37394
+ var _shader_subShaders_;
35672
37395
  this.trajectoryEnabled = trajectoryEnabled;
35673
- // The engine flavor owns shader registration; engine-core resolves the registered pass when needed
35674
- var feedbackShader = Shader.find(FEEDBACK_SHADER_NAME);
35675
- if (!feedbackShader) {
35676
- throw new Error("" + FEEDBACK_SHADER_NAME + ' shader is not registered. Import "@galacean/engine" before constructing the engine, ' + "or register the shader manually if you build a custom engine flavor.");
35677
- }
35678
- var feedbackPass = (_feedbackShader_subShaders_ = feedbackShader.subShaders[0]) == null ? void 0 : _feedbackShader_subShaders_.passes.find(function(pass) {
37396
+ var feedbackPass = !shader.destroyed && ((_shader_subShaders_ = shader.subShaders[0]) == null ? void 0 : _shader_subShaders_.passes.find(function(pass) {
35679
37397
  return pass.name === FEEDBACK_PASS_NAME;
35680
- });
37398
+ }));
35681
37399
  if (!feedbackPass) {
35682
- throw new Error(FEEDBACK_PASS_NAME + " pass is not registered in " + FEEDBACK_SHADER_NAME + ".");
37400
+ throw new Error(FEEDBACK_PASS_NAME + " pass is not available in " + shader.name + ".");
35683
37401
  }
35684
37402
  var vertexStride;
35685
37403
  var feedbackVaryings;
@@ -40407,7 +42125,8 @@ __decorate([
40407
42125
  * @internal
40408
42126
  */ _proto._setTransformFeedback = function _setTransformFeedback() {
40409
42127
  var _this__feedbackSimulator, _this__feedbackSimulator1;
40410
- var isWebGL2 = this._renderer.engine._hardwareRenderer.isWebGL2;
42128
+ var engine = this._renderer.engine;
42129
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
40411
42130
  var useTrajectory = isWebGL2 && (this.subEmitters._hasSubEmitterOfType(ParticleSubEmitterType.Death, false) || this.subEmitters._hasSubEmitterOfType(ParticleSubEmitterType.Birth, false));
40412
42131
  var useFeedback = isWebGL2 && (useTrajectory || this.limitVelocityOverLifetime.enabled || this.noise.enabled || this.inheritVelocity._needTransformFeedback() || this.velocityOverLifetime._needTransformFeedback());
40413
42132
  var _this__feedbackSimulator_trajectoryEnabled;
@@ -40417,7 +42136,7 @@ __decorate([
40417
42136
  }
40418
42137
  this._clearActiveParticles();
40419
42138
  (_this__feedbackSimulator1 = this._feedbackSimulator) == null ? void 0 : _this__feedbackSimulator1.destroy();
40420
- this._feedbackSimulator = useFeedback ? new ParticleTransformFeedbackSimulator(this._renderer.engine, useTrajectory, this._currentParticleCount) : null;
42139
+ this._feedbackSimulator = useFeedback ? new ParticleTransformFeedbackSimulator(engine, Engine._builtinShaders.particleFeedback, useTrajectory, this._currentParticleCount) : null;
40421
42140
  if (useFeedback) {
40422
42141
  this._renderer.shaderData.enableMacro(ParticleGenerator._transformFeedbackMacro);
40423
42142
  // Feedback buffer swaps every frame; VAO caching would bake stale buffer handles.
@@ -40934,7 +42653,8 @@ __decorate([
40934
42653
  if (this._subEmitterSpawnState) {
40935
42654
  return;
40936
42655
  }
40937
- this._subEmitterSpawnState = new ParticleSubEmitterSpawnState(this._renderer.engine, this._currentParticleCount, !this._feedbackSimulator);
42656
+ var engine = this._renderer.engine;
42657
+ this._subEmitterSpawnState = new ParticleSubEmitterSpawnState(engine, Engine._builtinShaders.particleFeedback, this._currentParticleCount, !this._feedbackSimulator);
40938
42658
  this._renderer.shaderData.enableMacro(ParticleGenerator._hasSubEmitterSpawnedParticlesMacro);
40939
42659
  this._reorganizeGeometryBuffers();
40940
42660
  };
@@ -41265,7 +42985,7 @@ __decorate([
41265
42985
  */ var ParticleMaterial = /*#__PURE__*/ function(EffectMaterial) {
41266
42986
  _inherits(ParticleMaterial, EffectMaterial);
41267
42987
  function ParticleMaterial(engine, shader) {
41268
- if (shader === void 0) shader = Shader.find("Effect/Particle");
42988
+ if (shader === void 0) shader = Engine._builtinShaders.particle;
41269
42989
  return EffectMaterial.call(this, engine, shader) || this;
41270
42990
  }
41271
42991
  var _proto = ParticleMaterial.prototype;
@@ -42636,7 +44356,7 @@ __decorate([
42636
44356
  */ var TrailMaterial = /*#__PURE__*/ function(EffectMaterial) {
42637
44357
  _inherits(TrailMaterial, EffectMaterial);
42638
44358
  function TrailMaterial(engine) {
42639
- return EffectMaterial.call(this, engine, Shader.find("Effect/Trail")) || this;
44359
+ return EffectMaterial.call(this, engine, Engine._builtinShaders.trail) || this;
42640
44360
  }
42641
44361
  var _proto = TrailMaterial.prototype;
42642
44362
  /**
@@ -43074,7 +44794,7 @@ AudioManager._recovering = false;
43074
44794
  if (!gainNode) {
43075
44795
  this._gainNode = gainNode = AudioManager.getContext().createGain();
43076
44796
  gainNode.connect(AudioManager.getGainNode());
43077
- gainNode.gain.setValueAtTime(this._volume, AudioManager.getContext().currentTime);
44797
+ gainNode.gain.value = this._volume;
43078
44798
  }
43079
44799
  return gainNode;
43080
44800
  };
@@ -43142,11 +44862,12 @@ AudioManager._recovering = false;
43142
44862
  return this._volume;
43143
44863
  },
43144
44864
  set: function set(value) {
43145
- var // No node yet -> _ensureGainNode() applies _volume on first play
43146
- _this__gainNode;
43147
44865
  value = Math.min(Math.max(0, value), 1.0);
43148
44866
  this._volume = value;
43149
- (_this__gainNode = this._gainNode) == null ? void 0 : _this__gainNode.gain.setValueAtTime(value, AudioManager.getContext().currentTime);
44867
+ // No node yet -> _ensureGainNode() applies _volume on first play
44868
+ if (this._gainNode) {
44869
+ this._gainNode.gain.value = value;
44870
+ }
43150
44871
  }
43151
44872
  },
43152
44873
  {
@@ -43558,6 +45279,7 @@ exports.PostProcessPassEvent = PostProcessPassEvent;
43558
45279
  exports.PostProcessUberPass = PostProcessUberPass;
43559
45280
  exports.Primitive = Primitive;
43560
45281
  exports.PrimitiveMesh = PrimitiveMesh;
45282
+ exports.PrimitiveMeshCapMode = PrimitiveMeshCapMode;
43561
45283
  exports.Probe = Probe;
43562
45284
  exports.ReferResource = ReferResource;
43563
45285
  exports.RefractionMode = RefractionMode;