@galacean/engine-core 2.0.0-alpha.55 → 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 +3007 -1280
- package/dist/main.js.map +1 -1
- package/dist/module.js +3007 -1281
- package/dist/module.js.map +1 -1
- package/package.json +3 -3
- package/types/BasicResources.d.ts +2 -2
- package/types/Engine.d.ts +3 -0
- package/types/lighting/ambientOcclusion/ScalableAmbientObscurancePass.d.ts +2 -2
- package/types/material/Material.d.ts +1 -0
- package/types/mesh/MeshTangentUtils.d.ts +9 -0
- package/types/mesh/ModelMesh.d.ts +5 -8
- package/types/mesh/PrimitiveMesh.d.ts +229 -101
- package/types/mesh/PrimitiveMeshOptions.d.ts +415 -0
- package/types/mesh/enums/PrimitiveMeshCapMode.d.ts +21 -0
- package/types/mesh/index.d.ts +2 -0
- package/types/mesh/primitive/MeshPathUtils.d.ts +13 -0
- package/types/mesh/primitive/PolygonUtils.d.ts +44 -0
- package/types/mesh/primitive/PrimitiveMeshBuilder.d.ts +25 -0
- package/types/mesh/primitive/PrimitiveMeshRestorer.d.ts +15 -0
- package/types/mesh/primitive/SubdivisionUtils.d.ts +9 -0
- package/types/particle/ParticleSubEmitterSpawnState.d.ts +2 -1
- package/types/particle/ParticleTransformFeedbackSimulator.d.ts +2 -6
- package/types/postProcess/FinalPass.d.ts +2 -1
- package/types/shader/BuiltinShaders.d.ts +27 -0
- package/types/shader/Shader.d.ts +0 -2
- package/types/shader/ShaderPass.d.ts +3 -1
- package/types/shader/index.d.ts +1 -0
- package/types/mesh/PrimitiveMeshRestorer.d.ts +0 -108
package/dist/main.js
CHANGED
|
@@ -7166,10 +7166,8 @@ ShaderBlockProperty._nameMap = Object.create(null);
|
|
|
7166
7166
|
mrtIndexSet.forEach(function(index) {
|
|
7167
7167
|
declaration += "layout(location=" + index + ") out vec4 fragOutColor" + index + ";\n";
|
|
7168
7168
|
});
|
|
7169
|
-
declaration += "void main(";
|
|
7170
7169
|
shader = shader.replace(/\bgl_FragData\[(.+?)\]/g, "fragOutColor$1");
|
|
7171
|
-
|
|
7172
|
-
return shader;
|
|
7170
|
+
return declaration + shader;
|
|
7173
7171
|
};
|
|
7174
7172
|
return ShaderFactory;
|
|
7175
7173
|
}();
|
|
@@ -9019,7 +9017,7 @@ var precisionStr = "\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision hig
|
|
|
9019
9017
|
* Shader pass containing vertex and fragment source.
|
|
9020
9018
|
*/ var ShaderPass = /*#__PURE__*/ function(ShaderPart) {
|
|
9021
9019
|
_inherits(ShaderPass, ShaderPart);
|
|
9022
|
-
function ShaderPass(name, vertexShaderInstructions, fragmentShaderInstructions, platformTarget, tags) {
|
|
9020
|
+
function ShaderPass(name, vertexShaderInstructions, fragmentShaderInstructions, platformTarget, tags, vertexOutputNames) {
|
|
9023
9021
|
var _this;
|
|
9024
9022
|
_this = ShaderPart.call(this) || this, /** @internal */ _this._shaderPassId = 0, /** @internal Pass-level render state — always present, populated from ShaderLab declarations. */ _this._renderState = new RenderState(), /** @internal */ _this._renderStateDataMap = {}, /** @internal */ _this._shaderProgramMaps = [];
|
|
9025
9023
|
_this._shaderPassId = ShaderPass._shaderPassCounter++;
|
|
@@ -9027,6 +9025,7 @@ var precisionStr = "\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision hig
|
|
|
9027
9025
|
_this._vertexShaderInstructions = vertexShaderInstructions;
|
|
9028
9026
|
_this._fragmentShaderInstructions = fragmentShaderInstructions;
|
|
9029
9027
|
_this._platformTarget = platformTarget;
|
|
9028
|
+
_this._vertexOutputNames = vertexOutputNames;
|
|
9030
9029
|
var mergedTags = _extends({
|
|
9031
9030
|
pipelineStage: PipelineStage.Forward
|
|
9032
9031
|
}, tags);
|
|
@@ -9062,6 +9061,12 @@ var precisionStr = "\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision hig
|
|
|
9062
9061
|
/**
|
|
9063
9062
|
* @internal
|
|
9064
9063
|
*/ _proto._compileShaderProgram = function _compileShaderProgram(engine, macroCollection, feedbackVaryings) {
|
|
9064
|
+
var names = this._vertexOutputNames;
|
|
9065
|
+
if (names && (feedbackVaryings == null ? void 0 : feedbackVaryings.length)) {
|
|
9066
|
+
feedbackVaryings = feedbackVaryings.map(function(name) {
|
|
9067
|
+
return Object.prototype.hasOwnProperty.call(names, name) ? names[name] : name;
|
|
9068
|
+
});
|
|
9069
|
+
}
|
|
9065
9070
|
var isGPUInstance = macroCollection.isEnable(InstanceBuffer.gpuInstanceMacro);
|
|
9066
9071
|
var _this__compileShaderSource = this._compileShaderSource(engine, macroCollection, isGPUInstance), vertexSource = _this__compileShaderSource.vertexSource, fragmentSource = _this__compileShaderSource.fragmentSource, instanceLayout = _this__compileShaderSource.instanceLayout;
|
|
9067
9072
|
var program = new ShaderProgram(engine, vertexSource, fragmentSource, feedbackVaryings);
|
|
@@ -9262,7 +9267,7 @@ ShaderPass._macroMap = new Map();
|
|
|
9262
9267
|
if (!shaderPassSource) {
|
|
9263
9268
|
throw 'Shader pass "' + parsedSource.name + "." + subShaderSource.name + "." + passSource.name + '" parse failed, please check the shader source code.';
|
|
9264
9269
|
}
|
|
9265
|
-
var shaderPass = new ShaderPass(passSource.name, shaderPassSource.vertexShaderInstructions, shaderPassSource.fragmentShaderInstructions, platformTarget, passSource.tags);
|
|
9270
|
+
var shaderPass = new ShaderPass(passSource.name, shaderPassSource.vertexShaderInstructions, shaderPassSource.fragmentShaderInstructions, platformTarget, passSource.tags, shaderPassSource.vertexOutputNames);
|
|
9266
9271
|
Shader._applyRenderStates(shaderPass, passSource.renderStates.constantMap, passSource.renderStates.variableMap, false);
|
|
9267
9272
|
return shaderPass;
|
|
9268
9273
|
});
|
|
@@ -9280,8 +9285,6 @@ ShaderPass._macroMap = new Map();
|
|
|
9280
9285
|
return shaders == null ? void 0 : shaders[shaders.length - 1];
|
|
9281
9286
|
};
|
|
9282
9287
|
/**
|
|
9283
|
-
* Create a shader from precompiled instructions.
|
|
9284
|
-
* @param data - Precompiled shader data
|
|
9285
9288
|
* @internal
|
|
9286
9289
|
*/ Shader._createFromPrecompiled = function _createFromPrecompiled(data) {
|
|
9287
9290
|
var subShaderList = data.subShaders.map(function(subData) {
|
|
@@ -9289,7 +9292,7 @@ ShaderPass._macroMap = new Map();
|
|
|
9289
9292
|
if (passData.isUsePass) {
|
|
9290
9293
|
return Shader._resolveUsePass(passData.name);
|
|
9291
9294
|
}
|
|
9292
|
-
var shaderPass = new ShaderPass(passData.name, passData.vertexShaderInstructions, passData.fragmentShaderInstructions, data.platformTarget, passData.tags);
|
|
9295
|
+
var shaderPass = new ShaderPass(passData.name, passData.vertexShaderInstructions, passData.fragmentShaderInstructions, data.platformTarget, passData.tags, passData.vertexOutputNames);
|
|
9293
9296
|
Shader._applyRenderStates(shaderPass, passData.renderStates.constantMap, passData.renderStates.variableMap, true);
|
|
9294
9297
|
return shaderPass;
|
|
9295
9298
|
});
|
|
@@ -11151,6 +11154,9 @@ var TextChunk = function TextChunk() {
|
|
|
11151
11154
|
_inherits(Material, ReferResource);
|
|
11152
11155
|
function Material(engine, shader) {
|
|
11153
11156
|
var _this;
|
|
11157
|
+
if (shader.destroyed) {
|
|
11158
|
+
throw new Error("Cannot create a material with a destroyed shader.");
|
|
11159
|
+
}
|
|
11154
11160
|
_this = ReferResource.call(this, engine) || this, _this._shaderData = new ShaderData(ShaderDataGroup.Material);
|
|
11155
11161
|
_this.shader = shader;
|
|
11156
11162
|
_this.name = shader.name;
|
|
@@ -11441,7 +11447,7 @@ BaseMaterial._rasterStateCullModeProp = ShaderProperty.getByName("rasterStateCul
|
|
|
11441
11447
|
_inherits(BlinnPhongMaterial, BaseMaterial);
|
|
11442
11448
|
function BlinnPhongMaterial(engine) {
|
|
11443
11449
|
var _this;
|
|
11444
|
-
_this = BaseMaterial.call(this, engine,
|
|
11450
|
+
_this = BaseMaterial.call(this, engine, Engine._builtinShaders.blinnPhong) || this;
|
|
11445
11451
|
var shaderData = _this.shaderData;
|
|
11446
11452
|
shaderData.enableMacro("MATERIAL_NEED_WORLD_POS");
|
|
11447
11453
|
shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
|
|
@@ -11637,7 +11643,7 @@ BlinnPhongMaterial._specularTextureProp = ShaderProperty.getByName("material_Spe
|
|
|
11637
11643
|
_inherits(PBRMaterial, BaseMaterial1);
|
|
11638
11644
|
function PBRMaterial(engine) {
|
|
11639
11645
|
var _this;
|
|
11640
|
-
_this = BaseMaterial1.call(this, engine,
|
|
11646
|
+
_this = BaseMaterial1.call(this, engine, Engine._builtinShaders.pbr) || this, _this._anisotropyRotation = 0, _this._iridescenceRange = new engineMath.Vector2(100, 400), _this._sheenEnabled = false;
|
|
11641
11647
|
var shaderData = _this.shaderData;
|
|
11642
11648
|
shaderData.enableMacro("MATERIAL_NEED_WORLD_POS");
|
|
11643
11649
|
shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
|
|
@@ -12433,7 +12439,7 @@ PBRMaterial._specularColorTextureProp = ShaderProperty.getByName("material_Specu
|
|
|
12433
12439
|
_inherits(UnlitMaterial, BaseMaterial);
|
|
12434
12440
|
function UnlitMaterial(engine) {
|
|
12435
12441
|
var _this;
|
|
12436
|
-
_this = BaseMaterial.call(this, engine,
|
|
12442
|
+
_this = BaseMaterial.call(this, engine, Engine._builtinShaders.unlit) || this;
|
|
12437
12443
|
var shaderData = _this.shaderData;
|
|
12438
12444
|
shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
|
|
12439
12445
|
shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
|
|
@@ -13775,6 +13781,134 @@ BlendShapeManager._blendShapeWeightsProperty = ShaderProperty.getByName("rendere
|
|
|
13775
13781
|
BlendShapeManager._blendShapeTextureProperty = ShaderProperty.getByName("renderer_BlendShapeTexture");
|
|
13776
13782
|
BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("renderer_BlendShapeTextureInfo");
|
|
13777
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
|
+
|
|
13778
13912
|
/**
|
|
13779
13913
|
* Vertex attribute types of a vertex in a ModelMesh.
|
|
13780
13914
|
*/ var VertexAttribute = /*#__PURE__*/ function(VertexAttribute) {
|
|
@@ -14187,9 +14321,11 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
|
|
|
14187
14321
|
}
|
|
14188
14322
|
};
|
|
14189
14323
|
/**
|
|
14190
|
-
* Calculate
|
|
14191
|
-
* @
|
|
14192
|
-
*
|
|
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
|
|
14193
14329
|
*/ _proto.calculateTangents = function calculateTangents() {
|
|
14194
14330
|
var positions = this.getPositions();
|
|
14195
14331
|
var normals = this.getNormals();
|
|
@@ -14197,68 +14333,7 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
|
|
|
14197
14333
|
if (!normals || !uvs) {
|
|
14198
14334
|
throw "Set normal and uv before calculation.";
|
|
14199
14335
|
}
|
|
14200
|
-
|
|
14201
|
-
var e1 = ModelMesh._tempVec0, e2 = ModelMesh._tempVec1, t = ModelMesh._tempVec2, b = ModelMesh._tempVec3, temp = ModelMesh._tempVec4;
|
|
14202
|
-
var triangleCount = indices ? indices.length / 3 : positions.length / 3;
|
|
14203
|
-
var tangents = new Array(vertexCount);
|
|
14204
|
-
var biTangents = new Array(vertexCount);
|
|
14205
|
-
for(var i = 0; i < vertexCount; i++){
|
|
14206
|
-
tangents[i] = new engineMath.Vector4();
|
|
14207
|
-
biTangents[i] = new engineMath.Vector3();
|
|
14208
|
-
}
|
|
14209
|
-
// Calculate tangent and bi-tangent for each triangle and add to all three vertices.
|
|
14210
|
-
for(var k = 0; k < triangleCount; k++){
|
|
14211
|
-
var i0 = 3 * k;
|
|
14212
|
-
var i1 = 3 * k + 1;
|
|
14213
|
-
var i2 = 3 * k + 2;
|
|
14214
|
-
if (indices) {
|
|
14215
|
-
i0 = indices[i0];
|
|
14216
|
-
i1 = indices[i1];
|
|
14217
|
-
i2 = indices[i2];
|
|
14218
|
-
}
|
|
14219
|
-
var p0 = positions[i0];
|
|
14220
|
-
var p1 = positions[i1];
|
|
14221
|
-
var p2 = positions[i2];
|
|
14222
|
-
var w0 = uvs[i0];
|
|
14223
|
-
var w1 = uvs[i1];
|
|
14224
|
-
var w2 = uvs[i2];
|
|
14225
|
-
engineMath.Vector3.subtract(p1, p0, e1);
|
|
14226
|
-
engineMath.Vector3.subtract(p2, p0, e2);
|
|
14227
|
-
var x1 = w1.x - w0.x;
|
|
14228
|
-
var x2 = w2.x - w0.x;
|
|
14229
|
-
var y1 = w1.y - w0.y;
|
|
14230
|
-
var y2 = w2.y - w0.y;
|
|
14231
|
-
var r = 1.0 / (x1 * y2 - x2 * y1);
|
|
14232
|
-
engineMath.Vector3.scale(e1, y2 * r, t);
|
|
14233
|
-
engineMath.Vector3.scale(e2, y1 * r, temp);
|
|
14234
|
-
engineMath.Vector3.subtract(t, temp, t);
|
|
14235
|
-
engineMath.Vector3.scale(e2, x1 * r, b);
|
|
14236
|
-
engineMath.Vector3.scale(e1, x2 * r, temp);
|
|
14237
|
-
engineMath.Vector3.subtract(b, temp, b);
|
|
14238
|
-
var tangent = tangents[i0];
|
|
14239
|
-
tangent.set(tangent.x + t.x, tangent.y + t.y, tangent.z + t.z, 1.0);
|
|
14240
|
-
tangent = tangents[i1];
|
|
14241
|
-
tangent.set(tangent.x + t.x, tangent.y + t.y, tangent.z + t.z, 1.0);
|
|
14242
|
-
tangent = tangents[i2];
|
|
14243
|
-
tangent.set(tangent.x + t.x, tangent.y + t.y, tangent.z + t.z, 1.0);
|
|
14244
|
-
biTangents[i0].add(b);
|
|
14245
|
-
biTangents[i1].add(b);
|
|
14246
|
-
biTangents[i2].add(b);
|
|
14247
|
-
}
|
|
14248
|
-
// Orthonormalize each tangent and calculate the handedness.
|
|
14249
|
-
for(var i3 = 0; i3 < vertexCount; i3++){
|
|
14250
|
-
var n = normals[i3];
|
|
14251
|
-
var b1 = biTangents[i3];
|
|
14252
|
-
var tangent1 = tangents[i3];
|
|
14253
|
-
t.set(tangent1.x, tangent1.y, tangent1.z);
|
|
14254
|
-
engineMath.Vector3.cross(t, b1, temp);
|
|
14255
|
-
var w = engineMath.Vector3.dot(temp, n) > 0.0 ? 1 : -1;
|
|
14256
|
-
engineMath.Vector3.scale(n, engineMath.Vector3.dot(t, n), temp);
|
|
14257
|
-
engineMath.Vector3.subtract(t, temp, t);
|
|
14258
|
-
t.normalize();
|
|
14259
|
-
tangent1.set(t.x, t.y, t.z, w);
|
|
14260
|
-
}
|
|
14261
|
-
this.setTangents(tangents);
|
|
14336
|
+
this.setTangents(MeshTangentUtils.calculateTangents(positions, normals, uvs, this._indices));
|
|
14262
14337
|
};
|
|
14263
14338
|
/**
|
|
14264
14339
|
* @internal
|
|
@@ -14266,25 +14341,25 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
|
|
|
14266
14341
|
var _this = this;
|
|
14267
14342
|
var vertexBufferBindings = this._primitive.vertexBufferBindings;
|
|
14268
14343
|
var updateInfos = this._vertexBufferInfos;
|
|
14269
|
-
var
|
|
14270
|
-
if (!_this._advancedDataSyncToBuffer) {
|
|
14271
|
-
updateInfos[index].dataVersion = _this._dataVersionCounter++;
|
|
14272
|
-
}
|
|
14273
|
-
};
|
|
14274
|
-
// Remove listener from previous binding
|
|
14344
|
+
var updateInfo = updateInfos[index];
|
|
14275
14345
|
var previousBinding = vertexBufferBindings[index];
|
|
14276
|
-
|
|
14346
|
+
if (previousBinding) {
|
|
14347
|
+
previousBinding.buffer._dataUpdateManager.removeListener(updateInfo.onBufferChanged);
|
|
14348
|
+
}
|
|
14277
14349
|
Mesh.prototype._setVertexBufferBinding.call(this, index, binding);
|
|
14278
|
-
// Add listener to new binding and trigger update
|
|
14279
14350
|
if (binding) {
|
|
14280
|
-
|
|
14281
|
-
|
|
14282
|
-
|
|
14283
|
-
|
|
14284
|
-
|
|
14285
|
-
|
|
14286
|
-
vertexBufferBindings.length--;
|
|
14351
|
+
if (!updateInfo) {
|
|
14352
|
+
updateInfo = updateInfos[index] = new BufferUpdateInfo(function() {
|
|
14353
|
+
if (!_this._advancedDataSyncToBuffer) {
|
|
14354
|
+
updateInfos[index].dataVersion = _this._dataVersionCounter++;
|
|
14355
|
+
}
|
|
14356
|
+
});
|
|
14287
14357
|
}
|
|
14358
|
+
binding.buffer._dataUpdateManager.addListener(updateInfo.onBufferChanged);
|
|
14359
|
+
updateInfo.reset();
|
|
14360
|
+
updateInfo.onBufferChanged();
|
|
14361
|
+
} else if (index + 1 == vertexBufferBindings.length) {
|
|
14362
|
+
vertexBufferBindings.length--;
|
|
14288
14363
|
}
|
|
14289
14364
|
};
|
|
14290
14365
|
/**
|
|
@@ -14306,6 +14381,11 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
|
|
|
14306
14381
|
/**
|
|
14307
14382
|
* @internal
|
|
14308
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
|
+
}
|
|
14309
14389
|
Mesh.prototype._onDestroy.call(this);
|
|
14310
14390
|
this._releaseCache(true);
|
|
14311
14391
|
};
|
|
@@ -14777,13 +14857,9 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
|
|
|
14777
14857
|
]);
|
|
14778
14858
|
return ModelMesh;
|
|
14779
14859
|
}(Mesh);
|
|
14780
|
-
ModelMesh._tempVec0 = new engineMath.Vector3();
|
|
14781
|
-
ModelMesh._tempVec1 = new engineMath.Vector3();
|
|
14782
|
-
ModelMesh._tempVec2 = new engineMath.Vector3();
|
|
14783
|
-
ModelMesh._tempVec3 = new engineMath.Vector3();
|
|
14784
|
-
ModelMesh._tempVec4 = new engineMath.Vector3();
|
|
14785
14860
|
var BufferUpdateInfo = /*#__PURE__*/ function() {
|
|
14786
|
-
function BufferUpdateInfo() {
|
|
14861
|
+
function BufferUpdateInfo(onBufferChanged) {
|
|
14862
|
+
this.onBufferChanged = onBufferChanged;
|
|
14787
14863
|
this.dataVersion = -1;
|
|
14788
14864
|
this.uploadAdvancedData = false;
|
|
14789
14865
|
}
|
|
@@ -14794,337 +14870,2339 @@ var BufferUpdateInfo = /*#__PURE__*/ function() {
|
|
|
14794
14870
|
return BufferUpdateInfo;
|
|
14795
14871
|
}();
|
|
14796
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
|
+
|
|
14797
15001
|
/**
|
|
14798
15002
|
* @internal
|
|
14799
15003
|
*/ var PrimitiveMeshRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
14800
15004
|
_inherits(PrimitiveMeshRestorer, ContentRestorer);
|
|
14801
|
-
function PrimitiveMeshRestorer(
|
|
15005
|
+
function PrimitiveMeshRestorer(mesh, _generate, _args) {
|
|
14802
15006
|
var _this;
|
|
14803
|
-
|
|
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;
|
|
14804
15012
|
return _this;
|
|
14805
15013
|
}
|
|
14806
15014
|
var _proto = PrimitiveMeshRestorer.prototype;
|
|
14807
15015
|
_proto.restoreContent = function restoreContent() {
|
|
14808
|
-
var
|
|
14809
|
-
|
|
14810
|
-
|
|
14811
|
-
|
|
14812
|
-
|
|
14813
|
-
|
|
14814
|
-
|
|
14815
|
-
|
|
14816
|
-
|
|
14817
|
-
|
|
14818
|
-
|
|
14819
|
-
|
|
14820
|
-
|
|
14821
|
-
|
|
14822
|
-
|
|
14823
|
-
|
|
14824
|
-
|
|
14825
|
-
|
|
14826
|
-
|
|
14827
|
-
var cylinderInfo = primitiveInfo;
|
|
14828
|
-
PrimitiveMesh._setCylinderData(this.resource, cylinderInfo.radiusTop, cylinderInfo.radiusBottom, cylinderInfo.height, cylinderInfo.radialSegments, cylinderInfo.heightSegments, cylinderInfo.noLongerAccessible, true, cylinderInfo.vertexBuffer);
|
|
14829
|
-
break;
|
|
14830
|
-
case 4:
|
|
14831
|
-
var torusInfo = primitiveInfo;
|
|
14832
|
-
PrimitiveMesh._setTorusData(this.resource, torusInfo.radius, torusInfo.tubeRadius, torusInfo.radialSegments, torusInfo.tubularSegments, torusInfo.arc, torusInfo.noLongerAccessible, true, torusInfo.vertexBuffer);
|
|
14833
|
-
break;
|
|
14834
|
-
case 5:
|
|
14835
|
-
var coneInfo = primitiveInfo;
|
|
14836
|
-
PrimitiveMesh._setConeData(this.resource, coneInfo.radius, coneInfo.height, coneInfo.radialSegments, coneInfo.heightSegments, coneInfo.noLongerAccessible, true, coneInfo.vertexBuffer);
|
|
14837
|
-
break;
|
|
14838
|
-
case 6:
|
|
14839
|
-
var capsuleInfo = primitiveInfo;
|
|
14840
|
-
PrimitiveMesh._setCapsuleData(this.resource, capsuleInfo.radius, capsuleInfo.height, capsuleInfo.radialSegments, capsuleInfo.heightSegments, capsuleInfo.noLongerAccessible, true, capsuleInfo.vertexBuffer);
|
|
14841
|
-
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);
|
|
14842
15035
|
}
|
|
14843
15036
|
};
|
|
14844
15037
|
return PrimitiveMeshRestorer;
|
|
14845
15038
|
}(ContentRestorer);
|
|
15039
|
+
|
|
14846
15040
|
/**
|
|
14847
15041
|
* @internal
|
|
14848
|
-
*/ var
|
|
14849
|
-
|
|
14850
|
-
|
|
14851
|
-
|
|
14852
|
-
|
|
14853
|
-
|
|
14854
|
-
|
|
14855
|
-
|
|
14856
|
-
|
|
14857
|
-
|
|
14858
|
-
|
|
14859
|
-
|
|
14860
|
-
|
|
14861
|
-
|
|
14862
|
-
|
|
14863
|
-
|
|
14864
|
-
|
|
14865
|
-
|
|
14866
|
-
|
|
14867
|
-
|
|
14868
|
-
|
|
14869
|
-
var
|
|
14870
|
-
|
|
14871
|
-
|
|
14872
|
-
|
|
14873
|
-
|
|
14874
|
-
|
|
14875
|
-
|
|
14876
|
-
|
|
14877
|
-
|
|
14878
|
-
|
|
14879
|
-
|
|
14880
|
-
var
|
|
14881
|
-
|
|
14882
|
-
|
|
14883
|
-
|
|
14884
|
-
|
|
14885
|
-
}
|
|
14886
|
-
|
|
14887
|
-
|
|
14888
|
-
|
|
14889
|
-
|
|
14890
|
-
|
|
14891
|
-
|
|
14892
|
-
|
|
14893
|
-
|
|
14894
|
-
|
|
14895
|
-
|
|
14896
|
-
|
|
14897
|
-
|
|
14898
|
-
|
|
14899
|
-
|
|
14900
|
-
|
|
14901
|
-
|
|
14902
|
-
|
|
14903
|
-
|
|
14904
|
-
|
|
14905
|
-
|
|
14906
|
-
|
|
14907
|
-
}
|
|
14908
|
-
|
|
14909
|
-
|
|
14910
|
-
|
|
14911
|
-
|
|
14912
|
-
|
|
14913
|
-
|
|
14914
|
-
|
|
14915
|
-
|
|
14916
|
-
|
|
14917
|
-
|
|
14918
|
-
|
|
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
|
+
|
|
14919
15178
|
/**
|
|
14920
15179
|
* @internal
|
|
14921
|
-
*/ var
|
|
14922
|
-
|
|
14923
|
-
function
|
|
14924
|
-
var
|
|
14925
|
-
|
|
14926
|
-
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
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
|
+
|
|
14930
15735
|
/**
|
|
14931
15736
|
* @internal
|
|
14932
|
-
*/ var
|
|
14933
|
-
|
|
14934
|
-
function
|
|
14935
|
-
var
|
|
14936
|
-
|
|
14937
|
-
|
|
14938
|
-
|
|
14939
|
-
|
|
14940
|
-
|
|
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
|
+
}();
|
|
14941
15834
|
|
|
14942
15835
|
/**
|
|
14943
|
-
*
|
|
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.
|
|
14944
15841
|
*/ var PrimitiveMesh = /*#__PURE__*/ function() {
|
|
14945
15842
|
function PrimitiveMesh() {}
|
|
14946
15843
|
/**
|
|
14947
|
-
* Create a sphere
|
|
14948
|
-
*
|
|
14949
|
-
*
|
|
14950
|
-
* @param
|
|
14951
|
-
* @param
|
|
14952
|
-
* @
|
|
14953
|
-
|
|
14954
|
-
|
|
14955
|
-
|
|
14956
|
-
|
|
14957
|
-
var
|
|
14958
|
-
|
|
14959
|
-
var
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14963
|
-
|
|
14964
|
-
|
|
14965
|
-
|
|
14966
|
-
|
|
14967
|
-
|
|
14968
|
-
|
|
14969
|
-
|
|
14970
|
-
*
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
14982
|
-
|
|
14983
|
-
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
|
|
14989
|
-
|
|
14990
|
-
|
|
14991
|
-
|
|
14992
|
-
|
|
14993
|
-
|
|
14994
|
-
|
|
14995
|
-
|
|
14996
|
-
|
|
14997
|
-
|
|
14998
|
-
|
|
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;
|
|
14999
16336
|
};
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15010
|
-
|
|
15011
|
-
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
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
|
+
}
|
|
15020
16380
|
};
|
|
15021
|
-
|
|
15022
|
-
|
|
15023
|
-
|
|
15024
|
-
|
|
15025
|
-
|
|
15026
|
-
|
|
15027
|
-
|
|
15028
|
-
|
|
15029
|
-
|
|
15030
|
-
|
|
15031
|
-
|
|
15032
|
-
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
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;
|
|
15043
16517
|
};
|
|
15044
|
-
|
|
15045
|
-
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
|
|
15064
|
-
|
|
15065
|
-
|
|
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;
|
|
15066
16548
|
};
|
|
15067
|
-
|
|
15068
|
-
|
|
15069
|
-
|
|
15070
|
-
|
|
15071
|
-
|
|
15072
|
-
|
|
15073
|
-
|
|
15074
|
-
|
|
15075
|
-
|
|
15076
|
-
|
|
15077
|
-
|
|
15078
|
-
|
|
15079
|
-
|
|
15080
|
-
|
|
15081
|
-
|
|
15082
|
-
|
|
15083
|
-
PrimitiveMesh._setConeData(mesh, radius, height, radialSegments, heightSegments, noLongerAccessible, false);
|
|
15084
|
-
var vertexBuffer = mesh.vertexBufferBindings[0].buffer;
|
|
15085
|
-
engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, new ConeRestoreInfo(radius, height, radialSegments, heightSegments, vertexBuffer, noLongerAccessible)));
|
|
15086
|
-
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;
|
|
15087
16565
|
};
|
|
15088
|
-
|
|
15089
|
-
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
|
|
15093
|
-
|
|
15094
|
-
|
|
15095
|
-
|
|
15096
|
-
|
|
15097
|
-
|
|
15098
|
-
|
|
15099
|
-
|
|
15100
|
-
|
|
15101
|
-
|
|
15102
|
-
|
|
15103
|
-
var
|
|
15104
|
-
|
|
15105
|
-
|
|
15106
|
-
|
|
15107
|
-
|
|
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;
|
|
15108
16590
|
};
|
|
15109
|
-
|
|
15110
|
-
|
|
15111
|
-
|
|
15112
|
-
|
|
15113
|
-
|
|
15114
|
-
var
|
|
15115
|
-
var
|
|
15116
|
-
PrimitiveMesh.
|
|
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;
|
|
15117
17197
|
var positionCount = positions.length / 3;
|
|
15118
17198
|
var cellsCount = cells.length / 4;
|
|
15119
|
-
var poleOffset = positionCount + Math.pow(2,
|
|
15120
|
-
//
|
|
15121
|
-
// 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
|
|
15122
17201
|
var vertexCount = poleOffset + 16;
|
|
15123
17202
|
var vertices = new Float32Array(vertexCount * 8);
|
|
15124
|
-
var indices =
|
|
17203
|
+
var indices = new Uint16Array(cellsCount * 6);
|
|
15125
17204
|
var seamCount = 0;
|
|
15126
17205
|
var seamVertices = {};
|
|
15127
|
-
// Get normals, uvs, and scale to radius
|
|
15128
17206
|
for(var i = 0; i < positionCount; i++){
|
|
15129
17207
|
var offset = 3 * i;
|
|
15130
17208
|
var x = positions[offset];
|
|
@@ -15143,875 +17221,182 @@ var BufferUpdateInfo = /*#__PURE__*/ function() {
|
|
|
15143
17221
|
vertices[offset + 5] = z;
|
|
15144
17222
|
vertices[offset + 6] = (Math.PI - Math.atan2(z, x)) / (2 * Math.PI);
|
|
15145
17223
|
vertices[offset + 7] = Math.acos(y) / Math.PI;
|
|
17224
|
+
// Duplicate the seam so adjacent triangles can use U = 0 and U = 1
|
|
15146
17225
|
if (vertices[offset + 6] === 0) {
|
|
15147
|
-
// Generate seam vertex
|
|
15148
17226
|
var seamOffset = 8 * (positionCount + seamCount++);
|
|
15149
17227
|
vertices.set(vertices.subarray(offset, offset + 8), seamOffset);
|
|
15150
17228
|
vertices[seamOffset + 6] = 1.0;
|
|
15151
|
-
// Cache seam vertex
|
|
15152
17229
|
seamVertices[offset / 8] = seamOffset / 8;
|
|
15153
17230
|
}
|
|
15154
17231
|
}
|
|
15155
|
-
// Get indices
|
|
15156
17232
|
var offset1 = 0;
|
|
15157
|
-
|
|
17233
|
+
var poleIndex = 0;
|
|
15158
17234
|
for(var i1 = 0; i1 < cellsCount; i1++){
|
|
15159
17235
|
var idx = 4 * i1;
|
|
15160
17236
|
var indexA = cells[idx];
|
|
15161
17237
|
var indexB = cells[idx + 1];
|
|
15162
17238
|
var indexC = cells[idx + 2];
|
|
15163
17239
|
var indexD = cells[idx + 3];
|
|
15164
|
-
// Handle seam by replacing vertex index to seam vertex index if necessary
|
|
15165
17240
|
var floatIndexA = 8 * indexA;
|
|
15166
17241
|
var floatIndexB = 8 * indexB;
|
|
15167
17242
|
var floatIndexC = 8 * indexC;
|
|
15168
17243
|
var floatIndexD = 8 * indexD;
|
|
15169
|
-
//
|
|
17244
|
+
// Use the U = 1 copies on the negative-Z side of the seam
|
|
15170
17245
|
if (vertices[floatIndexA + 2] + vertices[floatIndexB + 2] + vertices[floatIndexC + 2] < 0) {
|
|
15171
|
-
vertices[floatIndexA + 6] === 0
|
|
15172
|
-
|
|
15173
|
-
|
|
15174
|
-
vertices[
|
|
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
|
+
}
|
|
15175
17258
|
}
|
|
15176
17259
|
indices[offset1] = indexA;
|
|
15177
17260
|
indices[offset1 + 1] = indexB;
|
|
15178
17261
|
indices[offset1 + 2] = indexC;
|
|
15179
|
-
|
|
17262
|
+
poleIndex = PrimitiveMesh._replacePoleUV(indices, vertices, offset1, poleOffset, poleIndex);
|
|
15180
17263
|
indices[offset1 + 3] = indexA;
|
|
15181
17264
|
indices[offset1 + 4] = indexC;
|
|
15182
17265
|
indices[offset1 + 5] = indexD;
|
|
15183
|
-
|
|
17266
|
+
poleIndex = PrimitiveMesh._replacePoleUV(indices, vertices, offset1 + 3, poleOffset, poleIndex);
|
|
15184
17267
|
offset1 += 6;
|
|
15185
17268
|
}
|
|
15186
|
-
|
|
15187
|
-
|
|
15188
|
-
|
|
15189
|
-
|
|
15190
|
-
}
|
|
15191
|
-
PrimitiveMesh._initialize(sphereMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
|
|
15192
|
-
};
|
|
15193
|
-
/**
|
|
15194
|
-
* @internal
|
|
15195
|
-
*/ PrimitiveMesh._setSphereData = function _setSphereData(sphereMesh, radius, segments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
|
|
15196
|
-
segments = Math.max(2, Math.floor(segments));
|
|
15197
|
-
var count = segments + 1;
|
|
15198
|
-
var vertexCount = count * count;
|
|
15199
|
-
var rectangleCount = segments * segments;
|
|
15200
|
-
var indices = PrimitiveMesh._generateIndices(sphereMesh.engine, vertexCount, rectangleCount * 6);
|
|
15201
|
-
var thetaRange = Math.PI;
|
|
15202
|
-
var alphaRange = thetaRange * 2;
|
|
15203
|
-
var countReciprocal = 1.0 / count;
|
|
15204
|
-
var segmentsReciprocal = 1.0 / segments;
|
|
15205
|
-
var vertexFloatCount = 8;
|
|
15206
|
-
var vertices = new Float32Array(vertexCount * vertexFloatCount);
|
|
15207
|
-
for(var i = 0; i < vertexCount; ++i){
|
|
15208
|
-
var x = i % count;
|
|
15209
|
-
var y = i * countReciprocal | 0;
|
|
15210
|
-
var u = x * segmentsReciprocal;
|
|
15211
|
-
var v = y * segmentsReciprocal;
|
|
15212
|
-
var alphaDelta = u * alphaRange;
|
|
15213
|
-
var thetaDelta = v * thetaRange;
|
|
15214
|
-
var sinTheta = Math.sin(thetaDelta);
|
|
15215
|
-
var posX = -radius * Math.cos(alphaDelta) * sinTheta;
|
|
15216
|
-
var posY = radius * Math.cos(thetaDelta);
|
|
15217
|
-
var posZ = radius * Math.sin(alphaDelta) * sinTheta;
|
|
15218
|
-
var offset = i * vertexFloatCount;
|
|
15219
|
-
// Position
|
|
15220
|
-
vertices[offset++] = posX;
|
|
15221
|
-
vertices[offset++] = posY;
|
|
15222
|
-
vertices[offset++] = posZ;
|
|
15223
|
-
// Normal
|
|
15224
|
-
vertices[offset++] = posX;
|
|
15225
|
-
vertices[offset++] = posY;
|
|
15226
|
-
vertices[offset++] = posZ;
|
|
15227
|
-
// TexCoord
|
|
15228
|
-
vertices[offset++] = u;
|
|
15229
|
-
vertices[offset++] = v;
|
|
15230
|
-
}
|
|
15231
|
-
var offset1 = 0;
|
|
15232
|
-
for(var i1 = 0; i1 < rectangleCount; ++i1){
|
|
15233
|
-
var x1 = i1 % segments;
|
|
15234
|
-
var y1 = i1 * segmentsReciprocal | 0;
|
|
15235
|
-
var a = y1 * count + x1;
|
|
15236
|
-
var b = a + 1;
|
|
15237
|
-
var c = a + count;
|
|
15238
|
-
var d = c + 1;
|
|
15239
|
-
indices[offset1++] = b;
|
|
15240
|
-
indices[offset1++] = a;
|
|
15241
|
-
indices[offset1++] = d;
|
|
15242
|
-
indices[offset1++] = a;
|
|
15243
|
-
indices[offset1++] = c;
|
|
15244
|
-
indices[offset1++] = d;
|
|
15245
|
-
}
|
|
15246
|
-
if (!isRestoreMode) {
|
|
15247
|
-
var bounds = sphereMesh.bounds;
|
|
15248
|
-
bounds.min.set(-radius, -radius, -radius);
|
|
15249
|
-
bounds.max.set(radius, radius, radius);
|
|
15250
|
-
}
|
|
15251
|
-
PrimitiveMesh._initialize(sphereMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
|
|
15252
|
-
};
|
|
15253
|
-
/**
|
|
15254
|
-
* @internal
|
|
15255
|
-
*/ PrimitiveMesh._subdiveCatmullClark = function _subdiveCatmullClark(step, positions, cells) {
|
|
15256
|
-
var edges = new Map();
|
|
15257
|
-
var faces = new Array();
|
|
15258
|
-
positions.set(PrimitiveMesh._sphereSeedPositions);
|
|
15259
|
-
cells.set(PrimitiveMesh._sphereSeedCells);
|
|
15260
|
-
for(var i = 0; i < step; i++){
|
|
15261
|
-
var cellCount = 6 * Math.pow(4, i);
|
|
15262
|
-
var positionCount = 4 * cellCount + 2;
|
|
15263
|
-
edges.clear();
|
|
15264
|
-
faces.length = 0;
|
|
15265
|
-
// Get cell face's facePoint
|
|
15266
|
-
for(var j = 0; j < cellCount; j++){
|
|
15267
|
-
var face = faces[j] = {
|
|
15268
|
-
facePoint: new engineMath.Vector3(),
|
|
15269
|
-
adjacentEdges: new Array(4)
|
|
15270
|
-
};
|
|
15271
|
-
// Get cell's edgePoint
|
|
15272
|
-
for(var k = 0; k < 4; k++){
|
|
15273
|
-
var offset = 3 * cells[4 * j + k];
|
|
15274
|
-
face.facePoint.x += 0.25 * positions[offset];
|
|
15275
|
-
face.facePoint.y += 0.25 * positions[offset + 1];
|
|
15276
|
-
face.facePoint.z += 0.25 * positions[offset + 2];
|
|
15277
|
-
}
|
|
15278
|
-
// Get cell edges
|
|
15279
|
-
for(var k1 = 0; k1 < 4; k1++){
|
|
15280
|
-
var vertexIdxA = cells[4 * j + k1];
|
|
15281
|
-
var vertexIdxB = cells[4 * j + (k1 + 1) % 4];
|
|
15282
|
-
var edgeIdxKey = Math.min(vertexIdxA, vertexIdxB) * positionCount + Math.max(vertexIdxA, vertexIdxB);
|
|
15283
|
-
if (!edges.has(edgeIdxKey)) {
|
|
15284
|
-
var edge = {
|
|
15285
|
-
edgePoint: new engineMath.Vector3(),
|
|
15286
|
-
edgePointIndex: undefined
|
|
15287
|
-
};
|
|
15288
|
-
var offsetA = 3 * vertexIdxA;
|
|
15289
|
-
var offsetB = 3 * vertexIdxB;
|
|
15290
|
-
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]));
|
|
15291
|
-
edges.set(edgeIdxKey, edge);
|
|
15292
|
-
}
|
|
15293
|
-
var edge1 = edges.get(edgeIdxKey);
|
|
15294
|
-
face.adjacentEdges[k1] = edge1;
|
|
15295
|
-
var edgePoint = edge1.edgePoint;
|
|
15296
|
-
var facePoint = face.facePoint;
|
|
15297
|
-
edgePoint.x += 0.25 * facePoint.x;
|
|
15298
|
-
edgePoint.y += 0.25 * facePoint.y;
|
|
15299
|
-
edgePoint.z += 0.25 * facePoint.z;
|
|
15300
|
-
}
|
|
15301
|
-
}
|
|
15302
|
-
var prePointCount = cellCount + 2;
|
|
15303
|
-
var edgePointOffset = prePointCount + cellCount;
|
|
15304
|
-
var pointIdx = 0;
|
|
15305
|
-
this._sphereEdgeIdx = 0;
|
|
15306
|
-
var preCells = cells.slice(0, 4 * cellCount);
|
|
15307
|
-
// Get New positions, which consists of updated positions of existing points, face points and edge points
|
|
15308
|
-
for(var j1 = 0; j1 < cellCount; j1++){
|
|
15309
|
-
// Add face point to new positions
|
|
15310
|
-
var face1 = faces[j1];
|
|
15311
|
-
face1.facePoint.copyToArray(positions, 3 * (prePointCount + j1));
|
|
15312
|
-
// Get the face point index
|
|
15313
|
-
var ic = prePointCount + j1;
|
|
15314
|
-
var id = void 0, ib = void 0, temp = void 0;
|
|
15315
|
-
// ia -- id -- ia
|
|
15316
|
-
// | | |
|
|
15317
|
-
// ib -- ic -- ib
|
|
15318
|
-
// | | |
|
|
15319
|
-
// ia -- id -- ia
|
|
15320
|
-
for(var k2 = 0; k2 < 4; k2++){
|
|
15321
|
-
// Get the updated existing point index
|
|
15322
|
-
var ia = preCells[pointIdx++];
|
|
15323
|
-
// ib and id share four edge points in one cell
|
|
15324
|
-
switch(k2){
|
|
15325
|
-
case 0:
|
|
15326
|
-
{
|
|
15327
|
-
var edgeB = face1.adjacentEdges[k2 % 4];
|
|
15328
|
-
var edgeD = face1.adjacentEdges[(k2 + 3) % 4];
|
|
15329
|
-
ib = this._calculateEdgeIndex(positions, edgeB, edgePointOffset);
|
|
15330
|
-
id = this._calculateEdgeIndex(positions, edgeD, edgePointOffset);
|
|
15331
|
-
temp = id;
|
|
15332
|
-
break;
|
|
15333
|
-
}
|
|
15334
|
-
case 1:
|
|
15335
|
-
case 2:
|
|
15336
|
-
{
|
|
15337
|
-
var edgeB1 = face1.adjacentEdges[k2 % 4];
|
|
15338
|
-
id = ib;
|
|
15339
|
-
ib = this._calculateEdgeIndex(positions, edgeB1, edgePointOffset);
|
|
15340
|
-
break;
|
|
15341
|
-
}
|
|
15342
|
-
case 3:
|
|
15343
|
-
{
|
|
15344
|
-
id = ib;
|
|
15345
|
-
ib = temp;
|
|
15346
|
-
break;
|
|
15347
|
-
}
|
|
15348
|
-
}
|
|
15349
|
-
var idx = 4 * (4 * j1 + k2);
|
|
15350
|
-
cells[idx] = ia;
|
|
15351
|
-
cells[idx + 1] = ib;
|
|
15352
|
-
cells[idx + 2] = ic;
|
|
15353
|
-
cells[idx + 3] = id;
|
|
15354
|
-
}
|
|
15355
|
-
}
|
|
15356
|
-
}
|
|
17269
|
+
var data = new PrimitiveMeshBuilder();
|
|
17270
|
+
data.setData(vertices, indices);
|
|
17271
|
+
data.boundsExtent = new engineMath.Vector3(radius, radius, radius);
|
|
17272
|
+
return data;
|
|
15357
17273
|
};
|
|
15358
|
-
|
|
15359
|
-
* Duplicate vertices at the poles and adjust their UV coordinates.
|
|
15360
|
-
*/ PrimitiveMesh._generateAndReplacePoleUV = function _generateAndReplacePoleUV(indices, vertices, idx, poleOffset) {
|
|
17274
|
+
PrimitiveMesh._replacePoleUV = function _replacePoleUV(indices, vertices, idx, poleOffset, poleIndex) {
|
|
15361
17275
|
var v = vertices[8 * indices[idx] + 7];
|
|
15362
17276
|
if (v === 0 || v === 1) {
|
|
15363
17277
|
var offset = 8 * indices[idx];
|
|
15364
|
-
var addedOffset = 8 * (poleOffset +
|
|
17278
|
+
var addedOffset = 8 * (poleOffset + poleIndex);
|
|
15365
17279
|
vertices.set(vertices.subarray(offset, offset + 8), addedOffset);
|
|
15366
17280
|
vertices[addedOffset + 6] = 0.5 * (vertices[offset + 6] + vertices[8 * indices[idx + 1] + 6] + vertices[8 * indices[idx + 2] + 6] - 0.5);
|
|
15367
|
-
indices[idx] = poleOffset +
|
|
17281
|
+
indices[idx] = poleOffset + poleIndex++;
|
|
15368
17282
|
}
|
|
17283
|
+
return poleIndex;
|
|
15369
17284
|
};
|
|
15370
|
-
|
|
15371
|
-
|
|
15372
|
-
|
|
15373
|
-
|
|
15374
|
-
|
|
15375
|
-
} else {
|
|
15376
|
-
edge.edgePoint.copyToArray(positions, 3 * (offset + PrimitiveMesh._sphereEdgeIdx));
|
|
15377
|
-
var index = offset + PrimitiveMesh._sphereEdgeIdx++;
|
|
15378
|
-
edge.edgePointIndex = index;
|
|
15379
|
-
return index;
|
|
15380
|
-
}
|
|
15381
|
-
};
|
|
15382
|
-
/**
|
|
15383
|
-
* @internal
|
|
15384
|
-
*/ PrimitiveMesh._setCuboidData = function _setCuboidData(cuboidMesh, width, height, depth, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
|
|
15385
|
-
var halfWidth = width / 2;
|
|
15386
|
-
var halfHeight = height / 2;
|
|
15387
|
-
var halfDepth = depth / 2;
|
|
15388
|
-
var vertexFloatCount = 8;
|
|
15389
|
-
var vertices = new Float32Array(24 * vertexFloatCount);
|
|
15390
|
-
// Up
|
|
15391
|
-
vertices[0] = -halfWidth, vertices[1] = halfHeight, vertices[2] = -halfDepth;
|
|
15392
|
-
vertices[6] = 0, vertices[7] = 0;
|
|
15393
|
-
vertices[8] = halfWidth, vertices[9] = halfHeight, vertices[10] = -halfDepth;
|
|
15394
|
-
vertices[14] = 1, vertices[15] = 0;
|
|
15395
|
-
vertices[16] = halfWidth, vertices[17] = halfHeight, vertices[18] = halfDepth;
|
|
15396
|
-
vertices[22] = 1, vertices[23] = 1;
|
|
15397
|
-
vertices[24] = -halfWidth, vertices[25] = halfHeight, vertices[26] = halfDepth;
|
|
15398
|
-
vertices[30] = 0, vertices[31] = 1;
|
|
15399
|
-
for(var i = 0; i < 4; i++){
|
|
15400
|
-
var normalOffset = vertexFloatCount * i + 3;
|
|
15401
|
-
vertices[normalOffset++] = 0, vertices[normalOffset++] = 1, vertices[normalOffset++] = 0;
|
|
15402
|
-
}
|
|
15403
|
-
// Down
|
|
15404
|
-
vertices[32] = -halfWidth, vertices[33] = -halfHeight, vertices[34] = -halfDepth;
|
|
15405
|
-
vertices[38] = 0, vertices[39] = 1;
|
|
15406
|
-
vertices[40] = halfWidth, vertices[41] = -halfHeight, vertices[42] = -halfDepth;
|
|
15407
|
-
vertices[46] = 1, vertices[47] = 1;
|
|
15408
|
-
vertices[48] = halfWidth, vertices[49] = -halfHeight, vertices[50] = halfDepth;
|
|
15409
|
-
vertices[54] = 1, vertices[55] = 0;
|
|
15410
|
-
vertices[56] = -halfWidth, vertices[57] = -halfHeight, vertices[58] = halfDepth;
|
|
15411
|
-
vertices[62] = 0, vertices[63] = 0;
|
|
15412
|
-
for(var i1 = 0; i1 < 4; i1++){
|
|
15413
|
-
var normalOffset1 = vertexFloatCount * i1 + 35;
|
|
15414
|
-
vertices[normalOffset1++] = 0, vertices[normalOffset1++] = -1, vertices[normalOffset1++] = 0;
|
|
15415
|
-
}
|
|
15416
|
-
// Left
|
|
15417
|
-
vertices[64] = -halfWidth, vertices[65] = halfHeight, vertices[66] = -halfDepth;
|
|
15418
|
-
vertices[70] = 0, vertices[71] = 0;
|
|
15419
|
-
vertices[72] = -halfWidth, vertices[73] = halfHeight, vertices[74] = halfDepth;
|
|
15420
|
-
vertices[78] = 1, vertices[79] = 0;
|
|
15421
|
-
vertices[80] = -halfWidth, vertices[81] = -halfHeight, vertices[82] = halfDepth;
|
|
15422
|
-
vertices[86] = 1, vertices[87] = 1;
|
|
15423
|
-
vertices[88] = -halfWidth, vertices[89] = -halfHeight, vertices[90] = -halfDepth;
|
|
15424
|
-
vertices[94] = 0, vertices[95] = 1;
|
|
15425
|
-
for(var i2 = 0; i2 < 4; i2++){
|
|
15426
|
-
var normalOffset2 = vertexFloatCount * i2 + 67;
|
|
15427
|
-
vertices[normalOffset2++] = -1, vertices[normalOffset2++] = 0, vertices[normalOffset2++] = 0;
|
|
15428
|
-
}
|
|
15429
|
-
// Right
|
|
15430
|
-
vertices[96] = halfWidth, vertices[97] = halfHeight, vertices[98] = -halfDepth;
|
|
15431
|
-
vertices[102] = 1, vertices[103] = 0;
|
|
15432
|
-
vertices[104] = halfWidth, vertices[105] = halfHeight, vertices[106] = halfDepth;
|
|
15433
|
-
vertices[110] = 0, vertices[111] = 0;
|
|
15434
|
-
vertices[112] = halfWidth, vertices[113] = -halfHeight, vertices[114] = halfDepth;
|
|
15435
|
-
vertices[118] = 0, vertices[119] = 1;
|
|
15436
|
-
vertices[120] = halfWidth, vertices[121] = -halfHeight, vertices[122] = -halfDepth;
|
|
15437
|
-
vertices[126] = 1, vertices[127] = 1;
|
|
15438
|
-
for(var i3 = 0; i3 < 4; i3++){
|
|
15439
|
-
var normalOffset3 = vertexFloatCount * i3 + 99;
|
|
15440
|
-
vertices[normalOffset3++] = 1, vertices[normalOffset3++] = 0, vertices[normalOffset3++] = 0;
|
|
15441
|
-
}
|
|
15442
|
-
// Front
|
|
15443
|
-
vertices[128] = -halfWidth, vertices[129] = halfHeight, vertices[130] = halfDepth;
|
|
15444
|
-
vertices[134] = 0, vertices[135] = 0;
|
|
15445
|
-
vertices[136] = halfWidth, vertices[137] = halfHeight, vertices[138] = halfDepth;
|
|
15446
|
-
vertices[142] = 1, vertices[143] = 0;
|
|
15447
|
-
vertices[144] = halfWidth, vertices[145] = -halfHeight, vertices[146] = halfDepth;
|
|
15448
|
-
vertices[150] = 1, vertices[151] = 1;
|
|
15449
|
-
vertices[152] = -halfWidth, vertices[153] = -halfHeight, vertices[154] = halfDepth;
|
|
15450
|
-
vertices[158] = 0, vertices[159] = 1;
|
|
15451
|
-
for(var i4 = 0; i4 < 4; i4++){
|
|
15452
|
-
var normalOffset4 = vertexFloatCount * i4 + 131;
|
|
15453
|
-
vertices[normalOffset4++] = 0, vertices[normalOffset4++] = 0, vertices[normalOffset4++] = 1;
|
|
15454
|
-
}
|
|
15455
|
-
// Back
|
|
15456
|
-
vertices[160] = -halfWidth, vertices[161] = halfHeight, vertices[162] = -halfDepth;
|
|
15457
|
-
vertices[166] = 1, vertices[167] = 0;
|
|
15458
|
-
vertices[168] = halfWidth, vertices[169] = halfHeight, vertices[170] = -halfDepth;
|
|
15459
|
-
vertices[174] = 0, vertices[175] = 0;
|
|
15460
|
-
vertices[176] = halfWidth, vertices[177] = -halfHeight, vertices[178] = -halfDepth;
|
|
15461
|
-
vertices[182] = 0, vertices[183] = 1;
|
|
15462
|
-
vertices[184] = -halfWidth, vertices[185] = -halfHeight, vertices[186] = -halfDepth;
|
|
15463
|
-
vertices[190] = 1, vertices[191] = 1;
|
|
15464
|
-
for(var i5 = 0; i5 < 4; i5++){
|
|
15465
|
-
var normalOffset5 = vertexFloatCount * i5 + 163;
|
|
15466
|
-
vertices[normalOffset5++] = 0, vertices[normalOffset5++] = 0, vertices[normalOffset5++] = -1;
|
|
15467
|
-
}
|
|
15468
|
-
var indices = new Uint16Array(36);
|
|
15469
|
-
// prettier-ignore
|
|
15470
|
-
// Up
|
|
15471
|
-
indices[0] = 0, indices[1] = 2, indices[2] = 1, indices[3] = 2, indices[4] = 0, indices[5] = 3, // Down
|
|
15472
|
-
indices[6] = 4, indices[7] = 6, indices[8] = 7, indices[9] = 6, indices[10] = 4, indices[11] = 5, // Left
|
|
15473
|
-
indices[12] = 8, indices[13] = 10, indices[14] = 9, indices[15] = 10, indices[16] = 8, indices[17] = 11, // Right
|
|
15474
|
-
indices[18] = 12, indices[19] = 14, indices[20] = 15, indices[21] = 14, indices[22] = 12, indices[23] = 13, // Front
|
|
15475
|
-
indices[24] = 16, indices[25] = 18, indices[26] = 17, indices[27] = 18, indices[28] = 16, indices[29] = 19, // Back
|
|
15476
|
-
indices[30] = 20, indices[31] = 22, indices[32] = 23, indices[33] = 22, indices[34] = 20, indices[35] = 21;
|
|
15477
|
-
if (!isRestoreMode) {
|
|
15478
|
-
var bounds = cuboidMesh.bounds;
|
|
15479
|
-
bounds.min.set(-halfWidth, -halfHeight, -halfDepth);
|
|
15480
|
-
bounds.max.set(halfWidth, halfHeight, halfDepth);
|
|
15481
|
-
}
|
|
15482
|
-
PrimitiveMesh._initialize(cuboidMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
|
|
15483
|
-
};
|
|
15484
|
-
/**
|
|
15485
|
-
* @internal
|
|
15486
|
-
*/ PrimitiveMesh._setPlaneData = function _setPlaneData(planeMesh, width, height, horizontalSegments, verticalSegments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
|
|
15487
|
-
horizontalSegments = Math.max(1, Math.floor(horizontalSegments));
|
|
15488
|
-
verticalSegments = Math.max(1, Math.floor(verticalSegments));
|
|
15489
|
-
var horizontalCount = horizontalSegments + 1;
|
|
15490
|
-
var verticalCount = verticalSegments + 1;
|
|
15491
|
-
var halfWidth = width / 2;
|
|
15492
|
-
var halfHeight = height / 2;
|
|
15493
|
-
var gridWidth = width / horizontalSegments;
|
|
15494
|
-
var gridHeight = height / verticalSegments;
|
|
15495
|
-
var vertexCount = horizontalCount * verticalCount;
|
|
15496
|
-
var rectangleCount = verticalSegments * horizontalSegments;
|
|
15497
|
-
var indices = PrimitiveMesh._generateIndices(planeMesh.engine, vertexCount, rectangleCount * 6);
|
|
15498
|
-
var horizontalCountReciprocal = 1.0 / horizontalCount;
|
|
15499
|
-
var horizontalSegmentsReciprocal = 1.0 / horizontalSegments;
|
|
15500
|
-
var verticalSegmentsReciprocal = 1.0 / verticalSegments;
|
|
15501
|
-
var vertexFloatCount = 8;
|
|
15502
|
-
var vertices = new Float32Array(vertexCount * vertexFloatCount);
|
|
15503
|
-
for(var i = 0; i < vertexCount; ++i){
|
|
15504
|
-
var x = i % horizontalCount;
|
|
15505
|
-
var z = i * horizontalCountReciprocal | 0;
|
|
15506
|
-
var offset = i * vertexFloatCount;
|
|
15507
|
-
// Position
|
|
15508
|
-
vertices[offset++] = x * gridWidth - halfWidth;
|
|
15509
|
-
vertices[offset++] = 0;
|
|
15510
|
-
vertices[offset++] = z * gridHeight - halfHeight;
|
|
15511
|
-
// Normal
|
|
15512
|
-
vertices[offset++] = 0;
|
|
15513
|
-
vertices[offset++] = 1;
|
|
15514
|
-
vertices[offset++] = 0;
|
|
15515
|
-
// TexCoord
|
|
15516
|
-
vertices[offset++] = x * horizontalSegmentsReciprocal;
|
|
15517
|
-
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]);
|
|
15518
17290
|
}
|
|
15519
|
-
var
|
|
15520
|
-
|
|
15521
|
-
|
|
15522
|
-
|
|
15523
|
-
|
|
15524
|
-
|
|
15525
|
-
|
|
15526
|
-
|
|
15527
|
-
|
|
15528
|
-
|
|
15529
|
-
|
|
15530
|
-
|
|
15531
|
-
|
|
15532
|
-
|
|
15533
|
-
|
|
15534
|
-
|
|
15535
|
-
|
|
15536
|
-
|
|
15537
|
-
|
|
15538
|
-
|
|
15539
|
-
|
|
15540
|
-
|
|
15541
|
-
|
|
15542
|
-
|
|
15543
|
-
|
|
15544
|
-
|
|
15545
|
-
|
|
15546
|
-
if (height === void 0) height = 2;
|
|
15547
|
-
if (radialSegments === void 0) radialSegments = 20;
|
|
15548
|
-
if (heightSegments === void 0) heightSegments = 1;
|
|
15549
|
-
radialSegments = Math.floor(radialSegments);
|
|
15550
|
-
heightSegments = Math.floor(heightSegments);
|
|
15551
|
-
var radialCount = radialSegments + 1;
|
|
15552
|
-
var verticalCount = heightSegments + 1;
|
|
15553
|
-
var halfHeight = height * 0.5;
|
|
15554
|
-
var unitHeight = height / heightSegments;
|
|
15555
|
-
var torsoVertexCount = radialCount * verticalCount;
|
|
15556
|
-
var torsoRectangleCount = radialSegments * heightSegments;
|
|
15557
|
-
var capTriangleCount = radialSegments * 2;
|
|
15558
|
-
var totalVertexCount = torsoVertexCount + 2 + capTriangleCount;
|
|
15559
|
-
var indices = PrimitiveMesh._generateIndices(cylinderMesh.engine, totalVertexCount, torsoRectangleCount * 6 + capTriangleCount * 3);
|
|
15560
|
-
var radialCountReciprocal = 1.0 / radialCount;
|
|
15561
|
-
var radialSegmentsReciprocal = 1.0 / radialSegments;
|
|
15562
|
-
var heightSegmentsReciprocal = 1.0 / heightSegments;
|
|
15563
|
-
var vertexFloatCount = 8;
|
|
15564
|
-
var vertices = new Float32Array(totalVertexCount * vertexFloatCount);
|
|
15565
|
-
var indicesOffset = 0;
|
|
15566
|
-
// Create torso
|
|
15567
|
-
var thetaStart = Math.PI;
|
|
15568
|
-
var thetaRange = Math.PI * 2;
|
|
15569
|
-
var radiusDiff = radiusBottom - radiusTop;
|
|
15570
|
-
var slope = radiusDiff / height;
|
|
15571
|
-
var radiusSlope = radiusDiff / heightSegments;
|
|
15572
|
-
for(var i = 0; i < torsoVertexCount; ++i){
|
|
15573
|
-
var x = i % radialCount;
|
|
15574
|
-
var y = i * radialCountReciprocal | 0;
|
|
15575
|
-
var u = x * radialSegmentsReciprocal;
|
|
15576
|
-
var v = y * heightSegmentsReciprocal;
|
|
15577
|
-
var theta = thetaStart + u * thetaRange;
|
|
15578
|
-
var sinTheta = Math.sin(theta);
|
|
15579
|
-
var cosTheta = Math.cos(theta);
|
|
15580
|
-
var radius = radiusBottom - y * radiusSlope;
|
|
15581
|
-
var posX = radius * sinTheta;
|
|
15582
|
-
var posY = y * unitHeight - halfHeight;
|
|
15583
|
-
var posZ = radius * cosTheta;
|
|
15584
|
-
var offset = i * vertexFloatCount;
|
|
15585
|
-
// Position
|
|
15586
|
-
vertices[offset++] = posX;
|
|
15587
|
-
vertices[offset++] = posY;
|
|
15588
|
-
vertices[offset++] = posZ;
|
|
15589
|
-
// Normal
|
|
15590
|
-
vertices[offset++] = sinTheta;
|
|
15591
|
-
vertices[offset++] = slope;
|
|
15592
|
-
vertices[offset++] = cosTheta;
|
|
15593
|
-
// TexCoord
|
|
15594
|
-
vertices[offset++] = u;
|
|
15595
|
-
vertices[offset++] = 1 - v;
|
|
15596
|
-
}
|
|
15597
|
-
for(var i1 = 0; i1 < torsoRectangleCount; ++i1){
|
|
15598
|
-
var x1 = i1 % radialSegments;
|
|
15599
|
-
var y1 = i1 * radialSegmentsReciprocal | 0;
|
|
15600
|
-
var a = y1 * radialCount + x1;
|
|
15601
|
-
var b = a + 1;
|
|
15602
|
-
var c = a + radialCount;
|
|
15603
|
-
var d = c + 1;
|
|
15604
|
-
indices[indicesOffset++] = b;
|
|
15605
|
-
indices[indicesOffset++] = c;
|
|
15606
|
-
indices[indicesOffset++] = a;
|
|
15607
|
-
indices[indicesOffset++] = b;
|
|
15608
|
-
indices[indicesOffset++] = d;
|
|
15609
|
-
indices[indicesOffset++] = c;
|
|
15610
|
-
}
|
|
15611
|
-
var offset1 = torsoVertexCount * vertexFloatCount;
|
|
15612
|
-
// Bottom position
|
|
15613
|
-
vertices[offset1++] = 0;
|
|
15614
|
-
vertices[offset1++] = -halfHeight;
|
|
15615
|
-
vertices[offset1++] = 0;
|
|
15616
|
-
// Bottom normal
|
|
15617
|
-
vertices[offset1++] = 0;
|
|
15618
|
-
vertices[offset1++] = -1;
|
|
15619
|
-
vertices[offset1++] = 0;
|
|
15620
|
-
// Bottom texCoord
|
|
15621
|
-
vertices[offset1++] = 0.5;
|
|
15622
|
-
vertices[offset1++] = 0.5;
|
|
15623
|
-
// Top position
|
|
15624
|
-
vertices[offset1++] = 0;
|
|
15625
|
-
vertices[offset1++] = halfHeight;
|
|
15626
|
-
vertices[offset1++] = 0;
|
|
15627
|
-
// Top normal
|
|
15628
|
-
vertices[offset1++] = 0;
|
|
15629
|
-
vertices[offset1++] = 1;
|
|
15630
|
-
vertices[offset1++] = 0;
|
|
15631
|
-
// Top texCoord
|
|
15632
|
-
vertices[offset1++] = 0.5;
|
|
15633
|
-
vertices[offset1++] = 0.5;
|
|
15634
|
-
// Add cap vertices
|
|
15635
|
-
offset1 = (torsoVertexCount + 2) * vertexFloatCount;
|
|
15636
|
-
var diameterTopReciprocal = 1.0 / (radiusTop * 2);
|
|
15637
|
-
var diameterBottomReciprocal = 1.0 / (radiusBottom * 2);
|
|
15638
|
-
var positionStride = radialCount * heightSegments;
|
|
15639
|
-
for(var i2 = 0; i2 < radialSegments; ++i2){
|
|
15640
|
-
var curPosBottomOffset = i2 * vertexFloatCount;
|
|
15641
|
-
var curPosX = vertices[curPosBottomOffset];
|
|
15642
|
-
var curPosZ = vertices[curPosBottomOffset + 2];
|
|
15643
|
-
// Bottom position
|
|
15644
|
-
vertices[offset1++] = curPosX;
|
|
15645
|
-
vertices[offset1++] = -halfHeight;
|
|
15646
|
-
vertices[offset1++] = curPosZ;
|
|
15647
|
-
// Bottom normal
|
|
15648
|
-
vertices[offset1++] = 0;
|
|
15649
|
-
vertices[offset1++] = -1;
|
|
15650
|
-
vertices[offset1++] = 0;
|
|
15651
|
-
// Bottom texcoord
|
|
15652
|
-
vertices[offset1++] = curPosX * diameterBottomReciprocal + 0.5;
|
|
15653
|
-
vertices[offset1++] = 0.5 - curPosZ * diameterBottomReciprocal;
|
|
15654
|
-
var curPosTopOffset = (i2 + positionStride) * vertexFloatCount;
|
|
15655
|
-
curPosX = vertices[curPosTopOffset];
|
|
15656
|
-
curPosZ = vertices[curPosTopOffset + 2];
|
|
15657
|
-
// Top position
|
|
15658
|
-
vertices[offset1++] = curPosX;
|
|
15659
|
-
vertices[offset1++] = halfHeight;
|
|
15660
|
-
vertices[offset1++] = curPosZ;
|
|
15661
|
-
// Top normal
|
|
15662
|
-
vertices[offset1++] = 0;
|
|
15663
|
-
vertices[offset1++] = 1;
|
|
15664
|
-
vertices[offset1++] = 0;
|
|
15665
|
-
// Top texcoord
|
|
15666
|
-
vertices[offset1++] = curPosX * diameterTopReciprocal + 0.5;
|
|
15667
|
-
vertices[offset1++] = 0.5 - curPosZ * diameterTopReciprocal;
|
|
15668
|
-
}
|
|
15669
|
-
// Add cap indices
|
|
15670
|
-
var topCapIndex = torsoVertexCount + 1;
|
|
15671
|
-
var bottomIndiceIndex = torsoVertexCount + 2;
|
|
15672
|
-
var topIndiceIndex = bottomIndiceIndex + 1;
|
|
15673
|
-
for(var i3 = 0; i3 < radialSegments; ++i3){
|
|
15674
|
-
var firstStride = i3 * 2;
|
|
15675
|
-
var secondStride = i3 === radialSegments - 1 ? 0 : firstStride + 2;
|
|
15676
|
-
// Bottom
|
|
15677
|
-
indices[indicesOffset++] = torsoVertexCount;
|
|
15678
|
-
indices[indicesOffset++] = bottomIndiceIndex + secondStride;
|
|
15679
|
-
indices[indicesOffset++] = bottomIndiceIndex + firstStride;
|
|
15680
|
-
// Top
|
|
15681
|
-
indices[indicesOffset++] = topCapIndex;
|
|
15682
|
-
indices[indicesOffset++] = topIndiceIndex + firstStride;
|
|
15683
|
-
indices[indicesOffset++] = topIndiceIndex + secondStride;
|
|
15684
|
-
}
|
|
15685
|
-
if (!isRestoreMode) {
|
|
15686
|
-
var bounds = cylinderMesh.bounds;
|
|
15687
|
-
var radiusMax = Math.max(radiusTop, radiusBottom);
|
|
15688
|
-
bounds.min.set(-radiusMax, -halfHeight, -radiusMax);
|
|
15689
|
-
bounds.max.set(radiusMax, halfHeight, radiusMax);
|
|
15690
|
-
}
|
|
15691
|
-
PrimitiveMesh._initialize(cylinderMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
|
|
15692
|
-
};
|
|
15693
|
-
/**
|
|
15694
|
-
* @internal
|
|
15695
|
-
*/ PrimitiveMesh._setTorusData = function _setTorusData(torusMesh, radius, tubeRadius, radialSegments, tubularSegments, arc, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
|
|
15696
|
-
radialSegments = Math.floor(radialSegments);
|
|
15697
|
-
tubularSegments = Math.floor(tubularSegments);
|
|
15698
|
-
var vertexCount = (radialSegments + 1) * (tubularSegments + 1);
|
|
15699
|
-
var rectangleCount = radialSegments * tubularSegments;
|
|
15700
|
-
var indices = PrimitiveMesh._generateIndices(torusMesh.engine, vertexCount, rectangleCount * 6);
|
|
15701
|
-
var vertexFloatCount = 8;
|
|
15702
|
-
var vertices = new Float32Array(vertexCount * vertexFloatCount);
|
|
15703
|
-
arc = arc / 180 * Math.PI;
|
|
15704
|
-
var offset = 0;
|
|
15705
|
-
var normal = PrimitiveMesh._tempVec30;
|
|
15706
|
-
for(var i = 0; i <= radialSegments; i++){
|
|
15707
|
-
for(var j = 0; j <= tubularSegments; j++){
|
|
15708
|
-
var u = j / tubularSegments * arc;
|
|
15709
|
-
var v = i / radialSegments * Math.PI * 2;
|
|
15710
|
-
var cosV = Math.cos(v);
|
|
15711
|
-
var sinV = Math.sin(v);
|
|
15712
|
-
var cosU = Math.cos(u);
|
|
15713
|
-
var sinU = Math.sin(u);
|
|
15714
|
-
// Position
|
|
15715
|
-
var positionX = (radius + tubeRadius * cosV) * cosU;
|
|
15716
|
-
var positionY = (radius + tubeRadius * cosV) * sinU;
|
|
15717
|
-
var positionZ = tubeRadius * sinV;
|
|
15718
|
-
vertices[offset++] = positionX;
|
|
15719
|
-
vertices[offset++] = positionY;
|
|
15720
|
-
vertices[offset++] = positionZ;
|
|
15721
|
-
// Normal
|
|
15722
|
-
var centerX = radius * cosU;
|
|
15723
|
-
var centerY = radius * sinU;
|
|
15724
|
-
normal.set(positionX - centerX, positionY - centerY, positionZ).normalize();
|
|
15725
|
-
vertices[offset++] = normal.x;
|
|
15726
|
-
vertices[offset++] = normal.y;
|
|
15727
|
-
vertices[offset++] = normal.z;
|
|
15728
|
-
// UV
|
|
15729
|
-
vertices[offset++] = j / tubularSegments;
|
|
15730
|
-
vertices[offset++] = i / radialSegments;
|
|
15731
|
-
}
|
|
15732
|
-
}
|
|
15733
|
-
offset = 0;
|
|
15734
|
-
for(var i1 = 1; i1 <= radialSegments; i1++){
|
|
15735
|
-
for(var j1 = 1; j1 <= tubularSegments; j1++){
|
|
15736
|
-
var a = (tubularSegments + 1) * i1 + j1 - 1;
|
|
15737
|
-
var b = (tubularSegments + 1) * (i1 - 1) + j1 - 1;
|
|
15738
|
-
var c = (tubularSegments + 1) * (i1 - 1) + j1;
|
|
15739
|
-
var d = (tubularSegments + 1) * i1 + j1;
|
|
15740
|
-
indices[offset++] = a;
|
|
15741
|
-
indices[offset++] = b;
|
|
15742
|
-
indices[offset++] = d;
|
|
15743
|
-
indices[offset++] = b;
|
|
15744
|
-
indices[offset++] = c;
|
|
15745
|
-
indices[offset++] = d;
|
|
15746
|
-
}
|
|
15747
|
-
}
|
|
15748
|
-
if (!isRestoreMode) {
|
|
15749
|
-
var bounds = torusMesh.bounds;
|
|
15750
|
-
var outerRadius = radius + tubeRadius;
|
|
15751
|
-
bounds.min.set(-outerRadius, -outerRadius, -tubeRadius);
|
|
15752
|
-
bounds.max.set(outerRadius, outerRadius, tubeRadius);
|
|
15753
|
-
}
|
|
15754
|
-
PrimitiveMesh._initialize(torusMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
|
|
15755
|
-
};
|
|
15756
|
-
/**
|
|
15757
|
-
* @internal
|
|
15758
|
-
*/ PrimitiveMesh._setConeData = function _setConeData(coneMesh, radius, height, radialSegments, heightSegments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
|
|
15759
|
-
radialSegments = Math.floor(radialSegments);
|
|
15760
|
-
heightSegments = Math.floor(heightSegments);
|
|
15761
|
-
var radialCount = radialSegments + 1;
|
|
15762
|
-
var verticalCount = heightSegments + 1;
|
|
15763
|
-
var halfHeight = height * 0.5;
|
|
15764
|
-
var unitHeight = height / heightSegments;
|
|
15765
|
-
var torsoVertexCount = radialCount * verticalCount;
|
|
15766
|
-
var torsoRectangleCount = radialSegments * heightSegments;
|
|
15767
|
-
var totalVertexCount = torsoVertexCount + 1 + radialSegments;
|
|
15768
|
-
var indices = PrimitiveMesh._generateIndices(coneMesh.engine, totalVertexCount, torsoRectangleCount * 6 + radialSegments * 3);
|
|
15769
|
-
var radialCountReciprocal = 1.0 / radialCount;
|
|
15770
|
-
var radialSegmentsReciprocal = 1.0 / radialSegments;
|
|
15771
|
-
var heightSegmentsReciprocal = 1.0 / heightSegments;
|
|
15772
|
-
var vertexFloatCount = 8;
|
|
15773
|
-
var vertices = new Float32Array(totalVertexCount * 8);
|
|
15774
|
-
var indicesOffset = 0;
|
|
15775
|
-
// Create torso
|
|
15776
|
-
var thetaStart = Math.PI;
|
|
15777
|
-
var thetaRange = Math.PI * 2;
|
|
15778
|
-
var slope = radius / height;
|
|
15779
|
-
for(var i = 0; i < torsoVertexCount; ++i){
|
|
15780
|
-
var x = i % radialCount;
|
|
15781
|
-
var y = i * radialCountReciprocal | 0;
|
|
15782
|
-
var u = x * radialSegmentsReciprocal;
|
|
15783
|
-
var v = y * heightSegmentsReciprocal;
|
|
15784
|
-
var theta = thetaStart + u * thetaRange;
|
|
15785
|
-
var sinTheta = Math.sin(theta);
|
|
15786
|
-
var cosTheta = Math.cos(theta);
|
|
15787
|
-
var curRadius = radius - v * radius;
|
|
15788
|
-
var posX = curRadius * sinTheta;
|
|
15789
|
-
var posY = y * unitHeight - halfHeight;
|
|
15790
|
-
var posZ = curRadius * cosTheta;
|
|
15791
|
-
var offset = i * vertexFloatCount;
|
|
15792
|
-
// Position
|
|
15793
|
-
vertices[offset++] = posX;
|
|
15794
|
-
vertices[offset++] = posY;
|
|
15795
|
-
vertices[offset++] = posZ;
|
|
15796
|
-
// Normal
|
|
15797
|
-
vertices[offset++] = sinTheta;
|
|
15798
|
-
vertices[offset++] = slope;
|
|
15799
|
-
vertices[offset++] = cosTheta;
|
|
15800
|
-
// Texcoord
|
|
15801
|
-
vertices[offset++] = u;
|
|
15802
|
-
vertices[offset++] = 1 - v;
|
|
15803
|
-
}
|
|
15804
|
-
for(var i1 = 0; i1 < torsoRectangleCount; ++i1){
|
|
15805
|
-
var x1 = i1 % radialSegments;
|
|
15806
|
-
var y1 = i1 * radialSegmentsReciprocal | 0;
|
|
15807
|
-
var a = y1 * radialCount + x1;
|
|
15808
|
-
var b = a + 1;
|
|
15809
|
-
var c = a + radialCount;
|
|
15810
|
-
var d = c + 1;
|
|
15811
|
-
indices[indicesOffset++] = b;
|
|
15812
|
-
indices[indicesOffset++] = c;
|
|
15813
|
-
indices[indicesOffset++] = a;
|
|
15814
|
-
indices[indicesOffset++] = b;
|
|
15815
|
-
indices[indicesOffset++] = d;
|
|
15816
|
-
indices[indicesOffset++] = c;
|
|
15817
|
-
}
|
|
15818
|
-
var offset1 = torsoVertexCount * vertexFloatCount;
|
|
15819
|
-
// Bottom position
|
|
15820
|
-
vertices[offset1++] = 0;
|
|
15821
|
-
vertices[offset1++] = -halfHeight;
|
|
15822
|
-
vertices[offset1++] = 0;
|
|
15823
|
-
// Bottom normal
|
|
15824
|
-
vertices[offset1++] = 0;
|
|
15825
|
-
vertices[offset1++] = -1;
|
|
15826
|
-
vertices[offset1++] = 0;
|
|
15827
|
-
// Bottom texcoord
|
|
15828
|
-
vertices[offset1++] = 0.5;
|
|
15829
|
-
vertices[offset1++] = 0.5;
|
|
15830
|
-
// Add bottom cap vertices
|
|
15831
|
-
offset1 = (torsoVertexCount + 1) * vertexFloatCount;
|
|
15832
|
-
var diameterBottomReciprocal = 1.0 / (radius * 2);
|
|
15833
|
-
for(var i2 = 0; i2 < radialSegments; ++i2){
|
|
15834
|
-
var curPosX = vertices[i2 * vertexFloatCount];
|
|
15835
|
-
var curPosZ = vertices[i2 * vertexFloatCount + 2];
|
|
15836
|
-
// Bottom position
|
|
15837
|
-
vertices[offset1++] = curPosX;
|
|
15838
|
-
vertices[offset1++] = -halfHeight;
|
|
15839
|
-
vertices[offset1++] = curPosZ;
|
|
15840
|
-
// Bottom normal
|
|
15841
|
-
vertices[offset1++] = 0;
|
|
15842
|
-
vertices[offset1++] = -1;
|
|
15843
|
-
vertices[offset1++] = 0;
|
|
15844
|
-
// Bottom texcoord
|
|
15845
|
-
vertices[offset1++] = curPosX * diameterBottomReciprocal + 0.5;
|
|
15846
|
-
vertices[offset1++] = 0.5 - curPosZ * diameterBottomReciprocal;
|
|
15847
|
-
}
|
|
15848
|
-
var bottomIndiceIndex = torsoVertexCount + 1;
|
|
15849
|
-
for(var i3 = 0; i3 < radialSegments; ++i3){
|
|
15850
|
-
var firstStride = i3;
|
|
15851
|
-
var secondStride = i3 === radialSegments - 1 ? 0 : firstStride + 1;
|
|
15852
|
-
// Bottom
|
|
15853
|
-
indices[indicesOffset++] = torsoVertexCount;
|
|
15854
|
-
indices[indicesOffset++] = bottomIndiceIndex + secondStride;
|
|
15855
|
-
indices[indicesOffset++] = bottomIndiceIndex + firstStride;
|
|
15856
|
-
}
|
|
15857
|
-
if (!isRestoreMode) {
|
|
15858
|
-
var bounds = coneMesh.bounds;
|
|
15859
|
-
bounds.min.set(-radius, -halfHeight, -radius);
|
|
15860
|
-
bounds.max.set(radius, halfHeight, radius);
|
|
15861
|
-
}
|
|
15862
|
-
PrimitiveMesh._initialize(coneMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
|
|
15863
|
-
};
|
|
15864
|
-
/**
|
|
15865
|
-
* @internal
|
|
15866
|
-
*/ PrimitiveMesh._setCapsuleData = function _setCapsuleData(capsuleMesh, radius, height, radialSegments, heightSegments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
|
|
15867
|
-
radialSegments = Math.max(2, Math.floor(radialSegments));
|
|
15868
|
-
heightSegments = Math.floor(heightSegments);
|
|
15869
|
-
var radialCount = radialSegments + 1;
|
|
15870
|
-
var verticalCount = heightSegments + 1;
|
|
15871
|
-
var halfHeight = height * 0.5;
|
|
15872
|
-
var unitHeight = height / heightSegments;
|
|
15873
|
-
var torsoVertexCount = radialCount * verticalCount;
|
|
15874
|
-
var torsoRectangleCount = radialSegments * heightSegments;
|
|
15875
|
-
var capVertexCount = radialCount * radialCount;
|
|
15876
|
-
var capRectangleCount = radialSegments * radialSegments;
|
|
15877
|
-
var totalVertexCount = torsoVertexCount + 2 * capVertexCount;
|
|
15878
|
-
var indices = PrimitiveMesh._generateIndices(capsuleMesh.engine, totalVertexCount, (torsoRectangleCount + 2 * capRectangleCount) * 6);
|
|
15879
|
-
var radialCountReciprocal = 1.0 / radialCount;
|
|
15880
|
-
var radialSegmentsReciprocal = 1.0 / radialSegments;
|
|
15881
|
-
var heightSegmentsReciprocal = 1.0 / heightSegments;
|
|
15882
|
-
var thetaStart = Math.PI;
|
|
15883
|
-
var thetaRange = Math.PI * 2;
|
|
15884
|
-
var vertexFloatCount = 8;
|
|
15885
|
-
var vertices = new Float32Array(totalVertexCount * vertexFloatCount);
|
|
15886
|
-
var indicesOffset = 0;
|
|
15887
|
-
// create torso
|
|
15888
|
-
for(var i = 0; i < torsoVertexCount; ++i){
|
|
15889
|
-
var x = i % radialCount;
|
|
15890
|
-
var y = i * radialCountReciprocal | 0;
|
|
15891
|
-
var u = x * radialSegmentsReciprocal;
|
|
15892
|
-
var v = y * heightSegmentsReciprocal;
|
|
15893
|
-
var theta = thetaStart + u * thetaRange;
|
|
15894
|
-
var sinTheta = Math.sin(theta);
|
|
15895
|
-
var cosTheta = Math.cos(theta);
|
|
15896
|
-
var offset = i * vertexFloatCount;
|
|
15897
|
-
// position
|
|
15898
|
-
vertices[offset++] = radius * sinTheta;
|
|
15899
|
-
vertices[offset++] = y * unitHeight - halfHeight;
|
|
15900
|
-
vertices[offset++] = radius * cosTheta;
|
|
15901
|
-
// Normal
|
|
15902
|
-
vertices[offset++] = sinTheta;
|
|
15903
|
-
vertices[offset++] = 0;
|
|
15904
|
-
vertices[offset++] = cosTheta;
|
|
15905
|
-
// Texcoord
|
|
15906
|
-
vertices[offset++] = u;
|
|
15907
|
-
vertices[offset++] = 1 - v;
|
|
15908
|
-
}
|
|
15909
|
-
for(var i1 = 0; i1 < torsoRectangleCount; ++i1){
|
|
15910
|
-
var x1 = i1 % radialSegments;
|
|
15911
|
-
var y1 = i1 * radialSegmentsReciprocal | 0;
|
|
15912
|
-
var a = y1 * radialCount + x1;
|
|
15913
|
-
var b = a + 1;
|
|
15914
|
-
var c = a + radialCount;
|
|
15915
|
-
var d = c + 1;
|
|
15916
|
-
indices[indicesOffset++] = b;
|
|
15917
|
-
indices[indicesOffset++] = c;
|
|
15918
|
-
indices[indicesOffset++] = a;
|
|
15919
|
-
indices[indicesOffset++] = b;
|
|
15920
|
-
indices[indicesOffset++] = d;
|
|
15921
|
-
indices[indicesOffset++] = c;
|
|
15922
|
-
}
|
|
15923
|
-
PrimitiveMesh._createCapsuleCap(radius, height, radialSegments, thetaStart, thetaRange, torsoVertexCount, 1, vertices, indices, indicesOffset);
|
|
15924
|
-
PrimitiveMesh._createCapsuleCap(radius, height, radialSegments, thetaStart, -thetaRange, torsoVertexCount + capVertexCount, -1, vertices, indices, indicesOffset + 6 * capRectangleCount);
|
|
15925
|
-
if (!isRestoreMode) {
|
|
15926
|
-
var bounds = capsuleMesh.bounds;
|
|
15927
|
-
bounds.min.set(-radius, -radius - halfHeight, -radius);
|
|
15928
|
-
bounds.max.set(radius, radius + halfHeight, radius);
|
|
15929
|
-
}
|
|
15930
|
-
PrimitiveMesh._initialize(capsuleMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
|
|
15931
|
-
};
|
|
15932
|
-
PrimitiveMesh._initialize = function _initialize(mesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
|
|
15933
|
-
if (isRestoreMode) {
|
|
15934
|
-
restoreVertexBuffer.setData(vertices);
|
|
15935
|
-
mesh.setIndices(indices);
|
|
15936
|
-
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
|
+
}
|
|
15937
17318
|
} else {
|
|
15938
|
-
var vertexElements = [
|
|
15939
|
-
new VertexElement(VertexAttribute.Position, 0, VertexElementFormat.Vector3, 0),
|
|
15940
|
-
new VertexElement(VertexAttribute.Normal, 12, VertexElementFormat.Vector3, 0),
|
|
15941
|
-
new VertexElement(VertexAttribute.UV, 24, VertexElementFormat.Vector2, 0)
|
|
15942
|
-
];
|
|
15943
|
-
mesh.setVertexElements(vertexElements);
|
|
15944
|
-
var vertexBuffer = new Buffer(mesh.engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
|
|
15945
|
-
mesh.setVertexBufferBinding(vertexBuffer, 32, 0);
|
|
15946
|
-
mesh.setIndices(indices);
|
|
15947
|
-
mesh.calculateTangents();
|
|
15948
|
-
mesh.uploadData(noLongerAccessible);
|
|
15949
17319
|
mesh.addSubMesh(0, indices.length);
|
|
15950
17320
|
}
|
|
17321
|
+
engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(mesh, generate, args));
|
|
17322
|
+
return mesh;
|
|
15951
17323
|
};
|
|
15952
|
-
PrimitiveMesh.
|
|
15953
|
-
|
|
15954
|
-
|
|
15955
|
-
|
|
15956
|
-
|
|
15957
|
-
|
|
15958
|
-
|
|
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
|
|
15959
17336
|
}
|
|
15960
|
-
|
|
15961
|
-
|
|
15962
|
-
|
|
15963
|
-
|
|
15964
|
-
|
|
15965
|
-
|
|
15966
|
-
|
|
15967
|
-
|
|
15968
|
-
|
|
15969
|
-
var
|
|
15970
|
-
var
|
|
15971
|
-
var
|
|
15972
|
-
|
|
15973
|
-
|
|
15974
|
-
|
|
15975
|
-
|
|
15976
|
-
|
|
15977
|
-
|
|
15978
|
-
var theta = thetaStart + u * thetaRange;
|
|
15979
|
-
var alpha = v * Math.PI * 0.5;
|
|
15980
|
-
var sinAlpha = Math.sin(alpha);
|
|
15981
|
-
var posX = radius * Math.sin(theta) * sinAlpha;
|
|
15982
|
-
var posY = radius * Math.cos(alpha) * posIndex + halfHeight;
|
|
15983
|
-
var posZ = radius * Math.cos(theta) * sinAlpha;
|
|
15984
|
-
var index = (i + offset) * vertexFloatCount;
|
|
15985
|
-
// Position
|
|
15986
|
-
vertices[index++] = posX;
|
|
15987
|
-
vertices[index++] = posY;
|
|
15988
|
-
vertices[index++] = posZ;
|
|
15989
|
-
// Normal
|
|
15990
|
-
vertices[index++] = posX;
|
|
15991
|
-
vertices[index++] = posY - halfHeight;
|
|
15992
|
-
vertices[index++] = posZ;
|
|
15993
|
-
// Texcoord
|
|
15994
|
-
vertices[index++] = u;
|
|
15995
|
-
vertices[index++] = v;
|
|
15996
|
-
}
|
|
15997
|
-
for(var i1 = 0; i1 < capRectangleCount; ++i1){
|
|
15998
|
-
var x1 = i1 % radialSegments;
|
|
15999
|
-
var y1 = i1 * radialSegmentsReciprocal | 0;
|
|
16000
|
-
var a = y1 * radialCount + x1 + offset;
|
|
16001
|
-
var b = a + 1;
|
|
16002
|
-
var c = a + radialCount;
|
|
16003
|
-
var d = c + 1;
|
|
16004
|
-
indices[indicesOffset++] = b;
|
|
16005
|
-
indices[indicesOffset++] = a;
|
|
16006
|
-
indices[indicesOffset++] = d;
|
|
16007
|
-
indices[indicesOffset++] = a;
|
|
16008
|
-
indices[indicesOffset++] = c;
|
|
16009
|
-
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]);
|
|
16010
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);
|
|
16011
17397
|
};
|
|
16012
17398
|
return PrimitiveMesh;
|
|
16013
17399
|
}();
|
|
16014
|
-
PrimitiveMesh._tempVec30 = new engineMath.Vector3();
|
|
16015
17400
|
PrimitiveMesh._sphereSeedPositions = new Float32Array([
|
|
16016
17401
|
-1,
|
|
16017
17402
|
1,
|
|
@@ -16064,8 +17449,364 @@ PrimitiveMesh._sphereSeedCells = new Float32Array([
|
|
|
16064
17449
|
2,
|
|
16065
17450
|
1
|
|
16066
17451
|
]);
|
|
16067
|
-
PrimitiveMesh.
|
|
16068
|
-
PrimitiveMesh.
|
|
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
|
+
};
|
|
16069
17810
|
|
|
16070
17811
|
/**
|
|
16071
17812
|
* Skin used for skinned mesh renderer.
|
|
@@ -16436,7 +18177,7 @@ __decorate([
|
|
|
16436
18177
|
/**
|
|
16437
18178
|
* @internal
|
|
16438
18179
|
*/ var BasicResources = /*#__PURE__*/ function() {
|
|
16439
|
-
function BasicResources(engine) {
|
|
18180
|
+
function BasicResources(engine, shaders) {
|
|
16440
18181
|
this.engine = engine;
|
|
16441
18182
|
// prettier-ignore
|
|
16442
18183
|
var vertices = new Float32Array([
|
|
@@ -16468,9 +18209,9 @@ __decorate([
|
|
|
16468
18209
|
0,
|
|
16469
18210
|
2
|
|
16470
18211
|
]); // left-top
|
|
16471
|
-
var blitMaterial = new Material(engine,
|
|
18212
|
+
var blitMaterial = new Material(engine, shaders.blit);
|
|
16472
18213
|
blitMaterial._addReferCount(1);
|
|
16473
|
-
var blitScreenMaterial = new Material(engine,
|
|
18214
|
+
var blitScreenMaterial = new Material(engine, shaders.blitScreen);
|
|
16474
18215
|
blitScreenMaterial._addReferCount(1);
|
|
16475
18216
|
this.blitMaterial = blitMaterial;
|
|
16476
18217
|
this.blitScreenMaterial = blitScreenMaterial;
|
|
@@ -16496,11 +18237,11 @@ __decorate([
|
|
|
16496
18237
|
]);
|
|
16497
18238
|
this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
|
|
16498
18239
|
}
|
|
16499
|
-
this.spriteDefaultMaterial = this._create2DMaterial(engine,
|
|
16500
|
-
this.textDefaultMaterial = this._create2DMaterial(engine,
|
|
16501
|
-
this.spriteMaskDefaultMaterial = this.
|
|
16502
|
-
this.meshMagentaMaterial = this._createMagentaMaterial(engine,
|
|
16503
|
-
this.particleMagentaMaterial = this._createMagentaMaterial(engine,
|
|
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);
|
|
16504
18245
|
}
|
|
16505
18246
|
var _proto = BasicResources.prototype;
|
|
16506
18247
|
/**
|
|
@@ -16595,17 +18336,12 @@ __decorate([
|
|
|
16595
18336
|
material.isGCIgnored = true;
|
|
16596
18337
|
return material;
|
|
16597
18338
|
};
|
|
16598
|
-
_proto._createMagentaMaterial = function _createMagentaMaterial(engine,
|
|
16599
|
-
var material = new BaseMaterial(engine,
|
|
18339
|
+
_proto._createMagentaMaterial = function _createMagentaMaterial(engine, shader) {
|
|
18340
|
+
var material = new BaseMaterial(engine, shader);
|
|
16600
18341
|
material.isGCIgnored = true;
|
|
16601
18342
|
material.shaderData.setColor("material_BaseColor", new engineMath.Color(1.0, 0.0, 1.01, 1.0));
|
|
16602
18343
|
return material;
|
|
16603
18344
|
};
|
|
16604
|
-
_proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
|
|
16605
|
-
var material = new Material(engine, Shader.find("2D/SpriteMask"));
|
|
16606
|
-
material.isGCIgnored = true;
|
|
16607
|
-
return material;
|
|
16608
|
-
};
|
|
16609
18345
|
BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
|
|
16610
18346
|
var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
|
|
16611
18347
|
var renderStates;
|
|
@@ -16764,12 +18500,6 @@ function _construct(Parent, args, Class) {
|
|
|
16764
18500
|
return Layer;
|
|
16765
18501
|
}({});
|
|
16766
18502
|
|
|
16767
|
-
function _type_of(obj) {
|
|
16768
|
-
"@swc/helpers - typeof";
|
|
16769
|
-
|
|
16770
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
16771
|
-
}
|
|
16772
|
-
|
|
16773
18503
|
/**
|
|
16774
18504
|
* @internal
|
|
16775
18505
|
*/ var CloneUtil = /*#__PURE__*/ function() {
|
|
@@ -23953,10 +25683,10 @@ var PostProcessUberPass = /*#__PURE__*/ function(PostProcessPass) {
|
|
|
23953
25683
|
_this = PostProcessPass.call(this, engine) || this, _this._mipDownRT = [], _this._mipUpRT = [];
|
|
23954
25684
|
_this.event = PostProcessPassEvent.AfterUber - 1;
|
|
23955
25685
|
// Uber Material
|
|
23956
|
-
var uberMaterial = new Material(engine,
|
|
25686
|
+
var uberMaterial = new Material(engine, Engine._builtinShaders.uber);
|
|
23957
25687
|
_this._uberMaterial = uberMaterial;
|
|
23958
25688
|
// Bloom Material
|
|
23959
|
-
var bloomMaterial = new Material(engine,
|
|
25689
|
+
var bloomMaterial = new Material(engine, Engine._builtinShaders.bloom);
|
|
23960
25690
|
_this._bloomMaterial = bloomMaterial;
|
|
23961
25691
|
// ShaderData initialization
|
|
23962
25692
|
var bloomShaderData = bloomMaterial.shaderData;
|
|
@@ -24331,7 +26061,7 @@ Sky._projectionMatrix = new engineMath.Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, Sky.
|
|
|
24331
26061
|
this._solidColor = new engineMath.Color(0.05087608817155679, 0.05087608817155679, 0.05087608817155679, 1.0);
|
|
24332
26062
|
this._texture = null;
|
|
24333
26063
|
this._initMesh(_engine);
|
|
24334
|
-
this._initMaterial(_engine);
|
|
26064
|
+
this._initMaterial(_engine, Engine._builtinShaders.backgroundTexture);
|
|
24335
26065
|
}
|
|
24336
26066
|
var _proto = Background.prototype;
|
|
24337
26067
|
/**
|
|
@@ -24396,8 +26126,8 @@ Sky._projectionMatrix = new engineMath.Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, Sky.
|
|
|
24396
26126
|
}(ContentRestorer))());
|
|
24397
26127
|
this._mesh._addReferCount(1);
|
|
24398
26128
|
};
|
|
24399
|
-
_proto._initMaterial = function _initMaterial(engine) {
|
|
24400
|
-
var material = this._material = new Material(engine,
|
|
26129
|
+
_proto._initMaterial = function _initMaterial(engine, shader) {
|
|
26130
|
+
var material = this._material = new Material(engine, shader);
|
|
24401
26131
|
material._addReferCount(1);
|
|
24402
26132
|
};
|
|
24403
26133
|
_proto._createPlane = function _createPlane(engine) {
|
|
@@ -25323,10 +27053,10 @@ exports.Camera = __decorate([
|
|
|
25323
27053
|
* Scalable Ambient Obscurance render pass.
|
|
25324
27054
|
*/ var ScalableAmbientObscurancePass = /*#__PURE__*/ function(PipelinePass) {
|
|
25325
27055
|
_inherits(ScalableAmbientObscurancePass, PipelinePass);
|
|
25326
|
-
function ScalableAmbientObscurancePass(engine) {
|
|
27056
|
+
function ScalableAmbientObscurancePass(engine, shader) {
|
|
25327
27057
|
var _this;
|
|
25328
27058
|
_this = PipelinePass.call(this, engine) || this, _this._invProjScaleXY = new engineMath.Vector2(), _this._offsetX = new engineMath.Vector4(), _this._offsetY = new engineMath.Vector4();
|
|
25329
|
-
var material = new Material(engine,
|
|
27059
|
+
var material = new Material(engine, shader);
|
|
25330
27060
|
material._addReferCount(1);
|
|
25331
27061
|
_this._material = material;
|
|
25332
27062
|
_this.isSupported = _this.engine._hardwareRenderer.capability.isFragmentHighPrecision;
|
|
@@ -25449,7 +27179,6 @@ exports.Camera = __decorate([
|
|
|
25449
27179
|
};
|
|
25450
27180
|
return ScalableAmbientObscurancePass;
|
|
25451
27181
|
}(PipelinePass);
|
|
25452
|
-
ScalableAmbientObscurancePass.SHADER_NAME = "Lighting/ScalableAmbientOcclusion";
|
|
25453
27182
|
ScalableAmbientObscurancePass._invRadiusSquaredProp = ShaderProperty.getByName("material_invRadiusSquared");
|
|
25454
27183
|
ScalableAmbientObscurancePass._intensityProp = ShaderProperty.getByName("material_intensity");
|
|
25455
27184
|
ScalableAmbientObscurancePass._projectionScaleRadiusProp = ShaderProperty.getByName("material_projectionScaleRadius");
|
|
@@ -25795,15 +27524,15 @@ PostProcessManager._tempVector3 = new engineMath.Vector3();
|
|
|
25795
27524
|
* Processing sRGB Conversion and FXAA.
|
|
25796
27525
|
*/ var FinalPass = /*#__PURE__*/ function(PipelinePass) {
|
|
25797
27526
|
_inherits(FinalPass, PipelinePass);
|
|
25798
|
-
function FinalPass(engine) {
|
|
27527
|
+
function FinalPass(engine, sRGBShader, antiAliasingShader) {
|
|
25799
27528
|
var _this;
|
|
25800
27529
|
_this = PipelinePass.call(this, engine) || this;
|
|
25801
27530
|
// SRGB Material
|
|
25802
|
-
var sRGBmaterial = new Material(engine,
|
|
27531
|
+
var sRGBmaterial = new Material(engine, sRGBShader);
|
|
25803
27532
|
sRGBmaterial._addReferCount(1);
|
|
25804
27533
|
_this._sRGBmaterial = sRGBmaterial;
|
|
25805
27534
|
// FXAA Material
|
|
25806
|
-
var antiAliasingMaterial = new Material(engine,
|
|
27535
|
+
var antiAliasingMaterial = new Material(engine, antiAliasingShader);
|
|
25807
27536
|
antiAliasingMaterial._addReferCount(1);
|
|
25808
27537
|
_this._antiAliasingMaterial = antiAliasingMaterial;
|
|
25809
27538
|
return _this;
|
|
@@ -26884,12 +28613,13 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
|
|
|
26884
28613
|
this._shouldCopyBackgroundColor = false;
|
|
26885
28614
|
this._camera = camera;
|
|
26886
28615
|
var engine = camera.engine;
|
|
28616
|
+
var shaders = Engine._builtinShaders;
|
|
26887
28617
|
this._cullingResults = new CullingResults();
|
|
26888
28618
|
this._cascadedShadowCasterPass = new CascadedShadowCasterPass(camera);
|
|
26889
28619
|
this._depthOnlyPass = new DepthOnlyPass(engine);
|
|
26890
|
-
this._saoPass = new ScalableAmbientObscurancePass(engine);
|
|
28620
|
+
this._saoPass = new ScalableAmbientObscurancePass(engine, shaders.scalableAmbientOcclusion);
|
|
26891
28621
|
this._opaqueTexturePass = new OpaqueTexturePass(engine);
|
|
26892
|
-
this._finalPass = new FinalPass(engine);
|
|
28622
|
+
this._finalPass = new FinalPass(engine, shaders.finalSRGB, shaders.finalAntiAliasing);
|
|
26893
28623
|
}
|
|
26894
28624
|
var _proto = BasicRenderPipeline.prototype;
|
|
26895
28625
|
/**
|
|
@@ -27373,7 +29103,7 @@ var OverlayCamera = function OverlayCamera() {
|
|
|
27373
29103
|
if (!hardwareRenderer.canIUse(GLCapabilityType.sRGB)) {
|
|
27374
29104
|
_this._macroCollection.enable(Engine._noSRGBSupportMacro);
|
|
27375
29105
|
}
|
|
27376
|
-
_this._basicResources = new BasicResources(_this);
|
|
29106
|
+
_this._basicResources = new BasicResources(_this, Engine._builtinShaders);
|
|
27377
29107
|
_this._particleBufferUtils = new ParticleBufferUtils(_this);
|
|
27378
29108
|
var uberPass = new PostProcessUberPass(_this);
|
|
27379
29109
|
_this.addPostProcessPass(uberPass);
|
|
@@ -34051,7 +35781,7 @@ function _assert_this_initialized(self) {
|
|
|
34051
35781
|
_inherits(SkyBoxMaterial, Material);
|
|
34052
35782
|
function SkyBoxMaterial(engine) {
|
|
34053
35783
|
var _this;
|
|
34054
|
-
_this = Material.call(this, engine,
|
|
35784
|
+
_this = Material.call(this, engine, Engine._builtinShaders.skybox) || this, _this._tintColor = new engineMath.Color(1, 1, 1, 1);
|
|
34055
35785
|
_this.shaderData.setFloat(SkyBoxMaterial._rotationProp, 0);
|
|
34056
35786
|
_this.shaderData.setFloat(SkyBoxMaterial._exposureProp, 1);
|
|
34057
35787
|
_this.shaderData.setColor(SkyBoxMaterial._tintColorProp, _this._tintColor);
|
|
@@ -34132,7 +35862,7 @@ SkyBoxMaterial._exposureProp = ShaderProperty.getByName("material_Exposure");
|
|
|
34132
35862
|
_inherits(SkyProceduralMaterial, Material);
|
|
34133
35863
|
function SkyProceduralMaterial(engine) {
|
|
34134
35864
|
var _this;
|
|
34135
|
-
_this = Material.call(this, engine,
|
|
35865
|
+
_this = Material.call(this, engine, Engine._builtinShaders.skyProcedural) || this;
|
|
34136
35866
|
_this.sunMode = 2;
|
|
34137
35867
|
_this.sunSize = 0.04;
|
|
34138
35868
|
_this.sunSizeConvergence = 5;
|
|
@@ -35301,14 +37031,13 @@ __decorate([
|
|
|
35301
37031
|
return TransformFeedback;
|
|
35302
37032
|
}(GraphicsResource);
|
|
35303
37033
|
|
|
35304
|
-
var FEEDBACK_SHADER_NAME$1 = "Effect/ParticleFeedback";
|
|
35305
37034
|
var GATHER_PASS_NAME = "SubEmitterTrajectoryGather";
|
|
35306
37035
|
/**
|
|
35307
37036
|
* Maintains parent trajectory state aligned with sub-emitted particle slots.
|
|
35308
37037
|
* @internal
|
|
35309
37038
|
*/ var ParticleSubEmitterSpawnState = /*#__PURE__*/ function() {
|
|
35310
|
-
function ParticleSubEmitterSpawnState(engine, particleCapacity, needsRenderBinding) {
|
|
35311
|
-
var
|
|
37039
|
+
function ParticleSubEmitterSpawnState(engine, shader, particleCapacity, needsRenderBinding) {
|
|
37040
|
+
var _shader_subShaders_;
|
|
35312
37041
|
this._subPrimitive = new SubPrimitive(0, 0, MeshTopology.Points);
|
|
35313
37042
|
this._renderBinding = null;
|
|
35314
37043
|
this._pendingParentTrajectoryBinding = null;
|
|
@@ -35317,11 +37046,11 @@ var GATHER_PASS_NAME = "SubEmitterTrajectoryGather";
|
|
|
35317
37046
|
this._pendingChildrenPerParent = 0;
|
|
35318
37047
|
this._pendingParentCount = 0;
|
|
35319
37048
|
this._activeGatherProgram = null;
|
|
35320
|
-
var gatherPass =
|
|
37049
|
+
var gatherPass = !shader.destroyed && ((_shader_subShaders_ = shader.subShaders[0]) == null ? void 0 : _shader_subShaders_.passes.find(function(pass) {
|
|
35321
37050
|
return pass.name === GATHER_PASS_NAME;
|
|
35322
|
-
});
|
|
37051
|
+
}));
|
|
35323
37052
|
if (!gatherPass) {
|
|
35324
|
-
throw new Error(GATHER_PASS_NAME + " pass is not
|
|
37053
|
+
throw new Error(GATHER_PASS_NAME + " pass is not available in " + shader.name + ".");
|
|
35325
37054
|
}
|
|
35326
37055
|
this._gatherPass = gatherPass;
|
|
35327
37056
|
var primitive = this._primitive = new Primitive(engine);
|
|
@@ -35656,25 +37385,19 @@ ParticleSubEmitterSpawnState._gatherMacros = new ShaderMacroCollection();
|
|
|
35656
37385
|
return TransformFeedbackSimulator;
|
|
35657
37386
|
}();
|
|
35658
37387
|
|
|
35659
|
-
var FEEDBACK_SHADER_NAME = "Effect/ParticleFeedback";
|
|
35660
37388
|
var FEEDBACK_PASS_NAME = "TransformFeedback";
|
|
35661
37389
|
/**
|
|
35662
37390
|
* @internal
|
|
35663
37391
|
* Particle-specific Transform Feedback simulation.
|
|
35664
37392
|
*/ var ParticleTransformFeedbackSimulator = /*#__PURE__*/ function() {
|
|
35665
|
-
function ParticleTransformFeedbackSimulator(engine, trajectoryEnabled, particleCount) {
|
|
35666
|
-
var
|
|
37393
|
+
function ParticleTransformFeedbackSimulator(engine, shader, trajectoryEnabled, particleCount) {
|
|
37394
|
+
var _shader_subShaders_;
|
|
35667
37395
|
this.trajectoryEnabled = trajectoryEnabled;
|
|
35668
|
-
|
|
35669
|
-
var feedbackShader = Shader.find(FEEDBACK_SHADER_NAME);
|
|
35670
|
-
if (!feedbackShader) {
|
|
35671
|
-
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.");
|
|
35672
|
-
}
|
|
35673
|
-
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) {
|
|
35674
37397
|
return pass.name === FEEDBACK_PASS_NAME;
|
|
35675
|
-
});
|
|
37398
|
+
}));
|
|
35676
37399
|
if (!feedbackPass) {
|
|
35677
|
-
throw new Error(FEEDBACK_PASS_NAME + " pass is not
|
|
37400
|
+
throw new Error(FEEDBACK_PASS_NAME + " pass is not available in " + shader.name + ".");
|
|
35678
37401
|
}
|
|
35679
37402
|
var vertexStride;
|
|
35680
37403
|
var feedbackVaryings;
|
|
@@ -40402,7 +42125,8 @@ __decorate([
|
|
|
40402
42125
|
* @internal
|
|
40403
42126
|
*/ _proto._setTransformFeedback = function _setTransformFeedback() {
|
|
40404
42127
|
var _this__feedbackSimulator, _this__feedbackSimulator1;
|
|
40405
|
-
var
|
|
42128
|
+
var engine = this._renderer.engine;
|
|
42129
|
+
var isWebGL2 = engine._hardwareRenderer.isWebGL2;
|
|
40406
42130
|
var useTrajectory = isWebGL2 && (this.subEmitters._hasSubEmitterOfType(ParticleSubEmitterType.Death, false) || this.subEmitters._hasSubEmitterOfType(ParticleSubEmitterType.Birth, false));
|
|
40407
42131
|
var useFeedback = isWebGL2 && (useTrajectory || this.limitVelocityOverLifetime.enabled || this.noise.enabled || this.inheritVelocity._needTransformFeedback() || this.velocityOverLifetime._needTransformFeedback());
|
|
40408
42132
|
var _this__feedbackSimulator_trajectoryEnabled;
|
|
@@ -40412,7 +42136,7 @@ __decorate([
|
|
|
40412
42136
|
}
|
|
40413
42137
|
this._clearActiveParticles();
|
|
40414
42138
|
(_this__feedbackSimulator1 = this._feedbackSimulator) == null ? void 0 : _this__feedbackSimulator1.destroy();
|
|
40415
|
-
this._feedbackSimulator = useFeedback ? new ParticleTransformFeedbackSimulator(
|
|
42139
|
+
this._feedbackSimulator = useFeedback ? new ParticleTransformFeedbackSimulator(engine, Engine._builtinShaders.particleFeedback, useTrajectory, this._currentParticleCount) : null;
|
|
40416
42140
|
if (useFeedback) {
|
|
40417
42141
|
this._renderer.shaderData.enableMacro(ParticleGenerator._transformFeedbackMacro);
|
|
40418
42142
|
// Feedback buffer swaps every frame; VAO caching would bake stale buffer handles.
|
|
@@ -40929,7 +42653,8 @@ __decorate([
|
|
|
40929
42653
|
if (this._subEmitterSpawnState) {
|
|
40930
42654
|
return;
|
|
40931
42655
|
}
|
|
40932
|
-
|
|
42656
|
+
var engine = this._renderer.engine;
|
|
42657
|
+
this._subEmitterSpawnState = new ParticleSubEmitterSpawnState(engine, Engine._builtinShaders.particleFeedback, this._currentParticleCount, !this._feedbackSimulator);
|
|
40933
42658
|
this._renderer.shaderData.enableMacro(ParticleGenerator._hasSubEmitterSpawnedParticlesMacro);
|
|
40934
42659
|
this._reorganizeGeometryBuffers();
|
|
40935
42660
|
};
|
|
@@ -41260,7 +42985,7 @@ __decorate([
|
|
|
41260
42985
|
*/ var ParticleMaterial = /*#__PURE__*/ function(EffectMaterial) {
|
|
41261
42986
|
_inherits(ParticleMaterial, EffectMaterial);
|
|
41262
42987
|
function ParticleMaterial(engine, shader) {
|
|
41263
|
-
if (shader === void 0) shader =
|
|
42988
|
+
if (shader === void 0) shader = Engine._builtinShaders.particle;
|
|
41264
42989
|
return EffectMaterial.call(this, engine, shader) || this;
|
|
41265
42990
|
}
|
|
41266
42991
|
var _proto = ParticleMaterial.prototype;
|
|
@@ -42631,7 +44356,7 @@ __decorate([
|
|
|
42631
44356
|
*/ var TrailMaterial = /*#__PURE__*/ function(EffectMaterial) {
|
|
42632
44357
|
_inherits(TrailMaterial, EffectMaterial);
|
|
42633
44358
|
function TrailMaterial(engine) {
|
|
42634
|
-
return EffectMaterial.call(this, engine,
|
|
44359
|
+
return EffectMaterial.call(this, engine, Engine._builtinShaders.trail) || this;
|
|
42635
44360
|
}
|
|
42636
44361
|
var _proto = TrailMaterial.prototype;
|
|
42637
44362
|
/**
|
|
@@ -43069,7 +44794,7 @@ AudioManager._recovering = false;
|
|
|
43069
44794
|
if (!gainNode) {
|
|
43070
44795
|
this._gainNode = gainNode = AudioManager.getContext().createGain();
|
|
43071
44796
|
gainNode.connect(AudioManager.getGainNode());
|
|
43072
|
-
gainNode.gain.
|
|
44797
|
+
gainNode.gain.value = this._volume;
|
|
43073
44798
|
}
|
|
43074
44799
|
return gainNode;
|
|
43075
44800
|
};
|
|
@@ -43137,11 +44862,12 @@ AudioManager._recovering = false;
|
|
|
43137
44862
|
return this._volume;
|
|
43138
44863
|
},
|
|
43139
44864
|
set: function set(value) {
|
|
43140
|
-
var // No node yet -> _ensureGainNode() applies _volume on first play
|
|
43141
|
-
_this__gainNode;
|
|
43142
44865
|
value = Math.min(Math.max(0, value), 1.0);
|
|
43143
44866
|
this._volume = value;
|
|
43144
|
-
|
|
44867
|
+
// No node yet -> _ensureGainNode() applies _volume on first play
|
|
44868
|
+
if (this._gainNode) {
|
|
44869
|
+
this._gainNode.gain.value = value;
|
|
44870
|
+
}
|
|
43145
44871
|
}
|
|
43146
44872
|
},
|
|
43147
44873
|
{
|
|
@@ -43553,6 +45279,7 @@ exports.PostProcessPassEvent = PostProcessPassEvent;
|
|
|
43553
45279
|
exports.PostProcessUberPass = PostProcessUberPass;
|
|
43554
45280
|
exports.Primitive = Primitive;
|
|
43555
45281
|
exports.PrimitiveMesh = PrimitiveMesh;
|
|
45282
|
+
exports.PrimitiveMeshCapMode = PrimitiveMeshCapMode;
|
|
43556
45283
|
exports.Probe = Probe;
|
|
43557
45284
|
exports.ReferResource = ReferResource;
|
|
43558
45285
|
exports.RefractionMode = RefractionMode;
|