如何解决在Monogame中无需内容管道即可加载.FBX文件
我想知道是否有一种方法可以在不使用monogame内容管道的情况下将仅包含多维数据集的简单.fbx文件加载到我的游戏中。这是我当前拥有的代码,但实际上我只是想摆脱文件必须是.xnb
的要求 public static Model LoadModel(string model)
{
Model outModel = null;
// If model is already in memory,reference that instead of having to load it again
if (Loaded3DModels.ContainsKey(model))
{
Loaded3DModels.TryGetValue(model,out outModel);
}
else
{
if (File.Exists(Game.gameWindow.Content.RootDirectory + "/" + model + ".fbx"))
{
outModel = Game.gameWindow.Content.Load<Model>(model + ".fbx");
Loaded3DModels.Add(model,outModel);
}
else
{
Debug.LogError("The Model \"" + model + ".fbx\" does not exist!",true,2);
}
}
return outModel;
}
解决方法
所以我设法使用AssImp加载了一个网格,然后将其“转换”为Monogame可以渲染的东西
public Renderer3DComponent(Mesh mesh)
{
// Set up material
Material = new BasicEffect(Game.graphics.GraphicsDevice);
Material.Alpha = 1;
Material.VertexColorEnabled = true;
Material.LightingEnabled = false;
// Tris
for (int i = mesh.VertexCount - 1; i >= 0; i--)
{
var Vert = mesh.Vertices[i];
Verts.Add(new VertexPositionColor(new Vector3(Vert.X,Vert.Y,Vert.Z),Color.White));
}
// Buffer
Buffer = new VertexBuffer(Game.graphics.GraphicsDevice,typeof(VertexPositionColor),Verts.Count,BufferUsage.WriteOnly);
Buffer.SetData(Verts.ToArray());
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。