[英]How can I load a model with assimp.net and C# when my current code isn't working?
I'm trying to import a model with assimp.net and c# but the my code doesn't work any help?我正在尝试使用 assimp.net 和 c# 导入 model,但我的代码没有任何帮助?
Here is my code:这是我的代码:
public void LoadModel(string model, out float[] vertices, out int[] indices) {
AssimpContext contex = new AssimpContext();
var a = contex.ImportFile(model);
Mesh[] meshes;
int vnumber = 0;
calcMeshes(a,out meshes);
calcVerices(meshes[0], vnumber, out vertices);
calcIndices(meshes[0],out indices);
}
void calcMeshes(Scene scenes,out Mesh[] a)
{
a = scenes.Meshes.ToArray();
}
void calcIndices(Mesh mesh, out int[] a)
{
a = mesh.GetIndices();
}
void calcVerices(Mesh mesh,int vnumber, out float[] a)
{
List<float> v = new List<float>();
foreach (var item in mesh.Vertices)
{
v.Add(item.X);
v.Add(item.Y);
v.Add(item.Z);
v.Add(mesh.TextureCoordinateChannels[0][vnumber].X);
v.Add(mesh.TextureCoordinateChannels[0][vnumber].Y);
vnumber += 1;
}
a = v.ToArray();
}`
I tried to rewrite the function and the result is this the result (should be a cube):我试图重写 function 结果是这个结果(应该是一个立方体):
I don't know if is an indices issuse or a veritces issues.我不知道是 indices issuse 还是 veritces 问题。
For me it looks like a index issue.对我来说,它看起来像是一个索引问题。 Unfortunately, you havent't shown the code for creating the indices as well.不幸的是,您还没有显示用于创建索引的代码。 All render data in assimp is separated into vertex- and index data. assimp 中的所有渲染数据都分为顶点数据和索引数据。 The indices will describe which face with the related vertices shall be used.索引将描述应使用具有相关顶点的面。 And this information was ignored in your code if I have understood it correctly.如果我理解正确的话,这些信息在你的代码中被忽略了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.