corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | using System; |
2 | |||
3 | using OpenMetaverse; |
||
4 | using OpenMetaverse.Rendering; |
||
5 | |||
6 | namespace AvatarPreview |
||
7 | { |
||
8 | /// <summary> |
||
9 | /// Subclass of LindenMesh that adds vertex, index, and texture coordinate |
||
10 | /// arrays suitable for pushing direct to OpenGL |
||
11 | /// </summary> |
||
12 | public class GLMesh : LindenMesh |
||
13 | { |
||
14 | /// <summary> |
||
15 | /// Subclass of LODMesh that adds an index array suitable for pushing |
||
16 | /// direct to OpenGL |
||
17 | /// </summary> |
||
18 | new public class LODMesh : LindenMesh.LODMesh |
||
19 | { |
||
20 | public ushort[] Indices; |
||
21 | |||
22 | public override void LoadMesh(string filename) |
||
23 | { |
||
24 | base.LoadMesh(filename); |
||
25 | |||
26 | // Generate the index array |
||
27 | Indices = new ushort[_numFaces * 3]; |
||
28 | int current = 0; |
||
29 | for (int i = 0; i < _numFaces; i++) |
||
30 | { |
||
31 | Indices[current++] = (ushort)_faces[i].Indices[0]; |
||
32 | Indices[current++] = (ushort)_faces[i].Indices[1]; |
||
33 | Indices[current++] = (ushort)_faces[i].Indices[2]; |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | |||
38 | /// <summary> |
||
39 | /// |
||
40 | /// </summary> |
||
41 | public struct GLData |
||
42 | { |
||
43 | public float[] Vertices; |
||
44 | public ushort[] Indices; |
||
45 | public float[] TexCoords; |
||
46 | public Vector3 Center; |
||
47 | } |
||
48 | |||
49 | public GLData RenderData; |
||
50 | |||
51 | public GLMesh(string name) |
||
52 | : base(name) |
||
53 | { |
||
54 | } |
||
55 | |||
56 | public override void LoadMesh(string filename) |
||
57 | { |
||
58 | base.LoadMesh(filename); |
||
59 | |||
60 | float minX, minY, minZ; |
||
61 | minX = minY = minZ = Single.MaxValue; |
||
62 | float maxX, maxY, maxZ; |
||
63 | maxX = maxY = maxZ = Single.MinValue; |
||
64 | |||
65 | // Generate the vertex array |
||
66 | RenderData.Vertices = new float[NumVertices * 3]; |
||
67 | int current = 0; |
||
68 | for (int i = 0; i < NumVertices; i++) |
||
69 | { |
||
70 | RenderData.Vertices[current++] = Vertices[i].Coord.X; |
||
71 | RenderData.Vertices[current++] = Vertices[i].Coord.Y; |
||
72 | RenderData.Vertices[current++] = Vertices[i].Coord.Z; |
||
73 | |||
74 | if (Vertices[i].Coord.X < minX) |
||
75 | minX = Vertices[i].Coord.X; |
||
76 | else if (Vertices[i].Coord.X > maxX) |
||
77 | maxX = Vertices[i].Coord.X; |
||
78 | |||
79 | if (Vertices[i].Coord.Y < minY) |
||
80 | minY = Vertices[i].Coord.Y; |
||
81 | else if (Vertices[i].Coord.Y > maxY) |
||
82 | maxY = Vertices[i].Coord.Y; |
||
83 | |||
84 | if (Vertices[i].Coord.Z < minZ) |
||
85 | minZ = Vertices[i].Coord.Z; |
||
86 | else if (Vertices[i].Coord.Z > maxZ) |
||
87 | maxZ = Vertices[i].Coord.Z; |
||
88 | } |
||
89 | |||
90 | // Calculate the center-point from the bounding box edges |
||
91 | RenderData.Center = new Vector3((minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2); |
||
92 | |||
93 | // Generate the index array |
||
94 | RenderData.Indices = new ushort[NumFaces * 3]; |
||
95 | current = 0; |
||
96 | for (int i = 0; i < NumFaces; i++) |
||
97 | { |
||
98 | RenderData.Indices[current++] = (ushort)Faces[i].Indices[0]; |
||
99 | RenderData.Indices[current++] = (ushort)Faces[i].Indices[1]; |
||
100 | RenderData.Indices[current++] = (ushort)Faces[i].Indices[2]; |
||
101 | } |
||
102 | |||
103 | // Generate the texcoord array |
||
104 | RenderData.TexCoords = new float[NumVertices * 2]; |
||
105 | current = 0; |
||
106 | for (int i = 0; i < NumVertices; i++) |
||
107 | { |
||
108 | RenderData.TexCoords[current++] = Vertices[i].TexCoord.X; |
||
109 | RenderData.TexCoords[current++] = Vertices[i].TexCoord.Y; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | public override void LoadLODMesh(int level, string filename) |
||
114 | { |
||
115 | LODMesh lod = new LODMesh(); |
||
116 | lod.LoadMesh(filename); |
||
117 | LodMeshes[level] = lod; |
||
118 | } |
||
119 | } |
||
120 | } |