Kav/Loaders/ModelLoader.cs

59 lines
2.0 KiB
C#

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 effect = new Kav.DeferredPBR_GBufferEffect(
graphicsDevice
)
{
Albedo = meshPartData.Albedo,
Metallic = meshPartData.Metallic,
Roughness = meshPartData.Roughness,
AlbedoTexture = meshPartData.AlbedoTexture,
NormalTexture = meshPartData.NormalTexture,
MetallicRoughnessTexture = meshPartData.MetallicRoughnessTexture
};
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
);
}
meshParts.Add(new Kav.MeshPart(
meshPartData.VertexBuffer,
meshPartData.IndexBuffer,
meshPartData.Positions,
triangles,
effect
));
}
meshes.Add(new Kav.Mesh(meshParts.ToArray()));
}
return new Kav.Model(meshes.ToArray());
}
}
}