Storing Images in Scene Files?
-
On 26/01/2013 at 09:05, xxxxxxxx wrote:
There is only one tag per object. And that tag needs to hold multiple images and multiple UserData entries. Sort of like this:
Position
Rotation
Position
Rotation
etc....The bitmap buttons (the poses) in the GeDialog automatically update and change depending on which object is selected in the scene, or with the tree gizmo.
Based on what I'm hearing from you guys. I think what I have to do is:
-Create some kind of temporary image folder structure to save the rendered images when I'm actually using the plugin. Or save them into memory instead of the HD.
-Then execute a type of "file dump" maneuver. Using the overriden Write() method to take those images and store them into each specific StoragTag so the images will load if C4D is closed and re-opened.
-Then delete the temp images when C4D closesIt sounds like a fairly simple concept. And it might be simple for you advanced C++ guys.
But it's not simple for an average user like me with a plugin that has multiple tags to keep track of. And multiple images per tag that need to go on specific buttons. Which are being dynamically added & deleted. With constantly changing index numbers.
Not to mention being made even more difficult because the hyperfile has no indexing abilities.This is why I think it would be nice to have some some sort of storage tag that can store bitmap images added to the SDK.
That way we can save images for our gizmos locally in the scene file with index numbers..live..as we create them.. into this tag. And they will always be there. Locally serving our gui's images.
Or maybe a completely new type of plugin that has the Dialog and the Tag set up to talk to each other better than what we have now. With local image storage abilities.-ScottA
-
On 27/01/2013 at 13:28, xxxxxxxx wrote:
Hey Guys.
I've been working on it some more today and now I'm very, very close!
Here's the updated plugin and Source code:https://sites.google.com/site/scottayersmedia/Dialog_StorageTag.zipIt basically all works now. I can add my storage tag to any object and save the rendered scene image of it in the GeDialog's bitmap button.
And when I select different objects the button's image changes depending on which object is selected.
I can also save the scene file and re-open it. And all the images are still there and working like they should be.
*Hooray!Only one problem though. And it's a big one.
When I add something new to the scene after I've saved it and re-opened it again. I get the crash error:Incorrect File StructureIf I can figure out how to fix this one last problem. I've think I've got it all working.
I'm almost there.
Thanks for all the help guys.-ScottA
-
On 27/01/2013 at 13:34, xxxxxxxx wrote:
Make sure that your Read() and Write() are identical. If you are looping through to get each bitmap, make sure the count and each loop iteration is identical. Without seeing your code, hard to say if that is it. I'll take a look at it here shortly.
-
On 27/01/2013 at 13:35, xxxxxxxx wrote:
Hi Scott,
Bool StorageTag::Write(GeListNode* node, HyperFile* file) { //This is where the rendered scene image gets saved as a .jpg image when the scene file is saved //if (!file->WriteBool(tagBitmap != NULL)) return FALSE; //if (tagBitmap != NULL) file->WriteImage(tagBitmap, FILTER_JPG, NULL, SAVEBIT_ALPHA); imagecount = images.GetCount(); if (!file->WriteLong(imagecount)) return FALSE; //Iterate over all bitmaps and write them to the HyperFile for (LONG i=0; i < imagecount; i++) { **tagBitmap = BaseBitmap::Alloc(); //Allocate the bitmap variable so we can use it to make an image** tagBitmap = images[i]; file->WriteImage(tagBitmap, FILTER_JPG, NULL, SAVEBIT_ALPHA); } return TRUE; }
1. tagBitmap is a class-member. Why do you use it for temporary storage?
2. You will get memory-leaks at the red marked line.
3. Isn't that actually exactly what I showed you here?Next, in your Read() method, you only read a single image. What if you've previosuly written 7
images? That is where the incorrect file-structure message comes from.Best,
Niklas -
On 27/01/2013 at 13:43, xxxxxxxx wrote:
Bool StorageTag::Read(GeListNode* node, HyperFile* file, LONG level) { //Read the tag's hyperfile to see if there is an image stored in it LONG numImages = file->ReadLong(&imagecount); GePrint(LongToString(numImages)); for (LONG i = 0L; i != numImages; ++i) { tagBitmap = BaseBitmap::Alloc(); //Allocate the bitmap variable so we can use it to make an image if (!tagBitmap) return FALSE; //Error handling if allocation fails file->ReadImage(tagBitmap); images->Push(tagBitmap); } //This code sets the Bool's value //Depending if an image is, or is not, read when the scene file is opened in C4D //Bool hasBitmap; //if (!file->ReadBool(&hasBitmap)) return FALSE; //if (hasBitmap) //{ // if (!file->ReadImage(tagBitmap)) return FALSE; // GePrint(LongToString(tagBitmap->GetBh())); //} //else tagBitmap = NULL; return TRUE; } Bool StorageTag::Write(GeListNode* node, HyperFile* file) { //This is where the rendered scene image gets saved as a .jpg image when the scene file is saved //if (!file->WriteBool(tagBitmap != NULL)) return FALSE; //if (tagBitmap != NULL) file->WriteImage(tagBitmap, FILTER_JPG, NULL, SAVEBIT_ALPHA); imagecount = images.GetCount(); if (!file->WriteLong(imagecount)) return FALSE; //Iterate over all bitmaps and write them to the HyperFile for (LONG i=0; i < imagecount; i++) { file->WriteImage(images[i], FILTER_JPG, NULL, SAVEBIT_ALPHA); } return TRUE; }
-
On 27/01/2013 at 13:47, xxxxxxxx wrote:
I haven't tried multiple buttons yet Nik.
It's quite possible I put on my party hat too soon.-ScottA
*Edit- That fixed it Robert.....Once again I'm in your debt sir.