修复:Revolve建模错误

pull/907/MERGE
ChenX 5 years ago
parent b48039d332
commit 940ed79762

@ -1,30 +1,102 @@
import { Command } from "../Editor/CommandMachine";
import { Vector3 } from "three";
import { app } from "../ApplicationServices/Application";
import { PromptStatus } from "../Editor/PromptResult";
import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { RevolveSolid } from "../DatabaseServices/3DSolid/RevolveSolid";
import { TestDraw } from "./test/TestUtil";
import { Line } from "../DatabaseServices/Entity/Line";
import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
import { equalv3, ZeroVec } from "../Geometry/GeUtils";
import { HotCMD } from "../Hot/HotCommand";
import { TestDraw } from "./test/TestUtil";
@HotCMD
export class Command_DrawRevolve implements Command
{
async exec()
{
let enRes = await app.Editor.GetEntity({ Msg: "选择轴", Filter: { filterTypes: [Line] } });
if (enRes.Status !== PromptStatus.OK) return;
let axis = enRes.Entity as Line;
let enRes2 = await app.Editor.GetEntity({ Msg: "选择轮廓", Filter: { filterTypes: [Polyline] } });
if (enRes2.Status !== PromptStatus.OK) return;
let pl = enRes2.Entity as Polyline;
let rs = new RevolveSolid(
axis.GetFistDeriv(0).normalize(),
axis.StartPoint,
pl,
0, 0
);
let p0 = await app.Editor.GetPoint({
Msg: "指定轴起点或者根据以下选项之一定义轴:",
KeyWordList: [
{ key: "O", msg: "对象" },
{ key: "X", msg: "" },
{ key: "Y", msg: "" },
{ key: "Z", msg: "" },
]
});
if (p0.Status === PromptStatus.Keyword)
{
if (p0.StringResult === "O")
{
let enRes = await app.Editor.GetEntity({ Msg: "选择轴", Filter: { filterTypes: [Line] } });
if (enRes.Status !== PromptStatus.OK) return;
let axis = enRes.Entity as Line;
let rs = new RevolveSolid(
axis.GetFistDeriv(0).normalize(),
axis.StartPoint,
pl,
0, 0
);
TestDraw(rs);
}
else if (p0.StringResult === "X")
{
let rs = new RevolveSolid(
new Vector3(1),
new Vector3,
pl,
0, 0
);
TestDraw(rs);
}
else if (p0.StringResult === "Y")
{
let rs = new RevolveSolid(
new Vector3(0, 1),
new Vector3,
pl,
0, 0
);
TestDraw(rs);
}
else if (p0.StringResult === "Z")
{
let rs = new RevolveSolid(
new Vector3(0, 0, 1),
new Vector3,
pl,
0, 0
);
TestDraw(rs);
}
}
else if (p0.Status === PromptStatus.OK)
{
let p1Res = await app.Editor.GetPoint({ Msg: "指定轴端点:", BasePoint: p0.Point, AllowDrawRubberBand: true });
if (p1Res.Status === PromptStatus.OK)
{
let p1 = p1Res.Point;
let n = p1.sub(p0.Point);
if (equalv3(n, ZeroVec))
{
app.Editor.Prompt("重合!");
return;
}
let rs = new RevolveSolid(
n,
p0.Point,
pl,
0, 0
);
TestDraw(rs);
}
}
TestDraw(rs);
}
}

@ -1,9 +1,9 @@
import { Face3, Geometry, Line as TLine, Matrix4, Mesh, MeshNormalMaterial, Object3D, ShapeUtils, Vector2, Vector3 } from "three";
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 { ObjectSnapMode } from "../../Editor/ObjectSnapMode";
import { angle, AsVector3, equalv3, ZeroVec } from "../../Geometry/GeUtils";
import { angle, AsVector3, equaln, equalv3, ZeroVec } from "../../Geometry/GeUtils";
import { Matrix2 } from "../../Geometry/Matrix2";
import { Orbit } from "../../Geometry/Orbit";
import { RenderType } from "../../GraphicsSystem/RenderType";
@ -93,7 +93,7 @@ export class RevolveSolid extends Entity
GetGripPoints()
{
let p1 = this._Contour.StartPoint;
let p1 = new Vector3(10);
let p2 = p1.clone();
r.setRotate(this._StartAngle);
r.applyVector(p1);
@ -164,10 +164,8 @@ export class RevolveSolid extends Entity
if (this._CacheIsRev === undefined)
{
let ocsR0 = ocs.clone().setPosition(0, 0, 0);
//如果y.z大于0 则翻转面
let p = new Vector3(0, 1).applyMatrix4(ocsR0);
this._CacheIsRev = p.z > 0;
let n = this._Contour.Normal;
this._CacheIsRev = n.y > 0;
}
if (this._CacheContourPoints === undefined)
@ -188,16 +186,23 @@ 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 / 5));//合理的控制采样精度是性能的关键
let c = Math.max(2, Math.floor(length / 50));//合理的控制采样精度是性能的关键
v.divideScalar(c);
this._CacheContourPoints3DQ.push(p1);
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++)
{
this._CacheContourPoints3DQ.push(v.clone().multiplyScalar(j).add(p1));
}
}
if (!this._CacheIsRev)
this._CacheContourPoints3DQ.reverse();
}
//性能:此处用BufferGeometry可以提高性能
@ -270,9 +275,6 @@ export class RevolveSolid extends Entity
if (type === RenderType.Wireframe)
{
let geo = new Geometry;
geo.vertices.push(new Vector3, new Vector3(0, 0, 10));
obj.add(new TLine(geo));
let g = this.MeshGeometry;
g.computeFaceNormals();
g.computeVertexNormals();
@ -280,9 +282,6 @@ export class RevolveSolid extends Entity
}
else// if (type === RenderType.Conceptual || type===RenderType.Physical || type === RenderType.Jig)
{
let geo = new Geometry;
geo.vertices.push(new Vector3, new Vector3(0, 0, 10));
obj.add(new TLine(geo));
let g = this.MeshGeometry;
g.computeFaceNormals();
g.computeVertexNormals();
@ -342,7 +341,7 @@ 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 angleCount = Math.max(Math.floor(allAngle / 0.2), 3);//合理的控制采样精度是性能的关键
let anDiv = allAngle / (angleCount - 1);
let count = geo.vertices.length;

@ -66,11 +66,14 @@ export class Orbit
*/
static ComputUpDirection(n: Vector3, ay: Vector3 = new Vector3(), ax: Vector3 = new Vector3()): Vector3
{
n.normalize();
if (Math.abs(n.x) < 0.015625 && Math.abs(n.y) < 0.015625)
ax.crossVectors(YAxis, n);
else
ax.crossVectors(ZAxis, n);
ay.crossVectors(n, ax);
ax.normalize();
ay.normalize();
return ay;
}
}

Loading…
Cancel
Save