-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFXM__2__ASSIMP.cs
110 lines (78 loc) · 5.42 KB
/
FXM__2__ASSIMP.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
using System.IO;
using System.Linq;
using System.Collections.Generic;
using Assimp;
static class FXM__2__ASSIMP
{
static string extTextureFileName; // расширение текстуры
static string materialName;
public static void WORK()
{
List<short> face_list = new();
List<float> vert_list = new();
List<float> norm_list = new();
List<float> uvst_list = new();
string[] allFilesName = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.fxm", SearchOption.AllDirectories); // ищем fxm
foreach (var fxmName in allFilesName) // для каждого файла
{
using BinaryReader fxm = new(File.Open(fxmName, FileMode.Open)); // открыли на чтение
for (int temp_s = 0; temp_s < 11; temp_s++)
fxm.ReadSingle(); // skip 11 floats
int submesh__count = fxm.ReadInt32();
for (int subm = 0; subm < submesh__count; subm++) // для каждой сабмеши
{
//ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ
int name__length = fxm.ReadInt32(); // читаем количество букв в имени файла текстуры
byte[] textureFileNameHex = new byte[name__length];
fxm.Read(textureFileNameHex, 0, name__length);
materialName = System.Text.Encoding.Default.GetString(textureFileNameHex);
//ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ
// получаем имена всех текстур файлов и расширение нужного
List<string> texture_files = Directory.GetFiles(Path.GetDirectoryName(fxmName), "*.jpg", SearchOption.AllDirectories).ToList();
texture_files.AddRange(Directory.GetFiles(Path.GetDirectoryName(fxmName), "*.tga", SearchOption.AllDirectories).ToList());
texture_files.AddRange(Directory.GetFiles(Path.GetDirectoryName(fxmName), "*.JPG", SearchOption.AllDirectories).ToList());
texture_files.AddRange(Directory.GetFiles(Path.GetDirectoryName(fxmName), "*.TGA", SearchOption.AllDirectories).ToList());
for (int i = 0; i < texture_files.Count; i++)
{
if (materialName == Path.GetFileNameWithoutExtension(texture_files[i]))
{
extTextureFileName = Path.GetExtension(texture_files[i]);
break;
}
}
texture_files.Clear();
//ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ
for (int temp_s = 0; temp_s < 6; temp_s++)
fxm.ReadSingle(); // skip 6 floats
int faces__count = fxm.ReadInt32(); // количество граней
int vertex_count = fxm.ReadInt32(); // количество вершин
//ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ
for (int i = 0; i < faces__count; i++) // читаем грани f v1 v2 v3
{
face_list.Add(fxm.ReadInt16());
face_list.Add(fxm.ReadInt16());
face_list.Add(fxm.ReadInt16());
}
//ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ
for (int i = 0; i < vertex_count; i++) // считываем информацию по каждой вершине v vn vt
{
vert_list.Add(fxm.ReadSingle());
vert_list.Add(fxm.ReadSingle());
vert_list.Add(fxm.ReadSingle());
norm_list.Add(fxm.ReadSingle());
norm_list.Add(fxm.ReadSingle());
norm_list.Add(fxm.ReadSingle());
uvst_list.Add(fxm.ReadSingle());
uvst_list.Add(fxm.ReadSingle());
}
//ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ
// записываем всю информацию в *.x файл
//...
vert_list.Clear();
uvst_list.Clear();
norm_list.Clear();
face_list.Clear();
}
} // foreach (var fxmName in allFilesName)
} // static void Main()
} // class Program