Skip to content

Commit ffd5b41

Browse files
committed
Fixed Cylinder, Cone, Geosphere subdivision
The automatic calculation of subdivisions of the Cone, Cylinder, Geosphere Mesh helper functions produced different subdivision counts, dependent on voxel size. This reduced the quality massively at smaller voxel sizes. (These functions were not used outside tests, as the Shape Kernel has more advanced functionality).
1 parent a453807 commit ffd5b41

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

PicoGK_Utils.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,17 @@ static public Mesh mshCreateCylinder( Vector3? vecScale = null,
326326

327327
if (iSides <= 0)
328328
{
329+
float fVoxA = fA / Library.fVoxelSizeMM;
330+
float fVoxB = fB / Library.fVoxelSizeMM;
329331
//Ramanujan's ellipse perimeter
330332
//P ≈ π [ 3 (a + b) - √[(3a + b) (a + 3b) ]]
331333
//P ≈ π(a + b) [ 1 + (3h) / (10 + √(4 - 3h) ) ], where h = (a - b)2/(a + b)2
332334

333-
float fP = MathF.PI * (3.0f * (fA + fB) - MathF.Sqrt((3.0f * fA + fB) * (fA + 3.0f * fB)));
334-
iSides = 2 * (int)MathF.Ceiling(fP);
335+
float fP = float.Pi * (3.0f * (fVoxA + fVoxB)
336+
- float.Sqrt((3.0f * fVoxA + fVoxB)
337+
* (fVoxA + 3.0f * fVoxB)));
338+
339+
iSides = 2 * (int) float.Ceiling(fP);
335340
}
336341

337342
if (iSides < 3)
@@ -388,7 +393,13 @@ static public Mesh mshCreateCone(Vector3? vecScale = null,
388393

389394
if (iSides <= 0)
390395
{
391-
float fP = MathF.PI * (3.0f * (fA + fB) - MathF.Sqrt((3.0f * fA + fB) * (fA + 3.0f * fB)));
396+
float fVoxA = fA / Library.fVoxelSizeMM;
397+
float fVoxB = fB / Library.fVoxelSizeMM;
398+
399+
float fP = float.Pi * (3.0f * (fVoxA + fVoxB)
400+
- float.Sqrt((3.0f * fVoxA + fVoxB)
401+
* (fVoxA + 3.0f * fVoxB)));
402+
392403
iSides = 2 * (int)MathF.Ceiling(fP);
393404
}
394405

@@ -499,7 +510,10 @@ static public Mesh mshCreateGeoSphere(Vector3? vecScale = null,
499510

500511
if (iSubdivisions <= 0)
501512
{
502-
int iTargetTriangles = (int)MathF.Ceiling(fApproxEllipsoidSurfaceArea(vecRadii));
513+
int iTargetTriangles = (int) MathF.Ceiling(
514+
fApproxEllipsoidSurfaceArea(vecRadii)
515+
/ Library.fVoxelSizeMM
516+
/ Library.fVoxelSizeMM);
503517

504518
iSubdivisions = 1;
505519
int iTriangles = 80;

0 commit comments

Comments
 (0)