-
Notifications
You must be signed in to change notification settings - Fork 3
/
BMesh.cs
103 lines (89 loc) · 2.55 KB
/
BMesh.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
using FauFau.Util.CommmonDataTypes;
using Bitter;
using System;
using System.Collections.Generic;
using System.Text;
namespace FauFau.Formats
{
public class BMesh : BinaryWrapper
{
public List<Vertex> Vertices = new List<Vertex>();
public override void Read(BinaryStream bs)
{
if(bs.Length < 7 || !bs.Read.String(5).Equals("bMesh"))
{
throw new Exception("uh oh, this doesn't seem to be a bMesh file?");
}
ushort version = bs.Read.UShort();
bs.ByteOffset = 0;
switch(version)
{
case 32:
ReadBMesh32(bs);
break;
default:
throw new Exception("uh oh, I don't know how to parse bMesh version " + version);
}
}
public override void Write(BinaryStream bs)
{
base.Write(bs);
}
private void ReadBMesh32(BinaryStream bs)
{
BMesh32 bm = new BMesh32();
bm.Read(bs);
if (bm.Vertices.Count != bm.Normals.Count)
{
throw new Exception("uh oh, this mesh has " + bm.Vertices.Count + " vertices and " + bm.Normals.Count + " normals??");
}
Vertices = new List<Vertex>(bm.Vertices.Count);
for (int i = 0; i < bm.Vertices.Count; i++)
{
Vertices.Add(new Vertex
{
x = bm.Vertices[i].x,
y = bm.Vertices[i].y,
z = bm.Vertices[i].z,
normal = new Normal
{
x = bm.Normals[i].x,
y = bm.Normals[i].y,
z = bm.Normals[i].z
}
});
}
}
public class Vertex
{
public float x;
public float y;
public float z;
public Normal normal;
}
public class Normal
{
public float x;
public float y;
public float z;
}
public class Tangent
{
public float x;
public float y;
public float z;
public bool reverseBitangent;
}
public enum TangentType : byte
{
Melody = 0,
Turtle = 1
}
public enum MeshType : byte
{
None = 0,
BaseVariant = 1,
ConformMesh = 2
}
}
}