|
|
|
|
@ -22,6 +22,7 @@ using HelixToolkit.Wpf; |
|
|
|
|
using MeshBuilder = HelixToolkit.Wpf.SharpDX.MeshBuilder; |
|
|
|
|
using OrthographicCamera = HelixToolkit.Wpf.SharpDX.OrthographicCamera; |
|
|
|
|
using System.Windows.Input; |
|
|
|
|
using SparkClient.Model.Attributes; |
|
|
|
|
using SparkClient.Model.Extension; |
|
|
|
|
using SparkClient.Model.Helper; |
|
|
|
|
using MessageBox = SparkClient.Views.Dialog.MessageBox; |
|
|
|
|
@ -50,6 +51,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="viewport"></param> |
|
|
|
|
/// <param name="entities"></param> |
|
|
|
|
[Log] |
|
|
|
|
public static MeshGeometryModel3D GenerateModelByEntity(Viewport3DX viewport, List<Viewport3DTriangleEntity> entities, Color4? color = null) |
|
|
|
|
{ |
|
|
|
|
var geometryModel = GenerateModelByEntity(entities, color); |
|
|
|
|
@ -63,6 +65,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="entities"></param> |
|
|
|
|
/// <param name="color"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static MeshGeometryModel3D GenerateModelByEntity(List<Viewport3DTriangleEntity> entities, Color4? color = null) |
|
|
|
|
{ |
|
|
|
|
var meshBuilder = new MeshBuilder(true, false); |
|
|
|
|
@ -111,6 +114,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="entities"></param> |
|
|
|
|
/// <param name="color"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<MeshGeometryModel3D> GenerateModelByEntityGroupByType(List<Viewport3DTriangleEntity> entities) |
|
|
|
|
{ |
|
|
|
|
var groupedDict = entities |
|
|
|
|
@ -128,7 +132,7 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static Color4? GenFaceColor4(PlaneType planeType) |
|
|
|
|
{ |
|
|
|
|
switch (planeType) |
|
|
|
|
@ -159,6 +163,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="viewport"></param> |
|
|
|
|
/// <param name="filePath"></param> |
|
|
|
|
[Log] |
|
|
|
|
public static void SaveViewportAsImage(Viewport3DX viewport, string filePath) |
|
|
|
|
{ |
|
|
|
|
// 定义图像大小 |
|
|
|
|
@ -179,7 +184,7 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
public static async Task ExportModelsToVideo(Viewport3DX viewport, string filePath) |
|
|
|
|
{ |
|
|
|
|
if (viewport == null) |
|
|
|
|
@ -197,6 +202,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="viewport"></param> |
|
|
|
|
/// <param name="filePath"></param> |
|
|
|
|
[Log] |
|
|
|
|
public static void ExportModelsToStl(Viewport3DX viewport, string filePath) |
|
|
|
|
{ |
|
|
|
|
if (viewport == null) |
|
|
|
|
@ -248,6 +254,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="viewport"></param> |
|
|
|
|
/// <param name="filePath"></param> |
|
|
|
|
[Log] |
|
|
|
|
public static async Task ExportModelsToStlASync(string filePath) |
|
|
|
|
{ |
|
|
|
|
Viewport3DX viewport = ViewportManager.GetViewport3D(); |
|
|
|
|
@ -310,7 +317,7 @@ public class ViewportHelperPro |
|
|
|
|
}).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
public static List<LineGeometryModel3D> ShowCenterTag(float lineLength = 0.5f) |
|
|
|
|
{ |
|
|
|
|
List<LineGeometryModel3D> result = new List<LineGeometryModel3D>(); |
|
|
|
|
@ -382,6 +389,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="viewport"></param> |
|
|
|
|
/// <param name="entities"></param> |
|
|
|
|
[Log] |
|
|
|
|
public static List<LineGeometryModel3D> GentrateLineByEntity(Viewport3DX viewport, List<Viewport3DTriangleEntity> entities, Color4? color = null, double thickness = 1.0) |
|
|
|
|
{ |
|
|
|
|
List<LineGeometryModel3D> result = GentrateLineByEntity(entities, ViewportManager.isUglyDiamond ? new Color4(new Color3(1f, 0,0)):color, thickness); |
|
|
|
|
@ -397,6 +405,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="color"></param> |
|
|
|
|
/// <param name="thickness"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<LineGeometryModel3D> GentrateLineGirdleByEntity(List<Viewport3DTriangleEntity> entities, |
|
|
|
|
Color4? color = null, double thickness = 1.0) |
|
|
|
|
{ |
|
|
|
|
@ -503,6 +512,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="color"></param> |
|
|
|
|
/// <param name="thickness"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<LineGeometryModel3D> GentrateLineByEntity(List<Viewport3DTriangleEntity> entities, Color4? color = null, double thickness = 1.0) |
|
|
|
|
{ |
|
|
|
|
List<LineGeometryModel3D> result = new List<LineGeometryModel3D>(); |
|
|
|
|
@ -560,7 +570,7 @@ public class ViewportHelperPro |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
public static List<Viewport3DTriangleEntity> GenerateLineTextModelsByType(PlaneType type, Color4? textColor = null, |
|
|
|
|
bool showAll = false) |
|
|
|
|
{ |
|
|
|
|
@ -585,6 +595,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="entities">三角形集合</param> |
|
|
|
|
/// <param name="valKey">指定数据集</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<GeometryModel3D> GenerateLineTextModels(List<Viewport3DTriangleEntity> entities, string valKey = "") |
|
|
|
|
{ |
|
|
|
|
var result = new List<GeometryModel3D>(); |
|
|
|
|
@ -1119,6 +1130,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="triangleCode">三角形ID</param> |
|
|
|
|
/// <param name="selType">生成范围</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<GeometryModel3D> GentrateChosenView(string triangleCode, string valKey = "", params SelShowType[] selType) |
|
|
|
|
{ |
|
|
|
|
var res = ViewportManager.ViewportTriangle.Find(e => triangleCode.Equals(e.TriangleCode)); |
|
|
|
|
@ -1134,6 +1146,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="selType">生成范围</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
/// <exception cref="Exception"></exception> |
|
|
|
|
[Log] |
|
|
|
|
public static List<GeometryModel3D> GentrateChosenView(Viewport3DTriangleEntity entity, string valKey = "", params SelShowType[] selType) |
|
|
|
|
{ |
|
|
|
|
if (entity == null || entity.TriangleCode == null || entity.TriangleCode.Length == 0) |
|
|
|
|
@ -1192,6 +1205,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="textColor">文本颜色(默认红)</param> |
|
|
|
|
/// <param name="showAll">是否显示全部(默认否)</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<GeometryModel3D> GenerateLineAngleTextModels(List<Viewport3DTriangleEntity> entities, |
|
|
|
|
Color4? textColor = null, bool showAll = false) |
|
|
|
|
{ |
|
|
|
|
@ -1245,6 +1259,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="axis">中心</param> |
|
|
|
|
/// <param name="hasLine">是否包含线</param> |
|
|
|
|
/// <param name="speed">旋转时间 秒</param> |
|
|
|
|
[Log] |
|
|
|
|
public static void RotateModel(Vector3D axis, bool hasLine = true, int speed = 7, int to = 360) |
|
|
|
|
{ |
|
|
|
|
ViewportManager.GetViewport().ViewportRightMenuShowModelFaceByType.IsChecked = false; |
|
|
|
|
@ -1285,6 +1300,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="text">文字</param> |
|
|
|
|
/// <param name="position">位置</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static BillboardTextModel3D DisplayText3D(string text, Vector3 position, Color4? color = null) |
|
|
|
|
{ |
|
|
|
|
var billboardTextModel = new BillboardTextModel3D(); |
|
|
|
|
@ -1308,6 +1324,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="direction"></param> |
|
|
|
|
/// <param name="color"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static BillboardTextModel3D DisplayText3D(string text, Vector3 position, Vector3 direction, Color4? color = null) |
|
|
|
|
{ |
|
|
|
|
// 计算线段方向的角度 |
|
|
|
|
@ -1342,6 +1359,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="lineColor">线颜色</param> |
|
|
|
|
/// <param name="thickness">线粗细 默认1</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static LineGeometryModel3D DisplayLineModel3D(List<Vector3> points, Color4 lineColor, |
|
|
|
|
double thickness = 1.0) |
|
|
|
|
{ |
|
|
|
|
@ -1364,6 +1382,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="fieldOfView"></param> |
|
|
|
|
/// <param name="aspectRatio"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static HelixToolkit.Wpf.SharpDX.OrthographicCamera CalculateCamera(Vector3 positiveDirection, BoundingBox boundingBox, double fieldOfView = 45, double aspectRatio = 16.0 / 9.0) |
|
|
|
|
{ |
|
|
|
|
// 单位化正方向 |
|
|
|
|
@ -1409,6 +1428,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="headDiameterRatio">圆锥直径与圆柱直径的比例 1.5</param> |
|
|
|
|
/// <param name="padding">模型边界范围 1</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static MeshGeometryModel3D CreateArrow( |
|
|
|
|
Vector3 cameraPosition, |
|
|
|
|
Vector3 modelCenter, |
|
|
|
|
@ -1474,6 +1494,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="lineColor">线段颜色</param> |
|
|
|
|
/// <param name="thickness">线段粗细</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static LineGeometryModel3D DisplayLineModel3D(List<Tuple<Vector3, Vector3>> points, Color4 lineColor, |
|
|
|
|
double thickness = 1.0) |
|
|
|
|
{ |
|
|
|
|
@ -1506,6 +1527,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="viewport"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<Light3D> GenerateLightingForModel(Viewport3DX viewport) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
@ -1582,7 +1604,7 @@ public class ViewportHelperPro |
|
|
|
|
result.ForEach(e => viewport.Items.Add(e)); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
public static Vector3 GetCenterOfTriangles(List<Viewport3DTriangleEntity> triangles) |
|
|
|
|
{ |
|
|
|
|
if (triangles == null || triangles.Count == 0) |
|
|
|
|
@ -1603,7 +1625,7 @@ public class ViewportHelperPro |
|
|
|
|
// 计算平均坐标 |
|
|
|
|
return total / vertexCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
public static Vector3 CalculateCenter(List<Vector3> girdleTopLines, List<Vector3> girdleBottomLines) |
|
|
|
|
{ |
|
|
|
|
// 计算 GirdleTopLines 的中心点 |
|
|
|
|
@ -1625,6 +1647,7 @@ public class ViewportHelperPro |
|
|
|
|
/// 删除视图中的照明 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="viewport"></param> |
|
|
|
|
[Log] |
|
|
|
|
public static void RemoveLightingInViewport(Viewport3DX viewport) |
|
|
|
|
{ |
|
|
|
|
List<Light3D> lights = new List<Light3D>(); |
|
|
|
|
@ -1648,6 +1671,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="entities"></param> |
|
|
|
|
/// <param name="thickness"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<LineGeometryModel3D> ShowMeshLines(bool isCrown = true, double thickness = 0.5) |
|
|
|
|
{ |
|
|
|
|
List<LineGeometryModel3D> lines = new(); |
|
|
|
|
@ -1735,6 +1759,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="lineA"></param> |
|
|
|
|
/// <param name="lineB"></param> |
|
|
|
|
[Log] |
|
|
|
|
private static void bindingMoveLine(LineGeometryModel3D lineA, LineGeometryModel3D lineB) |
|
|
|
|
{ |
|
|
|
|
lineA.HitTestThickness = HitTestThickness; |
|
|
|
|
@ -1752,6 +1777,7 @@ public class ViewportHelperPro |
|
|
|
|
private static Point startDragPoint = new Point(); |
|
|
|
|
private static Transform3D initialTransform; |
|
|
|
|
private static Transform3D initialOtherTransform; |
|
|
|
|
[Log] |
|
|
|
|
private static void LineA_MouseMove3D(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (isDrawing) |
|
|
|
|
@ -1869,13 +1895,14 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 检查点是否在范围内(距离大于 minDistance 且小于等于 radius) |
|
|
|
|
[Log] |
|
|
|
|
private static bool IsPointInRange(Point3D point, Point3D center, double radius, double minDistance) |
|
|
|
|
{ |
|
|
|
|
double distance = (point - center).Length; |
|
|
|
|
Logger.Info("距离:" + distance); |
|
|
|
|
return distance > minDistance && distance <= radius; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static Point3D LimitToMaxPosition(Point3D center, double radius, Point3D currentCenter) |
|
|
|
|
{ |
|
|
|
|
// 计算当前中心点与中心点的方向 |
|
|
|
|
@ -1885,7 +1912,7 @@ public class ViewportHelperPro |
|
|
|
|
// 计算最大允许位置 |
|
|
|
|
return center + direction * radius; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static void LineA_MouseUp3D(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
isDrawing = false; |
|
|
|
|
@ -1893,7 +1920,7 @@ public class ViewportHelperPro |
|
|
|
|
Viewport.Cursor = Cursors.Arrow; |
|
|
|
|
startDragPoint = new Point(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static void LineA_MouseDown3D(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
isDrawing = true; |
|
|
|
|
@ -1912,6 +1939,7 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
[Log] |
|
|
|
|
private static Point3D Get3DPointFromMouse(Point mousePosition) |
|
|
|
|
{ |
|
|
|
|
// 使用 HelixToolkit 的 Ray3D 和 Plane3D |
|
|
|
|
@ -1932,7 +1960,7 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
return intersection.Value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static Ray3D GetRayFromMouse(Point mousePosition, Viewport3DX viewport) |
|
|
|
|
{ |
|
|
|
|
// 将鼠标坐标转换为归一化设备坐标 (NDC) |
|
|
|
|
@ -1951,7 +1979,7 @@ public class ViewportHelperPro |
|
|
|
|
// 返回射线 |
|
|
|
|
return new Ray3D(cameraPosition, ray); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static Point3D? GetIntersection(Ray3D ray, Plane3D plane) |
|
|
|
|
{ |
|
|
|
|
// 计算射线方向与平面法向量的点积 |
|
|
|
|
@ -1971,7 +1999,7 @@ public class ViewportHelperPro |
|
|
|
|
// 返回交点 |
|
|
|
|
return ray.Origin + ray.Direction * t; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//private static Point3D? GetIntersection(Ray3D ray, Plane3D plane) |
|
|
|
|
//{ |
|
|
|
|
// // 将射线转换为直线(起点和终点) |
|
|
|
|
@ -1987,6 +2015,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="radius"></param> |
|
|
|
|
/// <param name="thickness"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static LineGeometryModel3D ShowCircleLine(bool isCrown = true, double radius = 1.0, double thickness = 0.5) |
|
|
|
|
{ |
|
|
|
|
var Y = -0.01F; |
|
|
|
|
@ -2003,6 +2032,7 @@ public class ViewportHelperPro |
|
|
|
|
Circle.MouseMove3D += Circle_MouseMove3D; |
|
|
|
|
return Circle; |
|
|
|
|
} |
|
|
|
|
[Log] |
|
|
|
|
private static LineGeometryModel3D UpdateCircleGeometry(Vector3 center, double radius = 1.0, double thickness = 1.0) |
|
|
|
|
{ |
|
|
|
|
// 生成圆形线的点 |
|
|
|
|
@ -2026,7 +2056,7 @@ public class ViewportHelperPro |
|
|
|
|
// 更新圆形线的几何形状 |
|
|
|
|
return Circle; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static void Circle_MouseMove3D(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (isDrawing) |
|
|
|
|
@ -2073,6 +2103,7 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 计算两点之间的距离 |
|
|
|
|
[Log] |
|
|
|
|
private static double CalculateDistance(Point3D p1, Point3D p2) |
|
|
|
|
{ |
|
|
|
|
double dx = p2.X - p1.X; |
|
|
|
|
@ -2081,6 +2112,7 @@ public class ViewportHelperPro |
|
|
|
|
|
|
|
|
|
return Math.Sqrt(dx * dx + dy * dy + dz * dz); |
|
|
|
|
} |
|
|
|
|
[Log] |
|
|
|
|
private static void Circle_MouseUp3D(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
isDrawing = false; |
|
|
|
|
@ -2089,7 +2121,7 @@ public class ViewportHelperPro |
|
|
|
|
// 释放鼠标捕获 |
|
|
|
|
Viewport.ReleaseMouseCapture(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static void Circle_MouseDown3D(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
isDrawing = true; |
|
|
|
|
@ -2102,6 +2134,7 @@ public class ViewportHelperPro |
|
|
|
|
Viewport.CaptureMouse(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
[Log] |
|
|
|
|
public static bool IsCrown() |
|
|
|
|
{ |
|
|
|
|
bool isCrown = false; |
|
|
|
|
@ -2119,6 +2152,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="points"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<Vector3> VectorClockwiseSort(List<Vector3> points) |
|
|
|
|
{ |
|
|
|
|
Vector3 center = GetCentroid(points); |
|
|
|
|
@ -2131,6 +2165,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="points"></param> |
|
|
|
|
/// <param name="center"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static List<Vector3> VectorClockwiseSort(List<Vector3> points, Vector3 center) |
|
|
|
|
{ |
|
|
|
|
points.Sort((v1, v2) => |
|
|
|
|
@ -2141,7 +2176,7 @@ public class ViewportHelperPro |
|
|
|
|
}); |
|
|
|
|
return points; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static Vector3 GetCenter(List<Vector3> points) |
|
|
|
|
{ |
|
|
|
|
float x = points.Average(p => p.X); |
|
|
|
|
@ -2155,6 +2190,7 @@ public class ViewportHelperPro |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="vectors"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
public static Vector3 GetCentroid(List<Vector3> vectors) |
|
|
|
|
{ |
|
|
|
|
float x = vectors.Sum(v => v.X) / vectors.Count; |
|
|
|
|
@ -2162,6 +2198,7 @@ public class ViewportHelperPro |
|
|
|
|
float z = vectors.Sum(v => v.Z) / vectors.Count; |
|
|
|
|
return new Vector3(x, y, z); |
|
|
|
|
} |
|
|
|
|
[Log] |
|
|
|
|
public static Vector3 GetOffsetCenter(List<Vector3> facetVector, Vector3 center, float dev = 0.4f) |
|
|
|
|
{ |
|
|
|
|
// 1. 去重 facetVector |
|
|
|
|
@ -2184,6 +2221,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="v1"></param> |
|
|
|
|
/// <param name="v2"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[Log] |
|
|
|
|
private static float AngleBetween(Vector3 v1, Vector3 v2) |
|
|
|
|
{ |
|
|
|
|
// 计算两个向量的点积 |
|
|
|
|
@ -2208,19 +2246,20 @@ public class ViewportHelperPro |
|
|
|
|
// 返回角度,单位是度 |
|
|
|
|
return (float)(Math.Acos(cosTheta) * (180.0 / Math.PI)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static double GetBoundingBoxVolume(BoundingBox bound) |
|
|
|
|
{ |
|
|
|
|
var size = bound.Size; |
|
|
|
|
return size.X * size.Y * size.Z; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static Vector3 CalculateNormal(Vector3 p0, Vector3 p1, Vector3 p2) |
|
|
|
|
{ |
|
|
|
|
var u = p1 - p0; |
|
|
|
|
var v = p2 - p0; |
|
|
|
|
return Vector3.Cross(u, v); |
|
|
|
|
} |
|
|
|
|
[Log] |
|
|
|
|
private static bool IsLineSegmentParallelToYAxis(Tuple<Vector3, Vector3> lineSegment,float epsilon = 0.001f) |
|
|
|
|
{ |
|
|
|
|
Vector3 nowItem = lineSegment.Item1; |
|
|
|
|
@ -2233,12 +2272,14 @@ public class ViewportHelperPro |
|
|
|
|
return false; // 不平行于 Y 轴 |
|
|
|
|
} |
|
|
|
|
// 计算两个点之间的距离 |
|
|
|
|
[Log] |
|
|
|
|
private static float GetDistance(Vector3 point1, Vector3 point2) |
|
|
|
|
{ |
|
|
|
|
return (float)Math.Sqrt(Math.Pow(point2.X - point1.X, 2) + Math.Pow(point2.Y - point1.Y, 2) + Math.Pow(point2.Z - point1.Z, 2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 判断是否平行于Y轴的线段,返回较长或者较短的线段 |
|
|
|
|
[Log] |
|
|
|
|
private static Tuple<Vector3, Vector3> GetLongestOrShortestLineSegment(List<Vector3> facetPoints, bool returnLongest = true) |
|
|
|
|
{ |
|
|
|
|
Tuple<Vector3, Vector3> resultSegment = null; |
|
|
|
|
@ -2269,7 +2310,7 @@ public class ViewportHelperPro |
|
|
|
|
|
|
|
|
|
return resultSegment; // 返回符合条件的线段 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static Tuple<Vector3, Vector3> GetLeftOrRightLineSegment(List<Vector3> facetPoints, |
|
|
|
|
bool isLeft = true) |
|
|
|
|
{ |
|
|
|
|
@ -2302,7 +2343,7 @@ public class ViewportHelperPro |
|
|
|
|
return resultSegment; // 返回符合条件的线段 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static void CalculateLineSegmentStats(List<Tuple<Vector3, Vector3>> lines, |
|
|
|
|
out Tuple<Vector3, Vector3> maxLine, |
|
|
|
|
out Tuple<Vector3, Vector3> minLine, |
|
|
|
|
@ -2334,6 +2375,7 @@ public class ViewportHelperPro |
|
|
|
|
/// <param name="facetPoints">四边形的顶点列表</param> |
|
|
|
|
/// <param name="returnLongest">是否返回最长的边线</param> |
|
|
|
|
/// <returns>符合条件的边线,如果不存在则返回null</returns> |
|
|
|
|
[Log] |
|
|
|
|
public static Tuple<Vector3, Vector3> GetLeftParallelLineSegment( |
|
|
|
|
List<Vector3> facetPoints) |
|
|
|
|
{ |
|
|
|
|
@ -2365,7 +2407,7 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static string ValueFormat(string value, string type, bool hasUnit = false) |
|
|
|
|
{ |
|
|
|
|
if (double.TryParse(value, out var v) ) |
|
|
|
|
@ -2403,7 +2445,7 @@ public class ViewportHelperPro |
|
|
|
|
|
|
|
|
|
return "--"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static Vector3? CalculateIntersection( |
|
|
|
|
Tuple<Vector3, Vector3> line1, |
|
|
|
|
Tuple<Vector3, Vector3> line2) |
|
|
|
|
@ -2446,7 +2488,7 @@ public class ViewportHelperPro |
|
|
|
|
return new Vector3(x, maxY, z); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static bool FactoryShowTextCheck(string diamondType, PlaneType planeType) |
|
|
|
|
{ |
|
|
|
|
Dictionary<string, HashSet<PlaneType>> stepPlaneMappings = new() |
|
|
|
|
@ -2467,7 +2509,7 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
return allowedTypes.Contains(planeType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static string[] GetAlgorithmParam(string diamondType, PlaneType planeType) |
|
|
|
|
{ |
|
|
|
|
Dictionary<string, Dictionary<PlaneType, string[]>> stepPlaneMappings = new() |
|
|
|
|
@ -2516,7 +2558,7 @@ public class ViewportHelperPro |
|
|
|
|
|
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Log] |
|
|
|
|
private static float DisplacementCalculations(PlaneType planeType, float vol = 0.4f) |
|
|
|
|
{ |
|
|
|
|
switch (planeType) |
|
|
|
|
|