简体   繁体   English

当我当前的代码不工作时,如何使用 assimp.net 加载 model 和 C#?

[英]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.

相关问题 MS Visual Studio C#-有人可以向我解释为什么我的代码不起作用以及如何使它起作用吗? - MS Visual Studio C# - Can someone explain to me why my code isn't working and how I can get it to work? 我的C#代码生成的命令在C#中不起作用,但是当我将其粘贴到cmd时可以完美地工作 - My command which is being produced by my C# code isn't working in C#, but works perfectly when I paste it to cmd Assimp.Mesh中缺少Assimp.Net GetTextureCoords - Assimp.Net GetTextureCoords missing from Assimp.Mesh 模型没有按预期工作C# - model isn't working as expected C# C#我的吸气剂不起作用 - c# My getter isn't working 我无法弄清楚为什么我的文本框没有在asp.net中触发我的OnClick c#函数 - I can't figure out why my textbox isn't firing my OnClick c# function in asp.net POST model 绑定不适用于具有 .net 核心 c# 的命名空间路由约定 - POST model binding isn't working with Namespace Routing Convention with .net core c# 如果用户输入不正确,我该如何重复代码? C# - how can i repeat the code if the user input isn't correct ? c# 如何避免在Monodevelop中为c#对象键入完整的名称空间层次结构(“使用”无效)? - How can I avoid typing the full namespace hierarchy for c# objects in Monodevelop (“using” isn't working)? 我的MessageBox.Show代码在C#中不起作用。 没有错误但有些错误 - My MessageBox.Show Code In C# Isn't Working. There Are No Errors But Something Is Wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM