scripts
This commit is contained in:
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using TriangleNet.Data;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x02000025 RID: 37
|
||||
internal class DebugWriter
|
||||
{
|
||||
// Token: 0x0600012A RID: 298 RVA: 0x00013025 File Offset: 0x00011225
|
||||
private DebugWriter()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x17000057 RID: 87
|
||||
// (get) Token: 0x0600012B RID: 299 RVA: 0x00015A67 File Offset: 0x00013C67
|
||||
public static DebugWriter Session
|
||||
{
|
||||
get
|
||||
{
|
||||
return DebugWriter.instance;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600012C RID: 300 RVA: 0x00015A6E File Offset: 0x00013C6E
|
||||
public void Start(string session)
|
||||
{
|
||||
this.iteration = 0;
|
||||
this.session = session;
|
||||
if (this.stream != null)
|
||||
{
|
||||
throw new Exception("A session is active. Finish before starting a new.");
|
||||
}
|
||||
this.tmpFile = Path.GetTempFileName();
|
||||
this.stream = new StreamWriter(this.tmpFile);
|
||||
}
|
||||
|
||||
// Token: 0x0600012D RID: 301 RVA: 0x00015AAD File Offset: 0x00013CAD
|
||||
public void Write(Mesh mesh, bool skip)
|
||||
{
|
||||
this.WriteMesh(mesh, skip);
|
||||
this.triangles = mesh.Triangles.Count;
|
||||
}
|
||||
|
||||
// Token: 0x0600012E RID: 302 RVA: 0x00015AC8 File Offset: 0x00013CC8
|
||||
public void Write(Mesh mesh)
|
||||
{
|
||||
this.Write(mesh, false);
|
||||
}
|
||||
|
||||
// Token: 0x0600012F RID: 303 RVA: 0x00015AD2 File Offset: 0x00013CD2
|
||||
public void Finish()
|
||||
{
|
||||
this.Finish(this.session + ".mshx");
|
||||
}
|
||||
|
||||
// Token: 0x06000130 RID: 304 RVA: 0x00015AEC File Offset: 0x00013CEC
|
||||
private void Finish(string path)
|
||||
{
|
||||
if (this.stream != null)
|
||||
{
|
||||
this.stream.Flush();
|
||||
this.stream.Dispose();
|
||||
this.stream = null;
|
||||
string text = "#!N" + this.iteration + Environment.NewLine;
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Create))
|
||||
{
|
||||
using (GZipStream gzipStream = new GZipStream(fileStream, CompressionMode.Compress, false))
|
||||
{
|
||||
byte[] array = Encoding.UTF8.GetBytes(text);
|
||||
gzipStream.Write(array, 0, array.Length);
|
||||
array = File.ReadAllBytes(this.tmpFile);
|
||||
gzipStream.Write(array, 0, array.Length);
|
||||
}
|
||||
}
|
||||
File.Delete(this.tmpFile);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000131 RID: 305 RVA: 0x00015BB8 File Offset: 0x00013DB8
|
||||
private void WriteGeometry(InputGeometry geometry)
|
||||
{
|
||||
TextWriter textWriter = this.stream;
|
||||
string text = "#!G{0}";
|
||||
int num = this.iteration;
|
||||
this.iteration = num + 1;
|
||||
textWriter.WriteLine(text, num);
|
||||
}
|
||||
|
||||
// Token: 0x06000132 RID: 306 RVA: 0x00015BEC File Offset: 0x00013DEC
|
||||
private void WriteMesh(Mesh mesh, bool skip)
|
||||
{
|
||||
if (this.triangles == mesh.triangles.Count && skip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
TextWriter textWriter = this.stream;
|
||||
string text = "#!M{0}";
|
||||
int num = this.iteration;
|
||||
this.iteration = num + 1;
|
||||
textWriter.WriteLine(text, num);
|
||||
if (this.VerticesChanged(mesh))
|
||||
{
|
||||
this.HashVertices(mesh);
|
||||
this.stream.WriteLine("{0}", mesh.vertices.Count);
|
||||
using (Dictionary<int, Vertex>.ValueCollection.Enumerator enumerator = mesh.vertices.Values.GetEnumerator())
|
||||
{
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
Vertex vertex = enumerator.Current;
|
||||
this.stream.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
vertex.hash,
|
||||
vertex.x.ToString(DebugWriter.nfi),
|
||||
vertex.y.ToString(DebugWriter.nfi),
|
||||
vertex.mark
|
||||
});
|
||||
}
|
||||
goto IL_116;
|
||||
}
|
||||
}
|
||||
this.stream.WriteLine("0");
|
||||
IL_116:
|
||||
this.stream.WriteLine("{0}", mesh.subsegs.Count);
|
||||
Osub osub = default(Osub);
|
||||
osub.orient = 0;
|
||||
foreach (Segment segment in mesh.subsegs.Values)
|
||||
{
|
||||
if (segment.hash > 0)
|
||||
{
|
||||
osub.seg = segment;
|
||||
Vertex vertex2 = osub.Org();
|
||||
Vertex vertex3 = osub.Dest();
|
||||
this.stream.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
osub.seg.hash,
|
||||
vertex2.hash,
|
||||
vertex3.hash,
|
||||
osub.seg.boundary
|
||||
});
|
||||
}
|
||||
}
|
||||
Otri otri = default(Otri);
|
||||
Otri otri2 = default(Otri);
|
||||
otri.orient = 0;
|
||||
this.stream.WriteLine("{0}", mesh.triangles.Count);
|
||||
foreach (Triangle triangle in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle;
|
||||
Vertex vertex2 = otri.Org();
|
||||
Vertex vertex3 = otri.Dest();
|
||||
Vertex vertex4 = otri.Apex();
|
||||
int num2 = ((vertex2 == null) ? (-1) : vertex2.hash);
|
||||
int num3 = ((vertex3 == null) ? (-1) : vertex3.hash);
|
||||
int num4 = ((vertex4 == null) ? (-1) : vertex4.hash);
|
||||
this.stream.Write("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
otri.triangle.hash,
|
||||
num2,
|
||||
num3,
|
||||
num4
|
||||
});
|
||||
otri.orient = 1;
|
||||
otri.Sym(ref otri2);
|
||||
int hash = otri2.triangle.hash;
|
||||
otri.orient = 2;
|
||||
otri.Sym(ref otri2);
|
||||
int hash2 = otri2.triangle.hash;
|
||||
otri.orient = 0;
|
||||
otri.Sym(ref otri2);
|
||||
int hash3 = otri2.triangle.hash;
|
||||
this.stream.WriteLine(" {0} {1} {2}", hash, hash2, hash3);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000133 RID: 307 RVA: 0x00015FE0 File Offset: 0x000141E0
|
||||
private bool VerticesChanged(Mesh mesh)
|
||||
{
|
||||
if (this.vertices == null || mesh.Vertices.Count != this.vertices.Length)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int num = 0;
|
||||
using (IEnumerator<Vertex> enumerator = mesh.Vertices.GetEnumerator())
|
||||
{
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
if (enumerator.Current.id != this.vertices[num++])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Token: 0x06000134 RID: 308 RVA: 0x00016060 File Offset: 0x00014260
|
||||
private void HashVertices(Mesh mesh)
|
||||
{
|
||||
if (this.vertices == null || mesh.Vertices.Count != this.vertices.Length)
|
||||
{
|
||||
this.vertices = new int[mesh.Vertices.Count];
|
||||
}
|
||||
int num = 0;
|
||||
foreach (Vertex vertex in mesh.Vertices)
|
||||
{
|
||||
this.vertices[num++] = vertex.id;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040000E0 RID: 224
|
||||
private static NumberFormatInfo nfi = CultureInfo.InvariantCulture.NumberFormat;
|
||||
|
||||
// Token: 0x040000E1 RID: 225
|
||||
private int iteration;
|
||||
|
||||
// Token: 0x040000E2 RID: 226
|
||||
private string session;
|
||||
|
||||
// Token: 0x040000E3 RID: 227
|
||||
private StreamWriter stream;
|
||||
|
||||
// Token: 0x040000E4 RID: 228
|
||||
private string tmpFile;
|
||||
|
||||
// Token: 0x040000E5 RID: 229
|
||||
private int[] vertices;
|
||||
|
||||
// Token: 0x040000E6 RID: 230
|
||||
private int triangles;
|
||||
|
||||
// Token: 0x040000E7 RID: 231
|
||||
private static readonly DebugWriter instance = new DebugWriter();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user