压缩几何数据
This commit is contained in:
parent
6e8ba1b7ed
commit
c2047b4f19
@ -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()
|
||||
|
17
IDTF.Net/Point3Comparer.cs
Normal file
17
IDTF.Net/Point3Comparer.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IDTF.Net
|
||||
{
|
||||
public class Point3Comparer : IEqualityComparer<Point3>
|
||||
{
|
||||
public bool Equals(Point3 x, Point3 y)
|
||||
{
|
||||
return x.Equals(y);
|
||||
}
|
||||
|
||||
public int GetHashCode(Point3 obj)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Point3> points = new List<Point3>();
|
||||
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<Point3> points = new List<Point3>();
|
||||
//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);
|
||||
|
Loading…
Reference in New Issue
Block a user