2

I want to read a diffuse texture like this:

aiGetMaterialString(material,
                    AI_MATKEY_COLOR_DIFFUSE, // this is the pkey parameter
                    aiTextureType_DIFFUSE,
                    0,
                    path);

Why is there a pkey parameter? Is it not enough to specify the type?

Anyway, the path string is empty after calling above function. I was expecting to get the filename of the texture.

1
  • 1
    Please always indicate a language. Commented Jul 13 at 0:19

2 Answers 2

3

aiGetMaterialString is used to get string properties in general; the pKey is the name of the property that we want to retrive, which in this case should be: "$tex.file" .

AI_MATKEY_COLOR_DIFFUSE is not just the pKey parameter, it's the macro:

#define AI_MATKEY_COLOR_DIFFUSE "$clr.diffuse", 0, 0 

Which refers to the wrong property and expands to fill the pKey , type , and index parameters of the function


Try using this:

aiGetMaterialString(material,
                    "$tex.file",
                    aiTextureType_DIFFUSE,
                    0,
                    path);

or this (notice the AI_MATKEY_TEXTURE macro):

aiGetMaterialString(material,
                    AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0),
                    path);

where AI_MATKEY_TEXTURE(type, index) expands to "$tex.file", type, index


Also, regarding aiGetMaterialTexture, understand that it internally calls

aiGetMaterialString(mat, AI_MATKEY_TEXTURE(type, index), path) 

to retrive the path to the texture, and it's used to get much more information about the texture than just the path

Comments

Enter at least 15 characters
Enter at least 15 characters
2

I don't think that the purpose of the aiGetMaterialString function is to get the path to the texture. But I've found another function to get the path of the texture. And it doesn't even requiere a pkey parameter:

aiGetMaterialTexture(material,
                     type,
                     0,
                     path,
                     NULL, NULL, NULL, NULL, NULL, NULL);

Although I have found a solution I can work with, I wont accept my own answer, because I'm still clueless about the pkey parameter and the implicit question about the purpose of the aiGetMaterialString function.

Hopefully someone with deeper knowledge of the assimp library can shed some light on this.

Comments

Enter at least 15 characters
Enter at least 15 characters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.