Display Control
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/04/2011 at 09:24, xxxxxxxx wrote:
User Information:
Cinema 4D Version: C++
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;---------
Howdy,@Matthias
There seems to be only this one thread with any information about the DisplayControl in a ToolData plugin, but it doesn't look like any rule was established there:
DisplayControlCan you show a simple example of the proper way to handle the allocating and freeing of the display color array?
Adios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/04/2011 at 01:56, xxxxxxxx wrote:
I will try to get hold of an example with DisplayControl.
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/04/2011 at 08:12, xxxxxxxx wrote:
Howdy,
Thanks, Mattias.
Adios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/04/2011 at 00:24, xxxxxxxx wrote:
Turns out that using DisplayControl is really simple. The only important note is that the array for the vertex colors has to be allocated in DisplayControl(). Cinema will take over ownership, so you don't free it yourself. I will update the docs accordingly.
Simple example, random coloring of vertices:
Bool LiquidToolData::InitDisplayControl(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, const AtomArray *active) { return TRUE; } void LiquidToolData::FreeDisplayControl() { } Bool LiquidToolData::DisplayControl(BaseDocument *doc, BaseObject *op, BaseObject *chainstart, BaseDraw *bd, BaseDrawHelp *bh, ControlDisplayStruct &cds) { if (chainstart && op) // FIX[46030] { if (chainstart->IsInstanceOf(Opoint) && op->IsInstanceOf(Opoint) && ToPoint(chainstart)->GetPointCount()==ToPoint(op)->GetPointCount()) op=chainstart; else return TRUE; } if (!op || !op->IsInstanceOf(Opoint)) return TRUE; LONG pcnt = ToPoint(op)->GetPointCount(); cds.vertex_color = GeAllocTypeNC(SVector,pcnt); if (!cds.vertex_color) return FALSE; Random rnd; rnd.Init(45346); LONG i; for (i=0; i<pcnt; i++) { cds.vertex_color[i] = SVector(rnd.Get01(), rnd.Get01(), rnd.Get01()); } return TRUE; }
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/04/2011 at 03:52, xxxxxxxx wrote:
Howdy,
Ah, thanks Matthias!
So, for versions prior to R12, would I use this instead?:
cds.vertex_color = GeAllocNC(sizeof(Vector)*pcnt);
Edit:
Hehe, actually maybe this is correct :cds.vertex_color = (Vector* )GeAllocNC(sizeof(Vector)*pcnt);
Adios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/04/2011 at 04:26, xxxxxxxx wrote:
Yes, allocation prior R12:
cds.vertex_color = (Vector* )GeAllocNC(pcnt*sizeof(Vector));
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/04/2011 at 05:22, xxxxxxxx wrote:
Howdy,
Cool, thanks Matthias. I can finally clean up my tool code.
Adios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/04/2011 at 15:54, xxxxxxxx wrote:
Howdy,
Hmmmmm, that seems to cause another problem, that all of the objects in the scene are affected by the DisplayControl() function, when only one object should be affected. And also the other objects are displaying random colors.
The code I added is this:
LONG i, pCnt = ToPoint(dest)->GetPointCount(); #if API_VERSION < 12000 cds.vertex_color = (Vector* )GeAllocNC(sizeof(Vector)*pCnt); #else cds.vertex_color = (SVector* )GeAllocNC(sizeof(SVector)*pCnt); #endif if(!cds.vertex_color) return FALSE; for(i=0; i<pCnt; i++) { cds.vertex_color[i] = ptColor[i]; }
... the ptColor array is a class member variable that is built in ToolData::InitDisplayControl(), because to build it in ToolData::DisplayControl() is too time consuming. It is then freed in ToolData::FreeDisplayControl().
With the way I had it working before, only the object to be colorized was displaying colors. I was building the ptColor member variable array in TooData::InitDisplayControl(), the same as it is now. Then in ToolData::DisplayControl() I did this:
cds.vertex_color = ptColor;
... and then I simply did NOT free the ptColor array in ToolData::FreeDisplayControl(). It seemed to work and I didn't get any memory leaks. Was that a safe way of doing it, too?
Adios,
Cactus Dan -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/04/2011 at 05:18, xxxxxxxx wrote:
DisplayControl() will free the allocated memory passed to cds.vertex_color. So just make sure to pass a valid block of memory.
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/04/2011 at 07:06, xxxxxxxx wrote:
Howdy,
OK, thanks Matthias. I thought what I had before was OK, but I wasn't sure.
Sometimes it's easier for me to understand when I have to allocate and free memory myself. It get's a little confusing to me when those things are automated.
Adios,
Cactus Dan