-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
113 lines (93 loc) · 3.55 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Numerics;
using SharpGLTF.IO;
using SharpGLTF.Geometry;
using SharpGLTF.Geometry.VertexTypes;
using SharpGLTF.Materials;
using SharpGLTF.Schema2;
namespace PointCloudToGLB
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
StringBuilder sb = new StringBuilder();
int i1 = 1;
private void openFileDialog1_FileOk(object sender, CancelEventArgs e) //Операция открытия облака точек исходного
{
}
private void button1_Click(object sender, EventArgs e) //Кнопка открыть исходное облако точек
{
if (openFileDialog1.ShowDialog() == DialogResult.Cancel) return;
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e) //Каталог для сохранения
{
}
public void Operations(StringBuilder sb, int i1, string SaveFolderPath)
{
var mesh = VertexBuilder<VertexPosition, VertexColor1, VertexEmpty>.CreateCompatibleMesh("points");
var material = new MaterialBuilder();
var model = ModelRoot.CreateModel();
var guid = Guid.NewGuid();
string DataStr = null;
using (var reader = new StringReader(sb.ToString()))
{
while ((DataStr = reader.ReadLine()) != null)
{
string[] SingleStrValues = DataStr.Split(' ');
float R_code = (float)Convert.ToDouble(SingleStrValues[3]);
float G_code = (float)Convert.ToDouble(SingleStrValues[4]);
float B_code = (float)Convert.ToDouble(SingleStrValues[5]);
System.Numerics.Vector3 VectorOfPoint = new System.Numerics.Vector3((float)Convert.ToDouble(SingleStrValues[0]), (float)Convert.ToDouble(SingleStrValues[2]), (float)Convert.ToDouble(SingleStrValues[1]));
mesh.UsePrimitive(material, 1).AddPoint((VectorOfPoint, new Vector4(R_code / 256f, G_code / 256f, B_code / 256f, 1)));
}
}
model.CreateMeshes(mesh);
model.UseScene("Default").CreateNode().WithMesh(model.LogicalMeshes[0]);
if (listBox1.SelectedItem.ToString() == "GLTF") { model.SaveGLTF($@"{SaveFolderPath}\Export_Part-{i1}.gltf"); }
else if (listBox1.SelectedItem.ToString() == "GLB") { model.SaveGLB($@"{SaveFolderPath}\Export_Part-{i1}.glb"); }
//else if (listBox1.SelectedItem.ToString() == "OBJ") { model.SaveAsWavefront($@"{SaveFolderPath}\Export_Part-{i1}.obj"); }
mesh = null;
}
private void button2_Click(object sender, EventArgs e) //Кнопка выбора папки сохранения
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.Cancel) return;
}
string SaveFolderPath = null;
private void button3_Click(object sender, EventArgs e) //Кнопка запуска процесса
{
var guid = Guid.NewGuid();
SaveFolderPath = folderBrowserDialog1.SelectedPath + @"\" + guid;
System.IO.Directory.CreateDirectory(SaveFolderPath);
//string FilePath = @"C:\Users\GeorgKeneberg\Documents\Temp\Region02.pts";
long Counter = 0;
foreach (var SingleStr in File.ReadLines(openFileDialog1.FileName))
{
sb.AppendLine(SingleStr);
Counter++;
if (Counter == 2000000)
{
Operations(sb, i1, SaveFolderPath);
i1++;
sb.Clear();
Counter = 0;
}
}
Operations(sb, i1, SaveFolderPath);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) //Выбор типа экспортируемого файла
{
}
}
}