!3157 开发: ShowDirection命令(显示线段的绘制方向)

master
张子涵 1 day ago committed by ChenX
parent 2f6eb02d1c
commit 8fe306e1d3

@ -0,0 +1,100 @@
import { Matrix4, Vector3 } from "three";
import { app } from "../ApplicationServices/Application";
import { Arc } from "../DatabaseServices/Entity/Arc";
import { Curve } from "../DatabaseServices/Entity/Curve";
import { Line } from "../DatabaseServices/Entity/Line";
import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { Command } from "../Editor/CommandMachine";
import { Jig } from "../Editor/Jig";
import { PromptStatus } from "../Editor/PromptResult";
import { equaln } from "../Geometry/GeUtils";
/** 显示线段的绘制方向 */
export class ShowDirection implements Command
{
async exec()
{
let dirJig = new Jig();
let arrows: TArrow[] = [];
// 动态绘制箭头
const enRes = await app.Editor.GetEntity({
Filter: { filterTypes: [Curve] }, Callback: (res) =>
{
if (res.Status !== PromptStatus.OK) return;
let cu = res.Entity as Curve;
if (cu.Id)
{
dirJig.Destroy();
arrows.length = 0;
const endParam = cu.EndParam;
for (let i = 0; i < endParam; i++)
{
let bul = 0;
if (cu instanceof Arc)
bul = cu.Bul;
else if (cu instanceof Polyline)
bul = cu.GetBulgeAt(i);
const startPoint = cu.GetPointAtParam(i);
const endPoint = cu.GetPointAtParam(i + 1);
const nearEndPoint = cu.GetPointAtParam(i + 0.9);
const arrow = CreateArrow(startPoint, endPoint, { nearEndPoint });
arrows.push(arrow);
}
for (const arrow of arrows)
{
for (const line of arrow)
dirJig.Draw(line);
}
}
}
});
// 确定后,将绘制箭头添加到场景
if (enRes.Status === PromptStatus.OK)
{
for (const arrow of arrows)
{
for (const line of arrow)
app.Database.ModelSpace.Append(line);
}
}
dirJig.End();
}
}
/** 箭头类型 */
type TArrow = [Line, Line];
/**
*
* @param {Vector3} startPoint -
* @param {Vector3} endPoint -
* @param {Object} options -
* @property {Vector3} [nearEndPoint] -
* @property {number} [bul] -
* @property {number} [arrowColor] -
* @property {number} [lineColor] - 线
* @returns
*/
const CreateArrow = (startPoint: Vector3, endPoint: Vector3, options: { nearEndPoint?: Vector3, arrowColor?: number, lineColor?: number; } = {}) =>
{
const { nearEndPoint = startPoint, arrowColor = 2 } = options;
const len = endPoint.clone().sub(nearEndPoint);
const GetRotateMatrix = (angle: number) =>
{
if (equaln(startPoint.x, 0))
return new Matrix4().makeRotationX(angle);
else if (equaln(startPoint.y, 0))
return new Matrix4().makeRotationY(angle);
else
return new Matrix4().makeRotationZ(angle);
};
const roMatL = GetRotateMatrix(Math.PI / 4);
const roMatR = GetRotateMatrix(-Math.PI / 4);
const biasLPoint = endPoint.clone().sub(len.clone().applyMatrix4(roMatL));
const biasRPoint = endPoint.clone().sub(len.clone().applyMatrix4(roMatR));
const lineL = new Line(endPoint, biasLPoint);
lineL.ColorIndex = arrowColor;
const lineR = new Line(endPoint, biasRPoint);
lineR.ColorIndex = arrowColor;
return [lineL, lineR] as TArrow;
};

@ -34,6 +34,7 @@ export enum CommandNames
MoveAxis = "MOVEAXIS",
Rotate = "ROTATE", //旋转
RotateRefer = "ROTATEREFER", //旋转(参考)
ShowDirection = "SHOWDIRECTION", //显示线段方向
Revolve = "REVOLVE", //车削实体
Sphere = "SPHERE",
SpliteTemplate = "SPLITETEMPLATE",

@ -240,6 +240,7 @@ import { ForceOpendirOrNameChange } from "../Add-on/ForceOpenDirChange";
import { Command_HighlightNode, Command_HighlightNodeAndChilds } from "../Add-on/HighlightNode";
import { Command_Show2DPathLine } from "../Add-on/Show2DPathLine/Show2DPathLine";
import { Command_Show2DPathObject } from "../Add-on/Show2DPathLine/Show2DPathObject";
import { ShowDirection } from "../Add-on/ShowDirection";
import { TestFb } from "../Add-on/TestFb";
import { Command_TestPointPickParse } from "../Add-on/TestPointPickParse";
import { Text2Curve } from "../Add-on/Text2Curve";
@ -478,6 +479,8 @@ export function registerCommand()
commandMachine.RegisterCommand("ent", new Entsel());
commandMachine.RegisterCommand(CommandNames.ShowDirection, new ShowDirection());
if (IsTest())
commandMachine.RegisterCommand("sky", new DrawSky());

@ -3459,6 +3459,15 @@ export const CommandList: ICommand[] = [
chName: "高亮本节点及子节点",
chDes: "亮显选中实体当前节点的实体和子节点",
},
{
typeId: "hidedisplay",
link: `#`,
defaultCustom: CommandNames.ShowDirection,
command: CommandNames.ShowDirection,
type: "隐藏显示",
chName: "显示线段方向",
chDes: "显示直线/圆弧/多段线的绘制方向",
},
// 内置命令
{

Loading…
Cancel
Save