Making a Model Loader: What to do after reading the vertices and texture?

一笑奈何 提交于 2019-12-24 16:01:27

问题


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).

What I have now is this:

Read edit!

In 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();
    }
}

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;
    }
}

Edit:

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?

Thanks in advance.


回答1:


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.

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

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.



来源:https://stackoverflow.com/questions/29799677/making-a-model-loader-what-to-do-after-reading-the-vertices-and-texture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!