From c2047b4f19fceb9652cc927f0f4c05840ef294c4 Mon Sep 17 00:00:00 2001 From: Zhuangkh Date: Sat, 6 May 2023 14:02:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=8B=E7=BC=A9=E5=87=A0=E4=BD=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IDTF.Net/BasicTypes.cs | 10 ++++++-- IDTF.Net/Point3Comparer.cs | 17 ++++++++++++++ PDF3D.Addin/IDTFBuilder.cs | 48 ++++++++++++++++++++++++-------------- 3 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 IDTF.Net/Point3Comparer.cs diff --git a/IDTF.Net/BasicTypes.cs b/IDTF.Net/BasicTypes.cs index 4833df9..e337387 100644 --- a/IDTF.Net/BasicTypes.cs +++ b/IDTF.Net/BasicTypes.cs @@ -16,9 +16,15 @@ namespace IDTF.Net public float Y { get; set; } public float Z { get; set; } - public bool Equals(Point3 other) + public override bool Equals(object obj) { - return this.X == other.X && this.Y == other.Y && this.Z == other.Z; + if (obj is Point3 other) + { + return Math.Abs(this.X - other.X) < 0.000001 + && Math.Abs(this.Y - other.Y) < 0.000001 + && Math.Abs(this.Z - other.Z) < 0.000001; + } + return false; } public override string ToString() diff --git a/IDTF.Net/Point3Comparer.cs b/IDTF.Net/Point3Comparer.cs new file mode 100644 index 0000000..b1ab518 --- /dev/null +++ b/IDTF.Net/Point3Comparer.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace IDTF.Net +{ + public class Point3Comparer : IEqualityComparer + { + public bool Equals(Point3 x, Point3 y) + { + return x.Equals(y); + } + + public int GetHashCode(Point3 obj) + { + return -1; + } + } +} diff --git a/PDF3D.Addin/IDTFBuilder.cs b/PDF3D.Addin/IDTFBuilder.cs index 7822d6f..36636ba 100644 --- a/PDF3D.Addin/IDTFBuilder.cs +++ b/PDF3D.Addin/IDTFBuilder.cs @@ -30,7 +30,7 @@ namespace PDF3D.Addin MaterialDiffuse = System.Drawing.Color.FromArgb(255, 125, 125, 125), }; this._scene.MaterialResources.Add(mat.Name, mat); - this._scene.ShaderResources.Add(mat.Name, new ShaderResource() { ShaderMaterialName = mat.Name, Name = mat.Name }); + this._scene.ShaderResources.Add(mat.Name, new ShaderResource() { ShaderMaterialName = mat.Name, Name = mat.Name }); _shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count); } @@ -66,7 +66,7 @@ namespace PDF3D.Addin MaterialOpacity = (100 - material.Transparency) / 100f }; this._scene.MaterialResources.Add(mat.Name, mat); - this._scene.ShaderResources.Add(mat.Name, new ShaderResource() {ShaderMaterialName = mat.Name, Name = mat.Name }); + this._scene.ShaderResources.Add(mat.Name, new ShaderResource() { ShaderMaterialName = mat.Name, Name = mat.Name }); _shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count); return true; } @@ -238,42 +238,56 @@ namespace PDF3D.Addin public void Export(string path) { - // Distinct(); + Distinct(); _scene.Export(path); } private void Distinct() { + var comparer = new Point3Comparer(); foreach (var item in _scene.ModelResources.Values) { - List points = new List(); - foreach (var point in item.Mesh.ModelPositionList) - { - var str = point.ToString(); - if (!points.Any(x => x.ToString() == str)) - { - points.Add(point); - } - } + var points = item.Mesh.ModelPositionList.Distinct(comparer).ToList(); if (points.Count != item.Mesh.ModelPositionList.Count) { - var ptStr = points.Select(x => x.ToString()).ToList(); for (int i = 0; i < item.Mesh.MeshFacePositionList.Count; i++) { Int3 face = item.Mesh.MeshFacePositionList[i]; - int a = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[0]].ToString()); - int b = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[1]].ToString()); - int c = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[2]].ToString()); + int a = points.IndexOf(item.Mesh.ModelPositionList[face.IntArray[0]]); + int b = points.IndexOf(item.Mesh.ModelPositionList[face.IntArray[1]]); + int c = points.IndexOf(item.Mesh.ModelPositionList[face.IntArray[2]]); item.Mesh.MeshFacePositionList[i] = new Int3(a, b, c); } item.Mesh.ModelPositionList = points; } + //List points = new List(); + //foreach (var point in item.Mesh.ModelPositionList) + //{ + // var str = point.ToString(); + // if (!points.Any(x => x.ToString() == str)) + // { + // points.Add(point); + // } + //} + //if (points.Count != item.Mesh.ModelPositionList.Count) + //{ + // var ptStr = points.Select(x => x.ToString()).ToList(); + // for (int i = 0; i < item.Mesh.MeshFacePositionList.Count; i++) + // { + // Int3 face = item.Mesh.MeshFacePositionList[i]; + // int a = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[0]].ToString()); + // int b = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[1]].ToString()); + // int c = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[2]].ToString()); + // item.Mesh.MeshFacePositionList[i] = new Int3(a, b, c); + // } + // item.Mesh.ModelPositionList = points; + //} } } internal void InsertView(View3D item) { - IDTF.Net.View view = new IDTF.Net.View() { Name = item.Name }; + IDTF.Net.View view = new IDTF.Net.View() { Name = item.Name }; ViewData viewData = new ViewData(); view.ViewData = viewData; this._scene.Views.Add(view);