microsoft / DirectXTK

The DirectX Tool Kit (aka DirectXTK) is a collection of helper classes for writing DirectX 11.x code in C++

Home Page:https://walbourn.github.io/directxtk/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to create multiple models with different .dds textures?

duplicate-vegetable opened this issue · comments

I‘m trying to create multiple Model class instances each with a different .dds texture using Model::CreateFromCMO, but then I got confused about that even the code runs fine (without any exceptions thrown) when drawing models, it always uses the .dds texture referenced in the first .cmo file loaded. How to make the textures correspond to the models?

You should really try to share the model data as much as possible to save memory, so I'd suggest creating the 'master model' from the CMO, then clone it and modify the effects used (which is where the textures come from).

Thanks for the advice. I have solved the problem. After diving into EffectFactory's code, I found something that might be a bug: the effect caching use the texture name in the .cmo file, but multiple .cmo may use the same texture name for different texture file, which will prevent the loading of other materials.

Generally you want to share textures between models. It's critical for overall memory usage. The most common way to do that is shared material names. You can of course turn off this sharing by using the SetSharing(false); method on an EffectFactory.