2020-08-06 07:10:23 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace Kav
|
|
|
|
{
|
|
|
|
public static class ModelLoader
|
|
|
|
{
|
|
|
|
public static Kav.Model Load(GraphicsDevice graphicsDevice, Smuggler.ModelData modelData)
|
|
|
|
{
|
|
|
|
var meshes = new List<Kav.Mesh>();
|
|
|
|
|
|
|
|
foreach (var meshData in modelData.Meshes)
|
|
|
|
{
|
|
|
|
var meshParts = new List<Kav.MeshPart>();
|
|
|
|
|
|
|
|
foreach (var meshPartData in meshData.MeshParts)
|
|
|
|
{
|
|
|
|
var triangles = new Kav.Triangle[meshPartData.Triangles.Length];
|
|
|
|
for (int i = 0; i < meshPartData.Triangles.Length; i++)
|
|
|
|
{
|
|
|
|
var smugglerTriangle = meshPartData.Triangles[i];
|
|
|
|
|
|
|
|
triangles[i] = new Kav.Triangle(
|
|
|
|
smugglerTriangle.A,
|
|
|
|
smugglerTriangle.B,
|
|
|
|
smugglerTriangle.C
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-02 05:26:40 +00:00
|
|
|
var meshPart = new Kav.MeshPart(
|
2020-08-06 07:10:23 +00:00
|
|
|
meshPartData.VertexBuffer,
|
|
|
|
meshPartData.IndexBuffer,
|
|
|
|
meshPartData.Positions,
|
2020-10-02 05:26:40 +00:00
|
|
|
triangles
|
|
|
|
);
|
|
|
|
|
|
|
|
meshPart.Albedo = meshPartData.Albedo;
|
|
|
|
meshPart.Metallic = meshPartData.Metallic;
|
|
|
|
meshPart.Roughness = meshPartData.Roughness;
|
|
|
|
|
|
|
|
meshPart.AlbedoTexture = meshPartData.AlbedoTexture;
|
|
|
|
meshPart.NormalTexture = meshPartData.NormalTexture;
|
|
|
|
meshPart.MetallicRoughnessTexture = meshPartData.MetallicRoughnessTexture;
|
|
|
|
|
|
|
|
meshParts.Add(meshPart);
|
2020-08-06 07:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
meshes.Add(new Kav.Mesh(meshParts.ToArray()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Kav.Model(meshes.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|