制作模型加载器:读取顶点和纹理后该怎么办? [英] Making a Model Loader: What to do after reading the vertices and texture?

查看:89
本文介绍了制作模型加载器:读取顶点和纹理后该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在DirectX 11引擎中启动了一个小项目,该项目是制作一个简单的模型加载器。到目前为止,它所做的只是打开具有给定文件路径的文件,并准备从中读取文件。我的问题是,一旦我读取了顶点和纹理数据,该如何存储它直到渲染时间?我的想法是将这些数据放在一个char数组中,但这仅在我仅加载一个模型或具有许多个char数组(每个模型一个)的情况下才有效。

I recently started a small project within my DirectX 11 engine, which was to make a simple model loader. So far, all it does is open the file with the given file path and prepare to read from it. My question is this, once I read my vertices and texture data, what do I do with it to store it until rendering time? My idea was to put this data in a char array, but this would only work if I only loaded one model, or had many, many char arrays(one for each model).

我现在的状态是:

读取编辑内容!

在App.cpp中:

virtual void Load(String^ EntryPoint)
{
    std::auto_ptr<ModelLoad> ml(new ModelLoad);

    if (ml->LoadTVF("Triangle.tvf"))
    {
        // Load vertices and texture into a vertex buffer and texture buffer
    }
    else
    {
        MessageDialog Dialog("Failed to load a game model.\n'Triangle.tvf'", "Error");
        Dialog.ShowAsync();
    }
}

并在ModelLoader.cpp中的ModelLoad类中:

And in ModelLoader.cpp in class ModelLoad:

bool LoadTVF(string FP)
{
    ifstream TVFReader;
    TVFReader.open(FP);
    if (TVFReader.is_open())
    {
        // Read vertices and texture
        TVFReader.close();
        return true;
    }
    else
    {
        return false;
    }
}

编辑:

我为此做了很多工作,并完成了文件阅读器。现在,我得到两个字符串,一个用于纹理路径,一个用于顶点。我将使用这些内容,然后...做什么?

I have worked quite a bit more on this and have finished my file reader. Now, I end up with two strings, one for texture path, and one for vertices. I will use those and then...what?

预先感谢。

推荐答案

通常,您在加载时创建Direct3D 11顶点缓冲区和索引缓冲区,然后保留它们直到渲染。保留原始数据的内存副本的主要原因是为了避免碰撞,这可以通过实际上不渲染的边界体积或简化的碰撞网格更有效地完成。

Typically you create Direct3D 11 Vertex Buffers and Index Buffers at load time, and then keep them around until you render. The main reason to keep a memory copy of the original data is for collision, and this is more efficiently done with either bounding volumes or simplified collision meshes that you don't actually render.

请参见 DirectX工具包,它是模型实现的一些想法-也位于 GitHub

See DirectX Tool Kit for it's Model implementation for some ideas--which is also on GitHub

注意:这就是为什么大多数游戏不能完全处理 DXGI_ERROR_DEVICE_RESET DXGI_ERROR_DEVICE_REMOVED 的原因从 Present 返回,因为在这种情况下,您必须销毁设备并重新创建所有需要原始数据的Direct3D对象。游戏通常通过显示错误并需要重新加载来对此做出响应。这些不是正常工作的应用程序中的常见错误,因此通常可以。

Note: This is why most games don't fully handle DXGI_ERROR_DEVICE_RESET or DXGI_ERROR_DEVICE_REMOVED coming back from Present since in that case you have to destroy the device and recreate all Direct3D objects which would require having the original data. Games usually respond to these by displaying an error and requiring a reload. These are not common errors in properly working applications, so this is usually fine.

这篇关于制作模型加载器:读取顶点和纹理后该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆