压缩几何数据
This commit is contained in:
parent
6e8ba1b7ed
commit
c2047b4f19
@ -16,9 +16,15 @@ namespace IDTF.Net
|
|||||||
public float Y { get; set; }
|
public float Y { get; set; }
|
||||||
public float Z { 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()
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -66,7 +66,7 @@ namespace PDF3D.Addin
|
|||||||
MaterialOpacity = (100 - material.Transparency) / 100f
|
MaterialOpacity = (100 - material.Transparency) / 100f
|
||||||
};
|
};
|
||||||
this._scene.MaterialResources.Add(mat.Name, mat);
|
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);
|
_shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -238,36 +238,50 @@ namespace PDF3D.Addin
|
|||||||
|
|
||||||
public void Export(string path)
|
public void Export(string path)
|
||||||
{
|
{
|
||||||
// Distinct();
|
Distinct();
|
||||||
_scene.Export(path);
|
_scene.Export(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Distinct()
|
private void Distinct()
|
||||||
{
|
{
|
||||||
|
var comparer = new Point3Comparer();
|
||||||
foreach (var item in _scene.ModelResources.Values)
|
foreach (var item in _scene.ModelResources.Values)
|
||||||
{
|
{
|
||||||
List<Point3> points = new List<Point3>();
|
var points = item.Mesh.ModelPositionList.Distinct(comparer).ToList();
|
||||||
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)
|
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++)
|
for (int i = 0; i < item.Mesh.MeshFacePositionList.Count; i++)
|
||||||
{
|
{
|
||||||
Int3 face = item.Mesh.MeshFacePositionList[i];
|
Int3 face = item.Mesh.MeshFacePositionList[i];
|
||||||
int a = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[0]].ToString());
|
int a = points.IndexOf(item.Mesh.ModelPositionList[face.IntArray[0]]);
|
||||||
int b = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[1]].ToString());
|
int b = points.IndexOf(item.Mesh.ModelPositionList[face.IntArray[1]]);
|
||||||
int c = ptStr.IndexOf(item.Mesh.ModelPositionList[face.IntArray[2]].ToString());
|
int c = points.IndexOf(item.Mesh.ModelPositionList[face.IntArray[2]]);
|
||||||
item.Mesh.MeshFacePositionList[i] = new Int3(a, b, c);
|
item.Mesh.MeshFacePositionList[i] = new Int3(a, b, c);
|
||||||
}
|
}
|
||||||
item.Mesh.ModelPositionList = points;
|
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;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user