From 0ded969ce08550f32240d6de6d0c57dd91decca7 Mon Sep 17 00:00:00 2001 From: ChenX Date: Thu, 8 Apr 2021 09:41:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=E9=99=8D=E4=BD=8E=E6=97=8B?= =?UTF-8?q?=E8=BD=AC=E5=AE=9E=E4=BD=93=E7=9A=84=E5=BB=BA=E6=A8=A1=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6,=E6=8F=90=E9=AB=98=E7=BB=98=E5=9B=BE=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DatabaseServices/3DSolid/RevolveSolid.ts | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/DatabaseServices/3DSolid/RevolveSolid.ts b/src/DatabaseServices/3DSolid/RevolveSolid.ts index 83de04787..68741155a 100644 --- a/src/DatabaseServices/3DSolid/RevolveSolid.ts +++ b/src/DatabaseServices/3DSolid/RevolveSolid.ts @@ -1,7 +1,7 @@ import { Face3, Geometry, Matrix4, Mesh, MeshNormalMaterial, Object3D, ShapeUtils, Vector2, Vector3 } from "three"; import { ColorMaterial } from "../../Common/ColorPalette"; import { Object3DRemoveAll } from "../../Common/Dispose"; -import { FixIndex } from "../../Common/Utils"; +import { clamp, FixIndex } from "../../Common/Utils"; import { ObjectSnapMode } from "../../Editor/ObjectSnapMode"; import { angle, AsVector2, equaln, equalv3, ZeroVec, YAxis, isParallelTo } from "../../Geometry/GeUtils"; import { Matrix2 } from "../../Geometry/Matrix2"; @@ -179,7 +179,8 @@ export class RevolveSolid extends Entity this._CacheContourPoints3D.push(c.StartPoint); if (c instanceof Arc) { - let count = c.AllAngle / 0.2; + let minCount = Math.max(2, Math.ceil((c.AllAngle) / Math.PI) * 3); + let count = clamp(c.Length / 20, minCount, 30); for (let j = 0; j < count; j++) this._CacheContourPoints3D.push(c.GetPointAtParam((j + 1) / (count + 1))); } @@ -199,14 +200,14 @@ export class RevolveSolid extends Entity let p2 = this._CacheContourPoints3D[FixIndex(i + 1, this._CacheContourPoints3D)]; let length = p1.distanceTo(p2); v.subVectors(p2, p1); - let c = Math.max(2, Math.floor(length / 50));//合理的控制采样精度是性能的关键 - v.divideScalar(c); + let count = clamp(Math.floor(length / 50), 2, 16);//合理的控制采样精度是性能的关键 + v.divideScalar(count); this._CacheContourPoints3DQ.push(p1); if (equaln(p1.x, 0) && equaln(p1.y, 0) && equaln(p2.x, 0) && equaln(p2.y, 0)) continue; - for (let j = 1; j < c; j++) + for (let j = 1; j < count; j++) { this._CacheContourPoints3DQ.push(v.clone().multiplyScalar(j).add(p1)); } @@ -352,7 +353,20 @@ export class RevolveSolid extends Entity function RevolveLine(geo: Geometry, contourPoints: Vector3[], cachePoints: Vector3[][], startAngle: number, allAngle: number) { - let angleCount = Math.max(Math.floor(allAngle / 0.1), 3);//合理的控制采样精度是性能的关键 + //计算圆的半径 + let rotateCircleRadius = 0; + for (let p of contourPoints) + { + let r = p.x * p.x + p.y * p.y; + if (r > rotateCircleRadius) + rotateCircleRadius = r; + } + rotateCircleRadius = Math.sqrt(rotateCircleRadius); + + let minCount = Math.max(2, Math.ceil((allAngle) / Math.PI) * 4); + let angleCount = clamp(Math.floor(rotateCircleRadius / 3.2), minCount, 30); + + // let angleCount = Math.max(Math.floor(allAngle / 0.2), 3);//合理的控制采样精度是性能的关键 let anDiv = allAngle / angleCount; let startVerticesCount = geo.vertices.length;