CMO texture path problem

Mar 5, 2013 at 2:58 PM
I'm trying to get a model rendered with a texture using the SimpleSample (WP8) as a guide.
From Maya I've exported the FBX with the texture embedded (I've also tried with the Autodesk converter). Problem is that my app crashes because it cant find the texture.
In the SimpleSample, I've set a breakpoint on the following line:
virtual void CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override
    {
        WCHAR path[MAX_PATH] = {0};

        wcscpy_s( path, L"" );
         wcscat_s( path, name );

       /*HERE*/ EffectFactory::CreateTexture( path, deviceContext, textureView );
    }
And I can see that "path" ends up being "Tiny_skin.dds".
But when I use my model, the path ends up being "_Users_Matt_documents_visual studio 2012_Projects_TestCPPDXTK_TestCPPDXTK_TestCPPDXTKComp_Test.fbm_TestScribble.dds.dds"

So VS is extracting my TestScribble.dds file to a folder called Test.fbm (model is Test.fbx), and then trying to reference it incorrectly.
If I change the code in the above method to force path to be "TestScribble.dds" it works perfectly, but obviously that isn't a solution.

Would appreciate the help!
Coordinator
Mar 5, 2013 at 4:13 PM
I don't think the Visual Studio CMO converter will handle embedded FBX textures properly. Unlike for instance the XNA Content Pipeline, this functionality in VS does not understand references from one asset to another, file dependencies, etc. It just converts the model data, which might contain strings pointing to separate texture files, but VS knows nothing directly about those textures. It's up to you to arrange for the textures to end up in a suitable format and location for the model to load them (which typically means converting them to .dds format and adding them to your VS project so they will be deployed as part of the app package).
Mar 6, 2013 at 5:49 AM
I actually initially tried not embedding the textures. When I couldn't get that to work I tried embedding.

So, I guess my question is how can I export a model in such a way that VS knows to look in the same directory for the DDS?
Coordinator
Mar 6, 2013 at 6:22 AM
VS 2012's content pipeline just does that to the name, which is what is in the .CMO file. The main issue in DirectXTK is likely that you are loading the .CMO from a subdirectory of your working directory, but the default FXEffectFactory is trying to find the .DDS file in the current working directory.

I ran into this problem with the Windows Store app version of DirectXTK Simple Sample as well, which can be solved by creating a custom FXEffectFactory to implement whatever is the appropriate path search algorithm for your program. For the sample, I just have to look in "Assets" for the DDS files.
class MyEffectFactory : public EffectFactory 
{ 
public: 
    MyEffectFactory( _In_ ID3D11Device* device ) : EffectFactory( device ) {} 
 
    virtual void CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override 
    { 
        WCHAR path[MAX_PATH] = {0}; 
 
        wcscpy_s( path, L"Assets\\" ); 
        wcscat_s( path, name ); 
 
        EffectFactory::CreateTexture( path, deviceContext, textureView ); 
    } 
}; 
Mar 6, 2013 at 9:58 AM
Hmmm, to get around that I just put everything in the root, and still couldn't make it work :-/

It would be really awesome if someone could try stick my model into a test solution and see if it works like it should, or why it doesn't.

Here is the FBX: http://2share.co.za/Files/Test.fbx
And the DDS: http://2share.co.za/Files/TestScribble.dds
Mar 6, 2013 at 5:53 PM
I got it to work with a terrible hack.
In that method I just strip out the final filename from the path, and that solves it.
Coordinator
Mar 6, 2013 at 6:36 PM
I think the issue is that the content pipeline is assuming your 'source' textures are stored in something like JPG, PNG, etc. that gets built to .DDS files. Not that you have already converted them to DDS files and reference the from the FBX model as such.