优化:降低旋转实体的建模精度,提高绘图性能

pull/1470/head
ChenX 4 years ago
parent 31ccf1747e
commit 0ded969ce0

@ -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;

Loading…
Cancel
Save