GetAllTextures not working
-
On 19/02/2018 at 12:41, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R19
Platform: Windows ;
Language(s) : C++ ;---------
Hi,I was trying to obtain the path to a texture from a material assigned to an object.
Used the following code in a CommandData, and only got the path to the texture from running Test 2.In the first test I am calling GetAllTextures with an atomarray containing the object I want to get the texture path from. This fails, as the returned container is empty.
In the second test I am calling GetAllTextures with nullptr, which would return me texture paths for all objects in the scene. This works.Why does the first one fail ?
// Test 1 { GePrint("Test 1"); BaseDocument* doc = GetActiveDocument(); if (doc) { BaseObject* object = doc->GetActiveObject(); if (object) { // get all textures used by an object AutoAlloc<AtomArray> ar; if (ar) { ar->Append(object); BaseContainer texbc = doc->GetAllTextures(ar); BrowseContainer browse(&texbc); Int32 id; GeData* data; GePrint("Used textures:"); while (browse.GetNext(&id, &data)) { const Filename& filename = data->GetFilename(); GePrint(filename.GetFileString()); } } } } } // Test 2 { GePrint("Test 2"); BaseDocument* doc = GetActiveDocument(); if (doc) { BaseObject* object = doc->GetActiveObject(); if (object) { // get all textures BaseContainer texbc = doc->GetAllTextures(nullptr); BrowseContainer browse(&texbc); Int32 id; GeData* data; GePrint("Used textures:"); while (browse.GetNext(&id, &data)) { const Filename& filename = data->GetFilename(); GePrint(filename.GetFileString()); } } } }
-
On 20/02/2018 at 01:59, xxxxxxxx wrote:
Hi Daniel,
basically GetAllTextures() works via MSG_GETALLASSETS. But this message is not forwarded from objects to tags to materials. So, in the end you will need to get the materials from the texture tags yourself and then add the materials to the AtomArray passed to GetAllTextures(). On objects this will only work for special ones like the Displacer deformer, if a texture is used in there directly.
-
On 20/02/2018 at 03:16, xxxxxxxx wrote:
I see.
Adding the materials to the AtomArray ... Really? Wow!
So the word "objects" in the method description "Gets all used textures for the objects in ar." isn't only referring to BaseObjects. Nice!
Thanks Andreas.