85 lines
1.7 KiB
C#
85 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
class RSDatLoader
|
|
{
|
|
public Mesh loadModel(Packet p)
|
|
{
|
|
|
|
|
|
int vertexCount = p.readInt();
|
|
int indexCount = p.readInt();
|
|
int normalCount = p.readInt();
|
|
int uvCount = p.readInt();
|
|
int colorCount = p.readInt();
|
|
|
|
List<Vector3> vertices = new List<Vector3>();
|
|
List<int> indices = new List<int>();
|
|
List<Vector3> normals = new List<Vector3>();
|
|
List<Vector2> uvs = new List<Vector2>();
|
|
List<Color> colors = new List<Color>();
|
|
|
|
int i = 0;
|
|
|
|
while (i < vertexCount)
|
|
{
|
|
float v1, v2, v3;
|
|
v1 = (float)p.readInt() / 1000.0f;
|
|
v2 = (float)p.readInt() / 1000.0f;
|
|
v3 = (float)p.readInt() / 1000.0f;
|
|
vertices.Add(new Vector3(v1, v2, v3));
|
|
i += 3;
|
|
}
|
|
|
|
i = 0;
|
|
|
|
while (i < indexCount)
|
|
{
|
|
indices.Add(p.readInt());
|
|
i += 1;
|
|
}
|
|
|
|
i = 0;
|
|
while (i < normalCount)
|
|
{
|
|
float v1, v2, v3;
|
|
v1 = (float)p.readInt() / 1000.0f;
|
|
v2 = (float)p.readInt() / 1000.0f;
|
|
v3 = (float)p.readInt() / 1000.0f;
|
|
normals.Add(new Vector3(v1, v2, v3));
|
|
i += 3;
|
|
}
|
|
|
|
i = 0;
|
|
while (i < uvCount)
|
|
{
|
|
float v1, v2;
|
|
v1 = (float)p.readInt() / 1000.0f;
|
|
v2 = (float)p.readInt() / 1000.0f;
|
|
uvs.Add(new Vector2(v1, v2));
|
|
i += 2;
|
|
}
|
|
|
|
i = 0;
|
|
while (i < colorCount)
|
|
{
|
|
float v1, v2, v3;
|
|
v1 = (float)p.readInt() / 1000.0f;
|
|
v2 = (float)p.readInt() / 1000.0f;
|
|
v3 = (float)p.readInt() / 1000.0f;
|
|
colors.Add(new Color(v1, v2, v3));
|
|
i += 3;
|
|
}
|
|
|
|
Mesh m = new Mesh();
|
|
m.SetVertices(vertices);
|
|
m.SetColors(colors);
|
|
m.SetNormals(normals);
|
|
m.SetUVs(0, uvs.ToArray());
|
|
m.SetIndices(indices.ToArray(), MeshTopology.Triangles, 0);
|
|
return m;
|
|
|
|
}
|
|
} |